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 = scsicmd->request_buffer;
349 if (scsicmd->use_sg) {
350 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
351 transfer_len = min(sg->length, len + offset);
353 buf = scsicmd->request_buffer;
354 transfer_len = min(scsicmd->request_bufflen, len + offset);
356 transfer_len -= offset;
357 if (buf && transfer_len > 0)
358 memcpy(buf + offset, data, transfer_len);
361 kunmap_atomic(buf - sg->offset, KM_IRQ0);
365 static void get_container_name_callback(void *context, struct fib * fibptr)
367 struct aac_get_name_resp * get_name_reply;
368 struct scsi_cmnd * scsicmd;
370 scsicmd = (struct scsi_cmnd *) context;
372 if (!aac_valid_context(scsicmd, fibptr))
375 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
376 BUG_ON(fibptr == NULL);
378 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
379 /* Failure is irrelevant, using default value instead */
380 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
381 && (get_name_reply->data[0] != '\0')) {
382 char *sp = get_name_reply->data;
383 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
387 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
388 int count = sizeof(d);
391 *dp++ = (*sp) ? *sp++ : ' ';
392 } while (--count > 0);
393 aac_internal_transfer(scsicmd, d,
394 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
398 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
400 aac_fib_complete(fibptr);
401 aac_fib_free(fibptr);
402 scsicmd->scsi_done(scsicmd);
406 * aac_get_container_name - get container name, none blocking.
408 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
411 struct aac_get_name *dinfo;
412 struct fib * cmd_fibcontext;
413 struct aac_dev * dev;
415 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
417 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
420 aac_fib_init(cmd_fibcontext);
421 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
423 dinfo->command = cpu_to_le32(VM_ContainerConfig);
424 dinfo->type = cpu_to_le32(CT_READ_NAME);
425 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
426 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
428 status = aac_fib_send(ContainerCommand,
430 sizeof (struct aac_get_name),
433 (fib_callback) get_container_name_callback,
437 * Check that the command queued to the controller
439 if (status == -EINPROGRESS) {
440 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
444 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
445 aac_fib_complete(cmd_fibcontext);
446 aac_fib_free(cmd_fibcontext);
450 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
452 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
454 if (fsa_dev_ptr[scmd_id(scsicmd)].valid)
455 return aac_scsi_cmd(scsicmd);
457 scsicmd->result = DID_NO_CONNECT << 16;
458 scsicmd->scsi_done(scsicmd);
462 static int _aac_probe_container2(void * context, struct fib * fibptr)
464 struct fsa_dev_info *fsa_dev_ptr;
465 int (*callback)(struct scsi_cmnd *);
466 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
468 if (!aac_valid_context(scsicmd, fibptr))
471 fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
473 scsicmd->SCp.Status = 0;
475 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
476 fsa_dev_ptr += scmd_id(scsicmd);
478 if ((le32_to_cpu(dresp->status) == ST_OK) &&
479 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
480 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
481 fsa_dev_ptr->valid = 1;
482 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
484 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
485 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
486 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
488 if ((fsa_dev_ptr->valid & 1) == 0)
489 fsa_dev_ptr->valid = 0;
490 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
492 aac_fib_complete(fibptr);
493 aac_fib_free(fibptr);
494 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
495 scsicmd->SCp.ptr = NULL;
496 return (*callback)(scsicmd);
499 static int _aac_probe_container1(void * context, struct fib * fibptr)
501 struct scsi_cmnd * scsicmd;
502 struct aac_mount * dresp;
503 struct aac_query_mount *dinfo;
506 dresp = (struct aac_mount *) fib_data(fibptr);
507 dresp->mnt[0].capacityhigh = 0;
508 if ((le32_to_cpu(dresp->status) != ST_OK) ||
509 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE))
510 return _aac_probe_container2(context, fibptr);
511 scsicmd = (struct scsi_cmnd *) context;
512 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
514 if (!aac_valid_context(scsicmd, fibptr))
517 aac_fib_init(fibptr);
519 dinfo = (struct aac_query_mount *)fib_data(fibptr);
521 dinfo->command = cpu_to_le32(VM_NameServe64);
522 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
523 dinfo->type = cpu_to_le32(FT_FILESYS);
525 status = aac_fib_send(ContainerCommand,
527 sizeof(struct aac_query_mount),
530 (fib_callback) _aac_probe_container2,
533 * Check that the command queued to the controller
535 if (status == -EINPROGRESS) {
536 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
540 /* Inherit results from VM_NameServe, if any */
541 dresp->status = cpu_to_le32(ST_OK);
542 return _aac_probe_container2(context, fibptr);
547 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
550 int status = -ENOMEM;
552 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
553 struct aac_query_mount *dinfo;
555 aac_fib_init(fibptr);
557 dinfo = (struct aac_query_mount *)fib_data(fibptr);
559 dinfo->command = cpu_to_le32(VM_NameServe);
560 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
561 dinfo->type = cpu_to_le32(FT_FILESYS);
562 scsicmd->SCp.ptr = (char *)callback;
564 status = aac_fib_send(ContainerCommand,
566 sizeof(struct aac_query_mount),
569 (fib_callback) _aac_probe_container1,
572 * Check that the command queued to the controller
574 if (status == -EINPROGRESS) {
575 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
579 scsicmd->SCp.ptr = NULL;
580 aac_fib_complete(fibptr);
581 aac_fib_free(fibptr);
585 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
587 fsa_dev_ptr += scmd_id(scsicmd);
588 if ((fsa_dev_ptr->valid & 1) == 0) {
589 fsa_dev_ptr->valid = 0;
590 return (*callback)(scsicmd);
598 * aac_probe_container - query a logical volume
599 * @dev: device to query
600 * @cid: container identifier
602 * Queries the controller about the given volume. The volume information
603 * is updated in the struct fsa_dev_info structure rather than returned.
605 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
607 scsicmd->device = NULL;
611 int aac_probe_container(struct aac_dev *dev, int cid)
613 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
614 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
617 if (!scsicmd || !scsidev) {
622 scsicmd->list.next = NULL;
623 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))_aac_probe_container1;
625 scsicmd->device = scsidev;
626 scsidev->sdev_state = 0;
628 scsidev->host = dev->scsi_host_ptr;
630 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
631 while (scsicmd->device == scsidev)
634 status = scsicmd->SCp.Status;
639 /* Local Structure to set SCSI inquiry data strings */
641 char vid[8]; /* Vendor ID */
642 char pid[16]; /* Product ID */
643 char prl[4]; /* Product Revision Level */
647 * InqStrCopy - string merge
648 * @a: string to copy from
649 * @b: string to copy to
651 * Copy a String from one location to another
655 static void inqstrcpy(char *a, char *b)
662 static char *container_types[] = {
688 /* Function: setinqstr
690 * Arguments: [1] pointer to void [1] int
692 * Purpose: Sets SCSI inquiry data strings for vendor, product
693 * and revision level. Allows strings to be set in platform dependant
694 * files instead of in OS dependant driver source.
697 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
699 struct scsi_inq *str;
701 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
702 memset(str, ' ', sizeof(*str));
704 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
705 char * cp = dev->supplement_adapter_info.AdapterTypeText;
706 int c = sizeof(str->vid);
707 while (*cp && *cp != ' ' && --c)
711 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
714 while (*cp && *cp != ' ')
718 /* last six chars reserved for vol type */
720 if (strlen(cp) > sizeof(str->pid)) {
721 c = cp[sizeof(str->pid)];
722 cp[sizeof(str->pid)] = '\0';
724 inqstrcpy (cp, str->pid);
726 cp[sizeof(str->pid)] = c;
728 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
730 inqstrcpy (mp->vname, str->vid);
731 /* last six chars reserved for vol type */
732 inqstrcpy (mp->model, str->pid);
735 if (tindex < ARRAY_SIZE(container_types)){
736 char *findit = str->pid;
738 for ( ; *findit != ' '; findit++); /* walk till we find a space */
739 /* RAID is superfluous in the context of a RAID device */
740 if (memcmp(findit-4, "RAID", 4) == 0)
741 *(findit -= 4) = ' ';
742 if (((findit - str->pid) + strlen(container_types[tindex]))
743 < (sizeof(str->pid) + sizeof(str->prl)))
744 inqstrcpy (container_types[tindex], findit + 1);
746 inqstrcpy ("V1.0", str->prl);
749 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
750 u8 a_sense_code, u8 incorrect_length,
751 u8 bit_pointer, u16 field_pointer,
754 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
755 sense_buf[1] = 0; /* Segment number, always zero */
757 if (incorrect_length) {
758 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
759 sense_buf[3] = BYTE3(residue);
760 sense_buf[4] = BYTE2(residue);
761 sense_buf[5] = BYTE1(residue);
762 sense_buf[6] = BYTE0(residue);
764 sense_buf[2] = sense_key; /* Sense key */
766 if (sense_key == ILLEGAL_REQUEST)
767 sense_buf[7] = 10; /* Additional sense length */
769 sense_buf[7] = 6; /* Additional sense length */
771 sense_buf[12] = sense_code; /* Additional sense code */
772 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
773 if (sense_key == ILLEGAL_REQUEST) {
776 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
777 sense_buf[15] = 0x80;/* Std sense key specific field */
778 /* Illegal parameter is in the parameter block */
780 if (sense_code == SENCODE_INVALID_CDB_FIELD)
781 sense_buf[15] = 0xc0;/* Std sense key specific field */
782 /* Illegal parameter is in the CDB block */
783 sense_buf[15] |= bit_pointer;
784 sense_buf[16] = field_pointer >> 8; /* MSB */
785 sense_buf[17] = field_pointer; /* LSB */
789 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
791 if (lba & 0xffffffff00000000LL) {
792 int cid = scmd_id(cmd);
793 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
794 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
795 SAM_STAT_CHECK_CONDITION;
796 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
798 SENCODE_INTERNAL_TARGET_FAILURE,
799 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
801 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
802 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
803 ? sizeof(cmd->sense_buffer)
804 : sizeof(dev->fsa_dev[cid].sense_data));
811 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
816 static void io_callback(void *context, struct fib * fibptr);
818 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
821 struct aac_raw_io *readcmd;
823 readcmd = (struct aac_raw_io *) fib_data(fib);
824 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
825 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
826 readcmd->count = cpu_to_le32(count<<9);
827 readcmd->cid = cpu_to_le16(scmd_id(cmd));
828 readcmd->flags = cpu_to_le16(1);
829 readcmd->bpTotal = 0;
830 readcmd->bpComplete = 0;
832 aac_build_sgraw(cmd, &readcmd->sg);
833 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
834 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
836 * Now send the Fib to the adapter
838 return aac_fib_send(ContainerRawIo,
843 (fib_callback) io_callback,
847 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
850 struct aac_read64 *readcmd;
852 readcmd = (struct aac_read64 *) fib_data(fib);
853 readcmd->command = cpu_to_le32(VM_CtHostRead64);
854 readcmd->cid = cpu_to_le16(scmd_id(cmd));
855 readcmd->sector_count = cpu_to_le16(count);
856 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
860 aac_build_sg64(cmd, &readcmd->sg);
861 fibsize = sizeof(struct aac_read64) +
862 ((le32_to_cpu(readcmd->sg.count) - 1) *
863 sizeof (struct sgentry64));
864 BUG_ON (fibsize > (fib->dev->max_fib_size -
865 sizeof(struct aac_fibhdr)));
867 * Now send the Fib to the adapter
869 return aac_fib_send(ContainerCommand64,
874 (fib_callback) io_callback,
878 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
881 struct aac_read *readcmd;
883 readcmd = (struct aac_read *) fib_data(fib);
884 readcmd->command = cpu_to_le32(VM_CtBlockRead);
885 readcmd->cid = cpu_to_le16(scmd_id(cmd));
886 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
887 readcmd->count = cpu_to_le32(count * 512);
889 aac_build_sg(cmd, &readcmd->sg);
890 fibsize = sizeof(struct aac_read) +
891 ((le32_to_cpu(readcmd->sg.count) - 1) *
892 sizeof (struct sgentry));
893 BUG_ON (fibsize > (fib->dev->max_fib_size -
894 sizeof(struct aac_fibhdr)));
896 * Now send the Fib to the adapter
898 return aac_fib_send(ContainerCommand,
903 (fib_callback) io_callback,
907 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
910 struct aac_raw_io *writecmd;
912 writecmd = (struct aac_raw_io *) fib_data(fib);
913 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
914 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
915 writecmd->count = cpu_to_le32(count<<9);
916 writecmd->cid = cpu_to_le16(scmd_id(cmd));
918 writecmd->bpTotal = 0;
919 writecmd->bpComplete = 0;
921 aac_build_sgraw(cmd, &writecmd->sg);
922 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
923 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
925 * Now send the Fib to the adapter
927 return aac_fib_send(ContainerRawIo,
932 (fib_callback) io_callback,
936 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
939 struct aac_write64 *writecmd;
941 writecmd = (struct aac_write64 *) fib_data(fib);
942 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
943 writecmd->cid = cpu_to_le16(scmd_id(cmd));
944 writecmd->sector_count = cpu_to_le16(count);
945 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
949 aac_build_sg64(cmd, &writecmd->sg);
950 fibsize = sizeof(struct aac_write64) +
951 ((le32_to_cpu(writecmd->sg.count) - 1) *
952 sizeof (struct sgentry64));
953 BUG_ON (fibsize > (fib->dev->max_fib_size -
954 sizeof(struct aac_fibhdr)));
956 * Now send the Fib to the adapter
958 return aac_fib_send(ContainerCommand64,
963 (fib_callback) io_callback,
967 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
970 struct aac_write *writecmd;
972 writecmd = (struct aac_write *) fib_data(fib);
973 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
974 writecmd->cid = cpu_to_le16(scmd_id(cmd));
975 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
976 writecmd->count = cpu_to_le32(count * 512);
977 writecmd->sg.count = cpu_to_le32(1);
978 /* ->stable is not used - it did mean which type of write */
980 aac_build_sg(cmd, &writecmd->sg);
981 fibsize = sizeof(struct aac_write) +
982 ((le32_to_cpu(writecmd->sg.count) - 1) *
983 sizeof (struct sgentry));
984 BUG_ON (fibsize > (fib->dev->max_fib_size -
985 sizeof(struct aac_fibhdr)));
987 * Now send the Fib to the adapter
989 return aac_fib_send(ContainerCommand,
994 (fib_callback) io_callback,
998 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1000 struct aac_srb * srbcmd;
1005 switch(cmd->sc_data_direction){
1009 case DMA_BIDIRECTIONAL:
1010 flag = SRB_DataIn | SRB_DataOut;
1012 case DMA_FROM_DEVICE:
1016 default: /* shuts up some versions of gcc */
1017 flag = SRB_NoDataXfer;
1021 srbcmd = (struct aac_srb*) fib_data(fib);
1022 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1023 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1024 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1025 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1026 srbcmd->flags = cpu_to_le32(flag);
1027 timeout = cmd->timeout_per_command/HZ;
1030 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1031 srbcmd->retry_limit = 0; /* Obsolete parameter */
1032 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1036 static void aac_srb_callback(void *context, struct fib * fibptr);
1038 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1041 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1043 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1044 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
1046 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1047 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1049 * Build Scatter/Gather list
1051 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1052 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1053 sizeof (struct sgentry64));
1054 BUG_ON (fibsize > (fib->dev->max_fib_size -
1055 sizeof(struct aac_fibhdr)));
1058 * Now send the Fib to the adapter
1060 return aac_fib_send(ScsiPortCommand64, fib,
1061 fibsize, FsaNormal, 0, 1,
1062 (fib_callback) aac_srb_callback,
1066 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1069 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1071 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1072 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
1074 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1075 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1077 * Build Scatter/Gather list
1079 fibsize = sizeof (struct aac_srb) +
1080 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1081 sizeof (struct sgentry));
1082 BUG_ON (fibsize > (fib->dev->max_fib_size -
1083 sizeof(struct aac_fibhdr)));
1086 * Now send the Fib to the adapter
1088 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1089 (fib_callback) aac_srb_callback, (void *) cmd);
1092 int aac_get_adapter_info(struct aac_dev* dev)
1097 struct aac_adapter_info *info;
1098 struct aac_bus_info *command;
1099 struct aac_bus_info_response *bus_info;
1101 if (!(fibptr = aac_fib_alloc(dev)))
1104 aac_fib_init(fibptr);
1105 info = (struct aac_adapter_info *) fib_data(fibptr);
1106 memset(info,0,sizeof(*info));
1108 rcode = aac_fib_send(RequestAdapterInfo,
1112 -1, 1, /* First `interrupt' command uses special wait */
1117 aac_fib_complete(fibptr);
1118 aac_fib_free(fibptr);
1121 memcpy(&dev->adapter_info, info, sizeof(*info));
1123 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1124 struct aac_supplement_adapter_info * info;
1126 aac_fib_init(fibptr);
1128 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1130 memset(info,0,sizeof(*info));
1132 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1141 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
1149 aac_fib_init(fibptr);
1151 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1153 memset(bus_info, 0, sizeof(*bus_info));
1155 command = (struct aac_bus_info *)bus_info;
1157 command->Command = cpu_to_le32(VM_Ioctl);
1158 command->ObjType = cpu_to_le32(FT_DRIVE);
1159 command->MethodId = cpu_to_le32(1);
1160 command->CtlCmd = cpu_to_le32(GetBusInfo);
1162 rcode = aac_fib_send(ContainerCommand,
1169 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1170 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1171 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1174 if (!dev->in_reset) {
1175 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1176 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1182 le32_to_cpu(dev->adapter_info.kernelbuild),
1183 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1184 dev->supplement_adapter_info.BuildDate);
1185 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1186 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1188 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1189 le32_to_cpu(dev->adapter_info.monitorbuild));
1190 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1191 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1193 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1194 le32_to_cpu(dev->adapter_info.biosbuild));
1195 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
1196 printk(KERN_INFO "%s%d: serial %x\n",
1198 le32_to_cpu(dev->adapter_info.serial[0]));
1199 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1200 printk(KERN_INFO "%s%d: TSID %.*s\n",
1202 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1203 dev->supplement_adapter_info.VpdInfo.Tsid);
1207 dev->nondasd_support = 0;
1208 dev->raid_scsi_mode = 0;
1209 if(dev->adapter_info.options & AAC_OPT_NONDASD){
1210 dev->nondasd_support = 1;
1214 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1215 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1216 * force nondasd support on. If we decide to allow the non-dasd flag
1217 * additional changes changes will have to be made to support
1218 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1219 * changed to support the new dev->raid_scsi_mode flag instead of
1220 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1221 * function aac_detect will have to be modified where it sets up the
1222 * max number of channels based on the aac->nondasd_support flag only.
1224 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1225 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1226 dev->nondasd_support = 1;
1227 dev->raid_scsi_mode = 1;
1229 if (dev->raid_scsi_mode != 0)
1230 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1231 dev->name, dev->id);
1234 dev->nondasd_support = (nondasd!=0);
1236 if(dev->nondasd_support != 0){
1237 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1240 dev->dac_support = 0;
1241 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1242 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1243 dev->dac_support = 1;
1247 dev->dac_support = (dacmode!=0);
1249 if(dev->dac_support != 0) {
1250 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1251 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1252 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1253 dev->name, dev->id);
1254 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1255 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1256 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1257 dev->name, dev->id);
1258 dev->dac_support = 0;
1260 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1261 dev->name, dev->id);
1266 * Deal with configuring for the individualized limits of each packet
1269 dev->a_ops.adapter_scsi = (dev->dac_support)
1272 if (dev->raw_io_interface) {
1273 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1276 dev->a_ops.adapter_read = aac_read_raw_io;
1277 dev->a_ops.adapter_write = aac_write_raw_io;
1279 dev->a_ops.adapter_bounds = aac_bounds_32;
1280 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1281 sizeof(struct aac_fibhdr) -
1282 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1283 sizeof(struct sgentry);
1284 if (dev->dac_support) {
1285 dev->a_ops.adapter_read = aac_read_block64;
1286 dev->a_ops.adapter_write = aac_write_block64;
1288 * 38 scatter gather elements
1290 dev->scsi_host_ptr->sg_tablesize =
1291 (dev->max_fib_size -
1292 sizeof(struct aac_fibhdr) -
1293 sizeof(struct aac_write64) +
1294 sizeof(struct sgentry64)) /
1295 sizeof(struct sgentry64);
1297 dev->a_ops.adapter_read = aac_read_block;
1298 dev->a_ops.adapter_write = aac_write_block;
1300 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1301 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1303 * Worst case size that could cause sg overflow when
1304 * we break up SG elements that are larger than 64KB.
1305 * Would be nice if we could tell the SCSI layer what
1306 * the maximum SG element size can be. Worst case is
1307 * (sg_tablesize-1) 4KB elements with one 64KB
1309 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1311 dev->scsi_host_ptr->max_sectors =
1312 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1316 aac_fib_complete(fibptr);
1317 aac_fib_free(fibptr);
1323 static void io_callback(void *context, struct fib * fibptr)
1325 struct aac_dev *dev;
1326 struct aac_read_reply *readreply;
1327 struct scsi_cmnd *scsicmd;
1330 scsicmd = (struct scsi_cmnd *) context;
1332 if (!aac_valid_context(scsicmd, fibptr))
1335 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1336 cid = scmd_id(scsicmd);
1338 if (nblank(dprintk(x))) {
1340 switch (scsicmd->cmnd[0]) {
1343 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1344 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1348 lba = ((u64)scsicmd->cmnd[2] << 56) |
1349 ((u64)scsicmd->cmnd[3] << 48) |
1350 ((u64)scsicmd->cmnd[4] << 40) |
1351 ((u64)scsicmd->cmnd[5] << 32) |
1352 ((u64)scsicmd->cmnd[6] << 24) |
1353 (scsicmd->cmnd[7] << 16) |
1354 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1358 lba = ((u64)scsicmd->cmnd[2] << 24) |
1359 (scsicmd->cmnd[3] << 16) |
1360 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1363 lba = ((u64)scsicmd->cmnd[2] << 24) |
1364 (scsicmd->cmnd[3] << 16) |
1365 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1369 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1370 smp_processor_id(), (unsigned long long)lba, jiffies);
1373 BUG_ON(fibptr == NULL);
1376 pci_unmap_sg(dev->pdev,
1377 (struct scatterlist *)scsicmd->request_buffer,
1379 scsicmd->sc_data_direction);
1380 else if(scsicmd->request_bufflen)
1381 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
1382 scsicmd->request_bufflen,
1383 scsicmd->sc_data_direction);
1384 readreply = (struct aac_read_reply *)fib_data(fibptr);
1385 if (le32_to_cpu(readreply->status) == ST_OK)
1386 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1388 #ifdef AAC_DETAILED_STATUS_INFO
1389 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1390 le32_to_cpu(readreply->status));
1392 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1393 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1395 SENCODE_INTERNAL_TARGET_FAILURE,
1396 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1398 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1399 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1400 ? sizeof(scsicmd->sense_buffer)
1401 : sizeof(dev->fsa_dev[cid].sense_data));
1403 aac_fib_complete(fibptr);
1404 aac_fib_free(fibptr);
1406 scsicmd->scsi_done(scsicmd);
1409 static int aac_read(struct scsi_cmnd * scsicmd)
1414 struct aac_dev *dev;
1415 struct fib * cmd_fibcontext;
1417 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1419 * Get block address and transfer length
1421 switch (scsicmd->cmnd[0]) {
1423 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1425 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1426 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1427 count = scsicmd->cmnd[4];
1433 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1435 lba = ((u64)scsicmd->cmnd[2] << 56) |
1436 ((u64)scsicmd->cmnd[3] << 48) |
1437 ((u64)scsicmd->cmnd[4] << 40) |
1438 ((u64)scsicmd->cmnd[5] << 32) |
1439 ((u64)scsicmd->cmnd[6] << 24) |
1440 (scsicmd->cmnd[7] << 16) |
1441 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1442 count = (scsicmd->cmnd[10] << 24) |
1443 (scsicmd->cmnd[11] << 16) |
1444 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1447 dprintk((KERN_DEBUG "aachba: received a read(12) 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[6] << 24) |
1453 (scsicmd->cmnd[7] << 16) |
1454 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1457 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1459 lba = ((u64)scsicmd->cmnd[2] << 24) |
1460 (scsicmd->cmnd[3] << 16) |
1461 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1462 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1465 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1466 smp_processor_id(), (unsigned long long)lba, jiffies));
1467 if (aac_adapter_bounds(dev,scsicmd,lba))
1470 * Alocate and initialize a Fib
1472 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1476 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1479 * Check that the command queued to the controller
1481 if (status == -EINPROGRESS) {
1482 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1486 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1488 * For some reason, the Fib didn't queue, return QUEUE_FULL
1490 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1491 scsicmd->scsi_done(scsicmd);
1492 aac_fib_complete(cmd_fibcontext);
1493 aac_fib_free(cmd_fibcontext);
1497 static int aac_write(struct scsi_cmnd * scsicmd)
1502 struct aac_dev *dev;
1503 struct fib * cmd_fibcontext;
1505 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1507 * Get block address and transfer length
1509 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1511 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1512 count = scsicmd->cmnd[4];
1515 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1516 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1518 lba = ((u64)scsicmd->cmnd[2] << 56) |
1519 ((u64)scsicmd->cmnd[3] << 48) |
1520 ((u64)scsicmd->cmnd[4] << 40) |
1521 ((u64)scsicmd->cmnd[5] << 32) |
1522 ((u64)scsicmd->cmnd[6] << 24) |
1523 (scsicmd->cmnd[7] << 16) |
1524 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1525 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1526 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1527 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1528 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1530 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1531 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1532 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1533 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1535 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1536 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1537 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1539 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1540 smp_processor_id(), (unsigned long long)lba, jiffies));
1541 if (aac_adapter_bounds(dev,scsicmd,lba))
1544 * Allocate and initialize a Fib then setup a BlockWrite command
1546 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1547 scsicmd->result = DID_ERROR << 16;
1548 scsicmd->scsi_done(scsicmd);
1552 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count);
1555 * Check that the command queued to the controller
1557 if (status == -EINPROGRESS) {
1558 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1562 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1564 * For some reason, the Fib didn't queue, return QUEUE_FULL
1566 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1567 scsicmd->scsi_done(scsicmd);
1569 aac_fib_complete(cmd_fibcontext);
1570 aac_fib_free(cmd_fibcontext);
1574 static void synchronize_callback(void *context, struct fib *fibptr)
1576 struct aac_synchronize_reply *synchronizereply;
1577 struct scsi_cmnd *cmd;
1581 if (!aac_valid_context(cmd, fibptr))
1584 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1585 smp_processor_id(), jiffies));
1586 BUG_ON(fibptr == NULL);
1589 synchronizereply = fib_data(fibptr);
1590 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1591 cmd->result = DID_OK << 16 |
1592 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1594 struct scsi_device *sdev = cmd->device;
1595 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1596 u32 cid = sdev_id(sdev);
1598 "synchronize_callback: synchronize failed, status = %d\n",
1599 le32_to_cpu(synchronizereply->status));
1600 cmd->result = DID_OK << 16 |
1601 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1602 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1604 SENCODE_INTERNAL_TARGET_FAILURE,
1605 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1607 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1608 min(sizeof(dev->fsa_dev[cid].sense_data),
1609 sizeof(cmd->sense_buffer)));
1612 aac_fib_complete(fibptr);
1613 aac_fib_free(fibptr);
1614 cmd->scsi_done(cmd);
1617 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1620 struct fib *cmd_fibcontext;
1621 struct aac_synchronize *synchronizecmd;
1622 struct scsi_cmnd *cmd;
1623 struct scsi_device *sdev = scsicmd->device;
1625 struct aac_dev *aac;
1626 unsigned long flags;
1629 * Wait for all outstanding queued commands to complete to this
1630 * specific target (block).
1632 spin_lock_irqsave(&sdev->list_lock, flags);
1633 list_for_each_entry(cmd, &sdev->cmd_list, list)
1634 if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1639 spin_unlock_irqrestore(&sdev->list_lock, flags);
1642 * Yield the processor (requeue for later)
1645 return SCSI_MLQUEUE_DEVICE_BUSY;
1647 aac = (struct aac_dev *)scsicmd->device->host->hostdata;
1649 return SCSI_MLQUEUE_HOST_BUSY;
1652 * Allocate and initialize a Fib
1654 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1655 return SCSI_MLQUEUE_HOST_BUSY;
1657 aac_fib_init(cmd_fibcontext);
1659 synchronizecmd = fib_data(cmd_fibcontext);
1660 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1661 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1662 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
1663 synchronizecmd->count =
1664 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1667 * Now send the Fib to the adapter
1669 status = aac_fib_send(ContainerCommand,
1671 sizeof(struct aac_synchronize),
1674 (fib_callback)synchronize_callback,
1678 * Check that the command queued to the controller
1680 if (status == -EINPROGRESS) {
1681 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1686 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1687 aac_fib_complete(cmd_fibcontext);
1688 aac_fib_free(cmd_fibcontext);
1689 return SCSI_MLQUEUE_HOST_BUSY;
1693 * aac_scsi_cmd() - Process SCSI command
1694 * @scsicmd: SCSI command block
1696 * Emulate a SCSI command and queue the required request for the
1700 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1703 struct Scsi_Host *host = scsicmd->device->host;
1704 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1705 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1707 if (fsa_dev_ptr == NULL)
1710 * If the bus, id or lun is out of range, return fail
1711 * Test does not apply to ID 16, the pseudo id for the controller
1714 if (scmd_id(scsicmd) != host->this_id) {
1715 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
1716 if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
1717 (scsicmd->device->lun != 0)) {
1718 scsicmd->result = DID_NO_CONNECT << 16;
1719 scsicmd->scsi_done(scsicmd);
1722 cid = scmd_id(scsicmd);
1725 * If the target container doesn't exist, it may have
1726 * been newly created
1728 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1729 switch (scsicmd->cmnd[0]) {
1730 case SERVICE_ACTION_IN:
1731 if (!(dev->raw_io_interface) ||
1732 !(dev->raw_io_64) ||
1733 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1737 case TEST_UNIT_READY:
1740 return _aac_probe_container(scsicmd,
1741 aac_probe_container_callback2);
1746 } else { /* check for physical non-dasd devices */
1747 if ((dev->nondasd_support == 1) || expose_physicals) {
1750 return aac_send_srb_fib(scsicmd);
1752 scsicmd->result = DID_NO_CONNECT << 16;
1753 scsicmd->scsi_done(scsicmd);
1759 * else Command for the controller itself
1761 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1762 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1764 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1765 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1766 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1768 SENCODE_INVALID_COMMAND,
1769 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1770 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1771 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1772 ? sizeof(scsicmd->sense_buffer)
1773 : sizeof(dev->fsa_dev[cid].sense_data));
1774 scsicmd->scsi_done(scsicmd);
1779 /* Handle commands here that don't really require going out to the adapter */
1780 switch (scsicmd->cmnd[0]) {
1783 struct inquiry_data inq_data;
1785 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
1786 memset(&inq_data, 0, sizeof (struct inquiry_data));
1788 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1789 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 */
1790 inq_data.inqd_len = 31;
1791 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1792 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1794 * Set the Vendor, Product, and Revision Level
1795 * see: <vendor>.c i.e. aac.c
1797 if (scmd_id(scsicmd) == host->this_id) {
1798 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
1799 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1800 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1801 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1802 scsicmd->scsi_done(scsicmd);
1807 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1808 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1809 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1810 return aac_get_container_name(scsicmd);
1812 case SERVICE_ACTION_IN:
1813 if (!(dev->raw_io_interface) ||
1814 !(dev->raw_io_64) ||
1815 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1821 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1822 capacity = fsa_dev_ptr[cid].size - 1;
1823 cp[0] = (capacity >> 56) & 0xff;
1824 cp[1] = (capacity >> 48) & 0xff;
1825 cp[2] = (capacity >> 40) & 0xff;
1826 cp[3] = (capacity >> 32) & 0xff;
1827 cp[4] = (capacity >> 24) & 0xff;
1828 cp[5] = (capacity >> 16) & 0xff;
1829 cp[6] = (capacity >> 8) & 0xff;
1830 cp[7] = (capacity >> 0) & 0xff;
1836 aac_internal_transfer(scsicmd, cp, 0,
1837 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
1838 if (sizeof(cp) < scsicmd->cmnd[13]) {
1839 unsigned int len, offset = sizeof(cp);
1841 memset(cp, 0, offset);
1843 len = min_t(size_t, scsicmd->cmnd[13] - offset,
1845 aac_internal_transfer(scsicmd, cp, offset, len);
1846 } while ((offset += len) < scsicmd->cmnd[13]);
1849 /* Do not cache partition table for arrays */
1850 scsicmd->device->removable = 1;
1852 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1853 scsicmd->scsi_done(scsicmd);
1863 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1864 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
1865 capacity = fsa_dev_ptr[cid].size - 1;
1869 cp[0] = (capacity >> 24) & 0xff;
1870 cp[1] = (capacity >> 16) & 0xff;
1871 cp[2] = (capacity >> 8) & 0xff;
1872 cp[3] = (capacity >> 0) & 0xff;
1877 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1878 /* Do not cache partition table for arrays */
1879 scsicmd->device->removable = 1;
1881 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1882 scsicmd->scsi_done(scsicmd);
1891 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1892 mode_buf[0] = 3; /* Mode data length */
1893 mode_buf[1] = 0; /* Medium type - default */
1894 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1895 mode_buf[3] = 0; /* Block descriptor length */
1897 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1898 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1899 scsicmd->scsi_done(scsicmd);
1907 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1908 mode_buf[0] = 0; /* Mode data length (MSB) */
1909 mode_buf[1] = 6; /* Mode data length (LSB) */
1910 mode_buf[2] = 0; /* Medium type - default */
1911 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1912 mode_buf[4] = 0; /* reserved */
1913 mode_buf[5] = 0; /* reserved */
1914 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1915 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1916 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1918 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1919 scsicmd->scsi_done(scsicmd);
1924 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1925 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1926 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1927 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1928 scsicmd->scsi_done(scsicmd);
1931 case ALLOW_MEDIUM_REMOVAL:
1932 dprintk((KERN_DEBUG "LOCK command.\n"));
1933 if (scsicmd->cmnd[4])
1934 fsa_dev_ptr[cid].locked = 1;
1936 fsa_dev_ptr[cid].locked = 0;
1938 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1939 scsicmd->scsi_done(scsicmd);
1942 * These commands are all No-Ops
1944 case TEST_UNIT_READY:
1948 case REASSIGN_BLOCKS:
1951 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1952 scsicmd->scsi_done(scsicmd);
1956 switch (scsicmd->cmnd[0])
1965 * Hack to keep track of ordinal number of the device that
1966 * corresponds to a container. Needed to convert
1967 * containers to /dev/sd device names
1970 if (scsicmd->request->rq_disk)
1971 strlcpy(fsa_dev_ptr[cid].devname,
1972 scsicmd->request->rq_disk->disk_name,
1973 min(sizeof(fsa_dev_ptr[cid].devname),
1974 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1976 return aac_read(scsicmd);
1984 return aac_write(scsicmd);
1986 case SYNCHRONIZE_CACHE:
1987 /* Issue FIB to tell Firmware to flush it's cache */
1988 return aac_synchronize(scsicmd);
1992 * Unhandled commands
1994 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1995 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1996 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1997 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1998 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1999 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2000 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
2001 ? sizeof(scsicmd->sense_buffer)
2002 : sizeof(dev->fsa_dev[cid].sense_data));
2003 scsicmd->scsi_done(scsicmd);
2008 static int query_disk(struct aac_dev *dev, void __user *arg)
2010 struct aac_query_disk qd;
2011 struct fsa_dev_info *fsa_dev_ptr;
2013 fsa_dev_ptr = dev->fsa_dev;
2016 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2020 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2022 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2024 qd.instance = dev->scsi_host_ptr->host_no;
2026 qd.id = CONTAINER_TO_ID(qd.cnum);
2027 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2029 else return -EINVAL;
2031 qd.valid = fsa_dev_ptr[qd.cnum].valid;
2032 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2033 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2035 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2040 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2041 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2043 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2048 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2050 struct aac_delete_disk dd;
2051 struct fsa_dev_info *fsa_dev_ptr;
2053 fsa_dev_ptr = dev->fsa_dev;
2057 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2060 if (dd.cnum >= dev->maximum_num_containers)
2063 * Mark this container as being deleted.
2065 fsa_dev_ptr[dd.cnum].deleted = 1;
2067 * Mark the container as no longer valid
2069 fsa_dev_ptr[dd.cnum].valid = 0;
2073 static int delete_disk(struct aac_dev *dev, void __user *arg)
2075 struct aac_delete_disk dd;
2076 struct fsa_dev_info *fsa_dev_ptr;
2078 fsa_dev_ptr = dev->fsa_dev;
2082 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2085 if (dd.cnum >= dev->maximum_num_containers)
2088 * If the container is locked, it can not be deleted by the API.
2090 if (fsa_dev_ptr[dd.cnum].locked)
2094 * Mark the container as no longer being valid.
2096 fsa_dev_ptr[dd.cnum].valid = 0;
2097 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2102 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2105 case FSACTL_QUERY_DISK:
2106 return query_disk(dev, arg);
2107 case FSACTL_DELETE_DISK:
2108 return delete_disk(dev, arg);
2109 case FSACTL_FORCE_DELETE_DISK:
2110 return force_delete_disk(dev, arg);
2111 case FSACTL_GET_CONTAINERS:
2112 return aac_get_containers(dev);
2121 * @context: the context set in the fib - here it is scsi cmd
2122 * @fibptr: pointer to the fib
2124 * Handles the completion of a scsi command to a non dasd device
2128 static void aac_srb_callback(void *context, struct fib * fibptr)
2130 struct aac_dev *dev;
2131 struct aac_srb_reply *srbreply;
2132 struct scsi_cmnd *scsicmd;
2134 scsicmd = (struct scsi_cmnd *) context;
2136 if (!aac_valid_context(scsicmd, fibptr))
2139 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2141 BUG_ON(fibptr == NULL);
2143 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2145 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2147 * Calculate resid for sg
2150 scsicmd->resid = scsicmd->request_bufflen -
2151 le32_to_cpu(srbreply->data_xfer_length);
2154 pci_unmap_sg(dev->pdev,
2155 (struct scatterlist *)scsicmd->request_buffer,
2157 scsicmd->sc_data_direction);
2158 else if(scsicmd->request_bufflen)
2159 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
2160 scsicmd->sc_data_direction);
2163 * First check the fib status
2166 if (le32_to_cpu(srbreply->status) != ST_OK){
2168 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2169 len = (le32_to_cpu(srbreply->sense_data_size) >
2170 sizeof(scsicmd->sense_buffer)) ?
2171 sizeof(scsicmd->sense_buffer) :
2172 le32_to_cpu(srbreply->sense_data_size);
2173 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2174 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2178 * Next check the srb status
2180 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2181 case SRB_STATUS_ERROR_RECOVERY:
2182 case SRB_STATUS_PENDING:
2183 case SRB_STATUS_SUCCESS:
2184 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2186 case SRB_STATUS_DATA_OVERRUN:
2187 switch(scsicmd->cmnd[0]){
2196 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
2197 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2199 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2201 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2204 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2208 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2212 case SRB_STATUS_ABORTED:
2213 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2215 case SRB_STATUS_ABORT_FAILED:
2216 // Not sure about this one - but assuming the hba was trying to abort for some reason
2217 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2219 case SRB_STATUS_PARITY_ERROR:
2220 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2222 case SRB_STATUS_NO_DEVICE:
2223 case SRB_STATUS_INVALID_PATH_ID:
2224 case SRB_STATUS_INVALID_TARGET_ID:
2225 case SRB_STATUS_INVALID_LUN:
2226 case SRB_STATUS_SELECTION_TIMEOUT:
2227 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2230 case SRB_STATUS_COMMAND_TIMEOUT:
2231 case SRB_STATUS_TIMEOUT:
2232 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2235 case SRB_STATUS_BUSY:
2236 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2239 case SRB_STATUS_BUS_RESET:
2240 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2243 case SRB_STATUS_MESSAGE_REJECTED:
2244 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2246 case SRB_STATUS_REQUEST_FLUSHED:
2247 case SRB_STATUS_ERROR:
2248 case SRB_STATUS_INVALID_REQUEST:
2249 case SRB_STATUS_REQUEST_SENSE_FAILED:
2250 case SRB_STATUS_NO_HBA:
2251 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2252 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2253 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2254 case SRB_STATUS_DELAYED_RETRY:
2255 case SRB_STATUS_BAD_FUNCTION:
2256 case SRB_STATUS_NOT_STARTED:
2257 case SRB_STATUS_NOT_IN_USE:
2258 case SRB_STATUS_FORCE_ABORT:
2259 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2261 #ifdef AAC_DETAILED_STATUS_INFO
2262 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2263 le32_to_cpu(srbreply->srb_status) & 0x3F,
2264 aac_get_status_string(
2265 le32_to_cpu(srbreply->srb_status) & 0x3F),
2267 le32_to_cpu(srbreply->scsi_status));
2269 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2272 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2274 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2275 len = (le32_to_cpu(srbreply->sense_data_size) >
2276 sizeof(scsicmd->sense_buffer)) ?
2277 sizeof(scsicmd->sense_buffer) :
2278 le32_to_cpu(srbreply->sense_data_size);
2279 #ifdef AAC_DETAILED_STATUS_INFO
2280 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2281 le32_to_cpu(srbreply->status), len);
2283 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2287 * OR in the scsi status (already shifted up a bit)
2289 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2291 aac_fib_complete(fibptr);
2292 aac_fib_free(fibptr);
2293 scsicmd->scsi_done(scsicmd);
2299 * @scsicmd: the scsi command block
2301 * This routine will form a FIB and fill in the aac_srb from the
2302 * scsicmd passed in.
2305 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2307 struct fib* cmd_fibcontext;
2308 struct aac_dev* dev;
2311 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2312 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2313 scsicmd->device->lun > 7) {
2314 scsicmd->result = DID_NO_CONNECT << 16;
2315 scsicmd->scsi_done(scsicmd);
2320 * Allocate and initialize a Fib then setup a BlockWrite command
2322 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2325 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2328 * Check that the command queued to the controller
2330 if (status == -EINPROGRESS) {
2331 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2335 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2336 aac_fib_complete(cmd_fibcontext);
2337 aac_fib_free(cmd_fibcontext);
2342 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2344 struct aac_dev *dev;
2345 unsigned long byte_count = 0;
2347 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2348 // Get rid of old data
2350 psg->sg[0].addr = 0;
2351 psg->sg[0].count = 0;
2352 if (scsicmd->use_sg) {
2353 struct scatterlist *sg;
2356 sg = (struct scatterlist *) scsicmd->request_buffer;
2358 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2359 scsicmd->sc_data_direction);
2360 psg->count = cpu_to_le32(sg_count);
2362 for (i = 0; i < sg_count; i++) {
2363 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2364 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2365 byte_count += sg_dma_len(sg);
2368 /* hba wants the size to be exact */
2369 if(byte_count > scsicmd->request_bufflen){
2370 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2371 (byte_count - scsicmd->request_bufflen);
2372 psg->sg[i-1].count = cpu_to_le32(temp);
2373 byte_count = scsicmd->request_bufflen;
2375 /* Check for command underflow */
2376 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2377 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2378 byte_count, scsicmd->underflow);
2381 else if(scsicmd->request_bufflen) {
2383 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2384 scsicmd->request_buffer,
2385 scsicmd->request_bufflen,
2386 scsicmd->sc_data_direction);
2387 addr = scsicmd->SCp.dma_handle;
2388 psg->count = cpu_to_le32(1);
2389 psg->sg[0].addr = cpu_to_le32(addr);
2390 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2391 byte_count = scsicmd->request_bufflen;
2397 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2399 struct aac_dev *dev;
2400 unsigned long byte_count = 0;
2403 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2404 // Get rid of old data
2406 psg->sg[0].addr[0] = 0;
2407 psg->sg[0].addr[1] = 0;
2408 psg->sg[0].count = 0;
2409 if (scsicmd->use_sg) {
2410 struct scatterlist *sg;
2413 sg = (struct scatterlist *) scsicmd->request_buffer;
2415 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2416 scsicmd->sc_data_direction);
2418 for (i = 0; i < sg_count; i++) {
2419 int count = sg_dma_len(sg);
2420 addr = sg_dma_address(sg);
2421 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2422 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2423 psg->sg[i].count = cpu_to_le32(count);
2424 byte_count += count;
2427 psg->count = cpu_to_le32(sg_count);
2428 /* hba wants the size to be exact */
2429 if(byte_count > scsicmd->request_bufflen){
2430 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2431 (byte_count - scsicmd->request_bufflen);
2432 psg->sg[i-1].count = cpu_to_le32(temp);
2433 byte_count = scsicmd->request_bufflen;
2435 /* Check for command underflow */
2436 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2437 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2438 byte_count, scsicmd->underflow);
2441 else if(scsicmd->request_bufflen) {
2442 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2443 scsicmd->request_buffer,
2444 scsicmd->request_bufflen,
2445 scsicmd->sc_data_direction);
2446 addr = scsicmd->SCp.dma_handle;
2447 psg->count = cpu_to_le32(1);
2448 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2449 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2450 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2451 byte_count = scsicmd->request_bufflen;
2456 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2458 struct Scsi_Host *host = scsicmd->device->host;
2459 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2460 unsigned long byte_count = 0;
2462 // Get rid of old data
2464 psg->sg[0].next = 0;
2465 psg->sg[0].prev = 0;
2466 psg->sg[0].addr[0] = 0;
2467 psg->sg[0].addr[1] = 0;
2468 psg->sg[0].count = 0;
2469 psg->sg[0].flags = 0;
2470 if (scsicmd->use_sg) {
2471 struct scatterlist *sg;
2474 sg = (struct scatterlist *) scsicmd->request_buffer;
2476 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2477 scsicmd->sc_data_direction);
2479 for (i = 0; i < sg_count; i++) {
2480 int count = sg_dma_len(sg);
2481 u64 addr = sg_dma_address(sg);
2482 psg->sg[i].next = 0;
2483 psg->sg[i].prev = 0;
2484 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2485 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2486 psg->sg[i].count = cpu_to_le32(count);
2487 psg->sg[i].flags = 0;
2488 byte_count += count;
2491 psg->count = cpu_to_le32(sg_count);
2492 /* hba wants the size to be exact */
2493 if(byte_count > scsicmd->request_bufflen){
2494 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2495 (byte_count - scsicmd->request_bufflen);
2496 psg->sg[i-1].count = cpu_to_le32(temp);
2497 byte_count = scsicmd->request_bufflen;
2499 /* Check for command underflow */
2500 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2501 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2502 byte_count, scsicmd->underflow);
2505 else if(scsicmd->request_bufflen) {
2508 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2509 scsicmd->request_buffer,
2510 scsicmd->request_bufflen,
2511 scsicmd->sc_data_direction);
2512 addr = scsicmd->SCp.dma_handle;
2513 count = scsicmd->request_bufflen;
2514 psg->count = cpu_to_le32(1);
2515 psg->sg[0].next = 0;
2516 psg->sg[0].prev = 0;
2517 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2518 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2519 psg->sg[0].count = cpu_to_le32(count);
2520 psg->sg[0].flags = 0;
2521 byte_count = scsicmd->request_bufflen;
2526 #ifdef AAC_DETAILED_STATUS_INFO
2528 struct aac_srb_status_info {
2534 static struct aac_srb_status_info srb_status_info[] = {
2535 { SRB_STATUS_PENDING, "Pending Status"},
2536 { SRB_STATUS_SUCCESS, "Success"},
2537 { SRB_STATUS_ABORTED, "Aborted Command"},
2538 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2539 { SRB_STATUS_ERROR, "Error Event"},
2540 { SRB_STATUS_BUSY, "Device Busy"},
2541 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2542 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2543 { SRB_STATUS_NO_DEVICE, "No Device"},
2544 { SRB_STATUS_TIMEOUT, "Timeout"},
2545 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2546 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2547 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2548 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2549 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2550 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2551 { SRB_STATUS_NO_HBA, "No HBA"},
2552 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2553 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2554 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2555 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2556 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2557 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2558 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2559 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2560 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2561 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2562 { SRB_STATUS_NOT_STARTED, "Not Started"},
2563 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2564 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2565 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2566 { 0xff, "Unknown Error"}
2569 char *aac_get_status_string(u32 status)
2573 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2574 if (srb_status_info[i].status == status)
2575 return srb_status_info[i].str;
2577 return "Bad Status Code";