-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds bsg support to qla4xxx. Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com> Signed-off-by: Harish Zunjarrao <harish.zunjarrao@qlogic.com> Signed-off-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
- Loading branch information
Vikas Chaudhary
authored and
James Bottomley
committed
Aug 27, 2011
1 parent
90eeb01
commit a355943
Showing
6 changed files
with
238 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
qla4xxx-y := ql4_os.o ql4_init.o ql4_mbx.o ql4_iocb.o ql4_isr.o \ | ||
ql4_nx.o ql4_nvram.o ql4_dbg.o ql4_attr.o | ||
ql4_nx.o ql4_nvram.o ql4_dbg.o ql4_attr.o ql4_bsg.o | ||
|
||
obj-$(CONFIG_SCSI_QLA_ISCSI) += qla4xxx.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
/* | ||
* QLogic iSCSI HBA Driver | ||
* Copyright (c) 2011 QLogic Corporation | ||
* | ||
* See LICENSE.qla4xxx for copyright and licensing details. | ||
*/ | ||
|
||
#include "ql4_def.h" | ||
#include "ql4_glbl.h" | ||
#include "ql4_bsg.h" | ||
|
||
static int | ||
qla4xxx_read_flash(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_reply *bsg_reply = bsg_job->reply; | ||
struct iscsi_bsg_request *bsg_req = bsg_job->request; | ||
uint32_t sg_cnt; | ||
uint32_t offset = 0; | ||
uint32_t length = 0; | ||
dma_addr_t flash_dma; | ||
uint8_t *flash = NULL; | ||
int rval = 0; | ||
|
||
bsg_reply->reply_payload_rcv_len = 0; | ||
|
||
if (unlikely(pci_channel_offline(ha->pdev))) | ||
return -EINVAL; | ||
|
||
if (ha->flash_state != QLFLASH_WAITING) | ||
return -EBUSY; | ||
|
||
/* TODO: Add check for adapter online, reset active?? */ | ||
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) { | ||
ql4_printk(KERN_ERR, ha, "dma mapping resulted in different" | ||
" sg counts, sg_cnt: %x dma_sg_cnt: %x\n", | ||
bsg_job->reply_payload.sg_cnt, sg_cnt); | ||
rval = -EAGAIN; | ||
goto unmap_sg; | ||
} | ||
|
||
offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1]; | ||
length = bsg_job->reply_payload.payload_len; | ||
|
||
flash = dma_alloc_coherent(&ha->pdev->dev, length, &flash_dma, | ||
GFP_KERNEL); | ||
if (!flash) { | ||
ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash " | ||
"data\n", __func__); | ||
rval = -ENOMEM; | ||
goto unmap_sg; | ||
} | ||
|
||
ha->flash_state = QLFLASH_READING; | ||
if (qla4xxx_get_flash(ha, flash_dma, offset, length)) | ||
bsg_reply->result = (DID_ERROR << 16); | ||
else { | ||
sg_copy_from_buffer(bsg_job->reply_payload.sg_list, | ||
bsg_job->reply_payload.sg_cnt, | ||
flash, length); | ||
|
||
bsg_reply->result = DID_OK; | ||
bsg_reply->reply_payload_rcv_len = length; | ||
} | ||
|
||
if (flash) | ||
dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma); | ||
|
||
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; | ||
} | ||
|
||
static int | ||
qla4xxx_update_flash(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_reply *bsg_reply = bsg_job->reply; | ||
struct iscsi_bsg_request *bsg_req = bsg_job->request; | ||
uint32_t sg_cnt; | ||
uint32_t length = 0; | ||
uint32_t offset = 0; | ||
uint32_t options = 0; | ||
dma_addr_t flash_dma; | ||
uint8_t *flash = NULL; | ||
int rval = 0; | ||
|
||
bsg_reply->reply_payload_rcv_len = 0; | ||
|
||
if (unlikely(pci_channel_offline(ha->pdev))) | ||
return -EINVAL; | ||
|
||
if (ha->flash_state != QLFLASH_WAITING) | ||
return -EBUSY; | ||
|
||
sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list, | ||
bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE); | ||
|
||
if (!sg_cnt) | ||
return -ENOMEM; | ||
|
||
if (sg_cnt != bsg_job->request_payload.sg_cnt) { | ||
ql4_printk(KERN_ERR, ha, "dma mapping resulted in different " | ||
"sg counts request_sg_cnt: %x dma_request_sg_cnt: " | ||
"%x\n", bsg_job->request_payload.sg_cnt, sg_cnt); | ||
rval = -EAGAIN; | ||
goto unmap_sg; | ||
} | ||
|
||
length = bsg_job->request_payload.payload_len; | ||
offset = bsg_req->rqst_data.h_vendor.vendor_cmd[1]; | ||
options = bsg_req->rqst_data.h_vendor.vendor_cmd[2]; | ||
|
||
flash = dma_alloc_coherent(&ha->pdev->dev, length, &flash_dma, | ||
GFP_KERNEL); | ||
if (!flash) { | ||
ql4_printk(KERN_ERR, ha, "%s: dma alloc failed for flash " | ||
"data\n", __func__); | ||
rval = -ENOMEM; | ||
goto unmap_sg; | ||
} | ||
|
||
ha->flash_state = QLFLASH_WRITING; | ||
sg_copy_to_buffer(bsg_job->request_payload.sg_list, | ||
bsg_job->request_payload.sg_cnt, flash, length); | ||
|
||
if (qla4xxx_set_flash(ha, flash_dma, offset, length, options)) | ||
bsg_reply->result = (DID_ERROR << 16); | ||
else { | ||
bsg_reply->result = DID_OK; | ||
bsg_reply->reply_payload_rcv_len = length; | ||
} | ||
|
||
if (flash) | ||
dma_free_coherent(&ha->pdev->dev, length, flash, flash_dma); | ||
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; | ||
} | ||
|
||
/** | ||
* qla4xxx_process_vendor_specific - handle vendor specific bsg request | ||
* @job: iscsi_bsg_job to handle | ||
**/ | ||
int qla4xxx_process_vendor_specific(struct bsg_job *bsg_job) | ||
{ | ||
struct iscsi_bsg_reply *bsg_reply = bsg_job->reply; | ||
struct iscsi_bsg_request *bsg_req = bsg_job->request; | ||
struct Scsi_Host *host = iscsi_job_to_shost(bsg_job); | ||
struct scsi_qla_host *ha = to_qla_host(host); | ||
|
||
switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) { | ||
case QLISCSI_VND_READ_FLASH: | ||
return qla4xxx_read_flash(bsg_job); | ||
|
||
case QLISCSI_VND_UPDATE_FLASH: | ||
return qla4xxx_update_flash(bsg_job); | ||
|
||
default: | ||
ql4_printk(KERN_ERR, ha, "%s: invalid BSG vendor command: " | ||
"0x%x\n", __func__, bsg_req->msgcode); | ||
bsg_reply->result = (DID_ERROR << 16); | ||
bsg_reply->reply_payload_rcv_len = 0; | ||
bsg_job_done(bsg_job, bsg_reply->result, | ||
bsg_reply->reply_payload_rcv_len); | ||
return -ENOSYS; | ||
} | ||
} | ||
|
||
/** | ||
* qla4xxx_bsg_request - handle bsg request from ISCSI transport | ||
* @job: iscsi_bsg_job to handle | ||
*/ | ||
int qla4xxx_bsg_request(struct bsg_job *bsg_job) | ||
{ | ||
struct iscsi_bsg_request *bsg_req = bsg_job->request; | ||
struct Scsi_Host *host = iscsi_job_to_shost(bsg_job); | ||
struct scsi_qla_host *ha = to_qla_host(host); | ||
|
||
switch (bsg_req->msgcode) { | ||
case ISCSI_BSG_HST_VENDOR: | ||
return qla4xxx_process_vendor_specific(bsg_job); | ||
|
||
default: | ||
ql4_printk(KERN_ERR, ha, "%s: invalid BSG command: 0x%x\n", | ||
__func__, bsg_req->msgcode); | ||
} | ||
|
||
return -ENOSYS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* QLogic iSCSI HBA Driver | ||
* Copyright (c) 2011 QLogic Corporation | ||
* | ||
* See LICENSE.qla4xxx for copyright and licensing details. | ||
*/ | ||
#ifndef __QL4_BSG_H | ||
#define __QL4_BSG_H | ||
|
||
/* BSG Vendor specific commands */ | ||
#define QLISCSI_VND_READ_FLASH 1 | ||
#define QLISCSI_VND_UPDATE_FLASH 2 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters