[SCSI] qla2xxx: Export XGMAC statistics on supported ISPs.
authorAndrew Vasquez <andrew.vasquez@qlogic.com>
Wed, 3 Jun 2009 16:55:13 +0000 (09:55 -0700)
committerJames Bottomley <James.Bottomley@HansenPartnership.com>
Mon, 8 Jun 2009 19:46:34 +0000 (14:46 -0500)
Signed-off-by: Andrew Vasquez <andrew.vasquez@qlogic.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
drivers/scsi/qla2xxx/qla_attr.c
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_fw.h
drivers/scsi/qla2xxx/qla_gbl.h
drivers/scsi/qla2xxx/qla_mbx.c
drivers/scsi/qla2xxx/qla_os.c

index 524ceb9b9288cacd1719d6f60e5e81bd4ddedc7b..e8c1c9e01a7b9de695dfe6b17936c00e805cfc55 100644 (file)
@@ -692,6 +692,58 @@ static struct bin_attribute sysfs_edc_status_attr = {
        .read = qla2x00_sysfs_read_edc_status,
 };
 
+static ssize_t
+qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
+                      struct bin_attribute *bin_attr,
+                      char *buf, loff_t off, size_t count)
+{
+       struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
+           struct device, kobj)));
+       struct qla_hw_data *ha = vha->hw;
+       int rval;
+       uint16_t actual_size;
+
+       if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
+               return 0;
+
+       if (ha->xgmac_data)
+               goto do_read;
+
+       ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
+           &ha->xgmac_data_dma, GFP_KERNEL);
+       if (!ha->xgmac_data) {
+               qla_printk(KERN_WARNING, ha,
+                   "Unable to allocate memory for XGMAC read-data.\n");
+               return 0;
+       }
+
+do_read:
+       actual_size = 0;
+       memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
+
+       rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
+           XGMAC_DATA_SIZE, &actual_size);
+       if (rval != QLA_SUCCESS) {
+               qla_printk(KERN_WARNING, ha,
+                   "Unable to read XGMAC data (%x).\n", rval);
+               count = 0;
+       }
+
+       count = actual_size > count ? count: actual_size;
+       memcpy(buf, ha->xgmac_data, count);
+
+       return count;
+}
+
+static struct bin_attribute sysfs_xgmac_stats_attr = {
+       .attr = {
+               .name = "xgmac_stats",
+               .mode = S_IRUSR,
+       },
+       .size = 0,
+       .read = qla2x00_sysfs_read_xgmac_stats,
+};
+
 static struct sysfs_entry {
        char *name;
        struct bin_attribute *attr;
@@ -706,6 +758,7 @@ static struct sysfs_entry {
        { "reset", &sysfs_reset_attr, },
        { "edc", &sysfs_edc_attr, 2 },
        { "edc_status", &sysfs_edc_status_attr, 2 },
+       { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
        { NULL },
 };
 
@@ -721,6 +774,8 @@ qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
                        continue;
                if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
                        continue;
+               if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
+                       continue;
 
                ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
                    iter->attr);
@@ -743,6 +798,8 @@ qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
                        continue;
                if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
                        continue;
+               if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
+                       continue;
 
                sysfs_remove_bin_file(&host->shost_gendev.kobj,
                    iter->attr);
index 721bae94e4371004382cef90880b76602685a5c0..da941be9b1821734b59cfe243f9288d20772d029 100644 (file)
@@ -2397,6 +2397,10 @@ struct qla_hw_data {
        dma_addr_t      edc_data_dma;
        uint16_t        edc_data_len;
 
+#define XGMAC_DATA_SIZE        PAGE_SIZE
+       void            *xgmac_data;
+       dma_addr_t      xgmac_data_dma;
+
        struct task_struct      *dpc_thread;
        uint8_t dpc_active;                  /* DPC routine is active */
 
index f389f3da0baba3ed67b2910eb1bacbc8ae0e568d..80ab46cfaca6c18d792662511124111ab655b50e 100644 (file)
@@ -1405,6 +1405,7 @@ struct access_chip_rsp_84xx {
 #define MBC_IDC_ACK            0x101
 #define MBC_RESTART_MPI_FW     0x3d
 #define MBC_FLASH_ACCESS_CTRL  0x3e    /* Control flash access. */
+#define MBC_GET_XGMAC_STATS    0x7a
 
 /* Flash access control option field bit definitions */
 #define FAC_OPT_FORCE_SEMAPHORE                BIT_15
index f17d525897a0b240399866ee08b6f33535514b3e..66ba3997c91ceb977aa44f32027efa07939fd321 100644 (file)
@@ -293,6 +293,9 @@ qla81xx_fac_do_write_enable(scsi_qla_host_t *, int);
 extern int
 qla81xx_fac_erase_sector(scsi_qla_host_t *, uint32_t, uint32_t);
 
+extern int
+qla2x00_get_xgmac_stats(scsi_qla_host_t *, dma_addr_t, uint16_t, uint16_t *);
+
 /*
  * Global Function Prototypes in qla_isr.c source file.
  */
index 7d0eeec9ba57a7f3894a4a431f6e62e74c7c2066..2497fe4ce5aa4fc82deaa2bab7af5652b0ed6a96 100644 (file)
@@ -3462,3 +3462,41 @@ qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
 
        return rval;
 }
+
+int
+qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
+    uint16_t size_in_bytes, uint16_t *actual_size)
+{
+       int rval;
+       mbx_cmd_t mc;
+       mbx_cmd_t *mcp = &mc;
+
+       if (!IS_QLA81XX(vha->hw))
+               return QLA_FUNCTION_FAILED;
+
+       DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
+
+       mcp->mb[0] = MBC_GET_XGMAC_STATS;
+       mcp->mb[2] = MSW(stats_dma);
+       mcp->mb[3] = LSW(stats_dma);
+       mcp->mb[6] = MSW(MSD(stats_dma));
+       mcp->mb[7] = LSW(MSD(stats_dma));
+       mcp->mb[8] = size_in_bytes >> 2;
+       mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
+       mcp->in_mb = MBX_2|MBX_1|MBX_0;
+       mcp->tov = MBX_TOV_SECONDS;
+       mcp->flags = 0;
+       rval = qla2x00_mailbox_command(vha, mcp);
+
+       if (rval != QLA_SUCCESS) {
+               DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
+                   "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
+                   mcp->mb[0], mcp->mb[1], mcp->mb[2]));
+       } else {
+               DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
+
+               *actual_size = mcp->mb[2] << 2;
+       }
+
+       return rval;
+}
index f4f5355369528a00499ab37b64fdbfa067388580..642e976083e81b93c4208221728c6715a1396525 100644 (file)
@@ -2434,6 +2434,10 @@ qla2x00_mem_free(struct qla_hw_data *ha)
                vfree(ha->fw_dump);
        }
 
+       if (ha->xgmac_data)
+               dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
+                   ha->xgmac_data, ha->xgmac_data_dma);
+
        if (ha->sns_cmd)
                dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
                ha->sns_cmd, ha->sns_cmd_dma);