2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/slab.h>
32 #include <linux/completion.h>
33 #include <linux/blkdev.h>
34 #include <linux/dma-mapping.h>
35 #include <asm/semaphore.h>
36 #include <asm/uaccess.h>
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_cmnd.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_host.h>
45 /* values for inqd_pdt: Peripheral device type in plain English */
46 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
47 #define INQD_PDT_PROC 0x03 /* Processor device */
48 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
49 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
50 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
51 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
53 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
54 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
60 #define SENCODE_NO_SENSE 0x00
61 #define SENCODE_END_OF_DATA 0x00
62 #define SENCODE_BECOMING_READY 0x04
63 #define SENCODE_INIT_CMD_REQUIRED 0x04
64 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65 #define SENCODE_INVALID_COMMAND 0x20
66 #define SENCODE_LBA_OUT_OF_RANGE 0x21
67 #define SENCODE_INVALID_CDB_FIELD 0x24
68 #define SENCODE_LUN_NOT_SUPPORTED 0x25
69 #define SENCODE_INVALID_PARAM_FIELD 0x26
70 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
71 #define SENCODE_PARAM_VALUE_INVALID 0x26
72 #define SENCODE_RESET_OCCURRED 0x29
73 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
77 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
79 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80 #define SENCODE_OVERLAPPED_COMMAND 0x4E
83 * Additional sense codes
86 #define ASENCODE_NO_SENSE 0x00
87 #define ASENCODE_END_OF_DATA 0x05
88 #define ASENCODE_BECOMING_READY 0x01
89 #define ASENCODE_INIT_CMD_REQUIRED 0x02
90 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91 #define ASENCODE_INVALID_COMMAND 0x00
92 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
93 #define ASENCODE_INVALID_CDB_FIELD 0x00
94 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
95 #define ASENCODE_INVALID_PARAM_FIELD 0x00
96 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97 #define ASENCODE_PARAM_VALUE_INVALID 0x02
98 #define ASENCODE_RESET_OCCURRED 0x00
99 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106 #define ASENCODE_OVERLAPPED_COMMAND 0x00
108 #define BYTE0(x) (unsigned char)(x)
109 #define BYTE1(x) (unsigned char)((x) >> 8)
110 #define BYTE2(x) (unsigned char)((x) >> 16)
111 #define BYTE3(x) (unsigned char)((x) >> 24)
113 /*------------------------------------------------------------------------------
114 * S T R U C T S / T Y P E D E F S
115 *----------------------------------------------------------------------------*/
116 /* SCSI inquiry data */
117 struct inquiry_data {
118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq; /* RMB | Device Type Qualifier */
120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len; /* Additional length (n-4) */
123 u8 inqd_pad1[2];/* Reserved - must be zero */
124 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
125 u8 inqd_vid[8]; /* Vendor ID */
126 u8 inqd_pid[16];/* Product ID */
127 u8 inqd_prl[4]; /* Product Revision Level */
131 * M O D U L E G L O B A L S
134 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
136 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
137 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
138 #ifdef AAC_DETAILED_STATUS_INFO
139 static char *aac_get_status_string(u32 status);
143 * Non dasd selection is handled entirely in aachba now
146 static int nondasd = -1;
147 static int 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 kunmap_atomic(buf - sg->offset, KM_IRQ0);
373 static void get_container_name_callback(void *context, struct fib * fibptr)
375 struct aac_get_name_resp * get_name_reply;
376 struct scsi_cmnd * scsicmd;
378 scsicmd = (struct scsi_cmnd *) context;
380 if (!aac_valid_context(scsicmd, fibptr))
383 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
384 BUG_ON(fibptr == NULL);
386 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
387 /* Failure is irrelevant, using default value instead */
388 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
389 && (get_name_reply->data[0] != '\0')) {
390 char *sp = get_name_reply->data;
391 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
395 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
396 int count = sizeof(d);
399 *dp++ = (*sp) ? *sp++ : ' ';
400 } while (--count > 0);
401 aac_internal_transfer(scsicmd, d,
402 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
406 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
408 aac_fib_complete(fibptr);
409 aac_fib_free(fibptr);
410 scsicmd->scsi_done(scsicmd);
414 * aac_get_container_name - get container name, none blocking.
416 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
419 struct aac_get_name *dinfo;
420 struct fib * cmd_fibcontext;
421 struct aac_dev * dev;
423 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
425 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
428 aac_fib_init(cmd_fibcontext);
429 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
431 dinfo->command = cpu_to_le32(VM_ContainerConfig);
432 dinfo->type = cpu_to_le32(CT_READ_NAME);
433 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
434 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
436 status = aac_fib_send(ContainerCommand,
438 sizeof (struct aac_get_name),
441 (fib_callback) get_container_name_callback,
445 * Check that the command queued to the controller
447 if (status == -EINPROGRESS) {
448 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
452 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
453 aac_fib_complete(cmd_fibcontext);
454 aac_fib_free(cmd_fibcontext);
458 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
460 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
462 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
463 return aac_scsi_cmd(scsicmd);
465 scsicmd->result = DID_NO_CONNECT << 16;
466 scsicmd->scsi_done(scsicmd);
470 static void _aac_probe_container2(void * context, struct fib * fibptr)
472 struct fsa_dev_info *fsa_dev_ptr;
473 int (*callback)(struct scsi_cmnd *);
474 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
477 if (!aac_valid_context(scsicmd, fibptr))
480 scsicmd->SCp.Status = 0;
481 fsa_dev_ptr = fibptr->dev->fsa_dev;
483 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
484 fsa_dev_ptr += scmd_id(scsicmd);
486 if ((le32_to_cpu(dresp->status) == ST_OK) &&
487 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
488 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
489 fsa_dev_ptr->valid = 1;
490 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
492 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
493 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
494 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
496 if ((fsa_dev_ptr->valid & 1) == 0)
497 fsa_dev_ptr->valid = 0;
498 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
500 aac_fib_complete(fibptr);
501 aac_fib_free(fibptr);
502 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
503 scsicmd->SCp.ptr = NULL;
504 (*callback)(scsicmd);
508 static void _aac_probe_container1(void * context, struct fib * fibptr)
510 struct scsi_cmnd * scsicmd;
511 struct aac_mount * dresp;
512 struct aac_query_mount *dinfo;
515 dresp = (struct aac_mount *) fib_data(fibptr);
516 dresp->mnt[0].capacityhigh = 0;
517 if ((le32_to_cpu(dresp->status) != ST_OK) ||
518 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
519 _aac_probe_container2(context, fibptr);
522 scsicmd = (struct scsi_cmnd *) context;
524 if (!aac_valid_context(scsicmd, fibptr))
527 aac_fib_init(fibptr);
529 dinfo = (struct aac_query_mount *)fib_data(fibptr);
531 dinfo->command = cpu_to_le32(VM_NameServe64);
532 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
533 dinfo->type = cpu_to_le32(FT_FILESYS);
535 status = aac_fib_send(ContainerCommand,
537 sizeof(struct aac_query_mount),
540 _aac_probe_container2,
543 * Check that the command queued to the controller
545 if (status == -EINPROGRESS)
546 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
547 else if (status < 0) {
548 /* Inherit results from VM_NameServe, if any */
549 dresp->status = cpu_to_le32(ST_OK);
550 _aac_probe_container2(context, fibptr);
554 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
557 int status = -ENOMEM;
559 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
560 struct aac_query_mount *dinfo;
562 aac_fib_init(fibptr);
564 dinfo = (struct aac_query_mount *)fib_data(fibptr);
566 dinfo->command = cpu_to_le32(VM_NameServe);
567 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
568 dinfo->type = cpu_to_le32(FT_FILESYS);
569 scsicmd->SCp.ptr = (char *)callback;
571 status = aac_fib_send(ContainerCommand,
573 sizeof(struct aac_query_mount),
576 _aac_probe_container1,
579 * Check that the command queued to the controller
581 if (status == -EINPROGRESS) {
582 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
586 scsicmd->SCp.ptr = NULL;
587 aac_fib_complete(fibptr);
588 aac_fib_free(fibptr);
592 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
594 fsa_dev_ptr += scmd_id(scsicmd);
595 if ((fsa_dev_ptr->valid & 1) == 0) {
596 fsa_dev_ptr->valid = 0;
597 return (*callback)(scsicmd);
605 * aac_probe_container - query a logical volume
606 * @dev: device to query
607 * @cid: container identifier
609 * Queries the controller about the given volume. The volume information
610 * is updated in the struct fsa_dev_info structure rather than returned.
612 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
614 scsicmd->device = NULL;
618 int aac_probe_container(struct aac_dev *dev, int cid)
620 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
621 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
624 if (!scsicmd || !scsidev) {
629 scsicmd->list.next = NULL;
630 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
632 scsicmd->device = scsidev;
633 scsidev->sdev_state = 0;
635 scsidev->host = dev->scsi_host_ptr;
637 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
638 while (scsicmd->device == scsidev)
641 status = scsicmd->SCp.Status;
646 /* Local Structure to set SCSI inquiry data strings */
648 char vid[8]; /* Vendor ID */
649 char pid[16]; /* Product ID */
650 char prl[4]; /* Product Revision Level */
654 * InqStrCopy - string merge
655 * @a: string to copy from
656 * @b: string to copy to
658 * Copy a String from one location to another
662 static void inqstrcpy(char *a, char *b)
669 static char *container_types[] = {
693 char * get_container_type(unsigned tindex)
695 if (tindex >= ARRAY_SIZE(container_types))
696 tindex = ARRAY_SIZE(container_types) - 1;
697 return container_types[tindex];
700 /* Function: setinqstr
702 * Arguments: [1] pointer to void [1] int
704 * Purpose: Sets SCSI inquiry data strings for vendor, product
705 * and revision level. Allows strings to be set in platform dependant
706 * files instead of in OS dependant driver source.
709 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
711 struct scsi_inq *str;
713 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
714 memset(str, ' ', sizeof(*str));
716 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
717 char * cp = dev->supplement_adapter_info.AdapterTypeText;
718 int c = sizeof(str->vid);
719 while (*cp && *cp != ' ' && --c)
723 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
726 while (*cp && *cp != ' ')
730 /* last six chars reserved for vol type */
732 if (strlen(cp) > sizeof(str->pid)) {
733 c = cp[sizeof(str->pid)];
734 cp[sizeof(str->pid)] = '\0';
736 inqstrcpy (cp, str->pid);
738 cp[sizeof(str->pid)] = c;
740 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
742 inqstrcpy (mp->vname, str->vid);
743 /* last six chars reserved for vol type */
744 inqstrcpy (mp->model, str->pid);
747 if (tindex < ARRAY_SIZE(container_types)){
748 char *findit = str->pid;
750 for ( ; *findit != ' '; findit++); /* walk till we find a space */
751 /* RAID is superfluous in the context of a RAID device */
752 if (memcmp(findit-4, "RAID", 4) == 0)
753 *(findit -= 4) = ' ';
754 if (((findit - str->pid) + strlen(container_types[tindex]))
755 < (sizeof(str->pid) + sizeof(str->prl)))
756 inqstrcpy (container_types[tindex], findit + 1);
758 inqstrcpy ("V1.0", str->prl);
761 static void get_container_serial_callback(void *context, struct fib * fibptr)
763 struct aac_get_serial_resp * get_serial_reply;
764 struct scsi_cmnd * scsicmd;
766 BUG_ON(fibptr == NULL);
768 scsicmd = (struct scsi_cmnd *) context;
769 if (!aac_valid_context(scsicmd, fibptr))
772 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
773 /* Failure is irrelevant, using default value instead */
774 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
778 sp[1] = scsicmd->cmnd[2];
780 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
781 le32_to_cpu(get_serial_reply->uid));
782 aac_internal_transfer(scsicmd, sp, 0, sizeof(sp));
785 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
787 aac_fib_complete(fibptr);
788 aac_fib_free(fibptr);
789 scsicmd->scsi_done(scsicmd);
793 * aac_get_container_serial - get container serial, none blocking.
795 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
798 struct aac_get_serial *dinfo;
799 struct fib * cmd_fibcontext;
800 struct aac_dev * dev;
802 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
804 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
807 aac_fib_init(cmd_fibcontext);
808 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
810 dinfo->command = cpu_to_le32(VM_ContainerConfig);
811 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
812 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
814 status = aac_fib_send(ContainerCommand,
816 sizeof (struct aac_get_serial),
819 (fib_callback) get_container_serial_callback,
823 * Check that the command queued to the controller
825 if (status == -EINPROGRESS) {
826 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
830 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
831 aac_fib_complete(cmd_fibcontext);
832 aac_fib_free(cmd_fibcontext);
836 /* Function: setinqserial
838 * Arguments: [1] pointer to void [1] int
840 * Purpose: Sets SCSI Unit Serial number.
841 * This is a fake. We should read a proper
842 * serial number from the container. <SuSE>But
843 * without docs it's quite hard to do it :-)
844 * So this will have to do in the meantime.</SuSE>
847 static int setinqserial(struct aac_dev *dev, void *data, int cid)
850 * This breaks array migration.
852 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
853 le32_to_cpu(dev->adapter_info.serial[0]), cid);
856 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
857 u8 a_sense_code, u8 incorrect_length,
858 u8 bit_pointer, u16 field_pointer,
861 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
862 sense_buf[1] = 0; /* Segment number, always zero */
864 if (incorrect_length) {
865 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
866 sense_buf[3] = BYTE3(residue);
867 sense_buf[4] = BYTE2(residue);
868 sense_buf[5] = BYTE1(residue);
869 sense_buf[6] = BYTE0(residue);
871 sense_buf[2] = sense_key; /* Sense key */
873 if (sense_key == ILLEGAL_REQUEST)
874 sense_buf[7] = 10; /* Additional sense length */
876 sense_buf[7] = 6; /* Additional sense length */
878 sense_buf[12] = sense_code; /* Additional sense code */
879 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
880 if (sense_key == ILLEGAL_REQUEST) {
883 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
884 sense_buf[15] = 0x80;/* Std sense key specific field */
885 /* Illegal parameter is in the parameter block */
887 if (sense_code == SENCODE_INVALID_CDB_FIELD)
888 sense_buf[15] = 0xc0;/* Std sense key specific field */
889 /* Illegal parameter is in the CDB block */
890 sense_buf[15] |= bit_pointer;
891 sense_buf[16] = field_pointer >> 8; /* MSB */
892 sense_buf[17] = field_pointer; /* LSB */
896 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
898 if (lba & 0xffffffff00000000LL) {
899 int cid = scmd_id(cmd);
900 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
901 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
902 SAM_STAT_CHECK_CONDITION;
903 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
905 SENCODE_INTERNAL_TARGET_FAILURE,
906 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
908 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
909 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
910 ? sizeof(cmd->sense_buffer)
911 : sizeof(dev->fsa_dev[cid].sense_data));
918 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
923 static void io_callback(void *context, struct fib * fibptr);
925 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
928 struct aac_raw_io *readcmd;
930 readcmd = (struct aac_raw_io *) fib_data(fib);
931 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
932 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
933 readcmd->count = cpu_to_le32(count<<9);
934 readcmd->cid = cpu_to_le16(scmd_id(cmd));
935 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
936 readcmd->bpTotal = 0;
937 readcmd->bpComplete = 0;
939 aac_build_sgraw(cmd, &readcmd->sg);
940 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
941 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
943 * Now send the Fib to the adapter
945 return aac_fib_send(ContainerRawIo,
950 (fib_callback) io_callback,
954 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
957 struct aac_read64 *readcmd;
959 readcmd = (struct aac_read64 *) fib_data(fib);
960 readcmd->command = cpu_to_le32(VM_CtHostRead64);
961 readcmd->cid = cpu_to_le16(scmd_id(cmd));
962 readcmd->sector_count = cpu_to_le16(count);
963 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
967 aac_build_sg64(cmd, &readcmd->sg);
968 fibsize = sizeof(struct aac_read64) +
969 ((le32_to_cpu(readcmd->sg.count) - 1) *
970 sizeof (struct sgentry64));
971 BUG_ON (fibsize > (fib->dev->max_fib_size -
972 sizeof(struct aac_fibhdr)));
974 * Now send the Fib to the adapter
976 return aac_fib_send(ContainerCommand64,
981 (fib_callback) io_callback,
985 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
988 struct aac_read *readcmd;
990 readcmd = (struct aac_read *) fib_data(fib);
991 readcmd->command = cpu_to_le32(VM_CtBlockRead);
992 readcmd->cid = cpu_to_le32(scmd_id(cmd));
993 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
994 readcmd->count = cpu_to_le32(count * 512);
996 aac_build_sg(cmd, &readcmd->sg);
997 fibsize = sizeof(struct aac_read) +
998 ((le32_to_cpu(readcmd->sg.count) - 1) *
999 sizeof (struct sgentry));
1000 BUG_ON (fibsize > (fib->dev->max_fib_size -
1001 sizeof(struct aac_fibhdr)));
1003 * Now send the Fib to the adapter
1005 return aac_fib_send(ContainerCommand,
1010 (fib_callback) io_callback,
1014 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1017 struct aac_raw_io *writecmd;
1019 writecmd = (struct aac_raw_io *) fib_data(fib);
1020 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1021 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1022 writecmd->count = cpu_to_le32(count<<9);
1023 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1024 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1025 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1026 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
1027 cpu_to_le16(IO_TYPE_WRITE);
1028 writecmd->bpTotal = 0;
1029 writecmd->bpComplete = 0;
1031 aac_build_sgraw(cmd, &writecmd->sg);
1032 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1033 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1035 * Now send the Fib to the adapter
1037 return aac_fib_send(ContainerRawIo,
1042 (fib_callback) io_callback,
1046 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1049 struct aac_write64 *writecmd;
1051 writecmd = (struct aac_write64 *) fib_data(fib);
1052 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1053 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1054 writecmd->sector_count = cpu_to_le16(count);
1055 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1057 writecmd->flags = 0;
1059 aac_build_sg64(cmd, &writecmd->sg);
1060 fibsize = sizeof(struct aac_write64) +
1061 ((le32_to_cpu(writecmd->sg.count) - 1) *
1062 sizeof (struct sgentry64));
1063 BUG_ON (fibsize > (fib->dev->max_fib_size -
1064 sizeof(struct aac_fibhdr)));
1066 * Now send the Fib to the adapter
1068 return aac_fib_send(ContainerCommand64,
1073 (fib_callback) io_callback,
1077 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1080 struct aac_write *writecmd;
1082 writecmd = (struct aac_write *) fib_data(fib);
1083 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1084 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1085 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1086 writecmd->count = cpu_to_le32(count * 512);
1087 writecmd->sg.count = cpu_to_le32(1);
1088 /* ->stable is not used - it did mean which type of write */
1090 aac_build_sg(cmd, &writecmd->sg);
1091 fibsize = sizeof(struct aac_write) +
1092 ((le32_to_cpu(writecmd->sg.count) - 1) *
1093 sizeof (struct sgentry));
1094 BUG_ON (fibsize > (fib->dev->max_fib_size -
1095 sizeof(struct aac_fibhdr)));
1097 * Now send the Fib to the adapter
1099 return aac_fib_send(ContainerCommand,
1104 (fib_callback) io_callback,
1108 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1110 struct aac_srb * srbcmd;
1115 switch(cmd->sc_data_direction){
1119 case DMA_BIDIRECTIONAL:
1120 flag = SRB_DataIn | SRB_DataOut;
1122 case DMA_FROM_DEVICE:
1126 default: /* shuts up some versions of gcc */
1127 flag = SRB_NoDataXfer;
1131 srbcmd = (struct aac_srb*) fib_data(fib);
1132 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1133 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1134 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1135 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1136 srbcmd->flags = cpu_to_le32(flag);
1137 timeout = cmd->timeout_per_command/HZ;
1140 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1141 srbcmd->retry_limit = 0; /* Obsolete parameter */
1142 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1146 static void aac_srb_callback(void *context, struct fib * fibptr);
1148 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1151 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1153 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1154 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1156 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1157 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1159 * Build Scatter/Gather list
1161 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1162 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1163 sizeof (struct sgentry64));
1164 BUG_ON (fibsize > (fib->dev->max_fib_size -
1165 sizeof(struct aac_fibhdr)));
1168 * Now send the Fib to the adapter
1170 return aac_fib_send(ScsiPortCommand64, fib,
1171 fibsize, FsaNormal, 0, 1,
1172 (fib_callback) aac_srb_callback,
1176 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1179 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1181 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1182 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1184 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1185 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1187 * Build Scatter/Gather list
1189 fibsize = sizeof (struct aac_srb) +
1190 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1191 sizeof (struct sgentry));
1192 BUG_ON (fibsize > (fib->dev->max_fib_size -
1193 sizeof(struct aac_fibhdr)));
1196 * Now send the Fib to the adapter
1198 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1199 (fib_callback) aac_srb_callback, (void *) cmd);
1202 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1204 if ((sizeof(dma_addr_t) > 4) &&
1205 (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) &&
1206 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1208 return aac_scsi_32(fib, cmd);
1211 int aac_get_adapter_info(struct aac_dev* dev)
1216 struct aac_adapter_info *info;
1217 struct aac_bus_info *command;
1218 struct aac_bus_info_response *bus_info;
1220 if (!(fibptr = aac_fib_alloc(dev)))
1223 aac_fib_init(fibptr);
1224 info = (struct aac_adapter_info *) fib_data(fibptr);
1225 memset(info,0,sizeof(*info));
1227 rcode = aac_fib_send(RequestAdapterInfo,
1231 -1, 1, /* First `interrupt' command uses special wait */
1236 aac_fib_complete(fibptr);
1237 aac_fib_free(fibptr);
1240 memcpy(&dev->adapter_info, info, sizeof(*info));
1242 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1243 struct aac_supplement_adapter_info * info;
1245 aac_fib_init(fibptr);
1247 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1249 memset(info,0,sizeof(*info));
1251 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1260 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
1268 aac_fib_init(fibptr);
1270 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1272 memset(bus_info, 0, sizeof(*bus_info));
1274 command = (struct aac_bus_info *)bus_info;
1276 command->Command = cpu_to_le32(VM_Ioctl);
1277 command->ObjType = cpu_to_le32(FT_DRIVE);
1278 command->MethodId = cpu_to_le32(1);
1279 command->CtlCmd = cpu_to_le32(GetBusInfo);
1281 rcode = aac_fib_send(ContainerCommand,
1288 /* reasoned default */
1289 dev->maximum_num_physicals = 16;
1290 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1291 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1292 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1295 if (!dev->in_reset) {
1297 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1298 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1304 le32_to_cpu(dev->adapter_info.kernelbuild),
1305 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1306 dev->supplement_adapter_info.BuildDate);
1307 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1308 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1310 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1311 le32_to_cpu(dev->adapter_info.monitorbuild));
1312 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1313 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1315 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1316 le32_to_cpu(dev->adapter_info.biosbuild));
1318 if (aac_show_serial_number(
1319 shost_to_class(dev->scsi_host_ptr), buffer))
1320 printk(KERN_INFO "%s%d: serial %s",
1321 dev->name, dev->id, buffer);
1322 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1323 printk(KERN_INFO "%s%d: TSID %.*s\n",
1325 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1326 dev->supplement_adapter_info.VpdInfo.Tsid);
1328 if (!aac_check_reset ||
1329 ((aac_check_reset != 1) &&
1330 (dev->supplement_adapter_info.SupportedOptions2 &
1331 cpu_to_le32(AAC_OPTION_IGNORE_RESET)))) {
1332 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1333 dev->name, dev->id);
1337 dev->cache_protected = 0;
1338 dev->nondasd_support = 0;
1339 dev->raid_scsi_mode = 0;
1340 if(dev->adapter_info.options & AAC_OPT_NONDASD)
1341 dev->nondasd_support = 1;
1344 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1345 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1346 * force nondasd support on. If we decide to allow the non-dasd flag
1347 * additional changes changes will have to be made to support
1348 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1349 * changed to support the new dev->raid_scsi_mode flag instead of
1350 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1351 * function aac_detect will have to be modified where it sets up the
1352 * max number of channels based on the aac->nondasd_support flag only.
1354 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1355 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1356 dev->nondasd_support = 1;
1357 dev->raid_scsi_mode = 1;
1359 if (dev->raid_scsi_mode != 0)
1360 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1361 dev->name, dev->id);
1364 dev->nondasd_support = (nondasd!=0);
1365 if(dev->nondasd_support != 0) {
1366 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1369 dev->dac_support = 0;
1370 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1371 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1372 dev->dac_support = 1;
1376 dev->dac_support = (dacmode!=0);
1378 if(dev->dac_support != 0) {
1379 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1380 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1381 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1382 dev->name, dev->id);
1383 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1384 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1385 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1386 dev->name, dev->id);
1387 dev->dac_support = 0;
1389 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1390 dev->name, dev->id);
1395 * Deal with configuring for the individualized limits of each packet
1398 dev->a_ops.adapter_scsi = (dev->dac_support)
1399 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1403 if (dev->raw_io_interface) {
1404 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1407 dev->a_ops.adapter_read = aac_read_raw_io;
1408 dev->a_ops.adapter_write = aac_write_raw_io;
1410 dev->a_ops.adapter_bounds = aac_bounds_32;
1411 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1412 sizeof(struct aac_fibhdr) -
1413 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1414 sizeof(struct sgentry);
1415 if (dev->dac_support) {
1416 dev->a_ops.adapter_read = aac_read_block64;
1417 dev->a_ops.adapter_write = aac_write_block64;
1419 * 38 scatter gather elements
1421 dev->scsi_host_ptr->sg_tablesize =
1422 (dev->max_fib_size -
1423 sizeof(struct aac_fibhdr) -
1424 sizeof(struct aac_write64) +
1425 sizeof(struct sgentry64)) /
1426 sizeof(struct sgentry64);
1428 dev->a_ops.adapter_read = aac_read_block;
1429 dev->a_ops.adapter_write = aac_write_block;
1431 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1432 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1434 * Worst case size that could cause sg overflow when
1435 * we break up SG elements that are larger than 64KB.
1436 * Would be nice if we could tell the SCSI layer what
1437 * the maximum SG element size can be. Worst case is
1438 * (sg_tablesize-1) 4KB elements with one 64KB
1440 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1442 dev->scsi_host_ptr->max_sectors =
1443 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1447 aac_fib_complete(fibptr);
1448 aac_fib_free(fibptr);
1454 static void io_callback(void *context, struct fib * fibptr)
1456 struct aac_dev *dev;
1457 struct aac_read_reply *readreply;
1458 struct scsi_cmnd *scsicmd;
1461 scsicmd = (struct scsi_cmnd *) context;
1463 if (!aac_valid_context(scsicmd, fibptr))
1467 cid = scmd_id(scsicmd);
1469 if (nblank(dprintk(x))) {
1471 switch (scsicmd->cmnd[0]) {
1474 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1475 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1479 lba = ((u64)scsicmd->cmnd[2] << 56) |
1480 ((u64)scsicmd->cmnd[3] << 48) |
1481 ((u64)scsicmd->cmnd[4] << 40) |
1482 ((u64)scsicmd->cmnd[5] << 32) |
1483 ((u64)scsicmd->cmnd[6] << 24) |
1484 (scsicmd->cmnd[7] << 16) |
1485 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1489 lba = ((u64)scsicmd->cmnd[2] << 24) |
1490 (scsicmd->cmnd[3] << 16) |
1491 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1494 lba = ((u64)scsicmd->cmnd[2] << 24) |
1495 (scsicmd->cmnd[3] << 16) |
1496 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1500 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1501 smp_processor_id(), (unsigned long long)lba, jiffies);
1504 BUG_ON(fibptr == NULL);
1506 scsi_dma_unmap(scsicmd);
1508 readreply = (struct aac_read_reply *)fib_data(fibptr);
1509 if (le32_to_cpu(readreply->status) == ST_OK)
1510 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1512 #ifdef AAC_DETAILED_STATUS_INFO
1513 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1514 le32_to_cpu(readreply->status));
1516 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1517 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1519 SENCODE_INTERNAL_TARGET_FAILURE,
1520 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1522 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1523 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1524 ? sizeof(scsicmd->sense_buffer)
1525 : sizeof(dev->fsa_dev[cid].sense_data));
1527 aac_fib_complete(fibptr);
1528 aac_fib_free(fibptr);
1530 scsicmd->scsi_done(scsicmd);
1533 static int aac_read(struct scsi_cmnd * scsicmd)
1538 struct aac_dev *dev;
1539 struct fib * cmd_fibcontext;
1541 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1543 * Get block address and transfer length
1545 switch (scsicmd->cmnd[0]) {
1547 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1549 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1550 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1551 count = scsicmd->cmnd[4];
1557 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1559 lba = ((u64)scsicmd->cmnd[2] << 56) |
1560 ((u64)scsicmd->cmnd[3] << 48) |
1561 ((u64)scsicmd->cmnd[4] << 40) |
1562 ((u64)scsicmd->cmnd[5] << 32) |
1563 ((u64)scsicmd->cmnd[6] << 24) |
1564 (scsicmd->cmnd[7] << 16) |
1565 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1566 count = (scsicmd->cmnd[10] << 24) |
1567 (scsicmd->cmnd[11] << 16) |
1568 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1571 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1573 lba = ((u64)scsicmd->cmnd[2] << 24) |
1574 (scsicmd->cmnd[3] << 16) |
1575 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1576 count = (scsicmd->cmnd[6] << 24) |
1577 (scsicmd->cmnd[7] << 16) |
1578 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1581 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1583 lba = ((u64)scsicmd->cmnd[2] << 24) |
1584 (scsicmd->cmnd[3] << 16) |
1585 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1586 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1589 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1590 smp_processor_id(), (unsigned long long)lba, jiffies));
1591 if (aac_adapter_bounds(dev,scsicmd,lba))
1594 * Alocate and initialize a Fib
1596 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1600 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1603 * Check that the command queued to the controller
1605 if (status == -EINPROGRESS) {
1606 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1610 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1612 * For some reason, the Fib didn't queue, return QUEUE_FULL
1614 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1615 scsicmd->scsi_done(scsicmd);
1616 aac_fib_complete(cmd_fibcontext);
1617 aac_fib_free(cmd_fibcontext);
1621 static int aac_write(struct scsi_cmnd * scsicmd)
1627 struct aac_dev *dev;
1628 struct fib * cmd_fibcontext;
1630 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1632 * Get block address and transfer length
1634 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1636 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1637 count = scsicmd->cmnd[4];
1641 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1642 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1644 lba = ((u64)scsicmd->cmnd[2] << 56) |
1645 ((u64)scsicmd->cmnd[3] << 48) |
1646 ((u64)scsicmd->cmnd[4] << 40) |
1647 ((u64)scsicmd->cmnd[5] << 32) |
1648 ((u64)scsicmd->cmnd[6] << 24) |
1649 (scsicmd->cmnd[7] << 16) |
1650 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1651 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1652 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1653 fua = scsicmd->cmnd[1] & 0x8;
1654 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1655 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1657 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1658 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1659 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1660 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1661 fua = scsicmd->cmnd[1] & 0x8;
1663 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1664 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1665 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1666 fua = scsicmd->cmnd[1] & 0x8;
1668 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1669 smp_processor_id(), (unsigned long long)lba, jiffies));
1670 if (aac_adapter_bounds(dev,scsicmd,lba))
1673 * Allocate and initialize a Fib then setup a BlockWrite command
1675 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1676 scsicmd->result = DID_ERROR << 16;
1677 scsicmd->scsi_done(scsicmd);
1681 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1684 * Check that the command queued to the controller
1686 if (status == -EINPROGRESS) {
1687 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1691 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1693 * For some reason, the Fib didn't queue, return QUEUE_FULL
1695 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1696 scsicmd->scsi_done(scsicmd);
1698 aac_fib_complete(cmd_fibcontext);
1699 aac_fib_free(cmd_fibcontext);
1703 static void synchronize_callback(void *context, struct fib *fibptr)
1705 struct aac_synchronize_reply *synchronizereply;
1706 struct scsi_cmnd *cmd;
1710 if (!aac_valid_context(cmd, fibptr))
1713 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1714 smp_processor_id(), jiffies));
1715 BUG_ON(fibptr == NULL);
1718 synchronizereply = fib_data(fibptr);
1719 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1720 cmd->result = DID_OK << 16 |
1721 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1723 struct scsi_device *sdev = cmd->device;
1724 struct aac_dev *dev = fibptr->dev;
1725 u32 cid = sdev_id(sdev);
1727 "synchronize_callback: synchronize failed, status = %d\n",
1728 le32_to_cpu(synchronizereply->status));
1729 cmd->result = DID_OK << 16 |
1730 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1731 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1733 SENCODE_INTERNAL_TARGET_FAILURE,
1734 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1736 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1737 min(sizeof(dev->fsa_dev[cid].sense_data),
1738 sizeof(cmd->sense_buffer)));
1741 aac_fib_complete(fibptr);
1742 aac_fib_free(fibptr);
1743 cmd->scsi_done(cmd);
1746 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1749 struct fib *cmd_fibcontext;
1750 struct aac_synchronize *synchronizecmd;
1751 struct scsi_cmnd *cmd;
1752 struct scsi_device *sdev = scsicmd->device;
1754 struct aac_dev *aac;
1755 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1756 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1757 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1758 unsigned long flags;
1761 * Wait for all outstanding queued commands to complete to this
1762 * specific target (block).
1764 spin_lock_irqsave(&sdev->list_lock, flags);
1765 list_for_each_entry(cmd, &sdev->cmd_list, list)
1766 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1770 if (cmd->cmnd[0] == WRITE_6) {
1771 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1772 (cmd->cmnd[2] << 8) |
1774 cmnd_count = cmd->cmnd[4];
1775 if (cmnd_count == 0)
1777 } else if (cmd->cmnd[0] == WRITE_16) {
1778 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1779 ((u64)cmd->cmnd[3] << 48) |
1780 ((u64)cmd->cmnd[4] << 40) |
1781 ((u64)cmd->cmnd[5] << 32) |
1782 ((u64)cmd->cmnd[6] << 24) |
1783 (cmd->cmnd[7] << 16) |
1784 (cmd->cmnd[8] << 8) |
1786 cmnd_count = (cmd->cmnd[10] << 24) |
1787 (cmd->cmnd[11] << 16) |
1788 (cmd->cmnd[12] << 8) |
1790 } else if (cmd->cmnd[0] == WRITE_12) {
1791 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1792 (cmd->cmnd[3] << 16) |
1793 (cmd->cmnd[4] << 8) |
1795 cmnd_count = (cmd->cmnd[6] << 24) |
1796 (cmd->cmnd[7] << 16) |
1797 (cmd->cmnd[8] << 8) |
1799 } else if (cmd->cmnd[0] == WRITE_10) {
1800 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1801 (cmd->cmnd[3] << 16) |
1802 (cmd->cmnd[4] << 8) |
1804 cmnd_count = (cmd->cmnd[7] << 8) |
1808 if (((cmnd_lba + cmnd_count) < lba) ||
1809 (count && ((lba + count) < cmnd_lba)))
1815 spin_unlock_irqrestore(&sdev->list_lock, flags);
1818 * Yield the processor (requeue for later)
1821 return SCSI_MLQUEUE_DEVICE_BUSY;
1823 aac = (struct aac_dev *)sdev->host->hostdata;
1825 return SCSI_MLQUEUE_HOST_BUSY;
1828 * Allocate and initialize a Fib
1830 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1831 return SCSI_MLQUEUE_HOST_BUSY;
1833 aac_fib_init(cmd_fibcontext);
1835 synchronizecmd = fib_data(cmd_fibcontext);
1836 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1837 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1838 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
1839 synchronizecmd->count =
1840 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1843 * Now send the Fib to the adapter
1845 status = aac_fib_send(ContainerCommand,
1847 sizeof(struct aac_synchronize),
1850 (fib_callback)synchronize_callback,
1854 * Check that the command queued to the controller
1856 if (status == -EINPROGRESS) {
1857 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1862 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1863 aac_fib_complete(cmd_fibcontext);
1864 aac_fib_free(cmd_fibcontext);
1865 return SCSI_MLQUEUE_HOST_BUSY;
1869 * aac_scsi_cmd() - Process SCSI command
1870 * @scsicmd: SCSI command block
1872 * Emulate a SCSI command and queue the required request for the
1876 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1879 struct Scsi_Host *host = scsicmd->device->host;
1880 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1881 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1883 if (fsa_dev_ptr == NULL)
1886 * If the bus, id or lun is out of range, return fail
1887 * Test does not apply to ID 16, the pseudo id for the controller
1890 cid = scmd_id(scsicmd);
1891 if (cid != host->this_id) {
1892 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
1893 if((cid >= dev->maximum_num_containers) ||
1894 (scsicmd->device->lun != 0)) {
1895 scsicmd->result = DID_NO_CONNECT << 16;
1896 scsicmd->scsi_done(scsicmd);
1901 * If the target container doesn't exist, it may have
1902 * been newly created
1904 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1905 switch (scsicmd->cmnd[0]) {
1906 case SERVICE_ACTION_IN:
1907 if (!(dev->raw_io_interface) ||
1908 !(dev->raw_io_64) ||
1909 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1913 case TEST_UNIT_READY:
1916 return _aac_probe_container(scsicmd,
1917 aac_probe_container_callback2);
1922 } else { /* check for physical non-dasd devices */
1923 if ((dev->nondasd_support == 1) || expose_physicals) {
1926 return aac_send_srb_fib(scsicmd);
1928 scsicmd->result = DID_NO_CONNECT << 16;
1929 scsicmd->scsi_done(scsicmd);
1935 * else Command for the controller itself
1937 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1938 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1940 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1941 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1942 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1944 SENCODE_INVALID_COMMAND,
1945 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1946 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1947 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1948 ? sizeof(scsicmd->sense_buffer)
1949 : sizeof(dev->fsa_dev[cid].sense_data));
1950 scsicmd->scsi_done(scsicmd);
1955 /* Handle commands here that don't really require going out to the adapter */
1956 switch (scsicmd->cmnd[0]) {
1959 struct inquiry_data inq_data;
1961 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
1962 memset(&inq_data, 0, sizeof (struct inquiry_data));
1964 if (scsicmd->cmnd[1] & 0x1 ) {
1965 char *arr = (char *)&inq_data;
1968 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
1969 INQD_PDT_PROC : INQD_PDT_DA;
1970 if (scsicmd->cmnd[2] == 0) {
1971 /* supported vital product data pages */
1975 arr[1] = scsicmd->cmnd[2];
1976 aac_internal_transfer(scsicmd, &inq_data, 0,
1978 scsicmd->result = DID_OK << 16 |
1979 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1980 } else if (scsicmd->cmnd[2] == 0x80) {
1981 /* unit serial number page */
1982 arr[3] = setinqserial(dev, &arr[4],
1984 arr[1] = scsicmd->cmnd[2];
1985 aac_internal_transfer(scsicmd, &inq_data, 0,
1987 return aac_get_container_serial(scsicmd);
1989 /* vpd page not implemented */
1990 scsicmd->result = DID_OK << 16 |
1991 COMMAND_COMPLETE << 8 |
1992 SAM_STAT_CHECK_CONDITION;
1993 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1995 SENCODE_INVALID_CDB_FIELD,
1996 ASENCODE_NO_SENSE, 0, 7, 2, 0);
1997 memcpy(scsicmd->sense_buffer,
1998 &dev->fsa_dev[cid].sense_data,
1999 (sizeof(dev->fsa_dev[cid].sense_data) >
2000 sizeof(scsicmd->sense_buffer))
2001 ? sizeof(scsicmd->sense_buffer)
2002 : sizeof(dev->fsa_dev[cid].sense_data));
2004 scsicmd->scsi_done(scsicmd);
2007 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
2008 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 */
2009 inq_data.inqd_len = 31;
2010 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2011 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
2013 * Set the Vendor, Product, and Revision Level
2014 * see: <vendor>.c i.e. aac.c
2016 if (cid == host->this_id) {
2017 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
2018 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2019 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
2020 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2021 scsicmd->scsi_done(scsicmd);
2026 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2027 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2028 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
2029 return aac_get_container_name(scsicmd);
2031 case SERVICE_ACTION_IN:
2032 if (!(dev->raw_io_interface) ||
2033 !(dev->raw_io_64) ||
2034 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2040 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2041 capacity = fsa_dev_ptr[cid].size - 1;
2042 cp[0] = (capacity >> 56) & 0xff;
2043 cp[1] = (capacity >> 48) & 0xff;
2044 cp[2] = (capacity >> 40) & 0xff;
2045 cp[3] = (capacity >> 32) & 0xff;
2046 cp[4] = (capacity >> 24) & 0xff;
2047 cp[5] = (capacity >> 16) & 0xff;
2048 cp[6] = (capacity >> 8) & 0xff;
2049 cp[7] = (capacity >> 0) & 0xff;
2055 aac_internal_transfer(scsicmd, cp, 0,
2056 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
2057 if (sizeof(cp) < scsicmd->cmnd[13]) {
2058 unsigned int len, offset = sizeof(cp);
2060 memset(cp, 0, offset);
2062 len = min_t(size_t, scsicmd->cmnd[13] - offset,
2064 aac_internal_transfer(scsicmd, cp, offset, len);
2065 } while ((offset += len) < scsicmd->cmnd[13]);
2068 /* Do not cache partition table for arrays */
2069 scsicmd->device->removable = 1;
2071 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2072 scsicmd->scsi_done(scsicmd);
2082 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
2083 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2084 capacity = fsa_dev_ptr[cid].size - 1;
2088 cp[0] = (capacity >> 24) & 0xff;
2089 cp[1] = (capacity >> 16) & 0xff;
2090 cp[2] = (capacity >> 8) & 0xff;
2091 cp[3] = (capacity >> 0) & 0xff;
2096 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
2097 /* Do not cache partition table for arrays */
2098 scsicmd->device->removable = 1;
2100 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2101 scsicmd->scsi_done(scsicmd);
2109 int mode_buf_length = 4;
2111 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
2112 mode_buf[0] = 3; /* Mode data length */
2113 mode_buf[1] = 0; /* Medium type - default */
2114 mode_buf[2] = 0; /* Device-specific param,
2115 bit 8: 0/1 = write enabled/protected
2116 bit 4: 0/1 = FUA enabled */
2117 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2119 mode_buf[3] = 0; /* Block descriptor length */
2120 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2121 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2125 mode_buf[6] = ((aac_cache & 6) == 2)
2126 ? 0 : 0x04; /* WCE */
2127 mode_buf_length = 7;
2128 if (mode_buf_length > scsicmd->cmnd[4])
2129 mode_buf_length = scsicmd->cmnd[4];
2131 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
2132 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2133 scsicmd->scsi_done(scsicmd);
2140 int mode_buf_length = 8;
2142 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
2143 mode_buf[0] = 0; /* Mode data length (MSB) */
2144 mode_buf[1] = 6; /* Mode data length (LSB) */
2145 mode_buf[2] = 0; /* Medium type - default */
2146 mode_buf[3] = 0; /* Device-specific param,
2147 bit 8: 0/1 = write enabled/protected
2148 bit 4: 0/1 = FUA enabled */
2149 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2151 mode_buf[4] = 0; /* reserved */
2152 mode_buf[5] = 0; /* reserved */
2153 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2154 mode_buf[7] = 0; /* Block descriptor length (LSB) */
2155 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2156 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2160 mode_buf[10] = ((aac_cache & 6) == 2)
2161 ? 0 : 0x04; /* WCE */
2162 mode_buf_length = 11;
2163 if (mode_buf_length > scsicmd->cmnd[8])
2164 mode_buf_length = scsicmd->cmnd[8];
2166 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
2168 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2169 scsicmd->scsi_done(scsicmd);
2174 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2175 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2176 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2177 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2178 scsicmd->scsi_done(scsicmd);
2181 case ALLOW_MEDIUM_REMOVAL:
2182 dprintk((KERN_DEBUG "LOCK command.\n"));
2183 if (scsicmd->cmnd[4])
2184 fsa_dev_ptr[cid].locked = 1;
2186 fsa_dev_ptr[cid].locked = 0;
2188 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2189 scsicmd->scsi_done(scsicmd);
2192 * These commands are all No-Ops
2194 case TEST_UNIT_READY:
2198 case REASSIGN_BLOCKS:
2201 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2202 scsicmd->scsi_done(scsicmd);
2206 switch (scsicmd->cmnd[0])
2215 * Hack to keep track of ordinal number of the device that
2216 * corresponds to a container. Needed to convert
2217 * containers to /dev/sd device names
2220 if (scsicmd->request->rq_disk)
2221 strlcpy(fsa_dev_ptr[cid].devname,
2222 scsicmd->request->rq_disk->disk_name,
2223 min(sizeof(fsa_dev_ptr[cid].devname),
2224 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2226 return aac_read(scsicmd);
2234 return aac_write(scsicmd);
2236 case SYNCHRONIZE_CACHE:
2237 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2238 scsicmd->result = DID_OK << 16 |
2239 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2240 scsicmd->scsi_done(scsicmd);
2243 /* Issue FIB to tell Firmware to flush it's cache */
2244 if ((aac_cache & 6) != 2)
2245 return aac_synchronize(scsicmd);
2249 * Unhandled commands
2251 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2252 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2253 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
2254 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2255 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
2256 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2257 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
2258 ? sizeof(scsicmd->sense_buffer)
2259 : sizeof(dev->fsa_dev[cid].sense_data));
2260 scsicmd->scsi_done(scsicmd);
2265 static int query_disk(struct aac_dev *dev, void __user *arg)
2267 struct aac_query_disk qd;
2268 struct fsa_dev_info *fsa_dev_ptr;
2270 fsa_dev_ptr = dev->fsa_dev;
2273 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2277 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2279 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2281 qd.instance = dev->scsi_host_ptr->host_no;
2283 qd.id = CONTAINER_TO_ID(qd.cnum);
2284 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2286 else return -EINVAL;
2288 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
2289 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2290 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2292 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2297 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2298 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2300 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2305 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2307 struct aac_delete_disk dd;
2308 struct fsa_dev_info *fsa_dev_ptr;
2310 fsa_dev_ptr = dev->fsa_dev;
2314 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2317 if (dd.cnum >= dev->maximum_num_containers)
2320 * Mark this container as being deleted.
2322 fsa_dev_ptr[dd.cnum].deleted = 1;
2324 * Mark the container as no longer valid
2326 fsa_dev_ptr[dd.cnum].valid = 0;
2330 static int delete_disk(struct aac_dev *dev, void __user *arg)
2332 struct aac_delete_disk dd;
2333 struct fsa_dev_info *fsa_dev_ptr;
2335 fsa_dev_ptr = dev->fsa_dev;
2339 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2342 if (dd.cnum >= dev->maximum_num_containers)
2345 * If the container is locked, it can not be deleted by the API.
2347 if (fsa_dev_ptr[dd.cnum].locked)
2351 * Mark the container as no longer being valid.
2353 fsa_dev_ptr[dd.cnum].valid = 0;
2354 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2359 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2362 case FSACTL_QUERY_DISK:
2363 return query_disk(dev, arg);
2364 case FSACTL_DELETE_DISK:
2365 return delete_disk(dev, arg);
2366 case FSACTL_FORCE_DELETE_DISK:
2367 return force_delete_disk(dev, arg);
2368 case FSACTL_GET_CONTAINERS:
2369 return aac_get_containers(dev);
2378 * @context: the context set in the fib - here it is scsi cmd
2379 * @fibptr: pointer to the fib
2381 * Handles the completion of a scsi command to a non dasd device
2385 static void aac_srb_callback(void *context, struct fib * fibptr)
2387 struct aac_dev *dev;
2388 struct aac_srb_reply *srbreply;
2389 struct scsi_cmnd *scsicmd;
2391 scsicmd = (struct scsi_cmnd *) context;
2393 if (!aac_valid_context(scsicmd, fibptr))
2396 BUG_ON(fibptr == NULL);
2400 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2402 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2404 * Calculate resid for sg
2407 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2408 - le32_to_cpu(srbreply->data_xfer_length));
2410 scsi_dma_unmap(scsicmd);
2413 * First check the fib status
2416 if (le32_to_cpu(srbreply->status) != ST_OK){
2418 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2419 len = (le32_to_cpu(srbreply->sense_data_size) >
2420 sizeof(scsicmd->sense_buffer)) ?
2421 sizeof(scsicmd->sense_buffer) :
2422 le32_to_cpu(srbreply->sense_data_size);
2423 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2424 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2428 * Next check the srb status
2430 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2431 case SRB_STATUS_ERROR_RECOVERY:
2432 case SRB_STATUS_PENDING:
2433 case SRB_STATUS_SUCCESS:
2434 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2436 case SRB_STATUS_DATA_OVERRUN:
2437 switch(scsicmd->cmnd[0]){
2446 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
2447 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2449 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2451 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2454 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2458 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2462 case SRB_STATUS_ABORTED:
2463 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2465 case SRB_STATUS_ABORT_FAILED:
2466 // Not sure about this one - but assuming the hba was trying to abort for some reason
2467 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2469 case SRB_STATUS_PARITY_ERROR:
2470 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2472 case SRB_STATUS_NO_DEVICE:
2473 case SRB_STATUS_INVALID_PATH_ID:
2474 case SRB_STATUS_INVALID_TARGET_ID:
2475 case SRB_STATUS_INVALID_LUN:
2476 case SRB_STATUS_SELECTION_TIMEOUT:
2477 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2480 case SRB_STATUS_COMMAND_TIMEOUT:
2481 case SRB_STATUS_TIMEOUT:
2482 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2485 case SRB_STATUS_BUSY:
2486 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
2489 case SRB_STATUS_BUS_RESET:
2490 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2493 case SRB_STATUS_MESSAGE_REJECTED:
2494 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2496 case SRB_STATUS_REQUEST_FLUSHED:
2497 case SRB_STATUS_ERROR:
2498 case SRB_STATUS_INVALID_REQUEST:
2499 case SRB_STATUS_REQUEST_SENSE_FAILED:
2500 case SRB_STATUS_NO_HBA:
2501 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2502 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2503 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2504 case SRB_STATUS_DELAYED_RETRY:
2505 case SRB_STATUS_BAD_FUNCTION:
2506 case SRB_STATUS_NOT_STARTED:
2507 case SRB_STATUS_NOT_IN_USE:
2508 case SRB_STATUS_FORCE_ABORT:
2509 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2511 #ifdef AAC_DETAILED_STATUS_INFO
2512 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2513 le32_to_cpu(srbreply->srb_status) & 0x3F,
2514 aac_get_status_string(
2515 le32_to_cpu(srbreply->srb_status) & 0x3F),
2517 le32_to_cpu(srbreply->scsi_status));
2519 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2522 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2524 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2525 len = (le32_to_cpu(srbreply->sense_data_size) >
2526 sizeof(scsicmd->sense_buffer)) ?
2527 sizeof(scsicmd->sense_buffer) :
2528 le32_to_cpu(srbreply->sense_data_size);
2529 #ifdef AAC_DETAILED_STATUS_INFO
2530 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2531 le32_to_cpu(srbreply->status), len);
2533 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2537 * OR in the scsi status (already shifted up a bit)
2539 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2541 aac_fib_complete(fibptr);
2542 aac_fib_free(fibptr);
2543 scsicmd->scsi_done(scsicmd);
2549 * @scsicmd: the scsi command block
2551 * This routine will form a FIB and fill in the aac_srb from the
2552 * scsicmd passed in.
2555 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2557 struct fib* cmd_fibcontext;
2558 struct aac_dev* dev;
2561 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2562 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2563 scsicmd->device->lun > 7) {
2564 scsicmd->result = DID_NO_CONNECT << 16;
2565 scsicmd->scsi_done(scsicmd);
2570 * Allocate and initialize a Fib then setup a BlockWrite command
2572 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2575 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2578 * Check that the command queued to the controller
2580 if (status == -EINPROGRESS) {
2581 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2585 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2586 aac_fib_complete(cmd_fibcontext);
2587 aac_fib_free(cmd_fibcontext);
2592 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2594 struct aac_dev *dev;
2595 unsigned long byte_count = 0;
2598 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2599 // Get rid of old data
2601 psg->sg[0].addr = 0;
2602 psg->sg[0].count = 0;
2604 nseg = scsi_dma_map(scsicmd);
2607 struct scatterlist *sg;
2610 psg->count = cpu_to_le32(nseg);
2612 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2613 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2614 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2615 byte_count += sg_dma_len(sg);
2617 /* hba wants the size to be exact */
2618 if (byte_count > scsi_bufflen(scsicmd)) {
2619 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2620 (byte_count - scsi_bufflen(scsicmd));
2621 psg->sg[i-1].count = cpu_to_le32(temp);
2622 byte_count = scsi_bufflen(scsicmd);
2624 /* Check for command underflow */
2625 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2626 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2627 byte_count, scsicmd->underflow);
2634 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2636 struct aac_dev *dev;
2637 unsigned long byte_count = 0;
2641 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2642 // Get rid of old data
2644 psg->sg[0].addr[0] = 0;
2645 psg->sg[0].addr[1] = 0;
2646 psg->sg[0].count = 0;
2648 nseg = scsi_dma_map(scsicmd);
2651 struct scatterlist *sg;
2654 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2655 int count = sg_dma_len(sg);
2656 addr = sg_dma_address(sg);
2657 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2658 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2659 psg->sg[i].count = cpu_to_le32(count);
2660 byte_count += count;
2662 psg->count = cpu_to_le32(nseg);
2663 /* hba wants the size to be exact */
2664 if (byte_count > scsi_bufflen(scsicmd)) {
2665 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2666 (byte_count - scsi_bufflen(scsicmd));
2667 psg->sg[i-1].count = cpu_to_le32(temp);
2668 byte_count = scsi_bufflen(scsicmd);
2670 /* Check for command underflow */
2671 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2672 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2673 byte_count, scsicmd->underflow);
2679 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2681 unsigned long byte_count = 0;
2684 // Get rid of old data
2686 psg->sg[0].next = 0;
2687 psg->sg[0].prev = 0;
2688 psg->sg[0].addr[0] = 0;
2689 psg->sg[0].addr[1] = 0;
2690 psg->sg[0].count = 0;
2691 psg->sg[0].flags = 0;
2693 nseg = scsi_dma_map(scsicmd);
2696 struct scatterlist *sg;
2699 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2700 int count = sg_dma_len(sg);
2701 u64 addr = sg_dma_address(sg);
2702 psg->sg[i].next = 0;
2703 psg->sg[i].prev = 0;
2704 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2705 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2706 psg->sg[i].count = cpu_to_le32(count);
2707 psg->sg[i].flags = 0;
2708 byte_count += count;
2710 psg->count = cpu_to_le32(nseg);
2711 /* hba wants the size to be exact */
2712 if (byte_count > scsi_bufflen(scsicmd)) {
2713 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2714 (byte_count - scsi_bufflen(scsicmd));
2715 psg->sg[i-1].count = cpu_to_le32(temp);
2716 byte_count = scsi_bufflen(scsicmd);
2718 /* Check for command underflow */
2719 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2720 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2721 byte_count, scsicmd->underflow);
2727 #ifdef AAC_DETAILED_STATUS_INFO
2729 struct aac_srb_status_info {
2735 static struct aac_srb_status_info srb_status_info[] = {
2736 { SRB_STATUS_PENDING, "Pending Status"},
2737 { SRB_STATUS_SUCCESS, "Success"},
2738 { SRB_STATUS_ABORTED, "Aborted Command"},
2739 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2740 { SRB_STATUS_ERROR, "Error Event"},
2741 { SRB_STATUS_BUSY, "Device Busy"},
2742 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2743 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2744 { SRB_STATUS_NO_DEVICE, "No Device"},
2745 { SRB_STATUS_TIMEOUT, "Timeout"},
2746 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2747 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2748 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2749 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2750 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2751 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2752 { SRB_STATUS_NO_HBA, "No HBA"},
2753 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2754 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2755 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2756 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2757 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2758 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2759 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2760 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2761 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2762 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2763 { SRB_STATUS_NOT_STARTED, "Not Started"},
2764 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2765 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2766 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2767 { 0xff, "Unknown Error"}
2770 char *aac_get_status_string(u32 status)
2774 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2775 if (srb_status_info[i].status == status)
2776 return srb_status_info[i].str;
2778 return "Bad Status Code";