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 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 dacmode = -1;
149 static int commit = -1;
151 module_param(nondasd, int, 0);
152 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
153 module_param(dacmode, int, 0);
154 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
155 module_param(commit, int, 0);
156 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");
159 module_param(numacb, int, S_IRUGO|S_IWUSR);
160 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.");
163 module_param(acbsize, int, S_IRUGO|S_IWUSR);
164 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.");
166 * aac_get_config_status - check the adapter configuration
167 * @common: adapter to query
169 * Query config status, and commit the configuration if needed.
171 int aac_get_config_status(struct aac_dev *dev)
176 if (!(fibptr = fib_alloc(dev)))
181 struct aac_get_config_status *dinfo;
182 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
184 dinfo->command = cpu_to_le32(VM_ContainerConfig);
185 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
186 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
189 status = fib_send(ContainerCommand,
191 sizeof (struct aac_get_config_status),
196 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
198 struct aac_get_config_status_resp *reply
199 = (struct aac_get_config_status_resp *) fib_data(fibptr);
200 dprintk((KERN_WARNING
201 "aac_get_config_status: response=%d status=%d action=%d\n",
202 le32_to_cpu(reply->response),
203 le32_to_cpu(reply->status),
204 le32_to_cpu(reply->data.action)));
205 if ((le32_to_cpu(reply->response) != ST_OK) ||
206 (le32_to_cpu(reply->status) != CT_OK) ||
207 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
208 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
212 fib_complete(fibptr);
213 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
216 struct aac_commit_config * dinfo;
218 dinfo = (struct aac_commit_config *) fib_data(fibptr);
220 dinfo->command = cpu_to_le32(VM_ContainerConfig);
221 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
223 status = fib_send(ContainerCommand,
225 sizeof (struct aac_commit_config),
229 fib_complete(fibptr);
230 } else if (commit == 0) {
232 "aac_get_config_status: Foreign device configurations are being ignored\n");
240 * aac_get_containers - list containers
241 * @common: adapter to probe
243 * Make a list of all containers on this controller
245 int aac_get_containers(struct aac_dev *dev)
247 struct fsa_dev_info *fsa_dev_ptr;
252 struct aac_get_container_count *dinfo;
253 struct aac_get_container_count_resp *dresp;
254 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
256 instance = dev->scsi_host_ptr->unique_id;
258 if (!(fibptr = fib_alloc(dev)))
262 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
263 dinfo->command = cpu_to_le32(VM_ContainerConfig);
264 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
266 status = fib_send(ContainerCommand,
268 sizeof (struct aac_get_container_count),
273 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
274 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
275 fib_complete(fibptr);
278 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
279 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
280 fsa_dev_ptr = (struct fsa_dev_info *) kmalloc(
281 sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL);
286 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
288 dev->fsa_dev = fsa_dev_ptr;
289 dev->maximum_num_containers = maximum_num_containers;
291 for (index = 0; index < dev->maximum_num_containers; index++) {
292 struct aac_query_mount *dinfo;
293 struct aac_mount *dresp;
295 fsa_dev_ptr[index].devname[0] = '\0';
298 dinfo = (struct aac_query_mount *) fib_data(fibptr);
300 dinfo->command = cpu_to_le32(VM_NameServe);
301 dinfo->count = cpu_to_le32(index);
302 dinfo->type = cpu_to_le32(FT_FILESYS);
304 status = fib_send(ContainerCommand,
306 sizeof (struct aac_query_mount),
311 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
314 dresp = (struct aac_mount *)fib_data(fibptr);
317 "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%u\n",
318 (int)index, (int)le32_to_cpu(dresp->status),
319 (int)le32_to_cpu(dresp->mnt[0].vol),
320 (int)le32_to_cpu(dresp->mnt[0].state),
321 (unsigned)le32_to_cpu(dresp->mnt[0].capacity)));
322 if ((le32_to_cpu(dresp->status) == ST_OK) &&
323 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
324 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
325 fsa_dev_ptr[index].valid = 1;
326 fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
327 fsa_dev_ptr[index].size = le32_to_cpu(dresp->mnt[0].capacity);
328 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
329 fsa_dev_ptr[index].ro = 1;
331 fib_complete(fibptr);
333 * If there are no more containers, then stop asking.
335 if ((index + 1) >= le32_to_cpu(dresp->count)){
343 static void aac_io_done(struct scsi_cmnd * scsicmd)
345 unsigned long cpu_flags;
346 struct Scsi_Host *host = scsicmd->device->host;
347 spin_lock_irqsave(host->host_lock, cpu_flags);
348 scsicmd->scsi_done(scsicmd);
349 spin_unlock_irqrestore(host->host_lock, cpu_flags);
352 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
355 unsigned int transfer_len;
356 struct scatterlist *sg = scsicmd->request_buffer;
358 if (scsicmd->use_sg) {
359 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
360 transfer_len = min(sg->length, len + offset);
362 buf = scsicmd->request_buffer;
363 transfer_len = min(scsicmd->request_bufflen, len + offset);
366 memcpy(buf + offset, data, transfer_len - offset);
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 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
384 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
385 /* Failure is irrelevant, using default value instead */
386 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
387 && (get_name_reply->data[0] != '\0')) {
388 char *sp = get_name_reply->data;
389 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
393 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
394 int count = sizeof(d);
397 *dp++ = (*sp) ? *sp++ : ' ';
398 } while (--count > 0);
399 aac_internal_transfer(scsicmd, d,
400 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
404 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
406 fib_complete(fibptr);
408 aac_io_done(scsicmd);
412 * aac_get_container_name - get container name, none blocking.
414 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
417 struct aac_get_name *dinfo;
418 struct fib * cmd_fibcontext;
419 struct aac_dev * dev;
421 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
423 if (!(cmd_fibcontext = fib_alloc(dev)))
426 fib_init(cmd_fibcontext);
427 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
429 dinfo->command = cpu_to_le32(VM_ContainerConfig);
430 dinfo->type = cpu_to_le32(CT_READ_NAME);
431 dinfo->cid = cpu_to_le32(cid);
432 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
434 status = fib_send(ContainerCommand,
436 sizeof (struct aac_get_name),
439 (fib_callback) get_container_name_callback,
443 * Check that the command queued to the controller
445 if (status == -EINPROGRESS)
448 printk(KERN_WARNING "aac_get_container_name: fib_send failed with status: %d.\n", status);
449 fib_complete(cmd_fibcontext);
450 fib_free(cmd_fibcontext);
455 * probe_container - query a logical volume
456 * @dev: device to query
457 * @cid: container identifier
459 * Queries the controller about the given volume. The volume information
460 * is updated in the struct fsa_dev_info structure rather than returned.
463 static int probe_container(struct aac_dev *dev, int cid)
465 struct fsa_dev_info *fsa_dev_ptr;
467 struct aac_query_mount *dinfo;
468 struct aac_mount *dresp;
472 fsa_dev_ptr = dev->fsa_dev;
473 instance = dev->scsi_host_ptr->unique_id;
475 if (!(fibptr = fib_alloc(dev)))
480 dinfo = (struct aac_query_mount *)fib_data(fibptr);
482 dinfo->command = cpu_to_le32(VM_NameServe);
483 dinfo->count = cpu_to_le32(cid);
484 dinfo->type = cpu_to_le32(FT_FILESYS);
486 status = fib_send(ContainerCommand,
488 sizeof(struct aac_query_mount),
493 printk(KERN_WARNING "aacraid: probe_container query failed.\n");
497 dresp = (struct aac_mount *) fib_data(fibptr);
499 if ((le32_to_cpu(dresp->status) == ST_OK) &&
500 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
501 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
502 fsa_dev_ptr[cid].valid = 1;
503 fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
504 fsa_dev_ptr[cid].size = le32_to_cpu(dresp->mnt[0].capacity);
505 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
506 fsa_dev_ptr[cid].ro = 1;
510 fib_complete(fibptr);
516 /* Local Structure to set SCSI inquiry data strings */
518 char vid[8]; /* Vendor ID */
519 char pid[16]; /* Product ID */
520 char prl[4]; /* Product Revision Level */
524 * InqStrCopy - string merge
525 * @a: string to copy from
526 * @b: string to copy to
528 * Copy a String from one location to another
532 static void inqstrcpy(char *a, char *b)
539 static char *container_types[] = {
565 /* Function: setinqstr
567 * Arguments: [1] pointer to void [1] int
569 * Purpose: Sets SCSI inquiry data strings for vendor, product
570 * and revision level. Allows strings to be set in platform dependant
571 * files instead of in OS dependant driver source.
574 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
576 struct scsi_inq *str;
578 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
579 memset(str, ' ', sizeof(*str));
581 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
582 char * cp = dev->supplement_adapter_info.AdapterTypeText;
583 int c = sizeof(str->vid);
584 while (*cp && *cp != ' ' && --c)
588 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
591 while (*cp && *cp != ' ')
595 /* last six chars reserved for vol type */
597 if (strlen(cp) > sizeof(str->pid)) {
598 c = cp[sizeof(str->pid)];
599 cp[sizeof(str->pid)] = '\0';
601 inqstrcpy (cp, str->pid);
603 cp[sizeof(str->pid)] = c;
605 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
607 inqstrcpy (mp->vname, str->vid);
608 /* last six chars reserved for vol type */
609 inqstrcpy (mp->model, str->pid);
612 if (tindex < (sizeof(container_types)/sizeof(char *))){
613 char *findit = str->pid;
615 for ( ; *findit != ' '; findit++); /* walk till we find a space */
616 /* RAID is superfluous in the context of a RAID device */
617 if (memcmp(findit-4, "RAID", 4) == 0)
618 *(findit -= 4) = ' ';
619 if (((findit - str->pid) + strlen(container_types[tindex]))
620 < (sizeof(str->pid) + sizeof(str->prl)))
621 inqstrcpy (container_types[tindex], findit + 1);
623 inqstrcpy ("V1.0", str->prl);
626 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
627 u8 a_sense_code, u8 incorrect_length,
628 u8 bit_pointer, u16 field_pointer,
631 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
632 sense_buf[1] = 0; /* Segment number, always zero */
634 if (incorrect_length) {
635 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
636 sense_buf[3] = BYTE3(residue);
637 sense_buf[4] = BYTE2(residue);
638 sense_buf[5] = BYTE1(residue);
639 sense_buf[6] = BYTE0(residue);
641 sense_buf[2] = sense_key; /* Sense key */
643 if (sense_key == ILLEGAL_REQUEST)
644 sense_buf[7] = 10; /* Additional sense length */
646 sense_buf[7] = 6; /* Additional sense length */
648 sense_buf[12] = sense_code; /* Additional sense code */
649 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
650 if (sense_key == ILLEGAL_REQUEST) {
653 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
654 sense_buf[15] = 0x80;/* Std sense key specific field */
655 /* Illegal parameter is in the parameter block */
657 if (sense_code == SENCODE_INVALID_CDB_FIELD)
658 sense_buf[15] = 0xc0;/* Std sense key specific field */
659 /* Illegal parameter is in the CDB block */
660 sense_buf[15] |= bit_pointer;
661 sense_buf[16] = field_pointer >> 8; /* MSB */
662 sense_buf[17] = field_pointer; /* LSB */
666 int aac_get_adapter_info(struct aac_dev* dev)
671 struct aac_adapter_info *info;
672 struct aac_bus_info *command;
673 struct aac_bus_info_response *bus_info;
675 if (!(fibptr = fib_alloc(dev)))
679 info = (struct aac_adapter_info *) fib_data(fibptr);
680 memset(info,0,sizeof(*info));
682 rcode = fib_send(RequestAdapterInfo,
691 fib_complete(fibptr);
695 memcpy(&dev->adapter_info, info, sizeof(*info));
697 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
698 struct aac_supplement_adapter_info * info;
702 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
704 memset(info,0,sizeof(*info));
706 rcode = fib_send(RequestSupplementAdapterInfo,
715 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
725 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
727 memset(bus_info, 0, sizeof(*bus_info));
729 command = (struct aac_bus_info *)bus_info;
731 command->Command = cpu_to_le32(VM_Ioctl);
732 command->ObjType = cpu_to_le32(FT_DRIVE);
733 command->MethodId = cpu_to_le32(1);
734 command->CtlCmd = cpu_to_le32(GetBusInfo);
736 rcode = fib_send(ContainerCommand,
743 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
744 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
745 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
748 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
749 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
755 le32_to_cpu(dev->adapter_info.kernelbuild),
756 (int)sizeof(dev->supplement_adapter_info.BuildDate),
757 dev->supplement_adapter_info.BuildDate);
758 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
759 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
761 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
762 le32_to_cpu(dev->adapter_info.monitorbuild));
763 tmp = le32_to_cpu(dev->adapter_info.biosrev);
764 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
766 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
767 le32_to_cpu(dev->adapter_info.biosbuild));
768 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
769 printk(KERN_INFO "%s%d: serial %x\n",
771 le32_to_cpu(dev->adapter_info.serial[0]));
773 dev->nondasd_support = 0;
774 dev->raid_scsi_mode = 0;
775 if(dev->adapter_info.options & AAC_OPT_NONDASD){
776 dev->nondasd_support = 1;
780 * If the firmware supports ROMB RAID/SCSI mode and we are currently
781 * in RAID/SCSI mode, set the flag. For now if in this mode we will
782 * force nondasd support on. If we decide to allow the non-dasd flag
783 * additional changes changes will have to be made to support
784 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
785 * changed to support the new dev->raid_scsi_mode flag instead of
786 * leaching off of the dev->nondasd_support flag. Also in linit.c the
787 * function aac_detect will have to be modified where it sets up the
788 * max number of channels based on the aac->nondasd_support flag only.
790 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
791 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
792 dev->nondasd_support = 1;
793 dev->raid_scsi_mode = 1;
795 if (dev->raid_scsi_mode != 0)
796 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
800 dev->nondasd_support = (nondasd!=0);
802 if(dev->nondasd_support != 0){
803 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
806 dev->dac_support = 0;
807 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
808 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
809 dev->dac_support = 1;
813 dev->dac_support = (dacmode!=0);
815 if(dev->dac_support != 0) {
816 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
817 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
818 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
820 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
821 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
822 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
824 dev->dac_support = 0;
826 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
832 * 57 scatter gather elements
834 if (!(dev->raw_io_interface)) {
835 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
836 sizeof(struct aac_fibhdr) -
837 sizeof(struct aac_write) + sizeof(struct sgmap)) /
838 sizeof(struct sgmap);
839 if (dev->dac_support) {
841 * 38 scatter gather elements
843 dev->scsi_host_ptr->sg_tablesize =
845 sizeof(struct aac_fibhdr) -
846 sizeof(struct aac_write64) +
847 sizeof(struct sgmap64)) /
848 sizeof(struct sgmap64);
850 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
851 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
853 * Worst case size that could cause sg overflow when
854 * we break up SG elements that are larger than 64KB.
855 * Would be nice if we could tell the SCSI layer what
856 * the maximum SG element size can be. Worst case is
857 * (sg_tablesize-1) 4KB elements with one 64KB
859 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
861 dev->scsi_host_ptr->max_sectors =
862 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
866 fib_complete(fibptr);
873 static void io_callback(void *context, struct fib * fibptr)
876 struct aac_read_reply *readreply;
877 struct scsi_cmnd *scsicmd;
880 scsicmd = (struct scsi_cmnd *) context;
882 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
883 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
885 dprintk((KERN_DEBUG "io_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3], jiffies));
891 pci_unmap_sg(dev->pdev,
892 (struct scatterlist *)scsicmd->buffer,
894 scsicmd->sc_data_direction);
895 else if(scsicmd->request_bufflen)
896 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
897 scsicmd->request_bufflen,
898 scsicmd->sc_data_direction);
899 readreply = (struct aac_read_reply *)fib_data(fibptr);
900 if (le32_to_cpu(readreply->status) == ST_OK)
901 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
903 #ifdef AAC_DETAILED_STATUS_INFO
904 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
905 le32_to_cpu(readreply->status));
907 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
908 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
910 SENCODE_INTERNAL_TARGET_FAILURE,
911 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
913 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
914 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
915 ? sizeof(scsicmd->sense_buffer)
916 : sizeof(dev->fsa_dev[cid].sense_data));
918 fib_complete(fibptr);
921 aac_io_done(scsicmd);
924 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
932 struct fib * cmd_fibcontext;
934 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
936 * Get block address and transfer length
938 if (scsicmd->cmnd[0] == READ_6) /* 6 byte command */
940 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
942 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
943 count = scsicmd->cmnd[4];
948 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
950 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
951 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
953 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %u, t = %ld.\n",
954 smp_processor_id(), (unsigned long long)lba, jiffies));
956 * Alocate and initialize a Fib
958 if (!(cmd_fibcontext = fib_alloc(dev))) {
962 fib_init(cmd_fibcontext);
964 if (dev->raw_io_interface) {
965 struct aac_raw_io *readcmd;
966 readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
967 readcmd->block[0] = cpu_to_le32(lba);
968 readcmd->block[1] = 0;
969 readcmd->count = cpu_to_le32(count<<9);
970 readcmd->cid = cpu_to_le16(cid);
971 readcmd->flags = cpu_to_le16(1);
972 readcmd->bpTotal = 0;
973 readcmd->bpComplete = 0;
975 aac_build_sgraw(scsicmd, &readcmd->sg);
976 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
977 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
980 * Now send the Fib to the adapter
982 status = fib_send(ContainerRawIo,
987 (fib_callback) io_callback,
989 } else if (dev->dac_support == 1) {
990 struct aac_read64 *readcmd;
991 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
992 readcmd->command = cpu_to_le32(VM_CtHostRead64);
993 readcmd->cid = cpu_to_le16(cid);
994 readcmd->sector_count = cpu_to_le16(count);
995 readcmd->block = cpu_to_le32(lba);
999 aac_build_sg64(scsicmd, &readcmd->sg);
1000 fibsize = sizeof(struct aac_read64) +
1001 ((le32_to_cpu(readcmd->sg.count) - 1) *
1002 sizeof (struct sgentry64));
1003 BUG_ON (fibsize > (dev->max_fib_size -
1004 sizeof(struct aac_fibhdr)));
1006 * Now send the Fib to the adapter
1008 status = fib_send(ContainerCommand64,
1013 (fib_callback) io_callback,
1016 struct aac_read *readcmd;
1017 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
1018 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1019 readcmd->cid = cpu_to_le32(cid);
1020 readcmd->block = cpu_to_le32(lba);
1021 readcmd->count = cpu_to_le32(count * 512);
1023 aac_build_sg(scsicmd, &readcmd->sg);
1024 fibsize = sizeof(struct aac_read) +
1025 ((le32_to_cpu(readcmd->sg.count) - 1) *
1026 sizeof (struct sgentry));
1027 BUG_ON (fibsize > (dev->max_fib_size -
1028 sizeof(struct aac_fibhdr)));
1030 * Now send the Fib to the adapter
1032 status = fib_send(ContainerCommand,
1037 (fib_callback) io_callback,
1044 * Check that the command queued to the controller
1046 if (status == -EINPROGRESS)
1049 printk(KERN_WARNING "aac_read: fib_send failed with status: %d.\n", status);
1051 * For some reason, the Fib didn't queue, return QUEUE_FULL
1053 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1054 aac_io_done(scsicmd);
1055 fib_complete(cmd_fibcontext);
1056 fib_free(cmd_fibcontext);
1060 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1066 struct aac_dev *dev;
1067 struct fib * cmd_fibcontext;
1069 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1071 * Get block address and transfer length
1073 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1075 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1076 count = scsicmd->cmnd[4];
1080 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
1081 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1082 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1084 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %u, t = %ld.\n",
1085 smp_processor_id(), (unsigned long long)lba, jiffies));
1087 * Allocate and initialize a Fib then setup a BlockWrite command
1089 if (!(cmd_fibcontext = fib_alloc(dev))) {
1090 scsicmd->result = DID_ERROR << 16;
1091 aac_io_done(scsicmd);
1094 fib_init(cmd_fibcontext);
1096 if (dev->raw_io_interface) {
1097 struct aac_raw_io *writecmd;
1098 writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1099 writecmd->block[0] = cpu_to_le32(lba);
1100 writecmd->block[1] = 0;
1101 writecmd->count = cpu_to_le32(count<<9);
1102 writecmd->cid = cpu_to_le16(cid);
1103 writecmd->flags = 0;
1104 writecmd->bpTotal = 0;
1105 writecmd->bpComplete = 0;
1107 aac_build_sgraw(scsicmd, &writecmd->sg);
1108 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1109 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1112 * Now send the Fib to the adapter
1114 status = fib_send(ContainerRawIo,
1119 (fib_callback) io_callback,
1121 } else if (dev->dac_support == 1) {
1122 struct aac_write64 *writecmd;
1123 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1124 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1125 writecmd->cid = cpu_to_le16(cid);
1126 writecmd->sector_count = cpu_to_le16(count);
1127 writecmd->block = cpu_to_le32(lba);
1129 writecmd->flags = 0;
1131 aac_build_sg64(scsicmd, &writecmd->sg);
1132 fibsize = sizeof(struct aac_write64) +
1133 ((le32_to_cpu(writecmd->sg.count) - 1) *
1134 sizeof (struct sgentry64));
1135 BUG_ON (fibsize > (dev->max_fib_size -
1136 sizeof(struct aac_fibhdr)));
1138 * Now send the Fib to the adapter
1140 status = fib_send(ContainerCommand64,
1145 (fib_callback) io_callback,
1148 struct aac_write *writecmd;
1149 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
1150 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1151 writecmd->cid = cpu_to_le32(cid);
1152 writecmd->block = cpu_to_le32(lba);
1153 writecmd->count = cpu_to_le32(count * 512);
1154 writecmd->sg.count = cpu_to_le32(1);
1155 /* ->stable is not used - it did mean which type of write */
1157 aac_build_sg(scsicmd, &writecmd->sg);
1158 fibsize = sizeof(struct aac_write) +
1159 ((le32_to_cpu(writecmd->sg.count) - 1) *
1160 sizeof (struct sgentry));
1161 BUG_ON (fibsize > (dev->max_fib_size -
1162 sizeof(struct aac_fibhdr)));
1164 * Now send the Fib to the adapter
1166 status = fib_send(ContainerCommand,
1171 (fib_callback) io_callback,
1176 * Check that the command queued to the controller
1178 if (status == -EINPROGRESS)
1183 printk(KERN_WARNING "aac_write: fib_send failed with status: %d\n", status);
1185 * For some reason, the Fib didn't queue, return QUEUE_FULL
1187 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1188 aac_io_done(scsicmd);
1190 fib_complete(cmd_fibcontext);
1191 fib_free(cmd_fibcontext);
1195 static void synchronize_callback(void *context, struct fib *fibptr)
1197 struct aac_synchronize_reply *synchronizereply;
1198 struct scsi_cmnd *cmd;
1202 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1203 smp_processor_id(), jiffies));
1204 BUG_ON(fibptr == NULL);
1207 synchronizereply = fib_data(fibptr);
1208 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1209 cmd->result = DID_OK << 16 |
1210 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1212 struct scsi_device *sdev = cmd->device;
1213 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1214 u32 cid = ID_LUN_TO_CONTAINER(sdev->id, sdev->lun);
1216 "synchronize_callback: synchronize failed, status = %d\n",
1217 le32_to_cpu(synchronizereply->status));
1218 cmd->result = DID_OK << 16 |
1219 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1220 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1222 SENCODE_INTERNAL_TARGET_FAILURE,
1223 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1225 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1226 min(sizeof(dev->fsa_dev[cid].sense_data),
1227 sizeof(cmd->sense_buffer)));
1230 fib_complete(fibptr);
1235 static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1238 struct fib *cmd_fibcontext;
1239 struct aac_synchronize *synchronizecmd;
1240 struct scsi_cmnd *cmd;
1241 struct scsi_device *sdev = scsicmd->device;
1243 unsigned long flags;
1246 * Wait for all commands to complete to this specific
1249 spin_lock_irqsave(&sdev->list_lock, flags);
1250 list_for_each_entry(cmd, &sdev->cmd_list, list)
1251 if (cmd != scsicmd && cmd->serial_number != 0) {
1256 spin_unlock_irqrestore(&sdev->list_lock, flags);
1259 * Yield the processor (requeue for later)
1262 return SCSI_MLQUEUE_DEVICE_BUSY;
1265 * Allocate and initialize a Fib
1267 if (!(cmd_fibcontext =
1268 fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata)))
1269 return SCSI_MLQUEUE_HOST_BUSY;
1271 fib_init(cmd_fibcontext);
1273 synchronizecmd = fib_data(cmd_fibcontext);
1274 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1275 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1276 synchronizecmd->cid = cpu_to_le32(cid);
1277 synchronizecmd->count =
1278 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1281 * Now send the Fib to the adapter
1283 status = fib_send(ContainerCommand,
1285 sizeof(struct aac_synchronize),
1288 (fib_callback)synchronize_callback,
1292 * Check that the command queued to the controller
1294 if (status == -EINPROGRESS)
1298 "aac_synchronize: fib_send failed with status: %d.\n", status);
1299 fib_complete(cmd_fibcontext);
1300 fib_free(cmd_fibcontext);
1301 return SCSI_MLQUEUE_HOST_BUSY;
1305 * aac_scsi_cmd() - Process SCSI command
1306 * @scsicmd: SCSI command block
1308 * Emulate a SCSI command and queue the required request for the
1312 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1315 struct Scsi_Host *host = scsicmd->device->host;
1316 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1317 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1321 * If the bus, id or lun is out of range, return fail
1322 * Test does not apply to ID 16, the pseudo id for the controller
1325 if (scsicmd->device->id != host->this_id) {
1326 if ((scsicmd->device->channel == 0) ){
1327 if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){
1328 scsicmd->result = DID_NO_CONNECT << 16;
1329 scsicmd->scsi_done(scsicmd);
1332 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
1335 * If the target container doesn't exist, it may have
1336 * been newly created
1338 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1339 switch (scsicmd->cmnd[0]) {
1342 case TEST_UNIT_READY:
1343 spin_unlock_irq(host->host_lock);
1344 probe_container(dev, cid);
1345 spin_lock_irq(host->host_lock);
1346 if (fsa_dev_ptr[cid].valid == 0) {
1347 scsicmd->result = DID_NO_CONNECT << 16;
1348 scsicmd->scsi_done(scsicmd);
1356 * If the target container still doesn't exist,
1359 if (fsa_dev_ptr[cid].valid == 0) {
1360 scsicmd->result = DID_BAD_TARGET << 16;
1361 scsicmd->scsi_done(scsicmd);
1364 } else { /* check for physical non-dasd devices */
1365 if(dev->nondasd_support == 1){
1366 return aac_send_srb_fib(scsicmd);
1368 scsicmd->result = DID_NO_CONNECT << 16;
1369 scsicmd->scsi_done(scsicmd);
1375 * else Command for the controller itself
1377 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1378 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1380 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1381 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1382 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1384 SENCODE_INVALID_COMMAND,
1385 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1386 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1387 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1388 ? sizeof(scsicmd->sense_buffer)
1389 : sizeof(dev->fsa_dev[cid].sense_data));
1390 scsicmd->scsi_done(scsicmd);
1395 /* Handle commands here that don't really require going out to the adapter */
1396 switch (scsicmd->cmnd[0]) {
1399 struct inquiry_data inq_data;
1401 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
1402 memset(&inq_data, 0, sizeof (struct inquiry_data));
1404 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1405 inq_data.inqd_dtq = 0x80; /* set RMB bit to one indicating that the medium is removable */
1406 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 */
1407 inq_data.inqd_len = 31;
1408 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1409 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1411 * Set the Vendor, Product, and Revision Level
1412 * see: <vendor>.c i.e. aac.c
1414 if (scsicmd->device->id == host->this_id) {
1415 setinqstr(dev, (void *) (inq_data.inqd_vid), (sizeof(container_types)/sizeof(char *)));
1416 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1417 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1418 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1419 scsicmd->scsi_done(scsicmd);
1422 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1423 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1424 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1425 return aac_get_container_name(scsicmd, cid);
1432 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1433 if (fsa_dev_ptr[cid].size <= 0x100000000LL)
1434 capacity = fsa_dev_ptr[cid].size - 1;
1438 cp[0] = (capacity >> 24) & 0xff;
1439 cp[1] = (capacity >> 16) & 0xff;
1440 cp[2] = (capacity >> 8) & 0xff;
1441 cp[3] = (capacity >> 0) & 0xff;
1446 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1448 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1449 scsicmd->scsi_done(scsicmd);
1458 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1459 mode_buf[0] = 3; /* Mode data length */
1460 mode_buf[1] = 0; /* Medium type - default */
1461 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1462 mode_buf[3] = 0; /* Block descriptor length */
1464 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1465 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1466 scsicmd->scsi_done(scsicmd);
1474 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1475 mode_buf[0] = 0; /* Mode data length (MSB) */
1476 mode_buf[1] = 6; /* Mode data length (LSB) */
1477 mode_buf[2] = 0; /* Medium type - default */
1478 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1479 mode_buf[4] = 0; /* reserved */
1480 mode_buf[5] = 0; /* reserved */
1481 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1482 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1483 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1485 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1486 scsicmd->scsi_done(scsicmd);
1491 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1492 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1493 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1494 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1495 scsicmd->scsi_done(scsicmd);
1498 case ALLOW_MEDIUM_REMOVAL:
1499 dprintk((KERN_DEBUG "LOCK command.\n"));
1500 if (scsicmd->cmnd[4])
1501 fsa_dev_ptr[cid].locked = 1;
1503 fsa_dev_ptr[cid].locked = 0;
1505 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1506 scsicmd->scsi_done(scsicmd);
1509 * These commands are all No-Ops
1511 case TEST_UNIT_READY:
1515 case REASSIGN_BLOCKS:
1518 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1519 scsicmd->scsi_done(scsicmd);
1523 switch (scsicmd->cmnd[0])
1528 * Hack to keep track of ordinal number of the device that
1529 * corresponds to a container. Needed to convert
1530 * containers to /dev/sd device names
1533 spin_unlock_irq(host->host_lock);
1534 if (scsicmd->request->rq_disk)
1535 memcpy(fsa_dev_ptr[cid].devname,
1536 scsicmd->request->rq_disk->disk_name,
1539 ret = aac_read(scsicmd, cid);
1540 spin_lock_irq(host->host_lock);
1545 spin_unlock_irq(host->host_lock);
1546 ret = aac_write(scsicmd, cid);
1547 spin_lock_irq(host->host_lock);
1550 case SYNCHRONIZE_CACHE:
1551 /* Issue FIB to tell Firmware to flush it's cache */
1552 return aac_synchronize(scsicmd, cid);
1556 * Unhandled commands
1558 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1559 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1560 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1561 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1562 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1563 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1564 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1565 ? sizeof(scsicmd->sense_buffer)
1566 : sizeof(dev->fsa_dev[cid].sense_data));
1567 scsicmd->scsi_done(scsicmd);
1572 static int query_disk(struct aac_dev *dev, void __user *arg)
1574 struct aac_query_disk qd;
1575 struct fsa_dev_info *fsa_dev_ptr;
1577 fsa_dev_ptr = dev->fsa_dev;
1578 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1581 qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
1582 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1584 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1586 qd.instance = dev->scsi_host_ptr->host_no;
1588 qd.id = CONTAINER_TO_ID(qd.cnum);
1589 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1591 else return -EINVAL;
1593 qd.valid = fsa_dev_ptr[qd.cnum].valid;
1594 qd.locked = fsa_dev_ptr[qd.cnum].locked;
1595 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1597 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1602 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1603 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1605 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1610 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1612 struct aac_delete_disk dd;
1613 struct fsa_dev_info *fsa_dev_ptr;
1615 fsa_dev_ptr = dev->fsa_dev;
1617 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1620 if (dd.cnum >= dev->maximum_num_containers)
1623 * Mark this container as being deleted.
1625 fsa_dev_ptr[dd.cnum].deleted = 1;
1627 * Mark the container as no longer valid
1629 fsa_dev_ptr[dd.cnum].valid = 0;
1633 static int delete_disk(struct aac_dev *dev, void __user *arg)
1635 struct aac_delete_disk dd;
1636 struct fsa_dev_info *fsa_dev_ptr;
1638 fsa_dev_ptr = dev->fsa_dev;
1640 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1643 if (dd.cnum >= dev->maximum_num_containers)
1646 * If the container is locked, it can not be deleted by the API.
1648 if (fsa_dev_ptr[dd.cnum].locked)
1652 * Mark the container as no longer being valid.
1654 fsa_dev_ptr[dd.cnum].valid = 0;
1655 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
1660 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1663 case FSACTL_QUERY_DISK:
1664 return query_disk(dev, arg);
1665 case FSACTL_DELETE_DISK:
1666 return delete_disk(dev, arg);
1667 case FSACTL_FORCE_DELETE_DISK:
1668 return force_delete_disk(dev, arg);
1669 case FSACTL_GET_CONTAINERS:
1670 return aac_get_containers(dev);
1679 * @context: the context set in the fib - here it is scsi cmd
1680 * @fibptr: pointer to the fib
1682 * Handles the completion of a scsi command to a non dasd device
1686 static void aac_srb_callback(void *context, struct fib * fibptr)
1688 struct aac_dev *dev;
1689 struct aac_srb_reply *srbreply;
1690 struct scsi_cmnd *scsicmd;
1692 scsicmd = (struct scsi_cmnd *) context;
1693 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1698 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1700 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
1702 * Calculate resid for sg
1705 scsicmd->resid = scsicmd->request_bufflen -
1706 le32_to_cpu(srbreply->data_xfer_length);
1709 pci_unmap_sg(dev->pdev,
1710 (struct scatterlist *)scsicmd->buffer,
1712 scsicmd->sc_data_direction);
1713 else if(scsicmd->request_bufflen)
1714 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
1715 scsicmd->sc_data_direction);
1718 * First check the fib status
1721 if (le32_to_cpu(srbreply->status) != ST_OK){
1723 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1724 len = (le32_to_cpu(srbreply->sense_data_size) >
1725 sizeof(scsicmd->sense_buffer)) ?
1726 sizeof(scsicmd->sense_buffer) :
1727 le32_to_cpu(srbreply->sense_data_size);
1728 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1729 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1733 * Next check the srb status
1735 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1736 case SRB_STATUS_ERROR_RECOVERY:
1737 case SRB_STATUS_PENDING:
1738 case SRB_STATUS_SUCCESS:
1739 if(scsicmd->cmnd[0] == INQUIRY ){
1742 /* We can't expose disk devices because we can't tell whether they
1743 * are the raw container drives or stand alone drives. If they have
1744 * the removable bit set then we should expose them though.
1746 b = (*(u8*)scsicmd->buffer)&0x1f;
1747 b1 = ((u8*)scsicmd->buffer)[1];
1748 if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1749 || (b==TYPE_DISK && (b1&0x80)) ){
1750 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1752 * We will allow disk devices if in RAID/SCSI mode and
1755 } else if ((dev->raid_scsi_mode) &&
1756 (scsicmd->device->channel == 2)) {
1757 scsicmd->result = DID_OK << 16 |
1758 COMMAND_COMPLETE << 8;
1760 scsicmd->result = DID_NO_CONNECT << 16 |
1761 COMMAND_COMPLETE << 8;
1764 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1767 case SRB_STATUS_DATA_OVERRUN:
1768 switch(scsicmd->cmnd[0]){
1775 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1776 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1778 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1780 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1785 /* We can't expose disk devices because we can't tell whether they
1786 * are the raw container drives or stand alone drives
1788 b = (*(u8*)scsicmd->buffer)&0x0f;
1789 b1 = ((u8*)scsicmd->buffer)[1];
1790 if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1791 || (b==TYPE_DISK && (b1&0x80)) ){
1792 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1794 * We will allow disk devices if in RAID/SCSI mode and
1797 } else if ((dev->raid_scsi_mode) &&
1798 (scsicmd->device->channel == 2)) {
1799 scsicmd->result = DID_OK << 16 |
1800 COMMAND_COMPLETE << 8;
1802 scsicmd->result = DID_NO_CONNECT << 16 |
1803 COMMAND_COMPLETE << 8;
1808 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1812 case SRB_STATUS_ABORTED:
1813 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
1815 case SRB_STATUS_ABORT_FAILED:
1816 // Not sure about this one - but assuming the hba was trying to abort for some reason
1817 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
1819 case SRB_STATUS_PARITY_ERROR:
1820 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
1822 case SRB_STATUS_NO_DEVICE:
1823 case SRB_STATUS_INVALID_PATH_ID:
1824 case SRB_STATUS_INVALID_TARGET_ID:
1825 case SRB_STATUS_INVALID_LUN:
1826 case SRB_STATUS_SELECTION_TIMEOUT:
1827 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1830 case SRB_STATUS_COMMAND_TIMEOUT:
1831 case SRB_STATUS_TIMEOUT:
1832 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
1835 case SRB_STATUS_BUSY:
1836 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1839 case SRB_STATUS_BUS_RESET:
1840 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
1843 case SRB_STATUS_MESSAGE_REJECTED:
1844 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
1846 case SRB_STATUS_REQUEST_FLUSHED:
1847 case SRB_STATUS_ERROR:
1848 case SRB_STATUS_INVALID_REQUEST:
1849 case SRB_STATUS_REQUEST_SENSE_FAILED:
1850 case SRB_STATUS_NO_HBA:
1851 case SRB_STATUS_UNEXPECTED_BUS_FREE:
1852 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
1853 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
1854 case SRB_STATUS_DELAYED_RETRY:
1855 case SRB_STATUS_BAD_FUNCTION:
1856 case SRB_STATUS_NOT_STARTED:
1857 case SRB_STATUS_NOT_IN_USE:
1858 case SRB_STATUS_FORCE_ABORT:
1859 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
1861 #ifdef AAC_DETAILED_STATUS_INFO
1862 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
1863 le32_to_cpu(srbreply->srb_status) & 0x3F,
1864 aac_get_status_string(
1865 le32_to_cpu(srbreply->srb_status) & 0x3F),
1867 le32_to_cpu(srbreply->scsi_status));
1869 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1872 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
1874 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
1875 len = (le32_to_cpu(srbreply->sense_data_size) >
1876 sizeof(scsicmd->sense_buffer)) ?
1877 sizeof(scsicmd->sense_buffer) :
1878 le32_to_cpu(srbreply->sense_data_size);
1879 #ifdef AAC_DETAILED_STATUS_INFO
1880 dprintk((KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
1881 le32_to_cpu(srbreply->status), len));
1883 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1887 * OR in the scsi status (already shifted up a bit)
1889 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
1891 fib_complete(fibptr);
1893 aac_io_done(scsicmd);
1899 * @scsicmd: the scsi command block
1901 * This routine will form a FIB and fill in the aac_srb from the
1902 * scsicmd passed in.
1905 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
1907 struct fib* cmd_fibcontext;
1908 struct aac_dev* dev;
1910 struct aac_srb *srbcmd;
1915 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1916 if (scsicmd->device->id >= dev->maximum_num_physicals ||
1917 scsicmd->device->lun > 7) {
1918 scsicmd->result = DID_NO_CONNECT << 16;
1919 scsicmd->scsi_done(scsicmd);
1923 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1924 switch(scsicmd->sc_data_direction){
1928 case DMA_BIDIRECTIONAL:
1929 flag = SRB_DataIn | SRB_DataOut;
1931 case DMA_FROM_DEVICE:
1935 default: /* shuts up some versions of gcc */
1936 flag = SRB_NoDataXfer;
1942 * Allocate and initialize a Fib then setup a BlockWrite command
1944 if (!(cmd_fibcontext = fib_alloc(dev))) {
1947 fib_init(cmd_fibcontext);
1949 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
1950 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1951 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel));
1952 srbcmd->id = cpu_to_le32(scsicmd->device->id);
1953 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
1954 srbcmd->flags = cpu_to_le32(flag);
1955 timeout = scsicmd->timeout_per_command/HZ;
1959 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1960 srbcmd->retry_limit = 0; /* Obsolete parameter */
1961 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
1963 if( dev->dac_support == 1 ) {
1964 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
1965 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1967 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1968 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1970 * Build Scatter/Gather list
1972 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1973 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1974 sizeof (struct sgentry64));
1975 BUG_ON (fibsize > (dev->max_fib_size -
1976 sizeof(struct aac_fibhdr)));
1979 * Now send the Fib to the adapter
1981 status = fib_send(ScsiPortCommand64, cmd_fibcontext,
1982 fibsize, FsaNormal, 0, 1,
1983 (fib_callback) aac_srb_callback,
1986 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
1987 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1989 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1990 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1992 * Build Scatter/Gather list
1994 fibsize = sizeof (struct aac_srb) +
1995 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1996 sizeof (struct sgentry));
1997 BUG_ON (fibsize > (dev->max_fib_size -
1998 sizeof(struct aac_fibhdr)));
2001 * Now send the Fib to the adapter
2003 status = fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
2004 (fib_callback) aac_srb_callback, (void *) scsicmd);
2007 * Check that the command queued to the controller
2009 if (status == -EINPROGRESS){
2013 printk(KERN_WARNING "aac_srb: fib_send failed with status: %d\n", status);
2014 fib_complete(cmd_fibcontext);
2015 fib_free(cmd_fibcontext);
2020 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2022 struct aac_dev *dev;
2023 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;
2029 psg->sg[0].count = 0;
2030 if (scsicmd->use_sg) {
2031 struct scatterlist *sg;
2034 sg = (struct scatterlist *) scsicmd->request_buffer;
2036 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2037 scsicmd->sc_data_direction);
2038 psg->count = cpu_to_le32(sg_count);
2042 for (i = 0; i < sg_count; i++) {
2043 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2044 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2045 byte_count += sg_dma_len(sg);
2048 /* hba wants the size to be exact */
2049 if(byte_count > scsicmd->request_bufflen){
2050 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2051 (byte_count - scsicmd->request_bufflen);
2052 psg->sg[i-1].count = cpu_to_le32(temp);
2053 byte_count = scsicmd->request_bufflen;
2055 /* Check for command underflow */
2056 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2057 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2058 byte_count, scsicmd->underflow);
2061 else if(scsicmd->request_bufflen) {
2063 addr = pci_map_single(dev->pdev,
2064 scsicmd->request_buffer,
2065 scsicmd->request_bufflen,
2066 scsicmd->sc_data_direction);
2067 psg->count = cpu_to_le32(1);
2068 psg->sg[0].addr = cpu_to_le32(addr);
2069 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2070 scsicmd->SCp.dma_handle = addr;
2071 byte_count = scsicmd->request_bufflen;
2077 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2079 struct aac_dev *dev;
2080 unsigned long byte_count = 0;
2083 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2084 // Get rid of old data
2086 psg->sg[0].addr[0] = 0;
2087 psg->sg[0].addr[1] = 0;
2088 psg->sg[0].count = 0;
2089 if (scsicmd->use_sg) {
2090 struct scatterlist *sg;
2093 sg = (struct scatterlist *) scsicmd->request_buffer;
2095 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2096 scsicmd->sc_data_direction);
2097 psg->count = cpu_to_le32(sg_count);
2101 for (i = 0; i < sg_count; i++) {
2102 addr = sg_dma_address(sg);
2103 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2104 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2105 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2106 byte_count += sg_dma_len(sg);
2109 /* hba wants the size to be exact */
2110 if(byte_count > scsicmd->request_bufflen){
2111 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2112 (byte_count - scsicmd->request_bufflen);
2113 psg->sg[i-1].count = cpu_to_le32(temp);
2114 byte_count = scsicmd->request_bufflen;
2116 /* Check for command underflow */
2117 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2118 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2119 byte_count, scsicmd->underflow);
2122 else if(scsicmd->request_bufflen) {
2124 addr = pci_map_single(dev->pdev,
2125 scsicmd->request_buffer,
2126 scsicmd->request_bufflen,
2127 scsicmd->sc_data_direction);
2128 psg->count = cpu_to_le32(1);
2129 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2130 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2131 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2132 scsicmd->SCp.dma_handle = addr;
2133 byte_count = scsicmd->request_bufflen;
2138 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2140 struct Scsi_Host *host = scsicmd->device->host;
2141 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2142 unsigned long byte_count = 0;
2144 // Get rid of old data
2146 psg->sg[0].next = 0;
2147 psg->sg[0].prev = 0;
2148 psg->sg[0].addr[0] = 0;
2149 psg->sg[0].addr[1] = 0;
2150 psg->sg[0].count = 0;
2151 psg->sg[0].flags = 0;
2152 if (scsicmd->use_sg) {
2153 struct scatterlist *sg;
2156 sg = (struct scatterlist *) scsicmd->request_buffer;
2158 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2159 scsicmd->sc_data_direction);
2161 for (i = 0; i < sg_count; i++) {
2162 int count = sg_dma_len(sg);
2163 u64 addr = sg_dma_address(sg);
2164 psg->sg[i].next = 0;
2165 psg->sg[i].prev = 0;
2166 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2167 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2168 psg->sg[i].count = cpu_to_le32(count);
2169 psg->sg[i].flags = 0;
2170 byte_count += count;
2173 psg->count = cpu_to_le32(sg_count);
2174 /* hba wants the size to be exact */
2175 if(byte_count > scsicmd->request_bufflen){
2176 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2177 (byte_count - scsicmd->request_bufflen);
2178 psg->sg[i-1].count = cpu_to_le32(temp);
2179 byte_count = scsicmd->request_bufflen;
2181 /* Check for command underflow */
2182 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2183 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2184 byte_count, scsicmd->underflow);
2187 else if(scsicmd->request_bufflen) {
2190 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2191 scsicmd->request_buffer,
2192 scsicmd->request_bufflen,
2193 scsicmd->sc_data_direction);
2194 addr = scsicmd->SCp.dma_handle;
2195 count = scsicmd->request_bufflen;
2196 psg->count = cpu_to_le32(1);
2197 psg->sg[0].next = 0;
2198 psg->sg[0].prev = 0;
2199 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2200 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2201 psg->sg[0].count = cpu_to_le32(count);
2202 psg->sg[0].flags = 0;
2203 byte_count = scsicmd->request_bufflen;
2208 #ifdef AAC_DETAILED_STATUS_INFO
2210 struct aac_srb_status_info {
2216 static struct aac_srb_status_info srb_status_info[] = {
2217 { SRB_STATUS_PENDING, "Pending Status"},
2218 { SRB_STATUS_SUCCESS, "Success"},
2219 { SRB_STATUS_ABORTED, "Aborted Command"},
2220 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2221 { SRB_STATUS_ERROR, "Error Event"},
2222 { SRB_STATUS_BUSY, "Device Busy"},
2223 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2224 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2225 { SRB_STATUS_NO_DEVICE, "No Device"},
2226 { SRB_STATUS_TIMEOUT, "Timeout"},
2227 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2228 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2229 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2230 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2231 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2232 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2233 { SRB_STATUS_NO_HBA, "No HBA"},
2234 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2235 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2236 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2237 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2238 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2239 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2240 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2241 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2242 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2243 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2244 { SRB_STATUS_NOT_STARTED, "Not Started"},
2245 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2246 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2247 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2248 { 0xff, "Unknown Error"}
2251 char *aac_get_status_string(u32 status)
2255 for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
2256 if(srb_status_info[i].status == status){
2257 return srb_status_info[i].str;
2261 return "Bad Status Code";