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 = aac_fib_alloc(dev)))
179 aac_fib_init(fibptr);
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 = aac_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 aac_fib_complete(fibptr);
213 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
216 struct aac_commit_config * dinfo;
217 aac_fib_init(fibptr);
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 = aac_fib_send(ContainerCommand,
225 sizeof (struct aac_commit_config),
229 aac_fib_complete(fibptr);
230 } else if (commit == 0) {
232 "aac_get_config_status: Foreign device configurations are being ignored\n");
235 aac_fib_free(fibptr);
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 = aac_fib_alloc(dev)))
261 aac_fib_init(fibptr);
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 = aac_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 aac_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);
283 aac_fib_free(fibptr);
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';
297 aac_fib_init(fibptr);
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 = aac_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);
316 if ((le32_to_cpu(dresp->status) == ST_OK) &&
317 (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
318 dinfo->command = cpu_to_le32(VM_NameServe64);
319 dinfo->count = cpu_to_le32(index);
320 dinfo->type = cpu_to_le32(FT_FILESYS);
322 if (aac_fib_send(ContainerCommand,
324 sizeof(struct aac_query_mount),
330 dresp->mnt[0].capacityhigh = 0;
333 "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%llu\n",
334 (int)index, (int)le32_to_cpu(dresp->status),
335 (int)le32_to_cpu(dresp->mnt[0].vol),
336 (int)le32_to_cpu(dresp->mnt[0].state),
337 ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
338 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32)));
339 if ((le32_to_cpu(dresp->status) == ST_OK) &&
340 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
341 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
342 fsa_dev_ptr[index].valid = 1;
343 fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
344 fsa_dev_ptr[index].size
345 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
346 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
347 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
348 fsa_dev_ptr[index].ro = 1;
350 aac_fib_complete(fibptr);
352 * If there are no more containers, then stop asking.
354 if ((index + 1) >= le32_to_cpu(dresp->count)){
358 aac_fib_free(fibptr);
362 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
365 unsigned int transfer_len;
366 struct scatterlist *sg = scsicmd->request_buffer;
368 if (scsicmd->use_sg) {
369 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
370 transfer_len = min(sg->length, len + offset);
372 buf = scsicmd->request_buffer;
373 transfer_len = min(scsicmd->request_bufflen, len + offset);
376 memcpy(buf + offset, data, transfer_len - offset);
379 kunmap_atomic(buf - sg->offset, KM_IRQ0);
383 static void get_container_name_callback(void *context, struct fib * fibptr)
385 struct aac_get_name_resp * get_name_reply;
386 struct scsi_cmnd * scsicmd;
388 scsicmd = (struct scsi_cmnd *) context;
390 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
394 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
395 /* Failure is irrelevant, using default value instead */
396 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
397 && (get_name_reply->data[0] != '\0')) {
398 char *sp = get_name_reply->data;
399 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
403 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
404 int count = sizeof(d);
407 *dp++ = (*sp) ? *sp++ : ' ';
408 } while (--count > 0);
409 aac_internal_transfer(scsicmd, d,
410 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
414 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
416 aac_fib_complete(fibptr);
417 aac_fib_free(fibptr);
418 scsicmd->scsi_done(scsicmd);
422 * aac_get_container_name - get container name, none blocking.
424 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
427 struct aac_get_name *dinfo;
428 struct fib * cmd_fibcontext;
429 struct aac_dev * dev;
431 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
433 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
436 aac_fib_init(cmd_fibcontext);
437 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
439 dinfo->command = cpu_to_le32(VM_ContainerConfig);
440 dinfo->type = cpu_to_le32(CT_READ_NAME);
441 dinfo->cid = cpu_to_le32(cid);
442 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
444 status = aac_fib_send(ContainerCommand,
446 sizeof (struct aac_get_name),
449 (fib_callback) get_container_name_callback,
453 * Check that the command queued to the controller
455 if (status == -EINPROGRESS)
458 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
459 aac_fib_complete(cmd_fibcontext);
460 aac_fib_free(cmd_fibcontext);
465 * aac_probe_container - query a logical volume
466 * @dev: device to query
467 * @cid: container identifier
469 * Queries the controller about the given volume. The volume information
470 * is updated in the struct fsa_dev_info structure rather than returned.
473 int aac_probe_container(struct aac_dev *dev, int cid)
475 struct fsa_dev_info *fsa_dev_ptr;
477 struct aac_query_mount *dinfo;
478 struct aac_mount *dresp;
482 fsa_dev_ptr = dev->fsa_dev;
483 instance = dev->scsi_host_ptr->unique_id;
485 if (!(fibptr = aac_fib_alloc(dev)))
488 aac_fib_init(fibptr);
490 dinfo = (struct aac_query_mount *)fib_data(fibptr);
492 dinfo->command = cpu_to_le32(VM_NameServe);
493 dinfo->count = cpu_to_le32(cid);
494 dinfo->type = cpu_to_le32(FT_FILESYS);
496 status = aac_fib_send(ContainerCommand,
498 sizeof(struct aac_query_mount),
503 printk(KERN_WARNING "aacraid: aac_probe_container query failed.\n");
507 dresp = (struct aac_mount *) fib_data(fibptr);
509 if ((le32_to_cpu(dresp->status) == ST_OK) &&
510 (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
511 dinfo->command = cpu_to_le32(VM_NameServe64);
512 dinfo->count = cpu_to_le32(cid);
513 dinfo->type = cpu_to_le32(FT_FILESYS);
515 if (aac_fib_send(ContainerCommand,
517 sizeof(struct aac_query_mount),
523 dresp->mnt[0].capacityhigh = 0;
525 if ((le32_to_cpu(dresp->status) == ST_OK) &&
526 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
527 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
528 fsa_dev_ptr[cid].valid = 1;
529 fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
530 fsa_dev_ptr[cid].size
531 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
532 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
533 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
534 fsa_dev_ptr[cid].ro = 1;
538 aac_fib_complete(fibptr);
539 aac_fib_free(fibptr);
544 /* Local Structure to set SCSI inquiry data strings */
546 char vid[8]; /* Vendor ID */
547 char pid[16]; /* Product ID */
548 char prl[4]; /* Product Revision Level */
552 * InqStrCopy - string merge
553 * @a: string to copy from
554 * @b: string to copy to
556 * Copy a String from one location to another
560 static void inqstrcpy(char *a, char *b)
567 static char *container_types[] = {
593 /* Function: setinqstr
595 * Arguments: [1] pointer to void [1] int
597 * Purpose: Sets SCSI inquiry data strings for vendor, product
598 * and revision level. Allows strings to be set in platform dependant
599 * files instead of in OS dependant driver source.
602 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
604 struct scsi_inq *str;
606 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
607 memset(str, ' ', sizeof(*str));
609 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
610 char * cp = dev->supplement_adapter_info.AdapterTypeText;
611 int c = sizeof(str->vid);
612 while (*cp && *cp != ' ' && --c)
616 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
619 while (*cp && *cp != ' ')
623 /* last six chars reserved for vol type */
625 if (strlen(cp) > sizeof(str->pid)) {
626 c = cp[sizeof(str->pid)];
627 cp[sizeof(str->pid)] = '\0';
629 inqstrcpy (cp, str->pid);
631 cp[sizeof(str->pid)] = c;
633 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
635 inqstrcpy (mp->vname, str->vid);
636 /* last six chars reserved for vol type */
637 inqstrcpy (mp->model, str->pid);
640 if (tindex < (sizeof(container_types)/sizeof(char *))){
641 char *findit = str->pid;
643 for ( ; *findit != ' '; findit++); /* walk till we find a space */
644 /* RAID is superfluous in the context of a RAID device */
645 if (memcmp(findit-4, "RAID", 4) == 0)
646 *(findit -= 4) = ' ';
647 if (((findit - str->pid) + strlen(container_types[tindex]))
648 < (sizeof(str->pid) + sizeof(str->prl)))
649 inqstrcpy (container_types[tindex], findit + 1);
651 inqstrcpy ("V1.0", str->prl);
654 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
655 u8 a_sense_code, u8 incorrect_length,
656 u8 bit_pointer, u16 field_pointer,
659 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
660 sense_buf[1] = 0; /* Segment number, always zero */
662 if (incorrect_length) {
663 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
664 sense_buf[3] = BYTE3(residue);
665 sense_buf[4] = BYTE2(residue);
666 sense_buf[5] = BYTE1(residue);
667 sense_buf[6] = BYTE0(residue);
669 sense_buf[2] = sense_key; /* Sense key */
671 if (sense_key == ILLEGAL_REQUEST)
672 sense_buf[7] = 10; /* Additional sense length */
674 sense_buf[7] = 6; /* Additional sense length */
676 sense_buf[12] = sense_code; /* Additional sense code */
677 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
678 if (sense_key == ILLEGAL_REQUEST) {
681 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
682 sense_buf[15] = 0x80;/* Std sense key specific field */
683 /* Illegal parameter is in the parameter block */
685 if (sense_code == SENCODE_INVALID_CDB_FIELD)
686 sense_buf[15] = 0xc0;/* Std sense key specific field */
687 /* Illegal parameter is in the CDB block */
688 sense_buf[15] |= bit_pointer;
689 sense_buf[16] = field_pointer >> 8; /* MSB */
690 sense_buf[17] = field_pointer; /* LSB */
694 int aac_get_adapter_info(struct aac_dev* dev)
699 struct aac_adapter_info *info;
700 struct aac_bus_info *command;
701 struct aac_bus_info_response *bus_info;
703 if (!(fibptr = aac_fib_alloc(dev)))
706 aac_fib_init(fibptr);
707 info = (struct aac_adapter_info *) fib_data(fibptr);
708 memset(info,0,sizeof(*info));
710 rcode = aac_fib_send(RequestAdapterInfo,
714 -1, 1, /* First `interrupt' command uses special wait */
719 aac_fib_complete(fibptr);
720 aac_fib_free(fibptr);
723 memcpy(&dev->adapter_info, info, sizeof(*info));
725 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
726 struct aac_supplement_adapter_info * info;
728 aac_fib_init(fibptr);
730 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
732 memset(info,0,sizeof(*info));
734 rcode = aac_fib_send(RequestSupplementAdapterInfo,
743 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
751 aac_fib_init(fibptr);
753 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
755 memset(bus_info, 0, sizeof(*bus_info));
757 command = (struct aac_bus_info *)bus_info;
759 command->Command = cpu_to_le32(VM_Ioctl);
760 command->ObjType = cpu_to_le32(FT_DRIVE);
761 command->MethodId = cpu_to_le32(1);
762 command->CtlCmd = cpu_to_le32(GetBusInfo);
764 rcode = aac_fib_send(ContainerCommand,
771 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
772 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
773 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
776 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
777 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
783 le32_to_cpu(dev->adapter_info.kernelbuild),
784 (int)sizeof(dev->supplement_adapter_info.BuildDate),
785 dev->supplement_adapter_info.BuildDate);
786 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
787 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
789 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
790 le32_to_cpu(dev->adapter_info.monitorbuild));
791 tmp = le32_to_cpu(dev->adapter_info.biosrev);
792 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
794 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
795 le32_to_cpu(dev->adapter_info.biosbuild));
796 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
797 printk(KERN_INFO "%s%d: serial %x\n",
799 le32_to_cpu(dev->adapter_info.serial[0]));
801 dev->nondasd_support = 0;
802 dev->raid_scsi_mode = 0;
803 if(dev->adapter_info.options & AAC_OPT_NONDASD){
804 dev->nondasd_support = 1;
808 * If the firmware supports ROMB RAID/SCSI mode and we are currently
809 * in RAID/SCSI mode, set the flag. For now if in this mode we will
810 * force nondasd support on. If we decide to allow the non-dasd flag
811 * additional changes changes will have to be made to support
812 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
813 * changed to support the new dev->raid_scsi_mode flag instead of
814 * leaching off of the dev->nondasd_support flag. Also in linit.c the
815 * function aac_detect will have to be modified where it sets up the
816 * max number of channels based on the aac->nondasd_support flag only.
818 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
819 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
820 dev->nondasd_support = 1;
821 dev->raid_scsi_mode = 1;
823 if (dev->raid_scsi_mode != 0)
824 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
828 dev->nondasd_support = (nondasd!=0);
830 if(dev->nondasd_support != 0){
831 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
834 dev->dac_support = 0;
835 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
836 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
837 dev->dac_support = 1;
841 dev->dac_support = (dacmode!=0);
843 if(dev->dac_support != 0) {
844 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
845 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
846 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
848 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
849 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
850 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
852 dev->dac_support = 0;
854 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
860 * 57 scatter gather elements
862 if (!(dev->raw_io_interface)) {
863 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
864 sizeof(struct aac_fibhdr) -
865 sizeof(struct aac_write) + sizeof(struct sgentry)) /
866 sizeof(struct sgentry);
867 if (dev->dac_support) {
869 * 38 scatter gather elements
871 dev->scsi_host_ptr->sg_tablesize =
873 sizeof(struct aac_fibhdr) -
874 sizeof(struct aac_write64) +
875 sizeof(struct sgentry64)) /
876 sizeof(struct sgentry64);
878 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
879 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
881 * Worst case size that could cause sg overflow when
882 * we break up SG elements that are larger than 64KB.
883 * Would be nice if we could tell the SCSI layer what
884 * the maximum SG element size can be. Worst case is
885 * (sg_tablesize-1) 4KB elements with one 64KB
887 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
889 dev->scsi_host_ptr->max_sectors =
890 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
894 aac_fib_complete(fibptr);
895 aac_fib_free(fibptr);
901 static void io_callback(void *context, struct fib * fibptr)
904 struct aac_read_reply *readreply;
905 struct scsi_cmnd *scsicmd;
908 scsicmd = (struct scsi_cmnd *) context;
910 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
911 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
913 if (nblank(dprintk(x))) {
915 switch (scsicmd->cmnd[0]) {
918 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
919 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
923 lba = ((u64)scsicmd->cmnd[2] << 56) |
924 ((u64)scsicmd->cmnd[3] << 48) |
925 ((u64)scsicmd->cmnd[4] << 40) |
926 ((u64)scsicmd->cmnd[5] << 32) |
927 ((u64)scsicmd->cmnd[6] << 24) |
928 (scsicmd->cmnd[7] << 16) |
929 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
933 lba = ((u64)scsicmd->cmnd[2] << 24) |
934 (scsicmd->cmnd[3] << 16) |
935 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
938 lba = ((u64)scsicmd->cmnd[2] << 24) |
939 (scsicmd->cmnd[3] << 16) |
940 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
944 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
945 smp_processor_id(), (unsigned long long)lba, jiffies);
952 pci_unmap_sg(dev->pdev,
953 (struct scatterlist *)scsicmd->buffer,
955 scsicmd->sc_data_direction);
956 else if(scsicmd->request_bufflen)
957 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
958 scsicmd->request_bufflen,
959 scsicmd->sc_data_direction);
960 readreply = (struct aac_read_reply *)fib_data(fibptr);
961 if (le32_to_cpu(readreply->status) == ST_OK)
962 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
964 #ifdef AAC_DETAILED_STATUS_INFO
965 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
966 le32_to_cpu(readreply->status));
968 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
969 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
971 SENCODE_INTERNAL_TARGET_FAILURE,
972 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
974 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
975 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
976 ? sizeof(scsicmd->sense_buffer)
977 : sizeof(dev->fsa_dev[cid].sense_data));
979 aac_fib_complete(fibptr);
980 aac_fib_free(fibptr);
982 scsicmd->scsi_done(scsicmd);
985 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
993 struct fib * cmd_fibcontext;
995 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
997 * Get block address and transfer length
999 switch (scsicmd->cmnd[0]) {
1001 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
1003 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1004 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1005 count = scsicmd->cmnd[4];
1011 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", cid));
1013 lba = ((u64)scsicmd->cmnd[2] << 56) |
1014 ((u64)scsicmd->cmnd[3] << 48) |
1015 ((u64)scsicmd->cmnd[4] << 40) |
1016 ((u64)scsicmd->cmnd[5] << 32) |
1017 ((u64)scsicmd->cmnd[6] << 24) |
1018 (scsicmd->cmnd[7] << 16) |
1019 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1020 count = (scsicmd->cmnd[10] << 24) |
1021 (scsicmd->cmnd[11] << 16) |
1022 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1025 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", cid));
1027 lba = ((u64)scsicmd->cmnd[2] << 24) |
1028 (scsicmd->cmnd[3] << 16) |
1029 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1030 count = (scsicmd->cmnd[6] << 24) |
1031 (scsicmd->cmnd[7] << 16) |
1032 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1035 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
1037 lba = ((u64)scsicmd->cmnd[2] << 24) |
1038 (scsicmd->cmnd[3] << 16) |
1039 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1040 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1043 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1044 smp_processor_id(), (unsigned long long)lba, jiffies));
1045 if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) &&
1046 (lba & 0xffffffff00000000LL)) {
1047 dprintk((KERN_DEBUG "aac_read: Illegal lba\n"));
1048 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1049 SAM_STAT_CHECK_CONDITION;
1050 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1052 SENCODE_INTERNAL_TARGET_FAILURE,
1053 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1055 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1056 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1057 ? sizeof(scsicmd->sense_buffer)
1058 : sizeof(dev->fsa_dev[cid].sense_data));
1059 scsicmd->scsi_done(scsicmd);
1063 * Alocate and initialize a Fib
1065 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1069 aac_fib_init(cmd_fibcontext);
1071 if (dev->raw_io_interface) {
1072 struct aac_raw_io *readcmd;
1073 readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1074 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1075 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1076 readcmd->count = cpu_to_le32(count<<9);
1077 readcmd->cid = cpu_to_le16(cid);
1078 readcmd->flags = cpu_to_le16(1);
1079 readcmd->bpTotal = 0;
1080 readcmd->bpComplete = 0;
1082 aac_build_sgraw(scsicmd, &readcmd->sg);
1083 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
1084 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1087 * Now send the Fib to the adapter
1089 status = aac_fib_send(ContainerRawIo,
1094 (fib_callback) io_callback,
1096 } else if (dev->dac_support == 1) {
1097 struct aac_read64 *readcmd;
1098 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
1099 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1100 readcmd->cid = cpu_to_le16(cid);
1101 readcmd->sector_count = cpu_to_le16(count);
1102 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1106 aac_build_sg64(scsicmd, &readcmd->sg);
1107 fibsize = sizeof(struct aac_read64) +
1108 ((le32_to_cpu(readcmd->sg.count) - 1) *
1109 sizeof (struct sgentry64));
1110 BUG_ON (fibsize > (dev->max_fib_size -
1111 sizeof(struct aac_fibhdr)));
1113 * Now send the Fib to the adapter
1115 status = aac_fib_send(ContainerCommand64,
1120 (fib_callback) io_callback,
1123 struct aac_read *readcmd;
1124 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
1125 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1126 readcmd->cid = cpu_to_le32(cid);
1127 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1128 readcmd->count = cpu_to_le32(count * 512);
1130 aac_build_sg(scsicmd, &readcmd->sg);
1131 fibsize = sizeof(struct aac_read) +
1132 ((le32_to_cpu(readcmd->sg.count) - 1) *
1133 sizeof (struct sgentry));
1134 BUG_ON (fibsize > (dev->max_fib_size -
1135 sizeof(struct aac_fibhdr)));
1137 * Now send the Fib to the adapter
1139 status = aac_fib_send(ContainerCommand,
1144 (fib_callback) io_callback,
1151 * Check that the command queued to the controller
1153 if (status == -EINPROGRESS)
1156 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1158 * For some reason, the Fib didn't queue, return QUEUE_FULL
1160 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1161 scsicmd->scsi_done(scsicmd);
1162 aac_fib_complete(cmd_fibcontext);
1163 aac_fib_free(cmd_fibcontext);
1167 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1173 struct aac_dev *dev;
1174 struct fib * cmd_fibcontext;
1176 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1178 * Get block address and transfer length
1180 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1182 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1183 count = scsicmd->cmnd[4];
1186 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1187 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", cid));
1189 lba = ((u64)scsicmd->cmnd[2] << 56) |
1190 ((u64)scsicmd->cmnd[3] << 48) |
1191 ((u64)scsicmd->cmnd[4] << 40) |
1192 ((u64)scsicmd->cmnd[5] << 32) |
1193 ((u64)scsicmd->cmnd[6] << 24) |
1194 (scsicmd->cmnd[7] << 16) |
1195 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1196 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1197 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1198 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1199 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", cid));
1201 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1202 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1203 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1204 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1206 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
1207 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1208 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1210 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1211 smp_processor_id(), (unsigned long long)lba, jiffies));
1212 if ((!(dev->raw_io_interface) || !(dev->raw_io_64))
1213 && (lba & 0xffffffff00000000LL)) {
1214 dprintk((KERN_DEBUG "aac_write: Illegal lba\n"));
1215 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1216 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1218 SENCODE_INTERNAL_TARGET_FAILURE,
1219 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1221 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1222 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1223 ? sizeof(scsicmd->sense_buffer)
1224 : sizeof(dev->fsa_dev[cid].sense_data));
1225 scsicmd->scsi_done(scsicmd);
1229 * Allocate and initialize a Fib then setup a BlockWrite command
1231 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1232 scsicmd->result = DID_ERROR << 16;
1233 scsicmd->scsi_done(scsicmd);
1236 aac_fib_init(cmd_fibcontext);
1238 if (dev->raw_io_interface) {
1239 struct aac_raw_io *writecmd;
1240 writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1241 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1242 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1243 writecmd->count = cpu_to_le32(count<<9);
1244 writecmd->cid = cpu_to_le16(cid);
1245 writecmd->flags = 0;
1246 writecmd->bpTotal = 0;
1247 writecmd->bpComplete = 0;
1249 aac_build_sgraw(scsicmd, &writecmd->sg);
1250 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1251 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1254 * Now send the Fib to the adapter
1256 status = aac_fib_send(ContainerRawIo,
1261 (fib_callback) io_callback,
1263 } else if (dev->dac_support == 1) {
1264 struct aac_write64 *writecmd;
1265 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1266 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1267 writecmd->cid = cpu_to_le16(cid);
1268 writecmd->sector_count = cpu_to_le16(count);
1269 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1271 writecmd->flags = 0;
1273 aac_build_sg64(scsicmd, &writecmd->sg);
1274 fibsize = sizeof(struct aac_write64) +
1275 ((le32_to_cpu(writecmd->sg.count) - 1) *
1276 sizeof (struct sgentry64));
1277 BUG_ON (fibsize > (dev->max_fib_size -
1278 sizeof(struct aac_fibhdr)));
1280 * Now send the Fib to the adapter
1282 status = aac_fib_send(ContainerCommand64,
1287 (fib_callback) io_callback,
1290 struct aac_write *writecmd;
1291 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
1292 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1293 writecmd->cid = cpu_to_le32(cid);
1294 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1295 writecmd->count = cpu_to_le32(count * 512);
1296 writecmd->sg.count = cpu_to_le32(1);
1297 /* ->stable is not used - it did mean which type of write */
1299 aac_build_sg(scsicmd, &writecmd->sg);
1300 fibsize = sizeof(struct aac_write) +
1301 ((le32_to_cpu(writecmd->sg.count) - 1) *
1302 sizeof (struct sgentry));
1303 BUG_ON (fibsize > (dev->max_fib_size -
1304 sizeof(struct aac_fibhdr)));
1306 * Now send the Fib to the adapter
1308 status = aac_fib_send(ContainerCommand,
1313 (fib_callback) io_callback,
1318 * Check that the command queued to the controller
1320 if (status == -EINPROGRESS)
1325 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1327 * For some reason, the Fib didn't queue, return QUEUE_FULL
1329 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1330 scsicmd->scsi_done(scsicmd);
1332 aac_fib_complete(cmd_fibcontext);
1333 aac_fib_free(cmd_fibcontext);
1337 static void synchronize_callback(void *context, struct fib *fibptr)
1339 struct aac_synchronize_reply *synchronizereply;
1340 struct scsi_cmnd *cmd;
1344 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1345 smp_processor_id(), jiffies));
1346 BUG_ON(fibptr == NULL);
1349 synchronizereply = fib_data(fibptr);
1350 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1351 cmd->result = DID_OK << 16 |
1352 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1354 struct scsi_device *sdev = cmd->device;
1355 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1356 u32 cid = ID_LUN_TO_CONTAINER(sdev->id, sdev->lun);
1358 "synchronize_callback: synchronize failed, status = %d\n",
1359 le32_to_cpu(synchronizereply->status));
1360 cmd->result = DID_OK << 16 |
1361 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1362 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1364 SENCODE_INTERNAL_TARGET_FAILURE,
1365 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1367 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1368 min(sizeof(dev->fsa_dev[cid].sense_data),
1369 sizeof(cmd->sense_buffer)));
1372 aac_fib_complete(fibptr);
1373 aac_fib_free(fibptr);
1374 cmd->scsi_done(cmd);
1377 static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1380 struct fib *cmd_fibcontext;
1381 struct aac_synchronize *synchronizecmd;
1382 struct scsi_cmnd *cmd;
1383 struct scsi_device *sdev = scsicmd->device;
1385 unsigned long flags;
1388 * Wait for all commands to complete to this specific
1391 spin_lock_irqsave(&sdev->list_lock, flags);
1392 list_for_each_entry(cmd, &sdev->cmd_list, list)
1393 if (cmd != scsicmd && cmd->serial_number != 0) {
1398 spin_unlock_irqrestore(&sdev->list_lock, flags);
1401 * Yield the processor (requeue for later)
1404 return SCSI_MLQUEUE_DEVICE_BUSY;
1407 * Allocate and initialize a Fib
1409 if (!(cmd_fibcontext =
1410 aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata)))
1411 return SCSI_MLQUEUE_HOST_BUSY;
1413 aac_fib_init(cmd_fibcontext);
1415 synchronizecmd = fib_data(cmd_fibcontext);
1416 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1417 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1418 synchronizecmd->cid = cpu_to_le32(cid);
1419 synchronizecmd->count =
1420 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1423 * Now send the Fib to the adapter
1425 status = aac_fib_send(ContainerCommand,
1427 sizeof(struct aac_synchronize),
1430 (fib_callback)synchronize_callback,
1434 * Check that the command queued to the controller
1436 if (status == -EINPROGRESS)
1440 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1441 aac_fib_complete(cmd_fibcontext);
1442 aac_fib_free(cmd_fibcontext);
1443 return SCSI_MLQUEUE_HOST_BUSY;
1447 * aac_scsi_cmd() - Process SCSI command
1448 * @scsicmd: SCSI command block
1450 * Emulate a SCSI command and queue the required request for the
1454 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1457 struct Scsi_Host *host = scsicmd->device->host;
1458 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1459 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1463 * If the bus, id or lun is out of range, return fail
1464 * Test does not apply to ID 16, the pseudo id for the controller
1467 if (scmd_id(scsicmd) != host->this_id) {
1468 if ((scsicmd->device->channel == CONTAINER_CHANNEL)) {
1469 if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){
1470 scsicmd->result = DID_NO_CONNECT << 16;
1471 scsicmd->scsi_done(scsicmd);
1474 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
1477 * If the target container doesn't exist, it may have
1478 * been newly created
1480 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1481 switch (scsicmd->cmnd[0]) {
1482 case SERVICE_ACTION_IN:
1483 if (!(dev->raw_io_interface) ||
1484 !(dev->raw_io_64) ||
1485 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1489 case TEST_UNIT_READY:
1490 spin_unlock_irq(host->host_lock);
1491 aac_probe_container(dev, cid);
1492 if ((fsa_dev_ptr[cid].valid & 1) == 0)
1493 fsa_dev_ptr[cid].valid = 0;
1494 spin_lock_irq(host->host_lock);
1495 if (fsa_dev_ptr[cid].valid == 0) {
1496 scsicmd->result = DID_NO_CONNECT << 16;
1497 scsicmd->scsi_done(scsicmd);
1505 * If the target container still doesn't exist,
1508 if (fsa_dev_ptr[cid].valid == 0) {
1509 scsicmd->result = DID_BAD_TARGET << 16;
1510 scsicmd->scsi_done(scsicmd);
1513 } else { /* check for physical non-dasd devices */
1514 if(dev->nondasd_support == 1){
1515 return aac_send_srb_fib(scsicmd);
1517 scsicmd->result = DID_NO_CONNECT << 16;
1518 scsicmd->scsi_done(scsicmd);
1524 * else Command for the controller itself
1526 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1527 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1529 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1530 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1531 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1533 SENCODE_INVALID_COMMAND,
1534 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1535 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1536 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1537 ? sizeof(scsicmd->sense_buffer)
1538 : sizeof(dev->fsa_dev[cid].sense_data));
1539 scsicmd->scsi_done(scsicmd);
1544 /* Handle commands here that don't really require going out to the adapter */
1545 switch (scsicmd->cmnd[0]) {
1548 struct inquiry_data inq_data;
1550 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
1551 memset(&inq_data, 0, sizeof (struct inquiry_data));
1553 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1554 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 */
1555 inq_data.inqd_len = 31;
1556 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1557 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1559 * Set the Vendor, Product, and Revision Level
1560 * see: <vendor>.c i.e. aac.c
1562 if (scmd_id(scsicmd) == host->this_id) {
1563 setinqstr(dev, (void *) (inq_data.inqd_vid), (sizeof(container_types)/sizeof(char *)));
1564 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1565 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1566 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1567 scsicmd->scsi_done(scsicmd);
1570 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1571 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1572 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1573 return aac_get_container_name(scsicmd, cid);
1575 case SERVICE_ACTION_IN:
1576 if (!(dev->raw_io_interface) ||
1577 !(dev->raw_io_64) ||
1578 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1584 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1585 capacity = fsa_dev_ptr[cid].size - 1;
1586 cp[0] = (capacity >> 56) & 0xff;
1587 cp[1] = (capacity >> 48) & 0xff;
1588 cp[2] = (capacity >> 40) & 0xff;
1589 cp[3] = (capacity >> 32) & 0xff;
1590 cp[4] = (capacity >> 24) & 0xff;
1591 cp[5] = (capacity >> 16) & 0xff;
1592 cp[6] = (capacity >> 8) & 0xff;
1593 cp[7] = (capacity >> 0) & 0xff;
1599 aac_internal_transfer(scsicmd, cp, 0,
1600 min((unsigned int)scsicmd->cmnd[13], sizeof(cp)));
1601 if (sizeof(cp) < scsicmd->cmnd[13]) {
1602 unsigned int len, offset = sizeof(cp);
1604 memset(cp, 0, offset);
1606 len = min(scsicmd->cmnd[13]-offset, sizeof(cp));
1607 aac_internal_transfer(scsicmd, cp, offset, len);
1608 } while ((offset += len) < scsicmd->cmnd[13]);
1611 /* Do not cache partition table for arrays */
1612 scsicmd->device->removable = 1;
1614 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1615 scsicmd->scsi_done(scsicmd);
1625 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1626 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
1627 capacity = fsa_dev_ptr[cid].size - 1;
1631 cp[0] = (capacity >> 24) & 0xff;
1632 cp[1] = (capacity >> 16) & 0xff;
1633 cp[2] = (capacity >> 8) & 0xff;
1634 cp[3] = (capacity >> 0) & 0xff;
1639 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1640 /* Do not cache partition table for arrays */
1641 scsicmd->device->removable = 1;
1643 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1644 scsicmd->scsi_done(scsicmd);
1653 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1654 mode_buf[0] = 3; /* Mode data length */
1655 mode_buf[1] = 0; /* Medium type - default */
1656 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1657 mode_buf[3] = 0; /* Block descriptor length */
1659 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1660 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1661 scsicmd->scsi_done(scsicmd);
1669 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1670 mode_buf[0] = 0; /* Mode data length (MSB) */
1671 mode_buf[1] = 6; /* Mode data length (LSB) */
1672 mode_buf[2] = 0; /* Medium type - default */
1673 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1674 mode_buf[4] = 0; /* reserved */
1675 mode_buf[5] = 0; /* reserved */
1676 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1677 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1678 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1680 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1681 scsicmd->scsi_done(scsicmd);
1686 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1687 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1688 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1689 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1690 scsicmd->scsi_done(scsicmd);
1693 case ALLOW_MEDIUM_REMOVAL:
1694 dprintk((KERN_DEBUG "LOCK command.\n"));
1695 if (scsicmd->cmnd[4])
1696 fsa_dev_ptr[cid].locked = 1;
1698 fsa_dev_ptr[cid].locked = 0;
1700 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1701 scsicmd->scsi_done(scsicmd);
1704 * These commands are all No-Ops
1706 case TEST_UNIT_READY:
1710 case REASSIGN_BLOCKS:
1713 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1714 scsicmd->scsi_done(scsicmd);
1718 switch (scsicmd->cmnd[0])
1725 * Hack to keep track of ordinal number of the device that
1726 * corresponds to a container. Needed to convert
1727 * containers to /dev/sd device names
1730 spin_unlock_irq(host->host_lock);
1731 if (scsicmd->request->rq_disk)
1732 strlcpy(fsa_dev_ptr[cid].devname,
1733 scsicmd->request->rq_disk->disk_name,
1734 min(sizeof(fsa_dev_ptr[cid].devname),
1735 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1736 ret = aac_read(scsicmd, cid);
1737 spin_lock_irq(host->host_lock);
1744 spin_unlock_irq(host->host_lock);
1745 ret = aac_write(scsicmd, cid);
1746 spin_lock_irq(host->host_lock);
1749 case SYNCHRONIZE_CACHE:
1750 /* Issue FIB to tell Firmware to flush it's cache */
1751 return aac_synchronize(scsicmd, cid);
1755 * Unhandled commands
1757 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1758 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1759 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1760 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1761 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1762 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1763 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1764 ? sizeof(scsicmd->sense_buffer)
1765 : sizeof(dev->fsa_dev[cid].sense_data));
1766 scsicmd->scsi_done(scsicmd);
1771 static int query_disk(struct aac_dev *dev, void __user *arg)
1773 struct aac_query_disk qd;
1774 struct fsa_dev_info *fsa_dev_ptr;
1776 fsa_dev_ptr = dev->fsa_dev;
1777 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1780 qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
1781 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1783 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1785 qd.instance = dev->scsi_host_ptr->host_no;
1787 qd.id = CONTAINER_TO_ID(qd.cnum);
1788 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1790 else return -EINVAL;
1792 qd.valid = fsa_dev_ptr[qd.cnum].valid;
1793 qd.locked = fsa_dev_ptr[qd.cnum].locked;
1794 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1796 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1801 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1802 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1804 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1809 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1811 struct aac_delete_disk dd;
1812 struct fsa_dev_info *fsa_dev_ptr;
1814 fsa_dev_ptr = dev->fsa_dev;
1816 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1819 if (dd.cnum >= dev->maximum_num_containers)
1822 * Mark this container as being deleted.
1824 fsa_dev_ptr[dd.cnum].deleted = 1;
1826 * Mark the container as no longer valid
1828 fsa_dev_ptr[dd.cnum].valid = 0;
1832 static int delete_disk(struct aac_dev *dev, void __user *arg)
1834 struct aac_delete_disk dd;
1835 struct fsa_dev_info *fsa_dev_ptr;
1837 fsa_dev_ptr = dev->fsa_dev;
1839 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1842 if (dd.cnum >= dev->maximum_num_containers)
1845 * If the container is locked, it can not be deleted by the API.
1847 if (fsa_dev_ptr[dd.cnum].locked)
1851 * Mark the container as no longer being valid.
1853 fsa_dev_ptr[dd.cnum].valid = 0;
1854 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
1859 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1862 case FSACTL_QUERY_DISK:
1863 return query_disk(dev, arg);
1864 case FSACTL_DELETE_DISK:
1865 return delete_disk(dev, arg);
1866 case FSACTL_FORCE_DELETE_DISK:
1867 return force_delete_disk(dev, arg);
1868 case FSACTL_GET_CONTAINERS:
1869 return aac_get_containers(dev);
1878 * @context: the context set in the fib - here it is scsi cmd
1879 * @fibptr: pointer to the fib
1881 * Handles the completion of a scsi command to a non dasd device
1885 static void aac_srb_callback(void *context, struct fib * fibptr)
1887 struct aac_dev *dev;
1888 struct aac_srb_reply *srbreply;
1889 struct scsi_cmnd *scsicmd;
1891 scsicmd = (struct scsi_cmnd *) context;
1892 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1897 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1899 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
1901 * Calculate resid for sg
1904 scsicmd->resid = scsicmd->request_bufflen -
1905 le32_to_cpu(srbreply->data_xfer_length);
1908 pci_unmap_sg(dev->pdev,
1909 (struct scatterlist *)scsicmd->buffer,
1911 scsicmd->sc_data_direction);
1912 else if(scsicmd->request_bufflen)
1913 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
1914 scsicmd->sc_data_direction);
1917 * First check the fib status
1920 if (le32_to_cpu(srbreply->status) != ST_OK){
1922 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1923 len = (le32_to_cpu(srbreply->sense_data_size) >
1924 sizeof(scsicmd->sense_buffer)) ?
1925 sizeof(scsicmd->sense_buffer) :
1926 le32_to_cpu(srbreply->sense_data_size);
1927 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1928 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1932 * Next check the srb status
1934 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1935 case SRB_STATUS_ERROR_RECOVERY:
1936 case SRB_STATUS_PENDING:
1937 case SRB_STATUS_SUCCESS:
1938 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1940 case SRB_STATUS_DATA_OVERRUN:
1941 switch(scsicmd->cmnd[0]){
1950 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1951 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1953 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1955 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1958 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1962 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1966 case SRB_STATUS_ABORTED:
1967 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
1969 case SRB_STATUS_ABORT_FAILED:
1970 // Not sure about this one - but assuming the hba was trying to abort for some reason
1971 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
1973 case SRB_STATUS_PARITY_ERROR:
1974 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
1976 case SRB_STATUS_NO_DEVICE:
1977 case SRB_STATUS_INVALID_PATH_ID:
1978 case SRB_STATUS_INVALID_TARGET_ID:
1979 case SRB_STATUS_INVALID_LUN:
1980 case SRB_STATUS_SELECTION_TIMEOUT:
1981 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1984 case SRB_STATUS_COMMAND_TIMEOUT:
1985 case SRB_STATUS_TIMEOUT:
1986 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
1989 case SRB_STATUS_BUSY:
1990 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1993 case SRB_STATUS_BUS_RESET:
1994 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
1997 case SRB_STATUS_MESSAGE_REJECTED:
1998 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2000 case SRB_STATUS_REQUEST_FLUSHED:
2001 case SRB_STATUS_ERROR:
2002 case SRB_STATUS_INVALID_REQUEST:
2003 case SRB_STATUS_REQUEST_SENSE_FAILED:
2004 case SRB_STATUS_NO_HBA:
2005 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2006 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2007 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2008 case SRB_STATUS_DELAYED_RETRY:
2009 case SRB_STATUS_BAD_FUNCTION:
2010 case SRB_STATUS_NOT_STARTED:
2011 case SRB_STATUS_NOT_IN_USE:
2012 case SRB_STATUS_FORCE_ABORT:
2013 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2015 #ifdef AAC_DETAILED_STATUS_INFO
2016 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2017 le32_to_cpu(srbreply->srb_status) & 0x3F,
2018 aac_get_status_string(
2019 le32_to_cpu(srbreply->srb_status) & 0x3F),
2021 le32_to_cpu(srbreply->scsi_status));
2023 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2026 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2028 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2029 len = (le32_to_cpu(srbreply->sense_data_size) >
2030 sizeof(scsicmd->sense_buffer)) ?
2031 sizeof(scsicmd->sense_buffer) :
2032 le32_to_cpu(srbreply->sense_data_size);
2033 #ifdef AAC_DETAILED_STATUS_INFO
2034 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2035 le32_to_cpu(srbreply->status), len);
2037 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2041 * OR in the scsi status (already shifted up a bit)
2043 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2045 aac_fib_complete(fibptr);
2046 aac_fib_free(fibptr);
2047 scsicmd->scsi_done(scsicmd);
2053 * @scsicmd: the scsi command block
2055 * This routine will form a FIB and fill in the aac_srb from the
2056 * scsicmd passed in.
2059 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2061 struct fib* cmd_fibcontext;
2062 struct aac_dev* dev;
2064 struct aac_srb *srbcmd;
2069 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2070 if (scsicmd->device->id >= dev->maximum_num_physicals ||
2071 scsicmd->device->lun > 7) {
2072 scsicmd->result = DID_NO_CONNECT << 16;
2073 scsicmd->scsi_done(scsicmd);
2077 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2078 switch(scsicmd->sc_data_direction){
2082 case DMA_BIDIRECTIONAL:
2083 flag = SRB_DataIn | SRB_DataOut;
2085 case DMA_FROM_DEVICE:
2089 default: /* shuts up some versions of gcc */
2090 flag = SRB_NoDataXfer;
2096 * Allocate and initialize a Fib then setup a BlockWrite command
2098 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2101 aac_fib_init(cmd_fibcontext);
2103 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
2104 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
2105 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel));
2106 srbcmd->id = cpu_to_le32(scsicmd->device->id);
2107 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
2108 srbcmd->flags = cpu_to_le32(flag);
2109 timeout = scsicmd->timeout_per_command/HZ;
2113 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
2114 srbcmd->retry_limit = 0; /* Obsolete parameter */
2115 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
2117 if( dev->dac_support == 1 ) {
2118 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
2119 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2121 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2122 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2124 * Build Scatter/Gather list
2126 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
2127 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
2128 sizeof (struct sgentry64));
2129 BUG_ON (fibsize > (dev->max_fib_size -
2130 sizeof(struct aac_fibhdr)));
2133 * Now send the Fib to the adapter
2135 status = aac_fib_send(ScsiPortCommand64, cmd_fibcontext,
2136 fibsize, FsaNormal, 0, 1,
2137 (fib_callback) aac_srb_callback,
2140 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
2141 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2143 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2144 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2146 * Build Scatter/Gather list
2148 fibsize = sizeof (struct aac_srb) +
2149 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
2150 sizeof (struct sgentry));
2151 BUG_ON (fibsize > (dev->max_fib_size -
2152 sizeof(struct aac_fibhdr)));
2155 * Now send the Fib to the adapter
2157 status = aac_fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
2158 (fib_callback) aac_srb_callback, (void *) scsicmd);
2161 * Check that the command queued to the controller
2163 if (status == -EINPROGRESS){
2167 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2168 aac_fib_complete(cmd_fibcontext);
2169 aac_fib_free(cmd_fibcontext);
2174 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2176 struct aac_dev *dev;
2177 unsigned long byte_count = 0;
2179 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2180 // Get rid of old data
2182 psg->sg[0].addr = 0;
2183 psg->sg[0].count = 0;
2184 if (scsicmd->use_sg) {
2185 struct scatterlist *sg;
2188 sg = (struct scatterlist *) scsicmd->request_buffer;
2190 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2191 scsicmd->sc_data_direction);
2192 psg->count = cpu_to_le32(sg_count);
2196 for (i = 0; i < sg_count; i++) {
2197 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2198 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2199 byte_count += sg_dma_len(sg);
2202 /* hba wants the size to be exact */
2203 if(byte_count > scsicmd->request_bufflen){
2204 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2205 (byte_count - scsicmd->request_bufflen);
2206 psg->sg[i-1].count = cpu_to_le32(temp);
2207 byte_count = scsicmd->request_bufflen;
2209 /* Check for command underflow */
2210 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2211 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2212 byte_count, scsicmd->underflow);
2215 else if(scsicmd->request_bufflen) {
2217 addr = pci_map_single(dev->pdev,
2218 scsicmd->request_buffer,
2219 scsicmd->request_bufflen,
2220 scsicmd->sc_data_direction);
2221 psg->count = cpu_to_le32(1);
2222 psg->sg[0].addr = cpu_to_le32(addr);
2223 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2224 scsicmd->SCp.dma_handle = addr;
2225 byte_count = scsicmd->request_bufflen;
2231 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2233 struct aac_dev *dev;
2234 unsigned long byte_count = 0;
2237 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2238 // Get rid of old data
2240 psg->sg[0].addr[0] = 0;
2241 psg->sg[0].addr[1] = 0;
2242 psg->sg[0].count = 0;
2243 if (scsicmd->use_sg) {
2244 struct scatterlist *sg;
2247 sg = (struct scatterlist *) scsicmd->request_buffer;
2249 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2250 scsicmd->sc_data_direction);
2251 psg->count = cpu_to_le32(sg_count);
2255 for (i = 0; i < sg_count; i++) {
2256 addr = sg_dma_address(sg);
2257 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2258 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2259 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2260 byte_count += sg_dma_len(sg);
2263 /* hba wants the size to be exact */
2264 if(byte_count > scsicmd->request_bufflen){
2265 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2266 (byte_count - scsicmd->request_bufflen);
2267 psg->sg[i-1].count = cpu_to_le32(temp);
2268 byte_count = scsicmd->request_bufflen;
2270 /* Check for command underflow */
2271 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2272 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2273 byte_count, scsicmd->underflow);
2276 else if(scsicmd->request_bufflen) {
2278 addr = pci_map_single(dev->pdev,
2279 scsicmd->request_buffer,
2280 scsicmd->request_bufflen,
2281 scsicmd->sc_data_direction);
2282 psg->count = cpu_to_le32(1);
2283 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2284 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2285 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2286 scsicmd->SCp.dma_handle = addr;
2287 byte_count = scsicmd->request_bufflen;
2292 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2294 struct Scsi_Host *host = scsicmd->device->host;
2295 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2296 unsigned long byte_count = 0;
2298 // Get rid of old data
2300 psg->sg[0].next = 0;
2301 psg->sg[0].prev = 0;
2302 psg->sg[0].addr[0] = 0;
2303 psg->sg[0].addr[1] = 0;
2304 psg->sg[0].count = 0;
2305 psg->sg[0].flags = 0;
2306 if (scsicmd->use_sg) {
2307 struct scatterlist *sg;
2310 sg = (struct scatterlist *) scsicmd->request_buffer;
2312 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2313 scsicmd->sc_data_direction);
2315 for (i = 0; i < sg_count; i++) {
2316 int count = sg_dma_len(sg);
2317 u64 addr = sg_dma_address(sg);
2318 psg->sg[i].next = 0;
2319 psg->sg[i].prev = 0;
2320 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2321 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2322 psg->sg[i].count = cpu_to_le32(count);
2323 psg->sg[i].flags = 0;
2324 byte_count += count;
2327 psg->count = cpu_to_le32(sg_count);
2328 /* hba wants the size to be exact */
2329 if(byte_count > scsicmd->request_bufflen){
2330 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2331 (byte_count - scsicmd->request_bufflen);
2332 psg->sg[i-1].count = cpu_to_le32(temp);
2333 byte_count = scsicmd->request_bufflen;
2335 /* Check for command underflow */
2336 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2337 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2338 byte_count, scsicmd->underflow);
2341 else if(scsicmd->request_bufflen) {
2344 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2345 scsicmd->request_buffer,
2346 scsicmd->request_bufflen,
2347 scsicmd->sc_data_direction);
2348 addr = scsicmd->SCp.dma_handle;
2349 count = scsicmd->request_bufflen;
2350 psg->count = cpu_to_le32(1);
2351 psg->sg[0].next = 0;
2352 psg->sg[0].prev = 0;
2353 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2354 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2355 psg->sg[0].count = cpu_to_le32(count);
2356 psg->sg[0].flags = 0;
2357 byte_count = scsicmd->request_bufflen;
2362 #ifdef AAC_DETAILED_STATUS_INFO
2364 struct aac_srb_status_info {
2370 static struct aac_srb_status_info srb_status_info[] = {
2371 { SRB_STATUS_PENDING, "Pending Status"},
2372 { SRB_STATUS_SUCCESS, "Success"},
2373 { SRB_STATUS_ABORTED, "Aborted Command"},
2374 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2375 { SRB_STATUS_ERROR, "Error Event"},
2376 { SRB_STATUS_BUSY, "Device Busy"},
2377 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2378 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2379 { SRB_STATUS_NO_DEVICE, "No Device"},
2380 { SRB_STATUS_TIMEOUT, "Timeout"},
2381 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2382 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2383 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2384 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2385 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2386 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2387 { SRB_STATUS_NO_HBA, "No HBA"},
2388 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2389 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2390 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2391 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2392 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2393 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2394 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2395 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2396 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2397 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2398 { SRB_STATUS_NOT_STARTED, "Not Started"},
2399 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2400 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2401 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2402 { 0xff, "Unknown Error"}
2405 char *aac_get_status_string(u32 status)
2409 for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
2410 if(srb_status_info[i].status == status){
2411 return srb_status_info[i].str;
2415 return "Bad Status Code";