Skip to content

Commit

Permalink
[SCSI] sym53c8xx: convert to use the data buffer accessors
Browse files Browse the repository at this point in the history
- remove the unnecessary map_single path.

- convert to use the new accessors for the sg lists and the
parameters.

Jens Axboe <jens.axboe@oracle.com> did the for_each_sg cleanup.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Matthew Wilcox <matthew@wil.cx>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
  • Loading branch information
FUJITA Tomonori authored and James Bottomley committed Jul 15, 2007
1 parent cebadc5 commit 938febd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 73 deletions.
83 changes: 11 additions & 72 deletions drivers/scsi/sym53c8xx_2/sym_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,41 +146,17 @@ struct sym_ucmd { /* Override the SCSI pointer structure */

static void __unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
{
int dma_dir = cmd->sc_data_direction;
if (SYM_UCMD_PTR(cmd)->data_mapped)
scsi_dma_unmap(cmd);

switch(SYM_UCMD_PTR(cmd)->data_mapped) {
case 2:
pci_unmap_sg(pdev, cmd->request_buffer, cmd->use_sg, dma_dir);
break;
case 1:
pci_unmap_single(pdev, SYM_UCMD_PTR(cmd)->data_mapping,
cmd->request_bufflen, dma_dir);
break;
}
SYM_UCMD_PTR(cmd)->data_mapped = 0;
}

static dma_addr_t __map_scsi_single_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
{
dma_addr_t mapping;
int dma_dir = cmd->sc_data_direction;

mapping = pci_map_single(pdev, cmd->request_buffer,
cmd->request_bufflen, dma_dir);
if (mapping) {
SYM_UCMD_PTR(cmd)->data_mapped = 1;
SYM_UCMD_PTR(cmd)->data_mapping = mapping;
}

return mapping;
}

static int __map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
{
int use_sg;
int dma_dir = cmd->sc_data_direction;

use_sg = pci_map_sg(pdev, cmd->request_buffer, cmd->use_sg, dma_dir);
use_sg = scsi_dma_map(cmd);
if (use_sg > 0) {
SYM_UCMD_PTR(cmd)->data_mapped = 2;
SYM_UCMD_PTR(cmd)->data_mapping = use_sg;
Expand All @@ -191,8 +167,6 @@ static int __map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)

#define unmap_scsi_data(np, cmd) \
__unmap_scsi_data(np->s.device, cmd)
#define map_scsi_single_data(np, cmd) \
__map_scsi_single_data(np->s.device, cmd)
#define map_scsi_sg_data(np, cmd) \
__map_scsi_sg_data(np->s.device, cmd)
/*
Expand Down Expand Up @@ -322,55 +296,20 @@ void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
*/
cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
}
cmd->resid = resid;
scsi_set_resid(cmd, resid);
cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
}


/*
* Build the scatter/gather array for an I/O.
*/

static int sym_scatter_no_sglist(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
{
struct sym_tblmove *data = &cp->phys.data[SYM_CONF_MAX_SG-1];
int segment;
unsigned int len = cmd->request_bufflen;

if (len) {
dma_addr_t baddr = map_scsi_single_data(np, cmd);
if (baddr) {
if (len & 1) {
struct sym_tcb *tp = &np->target[cp->target];
if (tp->head.wval & EWS) {
len++;
cp->odd_byte_adjustment++;
}
}
cp->data_len = len;
sym_build_sge(np, data, baddr, len);
segment = 1;
} else {
segment = -2;
}
} else {
segment = 0;
}

return segment;
}

static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
{
int segment;
int use_sg = (int) cmd->use_sg;
int use_sg;

cp->data_len = 0;

if (!use_sg)
segment = sym_scatter_no_sglist(np, cp, cmd);
else if ((use_sg = map_scsi_sg_data(np, cmd)) > 0) {
struct scatterlist *scatter = (struct scatterlist *)cmd->request_buffer;
use_sg = map_scsi_sg_data(np, cmd);
if (use_sg > 0) {
struct scatterlist *sg;
struct sym_tcb *tp = &np->target[cp->target];
struct sym_tblmove *data;

Expand All @@ -381,9 +320,9 @@ static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd

data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];

for (segment = 0; segment < use_sg; segment++) {
dma_addr_t baddr = sg_dma_address(&scatter[segment]);
unsigned int len = sg_dma_len(&scatter[segment]);
scsi_for_each_sg(cmd, sg, use_sg, segment) {
dma_addr_t baddr = sg_dma_address(sg);
unsigned int len = sg_dma_len(sg);

if ((len & 1) && (tp->head.wval & EWS)) {
len++;
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/sym53c8xx_2/sym_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ sym_get_cam_status(struct scsi_cmnd *cmd)
*/
static __inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd *cmd, int resid)
{
cmd->resid = resid;
scsi_set_resid(cmd, resid);
cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
}
void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
Expand Down

0 comments on commit 938febd

Please sign in to comment.