提交 ef7830bb 编写于 作者: H Harish Zunjarrao 提交者: James Bottomley

[SCSI] qla4xxx: Code cleanup for read/update flash using BSG

- Corrected return status
- Added reset active check
- Removed unused dma_map_sg calls
- Added debug prints on failure
Signed-off-by: NHarish Zunjarrao <harish.zunjarrao@qlogic.com>
Signed-off-by: NVikas Chaudhary <vikas.chaudhary@qlogic.com>
Reviewed-by: NMike Christie <michaelc@cs.wisc.edu>
Signed-off-by: NJames Bottomley <JBottomley@Parallels.com>
上级 943c157b
...@@ -16,36 +16,31 @@ qla4xxx_read_flash(struct bsg_job *bsg_job) ...@@ -16,36 +16,31 @@ qla4xxx_read_flash(struct bsg_job *bsg_job)
struct scsi_qla_host *ha = to_qla_host(host); struct scsi_qla_host *ha = to_qla_host(host);
struct iscsi_bsg_reply *bsg_reply = bsg_job->reply; struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
struct iscsi_bsg_request *bsg_req = bsg_job->request; struct iscsi_bsg_request *bsg_req = bsg_job->request;
uint32_t sg_cnt;
uint32_t offset = 0; uint32_t offset = 0;
uint32_t length = 0; uint32_t length = 0;
dma_addr_t flash_dma; dma_addr_t flash_dma;
uint8_t *flash = NULL; uint8_t *flash = NULL;
int rval = 0; int rval = -EINVAL;
bsg_reply->reply_payload_rcv_len = 0; bsg_reply->reply_payload_rcv_len = 0;
if (unlikely(pci_channel_offline(ha->pdev))) if (unlikely(pci_channel_offline(ha->pdev)))
return -EINVAL; goto leave;
if (ha->flash_state != QLFLASH_WAITING) if (ql4xxx_reset_active(ha)) {
return -EBUSY; ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
rval = -EBUSY;
/* TODO: Add check for adapter online, reset active?? */ goto leave;
sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list, }
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
if (!sg_cnt)
return -ENOMEM;
if (sg_cnt != bsg_job->reply_payload.sg_cnt) { if (ha->flash_state != QLFLASH_WAITING) {
ql4_printk(KERN_ERR, ha, "dma mapping resulted in different" ql4_printk(KERN_ERR, ha, "%s: another flash operation "
" sg counts, sg_cnt: %x dma_sg_cnt: %x\n", "active\n", __func__);
bsg_job->reply_payload.sg_cnt, sg_cnt); rval = -EBUSY;
rval = -EAGAIN; goto leave;
goto unmap_sg;
} }
ha->flash_state = QLFLASH_READING;
offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1]; offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
length = bsg_job->reply_payload.payload_len; length = bsg_job->reply_payload.payload_len;
...@@ -55,31 +50,27 @@ qla4xxx_read_flash(struct bsg_job *bsg_job) ...@@ -55,31 +50,27 @@ qla4xxx_read_flash(struct bsg_job *bsg_job)
ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash " ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
"data\n", __func__); "data\n", __func__);
rval = -ENOMEM; rval = -ENOMEM;
goto unmap_sg; goto leave;
} }
ha->flash_state = QLFLASH_READING; rval = qla4xxx_get_flash(ha, flash_dma, offset, length);
if (qla4xxx_get_flash(ha, flash_dma, offset, length)) if (rval) {
bsg_reply->result = (DID_ERROR << 16); ql4_printk(KERN_ERR, ha, "%s: get flash failed\n", __func__);
else { bsg_reply->result = DID_ERROR << 16;
sg_copy_from_buffer(bsg_job->reply_payload.sg_list, rval = -EIO;
bsg_job->reply_payload.sg_cnt, } else {
flash, length); bsg_reply->reply_payload_rcv_len =
sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
bsg_reply->result = DID_OK; bsg_job->reply_payload.sg_cnt,
bsg_reply->reply_payload_rcv_len = length; flash, length);
bsg_reply->result = DID_OK << 16;
} }
if (flash) bsg_job_done(bsg_job, bsg_reply->result,
dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma); bsg_reply->reply_payload_rcv_len);
dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma);
leave:
ha->flash_state = QLFLASH_WAITING; ha->flash_state = QLFLASH_WAITING;
unmap_sg:
dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
if (!rval)
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return rval; return rval;
} }
...@@ -90,36 +81,32 @@ qla4xxx_update_flash(struct bsg_job *bsg_job) ...@@ -90,36 +81,32 @@ qla4xxx_update_flash(struct bsg_job *bsg_job)
struct scsi_qla_host *ha = to_qla_host(host); struct scsi_qla_host *ha = to_qla_host(host);
struct iscsi_bsg_reply *bsg_reply = bsg_job->reply; struct iscsi_bsg_reply *bsg_reply = bsg_job->reply;
struct iscsi_bsg_request *bsg_req = bsg_job->request; struct iscsi_bsg_request *bsg_req = bsg_job->request;
uint32_t sg_cnt;
uint32_t length = 0; uint32_t length = 0;
uint32_t offset = 0; uint32_t offset = 0;
uint32_t options = 0; uint32_t options = 0;
dma_addr_t flash_dma; dma_addr_t flash_dma;
uint8_t *flash = NULL; uint8_t *flash = NULL;
int rval = 0; int rval = -EINVAL;
bsg_reply->reply_payload_rcv_len = 0; bsg_reply->reply_payload_rcv_len = 0;
if (unlikely(pci_channel_offline(ha->pdev))) if (unlikely(pci_channel_offline(ha->pdev)))
return -EINVAL; goto leave;
if (ha->flash_state != QLFLASH_WAITING)
return -EBUSY;
sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, if (ql4xxx_reset_active(ha)) {
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); ql4_printk(KERN_ERR, ha, "%s: reset active\n", __func__);
rval = -EBUSY;
if (!sg_cnt) goto leave;
return -ENOMEM; }
if (sg_cnt != bsg_job->request_payload.sg_cnt) { if (ha->flash_state != QLFLASH_WAITING) {
ql4_printk(KERN_ERR, ha, "dma mapping resulted in different " ql4_printk(KERN_ERR, ha, "%s: another flash operation "
"sg counts request_sg_cnt: %x dma_request_sg_cnt: " "active\n", __func__);
"%x\n", bsg_job->request_payload.sg_cnt, sg_cnt); rval = -EBUSY;
rval = -EAGAIN; goto leave;
goto unmap_sg;
} }
ha->flash_state = QLFLASH_WRITING;
length = bsg_job->request_payload.payload_len; length = bsg_job->request_payload.payload_len;
offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1]; offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
options = bsg_req->rqst_data.h_vendor.vendor_cmd[2]; options = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
...@@ -130,30 +117,25 @@ qla4xxx_update_flash(struct bsg_job *bsg_job) ...@@ -130,30 +117,25 @@ qla4xxx_update_flash(struct bsg_job *bsg_job)
ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash " ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash "
"data\n", __func__); "data\n", __func__);
rval = -ENOMEM; rval = -ENOMEM;
goto unmap_sg; goto leave;
} }
ha->flash_state = QLFLASH_WRITING;
sg_copy_to_buffer(bsg_job->request_payload.sg_list, sg_copy_to_buffer(bsg_job->request_payload.sg_list,
bsg_job->request_payload.sg_cnt, flash, length); bsg_job->request_payload.sg_cnt, flash, length);
if (qla4xxx_set_flash(ha, flash_dma, offset, length, options)) rval = qla4xxx_set_flash(ha, flash_dma, offset, length, options);
bsg_reply->result = (DID_ERROR << 16); if (rval) {
else { ql4_printk(KERN_ERR, ha, "%s: set flash failed\n", __func__);
bsg_reply->result = DID_OK; bsg_reply->result = DID_ERROR << 16;
bsg_reply->reply_payload_rcv_len = length; rval = -EIO;
} } else
bsg_reply->result = DID_OK << 16;
if (flash)
dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma); bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma);
leave:
ha->flash_state = QLFLASH_WAITING; ha->flash_state = QLFLASH_WAITING;
unmap_sg:
dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
bsg_job->reply_payload.sg_cnt, DMA_TO_DEVICE);
if (!rval)
bsg_job_done(bsg_job, bsg_reply->result,
bsg_reply->reply_payload_rcv_len);
return rval; return rval;
} }
......
...@@ -803,6 +803,16 @@ static inline void ql4xxx_unlock_drvr(struct scsi_qla_host *a) ...@@ -803,6 +803,16 @@ static inline void ql4xxx_unlock_drvr(struct scsi_qla_host *a)
ql4xxx_sem_unlock(a, QL4022_DRVR_SEM_MASK); ql4xxx_sem_unlock(a, QL4022_DRVR_SEM_MASK);
} }
static inline int ql4xxx_reset_active(struct scsi_qla_host *ha)
{
return test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
}
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Defines for qla4xxx_initialize_adapter() and qla4xxx_recover_adapter() */ /* Defines for qla4xxx_initialize_adapter() and qla4xxx_recover_adapter() */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册