[SCSI] qla4xxx: Add read/update NVRAM support for 40xx adapters using BSG
authorHarish Zunjarrao <harish.zunjarrao@qlogic.com>
Mon, 1 Aug 2011 10:26:16 +0000 (03:26 -0700)
committerJames Bottomley <JBottomley@Parallels.com>
Sat, 27 Aug 2011 14:36:33 +0000 (08:36 -0600)
Signed-off-by: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
Reviewed-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/qla4xxx/ql4_bsg.c
drivers/scsi/qla4xxx/ql4_bsg.h
drivers/scsi/qla4xxx/ql4_fw.h
drivers/scsi/qla4xxx/ql4_glbl.h
drivers/scsi/qla4xxx/ql4_mbx.c

index de4db299bfcbf51508c36a2cbfffdd0d77376069..c47545356f7b6645468794955260f39a66aa8f68 100644 (file)
@@ -196,6 +196,147 @@ leave:
        return rval;
 }
 
+static int
+qla4xxx_read_nvram(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       uint32_t offset = 0;
+       uint32_t len = 0;
+       uint32_t total_len = 0;
+       dma_addr_t nvram_dma;
+       uint8_t *nvram = NULL;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       /* Only 40xx adapters are supported */
+       if (!(is_qla4010(ha) || is_qla4022(ha) || is_qla4032(ha)))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       len = bsg_job->reply_payload.payload_len;
+       total_len = offset + len;
+
+       /* total len should not be greater than max NVRAM size */
+       if ((is_qla4010(ha) && total_len > QL4010_NVRAM_SIZE) ||
+           ((is_qla4022(ha) || is_qla4032(ha)) &&
+            total_len > QL40X2_NVRAM_SIZE)) {
+               ql4_printk(KERN_ERR, ha, "%s: offset+len greater than max"
+                          " nvram size, offset=%d len=%d\n",
+                          __func__, offset, len);
+               goto leave;
+       }
+
+       nvram = dma_alloc_coherent(&ha->pdev->dev, len, &nvram_dma,
+                                  GFP_KERNEL);
+       if (!nvram) {
+               ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for nvram "
+                          "data\n", __func__);
+               rval = -ENOMEM;
+               goto leave;
+       }
+
+       rval = qla4xxx_get_nvram(ha, nvram_dma, offset, len);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: get nvram failed\n", __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else {
+               bsg_reply->reply_payload_rcv_len =
+                       sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
+                                           bsg_job->reply_payload.sg_cnt,
+                                           nvram, len);
+               bsg_reply->result = DID_OK << 16;
+       }
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+       dma_free_coherent(&ha->pdev->dev, len, nvram, nvram_dma);
+leave:
+       return rval;
+}
+
+static int
+qla4xxx_update_nvram(struct bsg_job *bsg_job)
+{
+       struct Scsi_Host *host = iscsi_job_to_shost(bsg_job);
+       struct scsi_qla_host *ha = to_qla_host(host);
+       struct iscsi_bsg_request *bsg_req = bsg_job->request;
+       struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
+       uint32_t offset = 0;
+       uint32_t len = 0;
+       uint32_t total_len = 0;
+       dma_addr_t nvram_dma;
+       uint8_t *nvram = NULL;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       if (!(is_qla4010(ha) || is_qla4022(ha) || is_qla4032(ha)))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       len = bsg_job->request_payload.payload_len;
+       total_len = offset + len;
+
+       /* total len should not be greater than max NVRAM size */
+       if ((is_qla4010(ha) && total_len > QL4010_NVRAM_SIZE) ||
+           ((is_qla4022(ha) || is_qla4032(ha)) &&
+            total_len > QL40X2_NVRAM_SIZE)) {
+               ql4_printk(KERN_ERR, ha, "%s: offset+len greater than max"
+                          " nvram size, offset=%d len=%d\n",
+                          __func__, offset, len);
+               goto leave;
+       }
+
+       nvram = dma_alloc_coherent(&ha->pdev->dev, len, &nvram_dma,
+                                  GFP_KERNEL);
+       if (!nvram) {
+               ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
+                          "data\n", __func__);
+               rval = -ENOMEM;
+               goto leave;
+       }
+
+       sg_copy_to_buffer(bsg_job->request_payload.sg_list,
+                         bsg_job->request_payload.sg_cnt, nvram, len);
+
+       rval = qla4xxx_set_nvram(ha, nvram_dma, offset, len);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: set nvram failed\n", __func__);
+               bsg_reply->result = DID_ERROR << 16;
+               rval = -EIO;
+       } else
+               bsg_reply->result = DID_OK << 16;
+
+       bsg_job_done(bsg_job, bsg_reply->result,
+                    bsg_reply->reply_payload_rcv_len);
+       dma_free_coherent(&ha->pdev->dev, len, nvram, nvram_dma);
+leave:
+       return rval;
+}
+
 /**
  * qla4xxx_process_vendor_specific - handle vendor specific bsg request
  * @job: iscsi_bsg_job to handle
@@ -217,6 +358,12 @@ int qla4xxx_process_vendor_specific(struct bsg_job *bsg_job)
        case QLISCSI_VND_GET_ACB_STATE:
                return qla4xxx_get_acb_state(bsg_job);
 
+       case QLISCSI_VND_READ_NVRAM:
+               return qla4xxx_read_nvram(bsg_job);
+
+       case QLISCSI_VND_UPDATE_NVRAM:
+               return qla4xxx_update_nvram(bsg_job);
+
        default:
                ql4_printk(KERN_ERR, ha, "%s: invalid BSG vendor command: "
                           "0x%x\n", __func__, bsg_req->msgcode);
index 0400e1a0b6700b5c37a7637a282be9bc3e891fe4..71df80d612dac6be4fd8051e4a59598d406fa62c 100644 (file)
@@ -11,5 +11,7 @@
 #define QLISCSI_VND_READ_FLASH         1
 #define QLISCSI_VND_UPDATE_FLASH       2
 #define QLISCSI_VND_GET_ACB_STATE      3
+#define QLISCSI_VND_READ_NVRAM         4
+#define QLISCSI_VND_UPDATE_NVRAM       5
 
 #endif
index 9dc439b0d75f16c279805e4b3abca66905a60b93..581ff7e4621c106d0d8cc7c1d886ae33232b63df 100644 (file)
@@ -201,6 +201,9 @@ static inline uint32_t clr_rmask(uint32_t val)
 /* ISP 4022 nvram definitions */
 #define NVR_WRITE_ENABLE                       0x00000010      /* 4022 */
 
+#define QL4010_NVRAM_SIZE                      0x200
+#define QL40X2_NVRAM_SIZE                      0x800
+
 /*  ISP port_status definitions */
 
 /*  ISP Semaphore definitions */
@@ -359,6 +362,8 @@ struct qla_flt_region {
 #define MBOX_CMD_GET_FW_STATE                  0x0069
 #define MBOX_CMD_GET_INIT_FW_CTRL_BLOCK_DEFAULTS 0x006A
 #define MBOX_CMD_GET_SYS_INFO                  0x0078
+#define MBOX_CMD_GET_NVRAM                     0x0078  /* For 40xx */
+#define MBOX_CMD_SET_NVRAM                     0x0079  /* For 40xx */
 #define MBOX_CMD_RESTORE_FACTORY_DEFAULTS      0x0087
 #define MBOX_CMD_SET_ACB                       0x0088
 #define MBOX_CMD_GET_ACB                       0x0089
index 5c8769651666ff4c01c9f7130f49f243b5b55782..35bd0c1ede38bddf0a359442b9dc38f5182a138c 100644 (file)
@@ -162,6 +162,10 @@ int qla4xxx_bootdb_by_index(struct scsi_qla_host *ha,
                            dma_addr_t fw_ddb_entry_dma, uint16_t ddb_index);
 int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username,
                     char *password, uint16_t idx);
+int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
+                     uint32_t offset, uint32_t size);
+int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
+                     uint32_t offset, uint32_t size);
 
 /* BSG Functions */
 int qla4xxx_bsg_request(struct bsg_job *bsg_job);
index aec72309f60f205dba389519b429df87585789bd..011c822f5ff616c2afbcd917f8ac5422d739d0a3 100644 (file)
@@ -1690,3 +1690,55 @@ int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
        memcpy(sts, mbox_sts, sizeof(mbox_sts));
        return status;
 }
+
+int qla4xxx_get_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
+                     uint32_t offset, uint32_t size)
+{
+       int status = QLA_SUCCESS;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_GET_NVRAM;
+       mbox_cmd[1] = LSDW(nvram_dma);
+       mbox_cmd[2] = MSDW(nvram_dma);
+       mbox_cmd[3] = offset;
+       mbox_cmd[4] = size;
+
+       status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
+                                 "status %04X\n", ha->host_no, __func__,
+                                 mbox_sts[0]));
+       }
+       return status;
+}
+
+int qla4xxx_set_nvram(struct scsi_qla_host *ha, dma_addr_t nvram_dma,
+                     uint32_t offset, uint32_t size)
+{
+       int status = QLA_SUCCESS;
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
+
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
+       mbox_cmd[0] = MBOX_CMD_SET_NVRAM;
+       mbox_cmd[1] = LSDW(nvram_dma);
+       mbox_cmd[2] = MSDW(nvram_dma);
+       mbox_cmd[3] = offset;
+       mbox_cmd[4] = size;
+
+       status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
+                                        &mbox_sts[0]);
+       if (status != QLA_SUCCESS) {
+               DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
+                                 "status %04X\n", ha->host_no, __func__,
+                                 mbox_sts[0]));
+       }
+       return status;
+}