aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/aacraid/aachba.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-15 19:51:54 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-15 19:51:54 -0400
commitbc06cffdec85d487c77109dffcd2f285bdc502d3 (patch)
treeadc6e6398243da87e66c56102840597a329183a0 /drivers/scsi/aacraid/aachba.c
parentd3502d7f25b22cfc9762bf1781faa9db1bb3be2e (diff)
parent9413d7b8aa777dd1fc7db9563ce5e80d769fe7b5 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6: (166 commits) [SCSI] ibmvscsi: convert to use the data buffer accessors [SCSI] dc395x: convert to use the data buffer accessors [SCSI] ncr53c8xx: convert to use the data buffer accessors [SCSI] sym53c8xx: convert to use the data buffer accessors [SCSI] ppa: coding police and printk levels [SCSI] aic7xxx_old: remove redundant GFP_ATOMIC from kmalloc [SCSI] i2o: remove redundant GFP_ATOMIC from kmalloc from device.c [SCSI] remove the dead CYBERSTORMIII_SCSI option [SCSI] don't build scsi_dma_{map,unmap} for !HAS_DMA [SCSI] Clean up scsi_add_lun a bit [SCSI] 53c700: Remove printk, which triggers because of low scsi clock on SNI RMs [SCSI] sni_53c710: Cleanup [SCSI] qla4xxx: Fix underrun/overrun conditions [SCSI] megaraid_mbox: use mutex instead of semaphore [SCSI] aacraid: add 51245, 51645 and 52245 adapters to documentation. [SCSI] qla2xxx: update version to 8.02.00-k1. [SCSI] qla2xxx: add support for NPIV [SCSI] stex: use resid for xfer len information [SCSI] Add Brownie 1200U3P to blacklist [SCSI] scsi.c: convert to use the data buffer accessors ...
Diffstat (limited to 'drivers/scsi/aacraid/aachba.c')
-rw-r--r--drivers/scsi/aacraid/aachba.c322
1 files changed, 154 insertions, 168 deletions
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 8dcfe4ec35c2..0b6fd0b654d2 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -169,6 +169,18 @@ int acbsize = -1;
169module_param(acbsize, int, S_IRUGO|S_IWUSR); 169module_param(acbsize, int, S_IRUGO|S_IWUSR);
170MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware."); 170MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware.");
171 171
172int update_interval = 30 * 60;
173module_param(update_interval, int, S_IRUGO|S_IWUSR);
174MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync updates issued to adapter.");
175
176int check_interval = 24 * 60 * 60;
177module_param(check_interval, int, S_IRUGO|S_IWUSR);
178MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health checks.");
179
180int check_reset = 1;
181module_param(check_reset, int, S_IRUGO|S_IWUSR);
182MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the adapter.");
183
172int expose_physicals = -1; 184int expose_physicals = -1;
173module_param(expose_physicals, int, S_IRUGO|S_IWUSR); 185module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
174MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on"); 186MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
@@ -312,11 +324,10 @@ int aac_get_containers(struct aac_dev *dev)
312 324
313 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS) 325 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
314 maximum_num_containers = MAXIMUM_NUM_CONTAINERS; 326 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
315 fsa_dev_ptr = kmalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers, 327 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
316 GFP_KERNEL); 328 GFP_KERNEL);
317 if (!fsa_dev_ptr) 329 if (!fsa_dev_ptr)
318 return -ENOMEM; 330 return -ENOMEM;
319 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
320 331
321 dev->fsa_dev = fsa_dev_ptr; 332 dev->fsa_dev = fsa_dev_ptr;
322 dev->maximum_num_containers = maximum_num_containers; 333 dev->maximum_num_containers = maximum_num_containers;
@@ -344,21 +355,16 @@ static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigne
344{ 355{
345 void *buf; 356 void *buf;
346 int transfer_len; 357 int transfer_len;
347 struct scatterlist *sg = scsicmd->request_buffer; 358 struct scatterlist *sg = scsi_sglist(scsicmd);
359
360 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
361 transfer_len = min(sg->length, len + offset);
348 362
349 if (scsicmd->use_sg) {
350 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
351 transfer_len = min(sg->length, len + offset);
352 } else {
353 buf = scsicmd->request_buffer;
354 transfer_len = min(scsicmd->request_bufflen, len + offset);
355 }
356 transfer_len -= offset; 363 transfer_len -= offset;
357 if (buf && transfer_len > 0) 364 if (buf && transfer_len > 0)
358 memcpy(buf + offset, data, transfer_len); 365 memcpy(buf + offset, data, transfer_len);
359 366
360 if (scsicmd->use_sg) 367 kunmap_atomic(buf - sg->offset, KM_IRQ0);
361 kunmap_atomic(buf - sg->offset, KM_IRQ0);
362 368
363} 369}
364 370
@@ -451,7 +457,7 @@ static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
451{ 457{
452 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev; 458 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
453 459
454 if (fsa_dev_ptr[scmd_id(scsicmd)].valid) 460 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
455 return aac_scsi_cmd(scsicmd); 461 return aac_scsi_cmd(scsicmd);
456 462
457 scsicmd->result = DID_NO_CONNECT << 16; 463 scsicmd->result = DID_NO_CONNECT << 16;
@@ -459,18 +465,18 @@ static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
459 return 0; 465 return 0;
460} 466}
461 467
462static int _aac_probe_container2(void * context, struct fib * fibptr) 468static void _aac_probe_container2(void * context, struct fib * fibptr)
463{ 469{
464 struct fsa_dev_info *fsa_dev_ptr; 470 struct fsa_dev_info *fsa_dev_ptr;
465 int (*callback)(struct scsi_cmnd *); 471 int (*callback)(struct scsi_cmnd *);
466 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context; 472 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
467 473
468 if (!aac_valid_context(scsicmd, fibptr))
469 return 0;
470 474
471 fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev; 475 if (!aac_valid_context(scsicmd, fibptr))
476 return;
472 477
473 scsicmd->SCp.Status = 0; 478 scsicmd->SCp.Status = 0;
479 fsa_dev_ptr = fibptr->dev->fsa_dev;
474 if (fsa_dev_ptr) { 480 if (fsa_dev_ptr) {
475 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr); 481 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
476 fsa_dev_ptr += scmd_id(scsicmd); 482 fsa_dev_ptr += scmd_id(scsicmd);
@@ -493,10 +499,11 @@ static int _aac_probe_container2(void * context, struct fib * fibptr)
493 aac_fib_free(fibptr); 499 aac_fib_free(fibptr);
494 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr); 500 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
495 scsicmd->SCp.ptr = NULL; 501 scsicmd->SCp.ptr = NULL;
496 return (*callback)(scsicmd); 502 (*callback)(scsicmd);
503 return;
497} 504}
498 505
499static int _aac_probe_container1(void * context, struct fib * fibptr) 506static void _aac_probe_container1(void * context, struct fib * fibptr)
500{ 507{
501 struct scsi_cmnd * scsicmd; 508 struct scsi_cmnd * scsicmd;
502 struct aac_mount * dresp; 509 struct aac_mount * dresp;
@@ -506,13 +513,14 @@ static int _aac_probe_container1(void * context, struct fib * fibptr)
506 dresp = (struct aac_mount *) fib_data(fibptr); 513 dresp = (struct aac_mount *) fib_data(fibptr);
507 dresp->mnt[0].capacityhigh = 0; 514 dresp->mnt[0].capacityhigh = 0;
508 if ((le32_to_cpu(dresp->status) != ST_OK) || 515 if ((le32_to_cpu(dresp->status) != ST_OK) ||
509 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) 516 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
510 return _aac_probe_container2(context, fibptr); 517 _aac_probe_container2(context, fibptr);
518 return;
519 }
511 scsicmd = (struct scsi_cmnd *) context; 520 scsicmd = (struct scsi_cmnd *) context;
512 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
513 521
514 if (!aac_valid_context(scsicmd, fibptr)) 522 if (!aac_valid_context(scsicmd, fibptr))
515 return 0; 523 return;
516 524
517 aac_fib_init(fibptr); 525 aac_fib_init(fibptr);
518 526
@@ -527,21 +535,18 @@ static int _aac_probe_container1(void * context, struct fib * fibptr)
527 sizeof(struct aac_query_mount), 535 sizeof(struct aac_query_mount),
528 FsaNormal, 536 FsaNormal,
529 0, 1, 537 0, 1,
530 (fib_callback) _aac_probe_container2, 538 _aac_probe_container2,
531 (void *) scsicmd); 539 (void *) scsicmd);
532 /* 540 /*
533 * Check that the command queued to the controller 541 * Check that the command queued to the controller
534 */ 542 */
535 if (status == -EINPROGRESS) { 543 if (status == -EINPROGRESS)
536 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 544 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
537 return 0; 545 else if (status < 0) {
538 }
539 if (status < 0) {
540 /* Inherit results from VM_NameServe, if any */ 546 /* Inherit results from VM_NameServe, if any */
541 dresp->status = cpu_to_le32(ST_OK); 547 dresp->status = cpu_to_le32(ST_OK);
542 return _aac_probe_container2(context, fibptr); 548 _aac_probe_container2(context, fibptr);
543 } 549 }
544 return 0;
545} 550}
546 551
547static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *)) 552static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
@@ -566,7 +571,7 @@ static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(stru
566 sizeof(struct aac_query_mount), 571 sizeof(struct aac_query_mount),
567 FsaNormal, 572 FsaNormal,
568 0, 1, 573 0, 1,
569 (fib_callback) _aac_probe_container1, 574 _aac_probe_container1,
570 (void *) scsicmd); 575 (void *) scsicmd);
571 /* 576 /*
572 * Check that the command queued to the controller 577 * Check that the command queued to the controller
@@ -620,7 +625,7 @@ int aac_probe_container(struct aac_dev *dev, int cid)
620 return -ENOMEM; 625 return -ENOMEM;
621 } 626 }
622 scsicmd->list.next = NULL; 627 scsicmd->list.next = NULL;
623 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))_aac_probe_container1; 628 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
624 629
625 scsicmd->device = scsidev; 630 scsicmd->device = scsidev;
626 scsidev->sdev_state = 0; 631 scsidev->sdev_state = 0;
@@ -825,7 +830,7 @@ static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3
825 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); 830 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
826 readcmd->count = cpu_to_le32(count<<9); 831 readcmd->count = cpu_to_le32(count<<9);
827 readcmd->cid = cpu_to_le16(scmd_id(cmd)); 832 readcmd->cid = cpu_to_le16(scmd_id(cmd));
828 readcmd->flags = cpu_to_le16(1); 833 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
829 readcmd->bpTotal = 0; 834 readcmd->bpTotal = 0;
830 readcmd->bpComplete = 0; 835 readcmd->bpComplete = 0;
831 836
@@ -904,7 +909,7 @@ static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32
904 (void *) cmd); 909 (void *) cmd);
905} 910}
906 911
907static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) 912static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
908{ 913{
909 u16 fibsize; 914 u16 fibsize;
910 struct aac_raw_io *writecmd; 915 struct aac_raw_io *writecmd;
@@ -914,7 +919,9 @@ static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u
914 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); 919 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
915 writecmd->count = cpu_to_le32(count<<9); 920 writecmd->count = cpu_to_le32(count<<9);
916 writecmd->cid = cpu_to_le16(scmd_id(cmd)); 921 writecmd->cid = cpu_to_le16(scmd_id(cmd));
917 writecmd->flags = 0; 922 writecmd->flags = fua ?
923 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
924 cpu_to_le16(IO_TYPE_WRITE);
918 writecmd->bpTotal = 0; 925 writecmd->bpTotal = 0;
919 writecmd->bpComplete = 0; 926 writecmd->bpComplete = 0;
920 927
@@ -933,7 +940,7 @@ static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u
933 (void *) cmd); 940 (void *) cmd);
934} 941}
935 942
936static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) 943static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
937{ 944{
938 u16 fibsize; 945 u16 fibsize;
939 struct aac_write64 *writecmd; 946 struct aac_write64 *writecmd;
@@ -964,7 +971,7 @@ static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba,
964 (void *) cmd); 971 (void *) cmd);
965} 972}
966 973
967static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) 974static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
968{ 975{
969 u16 fibsize; 976 u16 fibsize;
970 struct aac_write *writecmd; 977 struct aac_write *writecmd;
@@ -1041,7 +1048,7 @@ static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1041 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd); 1048 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1042 1049
1043 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg); 1050 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1044 srbcmd->count = cpu_to_le32(cmd->request_bufflen); 1051 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1045 1052
1046 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); 1053 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1047 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len); 1054 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
@@ -1069,7 +1076,7 @@ static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1069 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd); 1076 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1070 1077
1071 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg); 1078 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1072 srbcmd->count = cpu_to_le32(cmd->request_bufflen); 1079 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1073 1080
1074 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); 1081 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1075 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len); 1082 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
@@ -1172,6 +1179,7 @@ int aac_get_adapter_info(struct aac_dev* dev)
1172 } 1179 }
1173 1180
1174 if (!dev->in_reset) { 1181 if (!dev->in_reset) {
1182 char buffer[16];
1175 tmp = le32_to_cpu(dev->adapter_info.kernelrev); 1183 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1176 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n", 1184 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1177 dev->name, 1185 dev->name,
@@ -1192,16 +1200,23 @@ int aac_get_adapter_info(struct aac_dev* dev)
1192 dev->name, dev->id, 1200 dev->name, dev->id,
1193 tmp>>24,(tmp>>16)&0xff,tmp&0xff, 1201 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1194 le32_to_cpu(dev->adapter_info.biosbuild)); 1202 le32_to_cpu(dev->adapter_info.biosbuild));
1195 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0) 1203 buffer[0] = '\0';
1196 printk(KERN_INFO "%s%d: serial %x\n", 1204 if (aac_show_serial_number(
1197 dev->name, dev->id, 1205 shost_to_class(dev->scsi_host_ptr), buffer))
1198 le32_to_cpu(dev->adapter_info.serial[0])); 1206 printk(KERN_INFO "%s%d: serial %s",
1207 dev->name, dev->id, buffer);
1199 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) { 1208 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1200 printk(KERN_INFO "%s%d: TSID %.*s\n", 1209 printk(KERN_INFO "%s%d: TSID %.*s\n",
1201 dev->name, dev->id, 1210 dev->name, dev->id,
1202 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid), 1211 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1203 dev->supplement_adapter_info.VpdInfo.Tsid); 1212 dev->supplement_adapter_info.VpdInfo.Tsid);
1204 } 1213 }
1214 if (!check_reset ||
1215 (dev->supplement_adapter_info.SupportedOptions2 &
1216 le32_to_cpu(AAC_OPTION_IGNORE_RESET))) {
1217 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1218 dev->name, dev->id);
1219 }
1205 } 1220 }
1206 1221
1207 dev->nondasd_support = 0; 1222 dev->nondasd_support = 0;
@@ -1332,7 +1347,7 @@ static void io_callback(void *context, struct fib * fibptr)
1332 if (!aac_valid_context(scsicmd, fibptr)) 1347 if (!aac_valid_context(scsicmd, fibptr))
1333 return; 1348 return;
1334 1349
1335 dev = (struct aac_dev *)scsicmd->device->host->hostdata; 1350 dev = fibptr->dev;
1336 cid = scmd_id(scsicmd); 1351 cid = scmd_id(scsicmd);
1337 1352
1338 if (nblank(dprintk(x))) { 1353 if (nblank(dprintk(x))) {
@@ -1371,16 +1386,9 @@ static void io_callback(void *context, struct fib * fibptr)
1371 } 1386 }
1372 1387
1373 BUG_ON(fibptr == NULL); 1388 BUG_ON(fibptr == NULL);
1374 1389
1375 if(scsicmd->use_sg) 1390 scsi_dma_unmap(scsicmd);
1376 pci_unmap_sg(dev->pdev, 1391
1377 (struct scatterlist *)scsicmd->request_buffer,
1378 scsicmd->use_sg,
1379 scsicmd->sc_data_direction);
1380 else if(scsicmd->request_bufflen)
1381 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
1382 scsicmd->request_bufflen,
1383 scsicmd->sc_data_direction);
1384 readreply = (struct aac_read_reply *)fib_data(fibptr); 1392 readreply = (struct aac_read_reply *)fib_data(fibptr);
1385 if (le32_to_cpu(readreply->status) == ST_OK) 1393 if (le32_to_cpu(readreply->status) == ST_OK)
1386 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1394 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
@@ -1498,6 +1506,7 @@ static int aac_write(struct scsi_cmnd * scsicmd)
1498{ 1506{
1499 u64 lba; 1507 u64 lba;
1500 u32 count; 1508 u32 count;
1509 int fua;
1501 int status; 1510 int status;
1502 struct aac_dev *dev; 1511 struct aac_dev *dev;
1503 struct fib * cmd_fibcontext; 1512 struct fib * cmd_fibcontext;
@@ -1512,6 +1521,7 @@ static int aac_write(struct scsi_cmnd * scsicmd)
1512 count = scsicmd->cmnd[4]; 1521 count = scsicmd->cmnd[4];
1513 if (count == 0) 1522 if (count == 0)
1514 count = 256; 1523 count = 256;
1524 fua = 0;
1515 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */ 1525 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1516 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd))); 1526 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1517 1527
@@ -1524,6 +1534,7 @@ static int aac_write(struct scsi_cmnd * scsicmd)
1524 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 1534 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1525 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) | 1535 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1526 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13]; 1536 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1537 fua = scsicmd->cmnd[1] & 0x8;
1527 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */ 1538 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1528 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd))); 1539 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1529 1540
@@ -1531,10 +1542,12 @@ static int aac_write(struct scsi_cmnd * scsicmd)
1531 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 1542 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1532 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16) 1543 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1533 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 1544 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1545 fua = scsicmd->cmnd[1] & 0x8;
1534 } else { 1546 } else {
1535 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd))); 1547 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1536 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 1548 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1537 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; 1549 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1550 fua = scsicmd->cmnd[1] & 0x8;
1538 } 1551 }
1539 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n", 1552 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1540 smp_processor_id(), (unsigned long long)lba, jiffies)); 1553 smp_processor_id(), (unsigned long long)lba, jiffies));
@@ -1549,7 +1562,7 @@ static int aac_write(struct scsi_cmnd * scsicmd)
1549 return 0; 1562 return 0;
1550 } 1563 }
1551 1564
1552 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count); 1565 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1553 1566
1554 /* 1567 /*
1555 * Check that the command queued to the controller 1568 * Check that the command queued to the controller
@@ -1592,7 +1605,7 @@ static void synchronize_callback(void *context, struct fib *fibptr)
1592 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1605 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1593 else { 1606 else {
1594 struct scsi_device *sdev = cmd->device; 1607 struct scsi_device *sdev = cmd->device;
1595 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata; 1608 struct aac_dev *dev = fibptr->dev;
1596 u32 cid = sdev_id(sdev); 1609 u32 cid = sdev_id(sdev);
1597 printk(KERN_WARNING 1610 printk(KERN_WARNING
1598 "synchronize_callback: synchronize failed, status = %d\n", 1611 "synchronize_callback: synchronize failed, status = %d\n",
@@ -1699,7 +1712,7 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)
1699 1712
1700int aac_scsi_cmd(struct scsi_cmnd * scsicmd) 1713int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1701{ 1714{
1702 u32 cid = 0; 1715 u32 cid;
1703 struct Scsi_Host *host = scsicmd->device->host; 1716 struct Scsi_Host *host = scsicmd->device->host;
1704 struct aac_dev *dev = (struct aac_dev *)host->hostdata; 1717 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1705 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev; 1718 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
@@ -1711,15 +1724,15 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1711 * Test does not apply to ID 16, the pseudo id for the controller 1724 * Test does not apply to ID 16, the pseudo id for the controller
1712 * itself. 1725 * itself.
1713 */ 1726 */
1714 if (scmd_id(scsicmd) != host->this_id) { 1727 cid = scmd_id(scsicmd);
1715 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) { 1728 if (cid != host->this_id) {
1716 if((scmd_id(scsicmd) >= dev->maximum_num_containers) || 1729 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
1730 if((cid >= dev->maximum_num_containers) ||
1717 (scsicmd->device->lun != 0)) { 1731 (scsicmd->device->lun != 0)) {
1718 scsicmd->result = DID_NO_CONNECT << 16; 1732 scsicmd->result = DID_NO_CONNECT << 16;
1719 scsicmd->scsi_done(scsicmd); 1733 scsicmd->scsi_done(scsicmd);
1720 return 0; 1734 return 0;
1721 } 1735 }
1722 cid = scmd_id(scsicmd);
1723 1736
1724 /* 1737 /*
1725 * If the target container doesn't exist, it may have 1738 * If the target container doesn't exist, it may have
@@ -1782,7 +1795,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1782 { 1795 {
1783 struct inquiry_data inq_data; 1796 struct inquiry_data inq_data;
1784 1797
1785 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd))); 1798 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
1786 memset(&inq_data, 0, sizeof (struct inquiry_data)); 1799 memset(&inq_data, 0, sizeof (struct inquiry_data));
1787 1800
1788 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */ 1801 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
@@ -1794,7 +1807,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1794 * Set the Vendor, Product, and Revision Level 1807 * Set the Vendor, Product, and Revision Level
1795 * see: <vendor>.c i.e. aac.c 1808 * see: <vendor>.c i.e. aac.c
1796 */ 1809 */
1797 if (scmd_id(scsicmd) == host->this_id) { 1810 if (cid == host->this_id) {
1798 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types)); 1811 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
1799 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */ 1812 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1800 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data)); 1813 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
@@ -1886,15 +1899,29 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1886 1899
1887 case MODE_SENSE: 1900 case MODE_SENSE:
1888 { 1901 {
1889 char mode_buf[4]; 1902 char mode_buf[7];
1903 int mode_buf_length = 4;
1890 1904
1891 dprintk((KERN_DEBUG "MODE SENSE command.\n")); 1905 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1892 mode_buf[0] = 3; /* Mode data length */ 1906 mode_buf[0] = 3; /* Mode data length */
1893 mode_buf[1] = 0; /* Medium type - default */ 1907 mode_buf[1] = 0; /* Medium type - default */
1894 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */ 1908 mode_buf[2] = 0; /* Device-specific param,
1909 bit 8: 0/1 = write enabled/protected
1910 bit 4: 0/1 = FUA enabled */
1911 if (dev->raw_io_interface)
1912 mode_buf[2] = 0x10;
1895 mode_buf[3] = 0; /* Block descriptor length */ 1913 mode_buf[3] = 0; /* Block descriptor length */
1896 1914 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
1897 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf)); 1915 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
1916 mode_buf[0] = 6;
1917 mode_buf[4] = 8;
1918 mode_buf[5] = 1;
1919 mode_buf[6] = 0x04; /* WCE */
1920 mode_buf_length = 7;
1921 if (mode_buf_length > scsicmd->cmnd[4])
1922 mode_buf_length = scsicmd->cmnd[4];
1923 }
1924 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
1898 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1925 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1899 scsicmd->scsi_done(scsicmd); 1926 scsicmd->scsi_done(scsicmd);
1900 1927
@@ -1902,18 +1929,33 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1902 } 1929 }
1903 case MODE_SENSE_10: 1930 case MODE_SENSE_10:
1904 { 1931 {
1905 char mode_buf[8]; 1932 char mode_buf[11];
1933 int mode_buf_length = 8;
1906 1934
1907 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n")); 1935 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1908 mode_buf[0] = 0; /* Mode data length (MSB) */ 1936 mode_buf[0] = 0; /* Mode data length (MSB) */
1909 mode_buf[1] = 6; /* Mode data length (LSB) */ 1937 mode_buf[1] = 6; /* Mode data length (LSB) */
1910 mode_buf[2] = 0; /* Medium type - default */ 1938 mode_buf[2] = 0; /* Medium type - default */
1911 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */ 1939 mode_buf[3] = 0; /* Device-specific param,
1940 bit 8: 0/1 = write enabled/protected
1941 bit 4: 0/1 = FUA enabled */
1942 if (dev->raw_io_interface)
1943 mode_buf[3] = 0x10;
1912 mode_buf[4] = 0; /* reserved */ 1944 mode_buf[4] = 0; /* reserved */
1913 mode_buf[5] = 0; /* reserved */ 1945 mode_buf[5] = 0; /* reserved */
1914 mode_buf[6] = 0; /* Block descriptor length (MSB) */ 1946 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1915 mode_buf[7] = 0; /* Block descriptor length (LSB) */ 1947 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1916 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf)); 1948 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
1949 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
1950 mode_buf[1] = 9;
1951 mode_buf[8] = 8;
1952 mode_buf[9] = 1;
1953 mode_buf[10] = 0x04; /* WCE */
1954 mode_buf_length = 11;
1955 if (mode_buf_length > scsicmd->cmnd[8])
1956 mode_buf_length = scsicmd->cmnd[8];
1957 }
1958 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
1917 1959
1918 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1960 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1919 scsicmd->scsi_done(scsicmd); 1961 scsicmd->scsi_done(scsicmd);
@@ -2136,28 +2178,21 @@ static void aac_srb_callback(void *context, struct fib * fibptr)
2136 if (!aac_valid_context(scsicmd, fibptr)) 2178 if (!aac_valid_context(scsicmd, fibptr))
2137 return; 2179 return;
2138 2180
2139 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2140
2141 BUG_ON(fibptr == NULL); 2181 BUG_ON(fibptr == NULL);
2142 2182
2183 dev = fibptr->dev;
2184
2143 srbreply = (struct aac_srb_reply *) fib_data(fibptr); 2185 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2144 2186
2145 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */ 2187 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2146 /* 2188 /*
2147 * Calculate resid for sg 2189 * Calculate resid for sg
2148 */ 2190 */
2149 2191
2150 scsicmd->resid = scsicmd->request_bufflen - 2192 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2151 le32_to_cpu(srbreply->data_xfer_length); 2193 - le32_to_cpu(srbreply->data_xfer_length));
2152 2194
2153 if(scsicmd->use_sg) 2195 scsi_dma_unmap(scsicmd);
2154 pci_unmap_sg(dev->pdev,
2155 (struct scatterlist *)scsicmd->request_buffer,
2156 scsicmd->use_sg,
2157 scsicmd->sc_data_direction);
2158 else if(scsicmd->request_bufflen)
2159 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
2160 scsicmd->sc_data_direction);
2161 2196
2162 /* 2197 /*
2163 * First check the fib status 2198 * First check the fib status
@@ -2233,7 +2268,7 @@ static void aac_srb_callback(void *context, struct fib * fibptr)
2233 break; 2268 break;
2234 2269
2235 case SRB_STATUS_BUSY: 2270 case SRB_STATUS_BUSY:
2236 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8; 2271 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
2237 break; 2272 break;
2238 2273
2239 case SRB_STATUS_BUS_RESET: 2274 case SRB_STATUS_BUS_RESET:
@@ -2343,34 +2378,33 @@ static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2343{ 2378{
2344 struct aac_dev *dev; 2379 struct aac_dev *dev;
2345 unsigned long byte_count = 0; 2380 unsigned long byte_count = 0;
2381 int nseg;
2346 2382
2347 dev = (struct aac_dev *)scsicmd->device->host->hostdata; 2383 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2348 // Get rid of old data 2384 // Get rid of old data
2349 psg->count = 0; 2385 psg->count = 0;
2350 psg->sg[0].addr = 0; 2386 psg->sg[0].addr = 0;
2351 psg->sg[0].count = 0; 2387 psg->sg[0].count = 0;
2352 if (scsicmd->use_sg) { 2388
2389 nseg = scsi_dma_map(scsicmd);
2390 BUG_ON(nseg < 0);
2391 if (nseg) {
2353 struct scatterlist *sg; 2392 struct scatterlist *sg;
2354 int i; 2393 int i;
2355 int sg_count;
2356 sg = (struct scatterlist *) scsicmd->request_buffer;
2357 2394
2358 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg, 2395 psg->count = cpu_to_le32(nseg);
2359 scsicmd->sc_data_direction);
2360 psg->count = cpu_to_le32(sg_count);
2361 2396
2362 for (i = 0; i < sg_count; i++) { 2397 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2363 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg)); 2398 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2364 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg)); 2399 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2365 byte_count += sg_dma_len(sg); 2400 byte_count += sg_dma_len(sg);
2366 sg++;
2367 } 2401 }
2368 /* hba wants the size to be exact */ 2402 /* hba wants the size to be exact */
2369 if(byte_count > scsicmd->request_bufflen){ 2403 if (byte_count > scsi_bufflen(scsicmd)) {
2370 u32 temp = le32_to_cpu(psg->sg[i-1].count) - 2404 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2371 (byte_count - scsicmd->request_bufflen); 2405 (byte_count - scsi_bufflen(scsicmd));
2372 psg->sg[i-1].count = cpu_to_le32(temp); 2406 psg->sg[i-1].count = cpu_to_le32(temp);
2373 byte_count = scsicmd->request_bufflen; 2407 byte_count = scsi_bufflen(scsicmd);
2374 } 2408 }
2375 /* Check for command underflow */ 2409 /* Check for command underflow */
2376 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ 2410 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
@@ -2378,18 +2412,6 @@ static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2378 byte_count, scsicmd->underflow); 2412 byte_count, scsicmd->underflow);
2379 } 2413 }
2380 } 2414 }
2381 else if(scsicmd->request_bufflen) {
2382 u32 addr;
2383 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2384 scsicmd->request_buffer,
2385 scsicmd->request_bufflen,
2386 scsicmd->sc_data_direction);
2387 addr = scsicmd->SCp.dma_handle;
2388 psg->count = cpu_to_le32(1);
2389 psg->sg[0].addr = cpu_to_le32(addr);
2390 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2391 byte_count = scsicmd->request_bufflen;
2392 }
2393 return byte_count; 2415 return byte_count;
2394} 2416}
2395 2417
@@ -2399,6 +2421,7 @@ static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* p
2399 struct aac_dev *dev; 2421 struct aac_dev *dev;
2400 unsigned long byte_count = 0; 2422 unsigned long byte_count = 0;
2401 u64 addr; 2423 u64 addr;
2424 int nseg;
2402 2425
2403 dev = (struct aac_dev *)scsicmd->device->host->hostdata; 2426 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2404 // Get rid of old data 2427 // Get rid of old data
@@ -2406,31 +2429,28 @@ static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* p
2406 psg->sg[0].addr[0] = 0; 2429 psg->sg[0].addr[0] = 0;
2407 psg->sg[0].addr[1] = 0; 2430 psg->sg[0].addr[1] = 0;
2408 psg->sg[0].count = 0; 2431 psg->sg[0].count = 0;
2409 if (scsicmd->use_sg) { 2432
2433 nseg = scsi_dma_map(scsicmd);
2434 BUG_ON(nseg < 0);
2435 if (nseg) {
2410 struct scatterlist *sg; 2436 struct scatterlist *sg;
2411 int i; 2437 int i;
2412 int sg_count;
2413 sg = (struct scatterlist *) scsicmd->request_buffer;
2414
2415 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2416 scsicmd->sc_data_direction);
2417 2438
2418 for (i = 0; i < sg_count; i++) { 2439 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2419 int count = sg_dma_len(sg); 2440 int count = sg_dma_len(sg);
2420 addr = sg_dma_address(sg); 2441 addr = sg_dma_address(sg);
2421 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff); 2442 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2422 psg->sg[i].addr[1] = cpu_to_le32(addr>>32); 2443 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2423 psg->sg[i].count = cpu_to_le32(count); 2444 psg->sg[i].count = cpu_to_le32(count);
2424 byte_count += count; 2445 byte_count += count;
2425 sg++;
2426 } 2446 }
2427 psg->count = cpu_to_le32(sg_count); 2447 psg->count = cpu_to_le32(nseg);
2428 /* hba wants the size to be exact */ 2448 /* hba wants the size to be exact */
2429 if(byte_count > scsicmd->request_bufflen){ 2449 if (byte_count > scsi_bufflen(scsicmd)) {
2430 u32 temp = le32_to_cpu(psg->sg[i-1].count) - 2450 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2431 (byte_count - scsicmd->request_bufflen); 2451 (byte_count - scsi_bufflen(scsicmd));
2432 psg->sg[i-1].count = cpu_to_le32(temp); 2452 psg->sg[i-1].count = cpu_to_le32(temp);
2433 byte_count = scsicmd->request_bufflen; 2453 byte_count = scsi_bufflen(scsicmd);
2434 } 2454 }
2435 /* Check for command underflow */ 2455 /* Check for command underflow */
2436 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ 2456 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
@@ -2438,26 +2458,13 @@ static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* p
2438 byte_count, scsicmd->underflow); 2458 byte_count, scsicmd->underflow);
2439 } 2459 }
2440 } 2460 }
2441 else if(scsicmd->request_bufflen) {
2442 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2443 scsicmd->request_buffer,
2444 scsicmd->request_bufflen,
2445 scsicmd->sc_data_direction);
2446 addr = scsicmd->SCp.dma_handle;
2447 psg->count = cpu_to_le32(1);
2448 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2449 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2450 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2451 byte_count = scsicmd->request_bufflen;
2452 }
2453 return byte_count; 2461 return byte_count;
2454} 2462}
2455 2463
2456static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg) 2464static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2457{ 2465{
2458 struct Scsi_Host *host = scsicmd->device->host;
2459 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2460 unsigned long byte_count = 0; 2466 unsigned long byte_count = 0;
2467 int nseg;
2461 2468
2462 // Get rid of old data 2469 // Get rid of old data
2463 psg->count = 0; 2470 psg->count = 0;
@@ -2467,16 +2474,14 @@ static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw*
2467 psg->sg[0].addr[1] = 0; 2474 psg->sg[0].addr[1] = 0;
2468 psg->sg[0].count = 0; 2475 psg->sg[0].count = 0;
2469 psg->sg[0].flags = 0; 2476 psg->sg[0].flags = 0;
2470 if (scsicmd->use_sg) { 2477
2478 nseg = scsi_dma_map(scsicmd);
2479 BUG_ON(nseg < 0);
2480 if (nseg) {
2471 struct scatterlist *sg; 2481 struct scatterlist *sg;
2472 int i; 2482 int i;
2473 int sg_count;
2474 sg = (struct scatterlist *) scsicmd->request_buffer;
2475 2483
2476 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg, 2484 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2477 scsicmd->sc_data_direction);
2478
2479 for (i = 0; i < sg_count; i++) {
2480 int count = sg_dma_len(sg); 2485 int count = sg_dma_len(sg);
2481 u64 addr = sg_dma_address(sg); 2486 u64 addr = sg_dma_address(sg);
2482 psg->sg[i].next = 0; 2487 psg->sg[i].next = 0;
@@ -2486,15 +2491,14 @@ static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw*
2486 psg->sg[i].count = cpu_to_le32(count); 2491 psg->sg[i].count = cpu_to_le32(count);
2487 psg->sg[i].flags = 0; 2492 psg->sg[i].flags = 0;
2488 byte_count += count; 2493 byte_count += count;
2489 sg++;
2490 } 2494 }
2491 psg->count = cpu_to_le32(sg_count); 2495 psg->count = cpu_to_le32(nseg);
2492 /* hba wants the size to be exact */ 2496 /* hba wants the size to be exact */
2493 if(byte_count > scsicmd->request_bufflen){ 2497 if (byte_count > scsi_bufflen(scsicmd)) {
2494 u32 temp = le32_to_cpu(psg->sg[i-1].count) - 2498 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2495 (byte_count - scsicmd->request_bufflen); 2499 (byte_count - scsi_bufflen(scsicmd));
2496 psg->sg[i-1].count = cpu_to_le32(temp); 2500 psg->sg[i-1].count = cpu_to_le32(temp);
2497 byte_count = scsicmd->request_bufflen; 2501 byte_count = scsi_bufflen(scsicmd);
2498 } 2502 }
2499 /* Check for command underflow */ 2503 /* Check for command underflow */
2500 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ 2504 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
@@ -2502,24 +2506,6 @@ static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw*
2502 byte_count, scsicmd->underflow); 2506 byte_count, scsicmd->underflow);
2503 } 2507 }
2504 } 2508 }
2505 else if(scsicmd->request_bufflen) {
2506 int count;
2507 u64 addr;
2508 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2509 scsicmd->request_buffer,
2510 scsicmd->request_bufflen,
2511 scsicmd->sc_data_direction);
2512 addr = scsicmd->SCp.dma_handle;
2513 count = scsicmd->request_bufflen;
2514 psg->count = cpu_to_le32(1);
2515 psg->sg[0].next = 0;
2516 psg->sg[0].prev = 0;
2517 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2518 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2519 psg->sg[0].count = cpu_to_le32(count);
2520 psg->sg[0].flags = 0;
2521 byte_count = scsicmd->request_bufflen;
2522 }
2523 return byte_count; 2509 return byte_count;
2524} 2510}
2525 2511