Commit 31fe47d4 authored by FUJITA Tomonori's avatar FUJITA Tomonori Committed by James Bottomley

[SCSI] stex: use sg buffer copy helper functions

This replaces stex_internal_copy with scsi_sg_copy_to/from_buffer.
Signed-off-by: default avatarFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Acked-by: default avatarEd Lin <ed.lin@promise.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
parent d4345028
...@@ -426,49 +426,13 @@ static int stex_map_sg(struct st_hba *hba, ...@@ -426,49 +426,13 @@ static int stex_map_sg(struct st_hba *hba,
return 0; return 0;
} }
static void stex_internal_copy(struct scsi_cmnd *cmd,
const void *src, size_t *count, int sg_count, int direction)
{
size_t lcount;
size_t len;
void *s, *d, *base = NULL;
size_t offset;
if (*count > scsi_bufflen(cmd))
*count = scsi_bufflen(cmd);
lcount = *count;
while (lcount) {
len = lcount;
s = (void *)src;
offset = *count - lcount;
s += offset;
base = scsi_kmap_atomic_sg(scsi_sglist(cmd),
sg_count, &offset, &len);
if (!base) {
*count -= lcount;
return;
}
d = base + offset;
if (direction == ST_TO_CMD)
memcpy(d, s, len);
else
memcpy(s, d, len);
lcount -= len;
scsi_kunmap_atomic_sg(base);
}
}
static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb) static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb)
{ {
struct st_frame *p; struct st_frame *p;
size_t count = sizeof(struct st_frame); size_t count = sizeof(struct st_frame);
p = hba->copy_buffer; p = hba->copy_buffer;
stex_internal_copy(ccb->cmd, p, &count, scsi_sg_count(ccb->cmd), count = scsi_sg_copy_to_buffer(ccb->cmd, p, count);
ST_FROM_CMD);
memset(p->base, 0, sizeof(u32)*6); memset(p->base, 0, sizeof(u32)*6);
*(unsigned long *)(p->base) = pci_resource_start(hba->pdev, 0); *(unsigned long *)(p->base) = pci_resource_start(hba->pdev, 0);
p->rom_addr = 0; p->rom_addr = 0;
...@@ -486,8 +450,7 @@ static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb) ...@@ -486,8 +450,7 @@ static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb)
p->subid = p->subid =
hba->pdev->subsystem_vendor << 16 | hba->pdev->subsystem_device; hba->pdev->subsystem_vendor << 16 | hba->pdev->subsystem_device;
stex_internal_copy(ccb->cmd, p, &count, scsi_sg_count(ccb->cmd), count = scsi_sg_copy_from_buffer(ccb->cmd, p, count);
ST_TO_CMD);
} }
static void static void
...@@ -554,10 +517,8 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *)) ...@@ -554,10 +517,8 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
unsigned char page; unsigned char page;
page = cmd->cmnd[2] & 0x3f; page = cmd->cmnd[2] & 0x3f;
if (page == 0x8 || page == 0x3f) { if (page == 0x8 || page == 0x3f) {
size_t cp_len = sizeof(ms10_caching_page); scsi_sg_copy_from_buffer(cmd, ms10_caching_page,
stex_internal_copy(cmd, ms10_caching_page, sizeof(ms10_caching_page));
&cp_len, scsi_sg_count(cmd),
ST_TO_CMD);
cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
done(cmd); done(cmd);
} else } else
...@@ -586,10 +547,8 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *)) ...@@ -586,10 +547,8 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
if (id != host->max_id - 1) if (id != host->max_id - 1)
break; break;
if (lun == 0 && (cmd->cmnd[1] & INQUIRY_EVPD) == 0) { if (lun == 0 && (cmd->cmnd[1] & INQUIRY_EVPD) == 0) {
size_t cp_len = sizeof(console_inq_page); scsi_sg_copy_from_buffer(cmd, (void *)console_inq_page,
stex_internal_copy(cmd, console_inq_page, sizeof(console_inq_page));
&cp_len, scsi_sg_count(cmd),
ST_TO_CMD);
cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
done(cmd); done(cmd);
} else } else
...@@ -606,8 +565,7 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *)) ...@@ -606,8 +565,7 @@ stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
ver.signature[0] = PASSTHRU_SIGNATURE; ver.signature[0] = PASSTHRU_SIGNATURE;
ver.console_id = host->max_id - 1; ver.console_id = host->max_id - 1;
ver.host_no = hba->host->host_no; ver.host_no = hba->host->host_no;
stex_internal_copy(cmd, &ver, &cp_len, cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len);
scsi_sg_count(cmd), ST_TO_CMD);
cmd->result = sizeof(ver) == cp_len ? cmd->result = sizeof(ver) == cp_len ?
DID_OK << 16 | COMMAND_COMPLETE << 8 : DID_OK << 16 | COMMAND_COMPLETE << 8 :
DID_ERROR << 16 | COMMAND_COMPLETE << 8; DID_ERROR << 16 | COMMAND_COMPLETE << 8;
...@@ -700,15 +658,12 @@ static void stex_copy_data(struct st_ccb *ccb, ...@@ -700,15 +658,12 @@ static void stex_copy_data(struct st_ccb *ccb,
if (ccb->cmd == NULL) if (ccb->cmd == NULL)
return; return;
stex_internal_copy(ccb->cmd, count = scsi_sg_copy_from_buffer(ccb->cmd, resp->variable, count);
resp->variable, &count, scsi_sg_count(ccb->cmd), ST_TO_CMD);
} }
static void stex_ys_commands(struct st_hba *hba, static void stex_ys_commands(struct st_hba *hba,
struct st_ccb *ccb, struct status_msg *resp) struct st_ccb *ccb, struct status_msg *resp)
{ {
size_t count;
if (ccb->cmd->cmnd[0] == MGT_CMD && if (ccb->cmd->cmnd[0] == MGT_CMD &&
resp->scsi_status != SAM_STAT_CHECK_CONDITION) { resp->scsi_status != SAM_STAT_CHECK_CONDITION) {
scsi_set_resid(ccb->cmd, scsi_bufflen(ccb->cmd) - scsi_set_resid(ccb->cmd, scsi_bufflen(ccb->cmd) -
...@@ -724,9 +679,8 @@ static void stex_ys_commands(struct st_hba *hba, ...@@ -724,9 +679,8 @@ static void stex_ys_commands(struct st_hba *hba,
resp->scsi_status == SAM_STAT_GOOD) { resp->scsi_status == SAM_STAT_GOOD) {
ST_INQ *inq_data; ST_INQ *inq_data;
count = STEX_EXTRA_SIZE; scsi_sg_copy_to_buffer(ccb->cmd, hba->copy_buffer,
stex_internal_copy(ccb->cmd, hba->copy_buffer, STEX_EXTRA_SIZE);
&count, scsi_sg_count(ccb->cmd), ST_FROM_CMD);
inq_data = (ST_INQ *)hba->copy_buffer; inq_data = (ST_INQ *)hba->copy_buffer;
if (inq_data->DeviceTypeQualifier != 0) if (inq_data->DeviceTypeQualifier != 0)
ccb->srb_status = SRB_STATUS_SELECTION_TIMEOUT; ccb->srb_status = SRB_STATUS_SELECTION_TIMEOUT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment