[SCSI] qla4xxx: Added Get ACB support using BSG
authorHarish Zunjarrao <harish.zunjarrao@qlogic.com>
Fri, 12 Aug 2011 09:51:27 +0000 (02:51 -0700)
committerJames Bottomley <JBottomley@Parallels.com>
Sat, 27 Aug 2011 14:36:44 +0000 (08:36 -0600)
This command is used to read ACB params from firmware

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_glbl.h
drivers/scsi/qla4xxx/ql4_mbx.c

index 4704a52eaecd3fe3fb5e8dd58304cc2d21ef4087..8acdc582ff6d97fc6a56e5a898158c8bbd5634a2 100644 (file)
@@ -381,6 +381,71 @@ leave:
        return rval;
 }
 
+static int
+qla4xxx_bsg_get_acb(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 acb_type = 0;
+       uint32_t len = 0;
+       dma_addr_t acb_dma;
+       uint8_t *acb = NULL;
+       int rval = -EINVAL;
+
+       bsg_reply->reply_payload_rcv_len = 0;
+
+       if (unlikely(pci_channel_offline(ha->pdev)))
+               goto leave;
+
+       /* Only 4022 and above adapters are supported */
+       if (is_qla4010(ha))
+               goto leave;
+
+       if (ql4xxx_reset_active(ha)) {
+               ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
+               rval = -EBUSY;
+               goto leave;
+       }
+
+       acb_type = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
+       len = bsg_job->reply_payload.payload_len;
+       if (len < sizeof(struct addr_ctrl_blk)) {
+               ql4_printk(KERN_ERR, ha, "%s: invalid acb len %d\n",
+                          __func__, len);
+               rval = -EINVAL;
+               goto leave;
+       }
+
+       acb = dma_alloc_coherent(&ha->pdev->dev, len, &acb_dma, GFP_KERNEL);
+       if (!acb) {
+               ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for acb "
+                          "data\n", __func__);
+               rval = -ENOMEM;
+               goto leave;
+       }
+
+       rval = qla4xxx_get_acb(ha, acb_dma, acb_type, len);
+       if (rval) {
+               ql4_printk(KERN_ERR, ha, "%s: get acb 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,
+                                           acb, 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, acb, acb_dma);
+leave:
+       return rval;
+}
+
 /**
  * qla4xxx_process_vendor_specific - handle vendor specific bsg request
  * @job: iscsi_bsg_job to handle
@@ -411,6 +476,9 @@ int qla4xxx_process_vendor_specific(struct bsg_job *bsg_job)
        case QLISCSI_VND_RESTORE_DEFAULTS:
                return qla4xxx_restore_defaults(bsg_job);
 
+       case QLISCSI_VND_GET_ACB:
+               return qla4xxx_bsg_get_acb(bsg_job);
+
        default:
                ql4_printk(KERN_ERR, ha, "%s: invalid BSG vendor command: "
                           "0x%x\n", __func__, bsg_req->msgcode);
index 84a1391f9865203bc59d861b2095946567dd2d42..c6a0364509fda21c2d183fe5f06eb1511d44ecf6 100644 (file)
@@ -14,5 +14,6 @@
 #define QLISCSI_VND_READ_NVRAM         4
 #define QLISCSI_VND_UPDATE_NVRAM       5
 #define QLISCSI_VND_RESTORE_DEFAULTS   6
+#define QLISCSI_VND_GET_ACB            7
 
 #endif
index 1a0f60187ad647656871b68afccb375c91442596..160db9d5ea2101e8ccb2ef4772c81429747a4b0d 100644 (file)
@@ -56,8 +56,8 @@ int qla4xxx_conn_close_sess_logout(struct scsi_qla_host *ha,
 int qla4xxx_disable_acb(struct scsi_qla_host *ha);
 int qla4xxx_set_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
                    uint32_t *mbox_sts, dma_addr_t acb_dma);
-int qla4xxx_get_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
-                   uint32_t *mbox_sts, dma_addr_t acb_dma);
+int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
+                   uint32_t acb_type, uint32_t len);
 int qla4xxx_get_ip_state(struct scsi_qla_host *ha, uint32_t acb_idx,
                         uint32_t ip_idx, uint32_t *sts);
 void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session);
index dfc38aa8740d12dfb2b19a8b298507bbcd1dc94e..de733a77780342e5c4e523d34d6435f5d61c1d12 100644 (file)
@@ -1425,18 +1425,21 @@ int qla4xxx_disable_acb(struct scsi_qla_host *ha)
        return status;
 }
 
-int qla4xxx_get_acb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
-                   uint32_t *mbox_sts, dma_addr_t acb_dma)
+int qla4xxx_get_acb(struct scsi_qla_host *ha, dma_addr_t acb_dma,
+                   uint32_t acb_type, uint32_t len)
 {
+       uint32_t mbox_cmd[MBOX_REG_COUNT];
+       uint32_t mbox_sts[MBOX_REG_COUNT];
        int status = QLA_SUCCESS;
 
-       memset(mbox_cmd, 0, sizeof(mbox_cmd[0]) * MBOX_REG_COUNT);
-       memset(mbox_sts, 0, sizeof(mbox_sts[0]) * MBOX_REG_COUNT);
+       memset(&mbox_cmd, 0, sizeof(mbox_cmd));
+       memset(&mbox_sts, 0, sizeof(mbox_sts));
+
        mbox_cmd[0] = MBOX_CMD_GET_ACB;
-       mbox_cmd[1] = 0; /* Primary ACB */
+       mbox_cmd[1] = acb_type;
        mbox_cmd[2] = LSDW(acb_dma);
        mbox_cmd[3] = MSDW(acb_dma);
-       mbox_cmd[4] = sizeof(struct addr_ctrl_blk);
+       mbox_cmd[4] = len;
 
        status = qla4xxx_mailbox_command(ha, 5, 5, &mbox_cmd[0], &mbox_sts[0]);
        if (status != QLA_SUCCESS) {