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;
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."
157 module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
158 MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
159 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
160 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
161 "\tbit 2 - Disable only if Battery not protecting Cache");
162 module_param(dacmode, int, S_IRUGO|S_IWUSR);
163 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
165 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
166 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
167 " adapter for foreign arrays.\n"
168 "This is typically needed in systems that do not have a BIOS."
170 module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
171 MODULE_PARM_DESC(msi, "IRQ handling."
172 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
173 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
174 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
175 " adapter to have it's kernel up and\n"
176 "running. This is typically adjusted for large systems that do not"
178 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
179 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
180 " applications to pick up AIFs before\n"
181 "deregistering them. This is typically adjusted for heavily burdened"
185 module_param(numacb, int, S_IRUGO|S_IWUSR);
186 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
187 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
188 " to use suggestion from Firmware.");
191 module_param(acbsize, int, S_IRUGO|S_IWUSR);
192 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
193 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
194 " suggestion from Firmware.");
196 int update_interval = 30 * 60;
197 module_param(update_interval, int, S_IRUGO|S_IWUSR);
198 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
199 " updates issued to adapter.");
201 int check_interval = 24 * 60 * 60;
202 module_param(check_interval, int, S_IRUGO|S_IWUSR);
203 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
206 int aac_check_reset = 1;
207 module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
208 MODULE_PARM_DESC(aac_check_reset, "If adapter fails health check, reset the"
209 " adapter. a value of -1 forces the reset to adapters programmed to"
212 int expose_physicals = -1;
213 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
214 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
215 " -1=protect 0=off, 1=on");
217 int aac_reset_devices;
218 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
219 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
221 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
222 struct fib *fibptr) {
223 struct scsi_device *device;
225 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
226 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
227 aac_fib_complete(fibptr);
228 aac_fib_free(fibptr);
231 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
232 device = scsicmd->device;
233 if (unlikely(!device || !scsi_device_online(device))) {
234 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
235 aac_fib_complete(fibptr);
236 aac_fib_free(fibptr);
243 * aac_get_config_status - check the adapter configuration
244 * @common: adapter to query
246 * Query config status, and commit the configuration if needed.
248 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
253 if (!(fibptr = aac_fib_alloc(dev)))
256 aac_fib_init(fibptr);
258 struct aac_get_config_status *dinfo;
259 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
261 dinfo->command = cpu_to_le32(VM_ContainerConfig);
262 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
263 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
266 status = aac_fib_send(ContainerCommand,
268 sizeof (struct aac_get_config_status),
273 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
275 struct aac_get_config_status_resp *reply
276 = (struct aac_get_config_status_resp *) fib_data(fibptr);
277 dprintk((KERN_WARNING
278 "aac_get_config_status: response=%d status=%d action=%d\n",
279 le32_to_cpu(reply->response),
280 le32_to_cpu(reply->status),
281 le32_to_cpu(reply->data.action)));
282 if ((le32_to_cpu(reply->response) != ST_OK) ||
283 (le32_to_cpu(reply->status) != CT_OK) ||
284 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
285 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
289 aac_fib_complete(fibptr);
290 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
292 if ((aac_commit == 1) || commit_flag) {
293 struct aac_commit_config * dinfo;
294 aac_fib_init(fibptr);
295 dinfo = (struct aac_commit_config *) fib_data(fibptr);
297 dinfo->command = cpu_to_le32(VM_ContainerConfig);
298 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
300 status = aac_fib_send(ContainerCommand,
302 sizeof (struct aac_commit_config),
306 aac_fib_complete(fibptr);
307 } else if (aac_commit == 0) {
309 "aac_get_config_status: Foreign device configurations are being ignored\n");
312 aac_fib_free(fibptr);
317 * aac_get_containers - list containers
318 * @common: adapter to probe
320 * Make a list of all containers on this controller
322 int aac_get_containers(struct aac_dev *dev)
324 struct fsa_dev_info *fsa_dev_ptr;
328 struct aac_get_container_count *dinfo;
329 struct aac_get_container_count_resp *dresp;
330 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
332 if (!(fibptr = aac_fib_alloc(dev)))
335 aac_fib_init(fibptr);
336 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
337 dinfo->command = cpu_to_le32(VM_ContainerConfig);
338 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
340 status = aac_fib_send(ContainerCommand,
342 sizeof (struct aac_get_container_count),
347 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
348 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
349 aac_fib_complete(fibptr);
351 aac_fib_free(fibptr);
353 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
354 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
355 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
360 dev->fsa_dev = fsa_dev_ptr;
361 dev->maximum_num_containers = maximum_num_containers;
363 for (index = 0; index < dev->maximum_num_containers; ) {
364 fsa_dev_ptr[index].devname[0] = '\0';
366 status = aac_probe_container(dev, index);
369 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
374 * If there are no more containers, then stop asking.
376 if (++index >= status)
382 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
386 struct scatterlist *sg = scsi_sglist(scsicmd);
388 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
389 transfer_len = min(sg->length, len + offset);
391 transfer_len -= offset;
392 if (buf && transfer_len > 0)
393 memcpy(buf + offset, data, transfer_len);
395 flush_kernel_dcache_page(kmap_atomic_to_page(buf - sg->offset));
396 kunmap_atomic(buf - sg->offset, KM_IRQ0);
400 static void get_container_name_callback(void *context, struct fib * fibptr)
402 struct aac_get_name_resp * get_name_reply;
403 struct scsi_cmnd * scsicmd;
405 scsicmd = (struct scsi_cmnd *) context;
407 if (!aac_valid_context(scsicmd, fibptr))
410 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
411 BUG_ON(fibptr == NULL);
413 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
414 /* Failure is irrelevant, using default value instead */
415 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
416 && (get_name_reply->data[0] != '\0')) {
417 char *sp = get_name_reply->data;
418 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
422 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
423 int count = sizeof(d);
426 *dp++ = (*sp) ? *sp++ : ' ';
427 } while (--count > 0);
428 aac_internal_transfer(scsicmd, d,
429 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
433 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
435 aac_fib_complete(fibptr);
436 aac_fib_free(fibptr);
437 scsicmd->scsi_done(scsicmd);
441 * aac_get_container_name - get container name, none blocking.
443 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
446 struct aac_get_name *dinfo;
447 struct fib * cmd_fibcontext;
448 struct aac_dev * dev;
450 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
452 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
455 aac_fib_init(cmd_fibcontext);
456 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
458 dinfo->command = cpu_to_le32(VM_ContainerConfig);
459 dinfo->type = cpu_to_le32(CT_READ_NAME);
460 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
461 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
463 status = aac_fib_send(ContainerCommand,
465 sizeof (struct aac_get_name),
468 (fib_callback)get_container_name_callback,
472 * Check that the command queued to the controller
474 if (status == -EINPROGRESS) {
475 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
479 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
480 aac_fib_complete(cmd_fibcontext);
481 aac_fib_free(cmd_fibcontext);
485 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
487 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
489 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
490 return aac_scsi_cmd(scsicmd);
492 scsicmd->result = DID_NO_CONNECT << 16;
493 scsicmd->scsi_done(scsicmd);
497 static void _aac_probe_container2(void * context, struct fib * fibptr)
499 struct fsa_dev_info *fsa_dev_ptr;
500 int (*callback)(struct scsi_cmnd *);
501 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
504 if (!aac_valid_context(scsicmd, fibptr))
507 scsicmd->SCp.Status = 0;
508 fsa_dev_ptr = fibptr->dev->fsa_dev;
510 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
511 fsa_dev_ptr += scmd_id(scsicmd);
513 if ((le32_to_cpu(dresp->status) == ST_OK) &&
514 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
515 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
516 fsa_dev_ptr->valid = 1;
517 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
519 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
520 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
521 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
523 if ((fsa_dev_ptr->valid & 1) == 0)
524 fsa_dev_ptr->valid = 0;
525 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
527 aac_fib_complete(fibptr);
528 aac_fib_free(fibptr);
529 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
530 scsicmd->SCp.ptr = NULL;
531 (*callback)(scsicmd);
535 static void _aac_probe_container1(void * context, struct fib * fibptr)
537 struct scsi_cmnd * scsicmd;
538 struct aac_mount * dresp;
539 struct aac_query_mount *dinfo;
542 dresp = (struct aac_mount *) fib_data(fibptr);
543 dresp->mnt[0].capacityhigh = 0;
544 if ((le32_to_cpu(dresp->status) != ST_OK) ||
545 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
546 _aac_probe_container2(context, fibptr);
549 scsicmd = (struct scsi_cmnd *) context;
551 if (!aac_valid_context(scsicmd, fibptr))
554 aac_fib_init(fibptr);
556 dinfo = (struct aac_query_mount *)fib_data(fibptr);
558 dinfo->command = cpu_to_le32(VM_NameServe64);
559 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
560 dinfo->type = cpu_to_le32(FT_FILESYS);
562 status = aac_fib_send(ContainerCommand,
564 sizeof(struct aac_query_mount),
567 _aac_probe_container2,
570 * Check that the command queued to the controller
572 if (status == -EINPROGRESS)
573 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
574 else if (status < 0) {
575 /* Inherit results from VM_NameServe, if any */
576 dresp->status = cpu_to_le32(ST_OK);
577 _aac_probe_container2(context, fibptr);
581 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
584 int status = -ENOMEM;
586 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
587 struct aac_query_mount *dinfo;
589 aac_fib_init(fibptr);
591 dinfo = (struct aac_query_mount *)fib_data(fibptr);
593 dinfo->command = cpu_to_le32(VM_NameServe);
594 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
595 dinfo->type = cpu_to_le32(FT_FILESYS);
596 scsicmd->SCp.ptr = (char *)callback;
598 status = aac_fib_send(ContainerCommand,
600 sizeof(struct aac_query_mount),
603 _aac_probe_container1,
606 * Check that the command queued to the controller
608 if (status == -EINPROGRESS) {
609 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
613 scsicmd->SCp.ptr = NULL;
614 aac_fib_complete(fibptr);
615 aac_fib_free(fibptr);
619 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
621 fsa_dev_ptr += scmd_id(scsicmd);
622 if ((fsa_dev_ptr->valid & 1) == 0) {
623 fsa_dev_ptr->valid = 0;
624 return (*callback)(scsicmd);
632 * aac_probe_container - query a logical volume
633 * @dev: device to query
634 * @cid: container identifier
636 * Queries the controller about the given volume. The volume information
637 * is updated in the struct fsa_dev_info structure rather than returned.
639 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
641 scsicmd->device = NULL;
645 int aac_probe_container(struct aac_dev *dev, int cid)
647 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
648 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
651 if (!scsicmd || !scsidev) {
656 scsicmd->list.next = NULL;
657 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
659 scsicmd->device = scsidev;
660 scsidev->sdev_state = 0;
662 scsidev->host = dev->scsi_host_ptr;
664 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
665 while (scsicmd->device == scsidev)
668 status = scsicmd->SCp.Status;
673 /* Local Structure to set SCSI inquiry data strings */
675 char vid[8]; /* Vendor ID */
676 char pid[16]; /* Product ID */
677 char prl[4]; /* Product Revision Level */
681 * InqStrCopy - string merge
682 * @a: string to copy from
683 * @b: string to copy to
685 * Copy a String from one location to another
689 static void inqstrcpy(char *a, char *b)
692 while (*a != (char)0)
696 static char *container_types[] = {
720 char * get_container_type(unsigned tindex)
722 if (tindex >= ARRAY_SIZE(container_types))
723 tindex = ARRAY_SIZE(container_types) - 1;
724 return container_types[tindex];
727 /* Function: setinqstr
729 * Arguments: [1] pointer to void [1] int
731 * Purpose: Sets SCSI inquiry data strings for vendor, product
732 * and revision level. Allows strings to be set in platform dependant
733 * files instead of in OS dependant driver source.
736 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
738 struct scsi_inq *str;
740 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
741 memset(str, ' ', sizeof(*str));
743 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
744 char * cp = dev->supplement_adapter_info.AdapterTypeText;
746 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
747 inqstrcpy("SMC", str->vid);
749 c = sizeof(str->vid);
750 while (*cp && *cp != ' ' && --c)
754 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
757 while (*cp && *cp != ' ')
762 /* last six chars reserved for vol type */
764 if (strlen(cp) > sizeof(str->pid)) {
765 c = cp[sizeof(str->pid)];
766 cp[sizeof(str->pid)] = '\0';
768 inqstrcpy (cp, str->pid);
770 cp[sizeof(str->pid)] = c;
772 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
774 inqstrcpy (mp->vname, str->vid);
775 /* last six chars reserved for vol type */
776 inqstrcpy (mp->model, str->pid);
779 if (tindex < ARRAY_SIZE(container_types)){
780 char *findit = str->pid;
782 for ( ; *findit != ' '; findit++); /* walk till we find a space */
783 /* RAID is superfluous in the context of a RAID device */
784 if (memcmp(findit-4, "RAID", 4) == 0)
785 *(findit -= 4) = ' ';
786 if (((findit - str->pid) + strlen(container_types[tindex]))
787 < (sizeof(str->pid) + sizeof(str->prl)))
788 inqstrcpy (container_types[tindex], findit + 1);
790 inqstrcpy ("V1.0", str->prl);
793 static void get_container_serial_callback(void *context, struct fib * fibptr)
795 struct aac_get_serial_resp * get_serial_reply;
796 struct scsi_cmnd * scsicmd;
798 BUG_ON(fibptr == NULL);
800 scsicmd = (struct scsi_cmnd *) context;
801 if (!aac_valid_context(scsicmd, fibptr))
804 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
805 /* Failure is irrelevant, using default value instead */
806 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
810 sp[1] = scsicmd->cmnd[2];
812 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
813 le32_to_cpu(get_serial_reply->uid));
814 aac_internal_transfer(scsicmd, sp, 0, sizeof(sp));
817 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
819 aac_fib_complete(fibptr);
820 aac_fib_free(fibptr);
821 scsicmd->scsi_done(scsicmd);
825 * aac_get_container_serial - get container serial, none blocking.
827 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
830 struct aac_get_serial *dinfo;
831 struct fib * cmd_fibcontext;
832 struct aac_dev * dev;
834 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
836 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
839 aac_fib_init(cmd_fibcontext);
840 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
842 dinfo->command = cpu_to_le32(VM_ContainerConfig);
843 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
844 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
846 status = aac_fib_send(ContainerCommand,
848 sizeof (struct aac_get_serial),
851 (fib_callback) get_container_serial_callback,
855 * Check that the command queued to the controller
857 if (status == -EINPROGRESS) {
858 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
862 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
863 aac_fib_complete(cmd_fibcontext);
864 aac_fib_free(cmd_fibcontext);
868 /* Function: setinqserial
870 * Arguments: [1] pointer to void [1] int
872 * Purpose: Sets SCSI Unit Serial number.
873 * This is a fake. We should read a proper
874 * serial number from the container. <SuSE>But
875 * without docs it's quite hard to do it :-)
876 * So this will have to do in the meantime.</SuSE>
879 static int setinqserial(struct aac_dev *dev, void *data, int cid)
882 * This breaks array migration.
884 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
885 le32_to_cpu(dev->adapter_info.serial[0]), cid);
888 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
889 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
891 u8 *sense_buf = (u8 *)sense_data;
892 /* Sense data valid, err code 70h */
893 sense_buf[0] = 0x70; /* No info field */
894 sense_buf[1] = 0; /* Segment number, always zero */
896 sense_buf[2] = sense_key; /* Sense key */
898 sense_buf[12] = sense_code; /* Additional sense code */
899 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
901 if (sense_key == ILLEGAL_REQUEST) {
902 sense_buf[7] = 10; /* Additional sense length */
904 sense_buf[15] = bit_pointer;
905 /* Illegal parameter is in the parameter block */
906 if (sense_code == SENCODE_INVALID_CDB_FIELD)
907 sense_buf[15] |= 0xc0;/* Std sense key specific field */
908 /* Illegal parameter is in the CDB block */
909 sense_buf[16] = field_pointer >> 8; /* MSB */
910 sense_buf[17] = field_pointer; /* LSB */
912 sense_buf[7] = 6; /* Additional sense length */
915 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
917 if (lba & 0xffffffff00000000LL) {
918 int cid = scmd_id(cmd);
919 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
920 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
921 SAM_STAT_CHECK_CONDITION;
922 set_sense(&dev->fsa_dev[cid].sense_data,
923 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
924 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
925 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
926 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
927 SCSI_SENSE_BUFFERSIZE));
934 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
939 static void io_callback(void *context, struct fib * fibptr);
941 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
944 struct aac_raw_io *readcmd;
946 readcmd = (struct aac_raw_io *) fib_data(fib);
947 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
948 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
949 readcmd->count = cpu_to_le32(count<<9);
950 readcmd->cid = cpu_to_le16(scmd_id(cmd));
951 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
952 readcmd->bpTotal = 0;
953 readcmd->bpComplete = 0;
955 aac_build_sgraw(cmd, &readcmd->sg);
956 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
957 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
959 * Now send the Fib to the adapter
961 return aac_fib_send(ContainerRawIo,
966 (fib_callback) io_callback,
970 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
973 struct aac_read64 *readcmd;
975 readcmd = (struct aac_read64 *) fib_data(fib);
976 readcmd->command = cpu_to_le32(VM_CtHostRead64);
977 readcmd->cid = cpu_to_le16(scmd_id(cmd));
978 readcmd->sector_count = cpu_to_le16(count);
979 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
983 aac_build_sg64(cmd, &readcmd->sg);
984 fibsize = sizeof(struct aac_read64) +
985 ((le32_to_cpu(readcmd->sg.count) - 1) *
986 sizeof (struct sgentry64));
987 BUG_ON (fibsize > (fib->dev->max_fib_size -
988 sizeof(struct aac_fibhdr)));
990 * Now send the Fib to the adapter
992 return aac_fib_send(ContainerCommand64,
997 (fib_callback) io_callback,
1001 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1004 struct aac_read *readcmd;
1006 readcmd = (struct aac_read *) fib_data(fib);
1007 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1008 readcmd->cid = cpu_to_le32(scmd_id(cmd));
1009 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1010 readcmd->count = cpu_to_le32(count * 512);
1012 aac_build_sg(cmd, &readcmd->sg);
1013 fibsize = sizeof(struct aac_read) +
1014 ((le32_to_cpu(readcmd->sg.count) - 1) *
1015 sizeof (struct sgentry));
1016 BUG_ON (fibsize > (fib->dev->max_fib_size -
1017 sizeof(struct aac_fibhdr)));
1019 * Now send the Fib to the adapter
1021 return aac_fib_send(ContainerCommand,
1026 (fib_callback) io_callback,
1030 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1033 struct aac_raw_io *writecmd;
1035 writecmd = (struct aac_raw_io *) fib_data(fib);
1036 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1037 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1038 writecmd->count = cpu_to_le32(count<<9);
1039 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1040 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1041 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1042 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
1043 cpu_to_le16(IO_TYPE_WRITE);
1044 writecmd->bpTotal = 0;
1045 writecmd->bpComplete = 0;
1047 aac_build_sgraw(cmd, &writecmd->sg);
1048 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1049 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1051 * Now send the Fib to the adapter
1053 return aac_fib_send(ContainerRawIo,
1058 (fib_callback) io_callback,
1062 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1065 struct aac_write64 *writecmd;
1067 writecmd = (struct aac_write64 *) fib_data(fib);
1068 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1069 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1070 writecmd->sector_count = cpu_to_le16(count);
1071 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1073 writecmd->flags = 0;
1075 aac_build_sg64(cmd, &writecmd->sg);
1076 fibsize = sizeof(struct aac_write64) +
1077 ((le32_to_cpu(writecmd->sg.count) - 1) *
1078 sizeof (struct sgentry64));
1079 BUG_ON (fibsize > (fib->dev->max_fib_size -
1080 sizeof(struct aac_fibhdr)));
1082 * Now send the Fib to the adapter
1084 return aac_fib_send(ContainerCommand64,
1089 (fib_callback) io_callback,
1093 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1096 struct aac_write *writecmd;
1098 writecmd = (struct aac_write *) fib_data(fib);
1099 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1100 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1101 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1102 writecmd->count = cpu_to_le32(count * 512);
1103 writecmd->sg.count = cpu_to_le32(1);
1104 /* ->stable is not used - it did mean which type of write */
1106 aac_build_sg(cmd, &writecmd->sg);
1107 fibsize = sizeof(struct aac_write) +
1108 ((le32_to_cpu(writecmd->sg.count) - 1) *
1109 sizeof (struct sgentry));
1110 BUG_ON (fibsize > (fib->dev->max_fib_size -
1111 sizeof(struct aac_fibhdr)));
1113 * Now send the Fib to the adapter
1115 return aac_fib_send(ContainerCommand,
1120 (fib_callback) io_callback,
1124 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1126 struct aac_srb * srbcmd;
1131 switch(cmd->sc_data_direction){
1135 case DMA_BIDIRECTIONAL:
1136 flag = SRB_DataIn | SRB_DataOut;
1138 case DMA_FROM_DEVICE:
1142 default: /* shuts up some versions of gcc */
1143 flag = SRB_NoDataXfer;
1147 srbcmd = (struct aac_srb*) fib_data(fib);
1148 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1149 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1150 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1151 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1152 srbcmd->flags = cpu_to_le32(flag);
1153 timeout = cmd->timeout_per_command/HZ;
1156 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1157 srbcmd->retry_limit = 0; /* Obsolete parameter */
1158 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1162 static void aac_srb_callback(void *context, struct fib * fibptr);
1164 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1167 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1169 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1170 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1172 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1173 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1175 * Build Scatter/Gather list
1177 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1178 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1179 sizeof (struct sgentry64));
1180 BUG_ON (fibsize > (fib->dev->max_fib_size -
1181 sizeof(struct aac_fibhdr)));
1184 * Now send the Fib to the adapter
1186 return aac_fib_send(ScsiPortCommand64, fib,
1187 fibsize, FsaNormal, 0, 1,
1188 (fib_callback) aac_srb_callback,
1192 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1195 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1197 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1198 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1200 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1201 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1203 * Build Scatter/Gather list
1205 fibsize = sizeof (struct aac_srb) +
1206 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1207 sizeof (struct sgentry));
1208 BUG_ON (fibsize > (fib->dev->max_fib_size -
1209 sizeof(struct aac_fibhdr)));
1212 * Now send the Fib to the adapter
1214 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1215 (fib_callback) aac_srb_callback, (void *) cmd);
1218 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1220 if ((sizeof(dma_addr_t) > 4) &&
1221 (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) &&
1222 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1224 return aac_scsi_32(fib, cmd);
1227 int aac_get_adapter_info(struct aac_dev* dev)
1232 struct aac_adapter_info *info;
1233 struct aac_bus_info *command;
1234 struct aac_bus_info_response *bus_info;
1236 if (!(fibptr = aac_fib_alloc(dev)))
1239 aac_fib_init(fibptr);
1240 info = (struct aac_adapter_info *) fib_data(fibptr);
1241 memset(info,0,sizeof(*info));
1243 rcode = aac_fib_send(RequestAdapterInfo,
1247 -1, 1, /* First `interrupt' command uses special wait */
1252 aac_fib_complete(fibptr);
1253 aac_fib_free(fibptr);
1256 memcpy(&dev->adapter_info, info, sizeof(*info));
1258 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1259 struct aac_supplement_adapter_info * sinfo;
1261 aac_fib_init(fibptr);
1263 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1265 memset(sinfo,0,sizeof(*sinfo));
1267 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1276 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
1284 aac_fib_init(fibptr);
1286 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1288 memset(bus_info, 0, sizeof(*bus_info));
1290 command = (struct aac_bus_info *)bus_info;
1292 command->Command = cpu_to_le32(VM_Ioctl);
1293 command->ObjType = cpu_to_le32(FT_DRIVE);
1294 command->MethodId = cpu_to_le32(1);
1295 command->CtlCmd = cpu_to_le32(GetBusInfo);
1297 rcode = aac_fib_send(ContainerCommand,
1304 /* reasoned default */
1305 dev->maximum_num_physicals = 16;
1306 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1307 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1308 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1311 if (!dev->in_reset) {
1313 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1314 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1320 le32_to_cpu(dev->adapter_info.kernelbuild),
1321 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1322 dev->supplement_adapter_info.BuildDate);
1323 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1324 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1326 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1327 le32_to_cpu(dev->adapter_info.monitorbuild));
1328 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1329 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1331 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1332 le32_to_cpu(dev->adapter_info.biosbuild));
1334 if (aac_show_serial_number(
1335 shost_to_class(dev->scsi_host_ptr), buffer))
1336 printk(KERN_INFO "%s%d: serial %s",
1337 dev->name, dev->id, buffer);
1338 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1339 printk(KERN_INFO "%s%d: TSID %.*s\n",
1341 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1342 dev->supplement_adapter_info.VpdInfo.Tsid);
1344 if (!aac_check_reset || ((aac_check_reset != 1) &&
1345 (dev->supplement_adapter_info.SupportedOptions2 &
1346 AAC_OPTION_IGNORE_RESET))) {
1347 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1348 dev->name, dev->id);
1352 dev->cache_protected = 0;
1353 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1354 AAC_FEATURE_JBOD) != 0);
1355 dev->nondasd_support = 0;
1356 dev->raid_scsi_mode = 0;
1357 if(dev->adapter_info.options & AAC_OPT_NONDASD)
1358 dev->nondasd_support = 1;
1361 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1362 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1363 * force nondasd support on. If we decide to allow the non-dasd flag
1364 * additional changes changes will have to be made to support
1365 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1366 * changed to support the new dev->raid_scsi_mode flag instead of
1367 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1368 * function aac_detect will have to be modified where it sets up the
1369 * max number of channels based on the aac->nondasd_support flag only.
1371 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1372 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1373 dev->nondasd_support = 1;
1374 dev->raid_scsi_mode = 1;
1376 if (dev->raid_scsi_mode != 0)
1377 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1378 dev->name, dev->id);
1381 dev->nondasd_support = (nondasd!=0);
1382 if(dev->nondasd_support != 0) {
1383 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1386 dev->dac_support = 0;
1387 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1388 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1389 dev->dac_support = 1;
1393 dev->dac_support = (dacmode!=0);
1395 if(dev->dac_support != 0) {
1396 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1397 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1398 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1399 dev->name, dev->id);
1400 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1401 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1402 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1403 dev->name, dev->id);
1404 dev->dac_support = 0;
1406 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1407 dev->name, dev->id);
1412 * Deal with configuring for the individualized limits of each packet
1415 dev->a_ops.adapter_scsi = (dev->dac_support)
1416 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1420 if (dev->raw_io_interface) {
1421 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1424 dev->a_ops.adapter_read = aac_read_raw_io;
1425 dev->a_ops.adapter_write = aac_write_raw_io;
1427 dev->a_ops.adapter_bounds = aac_bounds_32;
1428 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1429 sizeof(struct aac_fibhdr) -
1430 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1431 sizeof(struct sgentry);
1432 if (dev->dac_support) {
1433 dev->a_ops.adapter_read = aac_read_block64;
1434 dev->a_ops.adapter_write = aac_write_block64;
1436 * 38 scatter gather elements
1438 dev->scsi_host_ptr->sg_tablesize =
1439 (dev->max_fib_size -
1440 sizeof(struct aac_fibhdr) -
1441 sizeof(struct aac_write64) +
1442 sizeof(struct sgentry64)) /
1443 sizeof(struct sgentry64);
1445 dev->a_ops.adapter_read = aac_read_block;
1446 dev->a_ops.adapter_write = aac_write_block;
1448 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1449 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1451 * Worst case size that could cause sg overflow when
1452 * we break up SG elements that are larger than 64KB.
1453 * Would be nice if we could tell the SCSI layer what
1454 * the maximum SG element size can be. Worst case is
1455 * (sg_tablesize-1) 4KB elements with one 64KB
1457 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1459 dev->scsi_host_ptr->max_sectors =
1460 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1464 aac_fib_complete(fibptr);
1465 aac_fib_free(fibptr);
1471 static void io_callback(void *context, struct fib * fibptr)
1473 struct aac_dev *dev;
1474 struct aac_read_reply *readreply;
1475 struct scsi_cmnd *scsicmd;
1478 scsicmd = (struct scsi_cmnd *) context;
1480 if (!aac_valid_context(scsicmd, fibptr))
1484 cid = scmd_id(scsicmd);
1486 if (nblank(dprintk(x))) {
1488 switch (scsicmd->cmnd[0]) {
1491 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1492 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1496 lba = ((u64)scsicmd->cmnd[2] << 56) |
1497 ((u64)scsicmd->cmnd[3] << 48) |
1498 ((u64)scsicmd->cmnd[4] << 40) |
1499 ((u64)scsicmd->cmnd[5] << 32) |
1500 ((u64)scsicmd->cmnd[6] << 24) |
1501 (scsicmd->cmnd[7] << 16) |
1502 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1506 lba = ((u64)scsicmd->cmnd[2] << 24) |
1507 (scsicmd->cmnd[3] << 16) |
1508 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1511 lba = ((u64)scsicmd->cmnd[2] << 24) |
1512 (scsicmd->cmnd[3] << 16) |
1513 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1517 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1518 smp_processor_id(), (unsigned long long)lba, jiffies);
1521 BUG_ON(fibptr == NULL);
1523 scsi_dma_unmap(scsicmd);
1525 readreply = (struct aac_read_reply *)fib_data(fibptr);
1526 if (le32_to_cpu(readreply->status) == ST_OK)
1527 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1529 #ifdef AAC_DETAILED_STATUS_INFO
1530 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1531 le32_to_cpu(readreply->status));
1533 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1534 set_sense(&dev->fsa_dev[cid].sense_data,
1535 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1536 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1537 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1538 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1539 SCSI_SENSE_BUFFERSIZE));
1541 aac_fib_complete(fibptr);
1542 aac_fib_free(fibptr);
1544 scsicmd->scsi_done(scsicmd);
1547 static int aac_read(struct scsi_cmnd * scsicmd)
1552 struct aac_dev *dev;
1553 struct fib * cmd_fibcontext;
1555 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1557 * Get block address and transfer length
1559 switch (scsicmd->cmnd[0]) {
1561 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1563 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1564 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1565 count = scsicmd->cmnd[4];
1571 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1573 lba = ((u64)scsicmd->cmnd[2] << 56) |
1574 ((u64)scsicmd->cmnd[3] << 48) |
1575 ((u64)scsicmd->cmnd[4] << 40) |
1576 ((u64)scsicmd->cmnd[5] << 32) |
1577 ((u64)scsicmd->cmnd[6] << 24) |
1578 (scsicmd->cmnd[7] << 16) |
1579 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1580 count = (scsicmd->cmnd[10] << 24) |
1581 (scsicmd->cmnd[11] << 16) |
1582 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1585 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1587 lba = ((u64)scsicmd->cmnd[2] << 24) |
1588 (scsicmd->cmnd[3] << 16) |
1589 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1590 count = (scsicmd->cmnd[6] << 24) |
1591 (scsicmd->cmnd[7] << 16) |
1592 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1595 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1597 lba = ((u64)scsicmd->cmnd[2] << 24) |
1598 (scsicmd->cmnd[3] << 16) |
1599 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1600 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1603 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1604 smp_processor_id(), (unsigned long long)lba, jiffies));
1605 if (aac_adapter_bounds(dev,scsicmd,lba))
1608 * Alocate and initialize a Fib
1610 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1614 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1617 * Check that the command queued to the controller
1619 if (status == -EINPROGRESS) {
1620 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1624 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1626 * For some reason, the Fib didn't queue, return QUEUE_FULL
1628 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1629 scsicmd->scsi_done(scsicmd);
1630 aac_fib_complete(cmd_fibcontext);
1631 aac_fib_free(cmd_fibcontext);
1635 static int aac_write(struct scsi_cmnd * scsicmd)
1641 struct aac_dev *dev;
1642 struct fib * cmd_fibcontext;
1644 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1646 * Get block address and transfer length
1648 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1650 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1651 count = scsicmd->cmnd[4];
1655 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1656 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1658 lba = ((u64)scsicmd->cmnd[2] << 56) |
1659 ((u64)scsicmd->cmnd[3] << 48) |
1660 ((u64)scsicmd->cmnd[4] << 40) |
1661 ((u64)scsicmd->cmnd[5] << 32) |
1662 ((u64)scsicmd->cmnd[6] << 24) |
1663 (scsicmd->cmnd[7] << 16) |
1664 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1665 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1666 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1667 fua = scsicmd->cmnd[1] & 0x8;
1668 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1669 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1671 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1672 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1673 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1674 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1675 fua = scsicmd->cmnd[1] & 0x8;
1677 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1678 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1679 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1680 fua = scsicmd->cmnd[1] & 0x8;
1682 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1683 smp_processor_id(), (unsigned long long)lba, jiffies));
1684 if (aac_adapter_bounds(dev,scsicmd,lba))
1687 * Allocate and initialize a Fib then setup a BlockWrite command
1689 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1690 scsicmd->result = DID_ERROR << 16;
1691 scsicmd->scsi_done(scsicmd);
1695 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1698 * Check that the command queued to the controller
1700 if (status == -EINPROGRESS) {
1701 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1705 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1707 * For some reason, the Fib didn't queue, return QUEUE_FULL
1709 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1710 scsicmd->scsi_done(scsicmd);
1712 aac_fib_complete(cmd_fibcontext);
1713 aac_fib_free(cmd_fibcontext);
1717 static void synchronize_callback(void *context, struct fib *fibptr)
1719 struct aac_synchronize_reply *synchronizereply;
1720 struct scsi_cmnd *cmd;
1724 if (!aac_valid_context(cmd, fibptr))
1727 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1728 smp_processor_id(), jiffies));
1729 BUG_ON(fibptr == NULL);
1732 synchronizereply = fib_data(fibptr);
1733 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1734 cmd->result = DID_OK << 16 |
1735 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1737 struct scsi_device *sdev = cmd->device;
1738 struct aac_dev *dev = fibptr->dev;
1739 u32 cid = sdev_id(sdev);
1741 "synchronize_callback: synchronize failed, status = %d\n",
1742 le32_to_cpu(synchronizereply->status));
1743 cmd->result = DID_OK << 16 |
1744 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1745 set_sense(&dev->fsa_dev[cid].sense_data,
1746 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1747 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1748 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1749 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1750 SCSI_SENSE_BUFFERSIZE));
1753 aac_fib_complete(fibptr);
1754 aac_fib_free(fibptr);
1755 cmd->scsi_done(cmd);
1758 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1761 struct fib *cmd_fibcontext;
1762 struct aac_synchronize *synchronizecmd;
1763 struct scsi_cmnd *cmd;
1764 struct scsi_device *sdev = scsicmd->device;
1766 struct aac_dev *aac;
1767 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1768 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1769 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1770 unsigned long flags;
1773 * Wait for all outstanding queued commands to complete to this
1774 * specific target (block).
1776 spin_lock_irqsave(&sdev->list_lock, flags);
1777 list_for_each_entry(cmd, &sdev->cmd_list, list)
1778 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1782 if (cmd->cmnd[0] == WRITE_6) {
1783 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1784 (cmd->cmnd[2] << 8) |
1786 cmnd_count = cmd->cmnd[4];
1787 if (cmnd_count == 0)
1789 } else if (cmd->cmnd[0] == WRITE_16) {
1790 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1791 ((u64)cmd->cmnd[3] << 48) |
1792 ((u64)cmd->cmnd[4] << 40) |
1793 ((u64)cmd->cmnd[5] << 32) |
1794 ((u64)cmd->cmnd[6] << 24) |
1795 (cmd->cmnd[7] << 16) |
1796 (cmd->cmnd[8] << 8) |
1798 cmnd_count = (cmd->cmnd[10] << 24) |
1799 (cmd->cmnd[11] << 16) |
1800 (cmd->cmnd[12] << 8) |
1802 } else if (cmd->cmnd[0] == WRITE_12) {
1803 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1804 (cmd->cmnd[3] << 16) |
1805 (cmd->cmnd[4] << 8) |
1807 cmnd_count = (cmd->cmnd[6] << 24) |
1808 (cmd->cmnd[7] << 16) |
1809 (cmd->cmnd[8] << 8) |
1811 } else if (cmd->cmnd[0] == WRITE_10) {
1812 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1813 (cmd->cmnd[3] << 16) |
1814 (cmd->cmnd[4] << 8) |
1816 cmnd_count = (cmd->cmnd[7] << 8) |
1820 if (((cmnd_lba + cmnd_count) < lba) ||
1821 (count && ((lba + count) < cmnd_lba)))
1827 spin_unlock_irqrestore(&sdev->list_lock, flags);
1830 * Yield the processor (requeue for later)
1833 return SCSI_MLQUEUE_DEVICE_BUSY;
1835 aac = (struct aac_dev *)sdev->host->hostdata;
1837 return SCSI_MLQUEUE_HOST_BUSY;
1840 * Allocate and initialize a Fib
1842 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1843 return SCSI_MLQUEUE_HOST_BUSY;
1845 aac_fib_init(cmd_fibcontext);
1847 synchronizecmd = fib_data(cmd_fibcontext);
1848 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1849 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1850 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
1851 synchronizecmd->count =
1852 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1855 * Now send the Fib to the adapter
1857 status = aac_fib_send(ContainerCommand,
1859 sizeof(struct aac_synchronize),
1862 (fib_callback)synchronize_callback,
1866 * Check that the command queued to the controller
1868 if (status == -EINPROGRESS) {
1869 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1874 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1875 aac_fib_complete(cmd_fibcontext);
1876 aac_fib_free(cmd_fibcontext);
1877 return SCSI_MLQUEUE_HOST_BUSY;
1881 * aac_scsi_cmd() - Process SCSI command
1882 * @scsicmd: SCSI command block
1884 * Emulate a SCSI command and queue the required request for the
1888 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1891 struct Scsi_Host *host = scsicmd->device->host;
1892 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1893 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1895 if (fsa_dev_ptr == NULL)
1898 * If the bus, id or lun is out of range, return fail
1899 * Test does not apply to ID 16, the pseudo id for the controller
1902 cid = scmd_id(scsicmd);
1903 if (cid != host->this_id) {
1904 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
1905 if((cid >= dev->maximum_num_containers) ||
1906 (scsicmd->device->lun != 0)) {
1907 scsicmd->result = DID_NO_CONNECT << 16;
1908 scsicmd->scsi_done(scsicmd);
1913 * If the target container doesn't exist, it may have
1914 * been newly created
1916 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1917 switch (scsicmd->cmnd[0]) {
1918 case SERVICE_ACTION_IN:
1919 if (!(dev->raw_io_interface) ||
1920 !(dev->raw_io_64) ||
1921 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1925 case TEST_UNIT_READY:
1928 return _aac_probe_container(scsicmd,
1929 aac_probe_container_callback2);
1934 } else { /* check for physical non-dasd devices */
1935 if (dev->nondasd_support || expose_physicals ||
1939 return aac_send_srb_fib(scsicmd);
1941 scsicmd->result = DID_NO_CONNECT << 16;
1942 scsicmd->scsi_done(scsicmd);
1948 * else Command for the controller itself
1950 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1951 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1953 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1954 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1955 set_sense(&dev->fsa_dev[cid].sense_data,
1956 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1957 ASENCODE_INVALID_COMMAND, 0, 0);
1958 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1959 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1960 SCSI_SENSE_BUFFERSIZE));
1961 scsicmd->scsi_done(scsicmd);
1966 /* Handle commands here that don't really require going out to the adapter */
1967 switch (scsicmd->cmnd[0]) {
1970 struct inquiry_data inq_data;
1972 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
1973 memset(&inq_data, 0, sizeof (struct inquiry_data));
1975 if (scsicmd->cmnd[1] & 0x1) {
1976 char *arr = (char *)&inq_data;
1979 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
1980 INQD_PDT_PROC : INQD_PDT_DA;
1981 if (scsicmd->cmnd[2] == 0) {
1982 /* supported vital product data pages */
1986 arr[1] = scsicmd->cmnd[2];
1987 aac_internal_transfer(scsicmd, &inq_data, 0,
1989 scsicmd->result = DID_OK << 16 |
1990 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1991 } else if (scsicmd->cmnd[2] == 0x80) {
1992 /* unit serial number page */
1993 arr[3] = setinqserial(dev, &arr[4],
1995 arr[1] = scsicmd->cmnd[2];
1996 aac_internal_transfer(scsicmd, &inq_data, 0,
1998 return aac_get_container_serial(scsicmd);
2000 /* vpd page not implemented */
2001 scsicmd->result = DID_OK << 16 |
2002 COMMAND_COMPLETE << 8 |
2003 SAM_STAT_CHECK_CONDITION;
2004 set_sense(&dev->fsa_dev[cid].sense_data,
2005 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2006 ASENCODE_NO_SENSE, 7, 2);
2007 memcpy(scsicmd->sense_buffer,
2008 &dev->fsa_dev[cid].sense_data,
2010 sizeof(dev->fsa_dev[cid].sense_data),
2011 SCSI_SENSE_BUFFERSIZE));
2013 scsicmd->scsi_done(scsicmd);
2016 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
2017 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 */
2018 inq_data.inqd_len = 31;
2019 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2020 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
2022 * Set the Vendor, Product, and Revision Level
2023 * see: <vendor>.c i.e. aac.c
2025 if (cid == host->this_id) {
2026 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
2027 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2028 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
2029 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2030 scsicmd->scsi_done(scsicmd);
2035 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2036 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2037 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
2038 return aac_get_container_name(scsicmd);
2040 case SERVICE_ACTION_IN:
2041 if (!(dev->raw_io_interface) ||
2042 !(dev->raw_io_64) ||
2043 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2049 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2050 capacity = fsa_dev_ptr[cid].size - 1;
2051 cp[0] = (capacity >> 56) & 0xff;
2052 cp[1] = (capacity >> 48) & 0xff;
2053 cp[2] = (capacity >> 40) & 0xff;
2054 cp[3] = (capacity >> 32) & 0xff;
2055 cp[4] = (capacity >> 24) & 0xff;
2056 cp[5] = (capacity >> 16) & 0xff;
2057 cp[6] = (capacity >> 8) & 0xff;
2058 cp[7] = (capacity >> 0) & 0xff;
2064 aac_internal_transfer(scsicmd, cp, 0,
2065 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
2066 if (sizeof(cp) < scsicmd->cmnd[13]) {
2067 unsigned int len, offset = sizeof(cp);
2069 memset(cp, 0, offset);
2071 len = min_t(size_t, scsicmd->cmnd[13] - offset,
2073 aac_internal_transfer(scsicmd, cp, offset, len);
2074 } while ((offset += len) < scsicmd->cmnd[13]);
2077 /* Do not cache partition table for arrays */
2078 scsicmd->device->removable = 1;
2080 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2081 scsicmd->scsi_done(scsicmd);
2091 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
2092 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2093 capacity = fsa_dev_ptr[cid].size - 1;
2097 cp[0] = (capacity >> 24) & 0xff;
2098 cp[1] = (capacity >> 16) & 0xff;
2099 cp[2] = (capacity >> 8) & 0xff;
2100 cp[3] = (capacity >> 0) & 0xff;
2105 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
2106 /* Do not cache partition table for arrays */
2107 scsicmd->device->removable = 1;
2109 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2110 scsicmd->scsi_done(scsicmd);
2118 int mode_buf_length = 4;
2120 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
2121 mode_buf[0] = 3; /* Mode data length */
2122 mode_buf[1] = 0; /* Medium type - default */
2123 mode_buf[2] = 0; /* Device-specific param,
2124 bit 8: 0/1 = write enabled/protected
2125 bit 4: 0/1 = FUA enabled */
2126 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2128 mode_buf[3] = 0; /* Block descriptor length */
2129 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2130 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2134 mode_buf[6] = ((aac_cache & 6) == 2)
2135 ? 0 : 0x04; /* WCE */
2136 mode_buf_length = 7;
2137 if (mode_buf_length > scsicmd->cmnd[4])
2138 mode_buf_length = scsicmd->cmnd[4];
2140 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
2141 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2142 scsicmd->scsi_done(scsicmd);
2149 int mode_buf_length = 8;
2151 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
2152 mode_buf[0] = 0; /* Mode data length (MSB) */
2153 mode_buf[1] = 6; /* Mode data length (LSB) */
2154 mode_buf[2] = 0; /* Medium type - default */
2155 mode_buf[3] = 0; /* Device-specific param,
2156 bit 8: 0/1 = write enabled/protected
2157 bit 4: 0/1 = FUA enabled */
2158 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2160 mode_buf[4] = 0; /* reserved */
2161 mode_buf[5] = 0; /* reserved */
2162 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2163 mode_buf[7] = 0; /* Block descriptor length (LSB) */
2164 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2165 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2169 mode_buf[10] = ((aac_cache & 6) == 2)
2170 ? 0 : 0x04; /* WCE */
2171 mode_buf_length = 11;
2172 if (mode_buf_length > scsicmd->cmnd[8])
2173 mode_buf_length = scsicmd->cmnd[8];
2175 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
2177 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2178 scsicmd->scsi_done(scsicmd);
2183 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2184 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2185 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2186 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2187 scsicmd->scsi_done(scsicmd);
2190 case ALLOW_MEDIUM_REMOVAL:
2191 dprintk((KERN_DEBUG "LOCK command.\n"));
2192 if (scsicmd->cmnd[4])
2193 fsa_dev_ptr[cid].locked = 1;
2195 fsa_dev_ptr[cid].locked = 0;
2197 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2198 scsicmd->scsi_done(scsicmd);
2201 * These commands are all No-Ops
2203 case TEST_UNIT_READY:
2207 case REASSIGN_BLOCKS:
2210 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2211 scsicmd->scsi_done(scsicmd);
2215 switch (scsicmd->cmnd[0])
2224 * Hack to keep track of ordinal number of the device that
2225 * corresponds to a container. Needed to convert
2226 * containers to /dev/sd device names
2229 if (scsicmd->request->rq_disk)
2230 strlcpy(fsa_dev_ptr[cid].devname,
2231 scsicmd->request->rq_disk->disk_name,
2232 min(sizeof(fsa_dev_ptr[cid].devname),
2233 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2235 return aac_read(scsicmd);
2243 return aac_write(scsicmd);
2245 case SYNCHRONIZE_CACHE:
2246 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2247 scsicmd->result = DID_OK << 16 |
2248 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2249 scsicmd->scsi_done(scsicmd);
2252 /* Issue FIB to tell Firmware to flush it's cache */
2253 if ((aac_cache & 6) != 2)
2254 return aac_synchronize(scsicmd);
2258 * Unhandled commands
2260 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2261 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2262 set_sense(&dev->fsa_dev[cid].sense_data,
2263 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2264 ASENCODE_INVALID_COMMAND, 0, 0);
2265 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2267 sizeof(dev->fsa_dev[cid].sense_data),
2268 SCSI_SENSE_BUFFERSIZE));
2269 scsicmd->scsi_done(scsicmd);
2274 static int query_disk(struct aac_dev *dev, void __user *arg)
2276 struct aac_query_disk qd;
2277 struct fsa_dev_info *fsa_dev_ptr;
2279 fsa_dev_ptr = dev->fsa_dev;
2282 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2286 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2288 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2290 qd.instance = dev->scsi_host_ptr->host_no;
2292 qd.id = CONTAINER_TO_ID(qd.cnum);
2293 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2295 else return -EINVAL;
2297 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
2298 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2299 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2301 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2306 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2307 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2309 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2314 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2316 struct aac_delete_disk dd;
2317 struct fsa_dev_info *fsa_dev_ptr;
2319 fsa_dev_ptr = dev->fsa_dev;
2323 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2326 if (dd.cnum >= dev->maximum_num_containers)
2329 * Mark this container as being deleted.
2331 fsa_dev_ptr[dd.cnum].deleted = 1;
2333 * Mark the container as no longer valid
2335 fsa_dev_ptr[dd.cnum].valid = 0;
2339 static int delete_disk(struct aac_dev *dev, void __user *arg)
2341 struct aac_delete_disk dd;
2342 struct fsa_dev_info *fsa_dev_ptr;
2344 fsa_dev_ptr = dev->fsa_dev;
2348 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2351 if (dd.cnum >= dev->maximum_num_containers)
2354 * If the container is locked, it can not be deleted by the API.
2356 if (fsa_dev_ptr[dd.cnum].locked)
2360 * Mark the container as no longer being valid.
2362 fsa_dev_ptr[dd.cnum].valid = 0;
2363 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2368 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2371 case FSACTL_QUERY_DISK:
2372 return query_disk(dev, arg);
2373 case FSACTL_DELETE_DISK:
2374 return delete_disk(dev, arg);
2375 case FSACTL_FORCE_DELETE_DISK:
2376 return force_delete_disk(dev, arg);
2377 case FSACTL_GET_CONTAINERS:
2378 return aac_get_containers(dev);
2387 * @context: the context set in the fib - here it is scsi cmd
2388 * @fibptr: pointer to the fib
2390 * Handles the completion of a scsi command to a non dasd device
2394 static void aac_srb_callback(void *context, struct fib * fibptr)
2396 struct aac_dev *dev;
2397 struct aac_srb_reply *srbreply;
2398 struct scsi_cmnd *scsicmd;
2400 scsicmd = (struct scsi_cmnd *) context;
2402 if (!aac_valid_context(scsicmd, fibptr))
2405 BUG_ON(fibptr == NULL);
2409 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2411 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2413 * Calculate resid for sg
2416 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2417 - le32_to_cpu(srbreply->data_xfer_length));
2419 scsi_dma_unmap(scsicmd);
2422 * First check the fib status
2425 if (le32_to_cpu(srbreply->status) != ST_OK){
2427 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2428 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2429 SCSI_SENSE_BUFFERSIZE);
2430 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2431 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2435 * Next check the srb status
2437 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2438 case SRB_STATUS_ERROR_RECOVERY:
2439 case SRB_STATUS_PENDING:
2440 case SRB_STATUS_SUCCESS:
2441 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2443 case SRB_STATUS_DATA_OVERRUN:
2444 switch(scsicmd->cmnd[0]){
2453 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
2454 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2456 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2458 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2461 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2465 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2469 case SRB_STATUS_ABORTED:
2470 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2472 case SRB_STATUS_ABORT_FAILED:
2473 // Not sure about this one - but assuming the hba was trying to abort for some reason
2474 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2476 case SRB_STATUS_PARITY_ERROR:
2477 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2479 case SRB_STATUS_NO_DEVICE:
2480 case SRB_STATUS_INVALID_PATH_ID:
2481 case SRB_STATUS_INVALID_TARGET_ID:
2482 case SRB_STATUS_INVALID_LUN:
2483 case SRB_STATUS_SELECTION_TIMEOUT:
2484 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2487 case SRB_STATUS_COMMAND_TIMEOUT:
2488 case SRB_STATUS_TIMEOUT:
2489 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2492 case SRB_STATUS_BUSY:
2493 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
2496 case SRB_STATUS_BUS_RESET:
2497 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2500 case SRB_STATUS_MESSAGE_REJECTED:
2501 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2503 case SRB_STATUS_REQUEST_FLUSHED:
2504 case SRB_STATUS_ERROR:
2505 case SRB_STATUS_INVALID_REQUEST:
2506 case SRB_STATUS_REQUEST_SENSE_FAILED:
2507 case SRB_STATUS_NO_HBA:
2508 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2509 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2510 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2511 case SRB_STATUS_DELAYED_RETRY:
2512 case SRB_STATUS_BAD_FUNCTION:
2513 case SRB_STATUS_NOT_STARTED:
2514 case SRB_STATUS_NOT_IN_USE:
2515 case SRB_STATUS_FORCE_ABORT:
2516 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2518 #ifdef AAC_DETAILED_STATUS_INFO
2519 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2520 le32_to_cpu(srbreply->srb_status) & 0x3F,
2521 aac_get_status_string(
2522 le32_to_cpu(srbreply->srb_status) & 0x3F),
2524 le32_to_cpu(srbreply->scsi_status));
2526 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2529 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
2531 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2532 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2533 SCSI_SENSE_BUFFERSIZE);
2534 #ifdef AAC_DETAILED_STATUS_INFO
2535 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2536 le32_to_cpu(srbreply->status), len);
2538 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2541 * OR in the scsi status (already shifted up a bit)
2543 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2545 aac_fib_complete(fibptr);
2546 aac_fib_free(fibptr);
2547 scsicmd->scsi_done(scsicmd);
2553 * @scsicmd: the scsi command block
2555 * This routine will form a FIB and fill in the aac_srb from the
2556 * scsicmd passed in.
2559 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2561 struct fib* cmd_fibcontext;
2562 struct aac_dev* dev;
2565 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2566 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2567 scsicmd->device->lun > 7) {
2568 scsicmd->result = DID_NO_CONNECT << 16;
2569 scsicmd->scsi_done(scsicmd);
2574 * Allocate and initialize a Fib then setup a BlockWrite command
2576 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2579 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2582 * Check that the command queued to the controller
2584 if (status == -EINPROGRESS) {
2585 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2589 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2590 aac_fib_complete(cmd_fibcontext);
2591 aac_fib_free(cmd_fibcontext);
2596 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2598 struct aac_dev *dev;
2599 unsigned long byte_count = 0;
2602 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2603 // Get rid of old data
2605 psg->sg[0].addr = 0;
2606 psg->sg[0].count = 0;
2608 nseg = scsi_dma_map(scsicmd);
2611 struct scatterlist *sg;
2614 psg->count = cpu_to_le32(nseg);
2616 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2617 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2618 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2619 byte_count += sg_dma_len(sg);
2621 /* hba wants the size to be exact */
2622 if (byte_count > scsi_bufflen(scsicmd)) {
2623 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2624 (byte_count - scsi_bufflen(scsicmd));
2625 psg->sg[i-1].count = cpu_to_le32(temp);
2626 byte_count = scsi_bufflen(scsicmd);
2628 /* Check for command underflow */
2629 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2630 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2631 byte_count, scsicmd->underflow);
2638 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2640 struct aac_dev *dev;
2641 unsigned long byte_count = 0;
2645 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2646 // Get rid of old data
2648 psg->sg[0].addr[0] = 0;
2649 psg->sg[0].addr[1] = 0;
2650 psg->sg[0].count = 0;
2652 nseg = scsi_dma_map(scsicmd);
2655 struct scatterlist *sg;
2658 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2659 int count = sg_dma_len(sg);
2660 addr = sg_dma_address(sg);
2661 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2662 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2663 psg->sg[i].count = cpu_to_le32(count);
2664 byte_count += count;
2666 psg->count = cpu_to_le32(nseg);
2667 /* hba wants the size to be exact */
2668 if (byte_count > scsi_bufflen(scsicmd)) {
2669 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2670 (byte_count - scsi_bufflen(scsicmd));
2671 psg->sg[i-1].count = cpu_to_le32(temp);
2672 byte_count = scsi_bufflen(scsicmd);
2674 /* Check for command underflow */
2675 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2676 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2677 byte_count, scsicmd->underflow);
2683 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2685 unsigned long byte_count = 0;
2688 // Get rid of old data
2690 psg->sg[0].next = 0;
2691 psg->sg[0].prev = 0;
2692 psg->sg[0].addr[0] = 0;
2693 psg->sg[0].addr[1] = 0;
2694 psg->sg[0].count = 0;
2695 psg->sg[0].flags = 0;
2697 nseg = scsi_dma_map(scsicmd);
2700 struct scatterlist *sg;
2703 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2704 int count = sg_dma_len(sg);
2705 u64 addr = sg_dma_address(sg);
2706 psg->sg[i].next = 0;
2707 psg->sg[i].prev = 0;
2708 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2709 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2710 psg->sg[i].count = cpu_to_le32(count);
2711 psg->sg[i].flags = 0;
2712 byte_count += count;
2714 psg->count = cpu_to_le32(nseg);
2715 /* hba wants the size to be exact */
2716 if (byte_count > scsi_bufflen(scsicmd)) {
2717 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2718 (byte_count - scsi_bufflen(scsicmd));
2719 psg->sg[i-1].count = cpu_to_le32(temp);
2720 byte_count = scsi_bufflen(scsicmd);
2722 /* Check for command underflow */
2723 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2724 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2725 byte_count, scsicmd->underflow);
2731 #ifdef AAC_DETAILED_STATUS_INFO
2733 struct aac_srb_status_info {
2739 static struct aac_srb_status_info srb_status_info[] = {
2740 { SRB_STATUS_PENDING, "Pending Status"},
2741 { SRB_STATUS_SUCCESS, "Success"},
2742 { SRB_STATUS_ABORTED, "Aborted Command"},
2743 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2744 { SRB_STATUS_ERROR, "Error Event"},
2745 { SRB_STATUS_BUSY, "Device Busy"},
2746 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2747 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2748 { SRB_STATUS_NO_DEVICE, "No Device"},
2749 { SRB_STATUS_TIMEOUT, "Timeout"},
2750 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2751 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2752 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2753 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2754 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2755 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2756 { SRB_STATUS_NO_HBA, "No HBA"},
2757 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2758 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2759 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2760 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2761 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2762 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2763 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2764 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2765 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2766 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2767 { SRB_STATUS_NOT_STARTED, "Not Started"},
2768 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2769 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2770 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2771 { 0xff, "Unknown Error"}
2774 char *aac_get_status_string(u32 status)
2778 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2779 if (srb_status_info[i].status == status)
2780 return srb_status_info[i].str;
2782 return "Bad Status Code";