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 <linux/dma-mapping.h>
36 #include <asm/semaphore.h>
37 #include <asm/uaccess.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_cmnd.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_host.h>
46 /* values for inqd_pdt: Peripheral device type in plain English */
47 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
48 #define INQD_PDT_PROC 0x03 /* Processor device */
49 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
50 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
51 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
52 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
54 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
55 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
61 #define SENCODE_NO_SENSE 0x00
62 #define SENCODE_END_OF_DATA 0x00
63 #define SENCODE_BECOMING_READY 0x04
64 #define SENCODE_INIT_CMD_REQUIRED 0x04
65 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
66 #define SENCODE_INVALID_COMMAND 0x20
67 #define SENCODE_LBA_OUT_OF_RANGE 0x21
68 #define SENCODE_INVALID_CDB_FIELD 0x24
69 #define SENCODE_LUN_NOT_SUPPORTED 0x25
70 #define SENCODE_INVALID_PARAM_FIELD 0x26
71 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
72 #define SENCODE_PARAM_VALUE_INVALID 0x26
73 #define SENCODE_RESET_OCCURRED 0x29
74 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
75 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
76 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
77 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
78 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
79 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
80 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
81 #define SENCODE_OVERLAPPED_COMMAND 0x4E
84 * Additional sense codes
87 #define ASENCODE_NO_SENSE 0x00
88 #define ASENCODE_END_OF_DATA 0x05
89 #define ASENCODE_BECOMING_READY 0x01
90 #define ASENCODE_INIT_CMD_REQUIRED 0x02
91 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
92 #define ASENCODE_INVALID_COMMAND 0x00
93 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
94 #define ASENCODE_INVALID_CDB_FIELD 0x00
95 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
96 #define ASENCODE_INVALID_PARAM_FIELD 0x00
97 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
98 #define ASENCODE_PARAM_VALUE_INVALID 0x02
99 #define ASENCODE_RESET_OCCURRED 0x00
100 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
101 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
102 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
103 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
104 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
105 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
106 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
107 #define ASENCODE_OVERLAPPED_COMMAND 0x00
109 #define BYTE0(x) (unsigned char)(x)
110 #define BYTE1(x) (unsigned char)((x) >> 8)
111 #define BYTE2(x) (unsigned char)((x) >> 16)
112 #define BYTE3(x) (unsigned char)((x) >> 24)
114 /*------------------------------------------------------------------------------
115 * S T R U C T S / T Y P E D E F S
116 *----------------------------------------------------------------------------*/
117 /* SCSI inquiry data */
118 struct inquiry_data {
119 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
120 u8 inqd_dtq; /* RMB | Device Type Qualifier */
121 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
122 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
123 u8 inqd_len; /* Additional length (n-4) */
124 u8 inqd_pad1[2];/* Reserved - must be zero */
125 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
126 u8 inqd_vid[8]; /* Vendor ID */
127 u8 inqd_pid[16];/* Product ID */
128 u8 inqd_prl[4]; /* Product Revision Level */
132 * M O D U L E G L O B A L S
135 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
136 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
137 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
138 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
139 #ifdef AAC_DETAILED_STATUS_INFO
140 static char *aac_get_status_string(u32 status);
144 * Non dasd selection is handled entirely in aachba now
147 static int nondasd = -1;
148 static int dacmode = -1;
150 static int commit = -1;
152 module_param(nondasd, int, S_IRUGO|S_IWUSR);
153 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
154 module_param(dacmode, int, S_IRUGO|S_IWUSR);
155 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
156 module_param(commit, int, S_IRUGO|S_IWUSR);
157 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");
160 module_param(numacb, int, S_IRUGO|S_IWUSR);
161 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid values are 512 and down. Default is to use suggestion from Firmware.");
164 module_param(acbsize, int, S_IRUGO|S_IWUSR);
165 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware.");
167 * aac_get_config_status - check the adapter configuration
168 * @common: adapter to query
170 * Query config status, and commit the configuration if needed.
172 int aac_get_config_status(struct aac_dev *dev)
177 if (!(fibptr = aac_fib_alloc(dev)))
180 aac_fib_init(fibptr);
182 struct aac_get_config_status *dinfo;
183 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
185 dinfo->command = cpu_to_le32(VM_ContainerConfig);
186 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
187 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
190 status = aac_fib_send(ContainerCommand,
192 sizeof (struct aac_get_config_status),
197 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
199 struct aac_get_config_status_resp *reply
200 = (struct aac_get_config_status_resp *) fib_data(fibptr);
201 dprintk((KERN_WARNING
202 "aac_get_config_status: response=%d status=%d action=%d\n",
203 le32_to_cpu(reply->response),
204 le32_to_cpu(reply->status),
205 le32_to_cpu(reply->data.action)));
206 if ((le32_to_cpu(reply->response) != ST_OK) ||
207 (le32_to_cpu(reply->status) != CT_OK) ||
208 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
209 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
213 aac_fib_complete(fibptr);
214 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
217 struct aac_commit_config * dinfo;
218 aac_fib_init(fibptr);
219 dinfo = (struct aac_commit_config *) fib_data(fibptr);
221 dinfo->command = cpu_to_le32(VM_ContainerConfig);
222 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
224 status = aac_fib_send(ContainerCommand,
226 sizeof (struct aac_commit_config),
230 aac_fib_complete(fibptr);
231 } else if (commit == 0) {
233 "aac_get_config_status: Foreign device configurations are being ignored\n");
236 aac_fib_free(fibptr);
241 * aac_get_containers - list containers
242 * @common: adapter to probe
244 * Make a list of all containers on this controller
246 int aac_get_containers(struct aac_dev *dev)
248 struct fsa_dev_info *fsa_dev_ptr;
253 struct aac_get_container_count *dinfo;
254 struct aac_get_container_count_resp *dresp;
255 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
257 instance = dev->scsi_host_ptr->unique_id;
259 if (!(fibptr = aac_fib_alloc(dev)))
262 aac_fib_init(fibptr);
263 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
264 dinfo->command = cpu_to_le32(VM_ContainerConfig);
265 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
267 status = aac_fib_send(ContainerCommand,
269 sizeof (struct aac_get_container_count),
274 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
275 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
276 aac_fib_complete(fibptr);
279 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
280 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
281 fsa_dev_ptr = (struct fsa_dev_info *) kmalloc(
282 sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL);
284 aac_fib_free(fibptr);
287 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
289 dev->fsa_dev = fsa_dev_ptr;
290 dev->maximum_num_containers = maximum_num_containers;
292 for (index = 0; index < dev->maximum_num_containers; index++) {
293 struct aac_query_mount *dinfo;
294 struct aac_mount *dresp;
296 fsa_dev_ptr[index].devname[0] = '\0';
298 aac_fib_init(fibptr);
299 dinfo = (struct aac_query_mount *) fib_data(fibptr);
301 dinfo->command = cpu_to_le32(VM_NameServe);
302 dinfo->count = cpu_to_le32(index);
303 dinfo->type = cpu_to_le32(FT_FILESYS);
305 status = aac_fib_send(ContainerCommand,
307 sizeof (struct aac_query_mount),
312 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
315 dresp = (struct aac_mount *)fib_data(fibptr);
317 if ((le32_to_cpu(dresp->status) == ST_OK) &&
318 (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
319 dinfo->command = cpu_to_le32(VM_NameServe64);
320 dinfo->count = cpu_to_le32(index);
321 dinfo->type = cpu_to_le32(FT_FILESYS);
323 if (aac_fib_send(ContainerCommand,
325 sizeof(struct aac_query_mount),
331 dresp->mnt[0].capacityhigh = 0;
334 "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%llu\n",
335 (int)index, (int)le32_to_cpu(dresp->status),
336 (int)le32_to_cpu(dresp->mnt[0].vol),
337 (int)le32_to_cpu(dresp->mnt[0].state),
338 ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
339 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32)));
340 if ((le32_to_cpu(dresp->status) == ST_OK) &&
341 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
342 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
343 fsa_dev_ptr[index].valid = 1;
344 fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
345 fsa_dev_ptr[index].size
346 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
347 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
348 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
349 fsa_dev_ptr[index].ro = 1;
351 aac_fib_complete(fibptr);
353 * If there are no more containers, then stop asking.
355 if ((index + 1) >= le32_to_cpu(dresp->count)){
359 aac_fib_free(fibptr);
363 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
366 unsigned int transfer_len;
367 struct scatterlist *sg = scsicmd->request_buffer;
369 if (scsicmd->use_sg) {
370 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
371 transfer_len = min(sg->length, len + offset);
373 buf = scsicmd->request_buffer;
374 transfer_len = min(scsicmd->request_bufflen, len + offset);
377 memcpy(buf + offset, data, transfer_len - offset);
380 kunmap_atomic(buf - sg->offset, KM_IRQ0);
384 static void get_container_name_callback(void *context, struct fib * fibptr)
386 struct aac_get_name_resp * get_name_reply;
387 struct scsi_cmnd * scsicmd;
389 scsicmd = (struct scsi_cmnd *) context;
390 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
392 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
396 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
397 /* Failure is irrelevant, using default value instead */
398 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
399 && (get_name_reply->data[0] != '\0')) {
400 char *sp = get_name_reply->data;
401 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
405 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
406 int count = sizeof(d);
409 *dp++ = (*sp) ? *sp++ : ' ';
410 } while (--count > 0);
411 aac_internal_transfer(scsicmd, d,
412 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
416 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
418 aac_fib_complete(fibptr);
419 aac_fib_free(fibptr);
420 scsicmd->scsi_done(scsicmd);
424 * aac_get_container_name - get container name, none blocking.
426 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
429 struct aac_get_name *dinfo;
430 struct fib * cmd_fibcontext;
431 struct aac_dev * dev;
433 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
435 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
438 aac_fib_init(cmd_fibcontext);
439 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
441 dinfo->command = cpu_to_le32(VM_ContainerConfig);
442 dinfo->type = cpu_to_le32(CT_READ_NAME);
443 dinfo->cid = cpu_to_le32(cid);
444 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
446 status = aac_fib_send(ContainerCommand,
448 sizeof (struct aac_get_name),
451 (fib_callback) get_container_name_callback,
455 * Check that the command queued to the controller
457 if (status == -EINPROGRESS) {
458 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
462 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
463 aac_fib_complete(cmd_fibcontext);
464 aac_fib_free(cmd_fibcontext);
469 * aac_probe_container - query a logical volume
470 * @dev: device to query
471 * @cid: container identifier
473 * Queries the controller about the given volume. The volume information
474 * is updated in the struct fsa_dev_info structure rather than returned.
477 int aac_probe_container(struct aac_dev *dev, int cid)
479 struct fsa_dev_info *fsa_dev_ptr;
481 struct aac_query_mount *dinfo;
482 struct aac_mount *dresp;
486 fsa_dev_ptr = dev->fsa_dev;
487 instance = dev->scsi_host_ptr->unique_id;
489 if (!(fibptr = aac_fib_alloc(dev)))
492 aac_fib_init(fibptr);
494 dinfo = (struct aac_query_mount *)fib_data(fibptr);
496 dinfo->command = cpu_to_le32(VM_NameServe);
497 dinfo->count = cpu_to_le32(cid);
498 dinfo->type = cpu_to_le32(FT_FILESYS);
500 status = aac_fib_send(ContainerCommand,
502 sizeof(struct aac_query_mount),
507 printk(KERN_WARNING "aacraid: aac_probe_container query failed.\n");
511 dresp = (struct aac_mount *) fib_data(fibptr);
513 if ((le32_to_cpu(dresp->status) == ST_OK) &&
514 (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
515 dinfo->command = cpu_to_le32(VM_NameServe64);
516 dinfo->count = cpu_to_le32(cid);
517 dinfo->type = cpu_to_le32(FT_FILESYS);
519 if (aac_fib_send(ContainerCommand,
521 sizeof(struct aac_query_mount),
527 dresp->mnt[0].capacityhigh = 0;
529 if ((le32_to_cpu(dresp->status) == ST_OK) &&
530 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
531 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
532 fsa_dev_ptr[cid].valid = 1;
533 fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
534 fsa_dev_ptr[cid].size
535 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
536 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
537 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
538 fsa_dev_ptr[cid].ro = 1;
542 aac_fib_complete(fibptr);
543 aac_fib_free(fibptr);
548 /* Local Structure to set SCSI inquiry data strings */
550 char vid[8]; /* Vendor ID */
551 char pid[16]; /* Product ID */
552 char prl[4]; /* Product Revision Level */
556 * InqStrCopy - string merge
557 * @a: string to copy from
558 * @b: string to copy to
560 * Copy a String from one location to another
564 static void inqstrcpy(char *a, char *b)
571 static char *container_types[] = {
597 /* Function: setinqstr
599 * Arguments: [1] pointer to void [1] int
601 * Purpose: Sets SCSI inquiry data strings for vendor, product
602 * and revision level. Allows strings to be set in platform dependant
603 * files instead of in OS dependant driver source.
606 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
608 struct scsi_inq *str;
610 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
611 memset(str, ' ', sizeof(*str));
613 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
614 char * cp = dev->supplement_adapter_info.AdapterTypeText;
615 int c = sizeof(str->vid);
616 while (*cp && *cp != ' ' && --c)
620 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
623 while (*cp && *cp != ' ')
627 /* last six chars reserved for vol type */
629 if (strlen(cp) > sizeof(str->pid)) {
630 c = cp[sizeof(str->pid)];
631 cp[sizeof(str->pid)] = '\0';
633 inqstrcpy (cp, str->pid);
635 cp[sizeof(str->pid)] = c;
637 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
639 inqstrcpy (mp->vname, str->vid);
640 /* last six chars reserved for vol type */
641 inqstrcpy (mp->model, str->pid);
644 if (tindex < (sizeof(container_types)/sizeof(char *))){
645 char *findit = str->pid;
647 for ( ; *findit != ' '; findit++); /* walk till we find a space */
648 /* RAID is superfluous in the context of a RAID device */
649 if (memcmp(findit-4, "RAID", 4) == 0)
650 *(findit -= 4) = ' ';
651 if (((findit - str->pid) + strlen(container_types[tindex]))
652 < (sizeof(str->pid) + sizeof(str->prl)))
653 inqstrcpy (container_types[tindex], findit + 1);
655 inqstrcpy ("V1.0", str->prl);
658 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
659 u8 a_sense_code, u8 incorrect_length,
660 u8 bit_pointer, u16 field_pointer,
663 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
664 sense_buf[1] = 0; /* Segment number, always zero */
666 if (incorrect_length) {
667 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
668 sense_buf[3] = BYTE3(residue);
669 sense_buf[4] = BYTE2(residue);
670 sense_buf[5] = BYTE1(residue);
671 sense_buf[6] = BYTE0(residue);
673 sense_buf[2] = sense_key; /* Sense key */
675 if (sense_key == ILLEGAL_REQUEST)
676 sense_buf[7] = 10; /* Additional sense length */
678 sense_buf[7] = 6; /* Additional sense length */
680 sense_buf[12] = sense_code; /* Additional sense code */
681 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
682 if (sense_key == ILLEGAL_REQUEST) {
685 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
686 sense_buf[15] = 0x80;/* Std sense key specific field */
687 /* Illegal parameter is in the parameter block */
689 if (sense_code == SENCODE_INVALID_CDB_FIELD)
690 sense_buf[15] = 0xc0;/* Std sense key specific field */
691 /* Illegal parameter is in the CDB block */
692 sense_buf[15] |= bit_pointer;
693 sense_buf[16] = field_pointer >> 8; /* MSB */
694 sense_buf[17] = field_pointer; /* LSB */
698 int aac_get_adapter_info(struct aac_dev* dev)
703 struct aac_adapter_info *info;
704 struct aac_bus_info *command;
705 struct aac_bus_info_response *bus_info;
707 if (!(fibptr = aac_fib_alloc(dev)))
710 aac_fib_init(fibptr);
711 info = (struct aac_adapter_info *) fib_data(fibptr);
712 memset(info,0,sizeof(*info));
714 rcode = aac_fib_send(RequestAdapterInfo,
718 -1, 1, /* First `interrupt' command uses special wait */
723 aac_fib_complete(fibptr);
724 aac_fib_free(fibptr);
727 memcpy(&dev->adapter_info, info, sizeof(*info));
729 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
730 struct aac_supplement_adapter_info * info;
732 aac_fib_init(fibptr);
734 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
736 memset(info,0,sizeof(*info));
738 rcode = aac_fib_send(RequestSupplementAdapterInfo,
747 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
755 aac_fib_init(fibptr);
757 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
759 memset(bus_info, 0, sizeof(*bus_info));
761 command = (struct aac_bus_info *)bus_info;
763 command->Command = cpu_to_le32(VM_Ioctl);
764 command->ObjType = cpu_to_le32(FT_DRIVE);
765 command->MethodId = cpu_to_le32(1);
766 command->CtlCmd = cpu_to_le32(GetBusInfo);
768 rcode = aac_fib_send(ContainerCommand,
775 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
776 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
777 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
780 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
781 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
787 le32_to_cpu(dev->adapter_info.kernelbuild),
788 (int)sizeof(dev->supplement_adapter_info.BuildDate),
789 dev->supplement_adapter_info.BuildDate);
790 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
791 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
793 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
794 le32_to_cpu(dev->adapter_info.monitorbuild));
795 tmp = le32_to_cpu(dev->adapter_info.biosrev);
796 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
798 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
799 le32_to_cpu(dev->adapter_info.biosbuild));
800 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
801 printk(KERN_INFO "%s%d: serial %x\n",
803 le32_to_cpu(dev->adapter_info.serial[0]));
805 dev->nondasd_support = 0;
806 dev->raid_scsi_mode = 0;
807 if(dev->adapter_info.options & AAC_OPT_NONDASD){
808 dev->nondasd_support = 1;
812 * If the firmware supports ROMB RAID/SCSI mode and we are currently
813 * in RAID/SCSI mode, set the flag. For now if in this mode we will
814 * force nondasd support on. If we decide to allow the non-dasd flag
815 * additional changes changes will have to be made to support
816 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
817 * changed to support the new dev->raid_scsi_mode flag instead of
818 * leaching off of the dev->nondasd_support flag. Also in linit.c the
819 * function aac_detect will have to be modified where it sets up the
820 * max number of channels based on the aac->nondasd_support flag only.
822 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
823 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
824 dev->nondasd_support = 1;
825 dev->raid_scsi_mode = 1;
827 if (dev->raid_scsi_mode != 0)
828 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
832 dev->nondasd_support = (nondasd!=0);
834 if(dev->nondasd_support != 0){
835 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
838 dev->dac_support = 0;
839 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
840 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
841 dev->dac_support = 1;
845 dev->dac_support = (dacmode!=0);
847 if(dev->dac_support != 0) {
848 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
849 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
850 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
852 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
853 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
854 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
856 dev->dac_support = 0;
858 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
864 * 57 scatter gather elements
866 if (!(dev->raw_io_interface)) {
867 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
868 sizeof(struct aac_fibhdr) -
869 sizeof(struct aac_write) + sizeof(struct sgentry)) /
870 sizeof(struct sgentry);
871 if (dev->dac_support) {
873 * 38 scatter gather elements
875 dev->scsi_host_ptr->sg_tablesize =
877 sizeof(struct aac_fibhdr) -
878 sizeof(struct aac_write64) +
879 sizeof(struct sgentry64)) /
880 sizeof(struct sgentry64);
882 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
883 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
885 * Worst case size that could cause sg overflow when
886 * we break up SG elements that are larger than 64KB.
887 * Would be nice if we could tell the SCSI layer what
888 * the maximum SG element size can be. Worst case is
889 * (sg_tablesize-1) 4KB elements with one 64KB
891 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
893 dev->scsi_host_ptr->max_sectors =
894 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
898 aac_fib_complete(fibptr);
899 aac_fib_free(fibptr);
905 static void io_callback(void *context, struct fib * fibptr)
908 struct aac_read_reply *readreply;
909 struct scsi_cmnd *scsicmd;
912 scsicmd = (struct scsi_cmnd *) context;
913 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
915 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
916 cid = scmd_id(scsicmd);
918 if (nblank(dprintk(x))) {
920 switch (scsicmd->cmnd[0]) {
923 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
924 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
928 lba = ((u64)scsicmd->cmnd[2] << 56) |
929 ((u64)scsicmd->cmnd[3] << 48) |
930 ((u64)scsicmd->cmnd[4] << 40) |
931 ((u64)scsicmd->cmnd[5] << 32) |
932 ((u64)scsicmd->cmnd[6] << 24) |
933 (scsicmd->cmnd[7] << 16) |
934 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
938 lba = ((u64)scsicmd->cmnd[2] << 24) |
939 (scsicmd->cmnd[3] << 16) |
940 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
943 lba = ((u64)scsicmd->cmnd[2] << 24) |
944 (scsicmd->cmnd[3] << 16) |
945 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
949 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
950 smp_processor_id(), (unsigned long long)lba, jiffies);
957 pci_unmap_sg(dev->pdev,
958 (struct scatterlist *)scsicmd->buffer,
960 scsicmd->sc_data_direction);
961 else if(scsicmd->request_bufflen)
962 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
963 scsicmd->request_bufflen,
964 scsicmd->sc_data_direction);
965 readreply = (struct aac_read_reply *)fib_data(fibptr);
966 if (le32_to_cpu(readreply->status) == ST_OK)
967 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
969 #ifdef AAC_DETAILED_STATUS_INFO
970 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
971 le32_to_cpu(readreply->status));
973 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
974 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
976 SENCODE_INTERNAL_TARGET_FAILURE,
977 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
979 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
980 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
981 ? sizeof(scsicmd->sense_buffer)
982 : sizeof(dev->fsa_dev[cid].sense_data));
984 aac_fib_complete(fibptr);
985 aac_fib_free(fibptr);
987 scsicmd->scsi_done(scsicmd);
990 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
998 struct fib * cmd_fibcontext;
1000 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1002 * Get block address and transfer length
1004 switch (scsicmd->cmnd[0]) {
1006 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
1008 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1009 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1010 count = scsicmd->cmnd[4];
1016 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", cid));
1018 lba = ((u64)scsicmd->cmnd[2] << 56) |
1019 ((u64)scsicmd->cmnd[3] << 48) |
1020 ((u64)scsicmd->cmnd[4] << 40) |
1021 ((u64)scsicmd->cmnd[5] << 32) |
1022 ((u64)scsicmd->cmnd[6] << 24) |
1023 (scsicmd->cmnd[7] << 16) |
1024 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1025 count = (scsicmd->cmnd[10] << 24) |
1026 (scsicmd->cmnd[11] << 16) |
1027 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1030 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", cid));
1032 lba = ((u64)scsicmd->cmnd[2] << 24) |
1033 (scsicmd->cmnd[3] << 16) |
1034 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1035 count = (scsicmd->cmnd[6] << 24) |
1036 (scsicmd->cmnd[7] << 16) |
1037 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1040 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
1042 lba = ((u64)scsicmd->cmnd[2] << 24) |
1043 (scsicmd->cmnd[3] << 16) |
1044 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1045 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1048 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1049 smp_processor_id(), (unsigned long long)lba, jiffies));
1050 if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) &&
1051 (lba & 0xffffffff00000000LL)) {
1052 dprintk((KERN_DEBUG "aac_read: Illegal lba\n"));
1053 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1054 SAM_STAT_CHECK_CONDITION;
1055 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1057 SENCODE_INTERNAL_TARGET_FAILURE,
1058 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1060 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1061 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1062 ? sizeof(scsicmd->sense_buffer)
1063 : sizeof(dev->fsa_dev[cid].sense_data));
1064 scsicmd->scsi_done(scsicmd);
1068 * Alocate and initialize a Fib
1070 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1074 aac_fib_init(cmd_fibcontext);
1076 if (dev->raw_io_interface) {
1077 struct aac_raw_io *readcmd;
1078 readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1079 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1080 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1081 readcmd->count = cpu_to_le32(count<<9);
1082 readcmd->cid = cpu_to_le16(cid);
1083 readcmd->flags = cpu_to_le16(1);
1084 readcmd->bpTotal = 0;
1085 readcmd->bpComplete = 0;
1087 aac_build_sgraw(scsicmd, &readcmd->sg);
1088 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
1089 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1092 * Now send the Fib to the adapter
1094 status = aac_fib_send(ContainerRawIo,
1099 (fib_callback) io_callback,
1101 } else if (dev->dac_support == 1) {
1102 struct aac_read64 *readcmd;
1103 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
1104 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1105 readcmd->cid = cpu_to_le16(cid);
1106 readcmd->sector_count = cpu_to_le16(count);
1107 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1111 aac_build_sg64(scsicmd, &readcmd->sg);
1112 fibsize = sizeof(struct aac_read64) +
1113 ((le32_to_cpu(readcmd->sg.count) - 1) *
1114 sizeof (struct sgentry64));
1115 BUG_ON (fibsize > (dev->max_fib_size -
1116 sizeof(struct aac_fibhdr)));
1118 * Now send the Fib to the adapter
1120 status = aac_fib_send(ContainerCommand64,
1125 (fib_callback) io_callback,
1128 struct aac_read *readcmd;
1129 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
1130 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1131 readcmd->cid = cpu_to_le32(cid);
1132 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1133 readcmd->count = cpu_to_le32(count * 512);
1135 aac_build_sg(scsicmd, &readcmd->sg);
1136 fibsize = sizeof(struct aac_read) +
1137 ((le32_to_cpu(readcmd->sg.count) - 1) *
1138 sizeof (struct sgentry));
1139 BUG_ON (fibsize > (dev->max_fib_size -
1140 sizeof(struct aac_fibhdr)));
1142 * Now send the Fib to the adapter
1144 status = aac_fib_send(ContainerCommand,
1149 (fib_callback) io_callback,
1156 * Check that the command queued to the controller
1158 if (status == -EINPROGRESS) {
1159 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1163 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1165 * For some reason, the Fib didn't queue, return QUEUE_FULL
1167 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1168 scsicmd->scsi_done(scsicmd);
1169 aac_fib_complete(cmd_fibcontext);
1170 aac_fib_free(cmd_fibcontext);
1174 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1180 struct aac_dev *dev;
1181 struct fib * cmd_fibcontext;
1183 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1185 * Get block address and transfer length
1187 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1189 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1190 count = scsicmd->cmnd[4];
1193 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1194 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", cid));
1196 lba = ((u64)scsicmd->cmnd[2] << 56) |
1197 ((u64)scsicmd->cmnd[3] << 48) |
1198 ((u64)scsicmd->cmnd[4] << 40) |
1199 ((u64)scsicmd->cmnd[5] << 32) |
1200 ((u64)scsicmd->cmnd[6] << 24) |
1201 (scsicmd->cmnd[7] << 16) |
1202 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1203 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1204 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1205 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1206 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", cid));
1208 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1209 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1210 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1211 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1213 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
1214 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1215 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1217 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1218 smp_processor_id(), (unsigned long long)lba, jiffies));
1219 if ((!(dev->raw_io_interface) || !(dev->raw_io_64))
1220 && (lba & 0xffffffff00000000LL)) {
1221 dprintk((KERN_DEBUG "aac_write: Illegal lba\n"));
1222 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1223 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1225 SENCODE_INTERNAL_TARGET_FAILURE,
1226 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1228 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1229 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1230 ? sizeof(scsicmd->sense_buffer)
1231 : sizeof(dev->fsa_dev[cid].sense_data));
1232 scsicmd->scsi_done(scsicmd);
1236 * Allocate and initialize a Fib then setup a BlockWrite command
1238 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1239 scsicmd->result = DID_ERROR << 16;
1240 scsicmd->scsi_done(scsicmd);
1243 aac_fib_init(cmd_fibcontext);
1245 if (dev->raw_io_interface) {
1246 struct aac_raw_io *writecmd;
1247 writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1248 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1249 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1250 writecmd->count = cpu_to_le32(count<<9);
1251 writecmd->cid = cpu_to_le16(cid);
1252 writecmd->flags = 0;
1253 writecmd->bpTotal = 0;
1254 writecmd->bpComplete = 0;
1256 aac_build_sgraw(scsicmd, &writecmd->sg);
1257 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1258 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1261 * Now send the Fib to the adapter
1263 status = aac_fib_send(ContainerRawIo,
1268 (fib_callback) io_callback,
1270 } else if (dev->dac_support == 1) {
1271 struct aac_write64 *writecmd;
1272 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1273 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1274 writecmd->cid = cpu_to_le16(cid);
1275 writecmd->sector_count = cpu_to_le16(count);
1276 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1278 writecmd->flags = 0;
1280 aac_build_sg64(scsicmd, &writecmd->sg);
1281 fibsize = sizeof(struct aac_write64) +
1282 ((le32_to_cpu(writecmd->sg.count) - 1) *
1283 sizeof (struct sgentry64));
1284 BUG_ON (fibsize > (dev->max_fib_size -
1285 sizeof(struct aac_fibhdr)));
1287 * Now send the Fib to the adapter
1289 status = aac_fib_send(ContainerCommand64,
1294 (fib_callback) io_callback,
1297 struct aac_write *writecmd;
1298 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
1299 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1300 writecmd->cid = cpu_to_le32(cid);
1301 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1302 writecmd->count = cpu_to_le32(count * 512);
1303 writecmd->sg.count = cpu_to_le32(1);
1304 /* ->stable is not used - it did mean which type of write */
1306 aac_build_sg(scsicmd, &writecmd->sg);
1307 fibsize = sizeof(struct aac_write) +
1308 ((le32_to_cpu(writecmd->sg.count) - 1) *
1309 sizeof (struct sgentry));
1310 BUG_ON (fibsize > (dev->max_fib_size -
1311 sizeof(struct aac_fibhdr)));
1313 * Now send the Fib to the adapter
1315 status = aac_fib_send(ContainerCommand,
1320 (fib_callback) io_callback,
1325 * Check that the command queued to the controller
1327 if (status == -EINPROGRESS) {
1328 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1332 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1334 * For some reason, the Fib didn't queue, return QUEUE_FULL
1336 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1337 scsicmd->scsi_done(scsicmd);
1339 aac_fib_complete(cmd_fibcontext);
1340 aac_fib_free(cmd_fibcontext);
1344 static void synchronize_callback(void *context, struct fib *fibptr)
1346 struct aac_synchronize_reply *synchronizereply;
1347 struct scsi_cmnd *cmd;
1350 cmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1352 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1353 smp_processor_id(), jiffies));
1354 BUG_ON(fibptr == NULL);
1357 synchronizereply = fib_data(fibptr);
1358 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1359 cmd->result = DID_OK << 16 |
1360 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1362 struct scsi_device *sdev = cmd->device;
1363 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1364 u32 cid = sdev_id(sdev);
1366 "synchronize_callback: synchronize failed, status = %d\n",
1367 le32_to_cpu(synchronizereply->status));
1368 cmd->result = DID_OK << 16 |
1369 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1370 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1372 SENCODE_INTERNAL_TARGET_FAILURE,
1373 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1375 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1376 min(sizeof(dev->fsa_dev[cid].sense_data),
1377 sizeof(cmd->sense_buffer)));
1380 aac_fib_complete(fibptr);
1381 aac_fib_free(fibptr);
1382 cmd->scsi_done(cmd);
1385 static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1388 struct fib *cmd_fibcontext;
1389 struct aac_synchronize *synchronizecmd;
1390 struct scsi_cmnd *cmd;
1391 struct scsi_device *sdev = scsicmd->device;
1393 unsigned long flags;
1396 * Wait for all outstanding queued commands to complete to this
1397 * specific target (block).
1399 spin_lock_irqsave(&sdev->list_lock, flags);
1400 list_for_each_entry(cmd, &sdev->cmd_list, list)
1401 if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1406 spin_unlock_irqrestore(&sdev->list_lock, flags);
1409 * Yield the processor (requeue for later)
1412 return SCSI_MLQUEUE_DEVICE_BUSY;
1415 * Allocate and initialize a Fib
1417 if (!(cmd_fibcontext =
1418 aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata)))
1419 return SCSI_MLQUEUE_HOST_BUSY;
1421 aac_fib_init(cmd_fibcontext);
1423 synchronizecmd = fib_data(cmd_fibcontext);
1424 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1425 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1426 synchronizecmd->cid = cpu_to_le32(cid);
1427 synchronizecmd->count =
1428 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1431 * Now send the Fib to the adapter
1433 status = aac_fib_send(ContainerCommand,
1435 sizeof(struct aac_synchronize),
1438 (fib_callback)synchronize_callback,
1442 * Check that the command queued to the controller
1444 if (status == -EINPROGRESS) {
1445 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1450 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1451 aac_fib_complete(cmd_fibcontext);
1452 aac_fib_free(cmd_fibcontext);
1453 return SCSI_MLQUEUE_HOST_BUSY;
1457 * aac_scsi_cmd() - Process SCSI command
1458 * @scsicmd: SCSI command block
1460 * Emulate a SCSI command and queue the required request for the
1464 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1467 struct Scsi_Host *host = scsicmd->device->host;
1468 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1469 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1472 * If the bus, id or lun is out of range, return fail
1473 * Test does not apply to ID 16, the pseudo id for the controller
1476 if (scmd_id(scsicmd) != host->this_id) {
1477 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
1478 if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
1479 (scsicmd->device->lun != 0)) {
1480 scsicmd->result = DID_NO_CONNECT << 16;
1481 scsicmd->scsi_done(scsicmd);
1484 cid = scmd_id(scsicmd);
1487 * If the target container doesn't exist, it may have
1488 * been newly created
1490 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1491 switch (scsicmd->cmnd[0]) {
1492 case SERVICE_ACTION_IN:
1493 if (!(dev->raw_io_interface) ||
1494 !(dev->raw_io_64) ||
1495 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1499 case TEST_UNIT_READY:
1500 spin_unlock_irq(host->host_lock);
1501 aac_probe_container(dev, cid);
1502 if ((fsa_dev_ptr[cid].valid & 1) == 0)
1503 fsa_dev_ptr[cid].valid = 0;
1504 spin_lock_irq(host->host_lock);
1505 if (fsa_dev_ptr[cid].valid == 0) {
1506 scsicmd->result = DID_NO_CONNECT << 16;
1507 scsicmd->scsi_done(scsicmd);
1515 * If the target container still doesn't exist,
1518 if (fsa_dev_ptr[cid].valid == 0) {
1519 scsicmd->result = DID_BAD_TARGET << 16;
1520 scsicmd->scsi_done(scsicmd);
1523 } else { /* check for physical non-dasd devices */
1524 if(dev->nondasd_support == 1){
1525 return aac_send_srb_fib(scsicmd);
1527 scsicmd->result = DID_NO_CONNECT << 16;
1528 scsicmd->scsi_done(scsicmd);
1534 * else Command for the controller itself
1536 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1537 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1539 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1540 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1541 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1543 SENCODE_INVALID_COMMAND,
1544 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1545 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1546 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1547 ? sizeof(scsicmd->sense_buffer)
1548 : sizeof(dev->fsa_dev[cid].sense_data));
1549 scsicmd->scsi_done(scsicmd);
1554 /* Handle commands here that don't really require going out to the adapter */
1555 switch (scsicmd->cmnd[0]) {
1558 struct inquiry_data inq_data;
1560 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
1561 memset(&inq_data, 0, sizeof (struct inquiry_data));
1563 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1564 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 */
1565 inq_data.inqd_len = 31;
1566 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1567 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1569 * Set the Vendor, Product, and Revision Level
1570 * see: <vendor>.c i.e. aac.c
1572 if (scmd_id(scsicmd) == host->this_id) {
1573 setinqstr(dev, (void *) (inq_data.inqd_vid), (sizeof(container_types)/sizeof(char *)));
1574 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1575 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1576 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1577 scsicmd->scsi_done(scsicmd);
1580 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1581 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1582 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1583 return aac_get_container_name(scsicmd, cid);
1585 case SERVICE_ACTION_IN:
1586 if (!(dev->raw_io_interface) ||
1587 !(dev->raw_io_64) ||
1588 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1594 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1595 capacity = fsa_dev_ptr[cid].size - 1;
1596 cp[0] = (capacity >> 56) & 0xff;
1597 cp[1] = (capacity >> 48) & 0xff;
1598 cp[2] = (capacity >> 40) & 0xff;
1599 cp[3] = (capacity >> 32) & 0xff;
1600 cp[4] = (capacity >> 24) & 0xff;
1601 cp[5] = (capacity >> 16) & 0xff;
1602 cp[6] = (capacity >> 8) & 0xff;
1603 cp[7] = (capacity >> 0) & 0xff;
1609 aac_internal_transfer(scsicmd, cp, 0,
1610 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
1611 if (sizeof(cp) < scsicmd->cmnd[13]) {
1612 unsigned int len, offset = sizeof(cp);
1614 memset(cp, 0, offset);
1616 len = min_t(size_t, scsicmd->cmnd[13] - offset,
1618 aac_internal_transfer(scsicmd, cp, offset, len);
1619 } while ((offset += len) < scsicmd->cmnd[13]);
1622 /* Do not cache partition table for arrays */
1623 scsicmd->device->removable = 1;
1625 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1626 scsicmd->scsi_done(scsicmd);
1636 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1637 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
1638 capacity = fsa_dev_ptr[cid].size - 1;
1642 cp[0] = (capacity >> 24) & 0xff;
1643 cp[1] = (capacity >> 16) & 0xff;
1644 cp[2] = (capacity >> 8) & 0xff;
1645 cp[3] = (capacity >> 0) & 0xff;
1650 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1651 /* Do not cache partition table for arrays */
1652 scsicmd->device->removable = 1;
1654 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1655 scsicmd->scsi_done(scsicmd);
1664 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1665 mode_buf[0] = 3; /* Mode data length */
1666 mode_buf[1] = 0; /* Medium type - default */
1667 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1668 mode_buf[3] = 0; /* Block descriptor length */
1670 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1671 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1672 scsicmd->scsi_done(scsicmd);
1680 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1681 mode_buf[0] = 0; /* Mode data length (MSB) */
1682 mode_buf[1] = 6; /* Mode data length (LSB) */
1683 mode_buf[2] = 0; /* Medium type - default */
1684 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1685 mode_buf[4] = 0; /* reserved */
1686 mode_buf[5] = 0; /* reserved */
1687 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1688 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1689 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1691 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1692 scsicmd->scsi_done(scsicmd);
1697 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1698 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1699 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1700 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1701 scsicmd->scsi_done(scsicmd);
1704 case ALLOW_MEDIUM_REMOVAL:
1705 dprintk((KERN_DEBUG "LOCK command.\n"));
1706 if (scsicmd->cmnd[4])
1707 fsa_dev_ptr[cid].locked = 1;
1709 fsa_dev_ptr[cid].locked = 0;
1711 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1712 scsicmd->scsi_done(scsicmd);
1715 * These commands are all No-Ops
1717 case TEST_UNIT_READY:
1721 case REASSIGN_BLOCKS:
1724 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1725 scsicmd->scsi_done(scsicmd);
1729 switch (scsicmd->cmnd[0])
1736 * Hack to keep track of ordinal number of the device that
1737 * corresponds to a container. Needed to convert
1738 * containers to /dev/sd device names
1741 if (scsicmd->request->rq_disk)
1742 strlcpy(fsa_dev_ptr[cid].devname,
1743 scsicmd->request->rq_disk->disk_name,
1744 min(sizeof(fsa_dev_ptr[cid].devname),
1745 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1747 return aac_read(scsicmd, cid);
1753 return aac_write(scsicmd, cid);
1755 case SYNCHRONIZE_CACHE:
1756 /* Issue FIB to tell Firmware to flush it's cache */
1757 return aac_synchronize(scsicmd, cid);
1761 * Unhandled commands
1763 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1764 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1765 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1766 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1767 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1768 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1769 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1770 ? sizeof(scsicmd->sense_buffer)
1771 : sizeof(dev->fsa_dev[cid].sense_data));
1772 scsicmd->scsi_done(scsicmd);
1777 static int query_disk(struct aac_dev *dev, void __user *arg)
1779 struct aac_query_disk qd;
1780 struct fsa_dev_info *fsa_dev_ptr;
1782 fsa_dev_ptr = dev->fsa_dev;
1783 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1787 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1789 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1791 qd.instance = dev->scsi_host_ptr->host_no;
1793 qd.id = CONTAINER_TO_ID(qd.cnum);
1794 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1796 else return -EINVAL;
1798 qd.valid = fsa_dev_ptr[qd.cnum].valid;
1799 qd.locked = fsa_dev_ptr[qd.cnum].locked;
1800 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1802 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1807 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1808 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1810 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1815 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1817 struct aac_delete_disk dd;
1818 struct fsa_dev_info *fsa_dev_ptr;
1820 fsa_dev_ptr = dev->fsa_dev;
1822 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1825 if (dd.cnum >= dev->maximum_num_containers)
1828 * Mark this container as being deleted.
1830 fsa_dev_ptr[dd.cnum].deleted = 1;
1832 * Mark the container as no longer valid
1834 fsa_dev_ptr[dd.cnum].valid = 0;
1838 static int delete_disk(struct aac_dev *dev, void __user *arg)
1840 struct aac_delete_disk dd;
1841 struct fsa_dev_info *fsa_dev_ptr;
1843 fsa_dev_ptr = dev->fsa_dev;
1845 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1848 if (dd.cnum >= dev->maximum_num_containers)
1851 * If the container is locked, it can not be deleted by the API.
1853 if (fsa_dev_ptr[dd.cnum].locked)
1857 * Mark the container as no longer being valid.
1859 fsa_dev_ptr[dd.cnum].valid = 0;
1860 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
1865 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1868 case FSACTL_QUERY_DISK:
1869 return query_disk(dev, arg);
1870 case FSACTL_DELETE_DISK:
1871 return delete_disk(dev, arg);
1872 case FSACTL_FORCE_DELETE_DISK:
1873 return force_delete_disk(dev, arg);
1874 case FSACTL_GET_CONTAINERS:
1875 return aac_get_containers(dev);
1884 * @context: the context set in the fib - here it is scsi cmd
1885 * @fibptr: pointer to the fib
1887 * Handles the completion of a scsi command to a non dasd device
1891 static void aac_srb_callback(void *context, struct fib * fibptr)
1893 struct aac_dev *dev;
1894 struct aac_srb_reply *srbreply;
1895 struct scsi_cmnd *scsicmd;
1897 scsicmd = (struct scsi_cmnd *) context;
1898 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1899 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1904 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1906 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
1908 * Calculate resid for sg
1911 scsicmd->resid = scsicmd->request_bufflen -
1912 le32_to_cpu(srbreply->data_xfer_length);
1915 pci_unmap_sg(dev->pdev,
1916 (struct scatterlist *)scsicmd->buffer,
1918 scsicmd->sc_data_direction);
1919 else if(scsicmd->request_bufflen)
1920 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
1921 scsicmd->sc_data_direction);
1924 * First check the fib status
1927 if (le32_to_cpu(srbreply->status) != ST_OK){
1929 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1930 len = (le32_to_cpu(srbreply->sense_data_size) >
1931 sizeof(scsicmd->sense_buffer)) ?
1932 sizeof(scsicmd->sense_buffer) :
1933 le32_to_cpu(srbreply->sense_data_size);
1934 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1935 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1939 * Next check the srb status
1941 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1942 case SRB_STATUS_ERROR_RECOVERY:
1943 case SRB_STATUS_PENDING:
1944 case SRB_STATUS_SUCCESS:
1945 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1947 case SRB_STATUS_DATA_OVERRUN:
1948 switch(scsicmd->cmnd[0]){
1957 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1958 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1960 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1962 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1965 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1969 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1973 case SRB_STATUS_ABORTED:
1974 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
1976 case SRB_STATUS_ABORT_FAILED:
1977 // Not sure about this one - but assuming the hba was trying to abort for some reason
1978 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
1980 case SRB_STATUS_PARITY_ERROR:
1981 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
1983 case SRB_STATUS_NO_DEVICE:
1984 case SRB_STATUS_INVALID_PATH_ID:
1985 case SRB_STATUS_INVALID_TARGET_ID:
1986 case SRB_STATUS_INVALID_LUN:
1987 case SRB_STATUS_SELECTION_TIMEOUT:
1988 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1991 case SRB_STATUS_COMMAND_TIMEOUT:
1992 case SRB_STATUS_TIMEOUT:
1993 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
1996 case SRB_STATUS_BUSY:
1997 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2000 case SRB_STATUS_BUS_RESET:
2001 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2004 case SRB_STATUS_MESSAGE_REJECTED:
2005 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2007 case SRB_STATUS_REQUEST_FLUSHED:
2008 case SRB_STATUS_ERROR:
2009 case SRB_STATUS_INVALID_REQUEST:
2010 case SRB_STATUS_REQUEST_SENSE_FAILED:
2011 case SRB_STATUS_NO_HBA:
2012 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2013 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2014 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2015 case SRB_STATUS_DELAYED_RETRY:
2016 case SRB_STATUS_BAD_FUNCTION:
2017 case SRB_STATUS_NOT_STARTED:
2018 case SRB_STATUS_NOT_IN_USE:
2019 case SRB_STATUS_FORCE_ABORT:
2020 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2022 #ifdef AAC_DETAILED_STATUS_INFO
2023 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2024 le32_to_cpu(srbreply->srb_status) & 0x3F,
2025 aac_get_status_string(
2026 le32_to_cpu(srbreply->srb_status) & 0x3F),
2028 le32_to_cpu(srbreply->scsi_status));
2030 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2033 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2035 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2036 len = (le32_to_cpu(srbreply->sense_data_size) >
2037 sizeof(scsicmd->sense_buffer)) ?
2038 sizeof(scsicmd->sense_buffer) :
2039 le32_to_cpu(srbreply->sense_data_size);
2040 #ifdef AAC_DETAILED_STATUS_INFO
2041 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2042 le32_to_cpu(srbreply->status), len);
2044 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2048 * OR in the scsi status (already shifted up a bit)
2050 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2052 aac_fib_complete(fibptr);
2053 aac_fib_free(fibptr);
2054 scsicmd->scsi_done(scsicmd);
2060 * @scsicmd: the scsi command block
2062 * This routine will form a FIB and fill in the aac_srb from the
2063 * scsicmd passed in.
2066 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2068 struct fib* cmd_fibcontext;
2069 struct aac_dev* dev;
2071 struct aac_srb *srbcmd;
2076 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2077 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2078 scsicmd->device->lun > 7) {
2079 scsicmd->result = DID_NO_CONNECT << 16;
2080 scsicmd->scsi_done(scsicmd);
2084 switch(scsicmd->sc_data_direction){
2088 case DMA_BIDIRECTIONAL:
2089 flag = SRB_DataIn | SRB_DataOut;
2091 case DMA_FROM_DEVICE:
2095 default: /* shuts up some versions of gcc */
2096 flag = SRB_NoDataXfer;
2102 * Allocate and initialize a Fib then setup a BlockWrite command
2104 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2107 aac_fib_init(cmd_fibcontext);
2109 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
2110 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
2111 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(scsicmd)));
2112 srbcmd->id = cpu_to_le32(scmd_id(scsicmd));
2113 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
2114 srbcmd->flags = cpu_to_le32(flag);
2115 timeout = scsicmd->timeout_per_command/HZ;
2119 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
2120 srbcmd->retry_limit = 0; /* Obsolete parameter */
2121 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
2123 if( dev->dac_support == 1 ) {
2124 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
2125 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2127 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2128 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2130 * Build Scatter/Gather list
2132 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
2133 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
2134 sizeof (struct sgentry64));
2135 BUG_ON (fibsize > (dev->max_fib_size -
2136 sizeof(struct aac_fibhdr)));
2139 * Now send the Fib to the adapter
2141 status = aac_fib_send(ScsiPortCommand64, cmd_fibcontext,
2142 fibsize, FsaNormal, 0, 1,
2143 (fib_callback) aac_srb_callback,
2146 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
2147 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2149 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2150 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2152 * Build Scatter/Gather list
2154 fibsize = sizeof (struct aac_srb) +
2155 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
2156 sizeof (struct sgentry));
2157 BUG_ON (fibsize > (dev->max_fib_size -
2158 sizeof(struct aac_fibhdr)));
2161 * Now send the Fib to the adapter
2163 status = aac_fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
2164 (fib_callback) aac_srb_callback, (void *) scsicmd);
2167 * Check that the command queued to the controller
2169 if (status == -EINPROGRESS) {
2170 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2174 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2175 aac_fib_complete(cmd_fibcontext);
2176 aac_fib_free(cmd_fibcontext);
2181 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2183 struct aac_dev *dev;
2184 unsigned long byte_count = 0;
2186 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2187 // Get rid of old data
2189 psg->sg[0].addr = 0;
2190 psg->sg[0].count = 0;
2191 if (scsicmd->use_sg) {
2192 struct scatterlist *sg;
2195 sg = (struct scatterlist *) scsicmd->request_buffer;
2197 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2198 scsicmd->sc_data_direction);
2199 psg->count = cpu_to_le32(sg_count);
2201 for (i = 0; i < sg_count; i++) {
2202 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2203 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2204 byte_count += sg_dma_len(sg);
2207 /* hba wants the size to be exact */
2208 if(byte_count > scsicmd->request_bufflen){
2209 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2210 (byte_count - scsicmd->request_bufflen);
2211 psg->sg[i-1].count = cpu_to_le32(temp);
2212 byte_count = scsicmd->request_bufflen;
2214 /* Check for command underflow */
2215 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2216 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2217 byte_count, scsicmd->underflow);
2220 else if(scsicmd->request_bufflen) {
2222 addr = pci_map_single(dev->pdev,
2223 scsicmd->request_buffer,
2224 scsicmd->request_bufflen,
2225 scsicmd->sc_data_direction);
2226 psg->count = cpu_to_le32(1);
2227 psg->sg[0].addr = cpu_to_le32(addr);
2228 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2229 scsicmd->SCp.dma_handle = addr;
2230 byte_count = scsicmd->request_bufflen;
2236 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2238 struct aac_dev *dev;
2239 unsigned long byte_count = 0;
2242 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2243 // Get rid of old data
2245 psg->sg[0].addr[0] = 0;
2246 psg->sg[0].addr[1] = 0;
2247 psg->sg[0].count = 0;
2248 if (scsicmd->use_sg) {
2249 struct scatterlist *sg;
2252 sg = (struct scatterlist *) scsicmd->request_buffer;
2254 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2255 scsicmd->sc_data_direction);
2257 for (i = 0; i < sg_count; i++) {
2258 int count = sg_dma_len(sg);
2259 addr = sg_dma_address(sg);
2260 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2261 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2262 psg->sg[i].count = cpu_to_le32(count);
2263 byte_count += count;
2266 psg->count = cpu_to_le32(sg_count);
2267 /* hba wants the size to be exact */
2268 if(byte_count > scsicmd->request_bufflen){
2269 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2270 (byte_count - scsicmd->request_bufflen);
2271 psg->sg[i-1].count = cpu_to_le32(temp);
2272 byte_count = scsicmd->request_bufflen;
2274 /* Check for command underflow */
2275 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2276 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2277 byte_count, scsicmd->underflow);
2280 else if(scsicmd->request_bufflen) {
2281 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2282 scsicmd->request_buffer,
2283 scsicmd->request_bufflen,
2284 scsicmd->sc_data_direction);
2285 addr = scsicmd->SCp.dma_handle;
2286 psg->count = cpu_to_le32(1);
2287 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2288 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2289 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2290 byte_count = scsicmd->request_bufflen;
2295 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2297 struct Scsi_Host *host = scsicmd->device->host;
2298 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2299 unsigned long byte_count = 0;
2301 // Get rid of old data
2303 psg->sg[0].next = 0;
2304 psg->sg[0].prev = 0;
2305 psg->sg[0].addr[0] = 0;
2306 psg->sg[0].addr[1] = 0;
2307 psg->sg[0].count = 0;
2308 psg->sg[0].flags = 0;
2309 if (scsicmd->use_sg) {
2310 struct scatterlist *sg;
2313 sg = (struct scatterlist *) scsicmd->request_buffer;
2315 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2316 scsicmd->sc_data_direction);
2318 for (i = 0; i < sg_count; i++) {
2319 int count = sg_dma_len(sg);
2320 u64 addr = sg_dma_address(sg);
2321 psg->sg[i].next = 0;
2322 psg->sg[i].prev = 0;
2323 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2324 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2325 psg->sg[i].count = cpu_to_le32(count);
2326 psg->sg[i].flags = 0;
2327 byte_count += count;
2330 psg->count = cpu_to_le32(sg_count);
2331 /* hba wants the size to be exact */
2332 if(byte_count > scsicmd->request_bufflen){
2333 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2334 (byte_count - scsicmd->request_bufflen);
2335 psg->sg[i-1].count = cpu_to_le32(temp);
2336 byte_count = scsicmd->request_bufflen;
2338 /* Check for command underflow */
2339 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2340 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2341 byte_count, scsicmd->underflow);
2344 else if(scsicmd->request_bufflen) {
2347 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2348 scsicmd->request_buffer,
2349 scsicmd->request_bufflen,
2350 scsicmd->sc_data_direction);
2351 addr = scsicmd->SCp.dma_handle;
2352 count = scsicmd->request_bufflen;
2353 psg->count = cpu_to_le32(1);
2354 psg->sg[0].next = 0;
2355 psg->sg[0].prev = 0;
2356 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2357 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2358 psg->sg[0].count = cpu_to_le32(count);
2359 psg->sg[0].flags = 0;
2360 byte_count = scsicmd->request_bufflen;
2365 #ifdef AAC_DETAILED_STATUS_INFO
2367 struct aac_srb_status_info {
2373 static struct aac_srb_status_info srb_status_info[] = {
2374 { SRB_STATUS_PENDING, "Pending Status"},
2375 { SRB_STATUS_SUCCESS, "Success"},
2376 { SRB_STATUS_ABORTED, "Aborted Command"},
2377 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2378 { SRB_STATUS_ERROR, "Error Event"},
2379 { SRB_STATUS_BUSY, "Device Busy"},
2380 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2381 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2382 { SRB_STATUS_NO_DEVICE, "No Device"},
2383 { SRB_STATUS_TIMEOUT, "Timeout"},
2384 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2385 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2386 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2387 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2388 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2389 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2390 { SRB_STATUS_NO_HBA, "No HBA"},
2391 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2392 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2393 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2394 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2395 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2396 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2397 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2398 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2399 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2400 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2401 { SRB_STATUS_NOT_STARTED, "Not Started"},
2402 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2403 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2404 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2405 { 0xff, "Unknown Error"}
2408 char *aac_get_status_string(u32 status)
2412 for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
2413 if(srb_status_info[i].status == status){
2414 return srb_status_info[i].str;
2418 return "Bad Status Code";