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-2007 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/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/slab.h>
32 #include <linux/completion.h>
33 #include <linux/blkdev.h>
34 #include <linux/dma-mapping.h>
35 #include <asm/semaphore.h>
36 #include <asm/uaccess.h>
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_cmnd.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_host.h>
45 /* values for inqd_pdt: Peripheral device type in plain English */
46 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
47 #define INQD_PDT_PROC 0x03 /* Processor device */
48 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
49 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
50 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
51 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
53 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
54 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
60 #define SENCODE_NO_SENSE 0x00
61 #define SENCODE_END_OF_DATA 0x00
62 #define SENCODE_BECOMING_READY 0x04
63 #define SENCODE_INIT_CMD_REQUIRED 0x04
64 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65 #define SENCODE_INVALID_COMMAND 0x20
66 #define SENCODE_LBA_OUT_OF_RANGE 0x21
67 #define SENCODE_INVALID_CDB_FIELD 0x24
68 #define SENCODE_LUN_NOT_SUPPORTED 0x25
69 #define SENCODE_INVALID_PARAM_FIELD 0x26
70 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
71 #define SENCODE_PARAM_VALUE_INVALID 0x26
72 #define SENCODE_RESET_OCCURRED 0x29
73 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
77 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
79 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80 #define SENCODE_OVERLAPPED_COMMAND 0x4E
83 * Additional sense codes
86 #define ASENCODE_NO_SENSE 0x00
87 #define ASENCODE_END_OF_DATA 0x05
88 #define ASENCODE_BECOMING_READY 0x01
89 #define ASENCODE_INIT_CMD_REQUIRED 0x02
90 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91 #define ASENCODE_INVALID_COMMAND 0x00
92 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
93 #define ASENCODE_INVALID_CDB_FIELD 0x00
94 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
95 #define ASENCODE_INVALID_PARAM_FIELD 0x00
96 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97 #define ASENCODE_PARAM_VALUE_INVALID 0x02
98 #define ASENCODE_RESET_OCCURRED 0x00
99 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106 #define ASENCODE_OVERLAPPED_COMMAND 0x00
108 #define BYTE0(x) (unsigned char)(x)
109 #define BYTE1(x) (unsigned char)((x) >> 8)
110 #define BYTE2(x) (unsigned char)((x) >> 16)
111 #define BYTE3(x) (unsigned char)((x) >> 24)
113 /*------------------------------------------------------------------------------
114 * S T R U C T S / T Y P E D E F S
115 *----------------------------------------------------------------------------*/
116 /* SCSI inquiry data */
117 struct inquiry_data {
118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq; /* RMB | Device Type Qualifier */
120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len; /* Additional length (n-4) */
123 u8 inqd_pad1[2];/* Reserved - must be zero */
124 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
125 u8 inqd_vid[8]; /* Vendor ID */
126 u8 inqd_pid[16];/* Product ID */
127 u8 inqd_prl[4]; /* Product Revision Level */
131 * M O D U L E G L O B A L S
134 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
136 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
137 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
138 #ifdef AAC_DETAILED_STATUS_INFO
139 static char *aac_get_status_string(u32 status);
143 * Non dasd selection is handled entirely in aachba now
146 static int nondasd = -1;
147 static int dacmode = -1;
149 static int commit = -1;
150 int startup_timeout = 180;
151 int aif_timeout = 120;
153 module_param(nondasd, int, S_IRUGO|S_IWUSR);
154 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
155 module_param(dacmode, int, S_IRUGO|S_IWUSR);
156 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
157 module_param(commit, int, S_IRUGO|S_IWUSR);
158 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on");
159 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
160 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.");
161 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
162 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.");
165 module_param(numacb, int, S_IRUGO|S_IWUSR);
166 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.");
169 module_param(acbsize, int, S_IRUGO|S_IWUSR);
170 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.");
172 int expose_physicals = -1;
173 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
174 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
177 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
178 struct fib *fibptr) {
179 struct scsi_device *device;
181 if (unlikely(!scsicmd || !scsicmd->scsi_done )) {
182 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"))
184 aac_fib_complete(fibptr);
185 aac_fib_free(fibptr);
188 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
189 device = scsicmd->device;
190 if (unlikely(!device || !scsi_device_online(device))) {
191 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
192 aac_fib_complete(fibptr);
193 aac_fib_free(fibptr);
200 * aac_get_config_status - check the adapter configuration
201 * @common: adapter to query
203 * Query config status, and commit the configuration if needed.
205 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
210 if (!(fibptr = aac_fib_alloc(dev)))
213 aac_fib_init(fibptr);
215 struct aac_get_config_status *dinfo;
216 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
218 dinfo->command = cpu_to_le32(VM_ContainerConfig);
219 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
220 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
223 status = aac_fib_send(ContainerCommand,
225 sizeof (struct aac_get_config_status),
230 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
232 struct aac_get_config_status_resp *reply
233 = (struct aac_get_config_status_resp *) fib_data(fibptr);
234 dprintk((KERN_WARNING
235 "aac_get_config_status: response=%d status=%d action=%d\n",
236 le32_to_cpu(reply->response),
237 le32_to_cpu(reply->status),
238 le32_to_cpu(reply->data.action)));
239 if ((le32_to_cpu(reply->response) != ST_OK) ||
240 (le32_to_cpu(reply->status) != CT_OK) ||
241 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
242 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
246 aac_fib_complete(fibptr);
247 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
249 if ((commit == 1) || commit_flag) {
250 struct aac_commit_config * dinfo;
251 aac_fib_init(fibptr);
252 dinfo = (struct aac_commit_config *) fib_data(fibptr);
254 dinfo->command = cpu_to_le32(VM_ContainerConfig);
255 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
257 status = aac_fib_send(ContainerCommand,
259 sizeof (struct aac_commit_config),
263 aac_fib_complete(fibptr);
264 } else if (commit == 0) {
266 "aac_get_config_status: Foreign device configurations are being ignored\n");
269 aac_fib_free(fibptr);
274 * aac_get_containers - list containers
275 * @common: adapter to probe
277 * Make a list of all containers on this controller
279 int aac_get_containers(struct aac_dev *dev)
281 struct fsa_dev_info *fsa_dev_ptr;
285 struct aac_get_container_count *dinfo;
286 struct aac_get_container_count_resp *dresp;
287 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
289 if (!(fibptr = aac_fib_alloc(dev)))
292 aac_fib_init(fibptr);
293 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
294 dinfo->command = cpu_to_le32(VM_ContainerConfig);
295 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
297 status = aac_fib_send(ContainerCommand,
299 sizeof (struct aac_get_container_count),
304 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
305 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
306 aac_fib_complete(fibptr);
308 aac_fib_free(fibptr);
310 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
311 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
312 fsa_dev_ptr = kmalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
316 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
318 dev->fsa_dev = fsa_dev_ptr;
319 dev->maximum_num_containers = maximum_num_containers;
321 for (index = 0; index < dev->maximum_num_containers; ) {
322 fsa_dev_ptr[index].devname[0] = '\0';
324 status = aac_probe_container(dev, index);
327 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
332 * If there are no more containers, then stop asking.
334 if (++index >= status)
340 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
343 unsigned int transfer_len;
344 struct scatterlist *sg = scsicmd->request_buffer;
346 if (scsicmd->use_sg) {
347 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
348 transfer_len = min(sg->length, len + offset);
350 buf = scsicmd->request_buffer;
351 transfer_len = min(scsicmd->request_bufflen, len + offset);
354 memcpy(buf + offset, data, transfer_len - offset);
357 kunmap_atomic(buf - sg->offset, KM_IRQ0);
361 static void get_container_name_callback(void *context, struct fib * fibptr)
363 struct aac_get_name_resp * get_name_reply;
364 struct scsi_cmnd * scsicmd;
366 scsicmd = (struct scsi_cmnd *) context;
367 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
369 if (!aac_valid_context(scsicmd, fibptr))
372 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
373 BUG_ON(fibptr == NULL);
375 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
376 /* Failure is irrelevant, using default value instead */
377 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
378 && (get_name_reply->data[0] != '\0')) {
379 char *sp = get_name_reply->data;
380 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
384 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
385 int count = sizeof(d);
388 *dp++ = (*sp) ? *sp++ : ' ';
389 } while (--count > 0);
390 aac_internal_transfer(scsicmd, d,
391 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
395 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
397 aac_fib_complete(fibptr);
398 aac_fib_free(fibptr);
399 scsicmd->scsi_done(scsicmd);
403 * aac_get_container_name - get container name, none blocking.
405 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
408 struct aac_get_name *dinfo;
409 struct fib * cmd_fibcontext;
410 struct aac_dev * dev;
412 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
414 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
417 aac_fib_init(cmd_fibcontext);
418 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
420 dinfo->command = cpu_to_le32(VM_ContainerConfig);
421 dinfo->type = cpu_to_le32(CT_READ_NAME);
422 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
423 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
425 status = aac_fib_send(ContainerCommand,
427 sizeof (struct aac_get_name),
430 (fib_callback) get_container_name_callback,
434 * Check that the command queued to the controller
436 if (status == -EINPROGRESS) {
437 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
441 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
442 aac_fib_complete(cmd_fibcontext);
443 aac_fib_free(cmd_fibcontext);
447 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
449 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
451 if (fsa_dev_ptr[scmd_id(scsicmd)].valid)
452 return aac_scsi_cmd(scsicmd);
454 scsicmd->result = DID_NO_CONNECT << 16;
455 scsicmd->scsi_done(scsicmd);
459 static int _aac_probe_container2(void * context, struct fib * fibptr)
461 struct fsa_dev_info *fsa_dev_ptr;
462 int (*callback)(struct scsi_cmnd *);
463 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
465 if (!aac_valid_context(scsicmd, fibptr))
468 fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
470 scsicmd->SCp.Status = 0;
472 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
473 fsa_dev_ptr += scmd_id(scsicmd);
475 if ((le32_to_cpu(dresp->status) == ST_OK) &&
476 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
477 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
478 fsa_dev_ptr->valid = 1;
479 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
481 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
482 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
483 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
485 if ((fsa_dev_ptr->valid & 1) == 0)
486 fsa_dev_ptr->valid = 0;
487 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
489 aac_fib_complete(fibptr);
490 aac_fib_free(fibptr);
491 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
492 scsicmd->SCp.ptr = NULL;
493 return (*callback)(scsicmd);
496 static int _aac_probe_container1(void * context, struct fib * fibptr)
498 struct scsi_cmnd * scsicmd;
499 struct aac_mount * dresp;
500 struct aac_query_mount *dinfo;
503 dresp = (struct aac_mount *) fib_data(fibptr);
504 dresp->mnt[0].capacityhigh = 0;
505 if ((le32_to_cpu(dresp->status) != ST_OK) ||
506 ((le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
507 (le32_to_cpu(dresp->mnt[0].state) == FSCS_HIDDEN)))
508 return _aac_probe_container2(context, fibptr);
509 scsicmd = (struct scsi_cmnd *) context;
510 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
512 if (!aac_valid_context(scsicmd, fibptr))
515 aac_fib_init(fibptr);
517 dinfo = (struct aac_query_mount *)fib_data(fibptr);
519 dinfo->command = cpu_to_le32(VM_NameServe64);
520 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
521 dinfo->type = cpu_to_le32(FT_FILESYS);
523 status = aac_fib_send(ContainerCommand,
525 sizeof(struct aac_query_mount),
528 (fib_callback) _aac_probe_container2,
531 * Check that the command queued to the controller
533 if (status == -EINPROGRESS) {
534 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
538 /* Inherit results from VM_NameServe, if any */
539 dresp->status = cpu_to_le32(ST_OK);
540 return _aac_probe_container2(context, fibptr);
545 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
548 int status = -ENOMEM;
550 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
551 struct aac_query_mount *dinfo;
553 aac_fib_init(fibptr);
555 dinfo = (struct aac_query_mount *)fib_data(fibptr);
557 dinfo->command = cpu_to_le32(VM_NameServe);
558 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
559 dinfo->type = cpu_to_le32(FT_FILESYS);
560 scsicmd->SCp.ptr = (char *)callback;
562 status = aac_fib_send(ContainerCommand,
564 sizeof(struct aac_query_mount),
567 (fib_callback) _aac_probe_container1,
570 * Check that the command queued to the controller
572 if (status == -EINPROGRESS) {
573 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
577 scsicmd->SCp.ptr = NULL;
578 aac_fib_complete(fibptr);
579 aac_fib_free(fibptr);
583 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
585 fsa_dev_ptr += scmd_id(scsicmd);
586 if ((fsa_dev_ptr->valid & 1) == 0) {
587 fsa_dev_ptr->valid = 0;
588 return (*callback)(scsicmd);
596 * aac_probe_container - query a logical volume
597 * @dev: device to query
598 * @cid: container identifier
600 * Queries the controller about the given volume. The volume information
601 * is updated in the struct fsa_dev_info structure rather than returned.
603 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
605 scsicmd->device = NULL;
609 int aac_probe_container(struct aac_dev *dev, int cid)
611 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
612 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
615 if (!scsicmd || !scsidev) {
620 scsicmd->list.next = NULL;
621 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))_aac_probe_container1;
623 scsicmd->device = scsidev;
624 scsidev->sdev_state = 0;
626 scsidev->host = dev->scsi_host_ptr;
628 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
629 while (scsicmd->device == scsidev)
631 status = scsicmd->SCp.Status;
637 /* Local Structure to set SCSI inquiry data strings */
639 char vid[8]; /* Vendor ID */
640 char pid[16]; /* Product ID */
641 char prl[4]; /* Product Revision Level */
645 * InqStrCopy - string merge
646 * @a: string to copy from
647 * @b: string to copy to
649 * Copy a String from one location to another
653 static void inqstrcpy(char *a, char *b)
660 static char *container_types[] = {
686 /* Function: setinqstr
688 * Arguments: [1] pointer to void [1] int
690 * Purpose: Sets SCSI inquiry data strings for vendor, product
691 * and revision level. Allows strings to be set in platform dependant
692 * files instead of in OS dependant driver source.
695 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
697 struct scsi_inq *str;
699 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
700 memset(str, ' ', sizeof(*str));
702 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
703 char * cp = dev->supplement_adapter_info.AdapterTypeText;
704 int c = sizeof(str->vid);
705 while (*cp && *cp != ' ' && --c)
709 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
712 while (*cp && *cp != ' ')
716 /* last six chars reserved for vol type */
718 if (strlen(cp) > sizeof(str->pid)) {
719 c = cp[sizeof(str->pid)];
720 cp[sizeof(str->pid)] = '\0';
722 inqstrcpy (cp, str->pid);
724 cp[sizeof(str->pid)] = c;
726 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
728 inqstrcpy (mp->vname, str->vid);
729 /* last six chars reserved for vol type */
730 inqstrcpy (mp->model, str->pid);
733 if (tindex < ARRAY_SIZE(container_types)){
734 char *findit = str->pid;
736 for ( ; *findit != ' '; findit++); /* walk till we find a space */
737 /* RAID is superfluous in the context of a RAID device */
738 if (memcmp(findit-4, "RAID", 4) == 0)
739 *(findit -= 4) = ' ';
740 if (((findit - str->pid) + strlen(container_types[tindex]))
741 < (sizeof(str->pid) + sizeof(str->prl)))
742 inqstrcpy (container_types[tindex], findit + 1);
744 inqstrcpy ("V1.0", str->prl);
747 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
748 u8 a_sense_code, u8 incorrect_length,
749 u8 bit_pointer, u16 field_pointer,
752 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
753 sense_buf[1] = 0; /* Segment number, always zero */
755 if (incorrect_length) {
756 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
757 sense_buf[3] = BYTE3(residue);
758 sense_buf[4] = BYTE2(residue);
759 sense_buf[5] = BYTE1(residue);
760 sense_buf[6] = BYTE0(residue);
762 sense_buf[2] = sense_key; /* Sense key */
764 if (sense_key == ILLEGAL_REQUEST)
765 sense_buf[7] = 10; /* Additional sense length */
767 sense_buf[7] = 6; /* Additional sense length */
769 sense_buf[12] = sense_code; /* Additional sense code */
770 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
771 if (sense_key == ILLEGAL_REQUEST) {
774 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
775 sense_buf[15] = 0x80;/* Std sense key specific field */
776 /* Illegal parameter is in the parameter block */
778 if (sense_code == SENCODE_INVALID_CDB_FIELD)
779 sense_buf[15] = 0xc0;/* Std sense key specific field */
780 /* Illegal parameter is in the CDB block */
781 sense_buf[15] |= bit_pointer;
782 sense_buf[16] = field_pointer >> 8; /* MSB */
783 sense_buf[17] = field_pointer; /* LSB */
787 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
789 if (lba & 0xffffffff00000000LL) {
790 int cid = scmd_id(cmd);
791 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
792 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
793 SAM_STAT_CHECK_CONDITION;
794 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
796 SENCODE_INTERNAL_TARGET_FAILURE,
797 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
799 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
800 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
801 ? sizeof(cmd->sense_buffer)
802 : sizeof(dev->fsa_dev[cid].sense_data));
809 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
814 static void io_callback(void *context, struct fib * fibptr);
816 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
819 struct aac_raw_io *readcmd;
821 readcmd = (struct aac_raw_io *) fib_data(fib);
822 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
823 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
824 readcmd->count = cpu_to_le32(count<<9);
825 readcmd->cid = cpu_to_le16(scmd_id(cmd));
826 readcmd->flags = cpu_to_le16(1);
827 readcmd->bpTotal = 0;
828 readcmd->bpComplete = 0;
830 aac_build_sgraw(cmd, &readcmd->sg);
831 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
832 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
834 * Now send the Fib to the adapter
836 return aac_fib_send(ContainerRawIo,
841 (fib_callback) io_callback,
845 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
848 struct aac_read64 *readcmd;
850 readcmd = (struct aac_read64 *) fib_data(fib);
851 readcmd->command = cpu_to_le32(VM_CtHostRead64);
852 readcmd->cid = cpu_to_le16(scmd_id(cmd));
853 readcmd->sector_count = cpu_to_le16(count);
854 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
858 aac_build_sg64(cmd, &readcmd->sg);
859 fibsize = sizeof(struct aac_read64) +
860 ((le32_to_cpu(readcmd->sg.count) - 1) *
861 sizeof (struct sgentry64));
862 BUG_ON (fibsize > (fib->dev->max_fib_size -
863 sizeof(struct aac_fibhdr)));
865 * Now send the Fib to the adapter
867 return aac_fib_send(ContainerCommand64,
872 (fib_callback) io_callback,
876 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
879 struct aac_read *readcmd;
881 readcmd = (struct aac_read *) fib_data(fib);
882 readcmd->command = cpu_to_le32(VM_CtBlockRead);
883 readcmd->cid = cpu_to_le16(scmd_id(cmd));
884 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
885 readcmd->count = cpu_to_le32(count * 512);
887 aac_build_sg(cmd, &readcmd->sg);
888 fibsize = sizeof(struct aac_read) +
889 ((le32_to_cpu(readcmd->sg.count) - 1) *
890 sizeof (struct sgentry));
891 BUG_ON (fibsize > (fib->dev->max_fib_size -
892 sizeof(struct aac_fibhdr)));
894 * Now send the Fib to the adapter
896 return aac_fib_send(ContainerCommand,
901 (fib_callback) io_callback,
905 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
908 struct aac_raw_io *writecmd;
910 writecmd = (struct aac_raw_io *) fib_data(fib);
911 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
912 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
913 writecmd->count = cpu_to_le32(count<<9);
914 writecmd->cid = cpu_to_le16(scmd_id(cmd));
916 writecmd->bpTotal = 0;
917 writecmd->bpComplete = 0;
919 aac_build_sgraw(cmd, &writecmd->sg);
920 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
921 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
923 * Now send the Fib to the adapter
925 return aac_fib_send(ContainerRawIo,
930 (fib_callback) io_callback,
934 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
937 struct aac_write64 *writecmd;
939 writecmd = (struct aac_write64 *) fib_data(fib);
940 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
941 writecmd->cid = cpu_to_le16(scmd_id(cmd));
942 writecmd->sector_count = cpu_to_le16(count);
943 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
947 aac_build_sg64(cmd, &writecmd->sg);
948 fibsize = sizeof(struct aac_write64) +
949 ((le32_to_cpu(writecmd->sg.count) - 1) *
950 sizeof (struct sgentry64));
951 BUG_ON (fibsize > (fib->dev->max_fib_size -
952 sizeof(struct aac_fibhdr)));
954 * Now send the Fib to the adapter
956 return aac_fib_send(ContainerCommand64,
961 (fib_callback) io_callback,
965 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
968 struct aac_write *writecmd;
970 writecmd = (struct aac_write *) fib_data(fib);
971 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
972 writecmd->cid = cpu_to_le16(scmd_id(cmd));
973 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
974 writecmd->count = cpu_to_le32(count * 512);
975 writecmd->sg.count = cpu_to_le32(1);
976 /* ->stable is not used - it did mean which type of write */
978 aac_build_sg(cmd, &writecmd->sg);
979 fibsize = sizeof(struct aac_write) +
980 ((le32_to_cpu(writecmd->sg.count) - 1) *
981 sizeof (struct sgentry));
982 BUG_ON (fibsize > (fib->dev->max_fib_size -
983 sizeof(struct aac_fibhdr)));
985 * Now send the Fib to the adapter
987 return aac_fib_send(ContainerCommand,
992 (fib_callback) io_callback,
996 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
998 struct aac_srb * srbcmd;
1003 switch(cmd->sc_data_direction){
1007 case DMA_BIDIRECTIONAL:
1008 flag = SRB_DataIn | SRB_DataOut;
1010 case DMA_FROM_DEVICE:
1014 default: /* shuts up some versions of gcc */
1015 flag = SRB_NoDataXfer;
1019 srbcmd = (struct aac_srb*) fib_data(fib);
1020 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1021 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1022 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1023 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1024 srbcmd->flags = cpu_to_le32(flag);
1025 timeout = cmd->timeout_per_command/HZ;
1028 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1029 srbcmd->retry_limit = 0; /* Obsolete parameter */
1030 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1034 static void aac_srb_callback(void *context, struct fib * fibptr);
1036 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1039 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1041 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1042 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
1044 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1045 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1047 * Build Scatter/Gather list
1049 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1050 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1051 sizeof (struct sgentry64));
1052 BUG_ON (fibsize > (fib->dev->max_fib_size -
1053 sizeof(struct aac_fibhdr)));
1056 * Now send the Fib to the adapter
1058 return aac_fib_send(ScsiPortCommand64, fib,
1059 fibsize, FsaNormal, 0, 1,
1060 (fib_callback) aac_srb_callback,
1064 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1067 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1069 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1070 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
1072 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1073 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1075 * Build Scatter/Gather list
1077 fibsize = sizeof (struct aac_srb) +
1078 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1079 sizeof (struct sgentry));
1080 BUG_ON (fibsize > (fib->dev->max_fib_size -
1081 sizeof(struct aac_fibhdr)));
1084 * Now send the Fib to the adapter
1086 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1087 (fib_callback) aac_srb_callback, (void *) cmd);
1090 int aac_get_adapter_info(struct aac_dev* dev)
1095 struct aac_adapter_info *info;
1096 struct aac_bus_info *command;
1097 struct aac_bus_info_response *bus_info;
1099 if (!(fibptr = aac_fib_alloc(dev)))
1102 aac_fib_init(fibptr);
1103 info = (struct aac_adapter_info *) fib_data(fibptr);
1104 memset(info,0,sizeof(*info));
1106 rcode = aac_fib_send(RequestAdapterInfo,
1110 -1, 1, /* First `interrupt' command uses special wait */
1115 aac_fib_complete(fibptr);
1116 aac_fib_free(fibptr);
1119 memcpy(&dev->adapter_info, info, sizeof(*info));
1121 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1122 struct aac_supplement_adapter_info * info;
1124 aac_fib_init(fibptr);
1126 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1128 memset(info,0,sizeof(*info));
1130 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1139 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
1147 aac_fib_init(fibptr);
1149 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1151 memset(bus_info, 0, sizeof(*bus_info));
1153 command = (struct aac_bus_info *)bus_info;
1155 command->Command = cpu_to_le32(VM_Ioctl);
1156 command->ObjType = cpu_to_le32(FT_DRIVE);
1157 command->MethodId = cpu_to_le32(1);
1158 command->CtlCmd = cpu_to_le32(GetBusInfo);
1160 rcode = aac_fib_send(ContainerCommand,
1167 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1168 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1169 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1172 if (!dev->in_reset) {
1173 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1174 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1180 le32_to_cpu(dev->adapter_info.kernelbuild),
1181 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1182 dev->supplement_adapter_info.BuildDate);
1183 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1184 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1186 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1187 le32_to_cpu(dev->adapter_info.monitorbuild));
1188 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1189 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1191 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1192 le32_to_cpu(dev->adapter_info.biosbuild));
1193 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
1194 printk(KERN_INFO "%s%d: serial %x\n",
1196 le32_to_cpu(dev->adapter_info.serial[0]));
1199 dev->nondasd_support = 0;
1200 dev->raid_scsi_mode = 0;
1201 if(dev->adapter_info.options & AAC_OPT_NONDASD){
1202 dev->nondasd_support = 1;
1206 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1207 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1208 * force nondasd support on. If we decide to allow the non-dasd flag
1209 * additional changes changes will have to be made to support
1210 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1211 * changed to support the new dev->raid_scsi_mode flag instead of
1212 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1213 * function aac_detect will have to be modified where it sets up the
1214 * max number of channels based on the aac->nondasd_support flag only.
1216 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1217 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1218 dev->nondasd_support = 1;
1219 dev->raid_scsi_mode = 1;
1221 if (dev->raid_scsi_mode != 0)
1222 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1223 dev->name, dev->id);
1226 dev->nondasd_support = (nondasd!=0);
1228 if(dev->nondasd_support != 0){
1229 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1232 dev->dac_support = 0;
1233 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1234 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1235 dev->dac_support = 1;
1239 dev->dac_support = (dacmode!=0);
1241 if(dev->dac_support != 0) {
1242 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1243 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1244 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1245 dev->name, dev->id);
1246 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1247 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1248 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1249 dev->name, dev->id);
1250 dev->dac_support = 0;
1252 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1253 dev->name, dev->id);
1258 * Deal with configuring for the individualized limits of each packet
1261 dev->a_ops.adapter_scsi = (dev->dac_support)
1264 if (dev->raw_io_interface) {
1265 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1268 dev->a_ops.adapter_read = aac_read_raw_io;
1269 dev->a_ops.adapter_write = aac_write_raw_io;
1271 dev->a_ops.adapter_bounds = aac_bounds_32;
1272 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1273 sizeof(struct aac_fibhdr) -
1274 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1275 sizeof(struct sgentry);
1276 if (dev->dac_support) {
1277 dev->a_ops.adapter_read = aac_read_block64;
1278 dev->a_ops.adapter_write = aac_write_block64;
1280 * 38 scatter gather elements
1282 dev->scsi_host_ptr->sg_tablesize =
1283 (dev->max_fib_size -
1284 sizeof(struct aac_fibhdr) -
1285 sizeof(struct aac_write64) +
1286 sizeof(struct sgentry64)) /
1287 sizeof(struct sgentry64);
1289 dev->a_ops.adapter_read = aac_read_block;
1290 dev->a_ops.adapter_write = aac_write_block;
1292 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1293 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1295 * Worst case size that could cause sg overflow when
1296 * we break up SG elements that are larger than 64KB.
1297 * Would be nice if we could tell the SCSI layer what
1298 * the maximum SG element size can be. Worst case is
1299 * (sg_tablesize-1) 4KB elements with one 64KB
1301 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1303 dev->scsi_host_ptr->max_sectors =
1304 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1308 aac_fib_complete(fibptr);
1309 aac_fib_free(fibptr);
1315 static void io_callback(void *context, struct fib * fibptr)
1317 struct aac_dev *dev;
1318 struct aac_read_reply *readreply;
1319 struct scsi_cmnd *scsicmd;
1322 scsicmd = (struct scsi_cmnd *) context;
1323 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1325 if (!aac_valid_context(scsicmd, fibptr))
1328 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1329 cid = scmd_id(scsicmd);
1331 if (nblank(dprintk(x))) {
1333 switch (scsicmd->cmnd[0]) {
1336 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1337 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1341 lba = ((u64)scsicmd->cmnd[2] << 56) |
1342 ((u64)scsicmd->cmnd[3] << 48) |
1343 ((u64)scsicmd->cmnd[4] << 40) |
1344 ((u64)scsicmd->cmnd[5] << 32) |
1345 ((u64)scsicmd->cmnd[6] << 24) |
1346 (scsicmd->cmnd[7] << 16) |
1347 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1351 lba = ((u64)scsicmd->cmnd[2] << 24) |
1352 (scsicmd->cmnd[3] << 16) |
1353 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1356 lba = ((u64)scsicmd->cmnd[2] << 24) |
1357 (scsicmd->cmnd[3] << 16) |
1358 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1362 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1363 smp_processor_id(), (unsigned long long)lba, jiffies);
1366 BUG_ON(fibptr == NULL);
1369 pci_unmap_sg(dev->pdev,
1370 (struct scatterlist *)scsicmd->request_buffer,
1372 scsicmd->sc_data_direction);
1373 else if(scsicmd->request_bufflen)
1374 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
1375 scsicmd->request_bufflen,
1376 scsicmd->sc_data_direction);
1377 readreply = (struct aac_read_reply *)fib_data(fibptr);
1378 if (le32_to_cpu(readreply->status) == ST_OK)
1379 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1381 #ifdef AAC_DETAILED_STATUS_INFO
1382 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1383 le32_to_cpu(readreply->status));
1385 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1386 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1388 SENCODE_INTERNAL_TARGET_FAILURE,
1389 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1391 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1392 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1393 ? sizeof(scsicmd->sense_buffer)
1394 : sizeof(dev->fsa_dev[cid].sense_data));
1396 aac_fib_complete(fibptr);
1397 aac_fib_free(fibptr);
1399 scsicmd->scsi_done(scsicmd);
1402 static int aac_read(struct scsi_cmnd * scsicmd)
1407 struct aac_dev *dev;
1408 struct fib * cmd_fibcontext;
1410 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1412 * Get block address and transfer length
1414 switch (scsicmd->cmnd[0]) {
1416 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1418 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1419 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1420 count = scsicmd->cmnd[4];
1426 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1428 lba = ((u64)scsicmd->cmnd[2] << 56) |
1429 ((u64)scsicmd->cmnd[3] << 48) |
1430 ((u64)scsicmd->cmnd[4] << 40) |
1431 ((u64)scsicmd->cmnd[5] << 32) |
1432 ((u64)scsicmd->cmnd[6] << 24) |
1433 (scsicmd->cmnd[7] << 16) |
1434 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1435 count = (scsicmd->cmnd[10] << 24) |
1436 (scsicmd->cmnd[11] << 16) |
1437 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1440 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1442 lba = ((u64)scsicmd->cmnd[2] << 24) |
1443 (scsicmd->cmnd[3] << 16) |
1444 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1445 count = (scsicmd->cmnd[6] << 24) |
1446 (scsicmd->cmnd[7] << 16) |
1447 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1450 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1452 lba = ((u64)scsicmd->cmnd[2] << 24) |
1453 (scsicmd->cmnd[3] << 16) |
1454 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1455 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1458 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1459 smp_processor_id(), (unsigned long long)lba, jiffies));
1460 if (aac_adapter_bounds(dev,scsicmd,lba))
1463 * Alocate and initialize a Fib
1465 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1469 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1472 * Check that the command queued to the controller
1474 if (status == -EINPROGRESS) {
1475 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1479 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1481 * For some reason, the Fib didn't queue, return QUEUE_FULL
1483 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1484 scsicmd->scsi_done(scsicmd);
1485 aac_fib_complete(cmd_fibcontext);
1486 aac_fib_free(cmd_fibcontext);
1490 static int aac_write(struct scsi_cmnd * scsicmd)
1495 struct aac_dev *dev;
1496 struct fib * cmd_fibcontext;
1498 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1500 * Get block address and transfer length
1502 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1504 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1505 count = scsicmd->cmnd[4];
1508 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1509 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1511 lba = ((u64)scsicmd->cmnd[2] << 56) |
1512 ((u64)scsicmd->cmnd[3] << 48) |
1513 ((u64)scsicmd->cmnd[4] << 40) |
1514 ((u64)scsicmd->cmnd[5] << 32) |
1515 ((u64)scsicmd->cmnd[6] << 24) |
1516 (scsicmd->cmnd[7] << 16) |
1517 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1518 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1519 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1520 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1521 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1523 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1524 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1525 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1526 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1528 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1529 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1530 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1532 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1533 smp_processor_id(), (unsigned long long)lba, jiffies));
1534 if (aac_adapter_bounds(dev,scsicmd,lba))
1537 * Allocate and initialize a Fib then setup a BlockWrite command
1539 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1540 scsicmd->result = DID_ERROR << 16;
1541 scsicmd->scsi_done(scsicmd);
1545 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count);
1548 * Check that the command queued to the controller
1550 if (status == -EINPROGRESS) {
1551 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1555 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1557 * For some reason, the Fib didn't queue, return QUEUE_FULL
1559 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1560 scsicmd->scsi_done(scsicmd);
1562 aac_fib_complete(cmd_fibcontext);
1563 aac_fib_free(cmd_fibcontext);
1567 static void synchronize_callback(void *context, struct fib *fibptr)
1569 struct aac_synchronize_reply *synchronizereply;
1570 struct scsi_cmnd *cmd;
1573 cmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1575 if (!aac_valid_context(cmd, fibptr))
1578 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1579 smp_processor_id(), jiffies));
1580 BUG_ON(fibptr == NULL);
1583 synchronizereply = fib_data(fibptr);
1584 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1585 cmd->result = DID_OK << 16 |
1586 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1588 struct scsi_device *sdev = cmd->device;
1589 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1590 u32 cid = sdev_id(sdev);
1592 "synchronize_callback: synchronize failed, status = %d\n",
1593 le32_to_cpu(synchronizereply->status));
1594 cmd->result = DID_OK << 16 |
1595 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1596 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1598 SENCODE_INTERNAL_TARGET_FAILURE,
1599 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1601 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1602 min(sizeof(dev->fsa_dev[cid].sense_data),
1603 sizeof(cmd->sense_buffer)));
1606 aac_fib_complete(fibptr);
1607 aac_fib_free(fibptr);
1608 cmd->scsi_done(cmd);
1611 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1614 struct fib *cmd_fibcontext;
1615 struct aac_synchronize *synchronizecmd;
1616 struct scsi_cmnd *cmd;
1617 struct scsi_device *sdev = scsicmd->device;
1619 struct aac_dev *aac;
1620 unsigned long flags;
1623 * Wait for all outstanding queued commands to complete to this
1624 * specific target (block).
1626 spin_lock_irqsave(&sdev->list_lock, flags);
1627 list_for_each_entry(cmd, &sdev->cmd_list, list)
1628 if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1633 spin_unlock_irqrestore(&sdev->list_lock, flags);
1636 * Yield the processor (requeue for later)
1639 return SCSI_MLQUEUE_DEVICE_BUSY;
1641 aac = (struct aac_dev *)scsicmd->device->host->hostdata;
1643 return SCSI_MLQUEUE_HOST_BUSY;
1646 * Allocate and initialize a Fib
1648 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1649 return SCSI_MLQUEUE_HOST_BUSY;
1651 aac_fib_init(cmd_fibcontext);
1653 synchronizecmd = fib_data(cmd_fibcontext);
1654 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1655 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1656 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
1657 synchronizecmd->count =
1658 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1661 * Now send the Fib to the adapter
1663 status = aac_fib_send(ContainerCommand,
1665 sizeof(struct aac_synchronize),
1668 (fib_callback)synchronize_callback,
1672 * Check that the command queued to the controller
1674 if (status == -EINPROGRESS) {
1675 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1680 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1681 aac_fib_complete(cmd_fibcontext);
1682 aac_fib_free(cmd_fibcontext);
1683 return SCSI_MLQUEUE_HOST_BUSY;
1687 * aac_scsi_cmd() - Process SCSI command
1688 * @scsicmd: SCSI command block
1690 * Emulate a SCSI command and queue the required request for the
1694 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1697 struct Scsi_Host *host = scsicmd->device->host;
1698 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1699 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1701 if (fsa_dev_ptr == NULL)
1704 * If the bus, id or lun is out of range, return fail
1705 * Test does not apply to ID 16, the pseudo id for the controller
1708 if (scmd_id(scsicmd) != host->this_id) {
1709 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
1710 if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
1711 (scsicmd->device->lun != 0)) {
1712 scsicmd->result = DID_NO_CONNECT << 16;
1713 scsicmd->scsi_done(scsicmd);
1716 cid = scmd_id(scsicmd);
1719 * If the target container doesn't exist, it may have
1720 * been newly created
1722 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1723 switch (scsicmd->cmnd[0]) {
1724 case SERVICE_ACTION_IN:
1725 if (!(dev->raw_io_interface) ||
1726 !(dev->raw_io_64) ||
1727 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1731 case TEST_UNIT_READY:
1734 return _aac_probe_container(scsicmd,
1735 aac_probe_container_callback2);
1740 } else { /* check for physical non-dasd devices */
1741 if ((dev->nondasd_support == 1) || expose_physicals) {
1744 return aac_send_srb_fib(scsicmd);
1746 scsicmd->result = DID_NO_CONNECT << 16;
1747 scsicmd->scsi_done(scsicmd);
1753 * else Command for the controller itself
1755 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1756 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1758 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 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,
1762 SENCODE_INVALID_COMMAND,
1763 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1764 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1765 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1766 ? sizeof(scsicmd->sense_buffer)
1767 : sizeof(dev->fsa_dev[cid].sense_data));
1768 scsicmd->scsi_done(scsicmd);
1773 /* Handle commands here that don't really require going out to the adapter */
1774 switch (scsicmd->cmnd[0]) {
1777 struct inquiry_data inq_data;
1779 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
1780 memset(&inq_data, 0, sizeof (struct inquiry_data));
1782 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1783 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 */
1784 inq_data.inqd_len = 31;
1785 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1786 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1788 * Set the Vendor, Product, and Revision Level
1789 * see: <vendor>.c i.e. aac.c
1791 if (scmd_id(scsicmd) == host->this_id) {
1792 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
1793 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1794 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1795 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1796 scsicmd->scsi_done(scsicmd);
1801 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1802 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1803 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1804 return aac_get_container_name(scsicmd);
1806 case SERVICE_ACTION_IN:
1807 if (!(dev->raw_io_interface) ||
1808 !(dev->raw_io_64) ||
1809 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1815 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1816 capacity = fsa_dev_ptr[cid].size - 1;
1817 cp[0] = (capacity >> 56) & 0xff;
1818 cp[1] = (capacity >> 48) & 0xff;
1819 cp[2] = (capacity >> 40) & 0xff;
1820 cp[3] = (capacity >> 32) & 0xff;
1821 cp[4] = (capacity >> 24) & 0xff;
1822 cp[5] = (capacity >> 16) & 0xff;
1823 cp[6] = (capacity >> 8) & 0xff;
1824 cp[7] = (capacity >> 0) & 0xff;
1830 aac_internal_transfer(scsicmd, cp, 0,
1831 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
1832 if (sizeof(cp) < scsicmd->cmnd[13]) {
1833 unsigned int len, offset = sizeof(cp);
1835 memset(cp, 0, offset);
1837 len = min_t(size_t, scsicmd->cmnd[13] - offset,
1839 aac_internal_transfer(scsicmd, cp, offset, len);
1840 } while ((offset += len) < scsicmd->cmnd[13]);
1843 /* Do not cache partition table for arrays */
1844 scsicmd->device->removable = 1;
1846 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1847 scsicmd->scsi_done(scsicmd);
1857 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1858 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
1859 capacity = fsa_dev_ptr[cid].size - 1;
1863 cp[0] = (capacity >> 24) & 0xff;
1864 cp[1] = (capacity >> 16) & 0xff;
1865 cp[2] = (capacity >> 8) & 0xff;
1866 cp[3] = (capacity >> 0) & 0xff;
1871 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1872 /* Do not cache partition table for arrays */
1873 scsicmd->device->removable = 1;
1875 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1876 scsicmd->scsi_done(scsicmd);
1885 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1886 mode_buf[0] = 3; /* Mode data length */
1887 mode_buf[1] = 0; /* Medium type - default */
1888 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1889 mode_buf[3] = 0; /* Block descriptor length */
1891 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1892 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1893 scsicmd->scsi_done(scsicmd);
1901 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1902 mode_buf[0] = 0; /* Mode data length (MSB) */
1903 mode_buf[1] = 6; /* Mode data length (LSB) */
1904 mode_buf[2] = 0; /* Medium type - default */
1905 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1906 mode_buf[4] = 0; /* reserved */
1907 mode_buf[5] = 0; /* reserved */
1908 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1909 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1910 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1912 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1913 scsicmd->scsi_done(scsicmd);
1918 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1919 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1920 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1921 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1922 scsicmd->scsi_done(scsicmd);
1925 case ALLOW_MEDIUM_REMOVAL:
1926 dprintk((KERN_DEBUG "LOCK command.\n"));
1927 if (scsicmd->cmnd[4])
1928 fsa_dev_ptr[cid].locked = 1;
1930 fsa_dev_ptr[cid].locked = 0;
1932 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1933 scsicmd->scsi_done(scsicmd);
1936 * These commands are all No-Ops
1938 case TEST_UNIT_READY:
1942 case REASSIGN_BLOCKS:
1945 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1946 scsicmd->scsi_done(scsicmd);
1950 switch (scsicmd->cmnd[0])
1959 * Hack to keep track of ordinal number of the device that
1960 * corresponds to a container. Needed to convert
1961 * containers to /dev/sd device names
1964 if (scsicmd->request->rq_disk)
1965 strlcpy(fsa_dev_ptr[cid].devname,
1966 scsicmd->request->rq_disk->disk_name,
1967 min(sizeof(fsa_dev_ptr[cid].devname),
1968 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1970 return aac_read(scsicmd);
1978 return aac_write(scsicmd);
1980 case SYNCHRONIZE_CACHE:
1981 /* Issue FIB to tell Firmware to flush it's cache */
1982 return aac_synchronize(scsicmd);
1986 * Unhandled commands
1988 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1989 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1990 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1991 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1992 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1993 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1994 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1995 ? sizeof(scsicmd->sense_buffer)
1996 : sizeof(dev->fsa_dev[cid].sense_data));
1997 scsicmd->scsi_done(scsicmd);
2002 static int query_disk(struct aac_dev *dev, void __user *arg)
2004 struct aac_query_disk qd;
2005 struct fsa_dev_info *fsa_dev_ptr;
2007 fsa_dev_ptr = dev->fsa_dev;
2010 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2014 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2016 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2018 qd.instance = dev->scsi_host_ptr->host_no;
2020 qd.id = CONTAINER_TO_ID(qd.cnum);
2021 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2023 else return -EINVAL;
2025 qd.valid = fsa_dev_ptr[qd.cnum].valid;
2026 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2027 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2029 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2034 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2035 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2037 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2042 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2044 struct aac_delete_disk dd;
2045 struct fsa_dev_info *fsa_dev_ptr;
2047 fsa_dev_ptr = dev->fsa_dev;
2051 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2054 if (dd.cnum >= dev->maximum_num_containers)
2057 * Mark this container as being deleted.
2059 fsa_dev_ptr[dd.cnum].deleted = 1;
2061 * Mark the container as no longer valid
2063 fsa_dev_ptr[dd.cnum].valid = 0;
2067 static int delete_disk(struct aac_dev *dev, void __user *arg)
2069 struct aac_delete_disk dd;
2070 struct fsa_dev_info *fsa_dev_ptr;
2072 fsa_dev_ptr = dev->fsa_dev;
2076 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2079 if (dd.cnum >= dev->maximum_num_containers)
2082 * If the container is locked, it can not be deleted by the API.
2084 if (fsa_dev_ptr[dd.cnum].locked)
2088 * Mark the container as no longer being valid.
2090 fsa_dev_ptr[dd.cnum].valid = 0;
2091 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2096 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2099 case FSACTL_QUERY_DISK:
2100 return query_disk(dev, arg);
2101 case FSACTL_DELETE_DISK:
2102 return delete_disk(dev, arg);
2103 case FSACTL_FORCE_DELETE_DISK:
2104 return force_delete_disk(dev, arg);
2105 case FSACTL_GET_CONTAINERS:
2106 return aac_get_containers(dev);
2115 * @context: the context set in the fib - here it is scsi cmd
2116 * @fibptr: pointer to the fib
2118 * Handles the completion of a scsi command to a non dasd device
2122 static void aac_srb_callback(void *context, struct fib * fibptr)
2124 struct aac_dev *dev;
2125 struct aac_srb_reply *srbreply;
2126 struct scsi_cmnd *scsicmd;
2128 scsicmd = (struct scsi_cmnd *) context;
2129 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
2131 if (!aac_valid_context(scsicmd, fibptr))
2134 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2136 BUG_ON(fibptr == NULL);
2138 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2140 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2142 * Calculate resid for sg
2145 scsicmd->resid = scsicmd->request_bufflen -
2146 le32_to_cpu(srbreply->data_xfer_length);
2149 pci_unmap_sg(dev->pdev,
2150 (struct scatterlist *)scsicmd->request_buffer,
2152 scsicmd->sc_data_direction);
2153 else if(scsicmd->request_bufflen)
2154 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
2155 scsicmd->sc_data_direction);
2158 * First check the fib status
2161 if (le32_to_cpu(srbreply->status) != ST_OK){
2163 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2164 len = (le32_to_cpu(srbreply->sense_data_size) >
2165 sizeof(scsicmd->sense_buffer)) ?
2166 sizeof(scsicmd->sense_buffer) :
2167 le32_to_cpu(srbreply->sense_data_size);
2168 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2169 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2173 * Next check the srb status
2175 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2176 case SRB_STATUS_ERROR_RECOVERY:
2177 case SRB_STATUS_PENDING:
2178 case SRB_STATUS_SUCCESS:
2179 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2181 case SRB_STATUS_DATA_OVERRUN:
2182 switch(scsicmd->cmnd[0]){
2191 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
2192 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2194 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2196 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2199 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2203 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2207 case SRB_STATUS_ABORTED:
2208 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2210 case SRB_STATUS_ABORT_FAILED:
2211 // Not sure about this one - but assuming the hba was trying to abort for some reason
2212 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2214 case SRB_STATUS_PARITY_ERROR:
2215 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2217 case SRB_STATUS_NO_DEVICE:
2218 case SRB_STATUS_INVALID_PATH_ID:
2219 case SRB_STATUS_INVALID_TARGET_ID:
2220 case SRB_STATUS_INVALID_LUN:
2221 case SRB_STATUS_SELECTION_TIMEOUT:
2222 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2225 case SRB_STATUS_COMMAND_TIMEOUT:
2226 case SRB_STATUS_TIMEOUT:
2227 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2230 case SRB_STATUS_BUSY:
2231 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2234 case SRB_STATUS_BUS_RESET:
2235 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2238 case SRB_STATUS_MESSAGE_REJECTED:
2239 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2241 case SRB_STATUS_REQUEST_FLUSHED:
2242 case SRB_STATUS_ERROR:
2243 case SRB_STATUS_INVALID_REQUEST:
2244 case SRB_STATUS_REQUEST_SENSE_FAILED:
2245 case SRB_STATUS_NO_HBA:
2246 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2247 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2248 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2249 case SRB_STATUS_DELAYED_RETRY:
2250 case SRB_STATUS_BAD_FUNCTION:
2251 case SRB_STATUS_NOT_STARTED:
2252 case SRB_STATUS_NOT_IN_USE:
2253 case SRB_STATUS_FORCE_ABORT:
2254 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2256 #ifdef AAC_DETAILED_STATUS_INFO
2257 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2258 le32_to_cpu(srbreply->srb_status) & 0x3F,
2259 aac_get_status_string(
2260 le32_to_cpu(srbreply->srb_status) & 0x3F),
2262 le32_to_cpu(srbreply->scsi_status));
2264 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2267 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2269 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2270 len = (le32_to_cpu(srbreply->sense_data_size) >
2271 sizeof(scsicmd->sense_buffer)) ?
2272 sizeof(scsicmd->sense_buffer) :
2273 le32_to_cpu(srbreply->sense_data_size);
2274 #ifdef AAC_DETAILED_STATUS_INFO
2275 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2276 le32_to_cpu(srbreply->status), len);
2278 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2282 * OR in the scsi status (already shifted up a bit)
2284 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2286 aac_fib_complete(fibptr);
2287 aac_fib_free(fibptr);
2288 scsicmd->scsi_done(scsicmd);
2294 * @scsicmd: the scsi command block
2296 * This routine will form a FIB and fill in the aac_srb from the
2297 * scsicmd passed in.
2300 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2302 struct fib* cmd_fibcontext;
2303 struct aac_dev* dev;
2306 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2307 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2308 scsicmd->device->lun > 7) {
2309 scsicmd->result = DID_NO_CONNECT << 16;
2310 scsicmd->scsi_done(scsicmd);
2315 * Allocate and initialize a Fib then setup a BlockWrite command
2317 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2320 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2323 * Check that the command queued to the controller
2325 if (status == -EINPROGRESS) {
2326 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2330 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2331 aac_fib_complete(cmd_fibcontext);
2332 aac_fib_free(cmd_fibcontext);
2337 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2339 struct aac_dev *dev;
2340 unsigned long byte_count = 0;
2342 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2343 // Get rid of old data
2345 psg->sg[0].addr = 0;
2346 psg->sg[0].count = 0;
2347 if (scsicmd->use_sg) {
2348 struct scatterlist *sg;
2351 sg = (struct scatterlist *) scsicmd->request_buffer;
2353 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2354 scsicmd->sc_data_direction);
2355 psg->count = cpu_to_le32(sg_count);
2357 for (i = 0; i < sg_count; i++) {
2358 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2359 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2360 byte_count += sg_dma_len(sg);
2363 /* hba wants the size to be exact */
2364 if(byte_count > scsicmd->request_bufflen){
2365 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2366 (byte_count - scsicmd->request_bufflen);
2367 psg->sg[i-1].count = cpu_to_le32(temp);
2368 byte_count = scsicmd->request_bufflen;
2370 /* Check for command underflow */
2371 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2372 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2373 byte_count, scsicmd->underflow);
2376 else if(scsicmd->request_bufflen) {
2378 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2379 scsicmd->request_buffer,
2380 scsicmd->request_bufflen,
2381 scsicmd->sc_data_direction);
2382 addr = scsicmd->SCp.dma_handle;
2383 psg->count = cpu_to_le32(1);
2384 psg->sg[0].addr = cpu_to_le32(addr);
2385 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2386 byte_count = scsicmd->request_bufflen;
2392 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2394 struct aac_dev *dev;
2395 unsigned long byte_count = 0;
2398 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2399 // Get rid of old data
2401 psg->sg[0].addr[0] = 0;
2402 psg->sg[0].addr[1] = 0;
2403 psg->sg[0].count = 0;
2404 if (scsicmd->use_sg) {
2405 struct scatterlist *sg;
2408 sg = (struct scatterlist *) scsicmd->request_buffer;
2410 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2411 scsicmd->sc_data_direction);
2413 for (i = 0; i < sg_count; i++) {
2414 int count = sg_dma_len(sg);
2415 addr = sg_dma_address(sg);
2416 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2417 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2418 psg->sg[i].count = cpu_to_le32(count);
2419 byte_count += count;
2422 psg->count = cpu_to_le32(sg_count);
2423 /* hba wants the size to be exact */
2424 if(byte_count > scsicmd->request_bufflen){
2425 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2426 (byte_count - scsicmd->request_bufflen);
2427 psg->sg[i-1].count = cpu_to_le32(temp);
2428 byte_count = scsicmd->request_bufflen;
2430 /* Check for command underflow */
2431 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2432 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2433 byte_count, scsicmd->underflow);
2436 else if(scsicmd->request_bufflen) {
2437 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2438 scsicmd->request_buffer,
2439 scsicmd->request_bufflen,
2440 scsicmd->sc_data_direction);
2441 addr = scsicmd->SCp.dma_handle;
2442 psg->count = cpu_to_le32(1);
2443 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2444 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2445 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2446 byte_count = scsicmd->request_bufflen;
2451 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2453 struct Scsi_Host *host = scsicmd->device->host;
2454 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2455 unsigned long byte_count = 0;
2457 // Get rid of old data
2459 psg->sg[0].next = 0;
2460 psg->sg[0].prev = 0;
2461 psg->sg[0].addr[0] = 0;
2462 psg->sg[0].addr[1] = 0;
2463 psg->sg[0].count = 0;
2464 psg->sg[0].flags = 0;
2465 if (scsicmd->use_sg) {
2466 struct scatterlist *sg;
2469 sg = (struct scatterlist *) scsicmd->request_buffer;
2471 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2472 scsicmd->sc_data_direction);
2474 for (i = 0; i < sg_count; i++) {
2475 int count = sg_dma_len(sg);
2476 u64 addr = sg_dma_address(sg);
2477 psg->sg[i].next = 0;
2478 psg->sg[i].prev = 0;
2479 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2480 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2481 psg->sg[i].count = cpu_to_le32(count);
2482 psg->sg[i].flags = 0;
2483 byte_count += count;
2486 psg->count = cpu_to_le32(sg_count);
2487 /* hba wants the size to be exact */
2488 if(byte_count > scsicmd->request_bufflen){
2489 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2490 (byte_count - scsicmd->request_bufflen);
2491 psg->sg[i-1].count = cpu_to_le32(temp);
2492 byte_count = scsicmd->request_bufflen;
2494 /* Check for command underflow */
2495 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2496 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2497 byte_count, scsicmd->underflow);
2500 else if(scsicmd->request_bufflen) {
2503 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2504 scsicmd->request_buffer,
2505 scsicmd->request_bufflen,
2506 scsicmd->sc_data_direction);
2507 addr = scsicmd->SCp.dma_handle;
2508 count = scsicmd->request_bufflen;
2509 psg->count = cpu_to_le32(1);
2510 psg->sg[0].next = 0;
2511 psg->sg[0].prev = 0;
2512 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2513 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2514 psg->sg[0].count = cpu_to_le32(count);
2515 psg->sg[0].flags = 0;
2516 byte_count = scsicmd->request_bufflen;
2521 #ifdef AAC_DETAILED_STATUS_INFO
2523 struct aac_srb_status_info {
2529 static struct aac_srb_status_info srb_status_info[] = {
2530 { SRB_STATUS_PENDING, "Pending Status"},
2531 { SRB_STATUS_SUCCESS, "Success"},
2532 { SRB_STATUS_ABORTED, "Aborted Command"},
2533 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2534 { SRB_STATUS_ERROR, "Error Event"},
2535 { SRB_STATUS_BUSY, "Device Busy"},
2536 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2537 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2538 { SRB_STATUS_NO_DEVICE, "No Device"},
2539 { SRB_STATUS_TIMEOUT, "Timeout"},
2540 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2541 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2542 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2543 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2544 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2545 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2546 { SRB_STATUS_NO_HBA, "No HBA"},
2547 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2548 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2549 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2550 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2551 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2552 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2553 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2554 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2555 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2556 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2557 { SRB_STATUS_NOT_STARTED, "Not Started"},
2558 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2559 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2560 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2561 { 0xff, "Unknown Error"}
2564 char *aac_get_status_string(u32 status)
2568 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2569 if (srb_status_info[i].status == status)
2570 return srb_status_info[i].str;
2572 return "Bad Status Code";