scsi: pm80xx: Add sysfs attribute to check MPI state
authorVishakha Channapattan <vishakhavc@google.com>
Thu, 15 Apr 2021 10:33:45 +0000 (16:03 +0530)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 16 Apr 2021 02:28:59 +0000 (22:28 -0400)
A new sysfs variable 'ctl_mpi_state' is being introduced to check the state
of MPI.

Using the 'ctl_mpi_state' sysfs variable we can check the MPI state:

    linux-2dq0:~# cat /sys/class/scsi_host/host*/ctl_mpi_state
    MPI is successfully initialized

Link: https://lore.kernel.org/r/20210415103352.3580-2-Viswas.G@microchip.com
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Vishakha Channapattan <vishakhavc@google.com>
Signed-off-by: Viswas G <Viswas.G@microchip.com>
Signed-off-by: Ruksar Devadi <Ruksar.devadi@microchip.com>
Signed-off-by: Ashokkumar N <Ashokkumar.N@microchip.com>
Signed-off-by: Radha Ramachandran <radha@google.com>
Signed-off-by: kernel test robot <lkp@intel.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/pm8001/pm8001_ctl.c

index 26e340e..f386307 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/slab.h>
 #include "pm8001_sas.h"
 #include "pm8001_ctl.h"
+#include "pm8001_chips.h"
 
 /* scsi host attributes */
 
@@ -879,9 +880,37 @@ static ssize_t pm8001_show_update_fw(struct device *cdev,
                        flash_error_table[i].err_code,
                        flash_error_table[i].reason);
 }
-
 static DEVICE_ATTR(update_fw, S_IRUGO|S_IWUSR|S_IWGRP,
        pm8001_show_update_fw, pm8001_store_update_fw);
+
+/**
+ * ctl_mpi_state_show - controller MPI state check
+ * @cdev: pointer to embedded class device
+ * @buf: the buffer returned
+ *
+ * A sysfs 'read-only' shost attribute.
+ */
+
+static const char *const mpiStateText[] = {
+       "MPI is not initialized",
+       "MPI is successfully initialized",
+       "MPI termination is in progress",
+       "MPI initialization failed with error in [31:16]"
+};
+
+static ssize_t ctl_mpi_state_show(struct device *cdev,
+               struct device_attribute *attr, char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(cdev);
+       struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
+       struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+       unsigned int mpidw0;
+
+       mpidw0 = pm8001_mr32(pm8001_ha->general_stat_tbl_addr, 0);
+       return sysfs_emit(buf, "%s\n", mpiStateText[mpidw0 & 0x0003]);
+}
+static DEVICE_ATTR_RO(ctl_mpi_state);
+
 struct device_attribute *pm8001_host_attrs[] = {
        &dev_attr_interface_rev,
        &dev_attr_controller_fatal_error,
@@ -905,6 +934,7 @@ struct device_attribute *pm8001_host_attrs[] = {
        &dev_attr_ob_log,
        &dev_attr_ila_version,
        &dev_attr_inc_fw_ver,
+       &dev_attr_ctl_mpi_state,
        NULL,
 };