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 <asm/uaccess.h>
35 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
37 #include <scsi/scsi.h>
38 #include <scsi/scsi_cmnd.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_host.h>
44 /* values for inqd_pdt: Peripheral device type in plain English */
45 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
46 #define INQD_PDT_PROC 0x03 /* Processor device */
47 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
48 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
49 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
50 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
52 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
53 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
59 #define SENCODE_NO_SENSE 0x00
60 #define SENCODE_END_OF_DATA 0x00
61 #define SENCODE_BECOMING_READY 0x04
62 #define SENCODE_INIT_CMD_REQUIRED 0x04
63 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
64 #define SENCODE_INVALID_COMMAND 0x20
65 #define SENCODE_LBA_OUT_OF_RANGE 0x21
66 #define SENCODE_INVALID_CDB_FIELD 0x24
67 #define SENCODE_LUN_NOT_SUPPORTED 0x25
68 #define SENCODE_INVALID_PARAM_FIELD 0x26
69 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
70 #define SENCODE_PARAM_VALUE_INVALID 0x26
71 #define SENCODE_RESET_OCCURRED 0x29
72 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
73 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
74 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
75 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
76 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
77 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
78 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
79 #define SENCODE_OVERLAPPED_COMMAND 0x4E
82 * Additional sense codes
85 #define ASENCODE_NO_SENSE 0x00
86 #define ASENCODE_END_OF_DATA 0x05
87 #define ASENCODE_BECOMING_READY 0x01
88 #define ASENCODE_INIT_CMD_REQUIRED 0x02
89 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
90 #define ASENCODE_INVALID_COMMAND 0x00
91 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
92 #define ASENCODE_INVALID_CDB_FIELD 0x00
93 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
94 #define ASENCODE_INVALID_PARAM_FIELD 0x00
95 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
96 #define ASENCODE_PARAM_VALUE_INVALID 0x02
97 #define ASENCODE_RESET_OCCURRED 0x00
98 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
99 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
100 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
101 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
102 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
103 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
104 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
105 #define ASENCODE_OVERLAPPED_COMMAND 0x00
107 #define BYTE0(x) (unsigned char)(x)
108 #define BYTE1(x) (unsigned char)((x) >> 8)
109 #define BYTE2(x) (unsigned char)((x) >> 16)
110 #define BYTE3(x) (unsigned char)((x) >> 24)
112 /*------------------------------------------------------------------------------
113 * S T R U C T S / T Y P E D E F S
114 *----------------------------------------------------------------------------*/
115 /* SCSI inquiry data */
116 struct inquiry_data {
117 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
118 u8 inqd_dtq; /* RMB | Device Type Qualifier */
119 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
120 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
121 u8 inqd_len; /* Additional length (n-4) */
122 u8 inqd_pad1[2];/* Reserved - must be zero */
123 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
124 u8 inqd_vid[8]; /* Vendor ID */
125 u8 inqd_pid[16];/* Product ID */
126 u8 inqd_prl[4]; /* Product Revision Level */
130 * M O D U L E G L O B A L S
133 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
134 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
135 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
136 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
137 #ifdef AAC_DETAILED_STATUS_INFO
138 static char *aac_get_status_string(u32 status);
142 * Non dasd selection is handled entirely in aachba now
145 static int nondasd = -1;
146 static int aac_cache;
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."
156 module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
157 MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
158 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
159 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
160 "\tbit 2 - Disable only if Battery not protecting Cache");
161 module_param(dacmode, int, S_IRUGO|S_IWUSR);
162 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
164 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
165 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
166 " adapter for foreign arrays.\n"
167 "This is typically needed in systems that do not have a BIOS."
169 module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
170 MODULE_PARM_DESC(msi, "IRQ handling."
171 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
172 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
173 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
174 " adapter to have it's kernel up and\n"
175 "running. This is typically adjusted for large systems that do not"
177 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
178 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
179 " applications to pick up AIFs before\n"
180 "deregistering them. This is typically adjusted for heavily burdened"
184 module_param(numacb, int, S_IRUGO|S_IWUSR);
185 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
186 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
187 " to use suggestion from Firmware.");
190 module_param(acbsize, int, S_IRUGO|S_IWUSR);
191 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
192 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
193 " suggestion from Firmware.");
195 int update_interval = 30 * 60;
196 module_param(update_interval, int, S_IRUGO|S_IWUSR);
197 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
198 " updates issued to adapter.");
200 int check_interval = 24 * 60 * 60;
201 module_param(check_interval, int, S_IRUGO|S_IWUSR);
202 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
205 int aac_check_reset = 1;
206 module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
207 MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
208 " adapter. a value of -1 forces the reset to adapters programmed to"
211 int expose_physicals = -1;
212 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
213 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
214 " -1=protect 0=off, 1=on");
216 int aac_reset_devices;
217 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
218 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
220 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
221 struct fib *fibptr) {
222 struct scsi_device *device;
224 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
225 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
226 aac_fib_complete(fibptr);
227 aac_fib_free(fibptr);
230 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
231 device = scsicmd->device;
232 if (unlikely(!device || !scsi_device_online(device))) {
233 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
234 aac_fib_complete(fibptr);
235 aac_fib_free(fibptr);
242 * aac_get_config_status - check the adapter configuration
243 * @common: adapter to query
245 * Query config status, and commit the configuration if needed.
247 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
252 if (!(fibptr = aac_fib_alloc(dev)))
255 aac_fib_init(fibptr);
257 struct aac_get_config_status *dinfo;
258 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
260 dinfo->command = cpu_to_le32(VM_ContainerConfig);
261 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
262 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
265 status = aac_fib_send(ContainerCommand,
267 sizeof (struct aac_get_config_status),
272 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
274 struct aac_get_config_status_resp *reply
275 = (struct aac_get_config_status_resp *) fib_data(fibptr);
276 dprintk((KERN_WARNING
277 "aac_get_config_status: response=%d status=%d action=%d\n",
278 le32_to_cpu(reply->response),
279 le32_to_cpu(reply->status),
280 le32_to_cpu(reply->data.action)));
281 if ((le32_to_cpu(reply->response) != ST_OK) ||
282 (le32_to_cpu(reply->status) != CT_OK) ||
283 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
284 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
288 aac_fib_complete(fibptr);
289 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
291 if ((aac_commit == 1) || commit_flag) {
292 struct aac_commit_config * dinfo;
293 aac_fib_init(fibptr);
294 dinfo = (struct aac_commit_config *) fib_data(fibptr);
296 dinfo->command = cpu_to_le32(VM_ContainerConfig);
297 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
299 status = aac_fib_send(ContainerCommand,
301 sizeof (struct aac_commit_config),
305 aac_fib_complete(fibptr);
306 } else if (aac_commit == 0) {
308 "aac_get_config_status: Foreign device configurations are being ignored\n");
311 aac_fib_free(fibptr);
316 * aac_get_containers - list containers
317 * @common: adapter to probe
319 * Make a list of all containers on this controller
321 int aac_get_containers(struct aac_dev *dev)
323 struct fsa_dev_info *fsa_dev_ptr;
327 struct aac_get_container_count *dinfo;
328 struct aac_get_container_count_resp *dresp;
329 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
331 if (!(fibptr = aac_fib_alloc(dev)))
334 aac_fib_init(fibptr);
335 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
336 dinfo->command = cpu_to_le32(VM_ContainerConfig);
337 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
339 status = aac_fib_send(ContainerCommand,
341 sizeof (struct aac_get_container_count),
346 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
347 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
348 aac_fib_complete(fibptr);
350 aac_fib_free(fibptr);
352 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
353 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
354 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
359 dev->fsa_dev = fsa_dev_ptr;
360 dev->maximum_num_containers = maximum_num_containers;
362 for (index = 0; index < dev->maximum_num_containers; ) {
363 fsa_dev_ptr[index].devname[0] = '\0';
365 status = aac_probe_container(dev, index);
368 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
373 * If there are no more containers, then stop asking.
375 if (++index >= status)
381 static void get_container_name_callback(void *context, struct fib * fibptr)
383 struct aac_get_name_resp * get_name_reply;
384 struct scsi_cmnd * scsicmd;
386 scsicmd = (struct scsi_cmnd *) context;
388 if (!aac_valid_context(scsicmd, fibptr))
391 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
392 BUG_ON(fibptr == NULL);
394 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
395 /* Failure is irrelevant, using default value instead */
396 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
397 && (get_name_reply->data[0] != '\0')) {
398 char *sp = get_name_reply->data;
399 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
403 struct inquiry_data inq;
404 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
405 int count = sizeof(d);
408 *dp++ = (*sp) ? *sp++ : ' ';
409 } while (--count > 0);
411 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
412 memcpy(inq.inqd_pid, d, sizeof(d));
413 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
417 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
419 aac_fib_complete(fibptr);
420 aac_fib_free(fibptr);
421 scsicmd->scsi_done(scsicmd);
425 * aac_get_container_name - get container name, none blocking.
427 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
430 struct aac_get_name *dinfo;
431 struct fib * cmd_fibcontext;
432 struct aac_dev * dev;
434 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
436 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
439 aac_fib_init(cmd_fibcontext);
440 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
442 dinfo->command = cpu_to_le32(VM_ContainerConfig);
443 dinfo->type = cpu_to_le32(CT_READ_NAME);
444 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
445 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
447 status = aac_fib_send(ContainerCommand,
449 sizeof (struct aac_get_name),
452 (fib_callback)get_container_name_callback,
456 * Check that the command queued to the controller
458 if (status == -EINPROGRESS) {
459 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
463 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
464 aac_fib_complete(cmd_fibcontext);
465 aac_fib_free(cmd_fibcontext);
469 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
471 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
473 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
474 return aac_scsi_cmd(scsicmd);
476 scsicmd->result = DID_NO_CONNECT << 16;
477 scsicmd->scsi_done(scsicmd);
481 static void _aac_probe_container2(void * context, struct fib * fibptr)
483 struct fsa_dev_info *fsa_dev_ptr;
484 int (*callback)(struct scsi_cmnd *);
485 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
488 if (!aac_valid_context(scsicmd, fibptr))
491 scsicmd->SCp.Status = 0;
492 fsa_dev_ptr = fibptr->dev->fsa_dev;
494 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
495 fsa_dev_ptr += scmd_id(scsicmd);
497 if ((le32_to_cpu(dresp->status) == ST_OK) &&
498 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
499 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
500 fsa_dev_ptr->valid = 1;
501 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
503 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
504 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
505 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
507 if ((fsa_dev_ptr->valid & 1) == 0)
508 fsa_dev_ptr->valid = 0;
509 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
511 aac_fib_complete(fibptr);
512 aac_fib_free(fibptr);
513 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
514 scsicmd->SCp.ptr = NULL;
515 (*callback)(scsicmd);
519 static void _aac_probe_container1(void * context, struct fib * fibptr)
521 struct scsi_cmnd * scsicmd;
522 struct aac_mount * dresp;
523 struct aac_query_mount *dinfo;
526 dresp = (struct aac_mount *) fib_data(fibptr);
527 dresp->mnt[0].capacityhigh = 0;
528 if ((le32_to_cpu(dresp->status) != ST_OK) ||
529 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
530 _aac_probe_container2(context, fibptr);
533 scsicmd = (struct scsi_cmnd *) context;
535 if (!aac_valid_context(scsicmd, fibptr))
538 aac_fib_init(fibptr);
540 dinfo = (struct aac_query_mount *)fib_data(fibptr);
542 dinfo->command = cpu_to_le32(VM_NameServe64);
543 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
544 dinfo->type = cpu_to_le32(FT_FILESYS);
546 status = aac_fib_send(ContainerCommand,
548 sizeof(struct aac_query_mount),
551 _aac_probe_container2,
554 * Check that the command queued to the controller
556 if (status == -EINPROGRESS)
557 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
558 else if (status < 0) {
559 /* Inherit results from VM_NameServe, if any */
560 dresp->status = cpu_to_le32(ST_OK);
561 _aac_probe_container2(context, fibptr);
565 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
568 int status = -ENOMEM;
570 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
571 struct aac_query_mount *dinfo;
573 aac_fib_init(fibptr);
575 dinfo = (struct aac_query_mount *)fib_data(fibptr);
577 dinfo->command = cpu_to_le32(VM_NameServe);
578 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
579 dinfo->type = cpu_to_le32(FT_FILESYS);
580 scsicmd->SCp.ptr = (char *)callback;
582 status = aac_fib_send(ContainerCommand,
584 sizeof(struct aac_query_mount),
587 _aac_probe_container1,
590 * Check that the command queued to the controller
592 if (status == -EINPROGRESS) {
593 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
597 scsicmd->SCp.ptr = NULL;
598 aac_fib_complete(fibptr);
599 aac_fib_free(fibptr);
603 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
605 fsa_dev_ptr += scmd_id(scsicmd);
606 if ((fsa_dev_ptr->valid & 1) == 0) {
607 fsa_dev_ptr->valid = 0;
608 return (*callback)(scsicmd);
616 * aac_probe_container - query a logical volume
617 * @dev: device to query
618 * @cid: container identifier
620 * Queries the controller about the given volume. The volume information
621 * is updated in the struct fsa_dev_info structure rather than returned.
623 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
625 scsicmd->device = NULL;
629 int aac_probe_container(struct aac_dev *dev, int cid)
631 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
632 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
635 if (!scsicmd || !scsidev) {
640 scsicmd->list.next = NULL;
641 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
643 scsicmd->device = scsidev;
644 scsidev->sdev_state = 0;
646 scsidev->host = dev->scsi_host_ptr;
648 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
649 while (scsicmd->device == scsidev)
652 status = scsicmd->SCp.Status;
657 /* Local Structure to set SCSI inquiry data strings */
659 char vid[8]; /* Vendor ID */
660 char pid[16]; /* Product ID */
661 char prl[4]; /* Product Revision Level */
665 * InqStrCopy - string merge
666 * @a: string to copy from
667 * @b: string to copy to
669 * Copy a String from one location to another
673 static void inqstrcpy(char *a, char *b)
676 while (*a != (char)0)
680 static char *container_types[] = {
704 char * get_container_type(unsigned tindex)
706 if (tindex >= ARRAY_SIZE(container_types))
707 tindex = ARRAY_SIZE(container_types) - 1;
708 return container_types[tindex];
711 /* Function: setinqstr
713 * Arguments: [1] pointer to void [1] int
715 * Purpose: Sets SCSI inquiry data strings for vendor, product
716 * and revision level. Allows strings to be set in platform dependant
717 * files instead of in OS dependant driver source.
720 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
722 struct scsi_inq *str;
724 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
725 memset(str, ' ', sizeof(*str));
727 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
728 char * cp = dev->supplement_adapter_info.AdapterTypeText;
730 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
731 inqstrcpy("SMC", str->vid);
733 c = sizeof(str->vid);
734 while (*cp && *cp != ' ' && --c)
738 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
741 while (*cp && *cp != ' ')
746 /* last six chars reserved for vol type */
748 if (strlen(cp) > sizeof(str->pid)) {
749 c = cp[sizeof(str->pid)];
750 cp[sizeof(str->pid)] = '\0';
752 inqstrcpy (cp, str->pid);
754 cp[sizeof(str->pid)] = c;
756 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
758 inqstrcpy (mp->vname, str->vid);
759 /* last six chars reserved for vol type */
760 inqstrcpy (mp->model, str->pid);
763 if (tindex < ARRAY_SIZE(container_types)){
764 char *findit = str->pid;
766 for ( ; *findit != ' '; findit++); /* walk till we find a space */
767 /* RAID is superfluous in the context of a RAID device */
768 if (memcmp(findit-4, "RAID", 4) == 0)
769 *(findit -= 4) = ' ';
770 if (((findit - str->pid) + strlen(container_types[tindex]))
771 < (sizeof(str->pid) + sizeof(str->prl)))
772 inqstrcpy (container_types[tindex], findit + 1);
774 inqstrcpy ("V1.0", str->prl);
777 static void get_container_serial_callback(void *context, struct fib * fibptr)
779 struct aac_get_serial_resp * get_serial_reply;
780 struct scsi_cmnd * scsicmd;
782 BUG_ON(fibptr == NULL);
784 scsicmd = (struct scsi_cmnd *) context;
785 if (!aac_valid_context(scsicmd, fibptr))
788 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
789 /* Failure is irrelevant, using default value instead */
790 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
794 sp[1] = scsicmd->cmnd[2];
796 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
797 le32_to_cpu(get_serial_reply->uid));
798 scsi_sg_copy_from_buffer(scsicmd, sp, sizeof(sp));
801 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
803 aac_fib_complete(fibptr);
804 aac_fib_free(fibptr);
805 scsicmd->scsi_done(scsicmd);
809 * aac_get_container_serial - get container serial, none blocking.
811 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
814 struct aac_get_serial *dinfo;
815 struct fib * cmd_fibcontext;
816 struct aac_dev * dev;
818 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
820 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
823 aac_fib_init(cmd_fibcontext);
824 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
826 dinfo->command = cpu_to_le32(VM_ContainerConfig);
827 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
828 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
830 status = aac_fib_send(ContainerCommand,
832 sizeof (struct aac_get_serial),
835 (fib_callback) get_container_serial_callback,
839 * Check that the command queued to the controller
841 if (status == -EINPROGRESS) {
842 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
846 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
847 aac_fib_complete(cmd_fibcontext);
848 aac_fib_free(cmd_fibcontext);
852 /* Function: setinqserial
854 * Arguments: [1] pointer to void [1] int
856 * Purpose: Sets SCSI Unit Serial number.
857 * This is a fake. We should read a proper
858 * serial number from the container. <SuSE>But
859 * without docs it's quite hard to do it :-)
860 * So this will have to do in the meantime.</SuSE>
863 static int setinqserial(struct aac_dev *dev, void *data, int cid)
866 * This breaks array migration.
868 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
869 le32_to_cpu(dev->adapter_info.serial[0]), cid);
872 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
873 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
875 u8 *sense_buf = (u8 *)sense_data;
876 /* Sense data valid, err code 70h */
877 sense_buf[0] = 0x70; /* No info field */
878 sense_buf[1] = 0; /* Segment number, always zero */
880 sense_buf[2] = sense_key; /* Sense key */
882 sense_buf[12] = sense_code; /* Additional sense code */
883 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
885 if (sense_key == ILLEGAL_REQUEST) {
886 sense_buf[7] = 10; /* Additional sense length */
888 sense_buf[15] = bit_pointer;
889 /* Illegal parameter is in the parameter block */
890 if (sense_code == SENCODE_INVALID_CDB_FIELD)
891 sense_buf[15] |= 0xc0;/* Std sense key specific field */
892 /* Illegal parameter is in the CDB block */
893 sense_buf[16] = field_pointer >> 8; /* MSB */
894 sense_buf[17] = field_pointer; /* LSB */
896 sense_buf[7] = 6; /* Additional sense length */
899 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
901 if (lba & 0xffffffff00000000LL) {
902 int cid = scmd_id(cmd);
903 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
904 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
905 SAM_STAT_CHECK_CONDITION;
906 set_sense(&dev->fsa_dev[cid].sense_data,
907 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
908 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
909 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
910 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
911 SCSI_SENSE_BUFFERSIZE));
918 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
923 static void io_callback(void *context, struct fib * fibptr);
925 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
928 struct aac_raw_io *readcmd;
930 readcmd = (struct aac_raw_io *) fib_data(fib);
931 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
932 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
933 readcmd->count = cpu_to_le32(count<<9);
934 readcmd->cid = cpu_to_le16(scmd_id(cmd));
935 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
936 readcmd->bpTotal = 0;
937 readcmd->bpComplete = 0;
939 aac_build_sgraw(cmd, &readcmd->sg);
940 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
941 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
943 * Now send the Fib to the adapter
945 return aac_fib_send(ContainerRawIo,
950 (fib_callback) io_callback,
954 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
957 struct aac_read64 *readcmd;
959 readcmd = (struct aac_read64 *) fib_data(fib);
960 readcmd->command = cpu_to_le32(VM_CtHostRead64);
961 readcmd->cid = cpu_to_le16(scmd_id(cmd));
962 readcmd->sector_count = cpu_to_le16(count);
963 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
967 aac_build_sg64(cmd, &readcmd->sg);
968 fibsize = sizeof(struct aac_read64) +
969 ((le32_to_cpu(readcmd->sg.count) - 1) *
970 sizeof (struct sgentry64));
971 BUG_ON (fibsize > (fib->dev->max_fib_size -
972 sizeof(struct aac_fibhdr)));
974 * Now send the Fib to the adapter
976 return aac_fib_send(ContainerCommand64,
981 (fib_callback) io_callback,
985 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
988 struct aac_read *readcmd;
990 readcmd = (struct aac_read *) fib_data(fib);
991 readcmd->command = cpu_to_le32(VM_CtBlockRead);
992 readcmd->cid = cpu_to_le32(scmd_id(cmd));
993 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
994 readcmd->count = cpu_to_le32(count * 512);
996 aac_build_sg(cmd, &readcmd->sg);
997 fibsize = sizeof(struct aac_read) +
998 ((le32_to_cpu(readcmd->sg.count) - 1) *
999 sizeof (struct sgentry));
1000 BUG_ON (fibsize > (fib->dev->max_fib_size -
1001 sizeof(struct aac_fibhdr)));
1003 * Now send the Fib to the adapter
1005 return aac_fib_send(ContainerCommand,
1010 (fib_callback) io_callback,
1014 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1017 struct aac_raw_io *writecmd;
1019 writecmd = (struct aac_raw_io *) fib_data(fib);
1020 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1021 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1022 writecmd->count = cpu_to_le32(count<<9);
1023 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1024 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1025 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1026 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
1027 cpu_to_le16(IO_TYPE_WRITE);
1028 writecmd->bpTotal = 0;
1029 writecmd->bpComplete = 0;
1031 aac_build_sgraw(cmd, &writecmd->sg);
1032 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1033 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1035 * Now send the Fib to the adapter
1037 return aac_fib_send(ContainerRawIo,
1042 (fib_callback) io_callback,
1046 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1049 struct aac_write64 *writecmd;
1051 writecmd = (struct aac_write64 *) fib_data(fib);
1052 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1053 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1054 writecmd->sector_count = cpu_to_le16(count);
1055 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1057 writecmd->flags = 0;
1059 aac_build_sg64(cmd, &writecmd->sg);
1060 fibsize = sizeof(struct aac_write64) +
1061 ((le32_to_cpu(writecmd->sg.count) - 1) *
1062 sizeof (struct sgentry64));
1063 BUG_ON (fibsize > (fib->dev->max_fib_size -
1064 sizeof(struct aac_fibhdr)));
1066 * Now send the Fib to the adapter
1068 return aac_fib_send(ContainerCommand64,
1073 (fib_callback) io_callback,
1077 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1080 struct aac_write *writecmd;
1082 writecmd = (struct aac_write *) fib_data(fib);
1083 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1084 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1085 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1086 writecmd->count = cpu_to_le32(count * 512);
1087 writecmd->sg.count = cpu_to_le32(1);
1088 /* ->stable is not used - it did mean which type of write */
1090 aac_build_sg(cmd, &writecmd->sg);
1091 fibsize = sizeof(struct aac_write) +
1092 ((le32_to_cpu(writecmd->sg.count) - 1) *
1093 sizeof (struct sgentry));
1094 BUG_ON (fibsize > (fib->dev->max_fib_size -
1095 sizeof(struct aac_fibhdr)));
1097 * Now send the Fib to the adapter
1099 return aac_fib_send(ContainerCommand,
1104 (fib_callback) io_callback,
1108 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1110 struct aac_srb * srbcmd;
1115 switch(cmd->sc_data_direction){
1119 case DMA_BIDIRECTIONAL:
1120 flag = SRB_DataIn | SRB_DataOut;
1122 case DMA_FROM_DEVICE:
1126 default: /* shuts up some versions of gcc */
1127 flag = SRB_NoDataXfer;
1131 srbcmd = (struct aac_srb*) fib_data(fib);
1132 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1133 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1134 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1135 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1136 srbcmd->flags = cpu_to_le32(flag);
1137 timeout = cmd->timeout_per_command/HZ;
1140 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1141 srbcmd->retry_limit = 0; /* Obsolete parameter */
1142 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1146 static void aac_srb_callback(void *context, struct fib * fibptr);
1148 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1151 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1153 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1154 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1156 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1157 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1159 * Build Scatter/Gather list
1161 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1162 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1163 sizeof (struct sgentry64));
1164 BUG_ON (fibsize > (fib->dev->max_fib_size -
1165 sizeof(struct aac_fibhdr)));
1168 * Now send the Fib to the adapter
1170 return aac_fib_send(ScsiPortCommand64, fib,
1171 fibsize, FsaNormal, 0, 1,
1172 (fib_callback) aac_srb_callback,
1176 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1179 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1181 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1182 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1184 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1185 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1187 * Build Scatter/Gather list
1189 fibsize = sizeof (struct aac_srb) +
1190 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1191 sizeof (struct sgentry));
1192 BUG_ON (fibsize > (fib->dev->max_fib_size -
1193 sizeof(struct aac_fibhdr)));
1196 * Now send the Fib to the adapter
1198 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1199 (fib_callback) aac_srb_callback, (void *) cmd);
1202 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1204 if ((sizeof(dma_addr_t) > 4) &&
1205 (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) &&
1206 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1208 return aac_scsi_32(fib, cmd);
1211 int aac_get_adapter_info(struct aac_dev* dev)
1216 struct aac_adapter_info *info;
1217 struct aac_bus_info *command;
1218 struct aac_bus_info_response *bus_info;
1220 if (!(fibptr = aac_fib_alloc(dev)))
1223 aac_fib_init(fibptr);
1224 info = (struct aac_adapter_info *) fib_data(fibptr);
1225 memset(info,0,sizeof(*info));
1227 rcode = aac_fib_send(RequestAdapterInfo,
1231 -1, 1, /* First `interrupt' command uses special wait */
1236 aac_fib_complete(fibptr);
1237 aac_fib_free(fibptr);
1240 memcpy(&dev->adapter_info, info, sizeof(*info));
1242 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1243 struct aac_supplement_adapter_info * sinfo;
1245 aac_fib_init(fibptr);
1247 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1249 memset(sinfo,0,sizeof(*sinfo));
1251 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1260 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
1268 aac_fib_init(fibptr);
1270 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1272 memset(bus_info, 0, sizeof(*bus_info));
1274 command = (struct aac_bus_info *)bus_info;
1276 command->Command = cpu_to_le32(VM_Ioctl);
1277 command->ObjType = cpu_to_le32(FT_DRIVE);
1278 command->MethodId = cpu_to_le32(1);
1279 command->CtlCmd = cpu_to_le32(GetBusInfo);
1281 rcode = aac_fib_send(ContainerCommand,
1288 /* reasoned default */
1289 dev->maximum_num_physicals = 16;
1290 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1291 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1292 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1295 if (!dev->in_reset) {
1297 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1298 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1304 le32_to_cpu(dev->adapter_info.kernelbuild),
1305 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1306 dev->supplement_adapter_info.BuildDate);
1307 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1308 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1310 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1311 le32_to_cpu(dev->adapter_info.monitorbuild));
1312 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1313 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1315 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1316 le32_to_cpu(dev->adapter_info.biosbuild));
1318 if (aac_get_serial_number(
1319 shost_to_class(dev->scsi_host_ptr), buffer))
1320 printk(KERN_INFO "%s%d: serial %s",
1321 dev->name, dev->id, buffer);
1322 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1323 printk(KERN_INFO "%s%d: TSID %.*s\n",
1325 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1326 dev->supplement_adapter_info.VpdInfo.Tsid);
1328 if (!aac_check_reset || ((aac_check_reset == 1) &&
1329 (dev->supplement_adapter_info.SupportedOptions2 &
1330 AAC_OPTION_IGNORE_RESET))) {
1331 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1332 dev->name, dev->id);
1336 dev->cache_protected = 0;
1337 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1338 AAC_FEATURE_JBOD) != 0);
1339 dev->nondasd_support = 0;
1340 dev->raid_scsi_mode = 0;
1341 if(dev->adapter_info.options & AAC_OPT_NONDASD)
1342 dev->nondasd_support = 1;
1345 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1346 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1347 * force nondasd support on. If we decide to allow the non-dasd flag
1348 * additional changes changes will have to be made to support
1349 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1350 * changed to support the new dev->raid_scsi_mode flag instead of
1351 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1352 * function aac_detect will have to be modified where it sets up the
1353 * max number of channels based on the aac->nondasd_support flag only.
1355 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1356 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1357 dev->nondasd_support = 1;
1358 dev->raid_scsi_mode = 1;
1360 if (dev->raid_scsi_mode != 0)
1361 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1362 dev->name, dev->id);
1365 dev->nondasd_support = (nondasd!=0);
1366 if (dev->nondasd_support && !dev->in_reset)
1367 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1369 dev->dac_support = 0;
1370 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1372 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
1373 dev->name, dev->id);
1374 dev->dac_support = 1;
1378 dev->dac_support = (dacmode!=0);
1380 if(dev->dac_support != 0) {
1381 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1382 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1384 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1385 dev->name, dev->id);
1386 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1387 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1388 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1389 dev->name, dev->id);
1390 dev->dac_support = 0;
1392 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1393 dev->name, dev->id);
1398 * Deal with configuring for the individualized limits of each packet
1401 dev->a_ops.adapter_scsi = (dev->dac_support)
1402 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1406 if (dev->raw_io_interface) {
1407 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1410 dev->a_ops.adapter_read = aac_read_raw_io;
1411 dev->a_ops.adapter_write = aac_write_raw_io;
1413 dev->a_ops.adapter_bounds = aac_bounds_32;
1414 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1415 sizeof(struct aac_fibhdr) -
1416 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1417 sizeof(struct sgentry);
1418 if (dev->dac_support) {
1419 dev->a_ops.adapter_read = aac_read_block64;
1420 dev->a_ops.adapter_write = aac_write_block64;
1422 * 38 scatter gather elements
1424 dev->scsi_host_ptr->sg_tablesize =
1425 (dev->max_fib_size -
1426 sizeof(struct aac_fibhdr) -
1427 sizeof(struct aac_write64) +
1428 sizeof(struct sgentry64)) /
1429 sizeof(struct sgentry64);
1431 dev->a_ops.adapter_read = aac_read_block;
1432 dev->a_ops.adapter_write = aac_write_block;
1434 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1435 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1437 * Worst case size that could cause sg overflow when
1438 * we break up SG elements that are larger than 64KB.
1439 * Would be nice if we could tell the SCSI layer what
1440 * the maximum SG element size can be. Worst case is
1441 * (sg_tablesize-1) 4KB elements with one 64KB
1443 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1445 dev->scsi_host_ptr->max_sectors =
1446 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1450 aac_fib_complete(fibptr);
1451 aac_fib_free(fibptr);
1457 static void io_callback(void *context, struct fib * fibptr)
1459 struct aac_dev *dev;
1460 struct aac_read_reply *readreply;
1461 struct scsi_cmnd *scsicmd;
1464 scsicmd = (struct scsi_cmnd *) context;
1466 if (!aac_valid_context(scsicmd, fibptr))
1470 cid = scmd_id(scsicmd);
1472 if (nblank(dprintk(x))) {
1474 switch (scsicmd->cmnd[0]) {
1477 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1478 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1482 lba = ((u64)scsicmd->cmnd[2] << 56) |
1483 ((u64)scsicmd->cmnd[3] << 48) |
1484 ((u64)scsicmd->cmnd[4] << 40) |
1485 ((u64)scsicmd->cmnd[5] << 32) |
1486 ((u64)scsicmd->cmnd[6] << 24) |
1487 (scsicmd->cmnd[7] << 16) |
1488 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1492 lba = ((u64)scsicmd->cmnd[2] << 24) |
1493 (scsicmd->cmnd[3] << 16) |
1494 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1497 lba = ((u64)scsicmd->cmnd[2] << 24) |
1498 (scsicmd->cmnd[3] << 16) |
1499 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1503 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1504 smp_processor_id(), (unsigned long long)lba, jiffies);
1507 BUG_ON(fibptr == NULL);
1509 scsi_dma_unmap(scsicmd);
1511 readreply = (struct aac_read_reply *)fib_data(fibptr);
1512 if (le32_to_cpu(readreply->status) == ST_OK)
1513 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1515 #ifdef AAC_DETAILED_STATUS_INFO
1516 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1517 le32_to_cpu(readreply->status));
1519 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1520 set_sense(&dev->fsa_dev[cid].sense_data,
1521 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1522 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1523 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1524 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1525 SCSI_SENSE_BUFFERSIZE));
1527 aac_fib_complete(fibptr);
1528 aac_fib_free(fibptr);
1530 scsicmd->scsi_done(scsicmd);
1533 static int aac_read(struct scsi_cmnd * scsicmd)
1538 struct aac_dev *dev;
1539 struct fib * cmd_fibcontext;
1541 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1543 * Get block address and transfer length
1545 switch (scsicmd->cmnd[0]) {
1547 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1549 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1550 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1551 count = scsicmd->cmnd[4];
1557 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1559 lba = ((u64)scsicmd->cmnd[2] << 56) |
1560 ((u64)scsicmd->cmnd[3] << 48) |
1561 ((u64)scsicmd->cmnd[4] << 40) |
1562 ((u64)scsicmd->cmnd[5] << 32) |
1563 ((u64)scsicmd->cmnd[6] << 24) |
1564 (scsicmd->cmnd[7] << 16) |
1565 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1566 count = (scsicmd->cmnd[10] << 24) |
1567 (scsicmd->cmnd[11] << 16) |
1568 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1571 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1573 lba = ((u64)scsicmd->cmnd[2] << 24) |
1574 (scsicmd->cmnd[3] << 16) |
1575 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1576 count = (scsicmd->cmnd[6] << 24) |
1577 (scsicmd->cmnd[7] << 16) |
1578 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1581 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1583 lba = ((u64)scsicmd->cmnd[2] << 24) |
1584 (scsicmd->cmnd[3] << 16) |
1585 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1586 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1589 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1590 smp_processor_id(), (unsigned long long)lba, jiffies));
1591 if (aac_adapter_bounds(dev,scsicmd,lba))
1594 * Alocate and initialize a Fib
1596 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1600 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1603 * Check that the command queued to the controller
1605 if (status == -EINPROGRESS) {
1606 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1610 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1612 * For some reason, the Fib didn't queue, return QUEUE_FULL
1614 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1615 scsicmd->scsi_done(scsicmd);
1616 aac_fib_complete(cmd_fibcontext);
1617 aac_fib_free(cmd_fibcontext);
1621 static int aac_write(struct scsi_cmnd * scsicmd)
1627 struct aac_dev *dev;
1628 struct fib * cmd_fibcontext;
1630 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1632 * Get block address and transfer length
1634 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1636 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1637 count = scsicmd->cmnd[4];
1641 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1642 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1644 lba = ((u64)scsicmd->cmnd[2] << 56) |
1645 ((u64)scsicmd->cmnd[3] << 48) |
1646 ((u64)scsicmd->cmnd[4] << 40) |
1647 ((u64)scsicmd->cmnd[5] << 32) |
1648 ((u64)scsicmd->cmnd[6] << 24) |
1649 (scsicmd->cmnd[7] << 16) |
1650 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1651 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1652 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1653 fua = scsicmd->cmnd[1] & 0x8;
1654 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1655 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1657 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1658 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1659 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1660 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1661 fua = scsicmd->cmnd[1] & 0x8;
1663 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1664 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1665 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1666 fua = scsicmd->cmnd[1] & 0x8;
1668 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1669 smp_processor_id(), (unsigned long long)lba, jiffies));
1670 if (aac_adapter_bounds(dev,scsicmd,lba))
1673 * Allocate and initialize a Fib then setup a BlockWrite command
1675 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1676 scsicmd->result = DID_ERROR << 16;
1677 scsicmd->scsi_done(scsicmd);
1681 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1684 * Check that the command queued to the controller
1686 if (status == -EINPROGRESS) {
1687 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1691 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1693 * For some reason, the Fib didn't queue, return QUEUE_FULL
1695 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1696 scsicmd->scsi_done(scsicmd);
1698 aac_fib_complete(cmd_fibcontext);
1699 aac_fib_free(cmd_fibcontext);
1703 static void synchronize_callback(void *context, struct fib *fibptr)
1705 struct aac_synchronize_reply *synchronizereply;
1706 struct scsi_cmnd *cmd;
1710 if (!aac_valid_context(cmd, fibptr))
1713 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1714 smp_processor_id(), jiffies));
1715 BUG_ON(fibptr == NULL);
1718 synchronizereply = fib_data(fibptr);
1719 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1720 cmd->result = DID_OK << 16 |
1721 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1723 struct scsi_device *sdev = cmd->device;
1724 struct aac_dev *dev = fibptr->dev;
1725 u32 cid = sdev_id(sdev);
1727 "synchronize_callback: synchronize failed, status = %d\n",
1728 le32_to_cpu(synchronizereply->status));
1729 cmd->result = DID_OK << 16 |
1730 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1731 set_sense(&dev->fsa_dev[cid].sense_data,
1732 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1733 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1734 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1735 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1736 SCSI_SENSE_BUFFERSIZE));
1739 aac_fib_complete(fibptr);
1740 aac_fib_free(fibptr);
1741 cmd->scsi_done(cmd);
1744 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1747 struct fib *cmd_fibcontext;
1748 struct aac_synchronize *synchronizecmd;
1749 struct scsi_cmnd *cmd;
1750 struct scsi_device *sdev = scsicmd->device;
1752 struct aac_dev *aac;
1753 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1754 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1755 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1756 unsigned long flags;
1759 * Wait for all outstanding queued commands to complete to this
1760 * specific target (block).
1762 spin_lock_irqsave(&sdev->list_lock, flags);
1763 list_for_each_entry(cmd, &sdev->cmd_list, list)
1764 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1768 if (cmd->cmnd[0] == WRITE_6) {
1769 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1770 (cmd->cmnd[2] << 8) |
1772 cmnd_count = cmd->cmnd[4];
1773 if (cmnd_count == 0)
1775 } else if (cmd->cmnd[0] == WRITE_16) {
1776 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1777 ((u64)cmd->cmnd[3] << 48) |
1778 ((u64)cmd->cmnd[4] << 40) |
1779 ((u64)cmd->cmnd[5] << 32) |
1780 ((u64)cmd->cmnd[6] << 24) |
1781 (cmd->cmnd[7] << 16) |
1782 (cmd->cmnd[8] << 8) |
1784 cmnd_count = (cmd->cmnd[10] << 24) |
1785 (cmd->cmnd[11] << 16) |
1786 (cmd->cmnd[12] << 8) |
1788 } else if (cmd->cmnd[0] == WRITE_12) {
1789 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1790 (cmd->cmnd[3] << 16) |
1791 (cmd->cmnd[4] << 8) |
1793 cmnd_count = (cmd->cmnd[6] << 24) |
1794 (cmd->cmnd[7] << 16) |
1795 (cmd->cmnd[8] << 8) |
1797 } else if (cmd->cmnd[0] == WRITE_10) {
1798 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1799 (cmd->cmnd[3] << 16) |
1800 (cmd->cmnd[4] << 8) |
1802 cmnd_count = (cmd->cmnd[7] << 8) |
1806 if (((cmnd_lba + cmnd_count) < lba) ||
1807 (count && ((lba + count) < cmnd_lba)))
1813 spin_unlock_irqrestore(&sdev->list_lock, flags);
1816 * Yield the processor (requeue for later)
1819 return SCSI_MLQUEUE_DEVICE_BUSY;
1821 aac = (struct aac_dev *)sdev->host->hostdata;
1823 return SCSI_MLQUEUE_HOST_BUSY;
1826 * Allocate and initialize a Fib
1828 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1829 return SCSI_MLQUEUE_HOST_BUSY;
1831 aac_fib_init(cmd_fibcontext);
1833 synchronizecmd = fib_data(cmd_fibcontext);
1834 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1835 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1836 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
1837 synchronizecmd->count =
1838 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1841 * Now send the Fib to the adapter
1843 status = aac_fib_send(ContainerCommand,
1845 sizeof(struct aac_synchronize),
1848 (fib_callback)synchronize_callback,
1852 * Check that the command queued to the controller
1854 if (status == -EINPROGRESS) {
1855 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1860 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1861 aac_fib_complete(cmd_fibcontext);
1862 aac_fib_free(cmd_fibcontext);
1863 return SCSI_MLQUEUE_HOST_BUSY;
1867 * aac_scsi_cmd() - Process SCSI command
1868 * @scsicmd: SCSI command block
1870 * Emulate a SCSI command and queue the required request for the
1874 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1877 struct Scsi_Host *host = scsicmd->device->host;
1878 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1879 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1881 if (fsa_dev_ptr == NULL)
1884 * If the bus, id or lun is out of range, return fail
1885 * Test does not apply to ID 16, the pseudo id for the controller
1888 cid = scmd_id(scsicmd);
1889 if (cid != host->this_id) {
1890 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
1891 if((cid >= dev->maximum_num_containers) ||
1892 (scsicmd->device->lun != 0)) {
1893 scsicmd->result = DID_NO_CONNECT << 16;
1894 scsicmd->scsi_done(scsicmd);
1899 * If the target container doesn't exist, it may have
1900 * been newly created
1902 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1903 switch (scsicmd->cmnd[0]) {
1904 case SERVICE_ACTION_IN:
1905 if (!(dev->raw_io_interface) ||
1906 !(dev->raw_io_64) ||
1907 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1911 case TEST_UNIT_READY:
1914 return _aac_probe_container(scsicmd,
1915 aac_probe_container_callback2);
1920 } else { /* check for physical non-dasd devices */
1921 if (dev->nondasd_support || expose_physicals ||
1925 return aac_send_srb_fib(scsicmd);
1927 scsicmd->result = DID_NO_CONNECT << 16;
1928 scsicmd->scsi_done(scsicmd);
1934 * else Command for the controller itself
1936 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1937 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1939 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1940 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1941 set_sense(&dev->fsa_dev[cid].sense_data,
1942 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1943 ASENCODE_INVALID_COMMAND, 0, 0);
1944 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1945 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1946 SCSI_SENSE_BUFFERSIZE));
1947 scsicmd->scsi_done(scsicmd);
1952 /* Handle commands here that don't really require going out to the adapter */
1953 switch (scsicmd->cmnd[0]) {
1956 struct inquiry_data inq_data;
1958 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
1959 memset(&inq_data, 0, sizeof (struct inquiry_data));
1961 if (scsicmd->cmnd[1] & 0x1) {
1962 char *arr = (char *)&inq_data;
1965 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
1966 INQD_PDT_PROC : INQD_PDT_DA;
1967 if (scsicmd->cmnd[2] == 0) {
1968 /* supported vital product data pages */
1972 arr[1] = scsicmd->cmnd[2];
1973 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
1975 scsicmd->result = DID_OK << 16 |
1976 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1977 } else if (scsicmd->cmnd[2] == 0x80) {
1978 /* unit serial number page */
1979 arr[3] = setinqserial(dev, &arr[4],
1981 arr[1] = scsicmd->cmnd[2];
1982 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
1984 return aac_get_container_serial(scsicmd);
1986 /* vpd page not implemented */
1987 scsicmd->result = DID_OK << 16 |
1988 COMMAND_COMPLETE << 8 |
1989 SAM_STAT_CHECK_CONDITION;
1990 set_sense(&dev->fsa_dev[cid].sense_data,
1991 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
1992 ASENCODE_NO_SENSE, 7, 2);
1993 memcpy(scsicmd->sense_buffer,
1994 &dev->fsa_dev[cid].sense_data,
1996 sizeof(dev->fsa_dev[cid].sense_data),
1997 SCSI_SENSE_BUFFERSIZE));
1999 scsicmd->scsi_done(scsicmd);
2002 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
2003 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 */
2004 inq_data.inqd_len = 31;
2005 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2006 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
2008 * Set the Vendor, Product, and Revision Level
2009 * see: <vendor>.c i.e. aac.c
2011 if (cid == host->this_id) {
2012 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
2013 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2014 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2016 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2017 scsicmd->scsi_done(scsicmd);
2022 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2023 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2024 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
2025 return aac_get_container_name(scsicmd);
2027 case SERVICE_ACTION_IN:
2028 if (!(dev->raw_io_interface) ||
2029 !(dev->raw_io_64) ||
2030 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2035 unsigned int alloc_len;
2037 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2038 capacity = fsa_dev_ptr[cid].size - 1;
2039 cp[0] = (capacity >> 56) & 0xff;
2040 cp[1] = (capacity >> 48) & 0xff;
2041 cp[2] = (capacity >> 40) & 0xff;
2042 cp[3] = (capacity >> 32) & 0xff;
2043 cp[4] = (capacity >> 24) & 0xff;
2044 cp[5] = (capacity >> 16) & 0xff;
2045 cp[6] = (capacity >> 8) & 0xff;
2046 cp[7] = (capacity >> 0) & 0xff;
2053 alloc_len = ((scsicmd->cmnd[10] << 24)
2054 + (scsicmd->cmnd[11] << 16)
2055 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2057 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
2058 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
2059 if (alloc_len < scsi_bufflen(scsicmd))
2060 scsi_set_resid(scsicmd,
2061 scsi_bufflen(scsicmd) - alloc_len);
2063 /* Do not cache partition table for arrays */
2064 scsicmd->device->removable = 1;
2066 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2067 scsicmd->scsi_done(scsicmd);
2077 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
2078 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2079 capacity = fsa_dev_ptr[cid].size - 1;
2083 cp[0] = (capacity >> 24) & 0xff;
2084 cp[1] = (capacity >> 16) & 0xff;
2085 cp[2] = (capacity >> 8) & 0xff;
2086 cp[3] = (capacity >> 0) & 0xff;
2091 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
2092 /* Do not cache partition table for arrays */
2093 scsicmd->device->removable = 1;
2095 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2096 scsicmd->scsi_done(scsicmd);
2104 int mode_buf_length = 4;
2106 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
2107 mode_buf[0] = 3; /* Mode data length */
2108 mode_buf[1] = 0; /* Medium type - default */
2109 mode_buf[2] = 0; /* Device-specific param,
2110 bit 8: 0/1 = write enabled/protected
2111 bit 4: 0/1 = FUA enabled */
2112 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2114 mode_buf[3] = 0; /* Block descriptor length */
2115 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2116 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2120 mode_buf[6] = ((aac_cache & 6) == 2)
2121 ? 0 : 0x04; /* WCE */
2122 mode_buf_length = 7;
2123 if (mode_buf_length > scsicmd->cmnd[4])
2124 mode_buf_length = scsicmd->cmnd[4];
2126 scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
2127 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2128 scsicmd->scsi_done(scsicmd);
2135 int mode_buf_length = 8;
2137 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
2138 mode_buf[0] = 0; /* Mode data length (MSB) */
2139 mode_buf[1] = 6; /* Mode data length (LSB) */
2140 mode_buf[2] = 0; /* Medium type - default */
2141 mode_buf[3] = 0; /* Device-specific param,
2142 bit 8: 0/1 = write enabled/protected
2143 bit 4: 0/1 = FUA enabled */
2144 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2146 mode_buf[4] = 0; /* reserved */
2147 mode_buf[5] = 0; /* reserved */
2148 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2149 mode_buf[7] = 0; /* Block descriptor length (LSB) */
2150 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2151 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2155 mode_buf[10] = ((aac_cache & 6) == 2)
2156 ? 0 : 0x04; /* WCE */
2157 mode_buf_length = 11;
2158 if (mode_buf_length > scsicmd->cmnd[8])
2159 mode_buf_length = scsicmd->cmnd[8];
2161 scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
2163 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2164 scsicmd->scsi_done(scsicmd);
2169 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2170 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2171 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2172 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2173 scsicmd->scsi_done(scsicmd);
2176 case ALLOW_MEDIUM_REMOVAL:
2177 dprintk((KERN_DEBUG "LOCK command.\n"));
2178 if (scsicmd->cmnd[4])
2179 fsa_dev_ptr[cid].locked = 1;
2181 fsa_dev_ptr[cid].locked = 0;
2183 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2184 scsicmd->scsi_done(scsicmd);
2187 * These commands are all No-Ops
2189 case TEST_UNIT_READY:
2193 case REASSIGN_BLOCKS:
2196 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2197 scsicmd->scsi_done(scsicmd);
2201 switch (scsicmd->cmnd[0])
2210 * Hack to keep track of ordinal number of the device that
2211 * corresponds to a container. Needed to convert
2212 * containers to /dev/sd device names
2215 if (scsicmd->request->rq_disk)
2216 strlcpy(fsa_dev_ptr[cid].devname,
2217 scsicmd->request->rq_disk->disk_name,
2218 min(sizeof(fsa_dev_ptr[cid].devname),
2219 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2221 return aac_read(scsicmd);
2229 return aac_write(scsicmd);
2231 case SYNCHRONIZE_CACHE:
2232 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2233 scsicmd->result = DID_OK << 16 |
2234 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2235 scsicmd->scsi_done(scsicmd);
2238 /* Issue FIB to tell Firmware to flush it's cache */
2239 if ((aac_cache & 6) != 2)
2240 return aac_synchronize(scsicmd);
2244 * Unhandled commands
2246 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2247 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2248 set_sense(&dev->fsa_dev[cid].sense_data,
2249 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2250 ASENCODE_INVALID_COMMAND, 0, 0);
2251 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2253 sizeof(dev->fsa_dev[cid].sense_data),
2254 SCSI_SENSE_BUFFERSIZE));
2255 scsicmd->scsi_done(scsicmd);
2260 static int query_disk(struct aac_dev *dev, void __user *arg)
2262 struct aac_query_disk qd;
2263 struct fsa_dev_info *fsa_dev_ptr;
2265 fsa_dev_ptr = dev->fsa_dev;
2268 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2272 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2274 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2276 qd.instance = dev->scsi_host_ptr->host_no;
2278 qd.id = CONTAINER_TO_ID(qd.cnum);
2279 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2281 else return -EINVAL;
2283 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
2284 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2285 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2287 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2292 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2293 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2295 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2300 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2302 struct aac_delete_disk dd;
2303 struct fsa_dev_info *fsa_dev_ptr;
2305 fsa_dev_ptr = dev->fsa_dev;
2309 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2312 if (dd.cnum >= dev->maximum_num_containers)
2315 * Mark this container as being deleted.
2317 fsa_dev_ptr[dd.cnum].deleted = 1;
2319 * Mark the container as no longer valid
2321 fsa_dev_ptr[dd.cnum].valid = 0;
2325 static int delete_disk(struct aac_dev *dev, void __user *arg)
2327 struct aac_delete_disk dd;
2328 struct fsa_dev_info *fsa_dev_ptr;
2330 fsa_dev_ptr = dev->fsa_dev;
2334 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2337 if (dd.cnum >= dev->maximum_num_containers)
2340 * If the container is locked, it can not be deleted by the API.
2342 if (fsa_dev_ptr[dd.cnum].locked)
2346 * Mark the container as no longer being valid.
2348 fsa_dev_ptr[dd.cnum].valid = 0;
2349 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2354 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2357 case FSACTL_QUERY_DISK:
2358 return query_disk(dev, arg);
2359 case FSACTL_DELETE_DISK:
2360 return delete_disk(dev, arg);
2361 case FSACTL_FORCE_DELETE_DISK:
2362 return force_delete_disk(dev, arg);
2363 case FSACTL_GET_CONTAINERS:
2364 return aac_get_containers(dev);
2373 * @context: the context set in the fib - here it is scsi cmd
2374 * @fibptr: pointer to the fib
2376 * Handles the completion of a scsi command to a non dasd device
2380 static void aac_srb_callback(void *context, struct fib * fibptr)
2382 struct aac_dev *dev;
2383 struct aac_srb_reply *srbreply;
2384 struct scsi_cmnd *scsicmd;
2386 scsicmd = (struct scsi_cmnd *) context;
2388 if (!aac_valid_context(scsicmd, fibptr))
2391 BUG_ON(fibptr == NULL);
2395 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2397 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2399 * Calculate resid for sg
2402 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2403 - le32_to_cpu(srbreply->data_xfer_length));
2405 scsi_dma_unmap(scsicmd);
2408 * First check the fib status
2411 if (le32_to_cpu(srbreply->status) != ST_OK){
2413 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2414 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2415 SCSI_SENSE_BUFFERSIZE);
2416 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2417 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2421 * Next check the srb status
2423 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2424 case SRB_STATUS_ERROR_RECOVERY:
2425 case SRB_STATUS_PENDING:
2426 case SRB_STATUS_SUCCESS:
2427 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2429 case SRB_STATUS_DATA_OVERRUN:
2430 switch(scsicmd->cmnd[0]){
2439 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
2440 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2442 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2444 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2447 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2451 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2455 case SRB_STATUS_ABORTED:
2456 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2458 case SRB_STATUS_ABORT_FAILED:
2459 // Not sure about this one - but assuming the hba was trying to abort for some reason
2460 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2462 case SRB_STATUS_PARITY_ERROR:
2463 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2465 case SRB_STATUS_NO_DEVICE:
2466 case SRB_STATUS_INVALID_PATH_ID:
2467 case SRB_STATUS_INVALID_TARGET_ID:
2468 case SRB_STATUS_INVALID_LUN:
2469 case SRB_STATUS_SELECTION_TIMEOUT:
2470 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2473 case SRB_STATUS_COMMAND_TIMEOUT:
2474 case SRB_STATUS_TIMEOUT:
2475 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2478 case SRB_STATUS_BUSY:
2479 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
2482 case SRB_STATUS_BUS_RESET:
2483 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2486 case SRB_STATUS_MESSAGE_REJECTED:
2487 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2489 case SRB_STATUS_REQUEST_FLUSHED:
2490 case SRB_STATUS_ERROR:
2491 case SRB_STATUS_INVALID_REQUEST:
2492 case SRB_STATUS_REQUEST_SENSE_FAILED:
2493 case SRB_STATUS_NO_HBA:
2494 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2495 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2496 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2497 case SRB_STATUS_DELAYED_RETRY:
2498 case SRB_STATUS_BAD_FUNCTION:
2499 case SRB_STATUS_NOT_STARTED:
2500 case SRB_STATUS_NOT_IN_USE:
2501 case SRB_STATUS_FORCE_ABORT:
2502 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2504 #ifdef AAC_DETAILED_STATUS_INFO
2505 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2506 le32_to_cpu(srbreply->srb_status) & 0x3F,
2507 aac_get_status_string(
2508 le32_to_cpu(srbreply->srb_status) & 0x3F),
2510 le32_to_cpu(srbreply->scsi_status));
2512 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2515 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
2517 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2518 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2519 SCSI_SENSE_BUFFERSIZE);
2520 #ifdef AAC_DETAILED_STATUS_INFO
2521 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2522 le32_to_cpu(srbreply->status), len);
2524 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2527 * OR in the scsi status (already shifted up a bit)
2529 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2531 aac_fib_complete(fibptr);
2532 aac_fib_free(fibptr);
2533 scsicmd->scsi_done(scsicmd);
2539 * @scsicmd: the scsi command block
2541 * This routine will form a FIB and fill in the aac_srb from the
2542 * scsicmd passed in.
2545 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2547 struct fib* cmd_fibcontext;
2548 struct aac_dev* dev;
2551 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2552 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2553 scsicmd->device->lun > 7) {
2554 scsicmd->result = DID_NO_CONNECT << 16;
2555 scsicmd->scsi_done(scsicmd);
2560 * Allocate and initialize a Fib then setup a BlockWrite command
2562 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2565 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2568 * Check that the command queued to the controller
2570 if (status == -EINPROGRESS) {
2571 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2575 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2576 aac_fib_complete(cmd_fibcontext);
2577 aac_fib_free(cmd_fibcontext);
2582 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2584 struct aac_dev *dev;
2585 unsigned long byte_count = 0;
2588 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2589 // Get rid of old data
2591 psg->sg[0].addr = 0;
2592 psg->sg[0].count = 0;
2594 nseg = scsi_dma_map(scsicmd);
2597 struct scatterlist *sg;
2600 psg->count = cpu_to_le32(nseg);
2602 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2603 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2604 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2605 byte_count += sg_dma_len(sg);
2607 /* hba wants the size to be exact */
2608 if (byte_count > scsi_bufflen(scsicmd)) {
2609 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2610 (byte_count - scsi_bufflen(scsicmd));
2611 psg->sg[i-1].count = cpu_to_le32(temp);
2612 byte_count = scsi_bufflen(scsicmd);
2614 /* Check for command underflow */
2615 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2616 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2617 byte_count, scsicmd->underflow);
2624 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2626 struct aac_dev *dev;
2627 unsigned long byte_count = 0;
2631 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2632 // Get rid of old data
2634 psg->sg[0].addr[0] = 0;
2635 psg->sg[0].addr[1] = 0;
2636 psg->sg[0].count = 0;
2638 nseg = scsi_dma_map(scsicmd);
2641 struct scatterlist *sg;
2644 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2645 int count = sg_dma_len(sg);
2646 addr = sg_dma_address(sg);
2647 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2648 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2649 psg->sg[i].count = cpu_to_le32(count);
2650 byte_count += count;
2652 psg->count = cpu_to_le32(nseg);
2653 /* hba wants the size to be exact */
2654 if (byte_count > scsi_bufflen(scsicmd)) {
2655 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2656 (byte_count - scsi_bufflen(scsicmd));
2657 psg->sg[i-1].count = cpu_to_le32(temp);
2658 byte_count = scsi_bufflen(scsicmd);
2660 /* Check for command underflow */
2661 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2662 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2663 byte_count, scsicmd->underflow);
2669 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2671 unsigned long byte_count = 0;
2674 // Get rid of old data
2676 psg->sg[0].next = 0;
2677 psg->sg[0].prev = 0;
2678 psg->sg[0].addr[0] = 0;
2679 psg->sg[0].addr[1] = 0;
2680 psg->sg[0].count = 0;
2681 psg->sg[0].flags = 0;
2683 nseg = scsi_dma_map(scsicmd);
2686 struct scatterlist *sg;
2689 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2690 int count = sg_dma_len(sg);
2691 u64 addr = sg_dma_address(sg);
2692 psg->sg[i].next = 0;
2693 psg->sg[i].prev = 0;
2694 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2695 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2696 psg->sg[i].count = cpu_to_le32(count);
2697 psg->sg[i].flags = 0;
2698 byte_count += count;
2700 psg->count = cpu_to_le32(nseg);
2701 /* hba wants the size to be exact */
2702 if (byte_count > scsi_bufflen(scsicmd)) {
2703 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2704 (byte_count - scsi_bufflen(scsicmd));
2705 psg->sg[i-1].count = cpu_to_le32(temp);
2706 byte_count = scsi_bufflen(scsicmd);
2708 /* Check for command underflow */
2709 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2710 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2711 byte_count, scsicmd->underflow);
2717 #ifdef AAC_DETAILED_STATUS_INFO
2719 struct aac_srb_status_info {
2725 static struct aac_srb_status_info srb_status_info[] = {
2726 { SRB_STATUS_PENDING, "Pending Status"},
2727 { SRB_STATUS_SUCCESS, "Success"},
2728 { SRB_STATUS_ABORTED, "Aborted Command"},
2729 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2730 { SRB_STATUS_ERROR, "Error Event"},
2731 { SRB_STATUS_BUSY, "Device Busy"},
2732 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2733 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2734 { SRB_STATUS_NO_DEVICE, "No Device"},
2735 { SRB_STATUS_TIMEOUT, "Timeout"},
2736 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2737 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2738 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2739 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2740 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2741 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2742 { SRB_STATUS_NO_HBA, "No HBA"},
2743 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2744 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2745 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2746 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2747 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2748 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2749 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2750 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2751 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2752 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2753 { SRB_STATUS_NOT_STARTED, "Not Started"},
2754 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2755 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2756 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2757 { 0xff, "Unknown Error"}
2760 char *aac_get_status_string(u32 status)
2764 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2765 if (srb_status_info[i].status == status)
2766 return srb_status_info[i].str;
2768 return "Bad Status Code";