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 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/sched.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 #include <linux/slab.h>
33 #include <linux/completion.h>
34 #include <linux/blkdev.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 int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
137 #ifdef AAC_DETAILED_STATUS_INFO
138 static char *aac_get_status_string(u32 status);
142 * Non dasd selection is handled entirely in aachba now
145 static int nondasd = -1;
146 static int dacmode = -1;
148 static int commit = -1;
150 module_param(nondasd, int, 0);
151 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
152 module_param(dacmode, int, 0);
153 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
154 module_param(commit, int, 0);
155 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");
158 module_param(numacb, int, S_IRUGO|S_IWUSR);
159 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid\nvalues are 512 and down. Default is to use suggestion from Firmware.");
162 module_param(acbsize, int, S_IRUGO|S_IWUSR);
163 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512,\n2048, 4096 and 8192. Default is to use suggestion from Firmware.");
165 * aac_get_config_status - check the adapter configuration
166 * @common: adapter to query
168 * Query config status, and commit the configuration if needed.
170 int aac_get_config_status(struct aac_dev *dev)
175 if (!(fibptr = fib_alloc(dev)))
180 struct aac_get_config_status *dinfo;
181 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
183 dinfo->command = cpu_to_le32(VM_ContainerConfig);
184 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
185 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
188 status = fib_send(ContainerCommand,
190 sizeof (struct aac_get_config_status),
195 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
197 struct aac_get_config_status_resp *reply
198 = (struct aac_get_config_status_resp *) fib_data(fibptr);
199 dprintk((KERN_WARNING
200 "aac_get_config_status: response=%d status=%d action=%d\n",
201 le32_to_cpu(reply->response),
202 le32_to_cpu(reply->status),
203 le32_to_cpu(reply->data.action)));
204 if ((le32_to_cpu(reply->response) != ST_OK) ||
205 (le32_to_cpu(reply->status) != CT_OK) ||
206 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
207 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
211 fib_complete(fibptr);
212 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
215 struct aac_commit_config * dinfo;
217 dinfo = (struct aac_commit_config *) fib_data(fibptr);
219 dinfo->command = cpu_to_le32(VM_ContainerConfig);
220 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
222 status = fib_send(ContainerCommand,
224 sizeof (struct aac_commit_config),
228 fib_complete(fibptr);
229 } else if (commit == 0) {
231 "aac_get_config_status: Foreign device configurations are being ignored\n");
239 * aac_get_containers - list containers
240 * @common: adapter to probe
242 * Make a list of all containers on this controller
244 int aac_get_containers(struct aac_dev *dev)
246 struct fsa_dev_info *fsa_dev_ptr;
251 struct aac_get_container_count *dinfo;
252 struct aac_get_container_count_resp *dresp;
253 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
255 instance = dev->scsi_host_ptr->unique_id;
257 if (!(fibptr = fib_alloc(dev)))
261 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
262 dinfo->command = cpu_to_le32(VM_ContainerConfig);
263 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
265 status = fib_send(ContainerCommand,
267 sizeof (struct aac_get_container_count),
272 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
273 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
274 fib_complete(fibptr);
277 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
278 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
279 fsa_dev_ptr = (struct fsa_dev_info *) kmalloc(
280 sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL);
285 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
287 dev->fsa_dev = fsa_dev_ptr;
288 dev->maximum_num_containers = maximum_num_containers;
290 for (index = 0; index < dev->maximum_num_containers; index++) {
291 struct aac_query_mount *dinfo;
292 struct aac_mount *dresp;
294 fsa_dev_ptr[index].devname[0] = '\0';
297 dinfo = (struct aac_query_mount *) fib_data(fibptr);
299 dinfo->command = cpu_to_le32(VM_NameServe);
300 dinfo->count = cpu_to_le32(index);
301 dinfo->type = cpu_to_le32(FT_FILESYS);
303 status = fib_send(ContainerCommand,
305 sizeof (struct aac_query_mount),
310 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
313 dresp = (struct aac_mount *)fib_data(fibptr);
316 "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%u\n",
317 (int)index, (int)le32_to_cpu(dresp->status),
318 (int)le32_to_cpu(dresp->mnt[0].vol),
319 (int)le32_to_cpu(dresp->mnt[0].state),
320 (unsigned)le32_to_cpu(dresp->mnt[0].capacity)));
321 if ((le32_to_cpu(dresp->status) == ST_OK) &&
322 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
323 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
324 fsa_dev_ptr[index].valid = 1;
325 fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
326 fsa_dev_ptr[index].size = le32_to_cpu(dresp->mnt[0].capacity);
327 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
328 fsa_dev_ptr[index].ro = 1;
330 fib_complete(fibptr);
332 * If there are no more containers, then stop asking.
334 if ((index + 1) >= le32_to_cpu(dresp->count)){
342 static void aac_io_done(struct scsi_cmnd * scsicmd)
344 unsigned long cpu_flags;
345 struct Scsi_Host *host = scsicmd->device->host;
346 spin_lock_irqsave(host->host_lock, cpu_flags);
347 scsicmd->scsi_done(scsicmd);
348 spin_unlock_irqrestore(host->host_lock, cpu_flags);
351 static void get_container_name_callback(void *context, struct fib * fibptr)
353 struct aac_get_name_resp * get_name_reply;
354 struct scsi_cmnd * scsicmd;
356 scsicmd = (struct scsi_cmnd *) context;
358 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
362 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
363 /* Failure is irrelevant, using default value instead */
364 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
365 && (get_name_reply->data[0] != '\0')) {
368 char * sp = get_name_reply->data;
369 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
372 count = sizeof(((struct inquiry_data *)NULL)->inqd_pid);
373 dp = ((struct inquiry_data *)scsicmd->request_buffer)->inqd_pid;
375 *dp++ = (*sp) ? *sp++ : ' ';
376 } while (--count > 0);
378 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
380 fib_complete(fibptr);
382 aac_io_done(scsicmd);
386 * aac_get_container_name - get container name, none blocking.
388 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
391 struct aac_get_name *dinfo;
392 struct fib * cmd_fibcontext;
393 struct aac_dev * dev;
395 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
397 if (!(cmd_fibcontext = fib_alloc(dev)))
400 fib_init(cmd_fibcontext);
401 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
403 dinfo->command = cpu_to_le32(VM_ContainerConfig);
404 dinfo->type = cpu_to_le32(CT_READ_NAME);
405 dinfo->cid = cpu_to_le32(cid);
406 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
408 status = fib_send(ContainerCommand,
410 sizeof (struct aac_get_name),
413 (fib_callback) get_container_name_callback,
417 * Check that the command queued to the controller
419 if (status == -EINPROGRESS)
422 printk(KERN_WARNING "aac_get_container_name: fib_send failed with status: %d.\n", status);
423 fib_complete(cmd_fibcontext);
424 fib_free(cmd_fibcontext);
429 * probe_container - query a logical volume
430 * @dev: device to query
431 * @cid: container identifier
433 * Queries the controller about the given volume. The volume information
434 * is updated in the struct fsa_dev_info structure rather than returned.
437 static int probe_container(struct aac_dev *dev, int cid)
439 struct fsa_dev_info *fsa_dev_ptr;
441 struct aac_query_mount *dinfo;
442 struct aac_mount *dresp;
446 fsa_dev_ptr = dev->fsa_dev;
447 instance = dev->scsi_host_ptr->unique_id;
449 if (!(fibptr = fib_alloc(dev)))
454 dinfo = (struct aac_query_mount *)fib_data(fibptr);
456 dinfo->command = cpu_to_le32(VM_NameServe);
457 dinfo->count = cpu_to_le32(cid);
458 dinfo->type = cpu_to_le32(FT_FILESYS);
460 status = fib_send(ContainerCommand,
462 sizeof(struct aac_query_mount),
467 printk(KERN_WARNING "aacraid: probe_container query failed.\n");
471 dresp = (struct aac_mount *) fib_data(fibptr);
473 if ((le32_to_cpu(dresp->status) == ST_OK) &&
474 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
475 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
476 fsa_dev_ptr[cid].valid = 1;
477 fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
478 fsa_dev_ptr[cid].size = le32_to_cpu(dresp->mnt[0].capacity);
479 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
480 fsa_dev_ptr[cid].ro = 1;
484 fib_complete(fibptr);
490 /* Local Structure to set SCSI inquiry data strings */
492 char vid[8]; /* Vendor ID */
493 char pid[16]; /* Product ID */
494 char prl[4]; /* Product Revision Level */
498 * InqStrCopy - string merge
499 * @a: string to copy from
500 * @b: string to copy to
502 * Copy a String from one location to another
506 static void inqstrcpy(char *a, char *b)
513 static char *container_types[] = {
539 /* Function: setinqstr
541 * Arguments: [1] pointer to void [1] int
543 * Purpose: Sets SCSI inquiry data strings for vendor, product
544 * and revision level. Allows strings to be set in platform dependant
545 * files instead of in OS dependant driver source.
548 static void setinqstr(int devtype, void *data, int tindex)
550 struct scsi_inq *str;
551 struct aac_driver_ident *mp;
553 mp = aac_get_driver_ident(devtype);
555 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
557 inqstrcpy (mp->vname, str->vid);
558 inqstrcpy (mp->model, str->pid); /* last six chars reserved for vol type */
560 if (tindex < (sizeof(container_types)/sizeof(char *))){
561 char *findit = str->pid;
563 for ( ; *findit != ' '; findit++); /* walk till we find a space */
564 /* RAID is superfluous in the context of a RAID device */
565 if (memcmp(findit-4, "RAID", 4) == 0)
566 *(findit -= 4) = ' ';
567 inqstrcpy (container_types[tindex], findit + 1);
569 inqstrcpy ("V1.0", str->prl);
572 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
573 u8 a_sense_code, u8 incorrect_length,
574 u8 bit_pointer, u16 field_pointer,
577 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
578 sense_buf[1] = 0; /* Segment number, always zero */
580 if (incorrect_length) {
581 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
582 sense_buf[3] = BYTE3(residue);
583 sense_buf[4] = BYTE2(residue);
584 sense_buf[5] = BYTE1(residue);
585 sense_buf[6] = BYTE0(residue);
587 sense_buf[2] = sense_key; /* Sense key */
589 if (sense_key == ILLEGAL_REQUEST)
590 sense_buf[7] = 10; /* Additional sense length */
592 sense_buf[7] = 6; /* Additional sense length */
594 sense_buf[12] = sense_code; /* Additional sense code */
595 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
596 if (sense_key == ILLEGAL_REQUEST) {
599 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
600 sense_buf[15] = 0x80;/* Std sense key specific field */
601 /* Illegal parameter is in the parameter block */
603 if (sense_code == SENCODE_INVALID_CDB_FIELD)
604 sense_buf[15] = 0xc0;/* Std sense key specific field */
605 /* Illegal parameter is in the CDB block */
606 sense_buf[15] |= bit_pointer;
607 sense_buf[16] = field_pointer >> 8; /* MSB */
608 sense_buf[17] = field_pointer; /* LSB */
612 int aac_get_adapter_info(struct aac_dev* dev)
617 struct aac_adapter_info *info;
618 struct aac_bus_info *command;
619 struct aac_bus_info_response *bus_info;
621 if (!(fibptr = fib_alloc(dev)))
625 info = (struct aac_adapter_info *) fib_data(fibptr);
626 memset(info,0,sizeof(*info));
628 rcode = fib_send(RequestAdapterInfo,
637 fib_complete(fibptr);
641 memcpy(&dev->adapter_info, info, sizeof(*info));
643 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
644 struct aac_supplement_adapter_info * info;
648 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
650 memset(info,0,sizeof(*info));
652 rcode = fib_send(RequestSupplementAdapterInfo,
661 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
671 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
673 memset(bus_info, 0, sizeof(*bus_info));
675 command = (struct aac_bus_info *)bus_info;
677 command->Command = cpu_to_le32(VM_Ioctl);
678 command->ObjType = cpu_to_le32(FT_DRIVE);
679 command->MethodId = cpu_to_le32(1);
680 command->CtlCmd = cpu_to_le32(GetBusInfo);
682 rcode = fib_send(ContainerCommand,
689 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
690 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
691 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
694 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
695 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
701 le32_to_cpu(dev->adapter_info.kernelbuild),
702 (int)sizeof(dev->supplement_adapter_info.BuildDate),
703 dev->supplement_adapter_info.BuildDate);
704 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
705 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
707 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
708 le32_to_cpu(dev->adapter_info.monitorbuild));
709 tmp = le32_to_cpu(dev->adapter_info.biosrev);
710 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
712 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
713 le32_to_cpu(dev->adapter_info.biosbuild));
714 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
715 printk(KERN_INFO "%s%d: serial %x\n",
717 le32_to_cpu(dev->adapter_info.serial[0]));
719 dev->nondasd_support = 0;
720 dev->raid_scsi_mode = 0;
721 if(dev->adapter_info.options & AAC_OPT_NONDASD){
722 dev->nondasd_support = 1;
726 * If the firmware supports ROMB RAID/SCSI mode and we are currently
727 * in RAID/SCSI mode, set the flag. For now if in this mode we will
728 * force nondasd support on. If we decide to allow the non-dasd flag
729 * additional changes changes will have to be made to support
730 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
731 * changed to support the new dev->raid_scsi_mode flag instead of
732 * leaching off of the dev->nondasd_support flag. Also in linit.c the
733 * function aac_detect will have to be modified where it sets up the
734 * max number of channels based on the aac->nondasd_support flag only.
736 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
737 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
738 dev->nondasd_support = 1;
739 dev->raid_scsi_mode = 1;
741 if (dev->raid_scsi_mode != 0)
742 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
746 dev->nondasd_support = (nondasd!=0);
748 if(dev->nondasd_support != 0){
749 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
752 dev->dac_support = 0;
753 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
754 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
755 dev->dac_support = 1;
759 dev->dac_support = (dacmode!=0);
761 if(dev->dac_support != 0) {
762 if (!pci_set_dma_mask(dev->pdev, 0xFFFFFFFFFFFFFFFFULL) &&
763 !pci_set_consistent_dma_mask(dev->pdev, 0xFFFFFFFFFFFFFFFFULL)) {
764 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
766 } else if (!pci_set_dma_mask(dev->pdev, 0xFFFFFFFFULL) &&
767 !pci_set_consistent_dma_mask(dev->pdev, 0xFFFFFFFFULL)) {
768 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
770 dev->dac_support = 0;
772 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
778 * 57 scatter gather elements
780 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
781 sizeof(struct aac_fibhdr) -
782 sizeof(struct aac_write) + sizeof(struct sgmap)) /
783 sizeof(struct sgmap);
784 if (dev->dac_support) {
786 * 38 scatter gather elements
788 dev->scsi_host_ptr->sg_tablesize =
790 sizeof(struct aac_fibhdr) -
791 sizeof(struct aac_write64) +
792 sizeof(struct sgmap64)) /
793 sizeof(struct sgmap64);
795 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
796 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
798 * Worst case size that could cause sg overflow when
799 * we break up SG elements that are larger than 64KB.
800 * Would be nice if we could tell the SCSI layer what
801 * the maximum SG element size can be. Worst case is
802 * (sg_tablesize-1) 4KB elements with one 64KB
804 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
806 dev->scsi_host_ptr->max_sectors =
807 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
810 fib_complete(fibptr);
817 static void read_callback(void *context, struct fib * fibptr)
820 struct aac_read_reply *readreply;
821 struct scsi_cmnd *scsicmd;
825 scsicmd = (struct scsi_cmnd *) context;
827 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
828 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
830 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
831 dprintk((KERN_DEBUG "read_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
837 pci_unmap_sg(dev->pdev,
838 (struct scatterlist *)scsicmd->buffer,
840 scsicmd->sc_data_direction);
841 else if(scsicmd->request_bufflen)
842 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
843 scsicmd->request_bufflen,
844 scsicmd->sc_data_direction);
845 readreply = (struct aac_read_reply *)fib_data(fibptr);
846 if (le32_to_cpu(readreply->status) == ST_OK)
847 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
849 #ifdef AAC_DETAILED_STATUS_INFO
850 printk(KERN_WARNING "read_callback: io failed, status = %d\n",
851 le32_to_cpu(readreply->status));
853 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
854 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
856 SENCODE_INTERNAL_TARGET_FAILURE,
857 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
859 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
860 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
861 ? sizeof(scsicmd->sense_buffer)
862 : sizeof(dev->fsa_dev[cid].sense_data));
864 fib_complete(fibptr);
867 aac_io_done(scsicmd);
870 static void write_callback(void *context, struct fib * fibptr)
873 struct aac_write_reply *writereply;
874 struct scsi_cmnd *scsicmd;
878 scsicmd = (struct scsi_cmnd *) context;
879 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
880 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
882 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
883 dprintk((KERN_DEBUG "write_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
888 pci_unmap_sg(dev->pdev,
889 (struct scatterlist *)scsicmd->buffer,
891 scsicmd->sc_data_direction);
892 else if(scsicmd->request_bufflen)
893 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
894 scsicmd->request_bufflen,
895 scsicmd->sc_data_direction);
897 writereply = (struct aac_write_reply *) fib_data(fibptr);
898 if (le32_to_cpu(writereply->status) == ST_OK)
899 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
901 printk(KERN_WARNING "write_callback: write failed, status = %d\n", writereply->status);
902 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | 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(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
909 sizeof(struct sense_data));
912 fib_complete(fibptr);
914 aac_io_done(scsicmd);
917 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
925 struct fib * cmd_fibcontext;
927 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
929 * Get block address and transfer length
931 if (scsicmd->cmnd[0] == READ_6) /* 6 byte command */
933 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
935 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
936 count = scsicmd->cmnd[4];
941 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
943 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
944 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
946 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %u, t = %ld.\n",
947 smp_processor_id(), (unsigned long long)lba, jiffies));
949 * Alocate and initialize a Fib
951 if (!(cmd_fibcontext = fib_alloc(dev))) {
955 fib_init(cmd_fibcontext);
957 if (dev->dac_support == 1) {
958 struct aac_read64 *readcmd;
959 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
960 readcmd->command = cpu_to_le32(VM_CtHostRead64);
961 readcmd->cid = cpu_to_le16(cid);
962 readcmd->sector_count = cpu_to_le16(count);
963 readcmd->block = cpu_to_le32(lba);
967 aac_build_sg64(scsicmd, &readcmd->sg);
968 fibsize = sizeof(struct aac_read64) +
969 ((le32_to_cpu(readcmd->sg.count) - 1) *
970 sizeof (struct sgentry64));
971 BUG_ON (fibsize > (sizeof(struct hw_fib) -
972 sizeof(struct aac_fibhdr)));
974 * Now send the Fib to the adapter
976 status = fib_send(ContainerCommand64,
981 (fib_callback) read_callback,
984 struct aac_read *readcmd;
985 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
986 readcmd->command = cpu_to_le32(VM_CtBlockRead);
987 readcmd->cid = cpu_to_le32(cid);
988 readcmd->block = cpu_to_le32(lba);
989 readcmd->count = cpu_to_le32(count * 512);
991 aac_build_sg(scsicmd, &readcmd->sg);
992 fibsize = sizeof(struct aac_read) +
993 ((le32_to_cpu(readcmd->sg.count) - 1) *
994 sizeof (struct sgentry));
995 BUG_ON (fibsize > (dev->max_fib_size -
996 sizeof(struct aac_fibhdr)));
998 * Now send the Fib to the adapter
1000 status = fib_send(ContainerCommand,
1005 (fib_callback) read_callback,
1012 * Check that the command queued to the controller
1014 if (status == -EINPROGRESS)
1017 printk(KERN_WARNING "aac_read: fib_send failed with status: %d.\n", status);
1019 * For some reason, the Fib didn't queue, return QUEUE_FULL
1021 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1022 aac_io_done(scsicmd);
1023 fib_complete(cmd_fibcontext);
1024 fib_free(cmd_fibcontext);
1028 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1034 struct aac_dev *dev;
1035 struct fib * cmd_fibcontext;
1037 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1039 * Get block address and transfer length
1041 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1043 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1044 count = scsicmd->cmnd[4];
1048 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
1049 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1050 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1052 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %u, t = %ld.\n",
1053 smp_processor_id(), (unsigned long long)lba, jiffies));
1055 * Allocate and initialize a Fib then setup a BlockWrite command
1057 if (!(cmd_fibcontext = fib_alloc(dev))) {
1058 scsicmd->result = DID_ERROR << 16;
1059 aac_io_done(scsicmd);
1062 fib_init(cmd_fibcontext);
1064 if(dev->dac_support == 1) {
1065 struct aac_write64 *writecmd;
1066 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1067 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1068 writecmd->cid = cpu_to_le16(cid);
1069 writecmd->sector_count = cpu_to_le16(count);
1070 writecmd->block = cpu_to_le32(lba);
1072 writecmd->flags = 0;
1074 aac_build_sg64(scsicmd, &writecmd->sg);
1075 fibsize = sizeof(struct aac_write64) +
1076 ((le32_to_cpu(writecmd->sg.count) - 1) *
1077 sizeof (struct sgentry64));
1078 BUG_ON (fibsize > (dev->max_fib_size -
1079 sizeof(struct aac_fibhdr)));
1081 * Now send the Fib to the adapter
1083 status = fib_send(ContainerCommand64,
1088 (fib_callback) write_callback,
1091 struct aac_write *writecmd;
1092 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
1093 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1094 writecmd->cid = cpu_to_le32(cid);
1095 writecmd->block = cpu_to_le32(lba);
1096 writecmd->count = cpu_to_le32(count * 512);
1097 writecmd->sg.count = cpu_to_le32(1);
1098 /* ->stable is not used - it did mean which type of write */
1100 aac_build_sg(scsicmd, &writecmd->sg);
1101 fibsize = sizeof(struct aac_write) +
1102 ((le32_to_cpu(writecmd->sg.count) - 1) *
1103 sizeof (struct sgentry));
1104 BUG_ON (fibsize > (dev->max_fib_size -
1105 sizeof(struct aac_fibhdr)));
1107 * Now send the Fib to the adapter
1109 status = fib_send(ContainerCommand,
1114 (fib_callback) write_callback,
1119 * Check that the command queued to the controller
1121 if (status == -EINPROGRESS)
1126 printk(KERN_WARNING "aac_write: fib_send failed with status: %d\n", status);
1128 * For some reason, the Fib didn't queue, return QUEUE_FULL
1130 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1131 aac_io_done(scsicmd);
1133 fib_complete(cmd_fibcontext);
1134 fib_free(cmd_fibcontext);
1138 static void synchronize_callback(void *context, struct fib *fibptr)
1140 struct aac_synchronize_reply *synchronizereply;
1141 struct scsi_cmnd *cmd;
1145 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1146 smp_processor_id(), jiffies));
1147 BUG_ON(fibptr == NULL);
1150 synchronizereply = fib_data(fibptr);
1151 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1152 cmd->result = DID_OK << 16 |
1153 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1155 struct scsi_device *sdev = cmd->device;
1156 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1157 u32 cid = ID_LUN_TO_CONTAINER(sdev->id, sdev->lun);
1159 "synchronize_callback: synchronize failed, status = %d\n",
1160 le32_to_cpu(synchronizereply->status));
1161 cmd->result = DID_OK << 16 |
1162 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1163 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1165 SENCODE_INTERNAL_TARGET_FAILURE,
1166 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1168 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1169 min(sizeof(dev->fsa_dev[cid].sense_data),
1170 sizeof(cmd->sense_buffer)));
1173 fib_complete(fibptr);
1178 static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1181 struct fib *cmd_fibcontext;
1182 struct aac_synchronize *synchronizecmd;
1183 struct scsi_cmnd *cmd;
1184 struct scsi_device *sdev = scsicmd->device;
1186 unsigned long flags;
1189 * Wait for all commands to complete to this specific
1192 spin_lock_irqsave(&sdev->list_lock, flags);
1193 list_for_each_entry(cmd, &sdev->cmd_list, list)
1194 if (cmd != scsicmd && cmd->serial_number != 0) {
1199 spin_unlock_irqrestore(&sdev->list_lock, flags);
1202 * Yield the processor (requeue for later)
1205 return SCSI_MLQUEUE_DEVICE_BUSY;
1208 * Allocate and initialize a Fib
1210 if (!(cmd_fibcontext =
1211 fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata)))
1212 return SCSI_MLQUEUE_HOST_BUSY;
1214 fib_init(cmd_fibcontext);
1216 synchronizecmd = fib_data(cmd_fibcontext);
1217 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1218 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1219 synchronizecmd->cid = cpu_to_le32(cid);
1220 synchronizecmd->count =
1221 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1224 * Now send the Fib to the adapter
1226 status = fib_send(ContainerCommand,
1228 sizeof(struct aac_synchronize),
1231 (fib_callback)synchronize_callback,
1235 * Check that the command queued to the controller
1237 if (status == -EINPROGRESS)
1241 "aac_synchronize: fib_send failed with status: %d.\n", status);
1242 fib_complete(cmd_fibcontext);
1243 fib_free(cmd_fibcontext);
1244 return SCSI_MLQUEUE_HOST_BUSY;
1248 * aac_scsi_cmd() - Process SCSI command
1249 * @scsicmd: SCSI command block
1251 * Emulate a SCSI command and queue the required request for the
1255 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1258 struct Scsi_Host *host = scsicmd->device->host;
1259 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1260 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1261 int cardtype = dev->cardtype;
1265 * If the bus, id or lun is out of range, return fail
1266 * Test does not apply to ID 16, the pseudo id for the controller
1269 if (scsicmd->device->id != host->this_id) {
1270 if ((scsicmd->device->channel == 0) ){
1271 if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){
1272 scsicmd->result = DID_NO_CONNECT << 16;
1273 scsicmd->scsi_done(scsicmd);
1276 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
1279 * If the target container doesn't exist, it may have
1280 * been newly created
1282 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1283 switch (scsicmd->cmnd[0]) {
1286 case TEST_UNIT_READY:
1287 spin_unlock_irq(host->host_lock);
1288 probe_container(dev, cid);
1289 spin_lock_irq(host->host_lock);
1290 if (fsa_dev_ptr[cid].valid == 0) {
1291 scsicmd->result = DID_NO_CONNECT << 16;
1292 scsicmd->scsi_done(scsicmd);
1300 * If the target container still doesn't exist,
1303 if (fsa_dev_ptr[cid].valid == 0) {
1304 scsicmd->result = DID_BAD_TARGET << 16;
1305 scsicmd->scsi_done(scsicmd);
1308 } else { /* check for physical non-dasd devices */
1309 if(dev->nondasd_support == 1){
1310 return aac_send_srb_fib(scsicmd);
1312 scsicmd->result = DID_NO_CONNECT << 16;
1313 scsicmd->scsi_done(scsicmd);
1319 * else Command for the controller itself
1321 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1322 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1324 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1325 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1326 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1328 SENCODE_INVALID_COMMAND,
1329 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1330 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1331 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1332 ? sizeof(scsicmd->sense_buffer)
1333 : sizeof(dev->fsa_dev[cid].sense_data));
1334 scsicmd->scsi_done(scsicmd);
1339 /* Handle commands here that don't really require going out to the adapter */
1340 switch (scsicmd->cmnd[0]) {
1343 struct inquiry_data *inq_data_ptr;
1345 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
1346 inq_data_ptr = (struct inquiry_data *)scsicmd->request_buffer;
1347 memset(inq_data_ptr, 0, sizeof (struct inquiry_data));
1349 inq_data_ptr->inqd_ver = 2; /* claim compliance to SCSI-2 */
1350 inq_data_ptr->inqd_dtq = 0x80; /* set RMB bit to one indicating that the medium is removable */
1351 inq_data_ptr->inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
1352 inq_data_ptr->inqd_len = 31;
1353 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1354 inq_data_ptr->inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1356 * Set the Vendor, Product, and Revision Level
1357 * see: <vendor>.c i.e. aac.c
1359 if (scsicmd->device->id == host->this_id) {
1360 setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), (sizeof(container_types)/sizeof(char *)));
1361 inq_data_ptr->inqd_pdt = INQD_PDT_PROC; /* Processor device */
1362 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1363 scsicmd->scsi_done(scsicmd);
1366 setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr[cid].type);
1367 inq_data_ptr->inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1368 return aac_get_container_name(scsicmd, cid);
1375 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1376 if (fsa_dev_ptr[cid].size <= 0x100000000LL)
1377 capacity = fsa_dev_ptr[cid].size - 1;
1380 cp = scsicmd->request_buffer;
1381 cp[0] = (capacity >> 24) & 0xff;
1382 cp[1] = (capacity >> 16) & 0xff;
1383 cp[2] = (capacity >> 8) & 0xff;
1384 cp[3] = (capacity >> 0) & 0xff;
1390 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1391 scsicmd->scsi_done(scsicmd);
1400 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1401 mode_buf = scsicmd->request_buffer;
1402 mode_buf[0] = 3; /* Mode data length */
1403 mode_buf[1] = 0; /* Medium type - default */
1404 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1405 mode_buf[3] = 0; /* Block descriptor length */
1407 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1408 scsicmd->scsi_done(scsicmd);
1416 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1417 mode_buf = scsicmd->request_buffer;
1418 mode_buf[0] = 0; /* Mode data length (MSB) */
1419 mode_buf[1] = 6; /* Mode data length (LSB) */
1420 mode_buf[2] = 0; /* Medium type - default */
1421 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1422 mode_buf[4] = 0; /* reserved */
1423 mode_buf[5] = 0; /* reserved */
1424 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1425 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1427 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1428 scsicmd->scsi_done(scsicmd);
1433 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1434 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1435 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1436 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1437 scsicmd->scsi_done(scsicmd);
1440 case ALLOW_MEDIUM_REMOVAL:
1441 dprintk((KERN_DEBUG "LOCK command.\n"));
1442 if (scsicmd->cmnd[4])
1443 fsa_dev_ptr[cid].locked = 1;
1445 fsa_dev_ptr[cid].locked = 0;
1447 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1448 scsicmd->scsi_done(scsicmd);
1451 * These commands are all No-Ops
1453 case TEST_UNIT_READY:
1457 case REASSIGN_BLOCKS:
1460 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1461 scsicmd->scsi_done(scsicmd);
1465 switch (scsicmd->cmnd[0])
1470 * Hack to keep track of ordinal number of the device that
1471 * corresponds to a container. Needed to convert
1472 * containers to /dev/sd device names
1475 spin_unlock_irq(host->host_lock);
1476 if (scsicmd->request->rq_disk)
1477 memcpy(fsa_dev_ptr[cid].devname,
1478 scsicmd->request->rq_disk->disk_name,
1481 ret = aac_read(scsicmd, cid);
1482 spin_lock_irq(host->host_lock);
1487 spin_unlock_irq(host->host_lock);
1488 ret = aac_write(scsicmd, cid);
1489 spin_lock_irq(host->host_lock);
1492 case SYNCHRONIZE_CACHE:
1493 /* Issue FIB to tell Firmware to flush it's cache */
1494 return aac_synchronize(scsicmd, cid);
1498 * Unhandled commands
1500 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1501 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1502 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1503 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1504 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1505 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1506 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1507 ? sizeof(scsicmd->sense_buffer)
1508 : sizeof(dev->fsa_dev[cid].sense_data));
1509 scsicmd->scsi_done(scsicmd);
1514 static int query_disk(struct aac_dev *dev, void __user *arg)
1516 struct aac_query_disk qd;
1517 struct fsa_dev_info *fsa_dev_ptr;
1519 fsa_dev_ptr = dev->fsa_dev;
1520 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1523 qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
1524 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1526 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1528 qd.instance = dev->scsi_host_ptr->host_no;
1530 qd.id = CONTAINER_TO_ID(qd.cnum);
1531 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1533 else return -EINVAL;
1535 qd.valid = fsa_dev_ptr[qd.cnum].valid;
1536 qd.locked = fsa_dev_ptr[qd.cnum].locked;
1537 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1539 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1544 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1545 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1547 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1552 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1554 struct aac_delete_disk dd;
1555 struct fsa_dev_info *fsa_dev_ptr;
1557 fsa_dev_ptr = dev->fsa_dev;
1559 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1562 if (dd.cnum >= dev->maximum_num_containers)
1565 * Mark this container as being deleted.
1567 fsa_dev_ptr[dd.cnum].deleted = 1;
1569 * Mark the container as no longer valid
1571 fsa_dev_ptr[dd.cnum].valid = 0;
1575 static int delete_disk(struct aac_dev *dev, void __user *arg)
1577 struct aac_delete_disk dd;
1578 struct fsa_dev_info *fsa_dev_ptr;
1580 fsa_dev_ptr = dev->fsa_dev;
1582 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1585 if (dd.cnum >= dev->maximum_num_containers)
1588 * If the container is locked, it can not be deleted by the API.
1590 if (fsa_dev_ptr[dd.cnum].locked)
1594 * Mark the container as no longer being valid.
1596 fsa_dev_ptr[dd.cnum].valid = 0;
1597 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
1602 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1605 case FSACTL_QUERY_DISK:
1606 return query_disk(dev, arg);
1607 case FSACTL_DELETE_DISK:
1608 return delete_disk(dev, arg);
1609 case FSACTL_FORCE_DELETE_DISK:
1610 return force_delete_disk(dev, arg);
1611 case FSACTL_GET_CONTAINERS:
1612 return aac_get_containers(dev);
1621 * @context: the context set in the fib - here it is scsi cmd
1622 * @fibptr: pointer to the fib
1624 * Handles the completion of a scsi command to a non dasd device
1628 static void aac_srb_callback(void *context, struct fib * fibptr)
1630 struct aac_dev *dev;
1631 struct aac_srb_reply *srbreply;
1632 struct scsi_cmnd *scsicmd;
1634 scsicmd = (struct scsi_cmnd *) context;
1635 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1640 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1642 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
1644 * Calculate resid for sg
1647 scsicmd->resid = scsicmd->request_bufflen -
1648 le32_to_cpu(srbreply->data_xfer_length);
1651 pci_unmap_sg(dev->pdev,
1652 (struct scatterlist *)scsicmd->buffer,
1654 scsicmd->sc_data_direction);
1655 else if(scsicmd->request_bufflen)
1656 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
1657 scsicmd->sc_data_direction);
1660 * First check the fib status
1663 if (le32_to_cpu(srbreply->status) != ST_OK){
1665 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1666 len = (le32_to_cpu(srbreply->sense_data_size) >
1667 sizeof(scsicmd->sense_buffer)) ?
1668 sizeof(scsicmd->sense_buffer) :
1669 le32_to_cpu(srbreply->sense_data_size);
1670 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1671 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1675 * Next check the srb status
1677 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1678 case SRB_STATUS_ERROR_RECOVERY:
1679 case SRB_STATUS_PENDING:
1680 case SRB_STATUS_SUCCESS:
1681 if(scsicmd->cmnd[0] == INQUIRY ){
1684 /* We can't expose disk devices because we can't tell whether they
1685 * are the raw container drives or stand alone drives. If they have
1686 * the removable bit set then we should expose them though.
1688 b = (*(u8*)scsicmd->buffer)&0x1f;
1689 b1 = ((u8*)scsicmd->buffer)[1];
1690 if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1691 || (b==TYPE_DISK && (b1&0x80)) ){
1692 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1694 * We will allow disk devices if in RAID/SCSI mode and
1697 } else if ((dev->raid_scsi_mode) &&
1698 (scsicmd->device->channel == 2)) {
1699 scsicmd->result = DID_OK << 16 |
1700 COMMAND_COMPLETE << 8;
1702 scsicmd->result = DID_NO_CONNECT << 16 |
1703 COMMAND_COMPLETE << 8;
1706 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1709 case SRB_STATUS_DATA_OVERRUN:
1710 switch(scsicmd->cmnd[0]){
1717 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1718 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1720 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1722 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1727 /* We can't expose disk devices because we can't tell whether they
1728 * are the raw container drives or stand alone drives
1730 b = (*(u8*)scsicmd->buffer)&0x0f;
1731 b1 = ((u8*)scsicmd->buffer)[1];
1732 if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1733 || (b==TYPE_DISK && (b1&0x80)) ){
1734 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1736 * We will allow disk devices if in RAID/SCSI mode and
1739 } else if ((dev->raid_scsi_mode) &&
1740 (scsicmd->device->channel == 2)) {
1741 scsicmd->result = DID_OK << 16 |
1742 COMMAND_COMPLETE << 8;
1744 scsicmd->result = DID_NO_CONNECT << 16 |
1745 COMMAND_COMPLETE << 8;
1750 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1754 case SRB_STATUS_ABORTED:
1755 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
1757 case SRB_STATUS_ABORT_FAILED:
1758 // Not sure about this one - but assuming the hba was trying to abort for some reason
1759 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
1761 case SRB_STATUS_PARITY_ERROR:
1762 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
1764 case SRB_STATUS_NO_DEVICE:
1765 case SRB_STATUS_INVALID_PATH_ID:
1766 case SRB_STATUS_INVALID_TARGET_ID:
1767 case SRB_STATUS_INVALID_LUN:
1768 case SRB_STATUS_SELECTION_TIMEOUT:
1769 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1772 case SRB_STATUS_COMMAND_TIMEOUT:
1773 case SRB_STATUS_TIMEOUT:
1774 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
1777 case SRB_STATUS_BUSY:
1778 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1781 case SRB_STATUS_BUS_RESET:
1782 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
1785 case SRB_STATUS_MESSAGE_REJECTED:
1786 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
1788 case SRB_STATUS_REQUEST_FLUSHED:
1789 case SRB_STATUS_ERROR:
1790 case SRB_STATUS_INVALID_REQUEST:
1791 case SRB_STATUS_REQUEST_SENSE_FAILED:
1792 case SRB_STATUS_NO_HBA:
1793 case SRB_STATUS_UNEXPECTED_BUS_FREE:
1794 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
1795 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
1796 case SRB_STATUS_DELAYED_RETRY:
1797 case SRB_STATUS_BAD_FUNCTION:
1798 case SRB_STATUS_NOT_STARTED:
1799 case SRB_STATUS_NOT_IN_USE:
1800 case SRB_STATUS_FORCE_ABORT:
1801 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
1803 #ifdef AAC_DETAILED_STATUS_INFO
1804 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
1805 le32_to_cpu(srbreply->srb_status) & 0x3F,
1806 aac_get_status_string(
1807 le32_to_cpu(srbreply->srb_status) & 0x3F),
1809 le32_to_cpu(srbreply->scsi_status));
1811 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1814 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
1816 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
1817 len = (le32_to_cpu(srbreply->sense_data_size) >
1818 sizeof(scsicmd->sense_buffer)) ?
1819 sizeof(scsicmd->sense_buffer) :
1820 le32_to_cpu(srbreply->sense_data_size);
1821 #ifdef AAC_DETAILED_STATUS_INFO
1822 dprintk((KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
1823 le32_to_cpu(srbreply->status), len));
1825 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1829 * OR in the scsi status (already shifted up a bit)
1831 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
1833 fib_complete(fibptr);
1835 aac_io_done(scsicmd);
1841 * @scsicmd: the scsi command block
1843 * This routine will form a FIB and fill in the aac_srb from the
1844 * scsicmd passed in.
1847 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
1849 struct fib* cmd_fibcontext;
1850 struct aac_dev* dev;
1852 struct aac_srb *srbcmd;
1857 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1858 if (scsicmd->device->id >= dev->maximum_num_physicals ||
1859 scsicmd->device->lun > 7) {
1860 scsicmd->result = DID_NO_CONNECT << 16;
1861 scsicmd->scsi_done(scsicmd);
1865 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1866 switch(scsicmd->sc_data_direction){
1870 case DMA_BIDIRECTIONAL:
1871 flag = SRB_DataIn | SRB_DataOut;
1873 case DMA_FROM_DEVICE:
1877 default: /* shuts up some versions of gcc */
1878 flag = SRB_NoDataXfer;
1884 * Allocate and initialize a Fib then setup a BlockWrite command
1886 if (!(cmd_fibcontext = fib_alloc(dev))) {
1889 fib_init(cmd_fibcontext);
1891 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
1892 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1893 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel));
1894 srbcmd->id = cpu_to_le32(scsicmd->device->id);
1895 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
1896 srbcmd->flags = cpu_to_le32(flag);
1897 timeout = (scsicmd->timeout-jiffies)/HZ;
1901 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1902 srbcmd->retry_limit = 0; /* Obsolete parameter */
1903 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
1905 if( dev->dac_support == 1 ) {
1906 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
1907 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1909 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1910 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1912 * Build Scatter/Gather list
1914 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1915 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1916 sizeof (struct sgentry64));
1917 BUG_ON (fibsize > (dev->max_fib_size -
1918 sizeof(struct aac_fibhdr)));
1921 * Now send the Fib to the adapter
1923 status = fib_send(ScsiPortCommand64, cmd_fibcontext,
1924 fibsize, FsaNormal, 0, 1,
1925 (fib_callback) aac_srb_callback,
1928 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
1929 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1931 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1932 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1934 * Build Scatter/Gather list
1936 fibsize = sizeof (struct aac_srb) +
1937 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1938 sizeof (struct sgentry));
1939 BUG_ON (fibsize > (dev->max_fib_size -
1940 sizeof(struct aac_fibhdr)));
1943 * Now send the Fib to the adapter
1945 status = fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
1946 (fib_callback) aac_srb_callback, (void *) scsicmd);
1949 * Check that the command queued to the controller
1951 if (status == -EINPROGRESS){
1955 printk(KERN_WARNING "aac_srb: fib_send failed with status: %d\n", status);
1956 fib_complete(cmd_fibcontext);
1957 fib_free(cmd_fibcontext);
1962 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
1964 struct aac_dev *dev;
1965 unsigned long byte_count = 0;
1967 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1968 // Get rid of old data
1970 psg->sg[0].addr = 0;
1971 psg->sg[0].count = 0;
1972 if (scsicmd->use_sg) {
1973 struct scatterlist *sg;
1976 sg = (struct scatterlist *) scsicmd->request_buffer;
1978 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
1979 scsicmd->sc_data_direction);
1980 psg->count = cpu_to_le32(sg_count);
1984 for (i = 0; i < sg_count; i++) {
1985 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
1986 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
1987 byte_count += sg_dma_len(sg);
1990 /* hba wants the size to be exact */
1991 if(byte_count > scsicmd->request_bufflen){
1992 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
1993 (byte_count - scsicmd->request_bufflen);
1994 psg->sg[i-1].count = cpu_to_le32(temp);
1995 byte_count = scsicmd->request_bufflen;
1997 /* Check for command underflow */
1998 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
1999 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2000 byte_count, scsicmd->underflow);
2003 else if(scsicmd->request_bufflen) {
2005 addr = pci_map_single(dev->pdev,
2006 scsicmd->request_buffer,
2007 scsicmd->request_bufflen,
2008 scsicmd->sc_data_direction);
2009 psg->count = cpu_to_le32(1);
2010 psg->sg[0].addr = cpu_to_le32(addr);
2011 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2012 scsicmd->SCp.dma_handle = addr;
2013 byte_count = scsicmd->request_bufflen;
2019 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2021 struct aac_dev *dev;
2022 unsigned long byte_count = 0;
2025 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2026 // Get rid of old data
2028 psg->sg[0].addr[0] = 0;
2029 psg->sg[0].addr[1] = 0;
2030 psg->sg[0].count = 0;
2031 if (scsicmd->use_sg) {
2032 struct scatterlist *sg;
2035 sg = (struct scatterlist *) scsicmd->request_buffer;
2037 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2038 scsicmd->sc_data_direction);
2039 psg->count = cpu_to_le32(sg_count);
2043 for (i = 0; i < sg_count; i++) {
2044 addr = sg_dma_address(sg);
2045 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2046 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2047 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2048 byte_count += sg_dma_len(sg);
2051 /* hba wants the size to be exact */
2052 if(byte_count > scsicmd->request_bufflen){
2053 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2054 (byte_count - scsicmd->request_bufflen);
2055 psg->sg[i-1].count = cpu_to_le32(temp);
2056 byte_count = scsicmd->request_bufflen;
2058 /* Check for command underflow */
2059 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2060 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2061 byte_count, scsicmd->underflow);
2064 else if(scsicmd->request_bufflen) {
2066 addr = pci_map_single(dev->pdev,
2067 scsicmd->request_buffer,
2068 scsicmd->request_bufflen,
2069 scsicmd->sc_data_direction);
2070 psg->count = cpu_to_le32(1);
2071 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2072 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2073 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2074 scsicmd->SCp.dma_handle = addr;
2075 byte_count = scsicmd->request_bufflen;
2080 #ifdef AAC_DETAILED_STATUS_INFO
2082 struct aac_srb_status_info {
2088 static struct aac_srb_status_info srb_status_info[] = {
2089 { SRB_STATUS_PENDING, "Pending Status"},
2090 { SRB_STATUS_SUCCESS, "Success"},
2091 { SRB_STATUS_ABORTED, "Aborted Command"},
2092 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2093 { SRB_STATUS_ERROR, "Error Event"},
2094 { SRB_STATUS_BUSY, "Device Busy"},
2095 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2096 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2097 { SRB_STATUS_NO_DEVICE, "No Device"},
2098 { SRB_STATUS_TIMEOUT, "Timeout"},
2099 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2100 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2101 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2102 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2103 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2104 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2105 { SRB_STATUS_NO_HBA, "No HBA"},
2106 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2107 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2108 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2109 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2110 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2111 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2112 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2113 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2114 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2115 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2116 { SRB_STATUS_NOT_STARTED, "Not Started"},
2117 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2118 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2119 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2120 { 0xff, "Unknown Error"}
2123 char *aac_get_status_string(u32 status)
2127 for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
2128 if(srb_status_info[i].status == status){
2129 return srb_status_info[i].str;
2133 return "Bad Status Code";