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, 0);
153 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
154 module_param(dacmode, int, 0);
155 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
156 module_param(commit, int, 0);
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\nvalues 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,\n2048, 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;
391 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
395 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
396 /* Failure is irrelevant, using default value instead */
397 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
398 && (get_name_reply->data[0] != '\0')) {
399 char *sp = get_name_reply->data;
400 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
404 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
405 int count = sizeof(d);
408 *dp++ = (*sp) ? *sp++ : ' ';
409 } while (--count > 0);
410 aac_internal_transfer(scsicmd, d,
411 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
415 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
417 aac_fib_complete(fibptr);
418 aac_fib_free(fibptr);
419 scsicmd->scsi_done(scsicmd);
423 * aac_get_container_name - get container name, none blocking.
425 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
428 struct aac_get_name *dinfo;
429 struct fib * cmd_fibcontext;
430 struct aac_dev * dev;
432 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
434 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
437 aac_fib_init(cmd_fibcontext);
438 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
440 dinfo->command = cpu_to_le32(VM_ContainerConfig);
441 dinfo->type = cpu_to_le32(CT_READ_NAME);
442 dinfo->cid = cpu_to_le32(cid);
443 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
445 status = aac_fib_send(ContainerCommand,
447 sizeof (struct aac_get_name),
450 (fib_callback) get_container_name_callback,
454 * Check that the command queued to the controller
456 if (status == -EINPROGRESS)
459 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
460 aac_fib_complete(cmd_fibcontext);
461 aac_fib_free(cmd_fibcontext);
466 * aac_probe_container - query a logical volume
467 * @dev: device to query
468 * @cid: container identifier
470 * Queries the controller about the given volume. The volume information
471 * is updated in the struct fsa_dev_info structure rather than returned.
474 int aac_probe_container(struct aac_dev *dev, int cid)
476 struct fsa_dev_info *fsa_dev_ptr;
478 struct aac_query_mount *dinfo;
479 struct aac_mount *dresp;
483 fsa_dev_ptr = dev->fsa_dev;
484 instance = dev->scsi_host_ptr->unique_id;
486 if (!(fibptr = aac_fib_alloc(dev)))
489 aac_fib_init(fibptr);
491 dinfo = (struct aac_query_mount *)fib_data(fibptr);
493 dinfo->command = cpu_to_le32(VM_NameServe);
494 dinfo->count = cpu_to_le32(cid);
495 dinfo->type = cpu_to_le32(FT_FILESYS);
497 status = aac_fib_send(ContainerCommand,
499 sizeof(struct aac_query_mount),
504 printk(KERN_WARNING "aacraid: aac_probe_container query failed.\n");
508 dresp = (struct aac_mount *) fib_data(fibptr);
510 if ((le32_to_cpu(dresp->status) == ST_OK) &&
511 (le32_to_cpu(dresp->mnt[0].vol) == CT_NONE)) {
512 dinfo->command = cpu_to_le32(VM_NameServe64);
513 dinfo->count = cpu_to_le32(cid);
514 dinfo->type = cpu_to_le32(FT_FILESYS);
516 if (aac_fib_send(ContainerCommand,
518 sizeof(struct aac_query_mount),
524 dresp->mnt[0].capacityhigh = 0;
526 if ((le32_to_cpu(dresp->status) == ST_OK) &&
527 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
528 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
529 fsa_dev_ptr[cid].valid = 1;
530 fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
531 fsa_dev_ptr[cid].size
532 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
533 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
534 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
535 fsa_dev_ptr[cid].ro = 1;
539 aac_fib_complete(fibptr);
540 aac_fib_free(fibptr);
545 /* Local Structure to set SCSI inquiry data strings */
547 char vid[8]; /* Vendor ID */
548 char pid[16]; /* Product ID */
549 char prl[4]; /* Product Revision Level */
553 * InqStrCopy - string merge
554 * @a: string to copy from
555 * @b: string to copy to
557 * Copy a String from one location to another
561 static void inqstrcpy(char *a, char *b)
568 static char *container_types[] = {
594 /* Function: setinqstr
596 * Arguments: [1] pointer to void [1] int
598 * Purpose: Sets SCSI inquiry data strings for vendor, product
599 * and revision level. Allows strings to be set in platform dependant
600 * files instead of in OS dependant driver source.
603 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
605 struct scsi_inq *str;
607 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
608 memset(str, ' ', sizeof(*str));
610 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
611 char * cp = dev->supplement_adapter_info.AdapterTypeText;
612 int c = sizeof(str->vid);
613 while (*cp && *cp != ' ' && --c)
617 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
620 while (*cp && *cp != ' ')
624 /* last six chars reserved for vol type */
626 if (strlen(cp) > sizeof(str->pid)) {
627 c = cp[sizeof(str->pid)];
628 cp[sizeof(str->pid)] = '\0';
630 inqstrcpy (cp, str->pid);
632 cp[sizeof(str->pid)] = c;
634 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
636 inqstrcpy (mp->vname, str->vid);
637 /* last six chars reserved for vol type */
638 inqstrcpy (mp->model, str->pid);
641 if (tindex < (sizeof(container_types)/sizeof(char *))){
642 char *findit = str->pid;
644 for ( ; *findit != ' '; findit++); /* walk till we find a space */
645 /* RAID is superfluous in the context of a RAID device */
646 if (memcmp(findit-4, "RAID", 4) == 0)
647 *(findit -= 4) = ' ';
648 if (((findit - str->pid) + strlen(container_types[tindex]))
649 < (sizeof(str->pid) + sizeof(str->prl)))
650 inqstrcpy (container_types[tindex], findit + 1);
652 inqstrcpy ("V1.0", str->prl);
655 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
656 u8 a_sense_code, u8 incorrect_length,
657 u8 bit_pointer, u16 field_pointer,
660 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
661 sense_buf[1] = 0; /* Segment number, always zero */
663 if (incorrect_length) {
664 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
665 sense_buf[3] = BYTE3(residue);
666 sense_buf[4] = BYTE2(residue);
667 sense_buf[5] = BYTE1(residue);
668 sense_buf[6] = BYTE0(residue);
670 sense_buf[2] = sense_key; /* Sense key */
672 if (sense_key == ILLEGAL_REQUEST)
673 sense_buf[7] = 10; /* Additional sense length */
675 sense_buf[7] = 6; /* Additional sense length */
677 sense_buf[12] = sense_code; /* Additional sense code */
678 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
679 if (sense_key == ILLEGAL_REQUEST) {
682 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
683 sense_buf[15] = 0x80;/* Std sense key specific field */
684 /* Illegal parameter is in the parameter block */
686 if (sense_code == SENCODE_INVALID_CDB_FIELD)
687 sense_buf[15] = 0xc0;/* Std sense key specific field */
688 /* Illegal parameter is in the CDB block */
689 sense_buf[15] |= bit_pointer;
690 sense_buf[16] = field_pointer >> 8; /* MSB */
691 sense_buf[17] = field_pointer; /* LSB */
695 int aac_get_adapter_info(struct aac_dev* dev)
700 struct aac_adapter_info *info;
701 struct aac_bus_info *command;
702 struct aac_bus_info_response *bus_info;
704 if (!(fibptr = aac_fib_alloc(dev)))
707 aac_fib_init(fibptr);
708 info = (struct aac_adapter_info *) fib_data(fibptr);
709 memset(info,0,sizeof(*info));
711 rcode = aac_fib_send(RequestAdapterInfo,
715 -1, 1, /* First `interrupt' command uses special wait */
720 aac_fib_complete(fibptr);
721 aac_fib_free(fibptr);
724 memcpy(&dev->adapter_info, info, sizeof(*info));
726 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
727 struct aac_supplement_adapter_info * info;
729 aac_fib_init(fibptr);
731 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
733 memset(info,0,sizeof(*info));
735 rcode = aac_fib_send(RequestSupplementAdapterInfo,
744 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
752 aac_fib_init(fibptr);
754 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
756 memset(bus_info, 0, sizeof(*bus_info));
758 command = (struct aac_bus_info *)bus_info;
760 command->Command = cpu_to_le32(VM_Ioctl);
761 command->ObjType = cpu_to_le32(FT_DRIVE);
762 command->MethodId = cpu_to_le32(1);
763 command->CtlCmd = cpu_to_le32(GetBusInfo);
765 rcode = aac_fib_send(ContainerCommand,
772 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
773 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
774 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
777 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
778 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
784 le32_to_cpu(dev->adapter_info.kernelbuild),
785 (int)sizeof(dev->supplement_adapter_info.BuildDate),
786 dev->supplement_adapter_info.BuildDate);
787 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
788 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
790 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
791 le32_to_cpu(dev->adapter_info.monitorbuild));
792 tmp = le32_to_cpu(dev->adapter_info.biosrev);
793 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
795 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
796 le32_to_cpu(dev->adapter_info.biosbuild));
797 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
798 printk(KERN_INFO "%s%d: serial %x\n",
800 le32_to_cpu(dev->adapter_info.serial[0]));
802 dev->nondasd_support = 0;
803 dev->raid_scsi_mode = 0;
804 if(dev->adapter_info.options & AAC_OPT_NONDASD){
805 dev->nondasd_support = 1;
809 * If the firmware supports ROMB RAID/SCSI mode and we are currently
810 * in RAID/SCSI mode, set the flag. For now if in this mode we will
811 * force nondasd support on. If we decide to allow the non-dasd flag
812 * additional changes changes will have to be made to support
813 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
814 * changed to support the new dev->raid_scsi_mode flag instead of
815 * leaching off of the dev->nondasd_support flag. Also in linit.c the
816 * function aac_detect will have to be modified where it sets up the
817 * max number of channels based on the aac->nondasd_support flag only.
819 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
820 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
821 dev->nondasd_support = 1;
822 dev->raid_scsi_mode = 1;
824 if (dev->raid_scsi_mode != 0)
825 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
829 dev->nondasd_support = (nondasd!=0);
831 if(dev->nondasd_support != 0){
832 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
835 dev->dac_support = 0;
836 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
837 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
838 dev->dac_support = 1;
842 dev->dac_support = (dacmode!=0);
844 if(dev->dac_support != 0) {
845 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
846 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
847 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
849 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
850 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
851 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
853 dev->dac_support = 0;
855 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
861 * 57 scatter gather elements
863 if (!(dev->raw_io_interface)) {
864 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
865 sizeof(struct aac_fibhdr) -
866 sizeof(struct aac_write) + sizeof(struct sgentry)) /
867 sizeof(struct sgentry);
868 if (dev->dac_support) {
870 * 38 scatter gather elements
872 dev->scsi_host_ptr->sg_tablesize =
874 sizeof(struct aac_fibhdr) -
875 sizeof(struct aac_write64) +
876 sizeof(struct sgentry64)) /
877 sizeof(struct sgentry64);
879 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
880 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
882 * Worst case size that could cause sg overflow when
883 * we break up SG elements that are larger than 64KB.
884 * Would be nice if we could tell the SCSI layer what
885 * the maximum SG element size can be. Worst case is
886 * (sg_tablesize-1) 4KB elements with one 64KB
888 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
890 dev->scsi_host_ptr->max_sectors =
891 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
895 aac_fib_complete(fibptr);
896 aac_fib_free(fibptr);
902 static void io_callback(void *context, struct fib * fibptr)
905 struct aac_read_reply *readreply;
906 struct scsi_cmnd *scsicmd;
909 scsicmd = (struct scsi_cmnd *) context;
911 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
912 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
914 if (nblank(dprintk(x))) {
916 switch (scsicmd->cmnd[0]) {
919 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
920 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
924 lba = ((u64)scsicmd->cmnd[2] << 56) |
925 ((u64)scsicmd->cmnd[3] << 48) |
926 ((u64)scsicmd->cmnd[4] << 40) |
927 ((u64)scsicmd->cmnd[5] << 32) |
928 ((u64)scsicmd->cmnd[6] << 24) |
929 (scsicmd->cmnd[7] << 16) |
930 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
934 lba = ((u64)scsicmd->cmnd[2] << 24) |
935 (scsicmd->cmnd[3] << 16) |
936 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
939 lba = ((u64)scsicmd->cmnd[2] << 24) |
940 (scsicmd->cmnd[3] << 16) |
941 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
945 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
946 smp_processor_id(), (unsigned long long)lba, jiffies);
953 pci_unmap_sg(dev->pdev,
954 (struct scatterlist *)scsicmd->buffer,
956 scsicmd->sc_data_direction);
957 else if(scsicmd->request_bufflen)
958 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
959 scsicmd->request_bufflen,
960 scsicmd->sc_data_direction);
961 readreply = (struct aac_read_reply *)fib_data(fibptr);
962 if (le32_to_cpu(readreply->status) == ST_OK)
963 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
965 #ifdef AAC_DETAILED_STATUS_INFO
966 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
967 le32_to_cpu(readreply->status));
969 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
970 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
972 SENCODE_INTERNAL_TARGET_FAILURE,
973 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
975 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
976 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
977 ? sizeof(scsicmd->sense_buffer)
978 : sizeof(dev->fsa_dev[cid].sense_data));
980 aac_fib_complete(fibptr);
981 aac_fib_free(fibptr);
983 scsicmd->scsi_done(scsicmd);
986 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
994 struct fib * cmd_fibcontext;
996 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
998 * Get block address and transfer length
1000 switch (scsicmd->cmnd[0]) {
1002 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
1004 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1005 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1006 count = scsicmd->cmnd[4];
1012 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", cid));
1014 lba = ((u64)scsicmd->cmnd[2] << 56) |
1015 ((u64)scsicmd->cmnd[3] << 48) |
1016 ((u64)scsicmd->cmnd[4] << 40) |
1017 ((u64)scsicmd->cmnd[5] << 32) |
1018 ((u64)scsicmd->cmnd[6] << 24) |
1019 (scsicmd->cmnd[7] << 16) |
1020 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1021 count = (scsicmd->cmnd[10] << 24) |
1022 (scsicmd->cmnd[11] << 16) |
1023 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1026 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", cid));
1028 lba = ((u64)scsicmd->cmnd[2] << 24) |
1029 (scsicmd->cmnd[3] << 16) |
1030 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1031 count = (scsicmd->cmnd[6] << 24) |
1032 (scsicmd->cmnd[7] << 16) |
1033 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1036 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
1038 lba = ((u64)scsicmd->cmnd[2] << 24) |
1039 (scsicmd->cmnd[3] << 16) |
1040 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1041 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1044 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1045 smp_processor_id(), (unsigned long long)lba, jiffies));
1046 if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) &&
1047 (lba & 0xffffffff00000000LL)) {
1048 dprintk((KERN_DEBUG "aac_read: Illegal lba\n"));
1049 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1050 SAM_STAT_CHECK_CONDITION;
1051 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1053 SENCODE_INTERNAL_TARGET_FAILURE,
1054 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1056 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1057 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1058 ? sizeof(scsicmd->sense_buffer)
1059 : sizeof(dev->fsa_dev[cid].sense_data));
1060 scsicmd->scsi_done(scsicmd);
1064 * Alocate and initialize a Fib
1066 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1070 aac_fib_init(cmd_fibcontext);
1072 if (dev->raw_io_interface) {
1073 struct aac_raw_io *readcmd;
1074 readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1075 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1076 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1077 readcmd->count = cpu_to_le32(count<<9);
1078 readcmd->cid = cpu_to_le16(cid);
1079 readcmd->flags = cpu_to_le16(1);
1080 readcmd->bpTotal = 0;
1081 readcmd->bpComplete = 0;
1083 aac_build_sgraw(scsicmd, &readcmd->sg);
1084 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
1085 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1088 * Now send the Fib to the adapter
1090 status = aac_fib_send(ContainerRawIo,
1095 (fib_callback) io_callback,
1097 } else if (dev->dac_support == 1) {
1098 struct aac_read64 *readcmd;
1099 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
1100 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1101 readcmd->cid = cpu_to_le16(cid);
1102 readcmd->sector_count = cpu_to_le16(count);
1103 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1107 aac_build_sg64(scsicmd, &readcmd->sg);
1108 fibsize = sizeof(struct aac_read64) +
1109 ((le32_to_cpu(readcmd->sg.count) - 1) *
1110 sizeof (struct sgentry64));
1111 BUG_ON (fibsize > (dev->max_fib_size -
1112 sizeof(struct aac_fibhdr)));
1114 * Now send the Fib to the adapter
1116 status = aac_fib_send(ContainerCommand64,
1121 (fib_callback) io_callback,
1124 struct aac_read *readcmd;
1125 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
1126 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1127 readcmd->cid = cpu_to_le32(cid);
1128 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1129 readcmd->count = cpu_to_le32(count * 512);
1131 aac_build_sg(scsicmd, &readcmd->sg);
1132 fibsize = sizeof(struct aac_read) +
1133 ((le32_to_cpu(readcmd->sg.count) - 1) *
1134 sizeof (struct sgentry));
1135 BUG_ON (fibsize > (dev->max_fib_size -
1136 sizeof(struct aac_fibhdr)));
1138 * Now send the Fib to the adapter
1140 status = aac_fib_send(ContainerCommand,
1145 (fib_callback) io_callback,
1152 * Check that the command queued to the controller
1154 if (status == -EINPROGRESS)
1157 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1159 * For some reason, the Fib didn't queue, return QUEUE_FULL
1161 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1162 scsicmd->scsi_done(scsicmd);
1163 aac_fib_complete(cmd_fibcontext);
1164 aac_fib_free(cmd_fibcontext);
1168 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1174 struct aac_dev *dev;
1175 struct fib * cmd_fibcontext;
1177 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1179 * Get block address and transfer length
1181 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1183 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1184 count = scsicmd->cmnd[4];
1187 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1188 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", cid));
1190 lba = ((u64)scsicmd->cmnd[2] << 56) |
1191 ((u64)scsicmd->cmnd[3] << 48) |
1192 ((u64)scsicmd->cmnd[4] << 40) |
1193 ((u64)scsicmd->cmnd[5] << 32) |
1194 ((u64)scsicmd->cmnd[6] << 24) |
1195 (scsicmd->cmnd[7] << 16) |
1196 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1197 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1198 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1199 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1200 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", cid));
1202 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1203 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1204 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1205 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1207 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
1208 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1209 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1211 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1212 smp_processor_id(), (unsigned long long)lba, jiffies));
1213 if ((!(dev->raw_io_interface) || !(dev->raw_io_64))
1214 && (lba & 0xffffffff00000000LL)) {
1215 dprintk((KERN_DEBUG "aac_write: Illegal lba\n"));
1216 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1217 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1219 SENCODE_INTERNAL_TARGET_FAILURE,
1220 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1222 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1223 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1224 ? sizeof(scsicmd->sense_buffer)
1225 : sizeof(dev->fsa_dev[cid].sense_data));
1226 scsicmd->scsi_done(scsicmd);
1230 * Allocate and initialize a Fib then setup a BlockWrite command
1232 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1233 scsicmd->result = DID_ERROR << 16;
1234 scsicmd->scsi_done(scsicmd);
1237 aac_fib_init(cmd_fibcontext);
1239 if (dev->raw_io_interface) {
1240 struct aac_raw_io *writecmd;
1241 writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1242 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1243 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1244 writecmd->count = cpu_to_le32(count<<9);
1245 writecmd->cid = cpu_to_le16(cid);
1246 writecmd->flags = 0;
1247 writecmd->bpTotal = 0;
1248 writecmd->bpComplete = 0;
1250 aac_build_sgraw(scsicmd, &writecmd->sg);
1251 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1252 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1255 * Now send the Fib to the adapter
1257 status = aac_fib_send(ContainerRawIo,
1262 (fib_callback) io_callback,
1264 } else if (dev->dac_support == 1) {
1265 struct aac_write64 *writecmd;
1266 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1267 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1268 writecmd->cid = cpu_to_le16(cid);
1269 writecmd->sector_count = cpu_to_le16(count);
1270 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1272 writecmd->flags = 0;
1274 aac_build_sg64(scsicmd, &writecmd->sg);
1275 fibsize = sizeof(struct aac_write64) +
1276 ((le32_to_cpu(writecmd->sg.count) - 1) *
1277 sizeof (struct sgentry64));
1278 BUG_ON (fibsize > (dev->max_fib_size -
1279 sizeof(struct aac_fibhdr)));
1281 * Now send the Fib to the adapter
1283 status = aac_fib_send(ContainerCommand64,
1288 (fib_callback) io_callback,
1291 struct aac_write *writecmd;
1292 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
1293 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1294 writecmd->cid = cpu_to_le32(cid);
1295 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1296 writecmd->count = cpu_to_le32(count * 512);
1297 writecmd->sg.count = cpu_to_le32(1);
1298 /* ->stable is not used - it did mean which type of write */
1300 aac_build_sg(scsicmd, &writecmd->sg);
1301 fibsize = sizeof(struct aac_write) +
1302 ((le32_to_cpu(writecmd->sg.count) - 1) *
1303 sizeof (struct sgentry));
1304 BUG_ON (fibsize > (dev->max_fib_size -
1305 sizeof(struct aac_fibhdr)));
1307 * Now send the Fib to the adapter
1309 status = aac_fib_send(ContainerCommand,
1314 (fib_callback) io_callback,
1319 * Check that the command queued to the controller
1321 if (status == -EINPROGRESS)
1326 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1328 * For some reason, the Fib didn't queue, return QUEUE_FULL
1330 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1331 scsicmd->scsi_done(scsicmd);
1333 aac_fib_complete(cmd_fibcontext);
1334 aac_fib_free(cmd_fibcontext);
1338 static void synchronize_callback(void *context, struct fib *fibptr)
1340 struct aac_synchronize_reply *synchronizereply;
1341 struct scsi_cmnd *cmd;
1345 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1346 smp_processor_id(), jiffies));
1347 BUG_ON(fibptr == NULL);
1350 synchronizereply = fib_data(fibptr);
1351 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1352 cmd->result = DID_OK << 16 |
1353 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1355 struct scsi_device *sdev = cmd->device;
1356 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1357 u32 cid = ID_LUN_TO_CONTAINER(sdev->id, sdev->lun);
1359 "synchronize_callback: synchronize failed, status = %d\n",
1360 le32_to_cpu(synchronizereply->status));
1361 cmd->result = DID_OK << 16 |
1362 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1363 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1365 SENCODE_INTERNAL_TARGET_FAILURE,
1366 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1368 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1369 min(sizeof(dev->fsa_dev[cid].sense_data),
1370 sizeof(cmd->sense_buffer)));
1373 aac_fib_complete(fibptr);
1374 aac_fib_free(fibptr);
1375 cmd->scsi_done(cmd);
1378 static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1381 struct fib *cmd_fibcontext;
1382 struct aac_synchronize *synchronizecmd;
1383 struct scsi_cmnd *cmd;
1384 struct scsi_device *sdev = scsicmd->device;
1386 unsigned long flags;
1389 * Wait for all commands to complete to this specific
1392 spin_lock_irqsave(&sdev->list_lock, flags);
1393 list_for_each_entry(cmd, &sdev->cmd_list, list)
1394 if (cmd != scsicmd && cmd->serial_number != 0) {
1399 spin_unlock_irqrestore(&sdev->list_lock, flags);
1402 * Yield the processor (requeue for later)
1405 return SCSI_MLQUEUE_DEVICE_BUSY;
1408 * Allocate and initialize a Fib
1410 if (!(cmd_fibcontext =
1411 aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata)))
1412 return SCSI_MLQUEUE_HOST_BUSY;
1414 aac_fib_init(cmd_fibcontext);
1416 synchronizecmd = fib_data(cmd_fibcontext);
1417 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1418 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1419 synchronizecmd->cid = cpu_to_le32(cid);
1420 synchronizecmd->count =
1421 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1424 * Now send the Fib to the adapter
1426 status = aac_fib_send(ContainerCommand,
1428 sizeof(struct aac_synchronize),
1431 (fib_callback)synchronize_callback,
1435 * Check that the command queued to the controller
1437 if (status == -EINPROGRESS)
1441 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1442 aac_fib_complete(cmd_fibcontext);
1443 aac_fib_free(cmd_fibcontext);
1444 return SCSI_MLQUEUE_HOST_BUSY;
1448 * aac_scsi_cmd() - Process SCSI command
1449 * @scsicmd: SCSI command block
1451 * Emulate a SCSI command and queue the required request for the
1455 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1458 struct Scsi_Host *host = scsicmd->device->host;
1459 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1460 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1464 * If the bus, id or lun is out of range, return fail
1465 * Test does not apply to ID 16, the pseudo id for the controller
1468 if (scmd_id(scsicmd) != host->this_id) {
1469 if ((scsicmd->device->channel == CONTAINER_CHANNEL)) {
1470 if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){
1471 scsicmd->result = DID_NO_CONNECT << 16;
1472 scsicmd->scsi_done(scsicmd);
1475 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
1478 * If the target container doesn't exist, it may have
1479 * been newly created
1481 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1482 switch (scsicmd->cmnd[0]) {
1483 case SERVICE_ACTION_IN:
1484 if (!(dev->raw_io_interface) ||
1485 !(dev->raw_io_64) ||
1486 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1490 case TEST_UNIT_READY:
1491 spin_unlock_irq(host->host_lock);
1492 aac_probe_container(dev, cid);
1493 if ((fsa_dev_ptr[cid].valid & 1) == 0)
1494 fsa_dev_ptr[cid].valid = 0;
1495 spin_lock_irq(host->host_lock);
1496 if (fsa_dev_ptr[cid].valid == 0) {
1497 scsicmd->result = DID_NO_CONNECT << 16;
1498 scsicmd->scsi_done(scsicmd);
1506 * If the target container still doesn't exist,
1509 if (fsa_dev_ptr[cid].valid == 0) {
1510 scsicmd->result = DID_BAD_TARGET << 16;
1511 scsicmd->scsi_done(scsicmd);
1514 } else { /* check for physical non-dasd devices */
1515 if(dev->nondasd_support == 1){
1516 return aac_send_srb_fib(scsicmd);
1518 scsicmd->result = DID_NO_CONNECT << 16;
1519 scsicmd->scsi_done(scsicmd);
1525 * else Command for the controller itself
1527 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1528 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1530 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1531 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1532 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1534 SENCODE_INVALID_COMMAND,
1535 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1536 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1537 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1538 ? sizeof(scsicmd->sense_buffer)
1539 : sizeof(dev->fsa_dev[cid].sense_data));
1540 scsicmd->scsi_done(scsicmd);
1545 /* Handle commands here that don't really require going out to the adapter */
1546 switch (scsicmd->cmnd[0]) {
1549 struct inquiry_data inq_data;
1551 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
1552 memset(&inq_data, 0, sizeof (struct inquiry_data));
1554 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1555 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 */
1556 inq_data.inqd_len = 31;
1557 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1558 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1560 * Set the Vendor, Product, and Revision Level
1561 * see: <vendor>.c i.e. aac.c
1563 if (scmd_id(scsicmd) == host->this_id) {
1564 setinqstr(dev, (void *) (inq_data.inqd_vid), (sizeof(container_types)/sizeof(char *)));
1565 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1566 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1567 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1568 scsicmd->scsi_done(scsicmd);
1571 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1572 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1573 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1574 return aac_get_container_name(scsicmd, cid);
1576 case SERVICE_ACTION_IN:
1577 if (!(dev->raw_io_interface) ||
1578 !(dev->raw_io_64) ||
1579 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1585 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1586 capacity = fsa_dev_ptr[cid].size - 1;
1587 cp[0] = (capacity >> 56) & 0xff;
1588 cp[1] = (capacity >> 48) & 0xff;
1589 cp[2] = (capacity >> 40) & 0xff;
1590 cp[3] = (capacity >> 32) & 0xff;
1591 cp[4] = (capacity >> 24) & 0xff;
1592 cp[5] = (capacity >> 16) & 0xff;
1593 cp[6] = (capacity >> 8) & 0xff;
1594 cp[7] = (capacity >> 0) & 0xff;
1600 aac_internal_transfer(scsicmd, cp, 0,
1601 min((unsigned int)scsicmd->cmnd[13], sizeof(cp)));
1602 if (sizeof(cp) < scsicmd->cmnd[13]) {
1603 unsigned int len, offset = sizeof(cp);
1605 memset(cp, 0, offset);
1607 len = min(scsicmd->cmnd[13]-offset, sizeof(cp));
1608 aac_internal_transfer(scsicmd, cp, offset, len);
1609 } while ((offset += len) < scsicmd->cmnd[13]);
1612 /* Do not cache partition table for arrays */
1613 scsicmd->device->removable = 1;
1615 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1616 scsicmd->scsi_done(scsicmd);
1626 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1627 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
1628 capacity = fsa_dev_ptr[cid].size - 1;
1632 cp[0] = (capacity >> 24) & 0xff;
1633 cp[1] = (capacity >> 16) & 0xff;
1634 cp[2] = (capacity >> 8) & 0xff;
1635 cp[3] = (capacity >> 0) & 0xff;
1640 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1641 /* Do not cache partition table for arrays */
1642 scsicmd->device->removable = 1;
1644 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1645 scsicmd->scsi_done(scsicmd);
1654 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1655 mode_buf[0] = 3; /* Mode data length */
1656 mode_buf[1] = 0; /* Medium type - default */
1657 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1658 mode_buf[3] = 0; /* Block descriptor length */
1660 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1661 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1662 scsicmd->scsi_done(scsicmd);
1670 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1671 mode_buf[0] = 0; /* Mode data length (MSB) */
1672 mode_buf[1] = 6; /* Mode data length (LSB) */
1673 mode_buf[2] = 0; /* Medium type - default */
1674 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1675 mode_buf[4] = 0; /* reserved */
1676 mode_buf[5] = 0; /* reserved */
1677 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1678 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1679 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1681 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1682 scsicmd->scsi_done(scsicmd);
1687 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1688 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1689 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1690 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1691 scsicmd->scsi_done(scsicmd);
1694 case ALLOW_MEDIUM_REMOVAL:
1695 dprintk((KERN_DEBUG "LOCK command.\n"));
1696 if (scsicmd->cmnd[4])
1697 fsa_dev_ptr[cid].locked = 1;
1699 fsa_dev_ptr[cid].locked = 0;
1701 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1702 scsicmd->scsi_done(scsicmd);
1705 * These commands are all No-Ops
1707 case TEST_UNIT_READY:
1711 case REASSIGN_BLOCKS:
1714 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1715 scsicmd->scsi_done(scsicmd);
1719 switch (scsicmd->cmnd[0])
1726 * Hack to keep track of ordinal number of the device that
1727 * corresponds to a container. Needed to convert
1728 * containers to /dev/sd device names
1731 spin_unlock_irq(host->host_lock);
1732 if (scsicmd->request->rq_disk)
1733 strlcpy(fsa_dev_ptr[cid].devname,
1734 scsicmd->request->rq_disk->disk_name,
1735 min(sizeof(fsa_dev_ptr[cid].devname),
1736 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1737 ret = aac_read(scsicmd, cid);
1738 spin_lock_irq(host->host_lock);
1745 spin_unlock_irq(host->host_lock);
1746 ret = aac_write(scsicmd, cid);
1747 spin_lock_irq(host->host_lock);
1750 case SYNCHRONIZE_CACHE:
1751 /* Issue FIB to tell Firmware to flush it's cache */
1752 return aac_synchronize(scsicmd, cid);
1756 * Unhandled commands
1758 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1759 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1760 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1761 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1762 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1763 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1764 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1765 ? sizeof(scsicmd->sense_buffer)
1766 : sizeof(dev->fsa_dev[cid].sense_data));
1767 scsicmd->scsi_done(scsicmd);
1772 static int query_disk(struct aac_dev *dev, void __user *arg)
1774 struct aac_query_disk qd;
1775 struct fsa_dev_info *fsa_dev_ptr;
1777 fsa_dev_ptr = dev->fsa_dev;
1778 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1781 qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
1782 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1784 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1786 qd.instance = dev->scsi_host_ptr->host_no;
1788 qd.id = CONTAINER_TO_ID(qd.cnum);
1789 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1791 else return -EINVAL;
1793 qd.valid = fsa_dev_ptr[qd.cnum].valid;
1794 qd.locked = fsa_dev_ptr[qd.cnum].locked;
1795 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1797 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1802 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1803 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1805 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1810 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1812 struct aac_delete_disk dd;
1813 struct fsa_dev_info *fsa_dev_ptr;
1815 fsa_dev_ptr = dev->fsa_dev;
1817 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1820 if (dd.cnum >= dev->maximum_num_containers)
1823 * Mark this container as being deleted.
1825 fsa_dev_ptr[dd.cnum].deleted = 1;
1827 * Mark the container as no longer valid
1829 fsa_dev_ptr[dd.cnum].valid = 0;
1833 static int delete_disk(struct aac_dev *dev, void __user *arg)
1835 struct aac_delete_disk dd;
1836 struct fsa_dev_info *fsa_dev_ptr;
1838 fsa_dev_ptr = dev->fsa_dev;
1840 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1843 if (dd.cnum >= dev->maximum_num_containers)
1846 * If the container is locked, it can not be deleted by the API.
1848 if (fsa_dev_ptr[dd.cnum].locked)
1852 * Mark the container as no longer being valid.
1854 fsa_dev_ptr[dd.cnum].valid = 0;
1855 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
1860 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1863 case FSACTL_QUERY_DISK:
1864 return query_disk(dev, arg);
1865 case FSACTL_DELETE_DISK:
1866 return delete_disk(dev, arg);
1867 case FSACTL_FORCE_DELETE_DISK:
1868 return force_delete_disk(dev, arg);
1869 case FSACTL_GET_CONTAINERS:
1870 return aac_get_containers(dev);
1879 * @context: the context set in the fib - here it is scsi cmd
1880 * @fibptr: pointer to the fib
1882 * Handles the completion of a scsi command to a non dasd device
1886 static void aac_srb_callback(void *context, struct fib * fibptr)
1888 struct aac_dev *dev;
1889 struct aac_srb_reply *srbreply;
1890 struct scsi_cmnd *scsicmd;
1892 scsicmd = (struct scsi_cmnd *) context;
1893 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1898 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1900 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
1902 * Calculate resid for sg
1905 scsicmd->resid = scsicmd->request_bufflen -
1906 le32_to_cpu(srbreply->data_xfer_length);
1909 pci_unmap_sg(dev->pdev,
1910 (struct scatterlist *)scsicmd->buffer,
1912 scsicmd->sc_data_direction);
1913 else if(scsicmd->request_bufflen)
1914 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
1915 scsicmd->sc_data_direction);
1918 * First check the fib status
1921 if (le32_to_cpu(srbreply->status) != ST_OK){
1923 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1924 len = (le32_to_cpu(srbreply->sense_data_size) >
1925 sizeof(scsicmd->sense_buffer)) ?
1926 sizeof(scsicmd->sense_buffer) :
1927 le32_to_cpu(srbreply->sense_data_size);
1928 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1929 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1933 * Next check the srb status
1935 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1936 case SRB_STATUS_ERROR_RECOVERY:
1937 case SRB_STATUS_PENDING:
1938 case SRB_STATUS_SUCCESS:
1939 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1941 case SRB_STATUS_DATA_OVERRUN:
1942 switch(scsicmd->cmnd[0]){
1951 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1952 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1954 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1956 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1959 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1963 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1967 case SRB_STATUS_ABORTED:
1968 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
1970 case SRB_STATUS_ABORT_FAILED:
1971 // Not sure about this one - but assuming the hba was trying to abort for some reason
1972 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
1974 case SRB_STATUS_PARITY_ERROR:
1975 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
1977 case SRB_STATUS_NO_DEVICE:
1978 case SRB_STATUS_INVALID_PATH_ID:
1979 case SRB_STATUS_INVALID_TARGET_ID:
1980 case SRB_STATUS_INVALID_LUN:
1981 case SRB_STATUS_SELECTION_TIMEOUT:
1982 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1985 case SRB_STATUS_COMMAND_TIMEOUT:
1986 case SRB_STATUS_TIMEOUT:
1987 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
1990 case SRB_STATUS_BUSY:
1991 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1994 case SRB_STATUS_BUS_RESET:
1995 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
1998 case SRB_STATUS_MESSAGE_REJECTED:
1999 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2001 case SRB_STATUS_REQUEST_FLUSHED:
2002 case SRB_STATUS_ERROR:
2003 case SRB_STATUS_INVALID_REQUEST:
2004 case SRB_STATUS_REQUEST_SENSE_FAILED:
2005 case SRB_STATUS_NO_HBA:
2006 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2007 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2008 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2009 case SRB_STATUS_DELAYED_RETRY:
2010 case SRB_STATUS_BAD_FUNCTION:
2011 case SRB_STATUS_NOT_STARTED:
2012 case SRB_STATUS_NOT_IN_USE:
2013 case SRB_STATUS_FORCE_ABORT:
2014 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2016 #ifdef AAC_DETAILED_STATUS_INFO
2017 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2018 le32_to_cpu(srbreply->srb_status) & 0x3F,
2019 aac_get_status_string(
2020 le32_to_cpu(srbreply->srb_status) & 0x3F),
2022 le32_to_cpu(srbreply->scsi_status));
2024 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2027 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2029 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2030 len = (le32_to_cpu(srbreply->sense_data_size) >
2031 sizeof(scsicmd->sense_buffer)) ?
2032 sizeof(scsicmd->sense_buffer) :
2033 le32_to_cpu(srbreply->sense_data_size);
2034 #ifdef AAC_DETAILED_STATUS_INFO
2035 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2036 le32_to_cpu(srbreply->status), len);
2038 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2042 * OR in the scsi status (already shifted up a bit)
2044 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2046 aac_fib_complete(fibptr);
2047 aac_fib_free(fibptr);
2048 scsicmd->scsi_done(scsicmd);
2054 * @scsicmd: the scsi command block
2056 * This routine will form a FIB and fill in the aac_srb from the
2057 * scsicmd passed in.
2060 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2062 struct fib* cmd_fibcontext;
2063 struct aac_dev* dev;
2065 struct aac_srb *srbcmd;
2070 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2071 if (scsicmd->device->id >= dev->maximum_num_physicals ||
2072 scsicmd->device->lun > 7) {
2073 scsicmd->result = DID_NO_CONNECT << 16;
2074 scsicmd->scsi_done(scsicmd);
2078 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2079 switch(scsicmd->sc_data_direction){
2083 case DMA_BIDIRECTIONAL:
2084 flag = SRB_DataIn | SRB_DataOut;
2086 case DMA_FROM_DEVICE:
2090 default: /* shuts up some versions of gcc */
2091 flag = SRB_NoDataXfer;
2097 * Allocate and initialize a Fib then setup a BlockWrite command
2099 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2102 aac_fib_init(cmd_fibcontext);
2104 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
2105 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
2106 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel));
2107 srbcmd->id = cpu_to_le32(scsicmd->device->id);
2108 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
2109 srbcmd->flags = cpu_to_le32(flag);
2110 timeout = scsicmd->timeout_per_command/HZ;
2114 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
2115 srbcmd->retry_limit = 0; /* Obsolete parameter */
2116 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
2118 if( dev->dac_support == 1 ) {
2119 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
2120 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2122 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2123 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2125 * Build Scatter/Gather list
2127 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
2128 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
2129 sizeof (struct sgentry64));
2130 BUG_ON (fibsize > (dev->max_fib_size -
2131 sizeof(struct aac_fibhdr)));
2134 * Now send the Fib to the adapter
2136 status = aac_fib_send(ScsiPortCommand64, cmd_fibcontext,
2137 fibsize, FsaNormal, 0, 1,
2138 (fib_callback) aac_srb_callback,
2141 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
2142 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2144 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2145 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2147 * Build Scatter/Gather list
2149 fibsize = sizeof (struct aac_srb) +
2150 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
2151 sizeof (struct sgentry));
2152 BUG_ON (fibsize > (dev->max_fib_size -
2153 sizeof(struct aac_fibhdr)));
2156 * Now send the Fib to the adapter
2158 status = aac_fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
2159 (fib_callback) aac_srb_callback, (void *) scsicmd);
2162 * Check that the command queued to the controller
2164 if (status == -EINPROGRESS){
2168 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2169 aac_fib_complete(cmd_fibcontext);
2170 aac_fib_free(cmd_fibcontext);
2175 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2177 struct aac_dev *dev;
2178 unsigned long byte_count = 0;
2180 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2181 // Get rid of old data
2183 psg->sg[0].addr = 0;
2184 psg->sg[0].count = 0;
2185 if (scsicmd->use_sg) {
2186 struct scatterlist *sg;
2189 sg = (struct scatterlist *) scsicmd->request_buffer;
2191 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2192 scsicmd->sc_data_direction);
2193 psg->count = cpu_to_le32(sg_count);
2197 for (i = 0; i < sg_count; i++) {
2198 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2199 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2200 byte_count += sg_dma_len(sg);
2203 /* hba wants the size to be exact */
2204 if(byte_count > scsicmd->request_bufflen){
2205 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2206 (byte_count - scsicmd->request_bufflen);
2207 psg->sg[i-1].count = cpu_to_le32(temp);
2208 byte_count = scsicmd->request_bufflen;
2210 /* Check for command underflow */
2211 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2212 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2213 byte_count, scsicmd->underflow);
2216 else if(scsicmd->request_bufflen) {
2218 addr = pci_map_single(dev->pdev,
2219 scsicmd->request_buffer,
2220 scsicmd->request_bufflen,
2221 scsicmd->sc_data_direction);
2222 psg->count = cpu_to_le32(1);
2223 psg->sg[0].addr = cpu_to_le32(addr);
2224 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2225 scsicmd->SCp.dma_handle = addr;
2226 byte_count = scsicmd->request_bufflen;
2232 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2234 struct aac_dev *dev;
2235 unsigned long byte_count = 0;
2238 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2239 // Get rid of old data
2241 psg->sg[0].addr[0] = 0;
2242 psg->sg[0].addr[1] = 0;
2243 psg->sg[0].count = 0;
2244 if (scsicmd->use_sg) {
2245 struct scatterlist *sg;
2248 sg = (struct scatterlist *) scsicmd->request_buffer;
2250 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2251 scsicmd->sc_data_direction);
2252 psg->count = cpu_to_le32(sg_count);
2256 for (i = 0; i < sg_count; i++) {
2257 addr = sg_dma_address(sg);
2258 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2259 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2260 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2261 byte_count += sg_dma_len(sg);
2264 /* hba wants the size to be exact */
2265 if(byte_count > scsicmd->request_bufflen){
2266 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2267 (byte_count - scsicmd->request_bufflen);
2268 psg->sg[i-1].count = cpu_to_le32(temp);
2269 byte_count = scsicmd->request_bufflen;
2271 /* Check for command underflow */
2272 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2273 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2274 byte_count, scsicmd->underflow);
2277 else if(scsicmd->request_bufflen) {
2279 addr = pci_map_single(dev->pdev,
2280 scsicmd->request_buffer,
2281 scsicmd->request_bufflen,
2282 scsicmd->sc_data_direction);
2283 psg->count = cpu_to_le32(1);
2284 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2285 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2286 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2287 scsicmd->SCp.dma_handle = addr;
2288 byte_count = scsicmd->request_bufflen;
2293 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2295 struct Scsi_Host *host = scsicmd->device->host;
2296 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2297 unsigned long byte_count = 0;
2299 // Get rid of old data
2301 psg->sg[0].next = 0;
2302 psg->sg[0].prev = 0;
2303 psg->sg[0].addr[0] = 0;
2304 psg->sg[0].addr[1] = 0;
2305 psg->sg[0].count = 0;
2306 psg->sg[0].flags = 0;
2307 if (scsicmd->use_sg) {
2308 struct scatterlist *sg;
2311 sg = (struct scatterlist *) scsicmd->request_buffer;
2313 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2314 scsicmd->sc_data_direction);
2316 for (i = 0; i < sg_count; i++) {
2317 int count = sg_dma_len(sg);
2318 u64 addr = sg_dma_address(sg);
2319 psg->sg[i].next = 0;
2320 psg->sg[i].prev = 0;
2321 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2322 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2323 psg->sg[i].count = cpu_to_le32(count);
2324 psg->sg[i].flags = 0;
2325 byte_count += count;
2328 psg->count = cpu_to_le32(sg_count);
2329 /* hba wants the size to be exact */
2330 if(byte_count > scsicmd->request_bufflen){
2331 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2332 (byte_count - scsicmd->request_bufflen);
2333 psg->sg[i-1].count = cpu_to_le32(temp);
2334 byte_count = scsicmd->request_bufflen;
2336 /* Check for command underflow */
2337 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2338 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2339 byte_count, scsicmd->underflow);
2342 else if(scsicmd->request_bufflen) {
2345 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2346 scsicmd->request_buffer,
2347 scsicmd->request_bufflen,
2348 scsicmd->sc_data_direction);
2349 addr = scsicmd->SCp.dma_handle;
2350 count = scsicmd->request_bufflen;
2351 psg->count = cpu_to_le32(1);
2352 psg->sg[0].next = 0;
2353 psg->sg[0].prev = 0;
2354 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2355 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2356 psg->sg[0].count = cpu_to_le32(count);
2357 psg->sg[0].flags = 0;
2358 byte_count = scsicmd->request_bufflen;
2363 #ifdef AAC_DETAILED_STATUS_INFO
2365 struct aac_srb_status_info {
2371 static struct aac_srb_status_info srb_status_info[] = {
2372 { SRB_STATUS_PENDING, "Pending Status"},
2373 { SRB_STATUS_SUCCESS, "Success"},
2374 { SRB_STATUS_ABORTED, "Aborted Command"},
2375 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2376 { SRB_STATUS_ERROR, "Error Event"},
2377 { SRB_STATUS_BUSY, "Device Busy"},
2378 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2379 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2380 { SRB_STATUS_NO_DEVICE, "No Device"},
2381 { SRB_STATUS_TIMEOUT, "Timeout"},
2382 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2383 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2384 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2385 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2386 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2387 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2388 { SRB_STATUS_NO_HBA, "No HBA"},
2389 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2390 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2391 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2392 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2393 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2394 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2395 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2396 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2397 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2398 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2399 { SRB_STATUS_NOT_STARTED, "Not Started"},
2400 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2401 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2402 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2403 { 0xff, "Unknown Error"}
2406 char *aac_get_status_string(u32 status)
2410 for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
2411 if(srb_status_info[i].status == status){
2412 return srb_status_info[i].str;
2416 return "Bad Status Code";