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;
151 int startup_timeout = 180;
152 int aif_timeout = 120;
154 module_param(nondasd, int, S_IRUGO|S_IWUSR);
155 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
156 module_param(dacmode, int, S_IRUGO|S_IWUSR);
157 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
158 module_param(commit, int, S_IRUGO|S_IWUSR);
159 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(startup_timeout, int, S_IRUGO|S_IWUSR);
161 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for adapter to have it's kernel up and\nrunning. This is typically adjusted for large systems that do not have a BIOS.");
162 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
163 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for applications to pick up AIFs before\nderegistering them. This is typically adjusted for heavily burdened systems.");
166 module_param(numacb, int, S_IRUGO|S_IWUSR);
167 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.");
170 module_param(acbsize, int, S_IRUGO|S_IWUSR);
171 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.");
173 * aac_get_config_status - check the adapter configuration
174 * @common: adapter to query
176 * Query config status, and commit the configuration if needed.
178 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
183 if (!(fibptr = aac_fib_alloc(dev)))
186 aac_fib_init(fibptr);
188 struct aac_get_config_status *dinfo;
189 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
191 dinfo->command = cpu_to_le32(VM_ContainerConfig);
192 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
193 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
196 status = aac_fib_send(ContainerCommand,
198 sizeof (struct aac_get_config_status),
203 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
205 struct aac_get_config_status_resp *reply
206 = (struct aac_get_config_status_resp *) fib_data(fibptr);
207 dprintk((KERN_WARNING
208 "aac_get_config_status: response=%d status=%d action=%d\n",
209 le32_to_cpu(reply->response),
210 le32_to_cpu(reply->status),
211 le32_to_cpu(reply->data.action)));
212 if ((le32_to_cpu(reply->response) != ST_OK) ||
213 (le32_to_cpu(reply->status) != CT_OK) ||
214 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
215 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
219 aac_fib_complete(fibptr);
220 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
222 if ((commit == 1) || commit_flag) {
223 struct aac_commit_config * dinfo;
224 aac_fib_init(fibptr);
225 dinfo = (struct aac_commit_config *) fib_data(fibptr);
227 dinfo->command = cpu_to_le32(VM_ContainerConfig);
228 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
230 status = aac_fib_send(ContainerCommand,
232 sizeof (struct aac_commit_config),
236 aac_fib_complete(fibptr);
237 } else if (commit == 0) {
239 "aac_get_config_status: Foreign device configurations are being ignored\n");
242 aac_fib_free(fibptr);
247 * aac_get_containers - list containers
248 * @common: adapter to probe
250 * Make a list of all containers on this controller
252 int aac_get_containers(struct aac_dev *dev)
254 struct fsa_dev_info *fsa_dev_ptr;
259 struct aac_get_container_count *dinfo;
260 struct aac_get_container_count_resp *dresp;
261 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
263 instance = dev->scsi_host_ptr->unique_id;
265 if (!(fibptr = aac_fib_alloc(dev)))
268 aac_fib_init(fibptr);
269 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
270 dinfo->command = cpu_to_le32(VM_ContainerConfig);
271 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
273 status = aac_fib_send(ContainerCommand,
275 sizeof (struct aac_get_container_count),
280 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
281 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
282 aac_fib_complete(fibptr);
285 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
286 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
287 fsa_dev_ptr = (struct fsa_dev_info *) kmalloc(
288 sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL);
290 aac_fib_free(fibptr);
293 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
295 dev->fsa_dev = fsa_dev_ptr;
296 dev->maximum_num_containers = maximum_num_containers;
298 for (index = 0; index < dev->maximum_num_containers; index++) {
299 struct aac_query_mount *dinfo;
300 struct aac_mount *dresp;
302 fsa_dev_ptr[index].devname[0] = '\0';
304 aac_fib_init(fibptr);
305 dinfo = (struct aac_query_mount *) fib_data(fibptr);
307 dinfo->command = cpu_to_le32(VM_NameServe);
308 dinfo->count = cpu_to_le32(index);
309 dinfo->type = cpu_to_le32(FT_FILESYS);
311 status = aac_fib_send(ContainerCommand,
313 sizeof (struct aac_query_mount),
318 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
321 dresp = (struct aac_mount *)fib_data(fibptr);
323 if ((le32_to_cpu(dresp->status) == ST_OK) &&
324 (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
325 dinfo->command = cpu_to_le32(VM_NameServe64);
326 dinfo->count = cpu_to_le32(index);
327 dinfo->type = cpu_to_le32(FT_FILESYS);
329 if (aac_fib_send(ContainerCommand,
331 sizeof(struct aac_query_mount),
337 dresp->mnt[0].capacityhigh = 0;
340 "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%llu\n",
341 (int)index, (int)le32_to_cpu(dresp->status),
342 (int)le32_to_cpu(dresp->mnt[0].vol),
343 (int)le32_to_cpu(dresp->mnt[0].state),
344 ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
345 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32)));
346 if ((le32_to_cpu(dresp->status) == ST_OK) &&
347 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
348 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
349 fsa_dev_ptr[index].valid = 1;
350 fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
351 fsa_dev_ptr[index].size
352 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
353 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
354 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
355 fsa_dev_ptr[index].ro = 1;
357 aac_fib_complete(fibptr);
359 * If there are no more containers, then stop asking.
361 if ((index + 1) >= le32_to_cpu(dresp->count)){
365 aac_fib_free(fibptr);
369 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
372 unsigned int transfer_len;
373 struct scatterlist *sg = scsicmd->request_buffer;
375 if (scsicmd->use_sg) {
376 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
377 transfer_len = min(sg->length, len + offset);
379 buf = scsicmd->request_buffer;
380 transfer_len = min(scsicmd->request_bufflen, len + offset);
383 memcpy(buf + offset, data, transfer_len - offset);
386 kunmap_atomic(buf - sg->offset, KM_IRQ0);
390 static void get_container_name_callback(void *context, struct fib * fibptr)
392 struct aac_get_name_resp * get_name_reply;
393 struct scsi_cmnd * scsicmd;
395 scsicmd = (struct scsi_cmnd *) context;
396 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
398 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
399 BUG_ON(fibptr == NULL);
401 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
402 /* Failure is irrelevant, using default value instead */
403 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
404 && (get_name_reply->data[0] != '\0')) {
405 char *sp = get_name_reply->data;
406 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
410 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
411 int count = sizeof(d);
414 *dp++ = (*sp) ? *sp++ : ' ';
415 } while (--count > 0);
416 aac_internal_transfer(scsicmd, d,
417 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
421 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
423 aac_fib_complete(fibptr);
424 aac_fib_free(fibptr);
425 scsicmd->scsi_done(scsicmd);
429 * aac_get_container_name - get container name, none blocking.
431 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
434 struct aac_get_name *dinfo;
435 struct fib * cmd_fibcontext;
436 struct aac_dev * dev;
438 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
440 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
443 aac_fib_init(cmd_fibcontext);
444 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
446 dinfo->command = cpu_to_le32(VM_ContainerConfig);
447 dinfo->type = cpu_to_le32(CT_READ_NAME);
448 dinfo->cid = cpu_to_le32(cid);
449 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
451 status = aac_fib_send(ContainerCommand,
453 sizeof (struct aac_get_name),
456 (fib_callback) get_container_name_callback,
460 * Check that the command queued to the controller
462 if (status == -EINPROGRESS) {
463 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
467 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
468 aac_fib_complete(cmd_fibcontext);
469 aac_fib_free(cmd_fibcontext);
474 * aac_probe_container - query a logical volume
475 * @dev: device to query
476 * @cid: container identifier
478 * Queries the controller about the given volume. The volume information
479 * is updated in the struct fsa_dev_info structure rather than returned.
482 int aac_probe_container(struct aac_dev *dev, int cid)
484 struct fsa_dev_info *fsa_dev_ptr;
486 struct aac_query_mount *dinfo;
487 struct aac_mount *dresp;
491 fsa_dev_ptr = dev->fsa_dev;
494 instance = dev->scsi_host_ptr->unique_id;
496 if (!(fibptr = aac_fib_alloc(dev)))
499 aac_fib_init(fibptr);
501 dinfo = (struct aac_query_mount *)fib_data(fibptr);
503 dinfo->command = cpu_to_le32(VM_NameServe);
504 dinfo->count = cpu_to_le32(cid);
505 dinfo->type = cpu_to_le32(FT_FILESYS);
507 status = aac_fib_send(ContainerCommand,
509 sizeof(struct aac_query_mount),
514 printk(KERN_WARNING "aacraid: aac_probe_container query failed.\n");
518 dresp = (struct aac_mount *) fib_data(fibptr);
520 if ((le32_to_cpu(dresp->status) == ST_OK) &&
521 (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
522 dinfo->command = cpu_to_le32(VM_NameServe64);
523 dinfo->count = cpu_to_le32(cid);
524 dinfo->type = cpu_to_le32(FT_FILESYS);
526 if (aac_fib_send(ContainerCommand,
528 sizeof(struct aac_query_mount),
534 dresp->mnt[0].capacityhigh = 0;
536 if ((le32_to_cpu(dresp->status) == ST_OK) &&
537 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
538 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
539 fsa_dev_ptr[cid].valid = 1;
540 fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
541 fsa_dev_ptr[cid].size
542 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
543 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
544 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
545 fsa_dev_ptr[cid].ro = 1;
549 aac_fib_complete(fibptr);
550 aac_fib_free(fibptr);
555 /* Local Structure to set SCSI inquiry data strings */
557 char vid[8]; /* Vendor ID */
558 char pid[16]; /* Product ID */
559 char prl[4]; /* Product Revision Level */
563 * InqStrCopy - string merge
564 * @a: string to copy from
565 * @b: string to copy to
567 * Copy a String from one location to another
571 static void inqstrcpy(char *a, char *b)
578 static char *container_types[] = {
604 /* Function: setinqstr
606 * Arguments: [1] pointer to void [1] int
608 * Purpose: Sets SCSI inquiry data strings for vendor, product
609 * and revision level. Allows strings to be set in platform dependant
610 * files instead of in OS dependant driver source.
613 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
615 struct scsi_inq *str;
617 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
618 memset(str, ' ', sizeof(*str));
620 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
621 char * cp = dev->supplement_adapter_info.AdapterTypeText;
622 int c = sizeof(str->vid);
623 while (*cp && *cp != ' ' && --c)
627 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
630 while (*cp && *cp != ' ')
634 /* last six chars reserved for vol type */
636 if (strlen(cp) > sizeof(str->pid)) {
637 c = cp[sizeof(str->pid)];
638 cp[sizeof(str->pid)] = '\0';
640 inqstrcpy (cp, str->pid);
642 cp[sizeof(str->pid)] = c;
644 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
646 inqstrcpy (mp->vname, str->vid);
647 /* last six chars reserved for vol type */
648 inqstrcpy (mp->model, str->pid);
651 if (tindex < ARRAY_SIZE(container_types)){
652 char *findit = str->pid;
654 for ( ; *findit != ' '; findit++); /* walk till we find a space */
655 /* RAID is superfluous in the context of a RAID device */
656 if (memcmp(findit-4, "RAID", 4) == 0)
657 *(findit -= 4) = ' ';
658 if (((findit - str->pid) + strlen(container_types[tindex]))
659 < (sizeof(str->pid) + sizeof(str->prl)))
660 inqstrcpy (container_types[tindex], findit + 1);
662 inqstrcpy ("V1.0", str->prl);
665 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
666 u8 a_sense_code, u8 incorrect_length,
667 u8 bit_pointer, u16 field_pointer,
670 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
671 sense_buf[1] = 0; /* Segment number, always zero */
673 if (incorrect_length) {
674 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
675 sense_buf[3] = BYTE3(residue);
676 sense_buf[4] = BYTE2(residue);
677 sense_buf[5] = BYTE1(residue);
678 sense_buf[6] = BYTE0(residue);
680 sense_buf[2] = sense_key; /* Sense key */
682 if (sense_key == ILLEGAL_REQUEST)
683 sense_buf[7] = 10; /* Additional sense length */
685 sense_buf[7] = 6; /* Additional sense length */
687 sense_buf[12] = sense_code; /* Additional sense code */
688 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
689 if (sense_key == ILLEGAL_REQUEST) {
692 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
693 sense_buf[15] = 0x80;/* Std sense key specific field */
694 /* Illegal parameter is in the parameter block */
696 if (sense_code == SENCODE_INVALID_CDB_FIELD)
697 sense_buf[15] = 0xc0;/* Std sense key specific field */
698 /* Illegal parameter is in the CDB block */
699 sense_buf[15] |= bit_pointer;
700 sense_buf[16] = field_pointer >> 8; /* MSB */
701 sense_buf[17] = field_pointer; /* LSB */
705 int aac_get_adapter_info(struct aac_dev* dev)
710 struct aac_adapter_info *info;
711 struct aac_bus_info *command;
712 struct aac_bus_info_response *bus_info;
714 if (!(fibptr = aac_fib_alloc(dev)))
717 aac_fib_init(fibptr);
718 info = (struct aac_adapter_info *) fib_data(fibptr);
719 memset(info,0,sizeof(*info));
721 rcode = aac_fib_send(RequestAdapterInfo,
725 -1, 1, /* First `interrupt' command uses special wait */
730 aac_fib_complete(fibptr);
731 aac_fib_free(fibptr);
734 memcpy(&dev->adapter_info, info, sizeof(*info));
736 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
737 struct aac_supplement_adapter_info * info;
739 aac_fib_init(fibptr);
741 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
743 memset(info,0,sizeof(*info));
745 rcode = aac_fib_send(RequestSupplementAdapterInfo,
754 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
762 aac_fib_init(fibptr);
764 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
766 memset(bus_info, 0, sizeof(*bus_info));
768 command = (struct aac_bus_info *)bus_info;
770 command->Command = cpu_to_le32(VM_Ioctl);
771 command->ObjType = cpu_to_le32(FT_DRIVE);
772 command->MethodId = cpu_to_le32(1);
773 command->CtlCmd = cpu_to_le32(GetBusInfo);
775 rcode = aac_fib_send(ContainerCommand,
782 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
783 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
784 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
787 if (!dev->in_reset) {
788 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
789 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
795 le32_to_cpu(dev->adapter_info.kernelbuild),
796 (int)sizeof(dev->supplement_adapter_info.BuildDate),
797 dev->supplement_adapter_info.BuildDate);
798 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
799 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
801 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
802 le32_to_cpu(dev->adapter_info.monitorbuild));
803 tmp = le32_to_cpu(dev->adapter_info.biosrev);
804 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
806 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
807 le32_to_cpu(dev->adapter_info.biosbuild));
808 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
809 printk(KERN_INFO "%s%d: serial %x\n",
811 le32_to_cpu(dev->adapter_info.serial[0]));
814 dev->nondasd_support = 0;
815 dev->raid_scsi_mode = 0;
816 if(dev->adapter_info.options & AAC_OPT_NONDASD){
817 dev->nondasd_support = 1;
821 * If the firmware supports ROMB RAID/SCSI mode and we are currently
822 * in RAID/SCSI mode, set the flag. For now if in this mode we will
823 * force nondasd support on. If we decide to allow the non-dasd flag
824 * additional changes changes will have to be made to support
825 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
826 * changed to support the new dev->raid_scsi_mode flag instead of
827 * leaching off of the dev->nondasd_support flag. Also in linit.c the
828 * function aac_detect will have to be modified where it sets up the
829 * max number of channels based on the aac->nondasd_support flag only.
831 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
832 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
833 dev->nondasd_support = 1;
834 dev->raid_scsi_mode = 1;
836 if (dev->raid_scsi_mode != 0)
837 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
841 dev->nondasd_support = (nondasd!=0);
843 if(dev->nondasd_support != 0){
844 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
847 dev->dac_support = 0;
848 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
849 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
850 dev->dac_support = 1;
854 dev->dac_support = (dacmode!=0);
856 if(dev->dac_support != 0) {
857 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
858 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
859 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
861 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
862 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
863 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
865 dev->dac_support = 0;
867 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
873 * 57 scatter gather elements
875 if (!(dev->raw_io_interface)) {
876 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
877 sizeof(struct aac_fibhdr) -
878 sizeof(struct aac_write) + sizeof(struct sgentry)) /
879 sizeof(struct sgentry);
880 if (dev->dac_support) {
882 * 38 scatter gather elements
884 dev->scsi_host_ptr->sg_tablesize =
886 sizeof(struct aac_fibhdr) -
887 sizeof(struct aac_write64) +
888 sizeof(struct sgentry64)) /
889 sizeof(struct sgentry64);
891 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
892 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
894 * Worst case size that could cause sg overflow when
895 * we break up SG elements that are larger than 64KB.
896 * Would be nice if we could tell the SCSI layer what
897 * the maximum SG element size can be. Worst case is
898 * (sg_tablesize-1) 4KB elements with one 64KB
900 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
902 dev->scsi_host_ptr->max_sectors =
903 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
907 aac_fib_complete(fibptr);
908 aac_fib_free(fibptr);
914 static void io_callback(void *context, struct fib * fibptr)
917 struct aac_read_reply *readreply;
918 struct scsi_cmnd *scsicmd;
921 scsicmd = (struct scsi_cmnd *) context;
922 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
924 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
925 cid = scmd_id(scsicmd);
927 if (nblank(dprintk(x))) {
929 switch (scsicmd->cmnd[0]) {
932 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
933 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
937 lba = ((u64)scsicmd->cmnd[2] << 56) |
938 ((u64)scsicmd->cmnd[3] << 48) |
939 ((u64)scsicmd->cmnd[4] << 40) |
940 ((u64)scsicmd->cmnd[5] << 32) |
941 ((u64)scsicmd->cmnd[6] << 24) |
942 (scsicmd->cmnd[7] << 16) |
943 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
947 lba = ((u64)scsicmd->cmnd[2] << 24) |
948 (scsicmd->cmnd[3] << 16) |
949 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
952 lba = ((u64)scsicmd->cmnd[2] << 24) |
953 (scsicmd->cmnd[3] << 16) |
954 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
958 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
959 smp_processor_id(), (unsigned long long)lba, jiffies);
962 BUG_ON(fibptr == NULL);
965 pci_unmap_sg(dev->pdev,
966 (struct scatterlist *)scsicmd->request_buffer,
968 scsicmd->sc_data_direction);
969 else if(scsicmd->request_bufflen)
970 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
971 scsicmd->request_bufflen,
972 scsicmd->sc_data_direction);
973 readreply = (struct aac_read_reply *)fib_data(fibptr);
974 if (le32_to_cpu(readreply->status) == ST_OK)
975 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
977 #ifdef AAC_DETAILED_STATUS_INFO
978 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
979 le32_to_cpu(readreply->status));
981 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
982 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
984 SENCODE_INTERNAL_TARGET_FAILURE,
985 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
987 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
988 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
989 ? sizeof(scsicmd->sense_buffer)
990 : sizeof(dev->fsa_dev[cid].sense_data));
992 aac_fib_complete(fibptr);
993 aac_fib_free(fibptr);
995 scsicmd->scsi_done(scsicmd);
998 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
1005 struct aac_dev *dev;
1006 struct fib * cmd_fibcontext;
1008 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1010 * Get block address and transfer length
1012 switch (scsicmd->cmnd[0]) {
1014 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
1016 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1017 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1018 count = scsicmd->cmnd[4];
1024 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", cid));
1026 lba = ((u64)scsicmd->cmnd[2] << 56) |
1027 ((u64)scsicmd->cmnd[3] << 48) |
1028 ((u64)scsicmd->cmnd[4] << 40) |
1029 ((u64)scsicmd->cmnd[5] << 32) |
1030 ((u64)scsicmd->cmnd[6] << 24) |
1031 (scsicmd->cmnd[7] << 16) |
1032 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1033 count = (scsicmd->cmnd[10] << 24) |
1034 (scsicmd->cmnd[11] << 16) |
1035 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1038 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", cid));
1040 lba = ((u64)scsicmd->cmnd[2] << 24) |
1041 (scsicmd->cmnd[3] << 16) |
1042 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1043 count = (scsicmd->cmnd[6] << 24) |
1044 (scsicmd->cmnd[7] << 16) |
1045 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1048 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
1050 lba = ((u64)scsicmd->cmnd[2] << 24) |
1051 (scsicmd->cmnd[3] << 16) |
1052 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1053 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1056 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1057 smp_processor_id(), (unsigned long long)lba, jiffies));
1058 if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) &&
1059 (lba & 0xffffffff00000000LL)) {
1060 dprintk((KERN_DEBUG "aac_read: Illegal lba\n"));
1061 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1062 SAM_STAT_CHECK_CONDITION;
1063 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1065 SENCODE_INTERNAL_TARGET_FAILURE,
1066 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1068 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1069 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1070 ? sizeof(scsicmd->sense_buffer)
1071 : sizeof(dev->fsa_dev[cid].sense_data));
1072 scsicmd->scsi_done(scsicmd);
1076 * Alocate and initialize a Fib
1078 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1082 aac_fib_init(cmd_fibcontext);
1084 if (dev->raw_io_interface) {
1085 struct aac_raw_io *readcmd;
1086 readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1087 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1088 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1089 readcmd->count = cpu_to_le32(count<<9);
1090 readcmd->cid = cpu_to_le16(cid);
1091 readcmd->flags = cpu_to_le16(1);
1092 readcmd->bpTotal = 0;
1093 readcmd->bpComplete = 0;
1095 aac_build_sgraw(scsicmd, &readcmd->sg);
1096 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
1097 BUG_ON(fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)));
1099 * Now send the Fib to the adapter
1101 status = aac_fib_send(ContainerRawIo,
1106 (fib_callback) io_callback,
1108 } else if (dev->dac_support == 1) {
1109 struct aac_read64 *readcmd;
1110 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
1111 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1112 readcmd->cid = cpu_to_le16(cid);
1113 readcmd->sector_count = cpu_to_le16(count);
1114 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1118 aac_build_sg64(scsicmd, &readcmd->sg);
1119 fibsize = sizeof(struct aac_read64) +
1120 ((le32_to_cpu(readcmd->sg.count) - 1) *
1121 sizeof (struct sgentry64));
1122 BUG_ON (fibsize > (dev->max_fib_size -
1123 sizeof(struct aac_fibhdr)));
1125 * Now send the Fib to the adapter
1127 status = aac_fib_send(ContainerCommand64,
1132 (fib_callback) io_callback,
1135 struct aac_read *readcmd;
1136 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
1137 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1138 readcmd->cid = cpu_to_le32(cid);
1139 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1140 readcmd->count = cpu_to_le32(count * 512);
1142 aac_build_sg(scsicmd, &readcmd->sg);
1143 fibsize = sizeof(struct aac_read) +
1144 ((le32_to_cpu(readcmd->sg.count) - 1) *
1145 sizeof (struct sgentry));
1146 BUG_ON (fibsize > (dev->max_fib_size -
1147 sizeof(struct aac_fibhdr)));
1149 * Now send the Fib to the adapter
1151 status = aac_fib_send(ContainerCommand,
1156 (fib_callback) io_callback,
1163 * Check that the command queued to the controller
1165 if (status == -EINPROGRESS) {
1166 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1170 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1172 * For some reason, the Fib didn't queue, return QUEUE_FULL
1174 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1175 scsicmd->scsi_done(scsicmd);
1176 aac_fib_complete(cmd_fibcontext);
1177 aac_fib_free(cmd_fibcontext);
1181 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1187 struct aac_dev *dev;
1188 struct fib * cmd_fibcontext;
1190 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1192 * Get block address and transfer length
1194 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1196 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1197 count = scsicmd->cmnd[4];
1200 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1201 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", cid));
1203 lba = ((u64)scsicmd->cmnd[2] << 56) |
1204 ((u64)scsicmd->cmnd[3] << 48) |
1205 ((u64)scsicmd->cmnd[4] << 40) |
1206 ((u64)scsicmd->cmnd[5] << 32) |
1207 ((u64)scsicmd->cmnd[6] << 24) |
1208 (scsicmd->cmnd[7] << 16) |
1209 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1210 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1211 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1212 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1213 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", cid));
1215 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1216 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1217 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1218 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1220 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
1221 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1222 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1224 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1225 smp_processor_id(), (unsigned long long)lba, jiffies));
1226 if ((!(dev->raw_io_interface) || !(dev->raw_io_64))
1227 && (lba & 0xffffffff00000000LL)) {
1228 dprintk((KERN_DEBUG "aac_write: Illegal lba\n"));
1229 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1230 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1232 SENCODE_INTERNAL_TARGET_FAILURE,
1233 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1235 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1236 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1237 ? sizeof(scsicmd->sense_buffer)
1238 : sizeof(dev->fsa_dev[cid].sense_data));
1239 scsicmd->scsi_done(scsicmd);
1243 * Allocate and initialize a Fib then setup a BlockWrite command
1245 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1246 scsicmd->result = DID_ERROR << 16;
1247 scsicmd->scsi_done(scsicmd);
1250 aac_fib_init(cmd_fibcontext);
1252 if (dev->raw_io_interface) {
1253 struct aac_raw_io *writecmd;
1254 writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1255 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1256 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1257 writecmd->count = cpu_to_le32(count<<9);
1258 writecmd->cid = cpu_to_le16(cid);
1259 writecmd->flags = 0;
1260 writecmd->bpTotal = 0;
1261 writecmd->bpComplete = 0;
1263 aac_build_sgraw(scsicmd, &writecmd->sg);
1264 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1265 BUG_ON(fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)));
1267 * Now send the Fib to the adapter
1269 status = aac_fib_send(ContainerRawIo,
1274 (fib_callback) io_callback,
1276 } else if (dev->dac_support == 1) {
1277 struct aac_write64 *writecmd;
1278 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1279 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1280 writecmd->cid = cpu_to_le16(cid);
1281 writecmd->sector_count = cpu_to_le16(count);
1282 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1284 writecmd->flags = 0;
1286 aac_build_sg64(scsicmd, &writecmd->sg);
1287 fibsize = sizeof(struct aac_write64) +
1288 ((le32_to_cpu(writecmd->sg.count) - 1) *
1289 sizeof (struct sgentry64));
1290 BUG_ON (fibsize > (dev->max_fib_size -
1291 sizeof(struct aac_fibhdr)));
1293 * Now send the Fib to the adapter
1295 status = aac_fib_send(ContainerCommand64,
1300 (fib_callback) io_callback,
1303 struct aac_write *writecmd;
1304 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
1305 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1306 writecmd->cid = cpu_to_le32(cid);
1307 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1308 writecmd->count = cpu_to_le32(count * 512);
1309 writecmd->sg.count = cpu_to_le32(1);
1310 /* ->stable is not used - it did mean which type of write */
1312 aac_build_sg(scsicmd, &writecmd->sg);
1313 fibsize = sizeof(struct aac_write) +
1314 ((le32_to_cpu(writecmd->sg.count) - 1) *
1315 sizeof (struct sgentry));
1316 BUG_ON (fibsize > (dev->max_fib_size -
1317 sizeof(struct aac_fibhdr)));
1319 * Now send the Fib to the adapter
1321 status = aac_fib_send(ContainerCommand,
1326 (fib_callback) io_callback,
1331 * Check that the command queued to the controller
1333 if (status == -EINPROGRESS) {
1334 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1338 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1340 * For some reason, the Fib didn't queue, return QUEUE_FULL
1342 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1343 scsicmd->scsi_done(scsicmd);
1345 aac_fib_complete(cmd_fibcontext);
1346 aac_fib_free(cmd_fibcontext);
1350 static void synchronize_callback(void *context, struct fib *fibptr)
1352 struct aac_synchronize_reply *synchronizereply;
1353 struct scsi_cmnd *cmd;
1356 cmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1358 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1359 smp_processor_id(), jiffies));
1360 BUG_ON(fibptr == NULL);
1363 synchronizereply = fib_data(fibptr);
1364 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1365 cmd->result = DID_OK << 16 |
1366 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1368 struct scsi_device *sdev = cmd->device;
1369 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1370 u32 cid = sdev_id(sdev);
1372 "synchronize_callback: synchronize failed, status = %d\n",
1373 le32_to_cpu(synchronizereply->status));
1374 cmd->result = DID_OK << 16 |
1375 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1376 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1378 SENCODE_INTERNAL_TARGET_FAILURE,
1379 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1381 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1382 min(sizeof(dev->fsa_dev[cid].sense_data),
1383 sizeof(cmd->sense_buffer)));
1386 aac_fib_complete(fibptr);
1387 aac_fib_free(fibptr);
1388 cmd->scsi_done(cmd);
1391 static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1394 struct fib *cmd_fibcontext;
1395 struct aac_synchronize *synchronizecmd;
1396 struct scsi_cmnd *cmd;
1397 struct scsi_device *sdev = scsicmd->device;
1399 struct aac_dev *aac;
1400 unsigned long flags;
1403 * Wait for all outstanding queued commands to complete to this
1404 * specific target (block).
1406 spin_lock_irqsave(&sdev->list_lock, flags);
1407 list_for_each_entry(cmd, &sdev->cmd_list, list)
1408 if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1413 spin_unlock_irqrestore(&sdev->list_lock, flags);
1416 * Yield the processor (requeue for later)
1419 return SCSI_MLQUEUE_DEVICE_BUSY;
1421 aac = (struct aac_dev *)scsicmd->device->host->hostdata;
1423 return SCSI_MLQUEUE_HOST_BUSY;
1426 * Allocate and initialize a Fib
1428 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1429 return SCSI_MLQUEUE_HOST_BUSY;
1431 aac_fib_init(cmd_fibcontext);
1433 synchronizecmd = fib_data(cmd_fibcontext);
1434 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1435 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1436 synchronizecmd->cid = cpu_to_le32(cid);
1437 synchronizecmd->count =
1438 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1441 * Now send the Fib to the adapter
1443 status = aac_fib_send(ContainerCommand,
1445 sizeof(struct aac_synchronize),
1448 (fib_callback)synchronize_callback,
1452 * Check that the command queued to the controller
1454 if (status == -EINPROGRESS) {
1455 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1460 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1461 aac_fib_complete(cmd_fibcontext);
1462 aac_fib_free(cmd_fibcontext);
1463 return SCSI_MLQUEUE_HOST_BUSY;
1467 * aac_scsi_cmd() - Process SCSI command
1468 * @scsicmd: SCSI command block
1470 * Emulate a SCSI command and queue the required request for the
1474 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1477 struct Scsi_Host *host = scsicmd->device->host;
1478 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1479 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1481 if (fsa_dev_ptr == NULL)
1484 * If the bus, id or lun is out of range, return fail
1485 * Test does not apply to ID 16, the pseudo id for the controller
1488 if (scmd_id(scsicmd) != host->this_id) {
1489 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
1490 if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
1491 (scsicmd->device->lun != 0)) {
1492 scsicmd->result = DID_NO_CONNECT << 16;
1493 scsicmd->scsi_done(scsicmd);
1496 cid = scmd_id(scsicmd);
1499 * If the target container doesn't exist, it may have
1500 * been newly created
1502 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1503 switch (scsicmd->cmnd[0]) {
1504 case SERVICE_ACTION_IN:
1505 if (!(dev->raw_io_interface) ||
1506 !(dev->raw_io_64) ||
1507 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1511 case TEST_UNIT_READY:
1514 spin_unlock_irq(host->host_lock);
1515 aac_probe_container(dev, cid);
1516 if ((fsa_dev_ptr[cid].valid & 1) == 0)
1517 fsa_dev_ptr[cid].valid = 0;
1518 spin_lock_irq(host->host_lock);
1519 if (fsa_dev_ptr[cid].valid == 0) {
1520 scsicmd->result = DID_NO_CONNECT << 16;
1521 scsicmd->scsi_done(scsicmd);
1529 * If the target container still doesn't exist,
1532 if (fsa_dev_ptr[cid].valid == 0) {
1533 scsicmd->result = DID_BAD_TARGET << 16;
1534 scsicmd->scsi_done(scsicmd);
1537 } else { /* check for physical non-dasd devices */
1538 if(dev->nondasd_support == 1){
1541 return aac_send_srb_fib(scsicmd);
1543 scsicmd->result = DID_NO_CONNECT << 16;
1544 scsicmd->scsi_done(scsicmd);
1550 * else Command for the controller itself
1552 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1553 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1555 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1556 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1557 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1559 SENCODE_INVALID_COMMAND,
1560 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1561 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1562 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1563 ? sizeof(scsicmd->sense_buffer)
1564 : sizeof(dev->fsa_dev[cid].sense_data));
1565 scsicmd->scsi_done(scsicmd);
1570 /* Handle commands here that don't really require going out to the adapter */
1571 switch (scsicmd->cmnd[0]) {
1574 struct inquiry_data inq_data;
1576 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
1577 memset(&inq_data, 0, sizeof (struct inquiry_data));
1579 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1580 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 */
1581 inq_data.inqd_len = 31;
1582 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1583 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1585 * Set the Vendor, Product, and Revision Level
1586 * see: <vendor>.c i.e. aac.c
1588 if (scmd_id(scsicmd) == host->this_id) {
1589 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
1590 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1591 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1592 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1593 scsicmd->scsi_done(scsicmd);
1598 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1599 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1600 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1601 return aac_get_container_name(scsicmd, cid);
1603 case SERVICE_ACTION_IN:
1604 if (!(dev->raw_io_interface) ||
1605 !(dev->raw_io_64) ||
1606 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1612 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1613 capacity = fsa_dev_ptr[cid].size - 1;
1614 cp[0] = (capacity >> 56) & 0xff;
1615 cp[1] = (capacity >> 48) & 0xff;
1616 cp[2] = (capacity >> 40) & 0xff;
1617 cp[3] = (capacity >> 32) & 0xff;
1618 cp[4] = (capacity >> 24) & 0xff;
1619 cp[5] = (capacity >> 16) & 0xff;
1620 cp[6] = (capacity >> 8) & 0xff;
1621 cp[7] = (capacity >> 0) & 0xff;
1627 aac_internal_transfer(scsicmd, cp, 0,
1628 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
1629 if (sizeof(cp) < scsicmd->cmnd[13]) {
1630 unsigned int len, offset = sizeof(cp);
1632 memset(cp, 0, offset);
1634 len = min_t(size_t, scsicmd->cmnd[13] - offset,
1636 aac_internal_transfer(scsicmd, cp, offset, len);
1637 } while ((offset += len) < scsicmd->cmnd[13]);
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);
1654 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1655 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
1656 capacity = fsa_dev_ptr[cid].size - 1;
1660 cp[0] = (capacity >> 24) & 0xff;
1661 cp[1] = (capacity >> 16) & 0xff;
1662 cp[2] = (capacity >> 8) & 0xff;
1663 cp[3] = (capacity >> 0) & 0xff;
1668 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1669 /* Do not cache partition table for arrays */
1670 scsicmd->device->removable = 1;
1672 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1673 scsicmd->scsi_done(scsicmd);
1682 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1683 mode_buf[0] = 3; /* Mode data length */
1684 mode_buf[1] = 0; /* Medium type - default */
1685 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1686 mode_buf[3] = 0; /* Block descriptor length */
1688 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1689 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1690 scsicmd->scsi_done(scsicmd);
1698 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1699 mode_buf[0] = 0; /* Mode data length (MSB) */
1700 mode_buf[1] = 6; /* Mode data length (LSB) */
1701 mode_buf[2] = 0; /* Medium type - default */
1702 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1703 mode_buf[4] = 0; /* reserved */
1704 mode_buf[5] = 0; /* reserved */
1705 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1706 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1707 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1709 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1710 scsicmd->scsi_done(scsicmd);
1715 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1716 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1717 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1718 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1719 scsicmd->scsi_done(scsicmd);
1722 case ALLOW_MEDIUM_REMOVAL:
1723 dprintk((KERN_DEBUG "LOCK command.\n"));
1724 if (scsicmd->cmnd[4])
1725 fsa_dev_ptr[cid].locked = 1;
1727 fsa_dev_ptr[cid].locked = 0;
1729 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1730 scsicmd->scsi_done(scsicmd);
1733 * These commands are all No-Ops
1735 case TEST_UNIT_READY:
1739 case REASSIGN_BLOCKS:
1742 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1743 scsicmd->scsi_done(scsicmd);
1747 switch (scsicmd->cmnd[0])
1756 * Hack to keep track of ordinal number of the device that
1757 * corresponds to a container. Needed to convert
1758 * containers to /dev/sd device names
1761 if (scsicmd->request->rq_disk)
1762 strlcpy(fsa_dev_ptr[cid].devname,
1763 scsicmd->request->rq_disk->disk_name,
1764 min(sizeof(fsa_dev_ptr[cid].devname),
1765 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1767 return aac_read(scsicmd, cid);
1775 return aac_write(scsicmd, cid);
1777 case SYNCHRONIZE_CACHE:
1778 /* Issue FIB to tell Firmware to flush it's cache */
1779 return aac_synchronize(scsicmd, cid);
1783 * Unhandled commands
1785 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1786 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1787 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1788 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1789 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1790 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1791 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1792 ? sizeof(scsicmd->sense_buffer)
1793 : sizeof(dev->fsa_dev[cid].sense_data));
1794 scsicmd->scsi_done(scsicmd);
1799 static int query_disk(struct aac_dev *dev, void __user *arg)
1801 struct aac_query_disk qd;
1802 struct fsa_dev_info *fsa_dev_ptr;
1804 fsa_dev_ptr = dev->fsa_dev;
1807 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1811 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1813 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1815 qd.instance = dev->scsi_host_ptr->host_no;
1817 qd.id = CONTAINER_TO_ID(qd.cnum);
1818 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1820 else return -EINVAL;
1822 qd.valid = fsa_dev_ptr[qd.cnum].valid;
1823 qd.locked = fsa_dev_ptr[qd.cnum].locked;
1824 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1826 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1831 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1832 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1834 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1839 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1841 struct aac_delete_disk dd;
1842 struct fsa_dev_info *fsa_dev_ptr;
1844 fsa_dev_ptr = dev->fsa_dev;
1846 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1849 if (dd.cnum >= dev->maximum_num_containers)
1852 * Mark this container as being deleted.
1854 fsa_dev_ptr[dd.cnum].deleted = 1;
1856 * Mark the container as no longer valid
1858 fsa_dev_ptr[dd.cnum].valid = 0;
1862 static int delete_disk(struct aac_dev *dev, void __user *arg)
1864 struct aac_delete_disk dd;
1865 struct fsa_dev_info *fsa_dev_ptr;
1867 fsa_dev_ptr = dev->fsa_dev;
1873 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1876 if (dd.cnum >= dev->maximum_num_containers)
1879 * If the container is locked, it can not be deleted by the API.
1881 if (fsa_dev_ptr[dd.cnum].locked)
1885 * Mark the container as no longer being valid.
1887 fsa_dev_ptr[dd.cnum].valid = 0;
1888 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
1893 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1896 case FSACTL_QUERY_DISK:
1897 return query_disk(dev, arg);
1898 case FSACTL_DELETE_DISK:
1899 return delete_disk(dev, arg);
1900 case FSACTL_FORCE_DELETE_DISK:
1901 return force_delete_disk(dev, arg);
1902 case FSACTL_GET_CONTAINERS:
1903 return aac_get_containers(dev);
1912 * @context: the context set in the fib - here it is scsi cmd
1913 * @fibptr: pointer to the fib
1915 * Handles the completion of a scsi command to a non dasd device
1919 static void aac_srb_callback(void *context, struct fib * fibptr)
1921 struct aac_dev *dev;
1922 struct aac_srb_reply *srbreply;
1923 struct scsi_cmnd *scsicmd;
1925 scsicmd = (struct scsi_cmnd *) context;
1926 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1927 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1929 BUG_ON(fibptr == NULL);
1931 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1933 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
1935 * Calculate resid for sg
1938 scsicmd->resid = scsicmd->request_bufflen -
1939 le32_to_cpu(srbreply->data_xfer_length);
1942 pci_unmap_sg(dev->pdev,
1943 (struct scatterlist *)scsicmd->request_buffer,
1945 scsicmd->sc_data_direction);
1946 else if(scsicmd->request_bufflen)
1947 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
1948 scsicmd->sc_data_direction);
1951 * First check the fib status
1954 if (le32_to_cpu(srbreply->status) != ST_OK){
1956 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1957 len = (le32_to_cpu(srbreply->sense_data_size) >
1958 sizeof(scsicmd->sense_buffer)) ?
1959 sizeof(scsicmd->sense_buffer) :
1960 le32_to_cpu(srbreply->sense_data_size);
1961 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1962 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1966 * Next check the srb status
1968 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1969 case SRB_STATUS_ERROR_RECOVERY:
1970 case SRB_STATUS_PENDING:
1971 case SRB_STATUS_SUCCESS:
1972 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1974 case SRB_STATUS_DATA_OVERRUN:
1975 switch(scsicmd->cmnd[0]){
1984 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1985 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1987 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1989 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1992 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1996 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2000 case SRB_STATUS_ABORTED:
2001 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2003 case SRB_STATUS_ABORT_FAILED:
2004 // Not sure about this one - but assuming the hba was trying to abort for some reason
2005 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2007 case SRB_STATUS_PARITY_ERROR:
2008 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2010 case SRB_STATUS_NO_DEVICE:
2011 case SRB_STATUS_INVALID_PATH_ID:
2012 case SRB_STATUS_INVALID_TARGET_ID:
2013 case SRB_STATUS_INVALID_LUN:
2014 case SRB_STATUS_SELECTION_TIMEOUT:
2015 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2018 case SRB_STATUS_COMMAND_TIMEOUT:
2019 case SRB_STATUS_TIMEOUT:
2020 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2023 case SRB_STATUS_BUSY:
2024 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2027 case SRB_STATUS_BUS_RESET:
2028 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2031 case SRB_STATUS_MESSAGE_REJECTED:
2032 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2034 case SRB_STATUS_REQUEST_FLUSHED:
2035 case SRB_STATUS_ERROR:
2036 case SRB_STATUS_INVALID_REQUEST:
2037 case SRB_STATUS_REQUEST_SENSE_FAILED:
2038 case SRB_STATUS_NO_HBA:
2039 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2040 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2041 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2042 case SRB_STATUS_DELAYED_RETRY:
2043 case SRB_STATUS_BAD_FUNCTION:
2044 case SRB_STATUS_NOT_STARTED:
2045 case SRB_STATUS_NOT_IN_USE:
2046 case SRB_STATUS_FORCE_ABORT:
2047 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2049 #ifdef AAC_DETAILED_STATUS_INFO
2050 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2051 le32_to_cpu(srbreply->srb_status) & 0x3F,
2052 aac_get_status_string(
2053 le32_to_cpu(srbreply->srb_status) & 0x3F),
2055 le32_to_cpu(srbreply->scsi_status));
2057 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2060 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2062 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2063 len = (le32_to_cpu(srbreply->sense_data_size) >
2064 sizeof(scsicmd->sense_buffer)) ?
2065 sizeof(scsicmd->sense_buffer) :
2066 le32_to_cpu(srbreply->sense_data_size);
2067 #ifdef AAC_DETAILED_STATUS_INFO
2068 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2069 le32_to_cpu(srbreply->status), len);
2071 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2075 * OR in the scsi status (already shifted up a bit)
2077 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2079 aac_fib_complete(fibptr);
2080 aac_fib_free(fibptr);
2081 scsicmd->scsi_done(scsicmd);
2087 * @scsicmd: the scsi command block
2089 * This routine will form a FIB and fill in the aac_srb from the
2090 * scsicmd passed in.
2093 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2095 struct fib* cmd_fibcontext;
2096 struct aac_dev* dev;
2098 struct aac_srb *srbcmd;
2103 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2104 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2105 scsicmd->device->lun > 7) {
2106 scsicmd->result = DID_NO_CONNECT << 16;
2107 scsicmd->scsi_done(scsicmd);
2111 switch(scsicmd->sc_data_direction){
2115 case DMA_BIDIRECTIONAL:
2116 flag = SRB_DataIn | SRB_DataOut;
2118 case DMA_FROM_DEVICE:
2122 default: /* shuts up some versions of gcc */
2123 flag = SRB_NoDataXfer;
2129 * Allocate and initialize a Fib then setup a BlockWrite command
2131 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2134 aac_fib_init(cmd_fibcontext);
2136 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
2137 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
2138 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(scsicmd)));
2139 srbcmd->id = cpu_to_le32(scmd_id(scsicmd));
2140 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
2141 srbcmd->flags = cpu_to_le32(flag);
2142 timeout = scsicmd->timeout_per_command/HZ;
2146 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
2147 srbcmd->retry_limit = 0; /* Obsolete parameter */
2148 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
2150 if( dev->dac_support == 1 ) {
2151 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
2152 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2154 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2155 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2157 * Build Scatter/Gather list
2159 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
2160 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
2161 sizeof (struct sgentry64));
2162 BUG_ON (fibsize > (dev->max_fib_size -
2163 sizeof(struct aac_fibhdr)));
2166 * Now send the Fib to the adapter
2168 status = aac_fib_send(ScsiPortCommand64, cmd_fibcontext,
2169 fibsize, FsaNormal, 0, 1,
2170 (fib_callback) aac_srb_callback,
2173 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
2174 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2176 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2177 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2179 * Build Scatter/Gather list
2181 fibsize = sizeof (struct aac_srb) +
2182 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
2183 sizeof (struct sgentry));
2184 BUG_ON (fibsize > (dev->max_fib_size -
2185 sizeof(struct aac_fibhdr)));
2188 * Now send the Fib to the adapter
2190 status = aac_fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
2191 (fib_callback) aac_srb_callback, (void *) scsicmd);
2194 * Check that the command queued to the controller
2196 if (status == -EINPROGRESS) {
2197 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2201 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2202 aac_fib_complete(cmd_fibcontext);
2203 aac_fib_free(cmd_fibcontext);
2208 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2210 struct aac_dev *dev;
2211 unsigned long byte_count = 0;
2213 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2214 // Get rid of old data
2216 psg->sg[0].addr = 0;
2217 psg->sg[0].count = 0;
2218 if (scsicmd->use_sg) {
2219 struct scatterlist *sg;
2222 sg = (struct scatterlist *) scsicmd->request_buffer;
2224 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2225 scsicmd->sc_data_direction);
2226 psg->count = cpu_to_le32(sg_count);
2228 for (i = 0; i < sg_count; i++) {
2229 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2230 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2231 byte_count += sg_dma_len(sg);
2234 /* hba wants the size to be exact */
2235 if(byte_count > scsicmd->request_bufflen){
2236 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2237 (byte_count - scsicmd->request_bufflen);
2238 psg->sg[i-1].count = cpu_to_le32(temp);
2239 byte_count = scsicmd->request_bufflen;
2241 /* Check for command underflow */
2242 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2243 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2244 byte_count, scsicmd->underflow);
2247 else if(scsicmd->request_bufflen) {
2249 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2250 scsicmd->request_buffer,
2251 scsicmd->request_bufflen,
2252 scsicmd->sc_data_direction);
2253 addr = scsicmd->SCp.dma_handle;
2254 psg->count = cpu_to_le32(1);
2255 psg->sg[0].addr = cpu_to_le32(addr);
2256 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2257 byte_count = scsicmd->request_bufflen;
2263 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2265 struct aac_dev *dev;
2266 unsigned long byte_count = 0;
2269 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2270 // Get rid of old data
2272 psg->sg[0].addr[0] = 0;
2273 psg->sg[0].addr[1] = 0;
2274 psg->sg[0].count = 0;
2275 if (scsicmd->use_sg) {
2276 struct scatterlist *sg;
2279 sg = (struct scatterlist *) scsicmd->request_buffer;
2281 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2282 scsicmd->sc_data_direction);
2284 for (i = 0; i < sg_count; i++) {
2285 int count = sg_dma_len(sg);
2286 addr = sg_dma_address(sg);
2287 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2288 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2289 psg->sg[i].count = cpu_to_le32(count);
2290 byte_count += count;
2293 psg->count = cpu_to_le32(sg_count);
2294 /* hba wants the size to be exact */
2295 if(byte_count > scsicmd->request_bufflen){
2296 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2297 (byte_count - scsicmd->request_bufflen);
2298 psg->sg[i-1].count = cpu_to_le32(temp);
2299 byte_count = scsicmd->request_bufflen;
2301 /* Check for command underflow */
2302 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2303 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2304 byte_count, scsicmd->underflow);
2307 else if(scsicmd->request_bufflen) {
2308 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2309 scsicmd->request_buffer,
2310 scsicmd->request_bufflen,
2311 scsicmd->sc_data_direction);
2312 addr = scsicmd->SCp.dma_handle;
2313 psg->count = cpu_to_le32(1);
2314 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2315 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2316 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2317 byte_count = scsicmd->request_bufflen;
2322 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2324 struct Scsi_Host *host = scsicmd->device->host;
2325 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2326 unsigned long byte_count = 0;
2328 // Get rid of old data
2330 psg->sg[0].next = 0;
2331 psg->sg[0].prev = 0;
2332 psg->sg[0].addr[0] = 0;
2333 psg->sg[0].addr[1] = 0;
2334 psg->sg[0].count = 0;
2335 psg->sg[0].flags = 0;
2336 if (scsicmd->use_sg) {
2337 struct scatterlist *sg;
2340 sg = (struct scatterlist *) scsicmd->request_buffer;
2342 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2343 scsicmd->sc_data_direction);
2345 for (i = 0; i < sg_count; i++) {
2346 int count = sg_dma_len(sg);
2347 u64 addr = sg_dma_address(sg);
2348 psg->sg[i].next = 0;
2349 psg->sg[i].prev = 0;
2350 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2351 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2352 psg->sg[i].count = cpu_to_le32(count);
2353 psg->sg[i].flags = 0;
2354 byte_count += count;
2357 psg->count = cpu_to_le32(sg_count);
2358 /* hba wants the size to be exact */
2359 if(byte_count > scsicmd->request_bufflen){
2360 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2361 (byte_count - scsicmd->request_bufflen);
2362 psg->sg[i-1].count = cpu_to_le32(temp);
2363 byte_count = scsicmd->request_bufflen;
2365 /* Check for command underflow */
2366 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2367 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2368 byte_count, scsicmd->underflow);
2371 else if(scsicmd->request_bufflen) {
2374 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2375 scsicmd->request_buffer,
2376 scsicmd->request_bufflen,
2377 scsicmd->sc_data_direction);
2378 addr = scsicmd->SCp.dma_handle;
2379 count = scsicmd->request_bufflen;
2380 psg->count = cpu_to_le32(1);
2381 psg->sg[0].next = 0;
2382 psg->sg[0].prev = 0;
2383 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2384 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2385 psg->sg[0].count = cpu_to_le32(count);
2386 psg->sg[0].flags = 0;
2387 byte_count = scsicmd->request_bufflen;
2392 #ifdef AAC_DETAILED_STATUS_INFO
2394 struct aac_srb_status_info {
2400 static struct aac_srb_status_info srb_status_info[] = {
2401 { SRB_STATUS_PENDING, "Pending Status"},
2402 { SRB_STATUS_SUCCESS, "Success"},
2403 { SRB_STATUS_ABORTED, "Aborted Command"},
2404 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2405 { SRB_STATUS_ERROR, "Error Event"},
2406 { SRB_STATUS_BUSY, "Device Busy"},
2407 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2408 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2409 { SRB_STATUS_NO_DEVICE, "No Device"},
2410 { SRB_STATUS_TIMEOUT, "Timeout"},
2411 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2412 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2413 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2414 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2415 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2416 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2417 { SRB_STATUS_NO_HBA, "No HBA"},
2418 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2419 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2420 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2421 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2422 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2423 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2424 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2425 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2426 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2427 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2428 { SRB_STATUS_NOT_STARTED, "Not Started"},
2429 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2430 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2431 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2432 { 0xff, "Unknown Error"}
2435 char *aac_get_status_string(u32 status)
2439 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2440 if (srb_status_info[i].status == status)
2441 return srb_status_info[i].str;
2443 return "Bad Status Code";