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/semaphore.h>
35 #include <asm/uaccess.h>
36 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
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 aac_cache = 0;
148 static int dacmode = -1;
151 int startup_timeout = 180;
152 int aif_timeout = 120;
154 module_param(nondasd, int, S_IRUGO|S_IWUSR);
155 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
156 module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
157 MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n\tbit 0 - Disable FUA in WRITE SCSI commands\n\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n\tbit 2 - Disable only if Battery not protecting Cache");
158 module_param(dacmode, int, S_IRUGO|S_IWUSR);
159 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
160 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
161 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");
162 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
163 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.");
164 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
165 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.");
168 module_param(numacb, int, S_IRUGO|S_IWUSR);
169 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.");
172 module_param(acbsize, int, S_IRUGO|S_IWUSR);
173 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.");
175 int update_interval = 30 * 60;
176 module_param(update_interval, int, S_IRUGO|S_IWUSR);
177 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync updates issued to adapter.");
179 int check_interval = 24 * 60 * 60;
180 module_param(check_interval, int, S_IRUGO|S_IWUSR);
181 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health checks.");
183 int aac_check_reset = 1;
184 module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
185 MODULE_PARM_DESC(aac_check_reset, "If adapter fails health check, reset the adapter. a value of -1 forces the reset to adapters programmed to ignore it.");
187 int expose_physicals = -1;
188 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
189 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
191 int aac_reset_devices = 0;
192 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
193 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
195 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
196 struct fib *fibptr) {
197 struct scsi_device *device;
199 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
200 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
201 aac_fib_complete(fibptr);
202 aac_fib_free(fibptr);
205 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
206 device = scsicmd->device;
207 if (unlikely(!device || !scsi_device_online(device))) {
208 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
209 aac_fib_complete(fibptr);
210 aac_fib_free(fibptr);
217 * aac_get_config_status - check the adapter configuration
218 * @common: adapter to query
220 * Query config status, and commit the configuration if needed.
222 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
227 if (!(fibptr = aac_fib_alloc(dev)))
230 aac_fib_init(fibptr);
232 struct aac_get_config_status *dinfo;
233 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
235 dinfo->command = cpu_to_le32(VM_ContainerConfig);
236 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
237 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
240 status = aac_fib_send(ContainerCommand,
242 sizeof (struct aac_get_config_status),
247 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
249 struct aac_get_config_status_resp *reply
250 = (struct aac_get_config_status_resp *) fib_data(fibptr);
251 dprintk((KERN_WARNING
252 "aac_get_config_status: response=%d status=%d action=%d\n",
253 le32_to_cpu(reply->response),
254 le32_to_cpu(reply->status),
255 le32_to_cpu(reply->data.action)));
256 if ((le32_to_cpu(reply->response) != ST_OK) ||
257 (le32_to_cpu(reply->status) != CT_OK) ||
258 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
259 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
263 aac_fib_complete(fibptr);
264 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
266 if ((aac_commit == 1) || commit_flag) {
267 struct aac_commit_config * dinfo;
268 aac_fib_init(fibptr);
269 dinfo = (struct aac_commit_config *) fib_data(fibptr);
271 dinfo->command = cpu_to_le32(VM_ContainerConfig);
272 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
274 status = aac_fib_send(ContainerCommand,
276 sizeof (struct aac_commit_config),
280 aac_fib_complete(fibptr);
281 } else if (aac_commit == 0) {
283 "aac_get_config_status: Foreign device configurations are being ignored\n");
286 aac_fib_free(fibptr);
291 * aac_get_containers - list containers
292 * @common: adapter to probe
294 * Make a list of all containers on this controller
296 int aac_get_containers(struct aac_dev *dev)
298 struct fsa_dev_info *fsa_dev_ptr;
302 struct aac_get_container_count *dinfo;
303 struct aac_get_container_count_resp *dresp;
304 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
306 if (!(fibptr = aac_fib_alloc(dev)))
309 aac_fib_init(fibptr);
310 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
311 dinfo->command = cpu_to_le32(VM_ContainerConfig);
312 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
314 status = aac_fib_send(ContainerCommand,
316 sizeof (struct aac_get_container_count),
321 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
322 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
323 aac_fib_complete(fibptr);
325 aac_fib_free(fibptr);
327 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
328 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
329 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
334 dev->fsa_dev = fsa_dev_ptr;
335 dev->maximum_num_containers = maximum_num_containers;
337 for (index = 0; index < dev->maximum_num_containers; ) {
338 fsa_dev_ptr[index].devname[0] = '\0';
340 status = aac_probe_container(dev, index);
343 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
348 * If there are no more containers, then stop asking.
350 if (++index >= status)
356 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
360 struct scatterlist *sg = scsi_sglist(scsicmd);
362 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
363 transfer_len = min(sg->length, len + offset);
365 transfer_len -= offset;
366 if (buf && transfer_len > 0)
367 memcpy(buf + offset, data, transfer_len);
369 flush_kernel_dcache_page(kmap_atomic_to_page(buf - sg->offset));
370 kunmap_atomic(buf - sg->offset, KM_IRQ0);
374 static void get_container_name_callback(void *context, struct fib * fibptr)
376 struct aac_get_name_resp * get_name_reply;
377 struct scsi_cmnd * scsicmd;
379 scsicmd = (struct scsi_cmnd *) context;
381 if (!aac_valid_context(scsicmd, fibptr))
384 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
385 BUG_ON(fibptr == NULL);
387 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
388 /* Failure is irrelevant, using default value instead */
389 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
390 && (get_name_reply->data[0] != '\0')) {
391 char *sp = get_name_reply->data;
392 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
396 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
397 int count = sizeof(d);
400 *dp++ = (*sp) ? *sp++ : ' ';
401 } while (--count > 0);
402 aac_internal_transfer(scsicmd, d,
403 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
407 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
409 aac_fib_complete(fibptr);
410 aac_fib_free(fibptr);
411 scsicmd->scsi_done(scsicmd);
415 * aac_get_container_name - get container name, none blocking.
417 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
420 struct aac_get_name *dinfo;
421 struct fib * cmd_fibcontext;
422 struct aac_dev * dev;
424 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
426 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
429 aac_fib_init(cmd_fibcontext);
430 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
432 dinfo->command = cpu_to_le32(VM_ContainerConfig);
433 dinfo->type = cpu_to_le32(CT_READ_NAME);
434 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
435 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
437 status = aac_fib_send(ContainerCommand,
439 sizeof (struct aac_get_name),
442 (fib_callback)get_container_name_callback,
446 * Check that the command queued to the controller
448 if (status == -EINPROGRESS) {
449 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
453 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
454 aac_fib_complete(cmd_fibcontext);
455 aac_fib_free(cmd_fibcontext);
459 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
461 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
463 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
464 return aac_scsi_cmd(scsicmd);
466 scsicmd->result = DID_NO_CONNECT << 16;
467 scsicmd->scsi_done(scsicmd);
471 static void _aac_probe_container2(void * context, struct fib * fibptr)
473 struct fsa_dev_info *fsa_dev_ptr;
474 int (*callback)(struct scsi_cmnd *);
475 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
478 if (!aac_valid_context(scsicmd, fibptr))
481 scsicmd->SCp.Status = 0;
482 fsa_dev_ptr = fibptr->dev->fsa_dev;
484 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
485 fsa_dev_ptr += scmd_id(scsicmd);
487 if ((le32_to_cpu(dresp->status) == ST_OK) &&
488 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
489 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
490 fsa_dev_ptr->valid = 1;
491 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
493 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
494 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
495 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
497 if ((fsa_dev_ptr->valid & 1) == 0)
498 fsa_dev_ptr->valid = 0;
499 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
501 aac_fib_complete(fibptr);
502 aac_fib_free(fibptr);
503 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
504 scsicmd->SCp.ptr = NULL;
505 (*callback)(scsicmd);
509 static void _aac_probe_container1(void * context, struct fib * fibptr)
511 struct scsi_cmnd * scsicmd;
512 struct aac_mount * dresp;
513 struct aac_query_mount *dinfo;
516 dresp = (struct aac_mount *) fib_data(fibptr);
517 dresp->mnt[0].capacityhigh = 0;
518 if ((le32_to_cpu(dresp->status) != ST_OK) ||
519 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
520 _aac_probe_container2(context, fibptr);
523 scsicmd = (struct scsi_cmnd *) context;
525 if (!aac_valid_context(scsicmd, fibptr))
528 aac_fib_init(fibptr);
530 dinfo = (struct aac_query_mount *)fib_data(fibptr);
532 dinfo->command = cpu_to_le32(VM_NameServe64);
533 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
534 dinfo->type = cpu_to_le32(FT_FILESYS);
536 status = aac_fib_send(ContainerCommand,
538 sizeof(struct aac_query_mount),
541 _aac_probe_container2,
544 * Check that the command queued to the controller
546 if (status == -EINPROGRESS)
547 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
548 else if (status < 0) {
549 /* Inherit results from VM_NameServe, if any */
550 dresp->status = cpu_to_le32(ST_OK);
551 _aac_probe_container2(context, fibptr);
555 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
558 int status = -ENOMEM;
560 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
561 struct aac_query_mount *dinfo;
563 aac_fib_init(fibptr);
565 dinfo = (struct aac_query_mount *)fib_data(fibptr);
567 dinfo->command = cpu_to_le32(VM_NameServe);
568 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
569 dinfo->type = cpu_to_le32(FT_FILESYS);
570 scsicmd->SCp.ptr = (char *)callback;
572 status = aac_fib_send(ContainerCommand,
574 sizeof(struct aac_query_mount),
577 _aac_probe_container1,
580 * Check that the command queued to the controller
582 if (status == -EINPROGRESS) {
583 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
587 scsicmd->SCp.ptr = NULL;
588 aac_fib_complete(fibptr);
589 aac_fib_free(fibptr);
593 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
595 fsa_dev_ptr += scmd_id(scsicmd);
596 if ((fsa_dev_ptr->valid & 1) == 0) {
597 fsa_dev_ptr->valid = 0;
598 return (*callback)(scsicmd);
606 * aac_probe_container - query a logical volume
607 * @dev: device to query
608 * @cid: container identifier
610 * Queries the controller about the given volume. The volume information
611 * is updated in the struct fsa_dev_info structure rather than returned.
613 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
615 scsicmd->device = NULL;
619 int aac_probe_container(struct aac_dev *dev, int cid)
621 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
622 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
625 if (!scsicmd || !scsidev) {
630 scsicmd->list.next = NULL;
631 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
633 scsicmd->device = scsidev;
634 scsidev->sdev_state = 0;
636 scsidev->host = dev->scsi_host_ptr;
638 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
639 while (scsicmd->device == scsidev)
642 status = scsicmd->SCp.Status;
647 /* Local Structure to set SCSI inquiry data strings */
649 char vid[8]; /* Vendor ID */
650 char pid[16]; /* Product ID */
651 char prl[4]; /* Product Revision Level */
655 * InqStrCopy - string merge
656 * @a: string to copy from
657 * @b: string to copy to
659 * Copy a String from one location to another
663 static void inqstrcpy(char *a, char *b)
666 while (*a != (char)0)
670 static char *container_types[] = {
694 char * get_container_type(unsigned tindex)
696 if (tindex >= ARRAY_SIZE(container_types))
697 tindex = ARRAY_SIZE(container_types) - 1;
698 return container_types[tindex];
701 /* Function: setinqstr
703 * Arguments: [1] pointer to void [1] int
705 * Purpose: Sets SCSI inquiry data strings for vendor, product
706 * and revision level. Allows strings to be set in platform dependant
707 * files instead of in OS dependant driver source.
710 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
712 struct scsi_inq *str;
714 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
715 memset(str, ' ', sizeof(*str));
717 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
718 char * cp = dev->supplement_adapter_info.AdapterTypeText;
720 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
721 inqstrcpy("SMC", str->vid);
723 c = sizeof(str->vid);
724 while (*cp && *cp != ' ' && --c)
728 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
731 while (*cp && *cp != ' ')
736 /* last six chars reserved for vol type */
738 if (strlen(cp) > sizeof(str->pid)) {
739 c = cp[sizeof(str->pid)];
740 cp[sizeof(str->pid)] = '\0';
742 inqstrcpy (cp, str->pid);
744 cp[sizeof(str->pid)] = c;
746 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
748 inqstrcpy (mp->vname, str->vid);
749 /* last six chars reserved for vol type */
750 inqstrcpy (mp->model, str->pid);
753 if (tindex < ARRAY_SIZE(container_types)){
754 char *findit = str->pid;
756 for ( ; *findit != ' '; findit++); /* walk till we find a space */
757 /* RAID is superfluous in the context of a RAID device */
758 if (memcmp(findit-4, "RAID", 4) == 0)
759 *(findit -= 4) = ' ';
760 if (((findit - str->pid) + strlen(container_types[tindex]))
761 < (sizeof(str->pid) + sizeof(str->prl)))
762 inqstrcpy (container_types[tindex], findit + 1);
764 inqstrcpy ("V1.0", str->prl);
767 static void get_container_serial_callback(void *context, struct fib * fibptr)
769 struct aac_get_serial_resp * get_serial_reply;
770 struct scsi_cmnd * scsicmd;
772 BUG_ON(fibptr == NULL);
774 scsicmd = (struct scsi_cmnd *) context;
775 if (!aac_valid_context(scsicmd, fibptr))
778 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
779 /* Failure is irrelevant, using default value instead */
780 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
784 sp[1] = scsicmd->cmnd[2];
786 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
787 le32_to_cpu(get_serial_reply->uid));
788 aac_internal_transfer(scsicmd, sp, 0, sizeof(sp));
791 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
793 aac_fib_complete(fibptr);
794 aac_fib_free(fibptr);
795 scsicmd->scsi_done(scsicmd);
799 * aac_get_container_serial - get container serial, none blocking.
801 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
804 struct aac_get_serial *dinfo;
805 struct fib * cmd_fibcontext;
806 struct aac_dev * dev;
808 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
810 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
813 aac_fib_init(cmd_fibcontext);
814 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
816 dinfo->command = cpu_to_le32(VM_ContainerConfig);
817 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
818 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
820 status = aac_fib_send(ContainerCommand,
822 sizeof (struct aac_get_serial),
825 (fib_callback) get_container_serial_callback,
829 * Check that the command queued to the controller
831 if (status == -EINPROGRESS) {
832 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
836 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
837 aac_fib_complete(cmd_fibcontext);
838 aac_fib_free(cmd_fibcontext);
842 /* Function: setinqserial
844 * Arguments: [1] pointer to void [1] int
846 * Purpose: Sets SCSI Unit Serial number.
847 * This is a fake. We should read a proper
848 * serial number from the container. <SuSE>But
849 * without docs it's quite hard to do it :-)
850 * So this will have to do in the meantime.</SuSE>
853 static int setinqserial(struct aac_dev *dev, void *data, int cid)
856 * This breaks array migration.
858 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
859 le32_to_cpu(dev->adapter_info.serial[0]), cid);
862 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
863 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
865 u8 *sense_buf = (u8 *)sense_data;
866 /* Sense data valid, err code 70h */
867 sense_buf[0] = 0x70; /* No info field */
868 sense_buf[1] = 0; /* Segment number, always zero */
870 sense_buf[2] = sense_key; /* Sense key */
872 sense_buf[12] = sense_code; /* Additional sense code */
873 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
875 if (sense_key == ILLEGAL_REQUEST) {
876 sense_buf[7] = 10; /* Additional sense length */
878 sense_buf[15] = bit_pointer;
879 /* Illegal parameter is in the parameter block */
880 if (sense_code == SENCODE_INVALID_CDB_FIELD)
881 sense_buf[15] |= 0xc0;/* Std sense key specific field */
882 /* Illegal parameter is in the CDB block */
883 sense_buf[16] = field_pointer >> 8; /* MSB */
884 sense_buf[17] = field_pointer; /* LSB */
886 sense_buf[7] = 6; /* Additional sense length */
889 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
891 if (lba & 0xffffffff00000000LL) {
892 int cid = scmd_id(cmd);
893 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
894 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
895 SAM_STAT_CHECK_CONDITION;
896 set_sense(&dev->fsa_dev[cid].sense_data,
897 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
898 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
899 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
900 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
901 SCSI_SENSE_BUFFERSIZE));
908 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
913 static void io_callback(void *context, struct fib * fibptr);
915 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
918 struct aac_raw_io *readcmd;
920 readcmd = (struct aac_raw_io *) fib_data(fib);
921 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
922 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
923 readcmd->count = cpu_to_le32(count<<9);
924 readcmd->cid = cpu_to_le16(scmd_id(cmd));
925 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
926 readcmd->bpTotal = 0;
927 readcmd->bpComplete = 0;
929 aac_build_sgraw(cmd, &readcmd->sg);
930 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
931 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
933 * Now send the Fib to the adapter
935 return aac_fib_send(ContainerRawIo,
940 (fib_callback) io_callback,
944 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
947 struct aac_read64 *readcmd;
949 readcmd = (struct aac_read64 *) fib_data(fib);
950 readcmd->command = cpu_to_le32(VM_CtHostRead64);
951 readcmd->cid = cpu_to_le16(scmd_id(cmd));
952 readcmd->sector_count = cpu_to_le16(count);
953 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
957 aac_build_sg64(cmd, &readcmd->sg);
958 fibsize = sizeof(struct aac_read64) +
959 ((le32_to_cpu(readcmd->sg.count) - 1) *
960 sizeof (struct sgentry64));
961 BUG_ON (fibsize > (fib->dev->max_fib_size -
962 sizeof(struct aac_fibhdr)));
964 * Now send the Fib to the adapter
966 return aac_fib_send(ContainerCommand64,
971 (fib_callback) io_callback,
975 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
978 struct aac_read *readcmd;
980 readcmd = (struct aac_read *) fib_data(fib);
981 readcmd->command = cpu_to_le32(VM_CtBlockRead);
982 readcmd->cid = cpu_to_le32(scmd_id(cmd));
983 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
984 readcmd->count = cpu_to_le32(count * 512);
986 aac_build_sg(cmd, &readcmd->sg);
987 fibsize = sizeof(struct aac_read) +
988 ((le32_to_cpu(readcmd->sg.count) - 1) *
989 sizeof (struct sgentry));
990 BUG_ON (fibsize > (fib->dev->max_fib_size -
991 sizeof(struct aac_fibhdr)));
993 * Now send the Fib to the adapter
995 return aac_fib_send(ContainerCommand,
1000 (fib_callback) io_callback,
1004 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1007 struct aac_raw_io *writecmd;
1009 writecmd = (struct aac_raw_io *) fib_data(fib);
1010 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1011 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1012 writecmd->count = cpu_to_le32(count<<9);
1013 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1014 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1015 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1016 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
1017 cpu_to_le16(IO_TYPE_WRITE);
1018 writecmd->bpTotal = 0;
1019 writecmd->bpComplete = 0;
1021 aac_build_sgraw(cmd, &writecmd->sg);
1022 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1023 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1025 * Now send the Fib to the adapter
1027 return aac_fib_send(ContainerRawIo,
1032 (fib_callback) io_callback,
1036 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1039 struct aac_write64 *writecmd;
1041 writecmd = (struct aac_write64 *) fib_data(fib);
1042 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1043 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1044 writecmd->sector_count = cpu_to_le16(count);
1045 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1047 writecmd->flags = 0;
1049 aac_build_sg64(cmd, &writecmd->sg);
1050 fibsize = sizeof(struct aac_write64) +
1051 ((le32_to_cpu(writecmd->sg.count) - 1) *
1052 sizeof (struct sgentry64));
1053 BUG_ON (fibsize > (fib->dev->max_fib_size -
1054 sizeof(struct aac_fibhdr)));
1056 * Now send the Fib to the adapter
1058 return aac_fib_send(ContainerCommand64,
1063 (fib_callback) io_callback,
1067 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1070 struct aac_write *writecmd;
1072 writecmd = (struct aac_write *) fib_data(fib);
1073 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1074 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1075 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1076 writecmd->count = cpu_to_le32(count * 512);
1077 writecmd->sg.count = cpu_to_le32(1);
1078 /* ->stable is not used - it did mean which type of write */
1080 aac_build_sg(cmd, &writecmd->sg);
1081 fibsize = sizeof(struct aac_write) +
1082 ((le32_to_cpu(writecmd->sg.count) - 1) *
1083 sizeof (struct sgentry));
1084 BUG_ON (fibsize > (fib->dev->max_fib_size -
1085 sizeof(struct aac_fibhdr)));
1087 * Now send the Fib to the adapter
1089 return aac_fib_send(ContainerCommand,
1094 (fib_callback) io_callback,
1098 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1100 struct aac_srb * srbcmd;
1105 switch(cmd->sc_data_direction){
1109 case DMA_BIDIRECTIONAL:
1110 flag = SRB_DataIn | SRB_DataOut;
1112 case DMA_FROM_DEVICE:
1116 default: /* shuts up some versions of gcc */
1117 flag = SRB_NoDataXfer;
1121 srbcmd = (struct aac_srb*) fib_data(fib);
1122 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1123 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1124 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1125 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1126 srbcmd->flags = cpu_to_le32(flag);
1127 timeout = cmd->timeout_per_command/HZ;
1130 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1131 srbcmd->retry_limit = 0; /* Obsolete parameter */
1132 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1136 static void aac_srb_callback(void *context, struct fib * fibptr);
1138 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1141 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1143 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1144 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1146 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1147 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1149 * Build Scatter/Gather list
1151 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1152 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1153 sizeof (struct sgentry64));
1154 BUG_ON (fibsize > (fib->dev->max_fib_size -
1155 sizeof(struct aac_fibhdr)));
1158 * Now send the Fib to the adapter
1160 return aac_fib_send(ScsiPortCommand64, fib,
1161 fibsize, FsaNormal, 0, 1,
1162 (fib_callback) aac_srb_callback,
1166 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1169 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1171 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1172 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1174 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1175 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1177 * Build Scatter/Gather list
1179 fibsize = sizeof (struct aac_srb) +
1180 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1181 sizeof (struct sgentry));
1182 BUG_ON (fibsize > (fib->dev->max_fib_size -
1183 sizeof(struct aac_fibhdr)));
1186 * Now send the Fib to the adapter
1188 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1189 (fib_callback) aac_srb_callback, (void *) cmd);
1192 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1194 if ((sizeof(dma_addr_t) > 4) &&
1195 (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) &&
1196 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1198 return aac_scsi_32(fib, cmd);
1201 int aac_get_adapter_info(struct aac_dev* dev)
1206 struct aac_adapter_info *info;
1207 struct aac_bus_info *command;
1208 struct aac_bus_info_response *bus_info;
1210 if (!(fibptr = aac_fib_alloc(dev)))
1213 aac_fib_init(fibptr);
1214 info = (struct aac_adapter_info *) fib_data(fibptr);
1215 memset(info,0,sizeof(*info));
1217 rcode = aac_fib_send(RequestAdapterInfo,
1221 -1, 1, /* First `interrupt' command uses special wait */
1226 aac_fib_complete(fibptr);
1227 aac_fib_free(fibptr);
1230 memcpy(&dev->adapter_info, info, sizeof(*info));
1232 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1233 struct aac_supplement_adapter_info * sinfo;
1235 aac_fib_init(fibptr);
1237 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1239 memset(sinfo,0,sizeof(*sinfo));
1241 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1250 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
1258 aac_fib_init(fibptr);
1260 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1262 memset(bus_info, 0, sizeof(*bus_info));
1264 command = (struct aac_bus_info *)bus_info;
1266 command->Command = cpu_to_le32(VM_Ioctl);
1267 command->ObjType = cpu_to_le32(FT_DRIVE);
1268 command->MethodId = cpu_to_le32(1);
1269 command->CtlCmd = cpu_to_le32(GetBusInfo);
1271 rcode = aac_fib_send(ContainerCommand,
1278 /* reasoned default */
1279 dev->maximum_num_physicals = 16;
1280 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1281 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1282 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1285 if (!dev->in_reset) {
1287 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1288 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1294 le32_to_cpu(dev->adapter_info.kernelbuild),
1295 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1296 dev->supplement_adapter_info.BuildDate);
1297 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1298 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1300 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1301 le32_to_cpu(dev->adapter_info.monitorbuild));
1302 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1303 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1305 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1306 le32_to_cpu(dev->adapter_info.biosbuild));
1308 if (aac_show_serial_number(
1309 shost_to_class(dev->scsi_host_ptr), buffer))
1310 printk(KERN_INFO "%s%d: serial %s",
1311 dev->name, dev->id, buffer);
1312 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1313 printk(KERN_INFO "%s%d: TSID %.*s\n",
1315 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1316 dev->supplement_adapter_info.VpdInfo.Tsid);
1318 if (!aac_check_reset || ((aac_check_reset != 1) &&
1319 (dev->supplement_adapter_info.SupportedOptions2 &
1320 AAC_OPTION_IGNORE_RESET))) {
1321 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1322 dev->name, dev->id);
1326 dev->cache_protected = 0;
1327 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1328 AAC_FEATURE_JBOD) != 0);
1329 dev->nondasd_support = 0;
1330 dev->raid_scsi_mode = 0;
1331 if(dev->adapter_info.options & AAC_OPT_NONDASD)
1332 dev->nondasd_support = 1;
1335 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1336 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1337 * force nondasd support on. If we decide to allow the non-dasd flag
1338 * additional changes changes will have to be made to support
1339 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1340 * changed to support the new dev->raid_scsi_mode flag instead of
1341 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1342 * function aac_detect will have to be modified where it sets up the
1343 * max number of channels based on the aac->nondasd_support flag only.
1345 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1346 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1347 dev->nondasd_support = 1;
1348 dev->raid_scsi_mode = 1;
1350 if (dev->raid_scsi_mode != 0)
1351 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1352 dev->name, dev->id);
1355 dev->nondasd_support = (nondasd!=0);
1356 if(dev->nondasd_support != 0) {
1357 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1360 dev->dac_support = 0;
1361 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1362 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1363 dev->dac_support = 1;
1367 dev->dac_support = (dacmode!=0);
1369 if(dev->dac_support != 0) {
1370 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1371 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1372 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1373 dev->name, dev->id);
1374 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1375 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1376 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1377 dev->name, dev->id);
1378 dev->dac_support = 0;
1380 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1381 dev->name, dev->id);
1386 * Deal with configuring for the individualized limits of each packet
1389 dev->a_ops.adapter_scsi = (dev->dac_support)
1390 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1394 if (dev->raw_io_interface) {
1395 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1398 dev->a_ops.adapter_read = aac_read_raw_io;
1399 dev->a_ops.adapter_write = aac_write_raw_io;
1401 dev->a_ops.adapter_bounds = aac_bounds_32;
1402 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1403 sizeof(struct aac_fibhdr) -
1404 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1405 sizeof(struct sgentry);
1406 if (dev->dac_support) {
1407 dev->a_ops.adapter_read = aac_read_block64;
1408 dev->a_ops.adapter_write = aac_write_block64;
1410 * 38 scatter gather elements
1412 dev->scsi_host_ptr->sg_tablesize =
1413 (dev->max_fib_size -
1414 sizeof(struct aac_fibhdr) -
1415 sizeof(struct aac_write64) +
1416 sizeof(struct sgentry64)) /
1417 sizeof(struct sgentry64);
1419 dev->a_ops.adapter_read = aac_read_block;
1420 dev->a_ops.adapter_write = aac_write_block;
1422 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1423 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1425 * Worst case size that could cause sg overflow when
1426 * we break up SG elements that are larger than 64KB.
1427 * Would be nice if we could tell the SCSI layer what
1428 * the maximum SG element size can be. Worst case is
1429 * (sg_tablesize-1) 4KB elements with one 64KB
1431 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1433 dev->scsi_host_ptr->max_sectors =
1434 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1438 aac_fib_complete(fibptr);
1439 aac_fib_free(fibptr);
1445 static void io_callback(void *context, struct fib * fibptr)
1447 struct aac_dev *dev;
1448 struct aac_read_reply *readreply;
1449 struct scsi_cmnd *scsicmd;
1452 scsicmd = (struct scsi_cmnd *) context;
1454 if (!aac_valid_context(scsicmd, fibptr))
1458 cid = scmd_id(scsicmd);
1460 if (nblank(dprintk(x))) {
1462 switch (scsicmd->cmnd[0]) {
1465 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1466 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1470 lba = ((u64)scsicmd->cmnd[2] << 56) |
1471 ((u64)scsicmd->cmnd[3] << 48) |
1472 ((u64)scsicmd->cmnd[4] << 40) |
1473 ((u64)scsicmd->cmnd[5] << 32) |
1474 ((u64)scsicmd->cmnd[6] << 24) |
1475 (scsicmd->cmnd[7] << 16) |
1476 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1480 lba = ((u64)scsicmd->cmnd[2] << 24) |
1481 (scsicmd->cmnd[3] << 16) |
1482 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1485 lba = ((u64)scsicmd->cmnd[2] << 24) |
1486 (scsicmd->cmnd[3] << 16) |
1487 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1491 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1492 smp_processor_id(), (unsigned long long)lba, jiffies);
1495 BUG_ON(fibptr == NULL);
1497 scsi_dma_unmap(scsicmd);
1499 readreply = (struct aac_read_reply *)fib_data(fibptr);
1500 if (le32_to_cpu(readreply->status) == ST_OK)
1501 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1503 #ifdef AAC_DETAILED_STATUS_INFO
1504 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1505 le32_to_cpu(readreply->status));
1507 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1508 set_sense(&dev->fsa_dev[cid].sense_data,
1509 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1510 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1511 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1512 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1513 SCSI_SENSE_BUFFERSIZE));
1515 aac_fib_complete(fibptr);
1516 aac_fib_free(fibptr);
1518 scsicmd->scsi_done(scsicmd);
1521 static int aac_read(struct scsi_cmnd * scsicmd)
1526 struct aac_dev *dev;
1527 struct fib * cmd_fibcontext;
1529 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1531 * Get block address and transfer length
1533 switch (scsicmd->cmnd[0]) {
1535 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1537 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1538 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1539 count = scsicmd->cmnd[4];
1545 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1547 lba = ((u64)scsicmd->cmnd[2] << 56) |
1548 ((u64)scsicmd->cmnd[3] << 48) |
1549 ((u64)scsicmd->cmnd[4] << 40) |
1550 ((u64)scsicmd->cmnd[5] << 32) |
1551 ((u64)scsicmd->cmnd[6] << 24) |
1552 (scsicmd->cmnd[7] << 16) |
1553 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1554 count = (scsicmd->cmnd[10] << 24) |
1555 (scsicmd->cmnd[11] << 16) |
1556 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1559 dprintk((KERN_DEBUG "aachba: received a read(12) 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[6] << 24) |
1565 (scsicmd->cmnd[7] << 16) |
1566 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1569 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1571 lba = ((u64)scsicmd->cmnd[2] << 24) |
1572 (scsicmd->cmnd[3] << 16) |
1573 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1574 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1577 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1578 smp_processor_id(), (unsigned long long)lba, jiffies));
1579 if (aac_adapter_bounds(dev,scsicmd,lba))
1582 * Alocate and initialize a Fib
1584 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1588 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1591 * Check that the command queued to the controller
1593 if (status == -EINPROGRESS) {
1594 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1598 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1600 * For some reason, the Fib didn't queue, return QUEUE_FULL
1602 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1603 scsicmd->scsi_done(scsicmd);
1604 aac_fib_complete(cmd_fibcontext);
1605 aac_fib_free(cmd_fibcontext);
1609 static int aac_write(struct scsi_cmnd * scsicmd)
1615 struct aac_dev *dev;
1616 struct fib * cmd_fibcontext;
1618 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1620 * Get block address and transfer length
1622 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1624 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1625 count = scsicmd->cmnd[4];
1629 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1630 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1632 lba = ((u64)scsicmd->cmnd[2] << 56) |
1633 ((u64)scsicmd->cmnd[3] << 48) |
1634 ((u64)scsicmd->cmnd[4] << 40) |
1635 ((u64)scsicmd->cmnd[5] << 32) |
1636 ((u64)scsicmd->cmnd[6] << 24) |
1637 (scsicmd->cmnd[7] << 16) |
1638 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1639 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1640 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1641 fua = scsicmd->cmnd[1] & 0x8;
1642 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1643 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1645 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1646 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1647 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1648 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1649 fua = scsicmd->cmnd[1] & 0x8;
1651 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1652 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1653 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1654 fua = scsicmd->cmnd[1] & 0x8;
1656 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1657 smp_processor_id(), (unsigned long long)lba, jiffies));
1658 if (aac_adapter_bounds(dev,scsicmd,lba))
1661 * Allocate and initialize a Fib then setup a BlockWrite command
1663 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1664 scsicmd->result = DID_ERROR << 16;
1665 scsicmd->scsi_done(scsicmd);
1669 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1672 * Check that the command queued to the controller
1674 if (status == -EINPROGRESS) {
1675 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1679 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1681 * For some reason, the Fib didn't queue, return QUEUE_FULL
1683 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1684 scsicmd->scsi_done(scsicmd);
1686 aac_fib_complete(cmd_fibcontext);
1687 aac_fib_free(cmd_fibcontext);
1691 static void synchronize_callback(void *context, struct fib *fibptr)
1693 struct aac_synchronize_reply *synchronizereply;
1694 struct scsi_cmnd *cmd;
1698 if (!aac_valid_context(cmd, fibptr))
1701 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1702 smp_processor_id(), jiffies));
1703 BUG_ON(fibptr == NULL);
1706 synchronizereply = fib_data(fibptr);
1707 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1708 cmd->result = DID_OK << 16 |
1709 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1711 struct scsi_device *sdev = cmd->device;
1712 struct aac_dev *dev = fibptr->dev;
1713 u32 cid = sdev_id(sdev);
1715 "synchronize_callback: synchronize failed, status = %d\n",
1716 le32_to_cpu(synchronizereply->status));
1717 cmd->result = DID_OK << 16 |
1718 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1719 set_sense(&dev->fsa_dev[cid].sense_data,
1720 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1721 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1722 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1723 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1724 SCSI_SENSE_BUFFERSIZE));
1727 aac_fib_complete(fibptr);
1728 aac_fib_free(fibptr);
1729 cmd->scsi_done(cmd);
1732 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1735 struct fib *cmd_fibcontext;
1736 struct aac_synchronize *synchronizecmd;
1737 struct scsi_cmnd *cmd;
1738 struct scsi_device *sdev = scsicmd->device;
1740 struct aac_dev *aac;
1741 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1742 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1743 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1744 unsigned long flags;
1747 * Wait for all outstanding queued commands to complete to this
1748 * specific target (block).
1750 spin_lock_irqsave(&sdev->list_lock, flags);
1751 list_for_each_entry(cmd, &sdev->cmd_list, list)
1752 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1756 if (cmd->cmnd[0] == WRITE_6) {
1757 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1758 (cmd->cmnd[2] << 8) |
1760 cmnd_count = cmd->cmnd[4];
1761 if (cmnd_count == 0)
1763 } else if (cmd->cmnd[0] == WRITE_16) {
1764 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1765 ((u64)cmd->cmnd[3] << 48) |
1766 ((u64)cmd->cmnd[4] << 40) |
1767 ((u64)cmd->cmnd[5] << 32) |
1768 ((u64)cmd->cmnd[6] << 24) |
1769 (cmd->cmnd[7] << 16) |
1770 (cmd->cmnd[8] << 8) |
1772 cmnd_count = (cmd->cmnd[10] << 24) |
1773 (cmd->cmnd[11] << 16) |
1774 (cmd->cmnd[12] << 8) |
1776 } else if (cmd->cmnd[0] == WRITE_12) {
1777 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1778 (cmd->cmnd[3] << 16) |
1779 (cmd->cmnd[4] << 8) |
1781 cmnd_count = (cmd->cmnd[6] << 24) |
1782 (cmd->cmnd[7] << 16) |
1783 (cmd->cmnd[8] << 8) |
1785 } else if (cmd->cmnd[0] == WRITE_10) {
1786 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1787 (cmd->cmnd[3] << 16) |
1788 (cmd->cmnd[4] << 8) |
1790 cmnd_count = (cmd->cmnd[7] << 8) |
1794 if (((cmnd_lba + cmnd_count) < lba) ||
1795 (count && ((lba + count) < cmnd_lba)))
1801 spin_unlock_irqrestore(&sdev->list_lock, flags);
1804 * Yield the processor (requeue for later)
1807 return SCSI_MLQUEUE_DEVICE_BUSY;
1809 aac = (struct aac_dev *)sdev->host->hostdata;
1811 return SCSI_MLQUEUE_HOST_BUSY;
1814 * Allocate and initialize a Fib
1816 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1817 return SCSI_MLQUEUE_HOST_BUSY;
1819 aac_fib_init(cmd_fibcontext);
1821 synchronizecmd = fib_data(cmd_fibcontext);
1822 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1823 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1824 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
1825 synchronizecmd->count =
1826 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1829 * Now send the Fib to the adapter
1831 status = aac_fib_send(ContainerCommand,
1833 sizeof(struct aac_synchronize),
1836 (fib_callback)synchronize_callback,
1840 * Check that the command queued to the controller
1842 if (status == -EINPROGRESS) {
1843 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1848 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1849 aac_fib_complete(cmd_fibcontext);
1850 aac_fib_free(cmd_fibcontext);
1851 return SCSI_MLQUEUE_HOST_BUSY;
1855 * aac_scsi_cmd() - Process SCSI command
1856 * @scsicmd: SCSI command block
1858 * Emulate a SCSI command and queue the required request for the
1862 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1865 struct Scsi_Host *host = scsicmd->device->host;
1866 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1867 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1869 if (fsa_dev_ptr == NULL)
1872 * If the bus, id or lun is out of range, return fail
1873 * Test does not apply to ID 16, the pseudo id for the controller
1876 cid = scmd_id(scsicmd);
1877 if (cid != host->this_id) {
1878 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
1879 if((cid >= dev->maximum_num_containers) ||
1880 (scsicmd->device->lun != 0)) {
1881 scsicmd->result = DID_NO_CONNECT << 16;
1882 scsicmd->scsi_done(scsicmd);
1887 * If the target container doesn't exist, it may have
1888 * been newly created
1890 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1891 switch (scsicmd->cmnd[0]) {
1892 case SERVICE_ACTION_IN:
1893 if (!(dev->raw_io_interface) ||
1894 !(dev->raw_io_64) ||
1895 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1899 case TEST_UNIT_READY:
1902 return _aac_probe_container(scsicmd,
1903 aac_probe_container_callback2);
1908 } else { /* check for physical non-dasd devices */
1909 if (dev->nondasd_support || expose_physicals ||
1913 return aac_send_srb_fib(scsicmd);
1915 scsicmd->result = DID_NO_CONNECT << 16;
1916 scsicmd->scsi_done(scsicmd);
1922 * else Command for the controller itself
1924 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1925 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1927 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1928 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1929 set_sense(&dev->fsa_dev[cid].sense_data,
1930 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1931 ASENCODE_INVALID_COMMAND, 0, 0);
1932 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1933 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1934 SCSI_SENSE_BUFFERSIZE));
1935 scsicmd->scsi_done(scsicmd);
1940 /* Handle commands here that don't really require going out to the adapter */
1941 switch (scsicmd->cmnd[0]) {
1944 struct inquiry_data inq_data;
1946 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
1947 memset(&inq_data, 0, sizeof (struct inquiry_data));
1949 if (scsicmd->cmnd[1] & 0x1) {
1950 char *arr = (char *)&inq_data;
1953 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
1954 INQD_PDT_PROC : INQD_PDT_DA;
1955 if (scsicmd->cmnd[2] == 0) {
1956 /* supported vital product data pages */
1960 arr[1] = scsicmd->cmnd[2];
1961 aac_internal_transfer(scsicmd, &inq_data, 0,
1963 scsicmd->result = DID_OK << 16 |
1964 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1965 } else if (scsicmd->cmnd[2] == 0x80) {
1966 /* unit serial number page */
1967 arr[3] = setinqserial(dev, &arr[4],
1969 arr[1] = scsicmd->cmnd[2];
1970 aac_internal_transfer(scsicmd, &inq_data, 0,
1972 return aac_get_container_serial(scsicmd);
1974 /* vpd page not implemented */
1975 scsicmd->result = DID_OK << 16 |
1976 COMMAND_COMPLETE << 8 |
1977 SAM_STAT_CHECK_CONDITION;
1978 set_sense(&dev->fsa_dev[cid].sense_data,
1979 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
1980 ASENCODE_NO_SENSE, 7, 2);
1981 memcpy(scsicmd->sense_buffer,
1982 &dev->fsa_dev[cid].sense_data,
1984 sizeof(dev->fsa_dev[cid].sense_data),
1985 SCSI_SENSE_BUFFERSIZE));
1987 scsicmd->scsi_done(scsicmd);
1990 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1991 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 */
1992 inq_data.inqd_len = 31;
1993 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1994 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1996 * Set the Vendor, Product, and Revision Level
1997 * see: <vendor>.c i.e. aac.c
1999 if (cid == host->this_id) {
2000 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
2001 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2002 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
2003 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2004 scsicmd->scsi_done(scsicmd);
2009 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2010 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2011 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
2012 return aac_get_container_name(scsicmd);
2014 case SERVICE_ACTION_IN:
2015 if (!(dev->raw_io_interface) ||
2016 !(dev->raw_io_64) ||
2017 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2023 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2024 capacity = fsa_dev_ptr[cid].size - 1;
2025 cp[0] = (capacity >> 56) & 0xff;
2026 cp[1] = (capacity >> 48) & 0xff;
2027 cp[2] = (capacity >> 40) & 0xff;
2028 cp[3] = (capacity >> 32) & 0xff;
2029 cp[4] = (capacity >> 24) & 0xff;
2030 cp[5] = (capacity >> 16) & 0xff;
2031 cp[6] = (capacity >> 8) & 0xff;
2032 cp[7] = (capacity >> 0) & 0xff;
2038 aac_internal_transfer(scsicmd, cp, 0,
2039 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
2040 if (sizeof(cp) < scsicmd->cmnd[13]) {
2041 unsigned int len, offset = sizeof(cp);
2043 memset(cp, 0, offset);
2045 len = min_t(size_t, scsicmd->cmnd[13] - offset,
2047 aac_internal_transfer(scsicmd, cp, offset, len);
2048 } while ((offset += len) < scsicmd->cmnd[13]);
2051 /* Do not cache partition table for arrays */
2052 scsicmd->device->removable = 1;
2054 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2055 scsicmd->scsi_done(scsicmd);
2065 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
2066 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2067 capacity = fsa_dev_ptr[cid].size - 1;
2071 cp[0] = (capacity >> 24) & 0xff;
2072 cp[1] = (capacity >> 16) & 0xff;
2073 cp[2] = (capacity >> 8) & 0xff;
2074 cp[3] = (capacity >> 0) & 0xff;
2079 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
2080 /* Do not cache partition table for arrays */
2081 scsicmd->device->removable = 1;
2083 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2084 scsicmd->scsi_done(scsicmd);
2092 int mode_buf_length = 4;
2094 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
2095 mode_buf[0] = 3; /* Mode data length */
2096 mode_buf[1] = 0; /* Medium type - default */
2097 mode_buf[2] = 0; /* Device-specific param,
2098 bit 8: 0/1 = write enabled/protected
2099 bit 4: 0/1 = FUA enabled */
2100 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2102 mode_buf[3] = 0; /* Block descriptor length */
2103 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2104 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2108 mode_buf[6] = ((aac_cache & 6) == 2)
2109 ? 0 : 0x04; /* WCE */
2110 mode_buf_length = 7;
2111 if (mode_buf_length > scsicmd->cmnd[4])
2112 mode_buf_length = scsicmd->cmnd[4];
2114 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
2115 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2116 scsicmd->scsi_done(scsicmd);
2123 int mode_buf_length = 8;
2125 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
2126 mode_buf[0] = 0; /* Mode data length (MSB) */
2127 mode_buf[1] = 6; /* Mode data length (LSB) */
2128 mode_buf[2] = 0; /* Medium type - default */
2129 mode_buf[3] = 0; /* Device-specific param,
2130 bit 8: 0/1 = write enabled/protected
2131 bit 4: 0/1 = FUA enabled */
2132 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2134 mode_buf[4] = 0; /* reserved */
2135 mode_buf[5] = 0; /* reserved */
2136 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2137 mode_buf[7] = 0; /* Block descriptor length (LSB) */
2138 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2139 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2143 mode_buf[10] = ((aac_cache & 6) == 2)
2144 ? 0 : 0x04; /* WCE */
2145 mode_buf_length = 11;
2146 if (mode_buf_length > scsicmd->cmnd[8])
2147 mode_buf_length = scsicmd->cmnd[8];
2149 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
2151 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2152 scsicmd->scsi_done(scsicmd);
2157 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2158 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2159 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2160 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2161 scsicmd->scsi_done(scsicmd);
2164 case ALLOW_MEDIUM_REMOVAL:
2165 dprintk((KERN_DEBUG "LOCK command.\n"));
2166 if (scsicmd->cmnd[4])
2167 fsa_dev_ptr[cid].locked = 1;
2169 fsa_dev_ptr[cid].locked = 0;
2171 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2172 scsicmd->scsi_done(scsicmd);
2175 * These commands are all No-Ops
2177 case TEST_UNIT_READY:
2181 case REASSIGN_BLOCKS:
2184 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2185 scsicmd->scsi_done(scsicmd);
2189 switch (scsicmd->cmnd[0])
2198 * Hack to keep track of ordinal number of the device that
2199 * corresponds to a container. Needed to convert
2200 * containers to /dev/sd device names
2203 if (scsicmd->request->rq_disk)
2204 strlcpy(fsa_dev_ptr[cid].devname,
2205 scsicmd->request->rq_disk->disk_name,
2206 min(sizeof(fsa_dev_ptr[cid].devname),
2207 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2209 return aac_read(scsicmd);
2217 return aac_write(scsicmd);
2219 case SYNCHRONIZE_CACHE:
2220 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2221 scsicmd->result = DID_OK << 16 |
2222 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2223 scsicmd->scsi_done(scsicmd);
2226 /* Issue FIB to tell Firmware to flush it's cache */
2227 if ((aac_cache & 6) != 2)
2228 return aac_synchronize(scsicmd);
2232 * Unhandled commands
2234 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2235 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2236 set_sense(&dev->fsa_dev[cid].sense_data,
2237 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2238 ASENCODE_INVALID_COMMAND, 0, 0);
2239 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2241 sizeof(dev->fsa_dev[cid].sense_data),
2242 SCSI_SENSE_BUFFERSIZE));
2243 scsicmd->scsi_done(scsicmd);
2248 static int query_disk(struct aac_dev *dev, void __user *arg)
2250 struct aac_query_disk qd;
2251 struct fsa_dev_info *fsa_dev_ptr;
2253 fsa_dev_ptr = dev->fsa_dev;
2256 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2260 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2262 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2264 qd.instance = dev->scsi_host_ptr->host_no;
2266 qd.id = CONTAINER_TO_ID(qd.cnum);
2267 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2269 else return -EINVAL;
2271 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
2272 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2273 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2275 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2280 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2281 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2283 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2288 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2290 struct aac_delete_disk dd;
2291 struct fsa_dev_info *fsa_dev_ptr;
2293 fsa_dev_ptr = dev->fsa_dev;
2297 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2300 if (dd.cnum >= dev->maximum_num_containers)
2303 * Mark this container as being deleted.
2305 fsa_dev_ptr[dd.cnum].deleted = 1;
2307 * Mark the container as no longer valid
2309 fsa_dev_ptr[dd.cnum].valid = 0;
2313 static int delete_disk(struct aac_dev *dev, void __user *arg)
2315 struct aac_delete_disk dd;
2316 struct fsa_dev_info *fsa_dev_ptr;
2318 fsa_dev_ptr = dev->fsa_dev;
2322 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2325 if (dd.cnum >= dev->maximum_num_containers)
2328 * If the container is locked, it can not be deleted by the API.
2330 if (fsa_dev_ptr[dd.cnum].locked)
2334 * Mark the container as no longer being valid.
2336 fsa_dev_ptr[dd.cnum].valid = 0;
2337 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2342 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2345 case FSACTL_QUERY_DISK:
2346 return query_disk(dev, arg);
2347 case FSACTL_DELETE_DISK:
2348 return delete_disk(dev, arg);
2349 case FSACTL_FORCE_DELETE_DISK:
2350 return force_delete_disk(dev, arg);
2351 case FSACTL_GET_CONTAINERS:
2352 return aac_get_containers(dev);
2361 * @context: the context set in the fib - here it is scsi cmd
2362 * @fibptr: pointer to the fib
2364 * Handles the completion of a scsi command to a non dasd device
2368 static void aac_srb_callback(void *context, struct fib * fibptr)
2370 struct aac_dev *dev;
2371 struct aac_srb_reply *srbreply;
2372 struct scsi_cmnd *scsicmd;
2374 scsicmd = (struct scsi_cmnd *) context;
2376 if (!aac_valid_context(scsicmd, fibptr))
2379 BUG_ON(fibptr == NULL);
2383 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2385 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2387 * Calculate resid for sg
2390 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2391 - le32_to_cpu(srbreply->data_xfer_length));
2393 scsi_dma_unmap(scsicmd);
2396 * First check the fib status
2399 if (le32_to_cpu(srbreply->status) != ST_OK){
2401 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2402 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2403 SCSI_SENSE_BUFFERSIZE);
2404 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2405 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2409 * Next check the srb status
2411 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2412 case SRB_STATUS_ERROR_RECOVERY:
2413 case SRB_STATUS_PENDING:
2414 case SRB_STATUS_SUCCESS:
2415 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2417 case SRB_STATUS_DATA_OVERRUN:
2418 switch(scsicmd->cmnd[0]){
2427 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
2428 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2430 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2432 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2435 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2439 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2443 case SRB_STATUS_ABORTED:
2444 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2446 case SRB_STATUS_ABORT_FAILED:
2447 // Not sure about this one - but assuming the hba was trying to abort for some reason
2448 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2450 case SRB_STATUS_PARITY_ERROR:
2451 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2453 case SRB_STATUS_NO_DEVICE:
2454 case SRB_STATUS_INVALID_PATH_ID:
2455 case SRB_STATUS_INVALID_TARGET_ID:
2456 case SRB_STATUS_INVALID_LUN:
2457 case SRB_STATUS_SELECTION_TIMEOUT:
2458 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2461 case SRB_STATUS_COMMAND_TIMEOUT:
2462 case SRB_STATUS_TIMEOUT:
2463 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2466 case SRB_STATUS_BUSY:
2467 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
2470 case SRB_STATUS_BUS_RESET:
2471 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2474 case SRB_STATUS_MESSAGE_REJECTED:
2475 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2477 case SRB_STATUS_REQUEST_FLUSHED:
2478 case SRB_STATUS_ERROR:
2479 case SRB_STATUS_INVALID_REQUEST:
2480 case SRB_STATUS_REQUEST_SENSE_FAILED:
2481 case SRB_STATUS_NO_HBA:
2482 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2483 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2484 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2485 case SRB_STATUS_DELAYED_RETRY:
2486 case SRB_STATUS_BAD_FUNCTION:
2487 case SRB_STATUS_NOT_STARTED:
2488 case SRB_STATUS_NOT_IN_USE:
2489 case SRB_STATUS_FORCE_ABORT:
2490 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2492 #ifdef AAC_DETAILED_STATUS_INFO
2493 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2494 le32_to_cpu(srbreply->srb_status) & 0x3F,
2495 aac_get_status_string(
2496 le32_to_cpu(srbreply->srb_status) & 0x3F),
2498 le32_to_cpu(srbreply->scsi_status));
2500 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2503 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
2505 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2506 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2507 SCSI_SENSE_BUFFERSIZE);
2508 #ifdef AAC_DETAILED_STATUS_INFO
2509 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2510 le32_to_cpu(srbreply->status), len);
2512 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2515 * OR in the scsi status (already shifted up a bit)
2517 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2519 aac_fib_complete(fibptr);
2520 aac_fib_free(fibptr);
2521 scsicmd->scsi_done(scsicmd);
2527 * @scsicmd: the scsi command block
2529 * This routine will form a FIB and fill in the aac_srb from the
2530 * scsicmd passed in.
2533 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2535 struct fib* cmd_fibcontext;
2536 struct aac_dev* dev;
2539 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2540 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2541 scsicmd->device->lun > 7) {
2542 scsicmd->result = DID_NO_CONNECT << 16;
2543 scsicmd->scsi_done(scsicmd);
2548 * Allocate and initialize a Fib then setup a BlockWrite command
2550 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2553 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2556 * Check that the command queued to the controller
2558 if (status == -EINPROGRESS) {
2559 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2563 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2564 aac_fib_complete(cmd_fibcontext);
2565 aac_fib_free(cmd_fibcontext);
2570 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2572 struct aac_dev *dev;
2573 unsigned long byte_count = 0;
2576 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2577 // Get rid of old data
2579 psg->sg[0].addr = 0;
2580 psg->sg[0].count = 0;
2582 nseg = scsi_dma_map(scsicmd);
2585 struct scatterlist *sg;
2588 psg->count = cpu_to_le32(nseg);
2590 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2591 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2592 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2593 byte_count += sg_dma_len(sg);
2595 /* hba wants the size to be exact */
2596 if (byte_count > scsi_bufflen(scsicmd)) {
2597 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2598 (byte_count - scsi_bufflen(scsicmd));
2599 psg->sg[i-1].count = cpu_to_le32(temp);
2600 byte_count = scsi_bufflen(scsicmd);
2602 /* Check for command underflow */
2603 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2604 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2605 byte_count, scsicmd->underflow);
2612 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2614 struct aac_dev *dev;
2615 unsigned long byte_count = 0;
2619 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2620 // Get rid of old data
2622 psg->sg[0].addr[0] = 0;
2623 psg->sg[0].addr[1] = 0;
2624 psg->sg[0].count = 0;
2626 nseg = scsi_dma_map(scsicmd);
2629 struct scatterlist *sg;
2632 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2633 int count = sg_dma_len(sg);
2634 addr = sg_dma_address(sg);
2635 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2636 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2637 psg->sg[i].count = cpu_to_le32(count);
2638 byte_count += count;
2640 psg->count = cpu_to_le32(nseg);
2641 /* hba wants the size to be exact */
2642 if (byte_count > scsi_bufflen(scsicmd)) {
2643 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2644 (byte_count - scsi_bufflen(scsicmd));
2645 psg->sg[i-1].count = cpu_to_le32(temp);
2646 byte_count = scsi_bufflen(scsicmd);
2648 /* Check for command underflow */
2649 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2650 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2651 byte_count, scsicmd->underflow);
2657 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2659 unsigned long byte_count = 0;
2662 // Get rid of old data
2664 psg->sg[0].next = 0;
2665 psg->sg[0].prev = 0;
2666 psg->sg[0].addr[0] = 0;
2667 psg->sg[0].addr[1] = 0;
2668 psg->sg[0].count = 0;
2669 psg->sg[0].flags = 0;
2671 nseg = scsi_dma_map(scsicmd);
2674 struct scatterlist *sg;
2677 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2678 int count = sg_dma_len(sg);
2679 u64 addr = sg_dma_address(sg);
2680 psg->sg[i].next = 0;
2681 psg->sg[i].prev = 0;
2682 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2683 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2684 psg->sg[i].count = cpu_to_le32(count);
2685 psg->sg[i].flags = 0;
2686 byte_count += count;
2688 psg->count = cpu_to_le32(nseg);
2689 /* hba wants the size to be exact */
2690 if (byte_count > scsi_bufflen(scsicmd)) {
2691 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2692 (byte_count - scsi_bufflen(scsicmd));
2693 psg->sg[i-1].count = cpu_to_le32(temp);
2694 byte_count = scsi_bufflen(scsicmd);
2696 /* Check for command underflow */
2697 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2698 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2699 byte_count, scsicmd->underflow);
2705 #ifdef AAC_DETAILED_STATUS_INFO
2707 struct aac_srb_status_info {
2713 static struct aac_srb_status_info srb_status_info[] = {
2714 { SRB_STATUS_PENDING, "Pending Status"},
2715 { SRB_STATUS_SUCCESS, "Success"},
2716 { SRB_STATUS_ABORTED, "Aborted Command"},
2717 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2718 { SRB_STATUS_ERROR, "Error Event"},
2719 { SRB_STATUS_BUSY, "Device Busy"},
2720 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2721 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2722 { SRB_STATUS_NO_DEVICE, "No Device"},
2723 { SRB_STATUS_TIMEOUT, "Timeout"},
2724 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2725 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2726 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2727 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2728 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2729 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2730 { SRB_STATUS_NO_HBA, "No HBA"},
2731 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2732 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2733 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2734 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2735 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2736 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2737 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2738 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2739 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2740 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2741 { SRB_STATUS_NOT_STARTED, "Not Started"},
2742 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2743 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2744 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2745 { 0xff, "Unknown Error"}
2748 char *aac_get_status_string(u32 status)
2752 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2753 if (srb_status_info[i].status == status)
2754 return srb_status_info[i].str;
2756 return "Bad Status Code";