aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/aacraid/aachba.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/aacraid/aachba.c')
-rw-r--r--drivers/scsi/aacraid/aachba.c400
1 files changed, 215 insertions, 185 deletions
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index a77ab8d693d..d7235f42cf5 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -31,9 +31,9 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/completion.h> 32#include <linux/completion.h>
33#include <linux/blkdev.h> 33#include <linux/blkdev.h>
34#include <linux/dma-mapping.h>
35#include <asm/semaphore.h> 34#include <asm/semaphore.h>
36#include <asm/uaccess.h> 35#include <asm/uaccess.h>
36#include <linux/highmem.h> /* For flush_kernel_dcache_page */
37 37
38#include <scsi/scsi.h> 38#include <scsi/scsi.h>
39#include <scsi/scsi_cmnd.h> 39#include <scsi/scsi_cmnd.h>
@@ -56,54 +56,54 @@
56/* 56/*
57 * Sense codes 57 * Sense codes
58 */ 58 */
59 59
60#define SENCODE_NO_SENSE 0x00 60#define SENCODE_NO_SENSE 0x00
61#define SENCODE_END_OF_DATA 0x00 61#define SENCODE_END_OF_DATA 0x00
62#define SENCODE_BECOMING_READY 0x04 62#define SENCODE_BECOMING_READY 0x04
63#define SENCODE_INIT_CMD_REQUIRED 0x04 63#define SENCODE_INIT_CMD_REQUIRED 0x04
64#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A 64#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65#define SENCODE_INVALID_COMMAND 0x20 65#define SENCODE_INVALID_COMMAND 0x20
66#define SENCODE_LBA_OUT_OF_RANGE 0x21 66#define SENCODE_LBA_OUT_OF_RANGE 0x21
67#define SENCODE_INVALID_CDB_FIELD 0x24 67#define SENCODE_INVALID_CDB_FIELD 0x24
68#define SENCODE_LUN_NOT_SUPPORTED 0x25 68#define SENCODE_LUN_NOT_SUPPORTED 0x25
69#define SENCODE_INVALID_PARAM_FIELD 0x26 69#define SENCODE_INVALID_PARAM_FIELD 0x26
70#define SENCODE_PARAM_NOT_SUPPORTED 0x26 70#define SENCODE_PARAM_NOT_SUPPORTED 0x26
71#define SENCODE_PARAM_VALUE_INVALID 0x26 71#define SENCODE_PARAM_VALUE_INVALID 0x26
72#define SENCODE_RESET_OCCURRED 0x29 72#define SENCODE_RESET_OCCURRED 0x29
73#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E 73#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74#define SENCODE_INQUIRY_DATA_CHANGED 0x3F 74#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39 75#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76#define SENCODE_DIAGNOSTIC_FAILURE 0x40 76#define SENCODE_DIAGNOSTIC_FAILURE 0x40
77#define SENCODE_INTERNAL_TARGET_FAILURE 0x44 77#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78#define SENCODE_INVALID_MESSAGE_ERROR 0x49 78#define SENCODE_INVALID_MESSAGE_ERROR 0x49
79#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c 79#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80#define SENCODE_OVERLAPPED_COMMAND 0x4E 80#define SENCODE_OVERLAPPED_COMMAND 0x4E
81 81
82/* 82/*
83 * Additional sense codes 83 * Additional sense codes
84 */ 84 */
85 85
86#define ASENCODE_NO_SENSE 0x00 86#define ASENCODE_NO_SENSE 0x00
87#define ASENCODE_END_OF_DATA 0x05 87#define ASENCODE_END_OF_DATA 0x05
88#define ASENCODE_BECOMING_READY 0x01 88#define ASENCODE_BECOMING_READY 0x01
89#define ASENCODE_INIT_CMD_REQUIRED 0x02 89#define ASENCODE_INIT_CMD_REQUIRED 0x02
90#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00 90#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91#define ASENCODE_INVALID_COMMAND 0x00 91#define ASENCODE_INVALID_COMMAND 0x00
92#define ASENCODE_LBA_OUT_OF_RANGE 0x00 92#define ASENCODE_LBA_OUT_OF_RANGE 0x00
93#define ASENCODE_INVALID_CDB_FIELD 0x00 93#define ASENCODE_INVALID_CDB_FIELD 0x00
94#define ASENCODE_LUN_NOT_SUPPORTED 0x00 94#define ASENCODE_LUN_NOT_SUPPORTED 0x00
95#define ASENCODE_INVALID_PARAM_FIELD 0x00 95#define ASENCODE_INVALID_PARAM_FIELD 0x00
96#define ASENCODE_PARAM_NOT_SUPPORTED 0x01 96#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97#define ASENCODE_PARAM_VALUE_INVALID 0x02 97#define ASENCODE_PARAM_VALUE_INVALID 0x02
98#define ASENCODE_RESET_OCCURRED 0x00 98#define ASENCODE_RESET_OCCURRED 0x00
99#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00 99#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100#define ASENCODE_INQUIRY_DATA_CHANGED 0x03 100#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00 101#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102#define ASENCODE_DIAGNOSTIC_FAILURE 0x80 102#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00 103#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104#define ASENCODE_INVALID_MESSAGE_ERROR 0x00 104#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00 105#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106#define ASENCODE_OVERLAPPED_COMMAND 0x00 106#define ASENCODE_OVERLAPPED_COMMAND 0x00
107 107
108#define BYTE0(x) (unsigned char)(x) 108#define BYTE0(x) (unsigned char)(x)
109#define BYTE1(x) (unsigned char)((x) >> 8) 109#define BYTE1(x) (unsigned char)((x) >> 8)
@@ -115,8 +115,8 @@
115 *----------------------------------------------------------------------------*/ 115 *----------------------------------------------------------------------------*/
116/* SCSI inquiry data */ 116/* SCSI inquiry data */
117struct inquiry_data { 117struct inquiry_data {
118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */ 118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq; /* RMB | Device Type Qualifier */ 119 u8 inqd_dtq; /* RMB | Device Type Qualifier */
120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */ 120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */ 121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len; /* Additional length (n-4) */ 122 u8 inqd_len; /* Additional length (n-4) */
@@ -130,7 +130,7 @@ struct inquiry_data {
130/* 130/*
131 * M O D U L E G L O B A L S 131 * M O D U L E G L O B A L S
132 */ 132 */
133 133
134static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap); 134static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg); 135static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
136static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg); 136static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
@@ -141,9 +141,10 @@ static char *aac_get_status_string(u32 status);
141 141
142/* 142/*
143 * Non dasd selection is handled entirely in aachba now 143 * Non dasd selection is handled entirely in aachba now
144 */ 144 */
145 145
146static int nondasd = -1; 146static int nondasd = -1;
147static int aac_cache = 0;
147static int dacmode = -1; 148static int dacmode = -1;
148 149
149int aac_commit = -1; 150int aac_commit = -1;
@@ -152,6 +153,8 @@ int aif_timeout = 120;
152 153
153module_param(nondasd, int, S_IRUGO|S_IWUSR); 154module_param(nondasd, int, S_IRUGO|S_IWUSR);
154MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on"); 155MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
156module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
157MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n\tbit 0 - Disable FUA in WRITE SCSI commands\n\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n\tbit 2 - Disable only if Battery not protecting Cache");
155module_param(dacmode, int, S_IRUGO|S_IWUSR); 158module_param(dacmode, int, S_IRUGO|S_IWUSR);
156MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on"); 159MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
157module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR); 160module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
@@ -179,7 +182,7 @@ MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health che
179 182
180int aac_check_reset = 1; 183int aac_check_reset = 1;
181module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR); 184module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
182MODULE_PARM_DESC(aac_check_reset, "If adapter fails health check, reset the adapter."); 185MODULE_PARM_DESC(aac_check_reset, "If adapter fails health check, reset the adapter. a value of -1 forces the reset to adapters programmed to ignore it.");
183 186
184int expose_physicals = -1; 187int expose_physicals = -1;
185module_param(expose_physicals, int, S_IRUGO|S_IWUSR); 188module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
@@ -193,12 +196,12 @@ static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
193 struct fib *fibptr) { 196 struct fib *fibptr) {
194 struct scsi_device *device; 197 struct scsi_device *device;
195 198
196 if (unlikely(!scsicmd || !scsicmd->scsi_done )) { 199 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
197 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n")); 200 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
198 aac_fib_complete(fibptr); 201 aac_fib_complete(fibptr);
199 aac_fib_free(fibptr); 202 aac_fib_free(fibptr);
200 return 0; 203 return 0;
201 } 204 }
202 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL; 205 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
203 device = scsicmd->device; 206 device = scsicmd->device;
204 if (unlikely(!device || !scsi_device_online(device))) { 207 if (unlikely(!device || !scsi_device_online(device))) {
@@ -240,7 +243,7 @@ int aac_get_config_status(struct aac_dev *dev, int commit_flag)
240 FsaNormal, 243 FsaNormal,
241 1, 1, 244 1, 1,
242 NULL, NULL); 245 NULL, NULL);
243 if (status < 0 ) { 246 if (status < 0) {
244 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n"); 247 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
245 } else { 248 } else {
246 struct aac_get_config_status_resp *reply 249 struct aac_get_config_status_resp *reply
@@ -264,10 +267,10 @@ int aac_get_config_status(struct aac_dev *dev, int commit_flag)
264 struct aac_commit_config * dinfo; 267 struct aac_commit_config * dinfo;
265 aac_fib_init(fibptr); 268 aac_fib_init(fibptr);
266 dinfo = (struct aac_commit_config *) fib_data(fibptr); 269 dinfo = (struct aac_commit_config *) fib_data(fibptr);
267 270
268 dinfo->command = cpu_to_le32(VM_ContainerConfig); 271 dinfo->command = cpu_to_le32(VM_ContainerConfig);
269 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG); 272 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
270 273
271 status = aac_fib_send(ContainerCommand, 274 status = aac_fib_send(ContainerCommand,
272 fibptr, 275 fibptr,
273 sizeof (struct aac_commit_config), 276 sizeof (struct aac_commit_config),
@@ -293,7 +296,7 @@ int aac_get_config_status(struct aac_dev *dev, int commit_flag)
293int aac_get_containers(struct aac_dev *dev) 296int aac_get_containers(struct aac_dev *dev)
294{ 297{
295 struct fsa_dev_info *fsa_dev_ptr; 298 struct fsa_dev_info *fsa_dev_ptr;
296 u32 index; 299 u32 index;
297 int status = 0; 300 int status = 0;
298 struct fib * fibptr; 301 struct fib * fibptr;
299 struct aac_get_container_count *dinfo; 302 struct aac_get_container_count *dinfo;
@@ -363,6 +366,7 @@ static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigne
363 if (buf && transfer_len > 0) 366 if (buf && transfer_len > 0)
364 memcpy(buf + offset, data, transfer_len); 367 memcpy(buf + offset, data, transfer_len);
365 368
369 flush_kernel_dcache_page(kmap_atomic_to_page(buf - sg->offset));
366 kunmap_atomic(buf - sg->offset, KM_IRQ0); 370 kunmap_atomic(buf - sg->offset, KM_IRQ0);
367 371
368} 372}
@@ -395,7 +399,7 @@ static void get_container_name_callback(void *context, struct fib * fibptr)
395 do { 399 do {
396 *dp++ = (*sp) ? *sp++ : ' '; 400 *dp++ = (*sp) ? *sp++ : ' ';
397 } while (--count > 0); 401 } while (--count > 0);
398 aac_internal_transfer(scsicmd, d, 402 aac_internal_transfer(scsicmd, d,
399 offsetof(struct inquiry_data, inqd_pid), sizeof(d)); 403 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
400 } 404 }
401 } 405 }
@@ -431,13 +435,13 @@ static int aac_get_container_name(struct scsi_cmnd * scsicmd)
431 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data)); 435 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
432 436
433 status = aac_fib_send(ContainerCommand, 437 status = aac_fib_send(ContainerCommand,
434 cmd_fibcontext, 438 cmd_fibcontext,
435 sizeof (struct aac_get_name), 439 sizeof (struct aac_get_name),
436 FsaNormal, 440 FsaNormal,
437 0, 1, 441 0, 1,
438 (fib_callback) get_container_name_callback, 442 (fib_callback)get_container_name_callback,
439 (void *) scsicmd); 443 (void *) scsicmd);
440 444
441 /* 445 /*
442 * Check that the command queued to the controller 446 * Check that the command queued to the controller
443 */ 447 */
@@ -445,7 +449,7 @@ static int aac_get_container_name(struct scsi_cmnd * scsicmd)
445 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 449 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
446 return 0; 450 return 0;
447 } 451 }
448 452
449 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status); 453 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
450 aac_fib_complete(cmd_fibcontext); 454 aac_fib_complete(cmd_fibcontext);
451 aac_fib_free(cmd_fibcontext); 455 aac_fib_free(cmd_fibcontext);
@@ -652,42 +656,47 @@ struct scsi_inq {
652 * @a: string to copy from 656 * @a: string to copy from
653 * @b: string to copy to 657 * @b: string to copy to
654 * 658 *
655 * Copy a String from one location to another 659 * Copy a String from one location to another
656 * without copying \0 660 * without copying \0
657 */ 661 */
658 662
659static void inqstrcpy(char *a, char *b) 663static void inqstrcpy(char *a, char *b)
660{ 664{
661 665
662 while(*a != (char)0) 666 while (*a != (char)0)
663 *b++ = *a++; 667 *b++ = *a++;
664} 668}
665 669
666static char *container_types[] = { 670static char *container_types[] = {
667 "None", 671 "None",
668 "Volume", 672 "Volume",
669 "Mirror", 673 "Mirror",
670 "Stripe", 674 "Stripe",
671 "RAID5", 675 "RAID5",
672 "SSRW", 676 "SSRW",
673 "SSRO", 677 "SSRO",
674 "Morph", 678 "Morph",
675 "Legacy", 679 "Legacy",
676 "RAID4", 680 "RAID4",
677 "RAID10", 681 "RAID10",
678 "RAID00", 682 "RAID00",
679 "V-MIRRORS", 683 "V-MIRRORS",
680 "PSEUDO R4", 684 "PSEUDO R4",
681 "RAID50", 685 "RAID50",
682 "RAID5D", 686 "RAID5D",
683 "RAID5D0", 687 "RAID5D0",
684 "RAID1E", 688 "RAID1E",
685 "RAID6", 689 "RAID6",
686 "RAID60", 690 "RAID60",
687 "Unknown" 691 "Unknown"
688}; 692};
689 693
690 694char * get_container_type(unsigned tindex)
695{
696 if (tindex >= ARRAY_SIZE(container_types))
697 tindex = ARRAY_SIZE(container_types) - 1;
698 return container_types[tindex];
699}
691 700
692/* Function: setinqstr 701/* Function: setinqstr
693 * 702 *
@@ -707,16 +716,21 @@ static void setinqstr(struct aac_dev *dev, void *data, int tindex)
707 716
708 if (dev->supplement_adapter_info.AdapterTypeText[0]) { 717 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
709 char * cp = dev->supplement_adapter_info.AdapterTypeText; 718 char * cp = dev->supplement_adapter_info.AdapterTypeText;
710 int c = sizeof(str->vid); 719 int c;
711 while (*cp && *cp != ' ' && --c) 720 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
712 ++cp; 721 inqstrcpy("SMC", str->vid);
713 c = *cp; 722 else {
714 *cp = '\0'; 723 c = sizeof(str->vid);
715 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText, 724 while (*cp && *cp != ' ' && --c)
716 str->vid); 725 ++cp;
717 *cp = c; 726 c = *cp;
718 while (*cp && *cp != ' ') 727 *cp = '\0';
719 ++cp; 728 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
729 str->vid);
730 *cp = c;
731 while (*cp && *cp != ' ')
732 ++cp;
733 }
720 while (*cp == ' ') 734 while (*cp == ' ')
721 ++cp; 735 ++cp;
722 /* last six chars reserved for vol type */ 736 /* last six chars reserved for vol type */
@@ -898,9 +912,8 @@ static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
898 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 912 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
899 0, 0); 913 0, 0);
900 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 914 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
901 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer)) 915 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
902 ? sizeof(cmd->sense_buffer) 916 SCSI_SENSE_BUFFERSIZE));
903 : sizeof(dev->fsa_dev[cid].sense_data));
904 cmd->scsi_done(cmd); 917 cmd->scsi_done(cmd);
905 return 1; 918 return 1;
906 } 919 }
@@ -981,7 +994,7 @@ static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32
981 aac_fib_init(fib); 994 aac_fib_init(fib);
982 readcmd = (struct aac_read *) fib_data(fib); 995 readcmd = (struct aac_read *) fib_data(fib);
983 readcmd->command = cpu_to_le32(VM_CtBlockRead); 996 readcmd->command = cpu_to_le32(VM_CtBlockRead);
984 readcmd->cid = cpu_to_le16(scmd_id(cmd)); 997 readcmd->cid = cpu_to_le32(scmd_id(cmd));
985 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff)); 998 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
986 readcmd->count = cpu_to_le32(count * 512); 999 readcmd->count = cpu_to_le32(count * 512);
987 1000
@@ -1013,7 +1026,8 @@ static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u
1013 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); 1026 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1014 writecmd->count = cpu_to_le32(count<<9); 1027 writecmd->count = cpu_to_le32(count<<9);
1015 writecmd->cid = cpu_to_le16(scmd_id(cmd)); 1028 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1016 writecmd->flags = fua ? 1029 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1030 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1017 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) : 1031 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
1018 cpu_to_le16(IO_TYPE_WRITE); 1032 cpu_to_le16(IO_TYPE_WRITE);
1019 writecmd->bpTotal = 0; 1033 writecmd->bpTotal = 0;
@@ -1072,7 +1086,7 @@ static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3
1072 aac_fib_init(fib); 1086 aac_fib_init(fib);
1073 writecmd = (struct aac_write *) fib_data(fib); 1087 writecmd = (struct aac_write *) fib_data(fib);
1074 writecmd->command = cpu_to_le32(VM_CtBlockWrite); 1088 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1075 writecmd->cid = cpu_to_le16(scmd_id(cmd)); 1089 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1076 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff)); 1090 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1077 writecmd->count = cpu_to_le32(count * 512); 1091 writecmd->count = cpu_to_le32(count * 512);
1078 writecmd->sg.count = cpu_to_le32(1); 1092 writecmd->sg.count = cpu_to_le32(1);
@@ -1190,6 +1204,15 @@ static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1190 (fib_callback) aac_srb_callback, (void *) cmd); 1204 (fib_callback) aac_srb_callback, (void *) cmd);
1191} 1205}
1192 1206
1207static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1208{
1209 if ((sizeof(dma_addr_t) > 4) &&
1210 (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) &&
1211 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1212 return FAILED;
1213 return aac_scsi_32(fib, cmd);
1214}
1215
1193int aac_get_adapter_info(struct aac_dev* dev) 1216int aac_get_adapter_info(struct aac_dev* dev)
1194{ 1217{
1195 struct fib* fibptr; 1218 struct fib* fibptr;
@@ -1207,11 +1230,11 @@ int aac_get_adapter_info(struct aac_dev* dev)
1207 memset(info,0,sizeof(*info)); 1230 memset(info,0,sizeof(*info));
1208 1231
1209 rcode = aac_fib_send(RequestAdapterInfo, 1232 rcode = aac_fib_send(RequestAdapterInfo,
1210 fibptr, 1233 fibptr,
1211 sizeof(*info), 1234 sizeof(*info),
1212 FsaNormal, 1235 FsaNormal,
1213 -1, 1, /* First `interrupt' command uses special wait */ 1236 -1, 1, /* First `interrupt' command uses special wait */
1214 NULL, 1237 NULL,
1215 NULL); 1238 NULL);
1216 1239
1217 if (rcode < 0) { 1240 if (rcode < 0) {
@@ -1222,29 +1245,29 @@ int aac_get_adapter_info(struct aac_dev* dev)
1222 memcpy(&dev->adapter_info, info, sizeof(*info)); 1245 memcpy(&dev->adapter_info, info, sizeof(*info));
1223 1246
1224 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) { 1247 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1225 struct aac_supplement_adapter_info * info; 1248 struct aac_supplement_adapter_info * sinfo;
1226 1249
1227 aac_fib_init(fibptr); 1250 aac_fib_init(fibptr);
1228 1251
1229 info = (struct aac_supplement_adapter_info *) fib_data(fibptr); 1252 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1230 1253
1231 memset(info,0,sizeof(*info)); 1254 memset(sinfo,0,sizeof(*sinfo));
1232 1255
1233 rcode = aac_fib_send(RequestSupplementAdapterInfo, 1256 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1234 fibptr, 1257 fibptr,
1235 sizeof(*info), 1258 sizeof(*sinfo),
1236 FsaNormal, 1259 FsaNormal,
1237 1, 1, 1260 1, 1,
1238 NULL, 1261 NULL,
1239 NULL); 1262 NULL);
1240 1263
1241 if (rcode >= 0) 1264 if (rcode >= 0)
1242 memcpy(&dev->supplement_adapter_info, info, sizeof(*info)); 1265 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
1243 } 1266 }
1244 1267
1245 1268
1246 /* 1269 /*
1247 * GetBusInfo 1270 * GetBusInfo
1248 */ 1271 */
1249 1272
1250 aac_fib_init(fibptr); 1273 aac_fib_init(fibptr);
@@ -1267,6 +1290,8 @@ int aac_get_adapter_info(struct aac_dev* dev)
1267 1, 1, 1290 1, 1,
1268 NULL, NULL); 1291 NULL, NULL);
1269 1292
1293 /* reasoned default */
1294 dev->maximum_num_physicals = 16;
1270 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) { 1295 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1271 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus); 1296 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1272 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount); 1297 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
@@ -1276,7 +1301,7 @@ int aac_get_adapter_info(struct aac_dev* dev)
1276 char buffer[16]; 1301 char buffer[16];
1277 tmp = le32_to_cpu(dev->adapter_info.kernelrev); 1302 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1278 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n", 1303 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1279 dev->name, 1304 dev->name,
1280 dev->id, 1305 dev->id,
1281 tmp>>24, 1306 tmp>>24,
1282 (tmp>>16)&0xff, 1307 (tmp>>16)&0xff,
@@ -1305,19 +1330,21 @@ int aac_get_adapter_info(struct aac_dev* dev)
1305 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid), 1330 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1306 dev->supplement_adapter_info.VpdInfo.Tsid); 1331 dev->supplement_adapter_info.VpdInfo.Tsid);
1307 } 1332 }
1308 if (!aac_check_reset || 1333 if (!aac_check_reset || ((aac_check_reset != 1) &&
1309 (dev->supplement_adapter_info.SupportedOptions2 & 1334 (dev->supplement_adapter_info.SupportedOptions2 &
1310 le32_to_cpu(AAC_OPTION_IGNORE_RESET))) { 1335 AAC_OPTION_IGNORE_RESET))) {
1311 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n", 1336 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1312 dev->name, dev->id); 1337 dev->name, dev->id);
1313 } 1338 }
1314 } 1339 }
1315 1340
1341 dev->cache_protected = 0;
1342 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1343 AAC_FEATURE_JBOD) != 0);
1316 dev->nondasd_support = 0; 1344 dev->nondasd_support = 0;
1317 dev->raid_scsi_mode = 0; 1345 dev->raid_scsi_mode = 0;
1318 if(dev->adapter_info.options & AAC_OPT_NONDASD){ 1346 if(dev->adapter_info.options & AAC_OPT_NONDASD)
1319 dev->nondasd_support = 1; 1347 dev->nondasd_support = 1;
1320 }
1321 1348
1322 /* 1349 /*
1323 * If the firmware supports ROMB RAID/SCSI mode and we are currently 1350 * If the firmware supports ROMB RAID/SCSI mode and we are currently
@@ -1338,11 +1365,10 @@ int aac_get_adapter_info(struct aac_dev* dev)
1338 if (dev->raid_scsi_mode != 0) 1365 if (dev->raid_scsi_mode != 0)
1339 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n", 1366 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1340 dev->name, dev->id); 1367 dev->name, dev->id);
1341 1368
1342 if(nondasd != -1) { 1369 if (nondasd != -1)
1343 dev->nondasd_support = (nondasd!=0); 1370 dev->nondasd_support = (nondasd!=0);
1344 } 1371 if(dev->nondasd_support != 0) {
1345 if(dev->nondasd_support != 0){
1346 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id); 1372 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1347 } 1373 }
1348 1374
@@ -1371,12 +1397,14 @@ int aac_get_adapter_info(struct aac_dev* dev)
1371 rcode = -ENOMEM; 1397 rcode = -ENOMEM;
1372 } 1398 }
1373 } 1399 }
1374 /* 1400 /*
1375 * Deal with configuring for the individualized limits of each packet 1401 * Deal with configuring for the individualized limits of each packet
1376 * interface. 1402 * interface.
1377 */ 1403 */
1378 dev->a_ops.adapter_scsi = (dev->dac_support) 1404 dev->a_ops.adapter_scsi = (dev->dac_support)
1379 ? aac_scsi_64 1405 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1406 ? aac_scsi_32_64
1407 : aac_scsi_64)
1380 : aac_scsi_32; 1408 : aac_scsi_32;
1381 if (dev->raw_io_interface) { 1409 if (dev->raw_io_interface) {
1382 dev->a_ops.adapter_bounds = (dev->raw_io_64) 1410 dev->a_ops.adapter_bounds = (dev->raw_io_64)
@@ -1393,8 +1421,8 @@ int aac_get_adapter_info(struct aac_dev* dev)
1393 if (dev->dac_support) { 1421 if (dev->dac_support) {
1394 dev->a_ops.adapter_read = aac_read_block64; 1422 dev->a_ops.adapter_read = aac_read_block64;
1395 dev->a_ops.adapter_write = aac_write_block64; 1423 dev->a_ops.adapter_write = aac_write_block64;
1396 /* 1424 /*
1397 * 38 scatter gather elements 1425 * 38 scatter gather elements
1398 */ 1426 */
1399 dev->scsi_host_ptr->sg_tablesize = 1427 dev->scsi_host_ptr->sg_tablesize =
1400 (dev->max_fib_size - 1428 (dev->max_fib_size -
@@ -1498,9 +1526,8 @@ static void io_callback(void *context, struct fib * fibptr)
1498 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 1526 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1499 0, 0); 1527 0, 0);
1500 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1528 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1501 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer)) 1529 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1502 ? sizeof(scsicmd->sense_buffer) 1530 SCSI_SENSE_BUFFERSIZE));
1503 : sizeof(dev->fsa_dev[cid].sense_data));
1504 } 1531 }
1505 aac_fib_complete(fibptr); 1532 aac_fib_complete(fibptr);
1506 aac_fib_free(fibptr); 1533 aac_fib_free(fibptr);
@@ -1524,7 +1551,7 @@ static int aac_read(struct scsi_cmnd * scsicmd)
1524 case READ_6: 1551 case READ_6:
1525 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd))); 1552 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1526 1553
1527 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | 1554 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1528 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; 1555 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1529 count = scsicmd->cmnd[4]; 1556 count = scsicmd->cmnd[4];
1530 1557
@@ -1534,32 +1561,32 @@ static int aac_read(struct scsi_cmnd * scsicmd)
1534 case READ_16: 1561 case READ_16:
1535 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd))); 1562 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1536 1563
1537 lba = ((u64)scsicmd->cmnd[2] << 56) | 1564 lba = ((u64)scsicmd->cmnd[2] << 56) |
1538 ((u64)scsicmd->cmnd[3] << 48) | 1565 ((u64)scsicmd->cmnd[3] << 48) |
1539 ((u64)scsicmd->cmnd[4] << 40) | 1566 ((u64)scsicmd->cmnd[4] << 40) |
1540 ((u64)scsicmd->cmnd[5] << 32) | 1567 ((u64)scsicmd->cmnd[5] << 32) |
1541 ((u64)scsicmd->cmnd[6] << 24) | 1568 ((u64)scsicmd->cmnd[6] << 24) |
1542 (scsicmd->cmnd[7] << 16) | 1569 (scsicmd->cmnd[7] << 16) |
1543 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 1570 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1544 count = (scsicmd->cmnd[10] << 24) | 1571 count = (scsicmd->cmnd[10] << 24) |
1545 (scsicmd->cmnd[11] << 16) | 1572 (scsicmd->cmnd[11] << 16) |
1546 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13]; 1573 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1547 break; 1574 break;
1548 case READ_12: 1575 case READ_12:
1549 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd))); 1576 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1550 1577
1551 lba = ((u64)scsicmd->cmnd[2] << 24) | 1578 lba = ((u64)scsicmd->cmnd[2] << 24) |
1552 (scsicmd->cmnd[3] << 16) | 1579 (scsicmd->cmnd[3] << 16) |
1553 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 1580 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1554 count = (scsicmd->cmnd[6] << 24) | 1581 count = (scsicmd->cmnd[6] << 24) |
1555 (scsicmd->cmnd[7] << 16) | 1582 (scsicmd->cmnd[7] << 16) |
1556 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 1583 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1557 break; 1584 break;
1558 default: 1585 default:
1559 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd))); 1586 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1560 1587
1561 lba = ((u64)scsicmd->cmnd[2] << 24) | 1588 lba = ((u64)scsicmd->cmnd[2] << 24) |
1562 (scsicmd->cmnd[3] << 16) | 1589 (scsicmd->cmnd[3] << 16) |
1563 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 1590 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1564 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; 1591 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1565 break; 1592 break;
@@ -1584,7 +1611,7 @@ static int aac_read(struct scsi_cmnd * scsicmd)
1584 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 1611 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1585 return 0; 1612 return 0;
1586 } 1613 }
1587 1614
1588 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status); 1615 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1589 /* 1616 /*
1590 * For some reason, the Fib didn't queue, return QUEUE_FULL 1617 * For some reason, the Fib didn't queue, return QUEUE_FULL
@@ -1619,11 +1646,11 @@ static int aac_write(struct scsi_cmnd * scsicmd)
1619 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */ 1646 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1620 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd))); 1647 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1621 1648
1622 lba = ((u64)scsicmd->cmnd[2] << 56) | 1649 lba = ((u64)scsicmd->cmnd[2] << 56) |
1623 ((u64)scsicmd->cmnd[3] << 48) | 1650 ((u64)scsicmd->cmnd[3] << 48) |
1624 ((u64)scsicmd->cmnd[4] << 40) | 1651 ((u64)scsicmd->cmnd[4] << 40) |
1625 ((u64)scsicmd->cmnd[5] << 32) | 1652 ((u64)scsicmd->cmnd[5] << 32) |
1626 ((u64)scsicmd->cmnd[6] << 24) | 1653 ((u64)scsicmd->cmnd[6] << 24) |
1627 (scsicmd->cmnd[7] << 16) | 1654 (scsicmd->cmnd[7] << 16) |
1628 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 1655 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1629 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) | 1656 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
@@ -1712,8 +1739,8 @@ static void synchronize_callback(void *context, struct fib *fibptr)
1712 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 1739 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1713 0, 0); 1740 0, 0);
1714 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1741 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1715 min(sizeof(dev->fsa_dev[cid].sense_data), 1742 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1716 sizeof(cmd->sense_buffer))); 1743 SCSI_SENSE_BUFFERSIZE));
1717 } 1744 }
1718 1745
1719 aac_fib_complete(fibptr); 1746 aac_fib_complete(fibptr);
@@ -1798,7 +1825,7 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)
1798 if (active) 1825 if (active)
1799 return SCSI_MLQUEUE_DEVICE_BUSY; 1826 return SCSI_MLQUEUE_DEVICE_BUSY;
1800 1827
1801 aac = (struct aac_dev *)scsicmd->device->host->hostdata; 1828 aac = (struct aac_dev *)sdev->host->hostdata;
1802 if (aac->in_reset) 1829 if (aac->in_reset)
1803 return SCSI_MLQUEUE_HOST_BUSY; 1830 return SCSI_MLQUEUE_HOST_BUSY;
1804 1831
@@ -1850,14 +1877,14 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)
1850 * Emulate a SCSI command and queue the required request for the 1877 * Emulate a SCSI command and queue the required request for the
1851 * aacraid firmware. 1878 * aacraid firmware.
1852 */ 1879 */
1853 1880
1854int aac_scsi_cmd(struct scsi_cmnd * scsicmd) 1881int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1855{ 1882{
1856 u32 cid; 1883 u32 cid;
1857 struct Scsi_Host *host = scsicmd->device->host; 1884 struct Scsi_Host *host = scsicmd->device->host;
1858 struct aac_dev *dev = (struct aac_dev *)host->hostdata; 1885 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1859 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev; 1886 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1860 1887
1861 if (fsa_dev_ptr == NULL) 1888 if (fsa_dev_ptr == NULL)
1862 return -1; 1889 return -1;
1863 /* 1890 /*
@@ -1898,7 +1925,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1898 } 1925 }
1899 } 1926 }
1900 } else { /* check for physical non-dasd devices */ 1927 } else { /* check for physical non-dasd devices */
1901 if ((dev->nondasd_support == 1) || expose_physicals) { 1928 if (dev->nondasd_support || expose_physicals ||
1929 dev->jbod) {
1902 if (dev->in_reset) 1930 if (dev->in_reset)
1903 return -1; 1931 return -1;
1904 return aac_send_srb_fib(scsicmd); 1932 return aac_send_srb_fib(scsicmd);
@@ -1913,7 +1941,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1913 * else Command for the controller itself 1941 * else Command for the controller itself
1914 */ 1942 */
1915 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */ 1943 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1916 (scsicmd->cmnd[0] != TEST_UNIT_READY)) 1944 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1917 { 1945 {
1918 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0])); 1946 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1919 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1947 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
@@ -1922,9 +1950,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1922 SENCODE_INVALID_COMMAND, 1950 SENCODE_INVALID_COMMAND,
1923 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0); 1951 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1924 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1952 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1925 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer)) 1953 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1926 ? sizeof(scsicmd->sense_buffer) 1954 SCSI_SENSE_BUFFERSIZE));
1927 : sizeof(dev->fsa_dev[cid].sense_data));
1928 scsicmd->scsi_done(scsicmd); 1955 scsicmd->scsi_done(scsicmd);
1929 return 0; 1956 return 0;
1930 } 1957 }
@@ -1939,7 +1966,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1939 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid)); 1966 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
1940 memset(&inq_data, 0, sizeof (struct inquiry_data)); 1967 memset(&inq_data, 0, sizeof (struct inquiry_data));
1941 1968
1942 if (scsicmd->cmnd[1] & 0x1 ) { 1969 if (scsicmd->cmnd[1] & 0x1) {
1943 char *arr = (char *)&inq_data; 1970 char *arr = (char *)&inq_data;
1944 1971
1945 /* EVPD bit set */ 1972 /* EVPD bit set */
@@ -1974,10 +2001,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1974 ASENCODE_NO_SENSE, 0, 7, 2, 0); 2001 ASENCODE_NO_SENSE, 0, 7, 2, 0);
1975 memcpy(scsicmd->sense_buffer, 2002 memcpy(scsicmd->sense_buffer,
1976 &dev->fsa_dev[cid].sense_data, 2003 &dev->fsa_dev[cid].sense_data,
1977 (sizeof(dev->fsa_dev[cid].sense_data) > 2004 min_t(size_t,
1978 sizeof(scsicmd->sense_buffer)) 2005 sizeof(dev->fsa_dev[cid].sense_data),
1979 ? sizeof(scsicmd->sense_buffer) 2006 SCSI_SENSE_BUFFERSIZE));
1980 : sizeof(dev->fsa_dev[cid].sense_data));
1981 } 2007 }
1982 scsicmd->scsi_done(scsicmd); 2008 scsicmd->scsi_done(scsicmd);
1983 return 0; 2009 return 0;
@@ -2092,7 +2118,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2092 mode_buf[2] = 0; /* Device-specific param, 2118 mode_buf[2] = 0; /* Device-specific param,
2093 bit 8: 0/1 = write enabled/protected 2119 bit 8: 0/1 = write enabled/protected
2094 bit 4: 0/1 = FUA enabled */ 2120 bit 4: 0/1 = FUA enabled */
2095 if (dev->raw_io_interface) 2121 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2096 mode_buf[2] = 0x10; 2122 mode_buf[2] = 0x10;
2097 mode_buf[3] = 0; /* Block descriptor length */ 2123 mode_buf[3] = 0; /* Block descriptor length */
2098 if (((scsicmd->cmnd[2] & 0x3f) == 8) || 2124 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
@@ -2100,7 +2126,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2100 mode_buf[0] = 6; 2126 mode_buf[0] = 6;
2101 mode_buf[4] = 8; 2127 mode_buf[4] = 8;
2102 mode_buf[5] = 1; 2128 mode_buf[5] = 1;
2103 mode_buf[6] = 0x04; /* WCE */ 2129 mode_buf[6] = ((aac_cache & 6) == 2)
2130 ? 0 : 0x04; /* WCE */
2104 mode_buf_length = 7; 2131 mode_buf_length = 7;
2105 if (mode_buf_length > scsicmd->cmnd[4]) 2132 if (mode_buf_length > scsicmd->cmnd[4])
2106 mode_buf_length = scsicmd->cmnd[4]; 2133 mode_buf_length = scsicmd->cmnd[4];
@@ -2123,7 +2150,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2123 mode_buf[3] = 0; /* Device-specific param, 2150 mode_buf[3] = 0; /* Device-specific param,
2124 bit 8: 0/1 = write enabled/protected 2151 bit 8: 0/1 = write enabled/protected
2125 bit 4: 0/1 = FUA enabled */ 2152 bit 4: 0/1 = FUA enabled */
2126 if (dev->raw_io_interface) 2153 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2127 mode_buf[3] = 0x10; 2154 mode_buf[3] = 0x10;
2128 mode_buf[4] = 0; /* reserved */ 2155 mode_buf[4] = 0; /* reserved */
2129 mode_buf[5] = 0; /* reserved */ 2156 mode_buf[5] = 0; /* reserved */
@@ -2134,7 +2161,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2134 mode_buf[1] = 9; 2161 mode_buf[1] = 9;
2135 mode_buf[8] = 8; 2162 mode_buf[8] = 8;
2136 mode_buf[9] = 1; 2163 mode_buf[9] = 1;
2137 mode_buf[10] = 0x04; /* WCE */ 2164 mode_buf[10] = ((aac_cache & 6) == 2)
2165 ? 0 : 0x04; /* WCE */
2138 mode_buf_length = 11; 2166 mode_buf_length = 11;
2139 if (mode_buf_length > scsicmd->cmnd[8]) 2167 if (mode_buf_length > scsicmd->cmnd[8])
2140 mode_buf_length = scsicmd->cmnd[8]; 2168 mode_buf_length = scsicmd->cmnd[8];
@@ -2179,7 +2207,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2179 return 0; 2207 return 0;
2180 } 2208 }
2181 2209
2182 switch (scsicmd->cmnd[0]) 2210 switch (scsicmd->cmnd[0])
2183 { 2211 {
2184 case READ_6: 2212 case READ_6:
2185 case READ_10: 2213 case READ_10:
@@ -2192,11 +2220,11 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2192 * corresponds to a container. Needed to convert 2220 * corresponds to a container. Needed to convert
2193 * containers to /dev/sd device names 2221 * containers to /dev/sd device names
2194 */ 2222 */
2195 2223
2196 if (scsicmd->request->rq_disk) 2224 if (scsicmd->request->rq_disk)
2197 strlcpy(fsa_dev_ptr[cid].devname, 2225 strlcpy(fsa_dev_ptr[cid].devname,
2198 scsicmd->request->rq_disk->disk_name, 2226 scsicmd->request->rq_disk->disk_name,
2199 min(sizeof(fsa_dev_ptr[cid].devname), 2227 min(sizeof(fsa_dev_ptr[cid].devname),
2200 sizeof(scsicmd->request->rq_disk->disk_name) + 1)); 2228 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2201 2229
2202 return aac_read(scsicmd); 2230 return aac_read(scsicmd);
@@ -2210,9 +2238,16 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2210 return aac_write(scsicmd); 2238 return aac_write(scsicmd);
2211 2239
2212 case SYNCHRONIZE_CACHE: 2240 case SYNCHRONIZE_CACHE:
2241 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2242 scsicmd->result = DID_OK << 16 |
2243 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2244 scsicmd->scsi_done(scsicmd);
2245 return 0;
2246 }
2213 /* Issue FIB to tell Firmware to flush it's cache */ 2247 /* Issue FIB to tell Firmware to flush it's cache */
2214 return aac_synchronize(scsicmd); 2248 if ((aac_cache & 6) != 2)
2215 2249 return aac_synchronize(scsicmd);
2250 /* FALLTHRU */
2216 default: 2251 default:
2217 /* 2252 /*
2218 * Unhandled commands 2253 * Unhandled commands
@@ -2223,9 +2258,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2223 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND, 2258 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2224 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0); 2259 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
2225 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 2260 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2226 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer)) 2261 min_t(size_t,
2227 ? sizeof(scsicmd->sense_buffer) 2262 sizeof(dev->fsa_dev[cid].sense_data),
2228 : sizeof(dev->fsa_dev[cid].sense_data)); 2263 SCSI_SENSE_BUFFERSIZE));
2229 scsicmd->scsi_done(scsicmd); 2264 scsicmd->scsi_done(scsicmd);
2230 return 0; 2265 return 0;
2231 } 2266 }
@@ -2243,7 +2278,7 @@ static int query_disk(struct aac_dev *dev, void __user *arg)
2243 return -EFAULT; 2278 return -EFAULT;
2244 if (qd.cnum == -1) 2279 if (qd.cnum == -1)
2245 qd.cnum = qd.id; 2280 qd.cnum = qd.id;
2246 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) 2281 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2247 { 2282 {
2248 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers) 2283 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2249 return -EINVAL; 2284 return -EINVAL;
@@ -2370,7 +2405,7 @@ static void aac_srb_callback(void *context, struct fib * fibptr)
2370 2405
2371 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */ 2406 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2372 /* 2407 /*
2373 * Calculate resid for sg 2408 * Calculate resid for sg
2374 */ 2409 */
2375 2410
2376 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd) 2411 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
@@ -2385,10 +2420,8 @@ static void aac_srb_callback(void *context, struct fib * fibptr)
2385 if (le32_to_cpu(srbreply->status) != ST_OK){ 2420 if (le32_to_cpu(srbreply->status) != ST_OK){
2386 int len; 2421 int len;
2387 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status)); 2422 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2388 len = (le32_to_cpu(srbreply->sense_data_size) > 2423 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2389 sizeof(scsicmd->sense_buffer)) ? 2424 SCSI_SENSE_BUFFERSIZE);
2390 sizeof(scsicmd->sense_buffer) :
2391 le32_to_cpu(srbreply->sense_data_size);
2392 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 2425 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2393 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len); 2426 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2394 } 2427 }
@@ -2412,7 +2445,7 @@ static void aac_srb_callback(void *context, struct fib * fibptr)
2412 case WRITE_12: 2445 case WRITE_12:
2413 case READ_16: 2446 case READ_16:
2414 case WRITE_16: 2447 case WRITE_16:
2415 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) { 2448 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
2416 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n"); 2449 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2417 } else { 2450 } else {
2418 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n"); 2451 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
@@ -2481,26 +2514,23 @@ static void aac_srb_callback(void *context, struct fib * fibptr)
2481 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n", 2514 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2482 le32_to_cpu(srbreply->srb_status) & 0x3F, 2515 le32_to_cpu(srbreply->srb_status) & 0x3F,
2483 aac_get_status_string( 2516 aac_get_status_string(
2484 le32_to_cpu(srbreply->srb_status) & 0x3F), 2517 le32_to_cpu(srbreply->srb_status) & 0x3F),
2485 scsicmd->cmnd[0], 2518 scsicmd->cmnd[0],
2486 le32_to_cpu(srbreply->scsi_status)); 2519 le32_to_cpu(srbreply->scsi_status));
2487#endif 2520#endif
2488 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8; 2521 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2489 break; 2522 break;
2490 } 2523 }
2491 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition 2524 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
2492 int len; 2525 int len;
2493 scsicmd->result |= SAM_STAT_CHECK_CONDITION; 2526 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2494 len = (le32_to_cpu(srbreply->sense_data_size) > 2527 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2495 sizeof(scsicmd->sense_buffer)) ? 2528 SCSI_SENSE_BUFFERSIZE);
2496 sizeof(scsicmd->sense_buffer) :
2497 le32_to_cpu(srbreply->sense_data_size);
2498#ifdef AAC_DETAILED_STATUS_INFO 2529#ifdef AAC_DETAILED_STATUS_INFO
2499 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n", 2530 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2500 le32_to_cpu(srbreply->status), len); 2531 le32_to_cpu(srbreply->status), len);
2501#endif 2532#endif
2502 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len); 2533 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2503
2504 } 2534 }
2505 /* 2535 /*
2506 * OR in the scsi status (already shifted up a bit) 2536 * OR in the scsi status (already shifted up a bit)
@@ -2517,7 +2547,7 @@ static void aac_srb_callback(void *context, struct fib * fibptr)
2517 * aac_send_scb_fib 2547 * aac_send_scb_fib
2518 * @scsicmd: the scsi command block 2548 * @scsicmd: the scsi command block
2519 * 2549 *
2520 * This routine will form a FIB and fill in the aac_srb from the 2550 * This routine will form a FIB and fill in the aac_srb from the
2521 * scsicmd passed in. 2551 * scsicmd passed in.
2522 */ 2552 */
2523 2553
@@ -2731,7 +2761,7 @@ static struct aac_srb_status_info srb_status_info[] = {
2731 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"}, 2761 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2732 { SRB_STATUS_NOT_STARTED, "Not Started"}, 2762 { SRB_STATUS_NOT_STARTED, "Not Started"},
2733 { SRB_STATUS_NOT_IN_USE, "Not In Use"}, 2763 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2734 { SRB_STATUS_FORCE_ABORT, "Force Abort"}, 2764 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2735 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"}, 2765 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2736 { 0xff, "Unknown Error"} 2766 { 0xff, "Unknown Error"}
2737}; 2767};