2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/slab.h>
32 #include <linux/completion.h>
33 #include <linux/blkdev.h>
34 #include <linux/dma-mapping.h>
35 #include <asm/semaphore.h>
36 #include <asm/uaccess.h>
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_cmnd.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_host.h>
45 /* values for inqd_pdt: Peripheral device type in plain English */
46 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
47 #define INQD_PDT_PROC 0x03 /* Processor device */
48 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
49 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
50 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
51 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
53 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
54 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
60 #define SENCODE_NO_SENSE 0x00
61 #define SENCODE_END_OF_DATA 0x00
62 #define SENCODE_BECOMING_READY 0x04
63 #define SENCODE_INIT_CMD_REQUIRED 0x04
64 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65 #define SENCODE_INVALID_COMMAND 0x20
66 #define SENCODE_LBA_OUT_OF_RANGE 0x21
67 #define SENCODE_INVALID_CDB_FIELD 0x24
68 #define SENCODE_LUN_NOT_SUPPORTED 0x25
69 #define SENCODE_INVALID_PARAM_FIELD 0x26
70 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
71 #define SENCODE_PARAM_VALUE_INVALID 0x26
72 #define SENCODE_RESET_OCCURRED 0x29
73 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
77 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
79 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80 #define SENCODE_OVERLAPPED_COMMAND 0x4E
83 * Additional sense codes
86 #define ASENCODE_NO_SENSE 0x00
87 #define ASENCODE_END_OF_DATA 0x05
88 #define ASENCODE_BECOMING_READY 0x01
89 #define ASENCODE_INIT_CMD_REQUIRED 0x02
90 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91 #define ASENCODE_INVALID_COMMAND 0x00
92 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
93 #define ASENCODE_INVALID_CDB_FIELD 0x00
94 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
95 #define ASENCODE_INVALID_PARAM_FIELD 0x00
96 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97 #define ASENCODE_PARAM_VALUE_INVALID 0x02
98 #define ASENCODE_RESET_OCCURRED 0x00
99 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106 #define ASENCODE_OVERLAPPED_COMMAND 0x00
108 #define BYTE0(x) (unsigned char)(x)
109 #define BYTE1(x) (unsigned char)((x) >> 8)
110 #define BYTE2(x) (unsigned char)((x) >> 16)
111 #define BYTE3(x) (unsigned char)((x) >> 24)
113 /*------------------------------------------------------------------------------
114 * S T R U C T S / T Y P E D E F S
115 *----------------------------------------------------------------------------*/
116 /* SCSI inquiry data */
117 struct inquiry_data {
118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq; /* RMB | Device Type Qualifier */
120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len; /* Additional length (n-4) */
123 u8 inqd_pad1[2];/* Reserved - must be zero */
124 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
125 u8 inqd_vid[8]; /* Vendor ID */
126 u8 inqd_pid[16];/* Product ID */
127 u8 inqd_prl[4]; /* Product Revision Level */
131 * M O D U L E G L O B A L S
134 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
136 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
137 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
138 #ifdef AAC_DETAILED_STATUS_INFO
139 static char *aac_get_status_string(u32 status);
143 * Non dasd selection is handled entirely in aachba now
146 static int nondasd = -1;
147 static int dacmode = -1;
149 static int commit = -1;
150 int startup_timeout = 180;
151 int aif_timeout = 120;
153 module_param(nondasd, int, S_IRUGO|S_IWUSR);
154 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
155 module_param(dacmode, int, S_IRUGO|S_IWUSR);
156 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
157 module_param(commit, int, S_IRUGO|S_IWUSR);
158 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on");
159 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
160 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for adapter to have it's kernel up and\nrunning. This is typically adjusted for large systems that do not have a BIOS.");
161 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
162 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for applications to pick up AIFs before\nderegistering them. This is typically adjusted for heavily burdened systems.");
165 module_param(numacb, int, S_IRUGO|S_IWUSR);
166 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid values are 512 and down. Default is to use suggestion from Firmware.");
169 module_param(acbsize, int, S_IRUGO|S_IWUSR);
170 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware.");
172 int expose_physicals = -1;
173 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
174 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
177 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
178 struct fib *fibptr) {
179 struct scsi_device *device;
181 if (unlikely(!scsicmd || !scsicmd->scsi_done )) {
182 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"))
184 aac_fib_complete(fibptr);
185 aac_fib_free(fibptr);
188 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
189 device = scsicmd->device;
190 if (unlikely(!device || !scsi_device_online(device))) {
191 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
192 aac_fib_complete(fibptr);
193 aac_fib_free(fibptr);
200 * aac_get_config_status - check the adapter configuration
201 * @common: adapter to query
203 * Query config status, and commit the configuration if needed.
205 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
210 if (!(fibptr = aac_fib_alloc(dev)))
213 aac_fib_init(fibptr);
215 struct aac_get_config_status *dinfo;
216 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
218 dinfo->command = cpu_to_le32(VM_ContainerConfig);
219 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
220 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
223 status = aac_fib_send(ContainerCommand,
225 sizeof (struct aac_get_config_status),
230 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
232 struct aac_get_config_status_resp *reply
233 = (struct aac_get_config_status_resp *) fib_data(fibptr);
234 dprintk((KERN_WARNING
235 "aac_get_config_status: response=%d status=%d action=%d\n",
236 le32_to_cpu(reply->response),
237 le32_to_cpu(reply->status),
238 le32_to_cpu(reply->data.action)));
239 if ((le32_to_cpu(reply->response) != ST_OK) ||
240 (le32_to_cpu(reply->status) != CT_OK) ||
241 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
242 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
246 aac_fib_complete(fibptr);
247 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
249 if ((commit == 1) || commit_flag) {
250 struct aac_commit_config * dinfo;
251 aac_fib_init(fibptr);
252 dinfo = (struct aac_commit_config *) fib_data(fibptr);
254 dinfo->command = cpu_to_le32(VM_ContainerConfig);
255 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
257 status = aac_fib_send(ContainerCommand,
259 sizeof (struct aac_commit_config),
263 aac_fib_complete(fibptr);
264 } else if (commit == 0) {
266 "aac_get_config_status: Foreign device configurations are being ignored\n");
269 aac_fib_free(fibptr);
274 * aac_get_containers - list containers
275 * @common: adapter to probe
277 * Make a list of all containers on this controller
279 int aac_get_containers(struct aac_dev *dev)
281 struct fsa_dev_info *fsa_dev_ptr;
285 struct aac_get_container_count *dinfo;
286 struct aac_get_container_count_resp *dresp;
287 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
289 if (!(fibptr = aac_fib_alloc(dev)))
292 aac_fib_init(fibptr);
293 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
294 dinfo->command = cpu_to_le32(VM_ContainerConfig);
295 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
297 status = aac_fib_send(ContainerCommand,
299 sizeof (struct aac_get_container_count),
304 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
305 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
306 aac_fib_complete(fibptr);
308 aac_fib_free(fibptr);
310 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
311 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
312 fsa_dev_ptr = kmalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
316 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
318 dev->fsa_dev = fsa_dev_ptr;
319 dev->maximum_num_containers = maximum_num_containers;
321 for (index = 0; index < dev->maximum_num_containers; ) {
322 fsa_dev_ptr[index].devname[0] = '\0';
324 status = aac_probe_container(dev, index);
327 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
332 * If there are no more containers, then stop asking.
334 if (++index >= status)
340 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
343 unsigned int transfer_len;
344 struct scatterlist *sg = scsicmd->request_buffer;
346 if (scsicmd->use_sg) {
347 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
348 transfer_len = min(sg->length, len + offset);
350 buf = scsicmd->request_buffer;
351 transfer_len = min(scsicmd->request_bufflen, len + offset);
353 transfer_len -= offset;
354 if (buf && transfer_len)
355 memcpy(buf + offset, data, transfer_len);
358 kunmap_atomic(buf - sg->offset, KM_IRQ0);
362 static void get_container_name_callback(void *context, struct fib * fibptr)
364 struct aac_get_name_resp * get_name_reply;
365 struct scsi_cmnd * scsicmd;
367 scsicmd = (struct scsi_cmnd *) context;
368 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
370 if (!aac_valid_context(scsicmd, fibptr))
373 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
374 BUG_ON(fibptr == NULL);
376 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
377 /* Failure is irrelevant, using default value instead */
378 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
379 && (get_name_reply->data[0] != '\0')) {
380 char *sp = get_name_reply->data;
381 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
385 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
386 int count = sizeof(d);
389 *dp++ = (*sp) ? *sp++ : ' ';
390 } while (--count > 0);
391 aac_internal_transfer(scsicmd, d,
392 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
396 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
398 aac_fib_complete(fibptr);
399 aac_fib_free(fibptr);
400 scsicmd->scsi_done(scsicmd);
404 * aac_get_container_name - get container name, none blocking.
406 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
409 struct aac_get_name *dinfo;
410 struct fib * cmd_fibcontext;
411 struct aac_dev * dev;
413 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
415 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
418 aac_fib_init(cmd_fibcontext);
419 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
421 dinfo->command = cpu_to_le32(VM_ContainerConfig);
422 dinfo->type = cpu_to_le32(CT_READ_NAME);
423 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
424 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
426 status = aac_fib_send(ContainerCommand,
428 sizeof (struct aac_get_name),
431 (fib_callback) get_container_name_callback,
435 * Check that the command queued to the controller
437 if (status == -EINPROGRESS) {
438 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
442 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
443 aac_fib_complete(cmd_fibcontext);
444 aac_fib_free(cmd_fibcontext);
448 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
450 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
452 if (fsa_dev_ptr[scmd_id(scsicmd)].valid)
453 return aac_scsi_cmd(scsicmd);
455 scsicmd->result = DID_NO_CONNECT << 16;
456 scsicmd->scsi_done(scsicmd);
460 static int _aac_probe_container2(void * context, struct fib * fibptr)
462 struct fsa_dev_info *fsa_dev_ptr;
463 int (*callback)(struct scsi_cmnd *);
464 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
466 if (!aac_valid_context(scsicmd, fibptr))
469 fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
471 scsicmd->SCp.Status = 0;
473 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
474 fsa_dev_ptr += scmd_id(scsicmd);
476 if ((le32_to_cpu(dresp->status) == ST_OK) &&
477 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
478 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
479 fsa_dev_ptr->valid = 1;
480 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
482 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
483 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
484 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
486 if ((fsa_dev_ptr->valid & 1) == 0)
487 fsa_dev_ptr->valid = 0;
488 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
490 aac_fib_complete(fibptr);
491 aac_fib_free(fibptr);
492 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
493 scsicmd->SCp.ptr = NULL;
494 return (*callback)(scsicmd);
497 static int _aac_probe_container1(void * context, struct fib * fibptr)
499 struct scsi_cmnd * scsicmd;
500 struct aac_mount * dresp;
501 struct aac_query_mount *dinfo;
504 dresp = (struct aac_mount *) fib_data(fibptr);
505 dresp->mnt[0].capacityhigh = 0;
506 if ((le32_to_cpu(dresp->status) != ST_OK) ||
507 ((le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
508 (le32_to_cpu(dresp->mnt[0].state) == FSCS_HIDDEN)))
509 return _aac_probe_container2(context, fibptr);
510 scsicmd = (struct scsi_cmnd *) context;
511 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
513 if (!aac_valid_context(scsicmd, fibptr))
516 aac_fib_init(fibptr);
518 dinfo = (struct aac_query_mount *)fib_data(fibptr);
520 dinfo->command = cpu_to_le32(VM_NameServe64);
521 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
522 dinfo->type = cpu_to_le32(FT_FILESYS);
524 status = aac_fib_send(ContainerCommand,
526 sizeof(struct aac_query_mount),
529 (fib_callback) _aac_probe_container2,
532 * Check that the command queued to the controller
534 if (status == -EINPROGRESS) {
535 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
539 /* Inherit results from VM_NameServe, if any */
540 dresp->status = cpu_to_le32(ST_OK);
541 return _aac_probe_container2(context, fibptr);
546 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
549 int status = -ENOMEM;
551 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
552 struct aac_query_mount *dinfo;
554 aac_fib_init(fibptr);
556 dinfo = (struct aac_query_mount *)fib_data(fibptr);
558 dinfo->command = cpu_to_le32(VM_NameServe);
559 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
560 dinfo->type = cpu_to_le32(FT_FILESYS);
561 scsicmd->SCp.ptr = (char *)callback;
563 status = aac_fib_send(ContainerCommand,
565 sizeof(struct aac_query_mount),
568 (fib_callback) _aac_probe_container1,
571 * Check that the command queued to the controller
573 if (status == -EINPROGRESS) {
574 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
578 scsicmd->SCp.ptr = NULL;
579 aac_fib_complete(fibptr);
580 aac_fib_free(fibptr);
584 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
586 fsa_dev_ptr += scmd_id(scsicmd);
587 if ((fsa_dev_ptr->valid & 1) == 0) {
588 fsa_dev_ptr->valid = 0;
589 return (*callback)(scsicmd);
597 * aac_probe_container - query a logical volume
598 * @dev: device to query
599 * @cid: container identifier
601 * Queries the controller about the given volume. The volume information
602 * is updated in the struct fsa_dev_info structure rather than returned.
604 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
606 scsicmd->device = NULL;
610 int aac_probe_container(struct aac_dev *dev, int cid)
612 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
613 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
616 if (!scsicmd || !scsidev) {
621 scsicmd->list.next = NULL;
622 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))_aac_probe_container1;
624 scsicmd->device = scsidev;
625 scsidev->sdev_state = 0;
627 scsidev->host = dev->scsi_host_ptr;
629 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
630 while (scsicmd->device == scsidev)
632 status = scsicmd->SCp.Status;
638 /* Local Structure to set SCSI inquiry data strings */
640 char vid[8]; /* Vendor ID */
641 char pid[16]; /* Product ID */
642 char prl[4]; /* Product Revision Level */
646 * InqStrCopy - string merge
647 * @a: string to copy from
648 * @b: string to copy to
650 * Copy a String from one location to another
654 static void inqstrcpy(char *a, char *b)
661 static char *container_types[] = {
687 /* Function: setinqstr
689 * Arguments: [1] pointer to void [1] int
691 * Purpose: Sets SCSI inquiry data strings for vendor, product
692 * and revision level. Allows strings to be set in platform dependant
693 * files instead of in OS dependant driver source.
696 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
698 struct scsi_inq *str;
700 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
701 memset(str, ' ', sizeof(*str));
703 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
704 char * cp = dev->supplement_adapter_info.AdapterTypeText;
705 int c = sizeof(str->vid);
706 while (*cp && *cp != ' ' && --c)
710 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
713 while (*cp && *cp != ' ')
717 /* last six chars reserved for vol type */
719 if (strlen(cp) > sizeof(str->pid)) {
720 c = cp[sizeof(str->pid)];
721 cp[sizeof(str->pid)] = '\0';
723 inqstrcpy (cp, str->pid);
725 cp[sizeof(str->pid)] = c;
727 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
729 inqstrcpy (mp->vname, str->vid);
730 /* last six chars reserved for vol type */
731 inqstrcpy (mp->model, str->pid);
734 if (tindex < ARRAY_SIZE(container_types)){
735 char *findit = str->pid;
737 for ( ; *findit != ' '; findit++); /* walk till we find a space */
738 /* RAID is superfluous in the context of a RAID device */
739 if (memcmp(findit-4, "RAID", 4) == 0)
740 *(findit -= 4) = ' ';
741 if (((findit - str->pid) + strlen(container_types[tindex]))
742 < (sizeof(str->pid) + sizeof(str->prl)))
743 inqstrcpy (container_types[tindex], findit + 1);
745 inqstrcpy ("V1.0", str->prl);
748 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
749 u8 a_sense_code, u8 incorrect_length,
750 u8 bit_pointer, u16 field_pointer,
753 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
754 sense_buf[1] = 0; /* Segment number, always zero */
756 if (incorrect_length) {
757 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
758 sense_buf[3] = BYTE3(residue);
759 sense_buf[4] = BYTE2(residue);
760 sense_buf[5] = BYTE1(residue);
761 sense_buf[6] = BYTE0(residue);
763 sense_buf[2] = sense_key; /* Sense key */
765 if (sense_key == ILLEGAL_REQUEST)
766 sense_buf[7] = 10; /* Additional sense length */
768 sense_buf[7] = 6; /* Additional sense length */
770 sense_buf[12] = sense_code; /* Additional sense code */
771 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
772 if (sense_key == ILLEGAL_REQUEST) {
775 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
776 sense_buf[15] = 0x80;/* Std sense key specific field */
777 /* Illegal parameter is in the parameter block */
779 if (sense_code == SENCODE_INVALID_CDB_FIELD)
780 sense_buf[15] = 0xc0;/* Std sense key specific field */
781 /* Illegal parameter is in the CDB block */
782 sense_buf[15] |= bit_pointer;
783 sense_buf[16] = field_pointer >> 8; /* MSB */
784 sense_buf[17] = field_pointer; /* LSB */
788 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
790 if (lba & 0xffffffff00000000LL) {
791 int cid = scmd_id(cmd);
792 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
793 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
794 SAM_STAT_CHECK_CONDITION;
795 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
797 SENCODE_INTERNAL_TARGET_FAILURE,
798 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
800 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
801 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
802 ? sizeof(cmd->sense_buffer)
803 : sizeof(dev->fsa_dev[cid].sense_data));
810 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
815 static void io_callback(void *context, struct fib * fibptr);
817 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
820 struct aac_raw_io *readcmd;
822 readcmd = (struct aac_raw_io *) fib_data(fib);
823 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
824 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
825 readcmd->count = cpu_to_le32(count<<9);
826 readcmd->cid = cpu_to_le16(scmd_id(cmd));
827 readcmd->flags = cpu_to_le16(1);
828 readcmd->bpTotal = 0;
829 readcmd->bpComplete = 0;
831 aac_build_sgraw(cmd, &readcmd->sg);
832 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
833 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
835 * Now send the Fib to the adapter
837 return aac_fib_send(ContainerRawIo,
842 (fib_callback) io_callback,
846 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
849 struct aac_read64 *readcmd;
851 readcmd = (struct aac_read64 *) fib_data(fib);
852 readcmd->command = cpu_to_le32(VM_CtHostRead64);
853 readcmd->cid = cpu_to_le16(scmd_id(cmd));
854 readcmd->sector_count = cpu_to_le16(count);
855 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
859 aac_build_sg64(cmd, &readcmd->sg);
860 fibsize = sizeof(struct aac_read64) +
861 ((le32_to_cpu(readcmd->sg.count) - 1) *
862 sizeof (struct sgentry64));
863 BUG_ON (fibsize > (fib->dev->max_fib_size -
864 sizeof(struct aac_fibhdr)));
866 * Now send the Fib to the adapter
868 return aac_fib_send(ContainerCommand64,
873 (fib_callback) io_callback,
877 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
880 struct aac_read *readcmd;
882 readcmd = (struct aac_read *) fib_data(fib);
883 readcmd->command = cpu_to_le32(VM_CtBlockRead);
884 readcmd->cid = cpu_to_le16(scmd_id(cmd));
885 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
886 readcmd->count = cpu_to_le32(count * 512);
888 aac_build_sg(cmd, &readcmd->sg);
889 fibsize = sizeof(struct aac_read) +
890 ((le32_to_cpu(readcmd->sg.count) - 1) *
891 sizeof (struct sgentry));
892 BUG_ON (fibsize > (fib->dev->max_fib_size -
893 sizeof(struct aac_fibhdr)));
895 * Now send the Fib to the adapter
897 return aac_fib_send(ContainerCommand,
902 (fib_callback) io_callback,
906 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
909 struct aac_raw_io *writecmd;
911 writecmd = (struct aac_raw_io *) fib_data(fib);
912 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
913 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
914 writecmd->count = cpu_to_le32(count<<9);
915 writecmd->cid = cpu_to_le16(scmd_id(cmd));
917 writecmd->bpTotal = 0;
918 writecmd->bpComplete = 0;
920 aac_build_sgraw(cmd, &writecmd->sg);
921 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
922 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
924 * Now send the Fib to the adapter
926 return aac_fib_send(ContainerRawIo,
931 (fib_callback) io_callback,
935 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
938 struct aac_write64 *writecmd;
940 writecmd = (struct aac_write64 *) fib_data(fib);
941 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
942 writecmd->cid = cpu_to_le16(scmd_id(cmd));
943 writecmd->sector_count = cpu_to_le16(count);
944 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
948 aac_build_sg64(cmd, &writecmd->sg);
949 fibsize = sizeof(struct aac_write64) +
950 ((le32_to_cpu(writecmd->sg.count) - 1) *
951 sizeof (struct sgentry64));
952 BUG_ON (fibsize > (fib->dev->max_fib_size -
953 sizeof(struct aac_fibhdr)));
955 * Now send the Fib to the adapter
957 return aac_fib_send(ContainerCommand64,
962 (fib_callback) io_callback,
966 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
969 struct aac_write *writecmd;
971 writecmd = (struct aac_write *) fib_data(fib);
972 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
973 writecmd->cid = cpu_to_le16(scmd_id(cmd));
974 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
975 writecmd->count = cpu_to_le32(count * 512);
976 writecmd->sg.count = cpu_to_le32(1);
977 /* ->stable is not used - it did mean which type of write */
979 aac_build_sg(cmd, &writecmd->sg);
980 fibsize = sizeof(struct aac_write) +
981 ((le32_to_cpu(writecmd->sg.count) - 1) *
982 sizeof (struct sgentry));
983 BUG_ON (fibsize > (fib->dev->max_fib_size -
984 sizeof(struct aac_fibhdr)));
986 * Now send the Fib to the adapter
988 return aac_fib_send(ContainerCommand,
993 (fib_callback) io_callback,
997 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
999 struct aac_srb * srbcmd;
1004 switch(cmd->sc_data_direction){
1008 case DMA_BIDIRECTIONAL:
1009 flag = SRB_DataIn | SRB_DataOut;
1011 case DMA_FROM_DEVICE:
1015 default: /* shuts up some versions of gcc */
1016 flag = SRB_NoDataXfer;
1020 srbcmd = (struct aac_srb*) fib_data(fib);
1021 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1022 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1023 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1024 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1025 srbcmd->flags = cpu_to_le32(flag);
1026 timeout = cmd->timeout_per_command/HZ;
1029 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1030 srbcmd->retry_limit = 0; /* Obsolete parameter */
1031 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1035 static void aac_srb_callback(void *context, struct fib * fibptr);
1037 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1040 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1042 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1043 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
1045 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1046 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1048 * Build Scatter/Gather list
1050 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1051 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1052 sizeof (struct sgentry64));
1053 BUG_ON (fibsize > (fib->dev->max_fib_size -
1054 sizeof(struct aac_fibhdr)));
1057 * Now send the Fib to the adapter
1059 return aac_fib_send(ScsiPortCommand64, fib,
1060 fibsize, FsaNormal, 0, 1,
1061 (fib_callback) aac_srb_callback,
1065 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1068 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1070 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1071 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
1073 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1074 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1076 * Build Scatter/Gather list
1078 fibsize = sizeof (struct aac_srb) +
1079 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1080 sizeof (struct sgentry));
1081 BUG_ON (fibsize > (fib->dev->max_fib_size -
1082 sizeof(struct aac_fibhdr)));
1085 * Now send the Fib to the adapter
1087 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1088 (fib_callback) aac_srb_callback, (void *) cmd);
1091 int aac_get_adapter_info(struct aac_dev* dev)
1096 struct aac_adapter_info *info;
1097 struct aac_bus_info *command;
1098 struct aac_bus_info_response *bus_info;
1100 if (!(fibptr = aac_fib_alloc(dev)))
1103 aac_fib_init(fibptr);
1104 info = (struct aac_adapter_info *) fib_data(fibptr);
1105 memset(info,0,sizeof(*info));
1107 rcode = aac_fib_send(RequestAdapterInfo,
1111 -1, 1, /* First `interrupt' command uses special wait */
1116 aac_fib_complete(fibptr);
1117 aac_fib_free(fibptr);
1120 memcpy(&dev->adapter_info, info, sizeof(*info));
1122 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1123 struct aac_supplement_adapter_info * info;
1125 aac_fib_init(fibptr);
1127 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1129 memset(info,0,sizeof(*info));
1131 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1140 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
1148 aac_fib_init(fibptr);
1150 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1152 memset(bus_info, 0, sizeof(*bus_info));
1154 command = (struct aac_bus_info *)bus_info;
1156 command->Command = cpu_to_le32(VM_Ioctl);
1157 command->ObjType = cpu_to_le32(FT_DRIVE);
1158 command->MethodId = cpu_to_le32(1);
1159 command->CtlCmd = cpu_to_le32(GetBusInfo);
1161 rcode = aac_fib_send(ContainerCommand,
1168 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1169 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1170 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1173 if (!dev->in_reset) {
1174 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1175 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1181 le32_to_cpu(dev->adapter_info.kernelbuild),
1182 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1183 dev->supplement_adapter_info.BuildDate);
1184 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1185 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1187 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1188 le32_to_cpu(dev->adapter_info.monitorbuild));
1189 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1190 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1192 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1193 le32_to_cpu(dev->adapter_info.biosbuild));
1194 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
1195 printk(KERN_INFO "%s%d: serial %x\n",
1197 le32_to_cpu(dev->adapter_info.serial[0]));
1200 dev->nondasd_support = 0;
1201 dev->raid_scsi_mode = 0;
1202 if(dev->adapter_info.options & AAC_OPT_NONDASD){
1203 dev->nondasd_support = 1;
1207 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1208 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1209 * force nondasd support on. If we decide to allow the non-dasd flag
1210 * additional changes changes will have to be made to support
1211 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1212 * changed to support the new dev->raid_scsi_mode flag instead of
1213 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1214 * function aac_detect will have to be modified where it sets up the
1215 * max number of channels based on the aac->nondasd_support flag only.
1217 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1218 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1219 dev->nondasd_support = 1;
1220 dev->raid_scsi_mode = 1;
1222 if (dev->raid_scsi_mode != 0)
1223 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1224 dev->name, dev->id);
1227 dev->nondasd_support = (nondasd!=0);
1229 if(dev->nondasd_support != 0){
1230 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1233 dev->dac_support = 0;
1234 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1235 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1236 dev->dac_support = 1;
1240 dev->dac_support = (dacmode!=0);
1242 if(dev->dac_support != 0) {
1243 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1244 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1245 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1246 dev->name, dev->id);
1247 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1248 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1249 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1250 dev->name, dev->id);
1251 dev->dac_support = 0;
1253 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1254 dev->name, dev->id);
1259 * Deal with configuring for the individualized limits of each packet
1262 dev->a_ops.adapter_scsi = (dev->dac_support)
1265 if (dev->raw_io_interface) {
1266 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1269 dev->a_ops.adapter_read = aac_read_raw_io;
1270 dev->a_ops.adapter_write = aac_write_raw_io;
1272 dev->a_ops.adapter_bounds = aac_bounds_32;
1273 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1274 sizeof(struct aac_fibhdr) -
1275 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1276 sizeof(struct sgentry);
1277 if (dev->dac_support) {
1278 dev->a_ops.adapter_read = aac_read_block64;
1279 dev->a_ops.adapter_write = aac_write_block64;
1281 * 38 scatter gather elements
1283 dev->scsi_host_ptr->sg_tablesize =
1284 (dev->max_fib_size -
1285 sizeof(struct aac_fibhdr) -
1286 sizeof(struct aac_write64) +
1287 sizeof(struct sgentry64)) /
1288 sizeof(struct sgentry64);
1290 dev->a_ops.adapter_read = aac_read_block;
1291 dev->a_ops.adapter_write = aac_write_block;
1293 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1294 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1296 * Worst case size that could cause sg overflow when
1297 * we break up SG elements that are larger than 64KB.
1298 * Would be nice if we could tell the SCSI layer what
1299 * the maximum SG element size can be. Worst case is
1300 * (sg_tablesize-1) 4KB elements with one 64KB
1302 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1304 dev->scsi_host_ptr->max_sectors =
1305 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1309 aac_fib_complete(fibptr);
1310 aac_fib_free(fibptr);
1316 static void io_callback(void *context, struct fib * fibptr)
1318 struct aac_dev *dev;
1319 struct aac_read_reply *readreply;
1320 struct scsi_cmnd *scsicmd;
1323 scsicmd = (struct scsi_cmnd *) context;
1324 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1326 if (!aac_valid_context(scsicmd, fibptr))
1329 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1330 cid = scmd_id(scsicmd);
1332 if (nblank(dprintk(x))) {
1334 switch (scsicmd->cmnd[0]) {
1337 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1338 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1342 lba = ((u64)scsicmd->cmnd[2] << 56) |
1343 ((u64)scsicmd->cmnd[3] << 48) |
1344 ((u64)scsicmd->cmnd[4] << 40) |
1345 ((u64)scsicmd->cmnd[5] << 32) |
1346 ((u64)scsicmd->cmnd[6] << 24) |
1347 (scsicmd->cmnd[7] << 16) |
1348 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1352 lba = ((u64)scsicmd->cmnd[2] << 24) |
1353 (scsicmd->cmnd[3] << 16) |
1354 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1357 lba = ((u64)scsicmd->cmnd[2] << 24) |
1358 (scsicmd->cmnd[3] << 16) |
1359 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1363 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1364 smp_processor_id(), (unsigned long long)lba, jiffies);
1367 BUG_ON(fibptr == NULL);
1370 pci_unmap_sg(dev->pdev,
1371 (struct scatterlist *)scsicmd->request_buffer,
1373 scsicmd->sc_data_direction);
1374 else if(scsicmd->request_bufflen)
1375 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
1376 scsicmd->request_bufflen,
1377 scsicmd->sc_data_direction);
1378 readreply = (struct aac_read_reply *)fib_data(fibptr);
1379 if (le32_to_cpu(readreply->status) == ST_OK)
1380 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1382 #ifdef AAC_DETAILED_STATUS_INFO
1383 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1384 le32_to_cpu(readreply->status));
1386 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1387 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1389 SENCODE_INTERNAL_TARGET_FAILURE,
1390 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1392 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1393 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1394 ? sizeof(scsicmd->sense_buffer)
1395 : sizeof(dev->fsa_dev[cid].sense_data));
1397 aac_fib_complete(fibptr);
1398 aac_fib_free(fibptr);
1400 scsicmd->scsi_done(scsicmd);
1403 static int aac_read(struct scsi_cmnd * scsicmd)
1408 struct aac_dev *dev;
1409 struct fib * cmd_fibcontext;
1411 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1413 * Get block address and transfer length
1415 switch (scsicmd->cmnd[0]) {
1417 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1419 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1420 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1421 count = scsicmd->cmnd[4];
1427 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1429 lba = ((u64)scsicmd->cmnd[2] << 56) |
1430 ((u64)scsicmd->cmnd[3] << 48) |
1431 ((u64)scsicmd->cmnd[4] << 40) |
1432 ((u64)scsicmd->cmnd[5] << 32) |
1433 ((u64)scsicmd->cmnd[6] << 24) |
1434 (scsicmd->cmnd[7] << 16) |
1435 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1436 count = (scsicmd->cmnd[10] << 24) |
1437 (scsicmd->cmnd[11] << 16) |
1438 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1441 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1443 lba = ((u64)scsicmd->cmnd[2] << 24) |
1444 (scsicmd->cmnd[3] << 16) |
1445 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1446 count = (scsicmd->cmnd[6] << 24) |
1447 (scsicmd->cmnd[7] << 16) |
1448 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1451 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1453 lba = ((u64)scsicmd->cmnd[2] << 24) |
1454 (scsicmd->cmnd[3] << 16) |
1455 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1456 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1459 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1460 smp_processor_id(), (unsigned long long)lba, jiffies));
1461 if (aac_adapter_bounds(dev,scsicmd,lba))
1464 * Alocate and initialize a Fib
1466 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1470 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1473 * Check that the command queued to the controller
1475 if (status == -EINPROGRESS) {
1476 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1480 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1482 * For some reason, the Fib didn't queue, return QUEUE_FULL
1484 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1485 scsicmd->scsi_done(scsicmd);
1486 aac_fib_complete(cmd_fibcontext);
1487 aac_fib_free(cmd_fibcontext);
1491 static int aac_write(struct scsi_cmnd * scsicmd)
1496 struct aac_dev *dev;
1497 struct fib * cmd_fibcontext;
1499 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1501 * Get block address and transfer length
1503 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1505 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1506 count = scsicmd->cmnd[4];
1509 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1510 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1512 lba = ((u64)scsicmd->cmnd[2] << 56) |
1513 ((u64)scsicmd->cmnd[3] << 48) |
1514 ((u64)scsicmd->cmnd[4] << 40) |
1515 ((u64)scsicmd->cmnd[5] << 32) |
1516 ((u64)scsicmd->cmnd[6] << 24) |
1517 (scsicmd->cmnd[7] << 16) |
1518 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1519 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1520 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1521 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1522 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1524 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1525 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1526 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1527 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
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];
1533 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1534 smp_processor_id(), (unsigned long long)lba, jiffies));
1535 if (aac_adapter_bounds(dev,scsicmd,lba))
1538 * Allocate and initialize a Fib then setup a BlockWrite command
1540 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1541 scsicmd->result = DID_ERROR << 16;
1542 scsicmd->scsi_done(scsicmd);
1546 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count);
1549 * Check that the command queued to the controller
1551 if (status == -EINPROGRESS) {
1552 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1556 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1558 * For some reason, the Fib didn't queue, return QUEUE_FULL
1560 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1561 scsicmd->scsi_done(scsicmd);
1563 aac_fib_complete(cmd_fibcontext);
1564 aac_fib_free(cmd_fibcontext);
1568 static void synchronize_callback(void *context, struct fib *fibptr)
1570 struct aac_synchronize_reply *synchronizereply;
1571 struct scsi_cmnd *cmd;
1574 cmd->SCp.phase = AAC_OWNER_MIDLEVEL;
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);
1886 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1887 mode_buf[0] = 3; /* Mode data length */
1888 mode_buf[1] = 0; /* Medium type - default */
1889 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1890 mode_buf[3] = 0; /* Block descriptor length */
1892 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1893 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1894 scsicmd->scsi_done(scsicmd);
1902 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1903 mode_buf[0] = 0; /* Mode data length (MSB) */
1904 mode_buf[1] = 6; /* Mode data length (LSB) */
1905 mode_buf[2] = 0; /* Medium type - default */
1906 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1907 mode_buf[4] = 0; /* reserved */
1908 mode_buf[5] = 0; /* reserved */
1909 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1910 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1911 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1913 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1914 scsicmd->scsi_done(scsicmd);
1919 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1920 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1921 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1922 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1923 scsicmd->scsi_done(scsicmd);
1926 case ALLOW_MEDIUM_REMOVAL:
1927 dprintk((KERN_DEBUG "LOCK command.\n"));
1928 if (scsicmd->cmnd[4])
1929 fsa_dev_ptr[cid].locked = 1;
1931 fsa_dev_ptr[cid].locked = 0;
1933 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1934 scsicmd->scsi_done(scsicmd);
1937 * These commands are all No-Ops
1939 case TEST_UNIT_READY:
1943 case REASSIGN_BLOCKS:
1946 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1947 scsicmd->scsi_done(scsicmd);
1951 switch (scsicmd->cmnd[0])
1960 * Hack to keep track of ordinal number of the device that
1961 * corresponds to a container. Needed to convert
1962 * containers to /dev/sd device names
1965 if (scsicmd->request->rq_disk)
1966 strlcpy(fsa_dev_ptr[cid].devname,
1967 scsicmd->request->rq_disk->disk_name,
1968 min(sizeof(fsa_dev_ptr[cid].devname),
1969 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1971 return aac_read(scsicmd);
1979 return aac_write(scsicmd);
1981 case SYNCHRONIZE_CACHE:
1982 /* Issue FIB to tell Firmware to flush it's cache */
1983 return aac_synchronize(scsicmd);
1987 * Unhandled commands
1989 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1990 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1991 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1992 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1993 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1994 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1995 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1996 ? sizeof(scsicmd->sense_buffer)
1997 : sizeof(dev->fsa_dev[cid].sense_data));
1998 scsicmd->scsi_done(scsicmd);
2003 static int query_disk(struct aac_dev *dev, void __user *arg)
2005 struct aac_query_disk qd;
2006 struct fsa_dev_info *fsa_dev_ptr;
2008 fsa_dev_ptr = dev->fsa_dev;
2011 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2015 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2017 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2019 qd.instance = dev->scsi_host_ptr->host_no;
2021 qd.id = CONTAINER_TO_ID(qd.cnum);
2022 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2024 else return -EINVAL;
2026 qd.valid = fsa_dev_ptr[qd.cnum].valid;
2027 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2028 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2030 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2035 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2036 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2038 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2043 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2045 struct aac_delete_disk dd;
2046 struct fsa_dev_info *fsa_dev_ptr;
2048 fsa_dev_ptr = dev->fsa_dev;
2052 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2055 if (dd.cnum >= dev->maximum_num_containers)
2058 * Mark this container as being deleted.
2060 fsa_dev_ptr[dd.cnum].deleted = 1;
2062 * Mark the container as no longer valid
2064 fsa_dev_ptr[dd.cnum].valid = 0;
2068 static int delete_disk(struct aac_dev *dev, void __user *arg)
2070 struct aac_delete_disk dd;
2071 struct fsa_dev_info *fsa_dev_ptr;
2073 fsa_dev_ptr = dev->fsa_dev;
2077 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2080 if (dd.cnum >= dev->maximum_num_containers)
2083 * If the container is locked, it can not be deleted by the API.
2085 if (fsa_dev_ptr[dd.cnum].locked)
2089 * Mark the container as no longer being valid.
2091 fsa_dev_ptr[dd.cnum].valid = 0;
2092 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2097 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2100 case FSACTL_QUERY_DISK:
2101 return query_disk(dev, arg);
2102 case FSACTL_DELETE_DISK:
2103 return delete_disk(dev, arg);
2104 case FSACTL_FORCE_DELETE_DISK:
2105 return force_delete_disk(dev, arg);
2106 case FSACTL_GET_CONTAINERS:
2107 return aac_get_containers(dev);
2116 * @context: the context set in the fib - here it is scsi cmd
2117 * @fibptr: pointer to the fib
2119 * Handles the completion of a scsi command to a non dasd device
2123 static void aac_srb_callback(void *context, struct fib * fibptr)
2125 struct aac_dev *dev;
2126 struct aac_srb_reply *srbreply;
2127 struct scsi_cmnd *scsicmd;
2129 scsicmd = (struct scsi_cmnd *) context;
2130 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
2132 if (!aac_valid_context(scsicmd, fibptr))
2135 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2137 BUG_ON(fibptr == NULL);
2139 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2141 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2143 * Calculate resid for sg
2146 scsicmd->resid = scsicmd->request_bufflen -
2147 le32_to_cpu(srbreply->data_xfer_length);
2150 pci_unmap_sg(dev->pdev,
2151 (struct scatterlist *)scsicmd->request_buffer,
2153 scsicmd->sc_data_direction);
2154 else if(scsicmd->request_bufflen)
2155 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
2156 scsicmd->sc_data_direction);
2159 * First check the fib status
2162 if (le32_to_cpu(srbreply->status) != ST_OK){
2164 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2165 len = (le32_to_cpu(srbreply->sense_data_size) >
2166 sizeof(scsicmd->sense_buffer)) ?
2167 sizeof(scsicmd->sense_buffer) :
2168 le32_to_cpu(srbreply->sense_data_size);
2169 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2170 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2174 * Next check the srb status
2176 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2177 case SRB_STATUS_ERROR_RECOVERY:
2178 case SRB_STATUS_PENDING:
2179 case SRB_STATUS_SUCCESS:
2180 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2182 case SRB_STATUS_DATA_OVERRUN:
2183 switch(scsicmd->cmnd[0]){
2192 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
2193 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2195 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2197 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2200 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2204 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2208 case SRB_STATUS_ABORTED:
2209 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2211 case SRB_STATUS_ABORT_FAILED:
2212 // Not sure about this one - but assuming the hba was trying to abort for some reason
2213 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2215 case SRB_STATUS_PARITY_ERROR:
2216 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2218 case SRB_STATUS_NO_DEVICE:
2219 case SRB_STATUS_INVALID_PATH_ID:
2220 case SRB_STATUS_INVALID_TARGET_ID:
2221 case SRB_STATUS_INVALID_LUN:
2222 case SRB_STATUS_SELECTION_TIMEOUT:
2223 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2226 case SRB_STATUS_COMMAND_TIMEOUT:
2227 case SRB_STATUS_TIMEOUT:
2228 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2231 case SRB_STATUS_BUSY:
2232 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2235 case SRB_STATUS_BUS_RESET:
2236 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2239 case SRB_STATUS_MESSAGE_REJECTED:
2240 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2242 case SRB_STATUS_REQUEST_FLUSHED:
2243 case SRB_STATUS_ERROR:
2244 case SRB_STATUS_INVALID_REQUEST:
2245 case SRB_STATUS_REQUEST_SENSE_FAILED:
2246 case SRB_STATUS_NO_HBA:
2247 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2248 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2249 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2250 case SRB_STATUS_DELAYED_RETRY:
2251 case SRB_STATUS_BAD_FUNCTION:
2252 case SRB_STATUS_NOT_STARTED:
2253 case SRB_STATUS_NOT_IN_USE:
2254 case SRB_STATUS_FORCE_ABORT:
2255 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2257 #ifdef AAC_DETAILED_STATUS_INFO
2258 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2259 le32_to_cpu(srbreply->srb_status) & 0x3F,
2260 aac_get_status_string(
2261 le32_to_cpu(srbreply->srb_status) & 0x3F),
2263 le32_to_cpu(srbreply->scsi_status));
2265 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2268 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2270 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2271 len = (le32_to_cpu(srbreply->sense_data_size) >
2272 sizeof(scsicmd->sense_buffer)) ?
2273 sizeof(scsicmd->sense_buffer) :
2274 le32_to_cpu(srbreply->sense_data_size);
2275 #ifdef AAC_DETAILED_STATUS_INFO
2276 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2277 le32_to_cpu(srbreply->status), len);
2279 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2283 * OR in the scsi status (already shifted up a bit)
2285 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2287 aac_fib_complete(fibptr);
2288 aac_fib_free(fibptr);
2289 scsicmd->scsi_done(scsicmd);
2295 * @scsicmd: the scsi command block
2297 * This routine will form a FIB and fill in the aac_srb from the
2298 * scsicmd passed in.
2301 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2303 struct fib* cmd_fibcontext;
2304 struct aac_dev* dev;
2307 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2308 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2309 scsicmd->device->lun > 7) {
2310 scsicmd->result = DID_NO_CONNECT << 16;
2311 scsicmd->scsi_done(scsicmd);
2316 * Allocate and initialize a Fib then setup a BlockWrite command
2318 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2321 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2324 * Check that the command queued to the controller
2326 if (status == -EINPROGRESS) {
2327 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2331 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2332 aac_fib_complete(cmd_fibcontext);
2333 aac_fib_free(cmd_fibcontext);
2338 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2340 struct aac_dev *dev;
2341 unsigned long byte_count = 0;
2343 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2344 // Get rid of old data
2346 psg->sg[0].addr = 0;
2347 psg->sg[0].count = 0;
2348 if (scsicmd->use_sg) {
2349 struct scatterlist *sg;
2352 sg = (struct scatterlist *) scsicmd->request_buffer;
2354 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2355 scsicmd->sc_data_direction);
2356 psg->count = cpu_to_le32(sg_count);
2358 for (i = 0; i < sg_count; i++) {
2359 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2360 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2361 byte_count += sg_dma_len(sg);
2364 /* hba wants the size to be exact */
2365 if(byte_count > scsicmd->request_bufflen){
2366 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2367 (byte_count - scsicmd->request_bufflen);
2368 psg->sg[i-1].count = cpu_to_le32(temp);
2369 byte_count = scsicmd->request_bufflen;
2371 /* Check for command underflow */
2372 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2373 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2374 byte_count, scsicmd->underflow);
2377 else if(scsicmd->request_bufflen) {
2379 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2380 scsicmd->request_buffer,
2381 scsicmd->request_bufflen,
2382 scsicmd->sc_data_direction);
2383 addr = scsicmd->SCp.dma_handle;
2384 psg->count = cpu_to_le32(1);
2385 psg->sg[0].addr = cpu_to_le32(addr);
2386 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2387 byte_count = scsicmd->request_bufflen;
2393 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2395 struct aac_dev *dev;
2396 unsigned long byte_count = 0;
2399 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2400 // Get rid of old data
2402 psg->sg[0].addr[0] = 0;
2403 psg->sg[0].addr[1] = 0;
2404 psg->sg[0].count = 0;
2405 if (scsicmd->use_sg) {
2406 struct scatterlist *sg;
2409 sg = (struct scatterlist *) scsicmd->request_buffer;
2411 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2412 scsicmd->sc_data_direction);
2414 for (i = 0; i < sg_count; i++) {
2415 int count = sg_dma_len(sg);
2416 addr = sg_dma_address(sg);
2417 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2418 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2419 psg->sg[i].count = cpu_to_le32(count);
2420 byte_count += count;
2423 psg->count = cpu_to_le32(sg_count);
2424 /* hba wants the size to be exact */
2425 if(byte_count > scsicmd->request_bufflen){
2426 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2427 (byte_count - scsicmd->request_bufflen);
2428 psg->sg[i-1].count = cpu_to_le32(temp);
2429 byte_count = scsicmd->request_bufflen;
2431 /* Check for command underflow */
2432 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2433 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2434 byte_count, scsicmd->underflow);
2437 else if(scsicmd->request_bufflen) {
2438 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2439 scsicmd->request_buffer,
2440 scsicmd->request_bufflen,
2441 scsicmd->sc_data_direction);
2442 addr = scsicmd->SCp.dma_handle;
2443 psg->count = cpu_to_le32(1);
2444 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2445 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2446 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2447 byte_count = scsicmd->request_bufflen;
2452 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2454 struct Scsi_Host *host = scsicmd->device->host;
2455 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2456 unsigned long byte_count = 0;
2458 // Get rid of old data
2460 psg->sg[0].next = 0;
2461 psg->sg[0].prev = 0;
2462 psg->sg[0].addr[0] = 0;
2463 psg->sg[0].addr[1] = 0;
2464 psg->sg[0].count = 0;
2465 psg->sg[0].flags = 0;
2466 if (scsicmd->use_sg) {
2467 struct scatterlist *sg;
2470 sg = (struct scatterlist *) scsicmd->request_buffer;
2472 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2473 scsicmd->sc_data_direction);
2475 for (i = 0; i < sg_count; i++) {
2476 int count = sg_dma_len(sg);
2477 u64 addr = sg_dma_address(sg);
2478 psg->sg[i].next = 0;
2479 psg->sg[i].prev = 0;
2480 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2481 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2482 psg->sg[i].count = cpu_to_le32(count);
2483 psg->sg[i].flags = 0;
2484 byte_count += count;
2487 psg->count = cpu_to_le32(sg_count);
2488 /* hba wants the size to be exact */
2489 if(byte_count > scsicmd->request_bufflen){
2490 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2491 (byte_count - scsicmd->request_bufflen);
2492 psg->sg[i-1].count = cpu_to_le32(temp);
2493 byte_count = scsicmd->request_bufflen;
2495 /* Check for command underflow */
2496 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2497 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2498 byte_count, scsicmd->underflow);
2501 else if(scsicmd->request_bufflen) {
2504 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2505 scsicmd->request_buffer,
2506 scsicmd->request_bufflen,
2507 scsicmd->sc_data_direction);
2508 addr = scsicmd->SCp.dma_handle;
2509 count = scsicmd->request_bufflen;
2510 psg->count = cpu_to_le32(1);
2511 psg->sg[0].next = 0;
2512 psg->sg[0].prev = 0;
2513 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2514 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2515 psg->sg[0].count = cpu_to_le32(count);
2516 psg->sg[0].flags = 0;
2517 byte_count = scsicmd->request_bufflen;
2522 #ifdef AAC_DETAILED_STATUS_INFO
2524 struct aac_srb_status_info {
2530 static struct aac_srb_status_info srb_status_info[] = {
2531 { SRB_STATUS_PENDING, "Pending Status"},
2532 { SRB_STATUS_SUCCESS, "Success"},
2533 { SRB_STATUS_ABORTED, "Aborted Command"},
2534 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2535 { SRB_STATUS_ERROR, "Error Event"},
2536 { SRB_STATUS_BUSY, "Device Busy"},
2537 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2538 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2539 { SRB_STATUS_NO_DEVICE, "No Device"},
2540 { SRB_STATUS_TIMEOUT, "Timeout"},
2541 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2542 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2543 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2544 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2545 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2546 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2547 { SRB_STATUS_NO_HBA, "No HBA"},
2548 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2549 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2550 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2551 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2552 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2553 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2554 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2555 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2556 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2557 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2558 { SRB_STATUS_NOT_STARTED, "Not Started"},
2559 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2560 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2561 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2562 { 0xff, "Unknown Error"}
2565 char *aac_get_status_string(u32 status)
2569 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2570 if (srb_status_info[i].status == status)
2571 return srb_status_info[i].str;
2573 return "Bad Status Code";