2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/slab.h>
32 #include <linux/completion.h>
33 #include <linux/blkdev.h>
34 #include <linux/dma-mapping.h>
35 #include <asm/semaphore.h>
36 #include <asm/uaccess.h>
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_cmnd.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_host.h>
45 /* values for inqd_pdt: Peripheral device type in plain English */
46 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
47 #define INQD_PDT_PROC 0x03 /* Processor device */
48 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
49 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
50 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
51 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
53 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
54 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
60 #define SENCODE_NO_SENSE 0x00
61 #define SENCODE_END_OF_DATA 0x00
62 #define SENCODE_BECOMING_READY 0x04
63 #define SENCODE_INIT_CMD_REQUIRED 0x04
64 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65 #define SENCODE_INVALID_COMMAND 0x20
66 #define SENCODE_LBA_OUT_OF_RANGE 0x21
67 #define SENCODE_INVALID_CDB_FIELD 0x24
68 #define SENCODE_LUN_NOT_SUPPORTED 0x25
69 #define SENCODE_INVALID_PARAM_FIELD 0x26
70 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
71 #define SENCODE_PARAM_VALUE_INVALID 0x26
72 #define SENCODE_RESET_OCCURRED 0x29
73 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
77 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
79 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80 #define SENCODE_OVERLAPPED_COMMAND 0x4E
83 * Additional sense codes
86 #define ASENCODE_NO_SENSE 0x00
87 #define ASENCODE_END_OF_DATA 0x05
88 #define ASENCODE_BECOMING_READY 0x01
89 #define ASENCODE_INIT_CMD_REQUIRED 0x02
90 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91 #define ASENCODE_INVALID_COMMAND 0x00
92 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
93 #define ASENCODE_INVALID_CDB_FIELD 0x00
94 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
95 #define ASENCODE_INVALID_PARAM_FIELD 0x00
96 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97 #define ASENCODE_PARAM_VALUE_INVALID 0x02
98 #define ASENCODE_RESET_OCCURRED 0x00
99 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106 #define ASENCODE_OVERLAPPED_COMMAND 0x00
108 #define BYTE0(x) (unsigned char)(x)
109 #define BYTE1(x) (unsigned char)((x) >> 8)
110 #define BYTE2(x) (unsigned char)((x) >> 16)
111 #define BYTE3(x) (unsigned char)((x) >> 24)
113 /*------------------------------------------------------------------------------
114 * S T R U C T S / T Y P E D E F S
115 *----------------------------------------------------------------------------*/
116 /* SCSI inquiry data */
117 struct inquiry_data {
118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq; /* RMB | Device Type Qualifier */
120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len; /* Additional length (n-4) */
123 u8 inqd_pad1[2];/* Reserved - must be zero */
124 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
125 u8 inqd_vid[8]; /* Vendor ID */
126 u8 inqd_pid[16];/* Product ID */
127 u8 inqd_prl[4]; /* Product Revision Level */
131 * M O D U L E G L O B A L S
134 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
136 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
137 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
138 #ifdef AAC_DETAILED_STATUS_INFO
139 static char *aac_get_status_string(u32 status);
143 * Non dasd selection is handled entirely in aachba now
146 static int nondasd = -1;
147 static int dacmode = -1;
150 int startup_timeout = 180;
151 int aif_timeout = 120;
153 module_param(nondasd, int, S_IRUGO|S_IWUSR);
154 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
155 module_param(dacmode, int, S_IRUGO|S_IWUSR);
156 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
157 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
158 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on");
159 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
160 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for adapter to have it's kernel up and\nrunning. This is typically adjusted for large systems that do not have a BIOS.");
161 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
162 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for applications to pick up AIFs before\nderegistering them. This is typically adjusted for heavily burdened systems.");
165 module_param(numacb, int, S_IRUGO|S_IWUSR);
166 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid values are 512 and down. Default is to use suggestion from Firmware.");
169 module_param(acbsize, int, S_IRUGO|S_IWUSR);
170 MODULE_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.");
172 int update_interval = 30 * 60;
173 module_param(update_interval, int, S_IRUGO|S_IWUSR);
174 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync updates issued to adapter.");
176 int check_interval = 24 * 60 * 60;
177 module_param(check_interval, int, S_IRUGO|S_IWUSR);
178 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health checks.");
181 module_param(check_reset, int, S_IRUGO|S_IWUSR);
182 MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the adapter.");
184 int expose_physicals = -1;
185 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
186 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
188 int aac_reset_devices = 0;
189 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
190 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
192 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
193 struct fib *fibptr) {
194 struct scsi_device *device;
196 if (unlikely(!scsicmd || !scsicmd->scsi_done )) {
197 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
198 aac_fib_complete(fibptr);
199 aac_fib_free(fibptr);
202 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
203 device = scsicmd->device;
204 if (unlikely(!device || !scsi_device_online(device))) {
205 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
206 aac_fib_complete(fibptr);
207 aac_fib_free(fibptr);
214 * aac_get_config_status - check the adapter configuration
215 * @common: adapter to query
217 * Query config status, and commit the configuration if needed.
219 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
224 if (!(fibptr = aac_fib_alloc(dev)))
227 aac_fib_init(fibptr);
229 struct aac_get_config_status *dinfo;
230 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
232 dinfo->command = cpu_to_le32(VM_ContainerConfig);
233 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
234 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
237 status = aac_fib_send(ContainerCommand,
239 sizeof (struct aac_get_config_status),
244 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
246 struct aac_get_config_status_resp *reply
247 = (struct aac_get_config_status_resp *) fib_data(fibptr);
248 dprintk((KERN_WARNING
249 "aac_get_config_status: response=%d status=%d action=%d\n",
250 le32_to_cpu(reply->response),
251 le32_to_cpu(reply->status),
252 le32_to_cpu(reply->data.action)));
253 if ((le32_to_cpu(reply->response) != ST_OK) ||
254 (le32_to_cpu(reply->status) != CT_OK) ||
255 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
256 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
260 aac_fib_complete(fibptr);
261 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
263 if ((aac_commit == 1) || commit_flag) {
264 struct aac_commit_config * dinfo;
265 aac_fib_init(fibptr);
266 dinfo = (struct aac_commit_config *) fib_data(fibptr);
268 dinfo->command = cpu_to_le32(VM_ContainerConfig);
269 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
271 status = aac_fib_send(ContainerCommand,
273 sizeof (struct aac_commit_config),
277 aac_fib_complete(fibptr);
278 } else if (aac_commit == 0) {
280 "aac_get_config_status: Foreign device configurations are being ignored\n");
283 aac_fib_free(fibptr);
288 * aac_get_containers - list containers
289 * @common: adapter to probe
291 * Make a list of all containers on this controller
293 int aac_get_containers(struct aac_dev *dev)
295 struct fsa_dev_info *fsa_dev_ptr;
299 struct aac_get_container_count *dinfo;
300 struct aac_get_container_count_resp *dresp;
301 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
303 if (!(fibptr = aac_fib_alloc(dev)))
306 aac_fib_init(fibptr);
307 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
308 dinfo->command = cpu_to_le32(VM_ContainerConfig);
309 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
311 status = aac_fib_send(ContainerCommand,
313 sizeof (struct aac_get_container_count),
318 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
319 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
320 aac_fib_complete(fibptr);
322 aac_fib_free(fibptr);
324 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
325 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
326 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
331 dev->fsa_dev = fsa_dev_ptr;
332 dev->maximum_num_containers = maximum_num_containers;
334 for (index = 0; index < dev->maximum_num_containers; ) {
335 fsa_dev_ptr[index].devname[0] = '\0';
337 status = aac_probe_container(dev, index);
340 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
345 * If there are no more containers, then stop asking.
347 if (++index >= status)
353 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
357 struct scatterlist *sg = scsi_sglist(scsicmd);
359 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
360 transfer_len = min(sg->length, len + offset);
362 transfer_len -= offset;
363 if (buf && transfer_len > 0)
364 memcpy(buf + offset, data, transfer_len);
366 kunmap_atomic(buf - sg->offset, KM_IRQ0);
370 static void get_container_name_callback(void *context, struct fib * fibptr)
372 struct aac_get_name_resp * get_name_reply;
373 struct scsi_cmnd * scsicmd;
375 scsicmd = (struct scsi_cmnd *) context;
377 if (!aac_valid_context(scsicmd, fibptr))
380 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
381 BUG_ON(fibptr == NULL);
383 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
384 /* Failure is irrelevant, using default value instead */
385 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
386 && (get_name_reply->data[0] != '\0')) {
387 char *sp = get_name_reply->data;
388 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
392 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
393 int count = sizeof(d);
396 *dp++ = (*sp) ? *sp++ : ' ';
397 } while (--count > 0);
398 aac_internal_transfer(scsicmd, d,
399 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
403 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
405 aac_fib_complete(fibptr);
406 aac_fib_free(fibptr);
407 scsicmd->scsi_done(scsicmd);
411 * aac_get_container_name - get container name, none blocking.
413 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
416 struct aac_get_name *dinfo;
417 struct fib * cmd_fibcontext;
418 struct aac_dev * dev;
420 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
422 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
425 aac_fib_init(cmd_fibcontext);
426 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
428 dinfo->command = cpu_to_le32(VM_ContainerConfig);
429 dinfo->type = cpu_to_le32(CT_READ_NAME);
430 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
431 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
433 status = aac_fib_send(ContainerCommand,
435 sizeof (struct aac_get_name),
438 (fib_callback) get_container_name_callback,
442 * Check that the command queued to the controller
444 if (status == -EINPROGRESS) {
445 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
449 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
450 aac_fib_complete(cmd_fibcontext);
451 aac_fib_free(cmd_fibcontext);
455 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
457 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
459 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
460 return aac_scsi_cmd(scsicmd);
462 scsicmd->result = DID_NO_CONNECT << 16;
463 scsicmd->scsi_done(scsicmd);
467 static void _aac_probe_container2(void * context, struct fib * fibptr)
469 struct fsa_dev_info *fsa_dev_ptr;
470 int (*callback)(struct scsi_cmnd *);
471 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
474 if (!aac_valid_context(scsicmd, fibptr))
477 scsicmd->SCp.Status = 0;
478 fsa_dev_ptr = fibptr->dev->fsa_dev;
480 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
481 fsa_dev_ptr += scmd_id(scsicmd);
483 if ((le32_to_cpu(dresp->status) == ST_OK) &&
484 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
485 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
486 fsa_dev_ptr->valid = 1;
487 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
489 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
490 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
491 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
493 if ((fsa_dev_ptr->valid & 1) == 0)
494 fsa_dev_ptr->valid = 0;
495 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
497 aac_fib_complete(fibptr);
498 aac_fib_free(fibptr);
499 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
500 scsicmd->SCp.ptr = NULL;
501 (*callback)(scsicmd);
505 static void _aac_probe_container1(void * context, struct fib * fibptr)
507 struct scsi_cmnd * scsicmd;
508 struct aac_mount * dresp;
509 struct aac_query_mount *dinfo;
512 dresp = (struct aac_mount *) fib_data(fibptr);
513 dresp->mnt[0].capacityhigh = 0;
514 if ((le32_to_cpu(dresp->status) != ST_OK) ||
515 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
516 _aac_probe_container2(context, fibptr);
519 scsicmd = (struct scsi_cmnd *) context;
521 if (!aac_valid_context(scsicmd, fibptr))
524 aac_fib_init(fibptr);
526 dinfo = (struct aac_query_mount *)fib_data(fibptr);
528 dinfo->command = cpu_to_le32(VM_NameServe64);
529 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
530 dinfo->type = cpu_to_le32(FT_FILESYS);
532 status = aac_fib_send(ContainerCommand,
534 sizeof(struct aac_query_mount),
537 _aac_probe_container2,
540 * Check that the command queued to the controller
542 if (status == -EINPROGRESS)
543 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
544 else if (status < 0) {
545 /* Inherit results from VM_NameServe, if any */
546 dresp->status = cpu_to_le32(ST_OK);
547 _aac_probe_container2(context, fibptr);
551 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
554 int status = -ENOMEM;
556 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
557 struct aac_query_mount *dinfo;
559 aac_fib_init(fibptr);
561 dinfo = (struct aac_query_mount *)fib_data(fibptr);
563 dinfo->command = cpu_to_le32(VM_NameServe);
564 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
565 dinfo->type = cpu_to_le32(FT_FILESYS);
566 scsicmd->SCp.ptr = (char *)callback;
568 status = aac_fib_send(ContainerCommand,
570 sizeof(struct aac_query_mount),
573 _aac_probe_container1,
576 * Check that the command queued to the controller
578 if (status == -EINPROGRESS) {
579 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
583 scsicmd->SCp.ptr = NULL;
584 aac_fib_complete(fibptr);
585 aac_fib_free(fibptr);
589 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
591 fsa_dev_ptr += scmd_id(scsicmd);
592 if ((fsa_dev_ptr->valid & 1) == 0) {
593 fsa_dev_ptr->valid = 0;
594 return (*callback)(scsicmd);
602 * aac_probe_container - query a logical volume
603 * @dev: device to query
604 * @cid: container identifier
606 * Queries the controller about the given volume. The volume information
607 * is updated in the struct fsa_dev_info structure rather than returned.
609 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
611 scsicmd->device = NULL;
615 int aac_probe_container(struct aac_dev *dev, int cid)
617 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
618 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
621 if (!scsicmd || !scsidev) {
626 scsicmd->list.next = NULL;
627 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
629 scsicmd->device = scsidev;
630 scsidev->sdev_state = 0;
632 scsidev->host = dev->scsi_host_ptr;
634 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
635 while (scsicmd->device == scsidev)
638 status = scsicmd->SCp.Status;
643 /* Local Structure to set SCSI inquiry data strings */
645 char vid[8]; /* Vendor ID */
646 char pid[16]; /* Product ID */
647 char prl[4]; /* Product Revision Level */
651 * InqStrCopy - string merge
652 * @a: string to copy from
653 * @b: string to copy to
655 * Copy a String from one location to another
659 static void inqstrcpy(char *a, char *b)
666 static char *container_types[] = {
692 /* Function: setinqstr
694 * Arguments: [1] pointer to void [1] int
696 * Purpose: Sets SCSI inquiry data strings for vendor, product
697 * and revision level. Allows strings to be set in platform dependant
698 * files instead of in OS dependant driver source.
701 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
703 struct scsi_inq *str;
705 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
706 memset(str, ' ', sizeof(*str));
708 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
709 char * cp = dev->supplement_adapter_info.AdapterTypeText;
710 int c = sizeof(str->vid);
711 while (*cp && *cp != ' ' && --c)
715 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
718 while (*cp && *cp != ' ')
722 /* last six chars reserved for vol type */
724 if (strlen(cp) > sizeof(str->pid)) {
725 c = cp[sizeof(str->pid)];
726 cp[sizeof(str->pid)] = '\0';
728 inqstrcpy (cp, str->pid);
730 cp[sizeof(str->pid)] = c;
732 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
734 inqstrcpy (mp->vname, str->vid);
735 /* last six chars reserved for vol type */
736 inqstrcpy (mp->model, str->pid);
739 if (tindex < ARRAY_SIZE(container_types)){
740 char *findit = str->pid;
742 for ( ; *findit != ' '; findit++); /* walk till we find a space */
743 /* RAID is superfluous in the context of a RAID device */
744 if (memcmp(findit-4, "RAID", 4) == 0)
745 *(findit -= 4) = ' ';
746 if (((findit - str->pid) + strlen(container_types[tindex]))
747 < (sizeof(str->pid) + sizeof(str->prl)))
748 inqstrcpy (container_types[tindex], findit + 1);
750 inqstrcpy ("V1.0", str->prl);
753 static void get_container_serial_callback(void *context, struct fib * fibptr)
755 struct aac_get_serial_resp * get_serial_reply;
756 struct scsi_cmnd * scsicmd;
758 BUG_ON(fibptr == NULL);
760 scsicmd = (struct scsi_cmnd *) context;
761 if (!aac_valid_context(scsicmd, fibptr))
764 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
765 /* Failure is irrelevant, using default value instead */
766 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
770 sp[1] = scsicmd->cmnd[2];
772 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
773 le32_to_cpu(get_serial_reply->uid));
774 aac_internal_transfer(scsicmd, sp, 0, sizeof(sp));
777 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
779 aac_fib_complete(fibptr);
780 aac_fib_free(fibptr);
781 scsicmd->scsi_done(scsicmd);
785 * aac_get_container_serial - get container serial, none blocking.
787 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
790 struct aac_get_serial *dinfo;
791 struct fib * cmd_fibcontext;
792 struct aac_dev * dev;
794 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
796 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
799 aac_fib_init(cmd_fibcontext);
800 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
802 dinfo->command = cpu_to_le32(VM_ContainerConfig);
803 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
804 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
806 status = aac_fib_send(ContainerCommand,
808 sizeof (struct aac_get_serial),
811 (fib_callback) get_container_serial_callback,
815 * Check that the command queued to the controller
817 if (status == -EINPROGRESS) {
818 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
822 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
823 aac_fib_complete(cmd_fibcontext);
824 aac_fib_free(cmd_fibcontext);
828 /* Function: setinqserial
830 * Arguments: [1] pointer to void [1] int
832 * Purpose: Sets SCSI Unit Serial number.
833 * This is a fake. We should read a proper
834 * serial number from the container. <SuSE>But
835 * without docs it's quite hard to do it :-)
836 * So this will have to do in the meantime.</SuSE>
839 static int setinqserial(struct aac_dev *dev, void *data, int cid)
842 * This breaks array migration.
844 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
845 le32_to_cpu(dev->adapter_info.serial[0]), cid);
848 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
849 u8 a_sense_code, u8 incorrect_length,
850 u8 bit_pointer, u16 field_pointer,
853 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
854 sense_buf[1] = 0; /* Segment number, always zero */
856 if (incorrect_length) {
857 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
858 sense_buf[3] = BYTE3(residue);
859 sense_buf[4] = BYTE2(residue);
860 sense_buf[5] = BYTE1(residue);
861 sense_buf[6] = BYTE0(residue);
863 sense_buf[2] = sense_key; /* Sense key */
865 if (sense_key == ILLEGAL_REQUEST)
866 sense_buf[7] = 10; /* Additional sense length */
868 sense_buf[7] = 6; /* Additional sense length */
870 sense_buf[12] = sense_code; /* Additional sense code */
871 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
872 if (sense_key == ILLEGAL_REQUEST) {
875 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
876 sense_buf[15] = 0x80;/* Std sense key specific field */
877 /* Illegal parameter is in the parameter block */
879 if (sense_code == SENCODE_INVALID_CDB_FIELD)
880 sense_buf[15] = 0xc0;/* Std sense key specific field */
881 /* Illegal parameter is in the CDB block */
882 sense_buf[15] |= bit_pointer;
883 sense_buf[16] = field_pointer >> 8; /* MSB */
884 sense_buf[17] = field_pointer; /* LSB */
888 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
890 if (lba & 0xffffffff00000000LL) {
891 int cid = scmd_id(cmd);
892 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
893 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
894 SAM_STAT_CHECK_CONDITION;
895 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
897 SENCODE_INTERNAL_TARGET_FAILURE,
898 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
900 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
901 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
902 ? sizeof(cmd->sense_buffer)
903 : sizeof(dev->fsa_dev[cid].sense_data));
910 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
915 static void io_callback(void *context, struct fib * fibptr);
917 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
920 struct aac_raw_io *readcmd;
922 readcmd = (struct aac_raw_io *) fib_data(fib);
923 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
924 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
925 readcmd->count = cpu_to_le32(count<<9);
926 readcmd->cid = cpu_to_le16(scmd_id(cmd));
927 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
928 readcmd->bpTotal = 0;
929 readcmd->bpComplete = 0;
931 aac_build_sgraw(cmd, &readcmd->sg);
932 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
933 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
935 * Now send the Fib to the adapter
937 return aac_fib_send(ContainerRawIo,
942 (fib_callback) io_callback,
946 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
949 struct aac_read64 *readcmd;
951 readcmd = (struct aac_read64 *) fib_data(fib);
952 readcmd->command = cpu_to_le32(VM_CtHostRead64);
953 readcmd->cid = cpu_to_le16(scmd_id(cmd));
954 readcmd->sector_count = cpu_to_le16(count);
955 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
959 aac_build_sg64(cmd, &readcmd->sg);
960 fibsize = sizeof(struct aac_read64) +
961 ((le32_to_cpu(readcmd->sg.count) - 1) *
962 sizeof (struct sgentry64));
963 BUG_ON (fibsize > (fib->dev->max_fib_size -
964 sizeof(struct aac_fibhdr)));
966 * Now send the Fib to the adapter
968 return aac_fib_send(ContainerCommand64,
973 (fib_callback) io_callback,
977 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
980 struct aac_read *readcmd;
982 readcmd = (struct aac_read *) fib_data(fib);
983 readcmd->command = cpu_to_le32(VM_CtBlockRead);
984 readcmd->cid = cpu_to_le16(scmd_id(cmd));
985 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
986 readcmd->count = cpu_to_le32(count * 512);
988 aac_build_sg(cmd, &readcmd->sg);
989 fibsize = sizeof(struct aac_read) +
990 ((le32_to_cpu(readcmd->sg.count) - 1) *
991 sizeof (struct sgentry));
992 BUG_ON (fibsize > (fib->dev->max_fib_size -
993 sizeof(struct aac_fibhdr)));
995 * Now send the Fib to the adapter
997 return aac_fib_send(ContainerCommand,
1002 (fib_callback) io_callback,
1006 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1009 struct aac_raw_io *writecmd;
1011 writecmd = (struct aac_raw_io *) fib_data(fib);
1012 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1013 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1014 writecmd->count = cpu_to_le32(count<<9);
1015 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1016 writecmd->flags = fua ?
1017 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
1018 cpu_to_le16(IO_TYPE_WRITE);
1019 writecmd->bpTotal = 0;
1020 writecmd->bpComplete = 0;
1022 aac_build_sgraw(cmd, &writecmd->sg);
1023 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1024 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1026 * Now send the Fib to the adapter
1028 return aac_fib_send(ContainerRawIo,
1033 (fib_callback) io_callback,
1037 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1040 struct aac_write64 *writecmd;
1042 writecmd = (struct aac_write64 *) fib_data(fib);
1043 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1044 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1045 writecmd->sector_count = cpu_to_le16(count);
1046 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1048 writecmd->flags = 0;
1050 aac_build_sg64(cmd, &writecmd->sg);
1051 fibsize = sizeof(struct aac_write64) +
1052 ((le32_to_cpu(writecmd->sg.count) - 1) *
1053 sizeof (struct sgentry64));
1054 BUG_ON (fibsize > (fib->dev->max_fib_size -
1055 sizeof(struct aac_fibhdr)));
1057 * Now send the Fib to the adapter
1059 return aac_fib_send(ContainerCommand64,
1064 (fib_callback) io_callback,
1068 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1071 struct aac_write *writecmd;
1073 writecmd = (struct aac_write *) fib_data(fib);
1074 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1075 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1076 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1077 writecmd->count = cpu_to_le32(count * 512);
1078 writecmd->sg.count = cpu_to_le32(1);
1079 /* ->stable is not used - it did mean which type of write */
1081 aac_build_sg(cmd, &writecmd->sg);
1082 fibsize = sizeof(struct aac_write) +
1083 ((le32_to_cpu(writecmd->sg.count) - 1) *
1084 sizeof (struct sgentry));
1085 BUG_ON (fibsize > (fib->dev->max_fib_size -
1086 sizeof(struct aac_fibhdr)));
1088 * Now send the Fib to the adapter
1090 return aac_fib_send(ContainerCommand,
1095 (fib_callback) io_callback,
1099 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1101 struct aac_srb * srbcmd;
1106 switch(cmd->sc_data_direction){
1110 case DMA_BIDIRECTIONAL:
1111 flag = SRB_DataIn | SRB_DataOut;
1113 case DMA_FROM_DEVICE:
1117 default: /* shuts up some versions of gcc */
1118 flag = SRB_NoDataXfer;
1122 srbcmd = (struct aac_srb*) fib_data(fib);
1123 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1124 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1125 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1126 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1127 srbcmd->flags = cpu_to_le32(flag);
1128 timeout = cmd->timeout_per_command/HZ;
1131 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1132 srbcmd->retry_limit = 0; /* Obsolete parameter */
1133 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1137 static void aac_srb_callback(void *context, struct fib * fibptr);
1139 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1142 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1144 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1145 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1147 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1148 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1150 * Build Scatter/Gather list
1152 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1153 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1154 sizeof (struct sgentry64));
1155 BUG_ON (fibsize > (fib->dev->max_fib_size -
1156 sizeof(struct aac_fibhdr)));
1159 * Now send the Fib to the adapter
1161 return aac_fib_send(ScsiPortCommand64, fib,
1162 fibsize, FsaNormal, 0, 1,
1163 (fib_callback) aac_srb_callback,
1167 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1170 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1172 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1173 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1175 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1176 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1178 * Build Scatter/Gather list
1180 fibsize = sizeof (struct aac_srb) +
1181 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1182 sizeof (struct sgentry));
1183 BUG_ON (fibsize > (fib->dev->max_fib_size -
1184 sizeof(struct aac_fibhdr)));
1187 * Now send the Fib to the adapter
1189 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1190 (fib_callback) aac_srb_callback, (void *) cmd);
1193 int aac_get_adapter_info(struct aac_dev* dev)
1198 struct aac_adapter_info *info;
1199 struct aac_bus_info *command;
1200 struct aac_bus_info_response *bus_info;
1202 if (!(fibptr = aac_fib_alloc(dev)))
1205 aac_fib_init(fibptr);
1206 info = (struct aac_adapter_info *) fib_data(fibptr);
1207 memset(info,0,sizeof(*info));
1209 rcode = aac_fib_send(RequestAdapterInfo,
1213 -1, 1, /* First `interrupt' command uses special wait */
1218 aac_fib_complete(fibptr);
1219 aac_fib_free(fibptr);
1222 memcpy(&dev->adapter_info, info, sizeof(*info));
1224 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1225 struct aac_supplement_adapter_info * info;
1227 aac_fib_init(fibptr);
1229 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1231 memset(info,0,sizeof(*info));
1233 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1242 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
1250 aac_fib_init(fibptr);
1252 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1254 memset(bus_info, 0, sizeof(*bus_info));
1256 command = (struct aac_bus_info *)bus_info;
1258 command->Command = cpu_to_le32(VM_Ioctl);
1259 command->ObjType = cpu_to_le32(FT_DRIVE);
1260 command->MethodId = cpu_to_le32(1);
1261 command->CtlCmd = cpu_to_le32(GetBusInfo);
1263 rcode = aac_fib_send(ContainerCommand,
1270 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1271 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1272 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1275 if (!dev->in_reset) {
1277 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1278 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1284 le32_to_cpu(dev->adapter_info.kernelbuild),
1285 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1286 dev->supplement_adapter_info.BuildDate);
1287 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1288 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1290 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1291 le32_to_cpu(dev->adapter_info.monitorbuild));
1292 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1293 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1295 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1296 le32_to_cpu(dev->adapter_info.biosbuild));
1298 if (aac_show_serial_number(
1299 shost_to_class(dev->scsi_host_ptr), buffer))
1300 printk(KERN_INFO "%s%d: serial %s",
1301 dev->name, dev->id, buffer);
1302 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1303 printk(KERN_INFO "%s%d: TSID %.*s\n",
1305 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1306 dev->supplement_adapter_info.VpdInfo.Tsid);
1309 (dev->supplement_adapter_info.SupportedOptions2 &
1310 le32_to_cpu(AAC_OPTION_IGNORE_RESET))) {
1311 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1312 dev->name, dev->id);
1316 dev->nondasd_support = 0;
1317 dev->raid_scsi_mode = 0;
1318 if(dev->adapter_info.options & AAC_OPT_NONDASD){
1319 dev->nondasd_support = 1;
1323 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1324 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1325 * force nondasd support on. If we decide to allow the non-dasd flag
1326 * additional changes changes will have to be made to support
1327 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1328 * changed to support the new dev->raid_scsi_mode flag instead of
1329 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1330 * function aac_detect will have to be modified where it sets up the
1331 * max number of channels based on the aac->nondasd_support flag only.
1333 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1334 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1335 dev->nondasd_support = 1;
1336 dev->raid_scsi_mode = 1;
1338 if (dev->raid_scsi_mode != 0)
1339 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1340 dev->name, dev->id);
1343 dev->nondasd_support = (nondasd!=0);
1345 if(dev->nondasd_support != 0){
1346 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1349 dev->dac_support = 0;
1350 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1351 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1352 dev->dac_support = 1;
1356 dev->dac_support = (dacmode!=0);
1358 if(dev->dac_support != 0) {
1359 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1360 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1361 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1362 dev->name, dev->id);
1363 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1364 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1365 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1366 dev->name, dev->id);
1367 dev->dac_support = 0;
1369 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1370 dev->name, dev->id);
1375 * Deal with configuring for the individualized limits of each packet
1378 dev->a_ops.adapter_scsi = (dev->dac_support)
1381 if (dev->raw_io_interface) {
1382 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1385 dev->a_ops.adapter_read = aac_read_raw_io;
1386 dev->a_ops.adapter_write = aac_write_raw_io;
1388 dev->a_ops.adapter_bounds = aac_bounds_32;
1389 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1390 sizeof(struct aac_fibhdr) -
1391 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1392 sizeof(struct sgentry);
1393 if (dev->dac_support) {
1394 dev->a_ops.adapter_read = aac_read_block64;
1395 dev->a_ops.adapter_write = aac_write_block64;
1397 * 38 scatter gather elements
1399 dev->scsi_host_ptr->sg_tablesize =
1400 (dev->max_fib_size -
1401 sizeof(struct aac_fibhdr) -
1402 sizeof(struct aac_write64) +
1403 sizeof(struct sgentry64)) /
1404 sizeof(struct sgentry64);
1406 dev->a_ops.adapter_read = aac_read_block;
1407 dev->a_ops.adapter_write = aac_write_block;
1409 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1410 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1412 * Worst case size that could cause sg overflow when
1413 * we break up SG elements that are larger than 64KB.
1414 * Would be nice if we could tell the SCSI layer what
1415 * the maximum SG element size can be. Worst case is
1416 * (sg_tablesize-1) 4KB elements with one 64KB
1418 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1420 dev->scsi_host_ptr->max_sectors =
1421 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1425 aac_fib_complete(fibptr);
1426 aac_fib_free(fibptr);
1432 static void io_callback(void *context, struct fib * fibptr)
1434 struct aac_dev *dev;
1435 struct aac_read_reply *readreply;
1436 struct scsi_cmnd *scsicmd;
1439 scsicmd = (struct scsi_cmnd *) context;
1441 if (!aac_valid_context(scsicmd, fibptr))
1445 cid = scmd_id(scsicmd);
1447 if (nblank(dprintk(x))) {
1449 switch (scsicmd->cmnd[0]) {
1452 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1453 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1457 lba = ((u64)scsicmd->cmnd[2] << 56) |
1458 ((u64)scsicmd->cmnd[3] << 48) |
1459 ((u64)scsicmd->cmnd[4] << 40) |
1460 ((u64)scsicmd->cmnd[5] << 32) |
1461 ((u64)scsicmd->cmnd[6] << 24) |
1462 (scsicmd->cmnd[7] << 16) |
1463 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1467 lba = ((u64)scsicmd->cmnd[2] << 24) |
1468 (scsicmd->cmnd[3] << 16) |
1469 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1472 lba = ((u64)scsicmd->cmnd[2] << 24) |
1473 (scsicmd->cmnd[3] << 16) |
1474 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1478 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1479 smp_processor_id(), (unsigned long long)lba, jiffies);
1482 BUG_ON(fibptr == NULL);
1484 scsi_dma_unmap(scsicmd);
1486 readreply = (struct aac_read_reply *)fib_data(fibptr);
1487 if (le32_to_cpu(readreply->status) == ST_OK)
1488 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1490 #ifdef AAC_DETAILED_STATUS_INFO
1491 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1492 le32_to_cpu(readreply->status));
1494 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1495 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1497 SENCODE_INTERNAL_TARGET_FAILURE,
1498 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1500 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1501 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1502 ? sizeof(scsicmd->sense_buffer)
1503 : sizeof(dev->fsa_dev[cid].sense_data));
1505 aac_fib_complete(fibptr);
1506 aac_fib_free(fibptr);
1508 scsicmd->scsi_done(scsicmd);
1511 static int aac_read(struct scsi_cmnd * scsicmd)
1516 struct aac_dev *dev;
1517 struct fib * cmd_fibcontext;
1519 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1521 * Get block address and transfer length
1523 switch (scsicmd->cmnd[0]) {
1525 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1527 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1528 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1529 count = scsicmd->cmnd[4];
1535 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1537 lba = ((u64)scsicmd->cmnd[2] << 56) |
1538 ((u64)scsicmd->cmnd[3] << 48) |
1539 ((u64)scsicmd->cmnd[4] << 40) |
1540 ((u64)scsicmd->cmnd[5] << 32) |
1541 ((u64)scsicmd->cmnd[6] << 24) |
1542 (scsicmd->cmnd[7] << 16) |
1543 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1544 count = (scsicmd->cmnd[10] << 24) |
1545 (scsicmd->cmnd[11] << 16) |
1546 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1549 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1551 lba = ((u64)scsicmd->cmnd[2] << 24) |
1552 (scsicmd->cmnd[3] << 16) |
1553 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1554 count = (scsicmd->cmnd[6] << 24) |
1555 (scsicmd->cmnd[7] << 16) |
1556 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1559 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1561 lba = ((u64)scsicmd->cmnd[2] << 24) |
1562 (scsicmd->cmnd[3] << 16) |
1563 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1564 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1567 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1568 smp_processor_id(), (unsigned long long)lba, jiffies));
1569 if (aac_adapter_bounds(dev,scsicmd,lba))
1572 * Alocate and initialize a Fib
1574 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1578 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1581 * Check that the command queued to the controller
1583 if (status == -EINPROGRESS) {
1584 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1588 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1590 * For some reason, the Fib didn't queue, return QUEUE_FULL
1592 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1593 scsicmd->scsi_done(scsicmd);
1594 aac_fib_complete(cmd_fibcontext);
1595 aac_fib_free(cmd_fibcontext);
1599 static int aac_write(struct scsi_cmnd * scsicmd)
1605 struct aac_dev *dev;
1606 struct fib * cmd_fibcontext;
1608 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1610 * Get block address and transfer length
1612 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1614 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1615 count = scsicmd->cmnd[4];
1619 } 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)));
1622 lba = ((u64)scsicmd->cmnd[2] << 56) |
1623 ((u64)scsicmd->cmnd[3] << 48) |
1624 ((u64)scsicmd->cmnd[4] << 40) |
1625 ((u64)scsicmd->cmnd[5] << 32) |
1626 ((u64)scsicmd->cmnd[6] << 24) |
1627 (scsicmd->cmnd[7] << 16) |
1628 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1629 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1630 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1631 fua = scsicmd->cmnd[1] & 0x8;
1632 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1633 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1635 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1636 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1637 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1638 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1639 fua = scsicmd->cmnd[1] & 0x8;
1641 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1642 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1643 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1644 fua = scsicmd->cmnd[1] & 0x8;
1646 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1647 smp_processor_id(), (unsigned long long)lba, jiffies));
1648 if (aac_adapter_bounds(dev,scsicmd,lba))
1651 * Allocate and initialize a Fib then setup a BlockWrite command
1653 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1654 scsicmd->result = DID_ERROR << 16;
1655 scsicmd->scsi_done(scsicmd);
1659 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1662 * Check that the command queued to the controller
1664 if (status == -EINPROGRESS) {
1665 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1669 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1671 * For some reason, the Fib didn't queue, return QUEUE_FULL
1673 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1674 scsicmd->scsi_done(scsicmd);
1676 aac_fib_complete(cmd_fibcontext);
1677 aac_fib_free(cmd_fibcontext);
1681 static void synchronize_callback(void *context, struct fib *fibptr)
1683 struct aac_synchronize_reply *synchronizereply;
1684 struct scsi_cmnd *cmd;
1688 if (!aac_valid_context(cmd, fibptr))
1691 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1692 smp_processor_id(), jiffies));
1693 BUG_ON(fibptr == NULL);
1696 synchronizereply = fib_data(fibptr);
1697 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1698 cmd->result = DID_OK << 16 |
1699 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1701 struct scsi_device *sdev = cmd->device;
1702 struct aac_dev *dev = fibptr->dev;
1703 u32 cid = sdev_id(sdev);
1705 "synchronize_callback: synchronize failed, status = %d\n",
1706 le32_to_cpu(synchronizereply->status));
1707 cmd->result = DID_OK << 16 |
1708 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1709 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1711 SENCODE_INTERNAL_TARGET_FAILURE,
1712 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1714 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1715 min(sizeof(dev->fsa_dev[cid].sense_data),
1716 sizeof(cmd->sense_buffer)));
1719 aac_fib_complete(fibptr);
1720 aac_fib_free(fibptr);
1721 cmd->scsi_done(cmd);
1724 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1727 struct fib *cmd_fibcontext;
1728 struct aac_synchronize *synchronizecmd;
1729 struct scsi_cmnd *cmd;
1730 struct scsi_device *sdev = scsicmd->device;
1732 struct aac_dev *aac;
1733 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1734 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1735 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1736 unsigned long flags;
1739 * Wait for all outstanding queued commands to complete to this
1740 * specific target (block).
1742 spin_lock_irqsave(&sdev->list_lock, flags);
1743 list_for_each_entry(cmd, &sdev->cmd_list, list)
1744 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1748 if (cmd->cmnd[0] == WRITE_6) {
1749 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1750 (cmd->cmnd[2] << 8) |
1752 cmnd_count = cmd->cmnd[4];
1753 if (cmnd_count == 0)
1755 } else if (cmd->cmnd[0] == WRITE_16) {
1756 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1757 ((u64)cmd->cmnd[3] << 48) |
1758 ((u64)cmd->cmnd[4] << 40) |
1759 ((u64)cmd->cmnd[5] << 32) |
1760 ((u64)cmd->cmnd[6] << 24) |
1761 (cmd->cmnd[7] << 16) |
1762 (cmd->cmnd[8] << 8) |
1764 cmnd_count = (cmd->cmnd[10] << 24) |
1765 (cmd->cmnd[11] << 16) |
1766 (cmd->cmnd[12] << 8) |
1768 } else if (cmd->cmnd[0] == WRITE_12) {
1769 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1770 (cmd->cmnd[3] << 16) |
1771 (cmd->cmnd[4] << 8) |
1773 cmnd_count = (cmd->cmnd[6] << 24) |
1774 (cmd->cmnd[7] << 16) |
1775 (cmd->cmnd[8] << 8) |
1777 } else if (cmd->cmnd[0] == WRITE_10) {
1778 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1779 (cmd->cmnd[3] << 16) |
1780 (cmd->cmnd[4] << 8) |
1782 cmnd_count = (cmd->cmnd[7] << 8) |
1786 if (((cmnd_lba + cmnd_count) < lba) ||
1787 (count && ((lba + count) < cmnd_lba)))
1793 spin_unlock_irqrestore(&sdev->list_lock, flags);
1796 * Yield the processor (requeue for later)
1799 return SCSI_MLQUEUE_DEVICE_BUSY;
1801 aac = (struct aac_dev *)scsicmd->device->host->hostdata;
1803 return SCSI_MLQUEUE_HOST_BUSY;
1806 * Allocate and initialize a Fib
1808 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1809 return SCSI_MLQUEUE_HOST_BUSY;
1811 aac_fib_init(cmd_fibcontext);
1813 synchronizecmd = fib_data(cmd_fibcontext);
1814 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1815 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1816 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
1817 synchronizecmd->count =
1818 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1821 * Now send the Fib to the adapter
1823 status = aac_fib_send(ContainerCommand,
1825 sizeof(struct aac_synchronize),
1828 (fib_callback)synchronize_callback,
1832 * Check that the command queued to the controller
1834 if (status == -EINPROGRESS) {
1835 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1840 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1841 aac_fib_complete(cmd_fibcontext);
1842 aac_fib_free(cmd_fibcontext);
1843 return SCSI_MLQUEUE_HOST_BUSY;
1847 * aac_scsi_cmd() - Process SCSI command
1848 * @scsicmd: SCSI command block
1850 * Emulate a SCSI command and queue the required request for the
1854 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1857 struct Scsi_Host *host = scsicmd->device->host;
1858 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1859 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1861 if (fsa_dev_ptr == NULL)
1864 * If the bus, id or lun is out of range, return fail
1865 * Test does not apply to ID 16, the pseudo id for the controller
1868 cid = scmd_id(scsicmd);
1869 if (cid != host->this_id) {
1870 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
1871 if((cid >= dev->maximum_num_containers) ||
1872 (scsicmd->device->lun != 0)) {
1873 scsicmd->result = DID_NO_CONNECT << 16;
1874 scsicmd->scsi_done(scsicmd);
1879 * If the target container doesn't exist, it may have
1880 * been newly created
1882 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1883 switch (scsicmd->cmnd[0]) {
1884 case SERVICE_ACTION_IN:
1885 if (!(dev->raw_io_interface) ||
1886 !(dev->raw_io_64) ||
1887 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1891 case TEST_UNIT_READY:
1894 return _aac_probe_container(scsicmd,
1895 aac_probe_container_callback2);
1900 } else { /* check for physical non-dasd devices */
1901 if ((dev->nondasd_support == 1) || expose_physicals) {
1904 return aac_send_srb_fib(scsicmd);
1906 scsicmd->result = DID_NO_CONNECT << 16;
1907 scsicmd->scsi_done(scsicmd);
1913 * else Command for the controller itself
1915 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1916 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1918 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;
1920 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1922 SENCODE_INVALID_COMMAND,
1923 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1924 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1925 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1926 ? sizeof(scsicmd->sense_buffer)
1927 : sizeof(dev->fsa_dev[cid].sense_data));
1928 scsicmd->scsi_done(scsicmd);
1933 /* Handle commands here that don't really require going out to the adapter */
1934 switch (scsicmd->cmnd[0]) {
1937 struct inquiry_data inq_data;
1939 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
1940 memset(&inq_data, 0, sizeof (struct inquiry_data));
1942 if (scsicmd->cmnd[1] & 0x1 ) {
1943 char *arr = (char *)&inq_data;
1946 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
1947 INQD_PDT_PROC : INQD_PDT_DA;
1948 if (scsicmd->cmnd[2] == 0) {
1949 /* supported vital product data pages */
1953 arr[1] = scsicmd->cmnd[2];
1954 aac_internal_transfer(scsicmd, &inq_data, 0,
1956 scsicmd->result = DID_OK << 16 |
1957 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1958 } else if (scsicmd->cmnd[2] == 0x80) {
1959 /* unit serial number page */
1960 arr[3] = setinqserial(dev, &arr[4],
1962 arr[1] = scsicmd->cmnd[2];
1963 aac_internal_transfer(scsicmd, &inq_data, 0,
1965 return aac_get_container_serial(scsicmd);
1967 /* vpd page not implemented */
1968 scsicmd->result = DID_OK << 16 |
1969 COMMAND_COMPLETE << 8 |
1970 SAM_STAT_CHECK_CONDITION;
1971 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1973 SENCODE_INVALID_CDB_FIELD,
1974 ASENCODE_NO_SENSE, 0, 7, 2, 0);
1975 memcpy(scsicmd->sense_buffer,
1976 &dev->fsa_dev[cid].sense_data,
1977 (sizeof(dev->fsa_dev[cid].sense_data) >
1978 sizeof(scsicmd->sense_buffer))
1979 ? sizeof(scsicmd->sense_buffer)
1980 : sizeof(dev->fsa_dev[cid].sense_data));
1982 scsicmd->scsi_done(scsicmd);
1985 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1986 inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
1987 inq_data.inqd_len = 31;
1988 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1989 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1991 * Set the Vendor, Product, and Revision Level
1992 * see: <vendor>.c i.e. aac.c
1994 if (cid == host->this_id) {
1995 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
1996 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1997 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1998 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1999 scsicmd->scsi_done(scsicmd);
2004 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2005 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2006 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
2007 return aac_get_container_name(scsicmd);
2009 case SERVICE_ACTION_IN:
2010 if (!(dev->raw_io_interface) ||
2011 !(dev->raw_io_64) ||
2012 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2018 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2019 capacity = fsa_dev_ptr[cid].size - 1;
2020 cp[0] = (capacity >> 56) & 0xff;
2021 cp[1] = (capacity >> 48) & 0xff;
2022 cp[2] = (capacity >> 40) & 0xff;
2023 cp[3] = (capacity >> 32) & 0xff;
2024 cp[4] = (capacity >> 24) & 0xff;
2025 cp[5] = (capacity >> 16) & 0xff;
2026 cp[6] = (capacity >> 8) & 0xff;
2027 cp[7] = (capacity >> 0) & 0xff;
2033 aac_internal_transfer(scsicmd, cp, 0,
2034 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
2035 if (sizeof(cp) < scsicmd->cmnd[13]) {
2036 unsigned int len, offset = sizeof(cp);
2038 memset(cp, 0, offset);
2040 len = min_t(size_t, scsicmd->cmnd[13] - offset,
2042 aac_internal_transfer(scsicmd, cp, offset, len);
2043 } while ((offset += len) < scsicmd->cmnd[13]);
2046 /* Do not cache partition table for arrays */
2047 scsicmd->device->removable = 1;
2049 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2050 scsicmd->scsi_done(scsicmd);
2060 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
2061 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2062 capacity = fsa_dev_ptr[cid].size - 1;
2066 cp[0] = (capacity >> 24) & 0xff;
2067 cp[1] = (capacity >> 16) & 0xff;
2068 cp[2] = (capacity >> 8) & 0xff;
2069 cp[3] = (capacity >> 0) & 0xff;
2074 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
2075 /* Do not cache partition table for arrays */
2076 scsicmd->device->removable = 1;
2078 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2079 scsicmd->scsi_done(scsicmd);
2087 int mode_buf_length = 4;
2089 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
2090 mode_buf[0] = 3; /* Mode data length */
2091 mode_buf[1] = 0; /* Medium type - default */
2092 mode_buf[2] = 0; /* Device-specific param,
2093 bit 8: 0/1 = write enabled/protected
2094 bit 4: 0/1 = FUA enabled */
2095 if (dev->raw_io_interface)
2097 mode_buf[3] = 0; /* Block descriptor length */
2098 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2099 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2103 mode_buf[6] = 0x04; /* WCE */
2104 mode_buf_length = 7;
2105 if (mode_buf_length > scsicmd->cmnd[4])
2106 mode_buf_length = scsicmd->cmnd[4];
2108 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
2109 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2110 scsicmd->scsi_done(scsicmd);
2117 int mode_buf_length = 8;
2119 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
2120 mode_buf[0] = 0; /* Mode data length (MSB) */
2121 mode_buf[1] = 6; /* Mode data length (LSB) */
2122 mode_buf[2] = 0; /* Medium type - default */
2123 mode_buf[3] = 0; /* Device-specific param,
2124 bit 8: 0/1 = write enabled/protected
2125 bit 4: 0/1 = FUA enabled */
2126 if (dev->raw_io_interface)
2128 mode_buf[4] = 0; /* reserved */
2129 mode_buf[5] = 0; /* reserved */
2130 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2131 mode_buf[7] = 0; /* Block descriptor length (LSB) */
2132 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2133 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2137 mode_buf[10] = 0x04; /* WCE */
2138 mode_buf_length = 11;
2139 if (mode_buf_length > scsicmd->cmnd[8])
2140 mode_buf_length = scsicmd->cmnd[8];
2142 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
2144 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2145 scsicmd->scsi_done(scsicmd);
2150 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2151 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2152 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2153 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2154 scsicmd->scsi_done(scsicmd);
2157 case ALLOW_MEDIUM_REMOVAL:
2158 dprintk((KERN_DEBUG "LOCK command.\n"));
2159 if (scsicmd->cmnd[4])
2160 fsa_dev_ptr[cid].locked = 1;
2162 fsa_dev_ptr[cid].locked = 0;
2164 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2165 scsicmd->scsi_done(scsicmd);
2168 * These commands are all No-Ops
2170 case TEST_UNIT_READY:
2174 case REASSIGN_BLOCKS:
2177 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2178 scsicmd->scsi_done(scsicmd);
2182 switch (scsicmd->cmnd[0])
2191 * Hack to keep track of ordinal number of the device that
2192 * corresponds to a container. Needed to convert
2193 * containers to /dev/sd device names
2196 if (scsicmd->request->rq_disk)
2197 strlcpy(fsa_dev_ptr[cid].devname,
2198 scsicmd->request->rq_disk->disk_name,
2199 min(sizeof(fsa_dev_ptr[cid].devname),
2200 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2202 return aac_read(scsicmd);
2210 return aac_write(scsicmd);
2212 case SYNCHRONIZE_CACHE:
2213 /* Issue FIB to tell Firmware to flush it's cache */
2214 return aac_synchronize(scsicmd);
2218 * Unhandled commands
2220 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2221 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2222 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
2223 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2224 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
2225 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2226 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
2227 ? sizeof(scsicmd->sense_buffer)
2228 : sizeof(dev->fsa_dev[cid].sense_data));
2229 scsicmd->scsi_done(scsicmd);
2234 static int query_disk(struct aac_dev *dev, void __user *arg)
2236 struct aac_query_disk qd;
2237 struct fsa_dev_info *fsa_dev_ptr;
2239 fsa_dev_ptr = dev->fsa_dev;
2242 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2246 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2248 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2250 qd.instance = dev->scsi_host_ptr->host_no;
2252 qd.id = CONTAINER_TO_ID(qd.cnum);
2253 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2255 else return -EINVAL;
2257 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
2258 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2259 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2261 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2266 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2267 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2269 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2274 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2276 struct aac_delete_disk dd;
2277 struct fsa_dev_info *fsa_dev_ptr;
2279 fsa_dev_ptr = dev->fsa_dev;
2283 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2286 if (dd.cnum >= dev->maximum_num_containers)
2289 * Mark this container as being deleted.
2291 fsa_dev_ptr[dd.cnum].deleted = 1;
2293 * Mark the container as no longer valid
2295 fsa_dev_ptr[dd.cnum].valid = 0;
2299 static int delete_disk(struct aac_dev *dev, void __user *arg)
2301 struct aac_delete_disk dd;
2302 struct fsa_dev_info *fsa_dev_ptr;
2304 fsa_dev_ptr = dev->fsa_dev;
2308 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2311 if (dd.cnum >= dev->maximum_num_containers)
2314 * If the container is locked, it can not be deleted by the API.
2316 if (fsa_dev_ptr[dd.cnum].locked)
2320 * Mark the container as no longer being valid.
2322 fsa_dev_ptr[dd.cnum].valid = 0;
2323 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2328 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2331 case FSACTL_QUERY_DISK:
2332 return query_disk(dev, arg);
2333 case FSACTL_DELETE_DISK:
2334 return delete_disk(dev, arg);
2335 case FSACTL_FORCE_DELETE_DISK:
2336 return force_delete_disk(dev, arg);
2337 case FSACTL_GET_CONTAINERS:
2338 return aac_get_containers(dev);
2347 * @context: the context set in the fib - here it is scsi cmd
2348 * @fibptr: pointer to the fib
2350 * Handles the completion of a scsi command to a non dasd device
2354 static void aac_srb_callback(void *context, struct fib * fibptr)
2356 struct aac_dev *dev;
2357 struct aac_srb_reply *srbreply;
2358 struct scsi_cmnd *scsicmd;
2360 scsicmd = (struct scsi_cmnd *) context;
2362 if (!aac_valid_context(scsicmd, fibptr))
2365 BUG_ON(fibptr == NULL);
2369 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2371 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2373 * Calculate resid for sg
2376 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2377 - le32_to_cpu(srbreply->data_xfer_length));
2379 scsi_dma_unmap(scsicmd);
2382 * First check the fib status
2385 if (le32_to_cpu(srbreply->status) != ST_OK){
2387 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) >
2389 sizeof(scsicmd->sense_buffer)) ?
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;
2393 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2397 * Next check the srb status
2399 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2400 case SRB_STATUS_ERROR_RECOVERY:
2401 case SRB_STATUS_PENDING:
2402 case SRB_STATUS_SUCCESS:
2403 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2405 case SRB_STATUS_DATA_OVERRUN:
2406 switch(scsicmd->cmnd[0]){
2415 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
2416 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2418 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2420 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2423 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2427 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2431 case SRB_STATUS_ABORTED:
2432 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2434 case SRB_STATUS_ABORT_FAILED:
2435 // Not sure about this one - but assuming the hba was trying to abort for some reason
2436 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2438 case SRB_STATUS_PARITY_ERROR:
2439 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2441 case SRB_STATUS_NO_DEVICE:
2442 case SRB_STATUS_INVALID_PATH_ID:
2443 case SRB_STATUS_INVALID_TARGET_ID:
2444 case SRB_STATUS_INVALID_LUN:
2445 case SRB_STATUS_SELECTION_TIMEOUT:
2446 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2449 case SRB_STATUS_COMMAND_TIMEOUT:
2450 case SRB_STATUS_TIMEOUT:
2451 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2454 case SRB_STATUS_BUSY:
2455 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
2458 case SRB_STATUS_BUS_RESET:
2459 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2462 case SRB_STATUS_MESSAGE_REJECTED:
2463 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2465 case SRB_STATUS_REQUEST_FLUSHED:
2466 case SRB_STATUS_ERROR:
2467 case SRB_STATUS_INVALID_REQUEST:
2468 case SRB_STATUS_REQUEST_SENSE_FAILED:
2469 case SRB_STATUS_NO_HBA:
2470 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2471 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2472 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2473 case SRB_STATUS_DELAYED_RETRY:
2474 case SRB_STATUS_BAD_FUNCTION:
2475 case SRB_STATUS_NOT_STARTED:
2476 case SRB_STATUS_NOT_IN_USE:
2477 case SRB_STATUS_FORCE_ABORT:
2478 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2480 #ifdef AAC_DETAILED_STATUS_INFO
2481 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2482 le32_to_cpu(srbreply->srb_status) & 0x3F,
2483 aac_get_status_string(
2484 le32_to_cpu(srbreply->srb_status) & 0x3F),
2486 le32_to_cpu(srbreply->scsi_status));
2488 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2491 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2493 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2494 len = (le32_to_cpu(srbreply->sense_data_size) >
2495 sizeof(scsicmd->sense_buffer)) ?
2496 sizeof(scsicmd->sense_buffer) :
2497 le32_to_cpu(srbreply->sense_data_size);
2498 #ifdef AAC_DETAILED_STATUS_INFO
2499 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2500 le32_to_cpu(srbreply->status), len);
2502 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2506 * OR in the scsi status (already shifted up a bit)
2508 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2510 aac_fib_complete(fibptr);
2511 aac_fib_free(fibptr);
2512 scsicmd->scsi_done(scsicmd);
2518 * @scsicmd: the scsi command block
2520 * This routine will form a FIB and fill in the aac_srb from the
2521 * scsicmd passed in.
2524 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2526 struct fib* cmd_fibcontext;
2527 struct aac_dev* dev;
2530 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2531 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2532 scsicmd->device->lun > 7) {
2533 scsicmd->result = DID_NO_CONNECT << 16;
2534 scsicmd->scsi_done(scsicmd);
2539 * Allocate and initialize a Fib then setup a BlockWrite command
2541 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2544 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2547 * Check that the command queued to the controller
2549 if (status == -EINPROGRESS) {
2550 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2554 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2555 aac_fib_complete(cmd_fibcontext);
2556 aac_fib_free(cmd_fibcontext);
2561 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2563 struct aac_dev *dev;
2564 unsigned long byte_count = 0;
2567 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2568 // Get rid of old data
2570 psg->sg[0].addr = 0;
2571 psg->sg[0].count = 0;
2573 nseg = scsi_dma_map(scsicmd);
2576 struct scatterlist *sg;
2579 psg->count = cpu_to_le32(nseg);
2581 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2582 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2583 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2584 byte_count += sg_dma_len(sg);
2586 /* hba wants the size to be exact */
2587 if (byte_count > scsi_bufflen(scsicmd)) {
2588 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2589 (byte_count - scsi_bufflen(scsicmd));
2590 psg->sg[i-1].count = cpu_to_le32(temp);
2591 byte_count = scsi_bufflen(scsicmd);
2593 /* Check for command underflow */
2594 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2595 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2596 byte_count, scsicmd->underflow);
2603 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2605 struct aac_dev *dev;
2606 unsigned long byte_count = 0;
2610 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2611 // Get rid of old data
2613 psg->sg[0].addr[0] = 0;
2614 psg->sg[0].addr[1] = 0;
2615 psg->sg[0].count = 0;
2617 nseg = scsi_dma_map(scsicmd);
2620 struct scatterlist *sg;
2623 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2624 int count = sg_dma_len(sg);
2625 addr = sg_dma_address(sg);
2626 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2627 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2628 psg->sg[i].count = cpu_to_le32(count);
2629 byte_count += count;
2631 psg->count = cpu_to_le32(nseg);
2632 /* hba wants the size to be exact */
2633 if (byte_count > scsi_bufflen(scsicmd)) {
2634 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2635 (byte_count - scsi_bufflen(scsicmd));
2636 psg->sg[i-1].count = cpu_to_le32(temp);
2637 byte_count = scsi_bufflen(scsicmd);
2639 /* Check for command underflow */
2640 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2641 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2642 byte_count, scsicmd->underflow);
2648 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2650 unsigned long byte_count = 0;
2653 // Get rid of old data
2655 psg->sg[0].next = 0;
2656 psg->sg[0].prev = 0;
2657 psg->sg[0].addr[0] = 0;
2658 psg->sg[0].addr[1] = 0;
2659 psg->sg[0].count = 0;
2660 psg->sg[0].flags = 0;
2662 nseg = scsi_dma_map(scsicmd);
2665 struct scatterlist *sg;
2668 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2669 int count = sg_dma_len(sg);
2670 u64 addr = sg_dma_address(sg);
2671 psg->sg[i].next = 0;
2672 psg->sg[i].prev = 0;
2673 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2674 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2675 psg->sg[i].count = cpu_to_le32(count);
2676 psg->sg[i].flags = 0;
2677 byte_count += count;
2679 psg->count = cpu_to_le32(nseg);
2680 /* hba wants the size to be exact */
2681 if (byte_count > scsi_bufflen(scsicmd)) {
2682 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2683 (byte_count - scsi_bufflen(scsicmd));
2684 psg->sg[i-1].count = cpu_to_le32(temp);
2685 byte_count = scsi_bufflen(scsicmd);
2687 /* Check for command underflow */
2688 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2689 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2690 byte_count, scsicmd->underflow);
2696 #ifdef AAC_DETAILED_STATUS_INFO
2698 struct aac_srb_status_info {
2704 static struct aac_srb_status_info srb_status_info[] = {
2705 { SRB_STATUS_PENDING, "Pending Status"},
2706 { SRB_STATUS_SUCCESS, "Success"},
2707 { SRB_STATUS_ABORTED, "Aborted Command"},
2708 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2709 { SRB_STATUS_ERROR, "Error Event"},
2710 { SRB_STATUS_BUSY, "Device Busy"},
2711 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2712 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2713 { SRB_STATUS_NO_DEVICE, "No Device"},
2714 { SRB_STATUS_TIMEOUT, "Timeout"},
2715 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2716 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2717 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2718 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2719 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2720 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2721 { SRB_STATUS_NO_HBA, "No HBA"},
2722 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2723 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2724 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2725 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2726 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2727 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2728 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2729 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2730 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2731 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2732 { SRB_STATUS_NOT_STARTED, "Not Started"},
2733 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2734 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2735 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2736 { 0xff, "Unknown Error"}
2739 char *aac_get_status_string(u32 status)
2743 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2744 if (srb_status_info[i].status == status)
2745 return srb_status_info[i].str;
2747 return "Bad Status Code";