diff mbox series

[v4,6/8] mpi3mr: expose adapter state to sysfs

Message ID 20220413145652.112271-7-sumit.saxena@broadcom.com
State Superseded
Headers show
Series mpi3mr: add BSG interface support for controller management | expand

Commit Message

Sumit Saxena April 13, 2022, 2:56 p.m. UTC
Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
---
 drivers/scsi/mpi3mr/mpi3mr.h     |  2 +-
 drivers/scsi/mpi3mr/mpi3mr_app.c | 46 ++++++++++++++++++++++++++++++++
 drivers/scsi/mpi3mr/mpi3mr_os.c  |  1 +
 3 files changed, 48 insertions(+), 1 deletion(-)

Comments

Himanshu Madhani April 19, 2022, 11:53 p.m. UTC | #1
> On Apr 13, 2022, at 7:56 AM, Sumit Saxena <sumit.saxena@broadcom.com> wrote:
> 
> Signed-off-by: Sumit Saxena <sumit.saxena@broadcom.com>
> ---
> drivers/scsi/mpi3mr/mpi3mr.h     |  2 +-
> drivers/scsi/mpi3mr/mpi3mr_app.c | 46 ++++++++++++++++++++++++++++++++
> drivers/scsi/mpi3mr/mpi3mr_os.c  |  1 +
> 3 files changed, 48 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
> index cc54231da658..1de3b006f444 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr.h
> +++ b/drivers/scsi/mpi3mr/mpi3mr.h
> @@ -1056,5 +1056,5 @@ int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc,
> 	struct mpi3mr_drv_cmd *drv_cmd);
> void mpi3mr_app_save_logdata(struct mpi3mr_ioc *mrioc, char *event_data,
> 	u16 event_data_size);
> -
> +extern const struct attribute_group *mpi3mr_host_groups[];
> #endif /*MPI3MR_H_INCLUDED*/
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
> index c5c447defef3..dada12216b97 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_app.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
> @@ -1217,3 +1217,49 @@ void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
> err_device_add:
> 	kfree(mrioc->bsg_dev);
> }
> +
> +/**
> + * adapter_state_show - SysFS callback for adapter state show
> + * @dev: class device
> + * @attr: Device attributes
> + * @buf: Buffer to copy
> + *
> + * Return: snprintf() return after copying adapter state
> + */
> +static ssize_t
> +adp_state_show(struct device *dev, struct device_attribute *attr,
> +	char *buf)
> +{
> +	struct Scsi_Host *shost = class_to_shost(dev);
> +	struct mpi3mr_ioc *mrioc = shost_priv(shost);
> +	enum mpi3mr_iocstate ioc_state;
> +	uint8_t adp_state;
> +
> +	ioc_state = mpi3mr_get_iocstate(mrioc);
> +	if (ioc_state == MRIOC_STATE_UNRECOVERABLE)
> +		adp_state = MPI3MR_BSG_ADPSTATE_UNRECOVERABLE;
> +	else if ((mrioc->reset_in_progress) || (mrioc->stop_bsgs))
> +		adp_state = MPI3MR_BSG_ADPSTATE_IN_RESET;
> +	else if (ioc_state == MRIOC_STATE_FAULT)
> +		adp_state = MPI3MR_BSG_ADPSTATE_FAULT;
> +	else
> +		adp_state = MPI3MR_BSG_ADPSTATE_OPERATIONAL;
> +
> +	return snprintf(buf, PAGE_SIZE, "%u\n", adp_state);
> +}
> +
> +static DEVICE_ATTR_RO(adp_state);
> +
> +static struct attribute *mpi3mr_host_attrs[] = {
> +	&dev_attr_adp_state.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group mpi3mr_host_attr_group = {
> +	.attrs = mpi3mr_host_attrs
> +};
> +
> +const struct attribute_group *mpi3mr_host_groups[] = {
> +	&mpi3mr_host_attr_group,
> +	NULL,
> +};
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 19298136edb6..89a4918c4a9e 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -4134,6 +4134,7 @@ static struct scsi_host_template mpi3mr_driver_template = {
> 	.max_segment_size		= 0xffffffff,
> 	.track_queue_depth		= 1,
> 	.cmd_size			= sizeof(struct scmd_priv),
> +	.shost_groups			= mpi3mr_host_groups,
> };
> 
> /**
> -- 
> 2.27.0
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
diff mbox series

Patch

diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h
index cc54231da658..1de3b006f444 100644
--- a/drivers/scsi/mpi3mr/mpi3mr.h
+++ b/drivers/scsi/mpi3mr/mpi3mr.h
@@ -1056,5 +1056,5 @@  int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc,
 	struct mpi3mr_drv_cmd *drv_cmd);
 void mpi3mr_app_save_logdata(struct mpi3mr_ioc *mrioc, char *event_data,
 	u16 event_data_size);
-
+extern const struct attribute_group *mpi3mr_host_groups[];
 #endif /*MPI3MR_H_INCLUDED*/
diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
index c5c447defef3..dada12216b97 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_app.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
@@ -1217,3 +1217,49 @@  void mpi3mr_bsg_init(struct mpi3mr_ioc *mrioc)
 err_device_add:
 	kfree(mrioc->bsg_dev);
 }
+
+/**
+ * adapter_state_show - SysFS callback for adapter state show
+ * @dev: class device
+ * @attr: Device attributes
+ * @buf: Buffer to copy
+ *
+ * Return: snprintf() return after copying adapter state
+ */
+static ssize_t
+adp_state_show(struct device *dev, struct device_attribute *attr,
+	char *buf)
+{
+	struct Scsi_Host *shost = class_to_shost(dev);
+	struct mpi3mr_ioc *mrioc = shost_priv(shost);
+	enum mpi3mr_iocstate ioc_state;
+	uint8_t adp_state;
+
+	ioc_state = mpi3mr_get_iocstate(mrioc);
+	if (ioc_state == MRIOC_STATE_UNRECOVERABLE)
+		adp_state = MPI3MR_BSG_ADPSTATE_UNRECOVERABLE;
+	else if ((mrioc->reset_in_progress) || (mrioc->stop_bsgs))
+		adp_state = MPI3MR_BSG_ADPSTATE_IN_RESET;
+	else if (ioc_state == MRIOC_STATE_FAULT)
+		adp_state = MPI3MR_BSG_ADPSTATE_FAULT;
+	else
+		adp_state = MPI3MR_BSG_ADPSTATE_OPERATIONAL;
+
+	return snprintf(buf, PAGE_SIZE, "%u\n", adp_state);
+}
+
+static DEVICE_ATTR_RO(adp_state);
+
+static struct attribute *mpi3mr_host_attrs[] = {
+	&dev_attr_adp_state.attr,
+	NULL,
+};
+
+static const struct attribute_group mpi3mr_host_attr_group = {
+	.attrs = mpi3mr_host_attrs
+};
+
+const struct attribute_group *mpi3mr_host_groups[] = {
+	&mpi3mr_host_attr_group,
+	NULL,
+};
diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
index 19298136edb6..89a4918c4a9e 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_os.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
@@ -4134,6 +4134,7 @@  static struct scsi_host_template mpi3mr_driver_template = {
 	.max_segment_size		= 0xffffffff,
 	.track_queue_depth		= 1,
 	.cmd_size			= sizeof(struct scmd_priv),
+	.shost_groups			= mpi3mr_host_groups,
 };
 
 /**