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;
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_named(commit, aac_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");
176 int aac_reset_devices = 0;
177 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
178 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
180 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
181 struct fib *fibptr) {
182 struct scsi_device *device;
184 if (unlikely(!scsicmd || !scsicmd->scsi_done )) {
185 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"))
187 aac_fib_complete(fibptr);
188 aac_fib_free(fibptr);
191 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
192 device = scsicmd->device;
193 if (unlikely(!device || !scsi_device_online(device))) {
194 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
195 aac_fib_complete(fibptr);
196 aac_fib_free(fibptr);
203 * aac_get_config_status - check the adapter configuration
204 * @common: adapter to query
206 * Query config status, and commit the configuration if needed.
208 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
213 if (!(fibptr = aac_fib_alloc(dev)))
216 aac_fib_init(fibptr);
218 struct aac_get_config_status *dinfo;
219 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
221 dinfo->command = cpu_to_le32(VM_ContainerConfig);
222 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
223 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
226 status = aac_fib_send(ContainerCommand,
228 sizeof (struct aac_get_config_status),
233 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
235 struct aac_get_config_status_resp *reply
236 = (struct aac_get_config_status_resp *) fib_data(fibptr);
237 dprintk((KERN_WARNING
238 "aac_get_config_status: response=%d status=%d action=%d\n",
239 le32_to_cpu(reply->response),
240 le32_to_cpu(reply->status),
241 le32_to_cpu(reply->data.action)));
242 if ((le32_to_cpu(reply->response) != ST_OK) ||
243 (le32_to_cpu(reply->status) != CT_OK) ||
244 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
245 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
249 aac_fib_complete(fibptr);
250 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
252 if ((aac_commit == 1) || commit_flag) {
253 struct aac_commit_config * dinfo;
254 aac_fib_init(fibptr);
255 dinfo = (struct aac_commit_config *) fib_data(fibptr);
257 dinfo->command = cpu_to_le32(VM_ContainerConfig);
258 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
260 status = aac_fib_send(ContainerCommand,
262 sizeof (struct aac_commit_config),
266 aac_fib_complete(fibptr);
267 } else if (aac_commit == 0) {
269 "aac_get_config_status: Foreign device configurations are being ignored\n");
272 aac_fib_free(fibptr);
277 * aac_get_containers - list containers
278 * @common: adapter to probe
280 * Make a list of all containers on this controller
282 int aac_get_containers(struct aac_dev *dev)
284 struct fsa_dev_info *fsa_dev_ptr;
288 struct aac_get_container_count *dinfo;
289 struct aac_get_container_count_resp *dresp;
290 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
292 if (!(fibptr = aac_fib_alloc(dev)))
295 aac_fib_init(fibptr);
296 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
297 dinfo->command = cpu_to_le32(VM_ContainerConfig);
298 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
300 status = aac_fib_send(ContainerCommand,
302 sizeof (struct aac_get_container_count),
307 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
308 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
309 aac_fib_complete(fibptr);
311 aac_fib_free(fibptr);
313 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
314 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
315 fsa_dev_ptr = kmalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
319 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
321 dev->fsa_dev = fsa_dev_ptr;
322 dev->maximum_num_containers = maximum_num_containers;
324 for (index = 0; index < dev->maximum_num_containers; ) {
325 fsa_dev_ptr[index].devname[0] = '\0';
327 status = aac_probe_container(dev, index);
330 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
335 * If there are no more containers, then stop asking.
337 if (++index >= status)
343 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
347 struct scatterlist *sg = scsi_sglist(scsicmd);
349 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
350 transfer_len = min(sg->length, len + offset);
352 transfer_len -= offset;
353 if (buf && transfer_len > 0)
354 memcpy(buf + offset, data, transfer_len);
356 kunmap_atomic(buf - sg->offset, KM_IRQ0);
360 static void get_container_name_callback(void *context, struct fib * fibptr)
362 struct aac_get_name_resp * get_name_reply;
363 struct scsi_cmnd * scsicmd;
365 scsicmd = (struct scsi_cmnd *) context;
367 if (!aac_valid_context(scsicmd, fibptr))
370 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
371 BUG_ON(fibptr == NULL);
373 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
374 /* Failure is irrelevant, using default value instead */
375 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
376 && (get_name_reply->data[0] != '\0')) {
377 char *sp = get_name_reply->data;
378 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
382 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
383 int count = sizeof(d);
386 *dp++ = (*sp) ? *sp++ : ' ';
387 } while (--count > 0);
388 aac_internal_transfer(scsicmd, d,
389 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
393 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
395 aac_fib_complete(fibptr);
396 aac_fib_free(fibptr);
397 scsicmd->scsi_done(scsicmd);
401 * aac_get_container_name - get container name, none blocking.
403 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
406 struct aac_get_name *dinfo;
407 struct fib * cmd_fibcontext;
408 struct aac_dev * dev;
410 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
412 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
415 aac_fib_init(cmd_fibcontext);
416 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
418 dinfo->command = cpu_to_le32(VM_ContainerConfig);
419 dinfo->type = cpu_to_le32(CT_READ_NAME);
420 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
421 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
423 status = aac_fib_send(ContainerCommand,
425 sizeof (struct aac_get_name),
428 (fib_callback) get_container_name_callback,
432 * Check that the command queued to the controller
434 if (status == -EINPROGRESS) {
435 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
439 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
440 aac_fib_complete(cmd_fibcontext);
441 aac_fib_free(cmd_fibcontext);
445 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
447 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
449 if (fsa_dev_ptr[scmd_id(scsicmd)].valid)
450 return aac_scsi_cmd(scsicmd);
452 scsicmd->result = DID_NO_CONNECT << 16;
453 scsicmd->scsi_done(scsicmd);
457 static int _aac_probe_container2(void * context, struct fib * fibptr)
459 struct fsa_dev_info *fsa_dev_ptr;
460 int (*callback)(struct scsi_cmnd *);
461 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
463 if (!aac_valid_context(scsicmd, fibptr))
466 fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
468 scsicmd->SCp.Status = 0;
470 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
471 fsa_dev_ptr += scmd_id(scsicmd);
473 if ((le32_to_cpu(dresp->status) == ST_OK) &&
474 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
475 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
476 fsa_dev_ptr->valid = 1;
477 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
479 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
480 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
481 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
483 if ((fsa_dev_ptr->valid & 1) == 0)
484 fsa_dev_ptr->valid = 0;
485 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
487 aac_fib_complete(fibptr);
488 aac_fib_free(fibptr);
489 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
490 scsicmd->SCp.ptr = NULL;
491 return (*callback)(scsicmd);
494 static int _aac_probe_container1(void * context, struct fib * fibptr)
496 struct scsi_cmnd * scsicmd;
497 struct aac_mount * dresp;
498 struct aac_query_mount *dinfo;
501 dresp = (struct aac_mount *) fib_data(fibptr);
502 dresp->mnt[0].capacityhigh = 0;
503 if ((le32_to_cpu(dresp->status) != ST_OK) ||
504 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE))
505 return _aac_probe_container2(context, fibptr);
506 scsicmd = (struct scsi_cmnd *) context;
507 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
509 if (!aac_valid_context(scsicmd, fibptr))
512 aac_fib_init(fibptr);
514 dinfo = (struct aac_query_mount *)fib_data(fibptr);
516 dinfo->command = cpu_to_le32(VM_NameServe64);
517 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
518 dinfo->type = cpu_to_le32(FT_FILESYS);
520 status = aac_fib_send(ContainerCommand,
522 sizeof(struct aac_query_mount),
525 (fib_callback) _aac_probe_container2,
528 * Check that the command queued to the controller
530 if (status == -EINPROGRESS) {
531 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
535 /* Inherit results from VM_NameServe, if any */
536 dresp->status = cpu_to_le32(ST_OK);
537 return _aac_probe_container2(context, fibptr);
542 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
545 int status = -ENOMEM;
547 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
548 struct aac_query_mount *dinfo;
550 aac_fib_init(fibptr);
552 dinfo = (struct aac_query_mount *)fib_data(fibptr);
554 dinfo->command = cpu_to_le32(VM_NameServe);
555 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
556 dinfo->type = cpu_to_le32(FT_FILESYS);
557 scsicmd->SCp.ptr = (char *)callback;
559 status = aac_fib_send(ContainerCommand,
561 sizeof(struct aac_query_mount),
564 (fib_callback) _aac_probe_container1,
567 * Check that the command queued to the controller
569 if (status == -EINPROGRESS) {
570 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
574 scsicmd->SCp.ptr = NULL;
575 aac_fib_complete(fibptr);
576 aac_fib_free(fibptr);
580 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
582 fsa_dev_ptr += scmd_id(scsicmd);
583 if ((fsa_dev_ptr->valid & 1) == 0) {
584 fsa_dev_ptr->valid = 0;
585 return (*callback)(scsicmd);
593 * aac_probe_container - query a logical volume
594 * @dev: device to query
595 * @cid: container identifier
597 * Queries the controller about the given volume. The volume information
598 * is updated in the struct fsa_dev_info structure rather than returned.
600 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
602 scsicmd->device = NULL;
606 int aac_probe_container(struct aac_dev *dev, int cid)
608 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
609 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
612 if (!scsicmd || !scsidev) {
617 scsicmd->list.next = NULL;
618 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))_aac_probe_container1;
620 scsicmd->device = scsidev;
621 scsidev->sdev_state = 0;
623 scsidev->host = dev->scsi_host_ptr;
625 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
626 while (scsicmd->device == scsidev)
629 status = scsicmd->SCp.Status;
634 /* Local Structure to set SCSI inquiry data strings */
636 char vid[8]; /* Vendor ID */
637 char pid[16]; /* Product ID */
638 char prl[4]; /* Product Revision Level */
642 * InqStrCopy - string merge
643 * @a: string to copy from
644 * @b: string to copy to
646 * Copy a String from one location to another
650 static void inqstrcpy(char *a, char *b)
657 static char *container_types[] = {
683 /* Function: setinqstr
685 * Arguments: [1] pointer to void [1] int
687 * Purpose: Sets SCSI inquiry data strings for vendor, product
688 * and revision level. Allows strings to be set in platform dependant
689 * files instead of in OS dependant driver source.
692 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
694 struct scsi_inq *str;
696 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
697 memset(str, ' ', sizeof(*str));
699 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
700 char * cp = dev->supplement_adapter_info.AdapterTypeText;
701 int c = sizeof(str->vid);
702 while (*cp && *cp != ' ' && --c)
706 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
709 while (*cp && *cp != ' ')
713 /* last six chars reserved for vol type */
715 if (strlen(cp) > sizeof(str->pid)) {
716 c = cp[sizeof(str->pid)];
717 cp[sizeof(str->pid)] = '\0';
719 inqstrcpy (cp, str->pid);
721 cp[sizeof(str->pid)] = c;
723 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
725 inqstrcpy (mp->vname, str->vid);
726 /* last six chars reserved for vol type */
727 inqstrcpy (mp->model, str->pid);
730 if (tindex < ARRAY_SIZE(container_types)){
731 char *findit = str->pid;
733 for ( ; *findit != ' '; findit++); /* walk till we find a space */
734 /* RAID is superfluous in the context of a RAID device */
735 if (memcmp(findit-4, "RAID", 4) == 0)
736 *(findit -= 4) = ' ';
737 if (((findit - str->pid) + strlen(container_types[tindex]))
738 < (sizeof(str->pid) + sizeof(str->prl)))
739 inqstrcpy (container_types[tindex], findit + 1);
741 inqstrcpy ("V1.0", str->prl);
744 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
745 u8 a_sense_code, u8 incorrect_length,
746 u8 bit_pointer, u16 field_pointer,
749 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
750 sense_buf[1] = 0; /* Segment number, always zero */
752 if (incorrect_length) {
753 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
754 sense_buf[3] = BYTE3(residue);
755 sense_buf[4] = BYTE2(residue);
756 sense_buf[5] = BYTE1(residue);
757 sense_buf[6] = BYTE0(residue);
759 sense_buf[2] = sense_key; /* Sense key */
761 if (sense_key == ILLEGAL_REQUEST)
762 sense_buf[7] = 10; /* Additional sense length */
764 sense_buf[7] = 6; /* Additional sense length */
766 sense_buf[12] = sense_code; /* Additional sense code */
767 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
768 if (sense_key == ILLEGAL_REQUEST) {
771 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
772 sense_buf[15] = 0x80;/* Std sense key specific field */
773 /* Illegal parameter is in the parameter block */
775 if (sense_code == SENCODE_INVALID_CDB_FIELD)
776 sense_buf[15] = 0xc0;/* Std sense key specific field */
777 /* Illegal parameter is in the CDB block */
778 sense_buf[15] |= bit_pointer;
779 sense_buf[16] = field_pointer >> 8; /* MSB */
780 sense_buf[17] = field_pointer; /* LSB */
784 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
786 if (lba & 0xffffffff00000000LL) {
787 int cid = scmd_id(cmd);
788 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
789 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
790 SAM_STAT_CHECK_CONDITION;
791 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
793 SENCODE_INTERNAL_TARGET_FAILURE,
794 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
796 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
797 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
798 ? sizeof(cmd->sense_buffer)
799 : sizeof(dev->fsa_dev[cid].sense_data));
806 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
811 static void io_callback(void *context, struct fib * fibptr);
813 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
816 struct aac_raw_io *readcmd;
818 readcmd = (struct aac_raw_io *) fib_data(fib);
819 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
820 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
821 readcmd->count = cpu_to_le32(count<<9);
822 readcmd->cid = cpu_to_le16(scmd_id(cmd));
823 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
824 readcmd->bpTotal = 0;
825 readcmd->bpComplete = 0;
827 aac_build_sgraw(cmd, &readcmd->sg);
828 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
829 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
831 * Now send the Fib to the adapter
833 return aac_fib_send(ContainerRawIo,
838 (fib_callback) io_callback,
842 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
845 struct aac_read64 *readcmd;
847 readcmd = (struct aac_read64 *) fib_data(fib);
848 readcmd->command = cpu_to_le32(VM_CtHostRead64);
849 readcmd->cid = cpu_to_le16(scmd_id(cmd));
850 readcmd->sector_count = cpu_to_le16(count);
851 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
855 aac_build_sg64(cmd, &readcmd->sg);
856 fibsize = sizeof(struct aac_read64) +
857 ((le32_to_cpu(readcmd->sg.count) - 1) *
858 sizeof (struct sgentry64));
859 BUG_ON (fibsize > (fib->dev->max_fib_size -
860 sizeof(struct aac_fibhdr)));
862 * Now send the Fib to the adapter
864 return aac_fib_send(ContainerCommand64,
869 (fib_callback) io_callback,
873 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
876 struct aac_read *readcmd;
878 readcmd = (struct aac_read *) fib_data(fib);
879 readcmd->command = cpu_to_le32(VM_CtBlockRead);
880 readcmd->cid = cpu_to_le16(scmd_id(cmd));
881 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
882 readcmd->count = cpu_to_le32(count * 512);
884 aac_build_sg(cmd, &readcmd->sg);
885 fibsize = sizeof(struct aac_read) +
886 ((le32_to_cpu(readcmd->sg.count) - 1) *
887 sizeof (struct sgentry));
888 BUG_ON (fibsize > (fib->dev->max_fib_size -
889 sizeof(struct aac_fibhdr)));
891 * Now send the Fib to the adapter
893 return aac_fib_send(ContainerCommand,
898 (fib_callback) io_callback,
902 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
905 struct aac_raw_io *writecmd;
907 writecmd = (struct aac_raw_io *) fib_data(fib);
908 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
909 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
910 writecmd->count = cpu_to_le32(count<<9);
911 writecmd->cid = cpu_to_le16(scmd_id(cmd));
912 writecmd->flags = fua ?
913 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
914 cpu_to_le16(IO_TYPE_WRITE);
915 writecmd->bpTotal = 0;
916 writecmd->bpComplete = 0;
918 aac_build_sgraw(cmd, &writecmd->sg);
919 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
920 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
922 * Now send the Fib to the adapter
924 return aac_fib_send(ContainerRawIo,
929 (fib_callback) io_callback,
933 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
936 struct aac_write64 *writecmd;
938 writecmd = (struct aac_write64 *) fib_data(fib);
939 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
940 writecmd->cid = cpu_to_le16(scmd_id(cmd));
941 writecmd->sector_count = cpu_to_le16(count);
942 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
946 aac_build_sg64(cmd, &writecmd->sg);
947 fibsize = sizeof(struct aac_write64) +
948 ((le32_to_cpu(writecmd->sg.count) - 1) *
949 sizeof (struct sgentry64));
950 BUG_ON (fibsize > (fib->dev->max_fib_size -
951 sizeof(struct aac_fibhdr)));
953 * Now send the Fib to the adapter
955 return aac_fib_send(ContainerCommand64,
960 (fib_callback) io_callback,
964 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
967 struct aac_write *writecmd;
969 writecmd = (struct aac_write *) fib_data(fib);
970 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
971 writecmd->cid = cpu_to_le16(scmd_id(cmd));
972 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
973 writecmd->count = cpu_to_le32(count * 512);
974 writecmd->sg.count = cpu_to_le32(1);
975 /* ->stable is not used - it did mean which type of write */
977 aac_build_sg(cmd, &writecmd->sg);
978 fibsize = sizeof(struct aac_write) +
979 ((le32_to_cpu(writecmd->sg.count) - 1) *
980 sizeof (struct sgentry));
981 BUG_ON (fibsize > (fib->dev->max_fib_size -
982 sizeof(struct aac_fibhdr)));
984 * Now send the Fib to the adapter
986 return aac_fib_send(ContainerCommand,
991 (fib_callback) io_callback,
995 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
997 struct aac_srb * srbcmd;
1002 switch(cmd->sc_data_direction){
1006 case DMA_BIDIRECTIONAL:
1007 flag = SRB_DataIn | SRB_DataOut;
1009 case DMA_FROM_DEVICE:
1013 default: /* shuts up some versions of gcc */
1014 flag = SRB_NoDataXfer;
1018 srbcmd = (struct aac_srb*) fib_data(fib);
1019 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1020 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1021 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1022 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1023 srbcmd->flags = cpu_to_le32(flag);
1024 timeout = cmd->timeout_per_command/HZ;
1027 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1028 srbcmd->retry_limit = 0; /* Obsolete parameter */
1029 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1033 static void aac_srb_callback(void *context, struct fib * fibptr);
1035 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1038 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1040 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1041 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1043 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1044 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1046 * Build Scatter/Gather list
1048 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1049 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1050 sizeof (struct sgentry64));
1051 BUG_ON (fibsize > (fib->dev->max_fib_size -
1052 sizeof(struct aac_fibhdr)));
1055 * Now send the Fib to the adapter
1057 return aac_fib_send(ScsiPortCommand64, fib,
1058 fibsize, FsaNormal, 0, 1,
1059 (fib_callback) aac_srb_callback,
1063 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1066 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1068 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1069 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1071 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1072 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1074 * Build Scatter/Gather list
1076 fibsize = sizeof (struct aac_srb) +
1077 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1078 sizeof (struct sgentry));
1079 BUG_ON (fibsize > (fib->dev->max_fib_size -
1080 sizeof(struct aac_fibhdr)));
1083 * Now send the Fib to the adapter
1085 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1086 (fib_callback) aac_srb_callback, (void *) cmd);
1089 int aac_get_adapter_info(struct aac_dev* dev)
1094 struct aac_adapter_info *info;
1095 struct aac_bus_info *command;
1096 struct aac_bus_info_response *bus_info;
1098 if (!(fibptr = aac_fib_alloc(dev)))
1101 aac_fib_init(fibptr);
1102 info = (struct aac_adapter_info *) fib_data(fibptr);
1103 memset(info,0,sizeof(*info));
1105 rcode = aac_fib_send(RequestAdapterInfo,
1109 -1, 1, /* First `interrupt' command uses special wait */
1114 aac_fib_complete(fibptr);
1115 aac_fib_free(fibptr);
1118 memcpy(&dev->adapter_info, info, sizeof(*info));
1120 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1121 struct aac_supplement_adapter_info * info;
1123 aac_fib_init(fibptr);
1125 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1127 memset(info,0,sizeof(*info));
1129 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1138 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
1146 aac_fib_init(fibptr);
1148 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1150 memset(bus_info, 0, sizeof(*bus_info));
1152 command = (struct aac_bus_info *)bus_info;
1154 command->Command = cpu_to_le32(VM_Ioctl);
1155 command->ObjType = cpu_to_le32(FT_DRIVE);
1156 command->MethodId = cpu_to_le32(1);
1157 command->CtlCmd = cpu_to_le32(GetBusInfo);
1159 rcode = aac_fib_send(ContainerCommand,
1166 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1167 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1168 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1171 if (!dev->in_reset) {
1172 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1173 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1179 le32_to_cpu(dev->adapter_info.kernelbuild),
1180 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1181 dev->supplement_adapter_info.BuildDate);
1182 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1183 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1185 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1186 le32_to_cpu(dev->adapter_info.monitorbuild));
1187 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1188 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1190 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1191 le32_to_cpu(dev->adapter_info.biosbuild));
1192 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
1193 printk(KERN_INFO "%s%d: serial %x\n",
1195 le32_to_cpu(dev->adapter_info.serial[0]));
1196 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1197 printk(KERN_INFO "%s%d: TSID %.*s\n",
1199 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1200 dev->supplement_adapter_info.VpdInfo.Tsid);
1204 dev->nondasd_support = 0;
1205 dev->raid_scsi_mode = 0;
1206 if(dev->adapter_info.options & AAC_OPT_NONDASD){
1207 dev->nondasd_support = 1;
1211 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1212 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1213 * force nondasd support on. If we decide to allow the non-dasd flag
1214 * additional changes changes will have to be made to support
1215 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1216 * changed to support the new dev->raid_scsi_mode flag instead of
1217 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1218 * function aac_detect will have to be modified where it sets up the
1219 * max number of channels based on the aac->nondasd_support flag only.
1221 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1222 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1223 dev->nondasd_support = 1;
1224 dev->raid_scsi_mode = 1;
1226 if (dev->raid_scsi_mode != 0)
1227 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1228 dev->name, dev->id);
1231 dev->nondasd_support = (nondasd!=0);
1233 if(dev->nondasd_support != 0){
1234 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1237 dev->dac_support = 0;
1238 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1239 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1240 dev->dac_support = 1;
1244 dev->dac_support = (dacmode!=0);
1246 if(dev->dac_support != 0) {
1247 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1248 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1249 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1250 dev->name, dev->id);
1251 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1252 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1253 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1254 dev->name, dev->id);
1255 dev->dac_support = 0;
1257 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1258 dev->name, dev->id);
1263 * Deal with configuring for the individualized limits of each packet
1266 dev->a_ops.adapter_scsi = (dev->dac_support)
1269 if (dev->raw_io_interface) {
1270 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1273 dev->a_ops.adapter_read = aac_read_raw_io;
1274 dev->a_ops.adapter_write = aac_write_raw_io;
1276 dev->a_ops.adapter_bounds = aac_bounds_32;
1277 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1278 sizeof(struct aac_fibhdr) -
1279 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1280 sizeof(struct sgentry);
1281 if (dev->dac_support) {
1282 dev->a_ops.adapter_read = aac_read_block64;
1283 dev->a_ops.adapter_write = aac_write_block64;
1285 * 38 scatter gather elements
1287 dev->scsi_host_ptr->sg_tablesize =
1288 (dev->max_fib_size -
1289 sizeof(struct aac_fibhdr) -
1290 sizeof(struct aac_write64) +
1291 sizeof(struct sgentry64)) /
1292 sizeof(struct sgentry64);
1294 dev->a_ops.adapter_read = aac_read_block;
1295 dev->a_ops.adapter_write = aac_write_block;
1297 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1298 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1300 * Worst case size that could cause sg overflow when
1301 * we break up SG elements that are larger than 64KB.
1302 * Would be nice if we could tell the SCSI layer what
1303 * the maximum SG element size can be. Worst case is
1304 * (sg_tablesize-1) 4KB elements with one 64KB
1306 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1308 dev->scsi_host_ptr->max_sectors =
1309 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1313 aac_fib_complete(fibptr);
1314 aac_fib_free(fibptr);
1320 static void io_callback(void *context, struct fib * fibptr)
1322 struct aac_dev *dev;
1323 struct aac_read_reply *readreply;
1324 struct scsi_cmnd *scsicmd;
1327 scsicmd = (struct scsi_cmnd *) context;
1329 if (!aac_valid_context(scsicmd, fibptr))
1332 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1333 cid = scmd_id(scsicmd);
1335 if (nblank(dprintk(x))) {
1337 switch (scsicmd->cmnd[0]) {
1340 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1341 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1345 lba = ((u64)scsicmd->cmnd[2] << 56) |
1346 ((u64)scsicmd->cmnd[3] << 48) |
1347 ((u64)scsicmd->cmnd[4] << 40) |
1348 ((u64)scsicmd->cmnd[5] << 32) |
1349 ((u64)scsicmd->cmnd[6] << 24) |
1350 (scsicmd->cmnd[7] << 16) |
1351 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1355 lba = ((u64)scsicmd->cmnd[2] << 24) |
1356 (scsicmd->cmnd[3] << 16) |
1357 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1360 lba = ((u64)scsicmd->cmnd[2] << 24) |
1361 (scsicmd->cmnd[3] << 16) |
1362 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1366 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1367 smp_processor_id(), (unsigned long long)lba, jiffies);
1370 BUG_ON(fibptr == NULL);
1372 scsi_dma_unmap(scsicmd);
1374 readreply = (struct aac_read_reply *)fib_data(fibptr);
1375 if (le32_to_cpu(readreply->status) == ST_OK)
1376 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1378 #ifdef AAC_DETAILED_STATUS_INFO
1379 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1380 le32_to_cpu(readreply->status));
1382 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1383 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1385 SENCODE_INTERNAL_TARGET_FAILURE,
1386 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1388 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1389 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1390 ? sizeof(scsicmd->sense_buffer)
1391 : sizeof(dev->fsa_dev[cid].sense_data));
1393 aac_fib_complete(fibptr);
1394 aac_fib_free(fibptr);
1396 scsicmd->scsi_done(scsicmd);
1399 static int aac_read(struct scsi_cmnd * scsicmd)
1404 struct aac_dev *dev;
1405 struct fib * cmd_fibcontext;
1407 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1409 * Get block address and transfer length
1411 switch (scsicmd->cmnd[0]) {
1413 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1415 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1416 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1417 count = scsicmd->cmnd[4];
1423 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1425 lba = ((u64)scsicmd->cmnd[2] << 56) |
1426 ((u64)scsicmd->cmnd[3] << 48) |
1427 ((u64)scsicmd->cmnd[4] << 40) |
1428 ((u64)scsicmd->cmnd[5] << 32) |
1429 ((u64)scsicmd->cmnd[6] << 24) |
1430 (scsicmd->cmnd[7] << 16) |
1431 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1432 count = (scsicmd->cmnd[10] << 24) |
1433 (scsicmd->cmnd[11] << 16) |
1434 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1437 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1439 lba = ((u64)scsicmd->cmnd[2] << 24) |
1440 (scsicmd->cmnd[3] << 16) |
1441 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1442 count = (scsicmd->cmnd[6] << 24) |
1443 (scsicmd->cmnd[7] << 16) |
1444 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1447 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1449 lba = ((u64)scsicmd->cmnd[2] << 24) |
1450 (scsicmd->cmnd[3] << 16) |
1451 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1452 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1455 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1456 smp_processor_id(), (unsigned long long)lba, jiffies));
1457 if (aac_adapter_bounds(dev,scsicmd,lba))
1460 * Alocate and initialize a Fib
1462 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1466 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1469 * Check that the command queued to the controller
1471 if (status == -EINPROGRESS) {
1472 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1476 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1478 * For some reason, the Fib didn't queue, return QUEUE_FULL
1480 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1481 scsicmd->scsi_done(scsicmd);
1482 aac_fib_complete(cmd_fibcontext);
1483 aac_fib_free(cmd_fibcontext);
1487 static int aac_write(struct scsi_cmnd * scsicmd)
1493 struct aac_dev *dev;
1494 struct fib * cmd_fibcontext;
1496 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1498 * Get block address and transfer length
1500 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1502 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1503 count = scsicmd->cmnd[4];
1507 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1508 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1510 lba = ((u64)scsicmd->cmnd[2] << 56) |
1511 ((u64)scsicmd->cmnd[3] << 48) |
1512 ((u64)scsicmd->cmnd[4] << 40) |
1513 ((u64)scsicmd->cmnd[5] << 32) |
1514 ((u64)scsicmd->cmnd[6] << 24) |
1515 (scsicmd->cmnd[7] << 16) |
1516 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1517 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1518 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1519 fua = scsicmd->cmnd[1] & 0x8;
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];
1527 fua = scsicmd->cmnd[1] & 0x8;
1529 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1530 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1531 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1532 fua = scsicmd->cmnd[1] & 0x8;
1534 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1535 smp_processor_id(), (unsigned long long)lba, jiffies));
1536 if (aac_adapter_bounds(dev,scsicmd,lba))
1539 * Allocate and initialize a Fib then setup a BlockWrite command
1541 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1542 scsicmd->result = DID_ERROR << 16;
1543 scsicmd->scsi_done(scsicmd);
1547 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1550 * Check that the command queued to the controller
1552 if (status == -EINPROGRESS) {
1553 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1557 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1559 * For some reason, the Fib didn't queue, return QUEUE_FULL
1561 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1562 scsicmd->scsi_done(scsicmd);
1564 aac_fib_complete(cmd_fibcontext);
1565 aac_fib_free(cmd_fibcontext);
1569 static void synchronize_callback(void *context, struct fib *fibptr)
1571 struct aac_synchronize_reply *synchronizereply;
1572 struct scsi_cmnd *cmd;
1576 if (!aac_valid_context(cmd, fibptr))
1579 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1580 smp_processor_id(), jiffies));
1581 BUG_ON(fibptr == NULL);
1584 synchronizereply = fib_data(fibptr);
1585 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1586 cmd->result = DID_OK << 16 |
1587 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1589 struct scsi_device *sdev = cmd->device;
1590 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1591 u32 cid = sdev_id(sdev);
1593 "synchronize_callback: synchronize failed, status = %d\n",
1594 le32_to_cpu(synchronizereply->status));
1595 cmd->result = DID_OK << 16 |
1596 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1597 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1599 SENCODE_INTERNAL_TARGET_FAILURE,
1600 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1602 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1603 min(sizeof(dev->fsa_dev[cid].sense_data),
1604 sizeof(cmd->sense_buffer)));
1607 aac_fib_complete(fibptr);
1608 aac_fib_free(fibptr);
1609 cmd->scsi_done(cmd);
1612 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1615 struct fib *cmd_fibcontext;
1616 struct aac_synchronize *synchronizecmd;
1617 struct scsi_cmnd *cmd;
1618 struct scsi_device *sdev = scsicmd->device;
1620 struct aac_dev *aac;
1621 unsigned long flags;
1624 * Wait for all outstanding queued commands to complete to this
1625 * specific target (block).
1627 spin_lock_irqsave(&sdev->list_lock, flags);
1628 list_for_each_entry(cmd, &sdev->cmd_list, list)
1629 if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1634 spin_unlock_irqrestore(&sdev->list_lock, flags);
1637 * Yield the processor (requeue for later)
1640 return SCSI_MLQUEUE_DEVICE_BUSY;
1642 aac = (struct aac_dev *)scsicmd->device->host->hostdata;
1644 return SCSI_MLQUEUE_HOST_BUSY;
1647 * Allocate and initialize a Fib
1649 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1650 return SCSI_MLQUEUE_HOST_BUSY;
1652 aac_fib_init(cmd_fibcontext);
1654 synchronizecmd = fib_data(cmd_fibcontext);
1655 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1656 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1657 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
1658 synchronizecmd->count =
1659 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1662 * Now send the Fib to the adapter
1664 status = aac_fib_send(ContainerCommand,
1666 sizeof(struct aac_synchronize),
1669 (fib_callback)synchronize_callback,
1673 * Check that the command queued to the controller
1675 if (status == -EINPROGRESS) {
1676 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1681 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1682 aac_fib_complete(cmd_fibcontext);
1683 aac_fib_free(cmd_fibcontext);
1684 return SCSI_MLQUEUE_HOST_BUSY;
1688 * aac_scsi_cmd() - Process SCSI command
1689 * @scsicmd: SCSI command block
1691 * Emulate a SCSI command and queue the required request for the
1695 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1698 struct Scsi_Host *host = scsicmd->device->host;
1699 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1700 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1702 if (fsa_dev_ptr == NULL)
1705 * If the bus, id or lun is out of range, return fail
1706 * Test does not apply to ID 16, the pseudo id for the controller
1709 if (scmd_id(scsicmd) != host->this_id) {
1710 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
1711 if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
1712 (scsicmd->device->lun != 0)) {
1713 scsicmd->result = DID_NO_CONNECT << 16;
1714 scsicmd->scsi_done(scsicmd);
1717 cid = scmd_id(scsicmd);
1720 * If the target container doesn't exist, it may have
1721 * been newly created
1723 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1724 switch (scsicmd->cmnd[0]) {
1725 case SERVICE_ACTION_IN:
1726 if (!(dev->raw_io_interface) ||
1727 !(dev->raw_io_64) ||
1728 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1732 case TEST_UNIT_READY:
1735 return _aac_probe_container(scsicmd,
1736 aac_probe_container_callback2);
1741 } else { /* check for physical non-dasd devices */
1742 if ((dev->nondasd_support == 1) || expose_physicals) {
1745 return aac_send_srb_fib(scsicmd);
1747 scsicmd->result = DID_NO_CONNECT << 16;
1748 scsicmd->scsi_done(scsicmd);
1754 * else Command for the controller itself
1756 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1757 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1759 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1760 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1761 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1763 SENCODE_INVALID_COMMAND,
1764 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1765 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1766 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1767 ? sizeof(scsicmd->sense_buffer)
1768 : sizeof(dev->fsa_dev[cid].sense_data));
1769 scsicmd->scsi_done(scsicmd);
1774 /* Handle commands here that don't really require going out to the adapter */
1775 switch (scsicmd->cmnd[0]) {
1778 struct inquiry_data inq_data;
1780 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
1781 memset(&inq_data, 0, sizeof (struct inquiry_data));
1783 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1784 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 */
1785 inq_data.inqd_len = 31;
1786 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1787 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1789 * Set the Vendor, Product, and Revision Level
1790 * see: <vendor>.c i.e. aac.c
1792 if (scmd_id(scsicmd) == host->this_id) {
1793 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
1794 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1795 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1796 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1797 scsicmd->scsi_done(scsicmd);
1802 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1803 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1804 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1805 return aac_get_container_name(scsicmd);
1807 case SERVICE_ACTION_IN:
1808 if (!(dev->raw_io_interface) ||
1809 !(dev->raw_io_64) ||
1810 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1816 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1817 capacity = fsa_dev_ptr[cid].size - 1;
1818 cp[0] = (capacity >> 56) & 0xff;
1819 cp[1] = (capacity >> 48) & 0xff;
1820 cp[2] = (capacity >> 40) & 0xff;
1821 cp[3] = (capacity >> 32) & 0xff;
1822 cp[4] = (capacity >> 24) & 0xff;
1823 cp[5] = (capacity >> 16) & 0xff;
1824 cp[6] = (capacity >> 8) & 0xff;
1825 cp[7] = (capacity >> 0) & 0xff;
1831 aac_internal_transfer(scsicmd, cp, 0,
1832 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
1833 if (sizeof(cp) < scsicmd->cmnd[13]) {
1834 unsigned int len, offset = sizeof(cp);
1836 memset(cp, 0, offset);
1838 len = min_t(size_t, scsicmd->cmnd[13] - offset,
1840 aac_internal_transfer(scsicmd, cp, offset, len);
1841 } while ((offset += len) < scsicmd->cmnd[13]);
1844 /* Do not cache partition table for arrays */
1845 scsicmd->device->removable = 1;
1847 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1848 scsicmd->scsi_done(scsicmd);
1858 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1859 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
1860 capacity = fsa_dev_ptr[cid].size - 1;
1864 cp[0] = (capacity >> 24) & 0xff;
1865 cp[1] = (capacity >> 16) & 0xff;
1866 cp[2] = (capacity >> 8) & 0xff;
1867 cp[3] = (capacity >> 0) & 0xff;
1872 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1873 /* Do not cache partition table for arrays */
1874 scsicmd->device->removable = 1;
1876 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1877 scsicmd->scsi_done(scsicmd);
1885 int mode_buf_length = 4;
1887 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1888 mode_buf[0] = 3; /* Mode data length */
1889 mode_buf[1] = 0; /* Medium type - default */
1890 mode_buf[2] = 0; /* Device-specific param,
1891 bit 8: 0/1 = write enabled/protected
1892 bit 4: 0/1 = FUA enabled */
1893 if (dev->raw_io_interface)
1895 mode_buf[3] = 0; /* Block descriptor length */
1896 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
1897 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
1901 mode_buf[6] = 0x04; /* WCE */
1902 mode_buf_length = 7;
1903 if (mode_buf_length > scsicmd->cmnd[4])
1904 mode_buf_length = scsicmd->cmnd[4];
1906 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
1907 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1908 scsicmd->scsi_done(scsicmd);
1915 int mode_buf_length = 8;
1917 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1918 mode_buf[0] = 0; /* Mode data length (MSB) */
1919 mode_buf[1] = 6; /* Mode data length (LSB) */
1920 mode_buf[2] = 0; /* Medium type - default */
1921 mode_buf[3] = 0; /* Device-specific param,
1922 bit 8: 0/1 = write enabled/protected
1923 bit 4: 0/1 = FUA enabled */
1924 if (dev->raw_io_interface)
1926 mode_buf[4] = 0; /* reserved */
1927 mode_buf[5] = 0; /* reserved */
1928 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1929 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1930 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
1931 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
1935 mode_buf[10] = 0x04; /* WCE */
1936 mode_buf_length = 11;
1937 if (mode_buf_length > scsicmd->cmnd[8])
1938 mode_buf_length = scsicmd->cmnd[8];
1940 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
1942 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1943 scsicmd->scsi_done(scsicmd);
1948 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1949 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1950 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1951 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1952 scsicmd->scsi_done(scsicmd);
1955 case ALLOW_MEDIUM_REMOVAL:
1956 dprintk((KERN_DEBUG "LOCK command.\n"));
1957 if (scsicmd->cmnd[4])
1958 fsa_dev_ptr[cid].locked = 1;
1960 fsa_dev_ptr[cid].locked = 0;
1962 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1963 scsicmd->scsi_done(scsicmd);
1966 * These commands are all No-Ops
1968 case TEST_UNIT_READY:
1972 case REASSIGN_BLOCKS:
1975 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1976 scsicmd->scsi_done(scsicmd);
1980 switch (scsicmd->cmnd[0])
1989 * Hack to keep track of ordinal number of the device that
1990 * corresponds to a container. Needed to convert
1991 * containers to /dev/sd device names
1994 if (scsicmd->request->rq_disk)
1995 strlcpy(fsa_dev_ptr[cid].devname,
1996 scsicmd->request->rq_disk->disk_name,
1997 min(sizeof(fsa_dev_ptr[cid].devname),
1998 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2000 return aac_read(scsicmd);
2008 return aac_write(scsicmd);
2010 case SYNCHRONIZE_CACHE:
2011 /* Issue FIB to tell Firmware to flush it's cache */
2012 return aac_synchronize(scsicmd);
2016 * Unhandled commands
2018 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2019 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2020 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
2021 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2022 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
2023 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2024 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
2025 ? sizeof(scsicmd->sense_buffer)
2026 : sizeof(dev->fsa_dev[cid].sense_data));
2027 scsicmd->scsi_done(scsicmd);
2032 static int query_disk(struct aac_dev *dev, void __user *arg)
2034 struct aac_query_disk qd;
2035 struct fsa_dev_info *fsa_dev_ptr;
2037 fsa_dev_ptr = dev->fsa_dev;
2040 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2044 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2046 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2048 qd.instance = dev->scsi_host_ptr->host_no;
2050 qd.id = CONTAINER_TO_ID(qd.cnum);
2051 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2053 else return -EINVAL;
2055 qd.valid = fsa_dev_ptr[qd.cnum].valid;
2056 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2057 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2059 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2064 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2065 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2067 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2072 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2074 struct aac_delete_disk dd;
2075 struct fsa_dev_info *fsa_dev_ptr;
2077 fsa_dev_ptr = dev->fsa_dev;
2081 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2084 if (dd.cnum >= dev->maximum_num_containers)
2087 * Mark this container as being deleted.
2089 fsa_dev_ptr[dd.cnum].deleted = 1;
2091 * Mark the container as no longer valid
2093 fsa_dev_ptr[dd.cnum].valid = 0;
2097 static int delete_disk(struct aac_dev *dev, void __user *arg)
2099 struct aac_delete_disk dd;
2100 struct fsa_dev_info *fsa_dev_ptr;
2102 fsa_dev_ptr = dev->fsa_dev;
2106 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2109 if (dd.cnum >= dev->maximum_num_containers)
2112 * If the container is locked, it can not be deleted by the API.
2114 if (fsa_dev_ptr[dd.cnum].locked)
2118 * Mark the container as no longer being valid.
2120 fsa_dev_ptr[dd.cnum].valid = 0;
2121 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2126 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2129 case FSACTL_QUERY_DISK:
2130 return query_disk(dev, arg);
2131 case FSACTL_DELETE_DISK:
2132 return delete_disk(dev, arg);
2133 case FSACTL_FORCE_DELETE_DISK:
2134 return force_delete_disk(dev, arg);
2135 case FSACTL_GET_CONTAINERS:
2136 return aac_get_containers(dev);
2145 * @context: the context set in the fib - here it is scsi cmd
2146 * @fibptr: pointer to the fib
2148 * Handles the completion of a scsi command to a non dasd device
2152 static void aac_srb_callback(void *context, struct fib * fibptr)
2154 struct aac_dev *dev;
2155 struct aac_srb_reply *srbreply;
2156 struct scsi_cmnd *scsicmd;
2158 scsicmd = (struct scsi_cmnd *) context;
2160 if (!aac_valid_context(scsicmd, fibptr))
2163 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2165 BUG_ON(fibptr == NULL);
2167 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2169 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2171 * Calculate resid for sg
2174 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2175 - le32_to_cpu(srbreply->data_xfer_length));
2177 scsi_dma_unmap(scsicmd);
2180 * First check the fib status
2183 if (le32_to_cpu(srbreply->status) != ST_OK){
2185 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2186 len = (le32_to_cpu(srbreply->sense_data_size) >
2187 sizeof(scsicmd->sense_buffer)) ?
2188 sizeof(scsicmd->sense_buffer) :
2189 le32_to_cpu(srbreply->sense_data_size);
2190 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2191 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2195 * Next check the srb status
2197 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2198 case SRB_STATUS_ERROR_RECOVERY:
2199 case SRB_STATUS_PENDING:
2200 case SRB_STATUS_SUCCESS:
2201 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2203 case SRB_STATUS_DATA_OVERRUN:
2204 switch(scsicmd->cmnd[0]){
2213 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
2214 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2216 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2218 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2221 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2225 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2229 case SRB_STATUS_ABORTED:
2230 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2232 case SRB_STATUS_ABORT_FAILED:
2233 // Not sure about this one - but assuming the hba was trying to abort for some reason
2234 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2236 case SRB_STATUS_PARITY_ERROR:
2237 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2239 case SRB_STATUS_NO_DEVICE:
2240 case SRB_STATUS_INVALID_PATH_ID:
2241 case SRB_STATUS_INVALID_TARGET_ID:
2242 case SRB_STATUS_INVALID_LUN:
2243 case SRB_STATUS_SELECTION_TIMEOUT:
2244 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2247 case SRB_STATUS_COMMAND_TIMEOUT:
2248 case SRB_STATUS_TIMEOUT:
2249 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2252 case SRB_STATUS_BUSY:
2253 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2256 case SRB_STATUS_BUS_RESET:
2257 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2260 case SRB_STATUS_MESSAGE_REJECTED:
2261 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2263 case SRB_STATUS_REQUEST_FLUSHED:
2264 case SRB_STATUS_ERROR:
2265 case SRB_STATUS_INVALID_REQUEST:
2266 case SRB_STATUS_REQUEST_SENSE_FAILED:
2267 case SRB_STATUS_NO_HBA:
2268 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2269 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2270 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2271 case SRB_STATUS_DELAYED_RETRY:
2272 case SRB_STATUS_BAD_FUNCTION:
2273 case SRB_STATUS_NOT_STARTED:
2274 case SRB_STATUS_NOT_IN_USE:
2275 case SRB_STATUS_FORCE_ABORT:
2276 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2278 #ifdef AAC_DETAILED_STATUS_INFO
2279 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2280 le32_to_cpu(srbreply->srb_status) & 0x3F,
2281 aac_get_status_string(
2282 le32_to_cpu(srbreply->srb_status) & 0x3F),
2284 le32_to_cpu(srbreply->scsi_status));
2286 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2289 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2291 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2292 len = (le32_to_cpu(srbreply->sense_data_size) >
2293 sizeof(scsicmd->sense_buffer)) ?
2294 sizeof(scsicmd->sense_buffer) :
2295 le32_to_cpu(srbreply->sense_data_size);
2296 #ifdef AAC_DETAILED_STATUS_INFO
2297 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2298 le32_to_cpu(srbreply->status), len);
2300 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2304 * OR in the scsi status (already shifted up a bit)
2306 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2308 aac_fib_complete(fibptr);
2309 aac_fib_free(fibptr);
2310 scsicmd->scsi_done(scsicmd);
2316 * @scsicmd: the scsi command block
2318 * This routine will form a FIB and fill in the aac_srb from the
2319 * scsicmd passed in.
2322 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2324 struct fib* cmd_fibcontext;
2325 struct aac_dev* dev;
2328 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2329 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2330 scsicmd->device->lun > 7) {
2331 scsicmd->result = DID_NO_CONNECT << 16;
2332 scsicmd->scsi_done(scsicmd);
2337 * Allocate and initialize a Fib then setup a BlockWrite command
2339 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2342 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2345 * Check that the command queued to the controller
2347 if (status == -EINPROGRESS) {
2348 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2352 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2353 aac_fib_complete(cmd_fibcontext);
2354 aac_fib_free(cmd_fibcontext);
2359 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2361 struct aac_dev *dev;
2362 unsigned long byte_count = 0;
2365 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2366 // Get rid of old data
2368 psg->sg[0].addr = 0;
2369 psg->sg[0].count = 0;
2371 nseg = scsi_dma_map(scsicmd);
2374 struct scatterlist *sg;
2377 psg->count = cpu_to_le32(nseg);
2379 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2380 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2381 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2382 byte_count += sg_dma_len(sg);
2384 /* hba wants the size to be exact */
2385 if (byte_count > scsi_bufflen(scsicmd)) {
2386 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2387 (byte_count - scsi_bufflen(scsicmd));
2388 psg->sg[i-1].count = cpu_to_le32(temp);
2389 byte_count = scsi_bufflen(scsicmd);
2391 /* Check for command underflow */
2392 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2393 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2394 byte_count, scsicmd->underflow);
2401 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2403 struct aac_dev *dev;
2404 unsigned long byte_count = 0;
2408 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2409 // Get rid of old data
2411 psg->sg[0].addr[0] = 0;
2412 psg->sg[0].addr[1] = 0;
2413 psg->sg[0].count = 0;
2415 nseg = scsi_dma_map(scsicmd);
2418 struct scatterlist *sg;
2421 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2422 int count = sg_dma_len(sg);
2423 addr = sg_dma_address(sg);
2424 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2425 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2426 psg->sg[i].count = cpu_to_le32(count);
2427 byte_count += count;
2429 psg->count = cpu_to_le32(nseg);
2430 /* hba wants the size to be exact */
2431 if (byte_count > scsi_bufflen(scsicmd)) {
2432 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2433 (byte_count - scsi_bufflen(scsicmd));
2434 psg->sg[i-1].count = cpu_to_le32(temp);
2435 byte_count = scsi_bufflen(scsicmd);
2437 /* Check for command underflow */
2438 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2439 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2440 byte_count, scsicmd->underflow);
2446 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2448 unsigned long byte_count = 0;
2451 // Get rid of old data
2453 psg->sg[0].next = 0;
2454 psg->sg[0].prev = 0;
2455 psg->sg[0].addr[0] = 0;
2456 psg->sg[0].addr[1] = 0;
2457 psg->sg[0].count = 0;
2458 psg->sg[0].flags = 0;
2460 nseg = scsi_dma_map(scsicmd);
2463 struct scatterlist *sg;
2466 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2467 int count = sg_dma_len(sg);
2468 u64 addr = sg_dma_address(sg);
2469 psg->sg[i].next = 0;
2470 psg->sg[i].prev = 0;
2471 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2472 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2473 psg->sg[i].count = cpu_to_le32(count);
2474 psg->sg[i].flags = 0;
2475 byte_count += count;
2477 psg->count = cpu_to_le32(nseg);
2478 /* hba wants the size to be exact */
2479 if (byte_count > scsi_bufflen(scsicmd)) {
2480 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2481 (byte_count - scsi_bufflen(scsicmd));
2482 psg->sg[i-1].count = cpu_to_le32(temp);
2483 byte_count = scsi_bufflen(scsicmd);
2485 /* Check for command underflow */
2486 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2487 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2488 byte_count, scsicmd->underflow);
2494 #ifdef AAC_DETAILED_STATUS_INFO
2496 struct aac_srb_status_info {
2502 static struct aac_srb_status_info srb_status_info[] = {
2503 { SRB_STATUS_PENDING, "Pending Status"},
2504 { SRB_STATUS_SUCCESS, "Success"},
2505 { SRB_STATUS_ABORTED, "Aborted Command"},
2506 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2507 { SRB_STATUS_ERROR, "Error Event"},
2508 { SRB_STATUS_BUSY, "Device Busy"},
2509 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2510 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2511 { SRB_STATUS_NO_DEVICE, "No Device"},
2512 { SRB_STATUS_TIMEOUT, "Timeout"},
2513 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2514 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2515 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2516 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2517 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2518 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2519 { SRB_STATUS_NO_HBA, "No HBA"},
2520 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2521 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2522 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2523 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2524 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2525 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2526 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2527 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2528 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2529 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2530 { SRB_STATUS_NOT_STARTED, "Not Started"},
2531 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2532 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2533 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2534 { 0xff, "Unknown Error"}
2537 char *aac_get_status_string(u32 status)
2541 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2542 if (srb_status_info[i].status == status)
2543 return srb_status_info[i].str;
2545 return "Bad Status Code";