2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000 Adaptec, Inc. (aacraid@adaptec.com)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/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");
176 * aac_get_config_status - check the adapter configuration
177 * @common: adapter to query
179 * Query config status, and commit the configuration if needed.
181 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
186 if (!(fibptr = aac_fib_alloc(dev)))
189 aac_fib_init(fibptr);
191 struct aac_get_config_status *dinfo;
192 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
194 dinfo->command = cpu_to_le32(VM_ContainerConfig);
195 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
196 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
199 status = aac_fib_send(ContainerCommand,
201 sizeof (struct aac_get_config_status),
206 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
208 struct aac_get_config_status_resp *reply
209 = (struct aac_get_config_status_resp *) fib_data(fibptr);
210 dprintk((KERN_WARNING
211 "aac_get_config_status: response=%d status=%d action=%d\n",
212 le32_to_cpu(reply->response),
213 le32_to_cpu(reply->status),
214 le32_to_cpu(reply->data.action)));
215 if ((le32_to_cpu(reply->response) != ST_OK) ||
216 (le32_to_cpu(reply->status) != CT_OK) ||
217 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
218 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
222 aac_fib_complete(fibptr);
223 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
225 if ((commit == 1) || commit_flag) {
226 struct aac_commit_config * dinfo;
227 aac_fib_init(fibptr);
228 dinfo = (struct aac_commit_config *) fib_data(fibptr);
230 dinfo->command = cpu_to_le32(VM_ContainerConfig);
231 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
233 status = aac_fib_send(ContainerCommand,
235 sizeof (struct aac_commit_config),
239 aac_fib_complete(fibptr);
240 } else if (commit == 0) {
242 "aac_get_config_status: Foreign device configurations are being ignored\n");
245 aac_fib_free(fibptr);
250 * aac_get_containers - list containers
251 * @common: adapter to probe
253 * Make a list of all containers on this controller
255 int aac_get_containers(struct aac_dev *dev)
257 struct fsa_dev_info *fsa_dev_ptr;
261 struct aac_get_container_count *dinfo;
262 struct aac_get_container_count_resp *dresp;
263 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
265 if (!(fibptr = aac_fib_alloc(dev)))
268 aac_fib_init(fibptr);
269 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
270 dinfo->command = cpu_to_le32(VM_ContainerConfig);
271 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
273 status = aac_fib_send(ContainerCommand,
275 sizeof (struct aac_get_container_count),
280 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
281 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
282 aac_fib_complete(fibptr);
284 aac_fib_free(fibptr);
286 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
287 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
288 fsa_dev_ptr = kmalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
292 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
294 dev->fsa_dev = fsa_dev_ptr;
295 dev->maximum_num_containers = maximum_num_containers;
297 for (index = 0; index < dev->maximum_num_containers; ) {
298 fsa_dev_ptr[index].devname[0] = '\0';
300 status = aac_probe_container(dev, index);
303 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
308 * If there are no more containers, then stop asking.
310 if (++index >= status)
316 static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
319 unsigned int transfer_len;
320 struct scatterlist *sg = scsicmd->request_buffer;
322 if (scsicmd->use_sg) {
323 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
324 transfer_len = min(sg->length, len + offset);
326 buf = scsicmd->request_buffer;
327 transfer_len = min(scsicmd->request_bufflen, len + offset);
330 memcpy(buf + offset, data, transfer_len - offset);
333 kunmap_atomic(buf - sg->offset, KM_IRQ0);
337 static void get_container_name_callback(void *context, struct fib * fibptr)
339 struct aac_get_name_resp * get_name_reply;
340 struct scsi_cmnd * scsicmd;
342 scsicmd = (struct scsi_cmnd *) context;
343 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
345 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
346 BUG_ON(fibptr == NULL);
348 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
349 /* Failure is irrelevant, using default value instead */
350 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
351 && (get_name_reply->data[0] != '\0')) {
352 char *sp = get_name_reply->data;
353 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
357 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
358 int count = sizeof(d);
361 *dp++ = (*sp) ? *sp++ : ' ';
362 } while (--count > 0);
363 aac_internal_transfer(scsicmd, d,
364 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
368 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
370 aac_fib_complete(fibptr);
371 aac_fib_free(fibptr);
372 scsicmd->scsi_done(scsicmd);
376 * aac_get_container_name - get container name, none blocking.
378 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
381 struct aac_get_name *dinfo;
382 struct fib * cmd_fibcontext;
383 struct aac_dev * dev;
385 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
387 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
390 aac_fib_init(cmd_fibcontext);
391 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
393 dinfo->command = cpu_to_le32(VM_ContainerConfig);
394 dinfo->type = cpu_to_le32(CT_READ_NAME);
395 dinfo->cid = cpu_to_le32(cid);
396 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
398 status = aac_fib_send(ContainerCommand,
400 sizeof (struct aac_get_name),
403 (fib_callback) get_container_name_callback,
407 * Check that the command queued to the controller
409 if (status == -EINPROGRESS) {
410 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
414 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
415 aac_fib_complete(cmd_fibcontext);
416 aac_fib_free(cmd_fibcontext);
420 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
422 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
424 if (fsa_dev_ptr[scmd_id(scsicmd)].valid)
425 return aac_scsi_cmd(scsicmd);
427 scsicmd->result = DID_NO_CONNECT << 16;
428 scsicmd->scsi_done(scsicmd);
432 static int _aac_probe_container2(void * context, struct fib * fibptr)
434 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
435 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
436 int (*callback)(struct scsi_cmnd *);
438 scsicmd->SCp.Status = 0;
440 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
441 fsa_dev_ptr += scmd_id(scsicmd);
443 if ((le32_to_cpu(dresp->status) == ST_OK) &&
444 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
445 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
446 fsa_dev_ptr->valid = 1;
447 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
449 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
450 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
451 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
453 if ((fsa_dev_ptr->valid & 1) == 0)
454 fsa_dev_ptr->valid = 0;
455 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
457 aac_fib_complete(fibptr);
458 aac_fib_free(fibptr);
459 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
460 scsicmd->SCp.ptr = NULL;
461 return (*callback)(scsicmd);
464 static int _aac_probe_container1(void * context, struct fib * fibptr)
466 struct scsi_cmnd * scsicmd;
467 struct aac_mount * dresp;
468 struct aac_query_mount *dinfo;
471 dresp = (struct aac_mount *) fib_data(fibptr);
472 dresp->mnt[0].capacityhigh = 0;
473 if ((le32_to_cpu(dresp->status) != ST_OK) ||
474 ((le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
475 (le32_to_cpu(dresp->mnt[0].state) == FSCS_HIDDEN)))
476 return _aac_probe_container2(context, fibptr);
477 scsicmd = (struct scsi_cmnd *) context;
478 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
480 aac_fib_init(fibptr);
482 dinfo = (struct aac_query_mount *)fib_data(fibptr);
484 dinfo->command = cpu_to_le32(VM_NameServe64);
485 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
486 dinfo->type = cpu_to_le32(FT_FILESYS);
488 status = aac_fib_send(ContainerCommand,
490 sizeof(struct aac_query_mount),
493 (fib_callback) _aac_probe_container2,
496 * Check that the command queued to the controller
498 if (status == -EINPROGRESS) {
499 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
503 /* Inherit results from VM_NameServe, if any */
504 dresp->status = cpu_to_le32(ST_OK);
505 return _aac_probe_container2(context, fibptr);
510 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
513 int status = -ENOMEM;
515 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
516 struct aac_query_mount *dinfo;
518 aac_fib_init(fibptr);
520 dinfo = (struct aac_query_mount *)fib_data(fibptr);
522 dinfo->command = cpu_to_le32(VM_NameServe);
523 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
524 dinfo->type = cpu_to_le32(FT_FILESYS);
525 scsicmd->SCp.ptr = (char *)callback;
527 status = aac_fib_send(ContainerCommand,
529 sizeof(struct aac_query_mount),
532 (fib_callback) _aac_probe_container1,
535 * Check that the command queued to the controller
537 if (status == -EINPROGRESS) {
538 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
542 scsicmd->SCp.ptr = NULL;
543 aac_fib_complete(fibptr);
544 aac_fib_free(fibptr);
548 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
550 fsa_dev_ptr += scmd_id(scsicmd);
551 if ((fsa_dev_ptr->valid & 1) == 0) {
552 fsa_dev_ptr->valid = 0;
553 return (*callback)(scsicmd);
561 * aac_probe_container - query a logical volume
562 * @dev: device to query
563 * @cid: container identifier
565 * Queries the controller about the given volume. The volume information
566 * is updated in the struct fsa_dev_info structure rather than returned.
568 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
570 scsicmd->device = NULL;
574 int aac_probe_container(struct aac_dev *dev, int cid)
576 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
577 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
580 if (!scsicmd || !scsidev) {
585 scsicmd->list.next = NULL;
586 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))_aac_probe_container1;
588 scsicmd->device = scsidev;
589 scsidev->sdev_state = 0;
591 scsidev->host = dev->scsi_host_ptr;
593 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
594 while (scsicmd->device == scsidev)
596 status = scsicmd->SCp.Status;
602 /* Local Structure to set SCSI inquiry data strings */
604 char vid[8]; /* Vendor ID */
605 char pid[16]; /* Product ID */
606 char prl[4]; /* Product Revision Level */
610 * InqStrCopy - string merge
611 * @a: string to copy from
612 * @b: string to copy to
614 * Copy a String from one location to another
618 static void inqstrcpy(char *a, char *b)
625 static char *container_types[] = {
651 /* Function: setinqstr
653 * Arguments: [1] pointer to void [1] int
655 * Purpose: Sets SCSI inquiry data strings for vendor, product
656 * and revision level. Allows strings to be set in platform dependant
657 * files instead of in OS dependant driver source.
660 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
662 struct scsi_inq *str;
664 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
665 memset(str, ' ', sizeof(*str));
667 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
668 char * cp = dev->supplement_adapter_info.AdapterTypeText;
669 int c = sizeof(str->vid);
670 while (*cp && *cp != ' ' && --c)
674 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
677 while (*cp && *cp != ' ')
681 /* last six chars reserved for vol type */
683 if (strlen(cp) > sizeof(str->pid)) {
684 c = cp[sizeof(str->pid)];
685 cp[sizeof(str->pid)] = '\0';
687 inqstrcpy (cp, str->pid);
689 cp[sizeof(str->pid)] = c;
691 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
693 inqstrcpy (mp->vname, str->vid);
694 /* last six chars reserved for vol type */
695 inqstrcpy (mp->model, str->pid);
698 if (tindex < ARRAY_SIZE(container_types)){
699 char *findit = str->pid;
701 for ( ; *findit != ' '; findit++); /* walk till we find a space */
702 /* RAID is superfluous in the context of a RAID device */
703 if (memcmp(findit-4, "RAID", 4) == 0)
704 *(findit -= 4) = ' ';
705 if (((findit - str->pid) + strlen(container_types[tindex]))
706 < (sizeof(str->pid) + sizeof(str->prl)))
707 inqstrcpy (container_types[tindex], findit + 1);
709 inqstrcpy ("V1.0", str->prl);
712 static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
713 u8 a_sense_code, u8 incorrect_length,
714 u8 bit_pointer, u16 field_pointer,
717 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
718 sense_buf[1] = 0; /* Segment number, always zero */
720 if (incorrect_length) {
721 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
722 sense_buf[3] = BYTE3(residue);
723 sense_buf[4] = BYTE2(residue);
724 sense_buf[5] = BYTE1(residue);
725 sense_buf[6] = BYTE0(residue);
727 sense_buf[2] = sense_key; /* Sense key */
729 if (sense_key == ILLEGAL_REQUEST)
730 sense_buf[7] = 10; /* Additional sense length */
732 sense_buf[7] = 6; /* Additional sense length */
734 sense_buf[12] = sense_code; /* Additional sense code */
735 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
736 if (sense_key == ILLEGAL_REQUEST) {
739 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
740 sense_buf[15] = 0x80;/* Std sense key specific field */
741 /* Illegal parameter is in the parameter block */
743 if (sense_code == SENCODE_INVALID_CDB_FIELD)
744 sense_buf[15] = 0xc0;/* Std sense key specific field */
745 /* Illegal parameter is in the CDB block */
746 sense_buf[15] |= bit_pointer;
747 sense_buf[16] = field_pointer >> 8; /* MSB */
748 sense_buf[17] = field_pointer; /* LSB */
752 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
754 if (lba & 0xffffffff00000000LL) {
755 int cid = scmd_id(cmd);
756 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
757 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
758 SAM_STAT_CHECK_CONDITION;
759 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
761 SENCODE_INTERNAL_TARGET_FAILURE,
762 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
764 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
765 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
766 ? sizeof(cmd->sense_buffer)
767 : sizeof(dev->fsa_dev[cid].sense_data));
774 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
779 static void io_callback(void *context, struct fib * fibptr);
781 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
784 struct aac_raw_io *readcmd;
786 readcmd = (struct aac_raw_io *) fib_data(fib);
787 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
788 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
789 readcmd->count = cpu_to_le32(count<<9);
790 readcmd->cid = cpu_to_le16(scmd_id(cmd));
791 readcmd->flags = cpu_to_le16(1);
792 readcmd->bpTotal = 0;
793 readcmd->bpComplete = 0;
795 aac_build_sgraw(cmd, &readcmd->sg);
796 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
797 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
799 * Now send the Fib to the adapter
801 return aac_fib_send(ContainerRawIo,
806 (fib_callback) io_callback,
810 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
813 struct aac_read64 *readcmd;
815 readcmd = (struct aac_read64 *) fib_data(fib);
816 readcmd->command = cpu_to_le32(VM_CtHostRead64);
817 readcmd->cid = cpu_to_le16(scmd_id(cmd));
818 readcmd->sector_count = cpu_to_le16(count);
819 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
823 aac_build_sg64(cmd, &readcmd->sg);
824 fibsize = sizeof(struct aac_read64) +
825 ((le32_to_cpu(readcmd->sg.count) - 1) *
826 sizeof (struct sgentry64));
827 BUG_ON (fibsize > (fib->dev->max_fib_size -
828 sizeof(struct aac_fibhdr)));
830 * Now send the Fib to the adapter
832 return aac_fib_send(ContainerCommand64,
837 (fib_callback) io_callback,
841 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
844 struct aac_read *readcmd;
846 readcmd = (struct aac_read *) fib_data(fib);
847 readcmd->command = cpu_to_le32(VM_CtBlockRead);
848 readcmd->cid = cpu_to_le16(scmd_id(cmd));
849 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
850 readcmd->count = cpu_to_le32(count * 512);
852 aac_build_sg(cmd, &readcmd->sg);
853 fibsize = sizeof(struct aac_read) +
854 ((le32_to_cpu(readcmd->sg.count) - 1) *
855 sizeof (struct sgentry));
856 BUG_ON (fibsize > (fib->dev->max_fib_size -
857 sizeof(struct aac_fibhdr)));
859 * Now send the Fib to the adapter
861 return aac_fib_send(ContainerCommand,
866 (fib_callback) io_callback,
870 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
873 struct aac_raw_io *writecmd;
875 writecmd = (struct aac_raw_io *) fib_data(fib);
876 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
877 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
878 writecmd->count = cpu_to_le32(count<<9);
879 writecmd->cid = cpu_to_le16(scmd_id(cmd));
881 writecmd->bpTotal = 0;
882 writecmd->bpComplete = 0;
884 aac_build_sgraw(cmd, &writecmd->sg);
885 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
886 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
888 * Now send the Fib to the adapter
890 return aac_fib_send(ContainerRawIo,
895 (fib_callback) io_callback,
899 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
902 struct aac_write64 *writecmd;
904 writecmd = (struct aac_write64 *) fib_data(fib);
905 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
906 writecmd->cid = cpu_to_le16(scmd_id(cmd));
907 writecmd->sector_count = cpu_to_le16(count);
908 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
912 aac_build_sg64(cmd, &writecmd->sg);
913 fibsize = sizeof(struct aac_write64) +
914 ((le32_to_cpu(writecmd->sg.count) - 1) *
915 sizeof (struct sgentry64));
916 BUG_ON (fibsize > (fib->dev->max_fib_size -
917 sizeof(struct aac_fibhdr)));
919 * Now send the Fib to the adapter
921 return aac_fib_send(ContainerCommand64,
926 (fib_callback) io_callback,
930 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
933 struct aac_write *writecmd;
935 writecmd = (struct aac_write *) fib_data(fib);
936 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
937 writecmd->cid = cpu_to_le16(scmd_id(cmd));
938 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
939 writecmd->count = cpu_to_le32(count * 512);
940 writecmd->sg.count = cpu_to_le32(1);
941 /* ->stable is not used - it did mean which type of write */
943 aac_build_sg(cmd, &writecmd->sg);
944 fibsize = sizeof(struct aac_write) +
945 ((le32_to_cpu(writecmd->sg.count) - 1) *
946 sizeof (struct sgentry));
947 BUG_ON (fibsize > (fib->dev->max_fib_size -
948 sizeof(struct aac_fibhdr)));
950 * Now send the Fib to the adapter
952 return aac_fib_send(ContainerCommand,
957 (fib_callback) io_callback,
961 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
963 struct aac_srb * srbcmd;
968 switch(cmd->sc_data_direction){
972 case DMA_BIDIRECTIONAL:
973 flag = SRB_DataIn | SRB_DataOut;
975 case DMA_FROM_DEVICE:
979 default: /* shuts up some versions of gcc */
980 flag = SRB_NoDataXfer;
984 srbcmd = (struct aac_srb*) fib_data(fib);
985 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
986 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
987 srbcmd->id = cpu_to_le32(scmd_id(cmd));
988 srbcmd->lun = cpu_to_le32(cmd->device->lun);
989 srbcmd->flags = cpu_to_le32(flag);
990 timeout = cmd->timeout_per_command/HZ;
993 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
994 srbcmd->retry_limit = 0; /* Obsolete parameter */
995 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
999 static void aac_srb_callback(void *context, struct fib * fibptr);
1001 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1004 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1006 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1007 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
1009 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1010 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1012 * Build Scatter/Gather list
1014 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1015 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1016 sizeof (struct sgentry64));
1017 BUG_ON (fibsize > (fib->dev->max_fib_size -
1018 sizeof(struct aac_fibhdr)));
1021 * Now send the Fib to the adapter
1023 return aac_fib_send(ScsiPortCommand64, fib,
1024 fibsize, FsaNormal, 0, 1,
1025 (fib_callback) aac_srb_callback,
1029 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1032 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1034 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1035 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
1037 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1038 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1040 * Build Scatter/Gather list
1042 fibsize = sizeof (struct aac_srb) +
1043 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1044 sizeof (struct sgentry));
1045 BUG_ON (fibsize > (fib->dev->max_fib_size -
1046 sizeof(struct aac_fibhdr)));
1049 * Now send the Fib to the adapter
1051 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1052 (fib_callback) aac_srb_callback, (void *) cmd);
1055 int aac_get_adapter_info(struct aac_dev* dev)
1060 struct aac_adapter_info *info;
1061 struct aac_bus_info *command;
1062 struct aac_bus_info_response *bus_info;
1064 if (!(fibptr = aac_fib_alloc(dev)))
1067 aac_fib_init(fibptr);
1068 info = (struct aac_adapter_info *) fib_data(fibptr);
1069 memset(info,0,sizeof(*info));
1071 rcode = aac_fib_send(RequestAdapterInfo,
1075 -1, 1, /* First `interrupt' command uses special wait */
1080 aac_fib_complete(fibptr);
1081 aac_fib_free(fibptr);
1084 memcpy(&dev->adapter_info, info, sizeof(*info));
1086 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1087 struct aac_supplement_adapter_info * info;
1089 aac_fib_init(fibptr);
1091 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1093 memset(info,0,sizeof(*info));
1095 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1104 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
1112 aac_fib_init(fibptr);
1114 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1116 memset(bus_info, 0, sizeof(*bus_info));
1118 command = (struct aac_bus_info *)bus_info;
1120 command->Command = cpu_to_le32(VM_Ioctl);
1121 command->ObjType = cpu_to_le32(FT_DRIVE);
1122 command->MethodId = cpu_to_le32(1);
1123 command->CtlCmd = cpu_to_le32(GetBusInfo);
1125 rcode = aac_fib_send(ContainerCommand,
1132 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1133 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1134 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1137 if (!dev->in_reset) {
1138 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1139 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1145 le32_to_cpu(dev->adapter_info.kernelbuild),
1146 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1147 dev->supplement_adapter_info.BuildDate);
1148 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1149 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1151 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1152 le32_to_cpu(dev->adapter_info.monitorbuild));
1153 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1154 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1156 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1157 le32_to_cpu(dev->adapter_info.biosbuild));
1158 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
1159 printk(KERN_INFO "%s%d: serial %x\n",
1161 le32_to_cpu(dev->adapter_info.serial[0]));
1164 dev->nondasd_support = 0;
1165 dev->raid_scsi_mode = 0;
1166 if(dev->adapter_info.options & AAC_OPT_NONDASD){
1167 dev->nondasd_support = 1;
1171 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1172 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1173 * force nondasd support on. If we decide to allow the non-dasd flag
1174 * additional changes changes will have to be made to support
1175 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1176 * changed to support the new dev->raid_scsi_mode flag instead of
1177 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1178 * function aac_detect will have to be modified where it sets up the
1179 * max number of channels based on the aac->nondasd_support flag only.
1181 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1182 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1183 dev->nondasd_support = 1;
1184 dev->raid_scsi_mode = 1;
1186 if (dev->raid_scsi_mode != 0)
1187 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1188 dev->name, dev->id);
1191 dev->nondasd_support = (nondasd!=0);
1193 if(dev->nondasd_support != 0){
1194 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1197 dev->dac_support = 0;
1198 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1199 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1200 dev->dac_support = 1;
1204 dev->dac_support = (dacmode!=0);
1206 if(dev->dac_support != 0) {
1207 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1208 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
1209 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1210 dev->name, dev->id);
1211 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1212 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
1213 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1214 dev->name, dev->id);
1215 dev->dac_support = 0;
1217 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1218 dev->name, dev->id);
1223 * Deal with configuring for the individualized limits of each packet
1226 dev->a_ops.adapter_scsi = (dev->dac_support)
1229 if (dev->raw_io_interface) {
1230 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1233 dev->a_ops.adapter_read = aac_read_raw_io;
1234 dev->a_ops.adapter_write = aac_write_raw_io;
1236 dev->a_ops.adapter_bounds = aac_bounds_32;
1237 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1238 sizeof(struct aac_fibhdr) -
1239 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1240 sizeof(struct sgentry);
1241 if (dev->dac_support) {
1242 dev->a_ops.adapter_read = aac_read_block64;
1243 dev->a_ops.adapter_write = aac_write_block64;
1245 * 38 scatter gather elements
1247 dev->scsi_host_ptr->sg_tablesize =
1248 (dev->max_fib_size -
1249 sizeof(struct aac_fibhdr) -
1250 sizeof(struct aac_write64) +
1251 sizeof(struct sgentry64)) /
1252 sizeof(struct sgentry64);
1254 dev->a_ops.adapter_read = aac_read_block;
1255 dev->a_ops.adapter_write = aac_write_block;
1257 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1258 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1260 * Worst case size that could cause sg overflow when
1261 * we break up SG elements that are larger than 64KB.
1262 * Would be nice if we could tell the SCSI layer what
1263 * the maximum SG element size can be. Worst case is
1264 * (sg_tablesize-1) 4KB elements with one 64KB
1266 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1268 dev->scsi_host_ptr->max_sectors =
1269 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1273 aac_fib_complete(fibptr);
1274 aac_fib_free(fibptr);
1280 static void io_callback(void *context, struct fib * fibptr)
1282 struct aac_dev *dev;
1283 struct aac_read_reply *readreply;
1284 struct scsi_cmnd *scsicmd;
1287 scsicmd = (struct scsi_cmnd *) context;
1288 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1290 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1291 cid = scmd_id(scsicmd);
1293 if (nblank(dprintk(x))) {
1295 switch (scsicmd->cmnd[0]) {
1298 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1299 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1303 lba = ((u64)scsicmd->cmnd[2] << 56) |
1304 ((u64)scsicmd->cmnd[3] << 48) |
1305 ((u64)scsicmd->cmnd[4] << 40) |
1306 ((u64)scsicmd->cmnd[5] << 32) |
1307 ((u64)scsicmd->cmnd[6] << 24) |
1308 (scsicmd->cmnd[7] << 16) |
1309 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1313 lba = ((u64)scsicmd->cmnd[2] << 24) |
1314 (scsicmd->cmnd[3] << 16) |
1315 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1318 lba = ((u64)scsicmd->cmnd[2] << 24) |
1319 (scsicmd->cmnd[3] << 16) |
1320 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1324 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1325 smp_processor_id(), (unsigned long long)lba, jiffies);
1328 BUG_ON(fibptr == NULL);
1331 pci_unmap_sg(dev->pdev,
1332 (struct scatterlist *)scsicmd->request_buffer,
1334 scsicmd->sc_data_direction);
1335 else if(scsicmd->request_bufflen)
1336 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
1337 scsicmd->request_bufflen,
1338 scsicmd->sc_data_direction);
1339 readreply = (struct aac_read_reply *)fib_data(fibptr);
1340 if (le32_to_cpu(readreply->status) == ST_OK)
1341 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1343 #ifdef AAC_DETAILED_STATUS_INFO
1344 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1345 le32_to_cpu(readreply->status));
1347 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1348 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1350 SENCODE_INTERNAL_TARGET_FAILURE,
1351 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1353 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1354 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1355 ? sizeof(scsicmd->sense_buffer)
1356 : sizeof(dev->fsa_dev[cid].sense_data));
1358 aac_fib_complete(fibptr);
1359 aac_fib_free(fibptr);
1361 scsicmd->scsi_done(scsicmd);
1364 static int aac_read(struct scsi_cmnd * scsicmd, int cid)
1369 struct aac_dev *dev;
1370 struct fib * cmd_fibcontext;
1372 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1374 * Get block address and transfer length
1376 switch (scsicmd->cmnd[0]) {
1378 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
1380 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1381 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1382 count = scsicmd->cmnd[4];
1388 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", cid));
1390 lba = ((u64)scsicmd->cmnd[2] << 56) |
1391 ((u64)scsicmd->cmnd[3] << 48) |
1392 ((u64)scsicmd->cmnd[4] << 40) |
1393 ((u64)scsicmd->cmnd[5] << 32) |
1394 ((u64)scsicmd->cmnd[6] << 24) |
1395 (scsicmd->cmnd[7] << 16) |
1396 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1397 count = (scsicmd->cmnd[10] << 24) |
1398 (scsicmd->cmnd[11] << 16) |
1399 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1402 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", cid));
1404 lba = ((u64)scsicmd->cmnd[2] << 24) |
1405 (scsicmd->cmnd[3] << 16) |
1406 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1407 count = (scsicmd->cmnd[6] << 24) |
1408 (scsicmd->cmnd[7] << 16) |
1409 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1412 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
1414 lba = ((u64)scsicmd->cmnd[2] << 24) |
1415 (scsicmd->cmnd[3] << 16) |
1416 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1417 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1420 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1421 smp_processor_id(), (unsigned long long)lba, jiffies));
1422 if (aac_adapter_bounds(dev,scsicmd,lba))
1425 * Alocate and initialize a Fib
1427 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1431 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1434 * Check that the command queued to the controller
1436 if (status == -EINPROGRESS) {
1437 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1441 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1443 * For some reason, the Fib didn't queue, return QUEUE_FULL
1445 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1446 scsicmd->scsi_done(scsicmd);
1447 aac_fib_complete(cmd_fibcontext);
1448 aac_fib_free(cmd_fibcontext);
1452 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1457 struct aac_dev *dev;
1458 struct fib * cmd_fibcontext;
1460 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1462 * Get block address and transfer length
1464 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1466 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1467 count = scsicmd->cmnd[4];
1470 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1471 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", cid));
1473 lba = ((u64)scsicmd->cmnd[2] << 56) |
1474 ((u64)scsicmd->cmnd[3] << 48) |
1475 ((u64)scsicmd->cmnd[4] << 40) |
1476 ((u64)scsicmd->cmnd[5] << 32) |
1477 ((u64)scsicmd->cmnd[6] << 24) |
1478 (scsicmd->cmnd[7] << 16) |
1479 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1480 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1481 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1482 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1483 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", cid));
1485 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1486 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1487 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1488 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1490 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
1491 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1492 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1494 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1495 smp_processor_id(), (unsigned long long)lba, jiffies));
1496 if (aac_adapter_bounds(dev,scsicmd,lba))
1499 * Allocate and initialize a Fib then setup a BlockWrite command
1501 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1502 scsicmd->result = DID_ERROR << 16;
1503 scsicmd->scsi_done(scsicmd);
1507 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count);
1510 * Check that the command queued to the controller
1512 if (status == -EINPROGRESS) {
1513 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1517 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1519 * For some reason, the Fib didn't queue, return QUEUE_FULL
1521 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1522 scsicmd->scsi_done(scsicmd);
1524 aac_fib_complete(cmd_fibcontext);
1525 aac_fib_free(cmd_fibcontext);
1529 static void synchronize_callback(void *context, struct fib *fibptr)
1531 struct aac_synchronize_reply *synchronizereply;
1532 struct scsi_cmnd *cmd;
1535 cmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1537 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1538 smp_processor_id(), jiffies));
1539 BUG_ON(fibptr == NULL);
1542 synchronizereply = fib_data(fibptr);
1543 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1544 cmd->result = DID_OK << 16 |
1545 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1547 struct scsi_device *sdev = cmd->device;
1548 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1549 u32 cid = sdev_id(sdev);
1551 "synchronize_callback: synchronize failed, status = %d\n",
1552 le32_to_cpu(synchronizereply->status));
1553 cmd->result = DID_OK << 16 |
1554 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1555 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1557 SENCODE_INTERNAL_TARGET_FAILURE,
1558 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1560 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1561 min(sizeof(dev->fsa_dev[cid].sense_data),
1562 sizeof(cmd->sense_buffer)));
1565 aac_fib_complete(fibptr);
1566 aac_fib_free(fibptr);
1567 cmd->scsi_done(cmd);
1570 static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1573 struct fib *cmd_fibcontext;
1574 struct aac_synchronize *synchronizecmd;
1575 struct scsi_cmnd *cmd;
1576 struct scsi_device *sdev = scsicmd->device;
1578 struct aac_dev *aac;
1579 unsigned long flags;
1582 * Wait for all outstanding queued commands to complete to this
1583 * specific target (block).
1585 spin_lock_irqsave(&sdev->list_lock, flags);
1586 list_for_each_entry(cmd, &sdev->cmd_list, list)
1587 if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1592 spin_unlock_irqrestore(&sdev->list_lock, flags);
1595 * Yield the processor (requeue for later)
1598 return SCSI_MLQUEUE_DEVICE_BUSY;
1600 aac = (struct aac_dev *)scsicmd->device->host->hostdata;
1602 return SCSI_MLQUEUE_HOST_BUSY;
1605 * Allocate and initialize a Fib
1607 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1608 return SCSI_MLQUEUE_HOST_BUSY;
1610 aac_fib_init(cmd_fibcontext);
1612 synchronizecmd = fib_data(cmd_fibcontext);
1613 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1614 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
1615 synchronizecmd->cid = cpu_to_le32(cid);
1616 synchronizecmd->count =
1617 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1620 * Now send the Fib to the adapter
1622 status = aac_fib_send(ContainerCommand,
1624 sizeof(struct aac_synchronize),
1627 (fib_callback)synchronize_callback,
1631 * Check that the command queued to the controller
1633 if (status == -EINPROGRESS) {
1634 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1639 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1640 aac_fib_complete(cmd_fibcontext);
1641 aac_fib_free(cmd_fibcontext);
1642 return SCSI_MLQUEUE_HOST_BUSY;
1646 * aac_scsi_cmd() - Process SCSI command
1647 * @scsicmd: SCSI command block
1649 * Emulate a SCSI command and queue the required request for the
1653 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1656 struct Scsi_Host *host = scsicmd->device->host;
1657 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1658 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1660 if (fsa_dev_ptr == NULL)
1663 * If the bus, id or lun is out of range, return fail
1664 * Test does not apply to ID 16, the pseudo id for the controller
1667 if (scmd_id(scsicmd) != host->this_id) {
1668 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
1669 if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
1670 (scsicmd->device->lun != 0)) {
1671 scsicmd->result = DID_NO_CONNECT << 16;
1672 scsicmd->scsi_done(scsicmd);
1675 cid = scmd_id(scsicmd);
1678 * If the target container doesn't exist, it may have
1679 * been newly created
1681 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1682 switch (scsicmd->cmnd[0]) {
1683 case SERVICE_ACTION_IN:
1684 if (!(dev->raw_io_interface) ||
1685 !(dev->raw_io_64) ||
1686 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1690 case TEST_UNIT_READY:
1693 return _aac_probe_container(scsicmd,
1694 aac_probe_container_callback2);
1699 } else { /* check for physical non-dasd devices */
1700 if ((dev->nondasd_support == 1) || expose_physicals) {
1703 return aac_send_srb_fib(scsicmd);
1705 scsicmd->result = DID_NO_CONNECT << 16;
1706 scsicmd->scsi_done(scsicmd);
1712 * else Command for the controller itself
1714 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1715 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1717 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1718 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1719 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1721 SENCODE_INVALID_COMMAND,
1722 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1723 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1724 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1725 ? sizeof(scsicmd->sense_buffer)
1726 : sizeof(dev->fsa_dev[cid].sense_data));
1727 scsicmd->scsi_done(scsicmd);
1732 /* Handle commands here that don't really require going out to the adapter */
1733 switch (scsicmd->cmnd[0]) {
1736 struct inquiry_data inq_data;
1738 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
1739 memset(&inq_data, 0, sizeof (struct inquiry_data));
1741 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1742 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 */
1743 inq_data.inqd_len = 31;
1744 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1745 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1747 * Set the Vendor, Product, and Revision Level
1748 * see: <vendor>.c i.e. aac.c
1750 if (scmd_id(scsicmd) == host->this_id) {
1751 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
1752 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1753 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1754 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1755 scsicmd->scsi_done(scsicmd);
1760 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1761 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1762 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1763 return aac_get_container_name(scsicmd, cid);
1765 case SERVICE_ACTION_IN:
1766 if (!(dev->raw_io_interface) ||
1767 !(dev->raw_io_64) ||
1768 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1774 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1775 capacity = fsa_dev_ptr[cid].size - 1;
1776 cp[0] = (capacity >> 56) & 0xff;
1777 cp[1] = (capacity >> 48) & 0xff;
1778 cp[2] = (capacity >> 40) & 0xff;
1779 cp[3] = (capacity >> 32) & 0xff;
1780 cp[4] = (capacity >> 24) & 0xff;
1781 cp[5] = (capacity >> 16) & 0xff;
1782 cp[6] = (capacity >> 8) & 0xff;
1783 cp[7] = (capacity >> 0) & 0xff;
1789 aac_internal_transfer(scsicmd, cp, 0,
1790 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
1791 if (sizeof(cp) < scsicmd->cmnd[13]) {
1792 unsigned int len, offset = sizeof(cp);
1794 memset(cp, 0, offset);
1796 len = min_t(size_t, scsicmd->cmnd[13] - offset,
1798 aac_internal_transfer(scsicmd, cp, offset, len);
1799 } while ((offset += len) < scsicmd->cmnd[13]);
1802 /* Do not cache partition table for arrays */
1803 scsicmd->device->removable = 1;
1805 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1806 scsicmd->scsi_done(scsicmd);
1816 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1817 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
1818 capacity = fsa_dev_ptr[cid].size - 1;
1822 cp[0] = (capacity >> 24) & 0xff;
1823 cp[1] = (capacity >> 16) & 0xff;
1824 cp[2] = (capacity >> 8) & 0xff;
1825 cp[3] = (capacity >> 0) & 0xff;
1830 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1831 /* Do not cache partition table for arrays */
1832 scsicmd->device->removable = 1;
1834 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1835 scsicmd->scsi_done(scsicmd);
1844 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1845 mode_buf[0] = 3; /* Mode data length */
1846 mode_buf[1] = 0; /* Medium type - default */
1847 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1848 mode_buf[3] = 0; /* Block descriptor length */
1850 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1851 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1852 scsicmd->scsi_done(scsicmd);
1860 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1861 mode_buf[0] = 0; /* Mode data length (MSB) */
1862 mode_buf[1] = 6; /* Mode data length (LSB) */
1863 mode_buf[2] = 0; /* Medium type - default */
1864 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1865 mode_buf[4] = 0; /* reserved */
1866 mode_buf[5] = 0; /* reserved */
1867 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1868 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1869 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1871 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1872 scsicmd->scsi_done(scsicmd);
1877 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1878 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1879 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1880 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1881 scsicmd->scsi_done(scsicmd);
1884 case ALLOW_MEDIUM_REMOVAL:
1885 dprintk((KERN_DEBUG "LOCK command.\n"));
1886 if (scsicmd->cmnd[4])
1887 fsa_dev_ptr[cid].locked = 1;
1889 fsa_dev_ptr[cid].locked = 0;
1891 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1892 scsicmd->scsi_done(scsicmd);
1895 * These commands are all No-Ops
1897 case TEST_UNIT_READY:
1901 case REASSIGN_BLOCKS:
1904 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1905 scsicmd->scsi_done(scsicmd);
1909 switch (scsicmd->cmnd[0])
1918 * Hack to keep track of ordinal number of the device that
1919 * corresponds to a container. Needed to convert
1920 * containers to /dev/sd device names
1923 if (scsicmd->request->rq_disk)
1924 strlcpy(fsa_dev_ptr[cid].devname,
1925 scsicmd->request->rq_disk->disk_name,
1926 min(sizeof(fsa_dev_ptr[cid].devname),
1927 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1929 return aac_read(scsicmd, cid);
1937 return aac_write(scsicmd, cid);
1939 case SYNCHRONIZE_CACHE:
1940 /* Issue FIB to tell Firmware to flush it's cache */
1941 return aac_synchronize(scsicmd, cid);
1945 * Unhandled commands
1947 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
1948 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1949 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1950 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1951 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1952 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1953 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1954 ? sizeof(scsicmd->sense_buffer)
1955 : sizeof(dev->fsa_dev[cid].sense_data));
1956 scsicmd->scsi_done(scsicmd);
1961 static int query_disk(struct aac_dev *dev, void __user *arg)
1963 struct aac_query_disk qd;
1964 struct fsa_dev_info *fsa_dev_ptr;
1966 fsa_dev_ptr = dev->fsa_dev;
1969 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1973 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1975 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1977 qd.instance = dev->scsi_host_ptr->host_no;
1979 qd.id = CONTAINER_TO_ID(qd.cnum);
1980 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1982 else return -EINVAL;
1984 qd.valid = fsa_dev_ptr[qd.cnum].valid;
1985 qd.locked = fsa_dev_ptr[qd.cnum].locked;
1986 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1988 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1993 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1994 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1996 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2001 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2003 struct aac_delete_disk dd;
2004 struct fsa_dev_info *fsa_dev_ptr;
2006 fsa_dev_ptr = dev->fsa_dev;
2010 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2013 if (dd.cnum >= dev->maximum_num_containers)
2016 * Mark this container as being deleted.
2018 fsa_dev_ptr[dd.cnum].deleted = 1;
2020 * Mark the container as no longer valid
2022 fsa_dev_ptr[dd.cnum].valid = 0;
2026 static int delete_disk(struct aac_dev *dev, void __user *arg)
2028 struct aac_delete_disk dd;
2029 struct fsa_dev_info *fsa_dev_ptr;
2031 fsa_dev_ptr = dev->fsa_dev;
2035 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2038 if (dd.cnum >= dev->maximum_num_containers)
2041 * If the container is locked, it can not be deleted by the API.
2043 if (fsa_dev_ptr[dd.cnum].locked)
2047 * Mark the container as no longer being valid.
2049 fsa_dev_ptr[dd.cnum].valid = 0;
2050 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2055 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2058 case FSACTL_QUERY_DISK:
2059 return query_disk(dev, arg);
2060 case FSACTL_DELETE_DISK:
2061 return delete_disk(dev, arg);
2062 case FSACTL_FORCE_DELETE_DISK:
2063 return force_delete_disk(dev, arg);
2064 case FSACTL_GET_CONTAINERS:
2065 return aac_get_containers(dev);
2074 * @context: the context set in the fib - here it is scsi cmd
2075 * @fibptr: pointer to the fib
2077 * Handles the completion of a scsi command to a non dasd device
2081 static void aac_srb_callback(void *context, struct fib * fibptr)
2083 struct aac_dev *dev;
2084 struct aac_srb_reply *srbreply;
2085 struct scsi_cmnd *scsicmd;
2087 scsicmd = (struct scsi_cmnd *) context;
2088 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
2089 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2091 BUG_ON(fibptr == NULL);
2093 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2095 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2097 * Calculate resid for sg
2100 scsicmd->resid = scsicmd->request_bufflen -
2101 le32_to_cpu(srbreply->data_xfer_length);
2104 pci_unmap_sg(dev->pdev,
2105 (struct scatterlist *)scsicmd->request_buffer,
2107 scsicmd->sc_data_direction);
2108 else if(scsicmd->request_bufflen)
2109 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
2110 scsicmd->sc_data_direction);
2113 * First check the fib status
2116 if (le32_to_cpu(srbreply->status) != ST_OK){
2118 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2119 len = (le32_to_cpu(srbreply->sense_data_size) >
2120 sizeof(scsicmd->sense_buffer)) ?
2121 sizeof(scsicmd->sense_buffer) :
2122 le32_to_cpu(srbreply->sense_data_size);
2123 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2124 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2128 * Next check the srb status
2130 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2131 case SRB_STATUS_ERROR_RECOVERY:
2132 case SRB_STATUS_PENDING:
2133 case SRB_STATUS_SUCCESS:
2134 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2136 case SRB_STATUS_DATA_OVERRUN:
2137 switch(scsicmd->cmnd[0]){
2146 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
2147 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2149 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2151 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2154 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2158 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2162 case SRB_STATUS_ABORTED:
2163 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2165 case SRB_STATUS_ABORT_FAILED:
2166 // Not sure about this one - but assuming the hba was trying to abort for some reason
2167 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2169 case SRB_STATUS_PARITY_ERROR:
2170 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2172 case SRB_STATUS_NO_DEVICE:
2173 case SRB_STATUS_INVALID_PATH_ID:
2174 case SRB_STATUS_INVALID_TARGET_ID:
2175 case SRB_STATUS_INVALID_LUN:
2176 case SRB_STATUS_SELECTION_TIMEOUT:
2177 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2180 case SRB_STATUS_COMMAND_TIMEOUT:
2181 case SRB_STATUS_TIMEOUT:
2182 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2185 case SRB_STATUS_BUSY:
2186 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2189 case SRB_STATUS_BUS_RESET:
2190 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2193 case SRB_STATUS_MESSAGE_REJECTED:
2194 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2196 case SRB_STATUS_REQUEST_FLUSHED:
2197 case SRB_STATUS_ERROR:
2198 case SRB_STATUS_INVALID_REQUEST:
2199 case SRB_STATUS_REQUEST_SENSE_FAILED:
2200 case SRB_STATUS_NO_HBA:
2201 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2202 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2203 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2204 case SRB_STATUS_DELAYED_RETRY:
2205 case SRB_STATUS_BAD_FUNCTION:
2206 case SRB_STATUS_NOT_STARTED:
2207 case SRB_STATUS_NOT_IN_USE:
2208 case SRB_STATUS_FORCE_ABORT:
2209 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2211 #ifdef AAC_DETAILED_STATUS_INFO
2212 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2213 le32_to_cpu(srbreply->srb_status) & 0x3F,
2214 aac_get_status_string(
2215 le32_to_cpu(srbreply->srb_status) & 0x3F),
2217 le32_to_cpu(srbreply->scsi_status));
2219 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2222 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2224 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2225 len = (le32_to_cpu(srbreply->sense_data_size) >
2226 sizeof(scsicmd->sense_buffer)) ?
2227 sizeof(scsicmd->sense_buffer) :
2228 le32_to_cpu(srbreply->sense_data_size);
2229 #ifdef AAC_DETAILED_STATUS_INFO
2230 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2231 le32_to_cpu(srbreply->status), len);
2233 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2237 * OR in the scsi status (already shifted up a bit)
2239 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2241 aac_fib_complete(fibptr);
2242 aac_fib_free(fibptr);
2243 scsicmd->scsi_done(scsicmd);
2249 * @scsicmd: the scsi command block
2251 * This routine will form a FIB and fill in the aac_srb from the
2252 * scsicmd passed in.
2255 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2257 struct fib* cmd_fibcontext;
2258 struct aac_dev* dev;
2261 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2262 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2263 scsicmd->device->lun > 7) {
2264 scsicmd->result = DID_NO_CONNECT << 16;
2265 scsicmd->scsi_done(scsicmd);
2270 * Allocate and initialize a Fib then setup a BlockWrite command
2272 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2275 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2278 * Check that the command queued to the controller
2280 if (status == -EINPROGRESS) {
2281 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2285 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2286 aac_fib_complete(cmd_fibcontext);
2287 aac_fib_free(cmd_fibcontext);
2292 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2294 struct aac_dev *dev;
2295 unsigned long byte_count = 0;
2297 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2298 // Get rid of old data
2300 psg->sg[0].addr = 0;
2301 psg->sg[0].count = 0;
2302 if (scsicmd->use_sg) {
2303 struct scatterlist *sg;
2306 sg = (struct scatterlist *) scsicmd->request_buffer;
2308 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2309 scsicmd->sc_data_direction);
2310 psg->count = cpu_to_le32(sg_count);
2312 for (i = 0; i < sg_count; i++) {
2313 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2314 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2315 byte_count += sg_dma_len(sg);
2318 /* hba wants the size to be exact */
2319 if(byte_count > scsicmd->request_bufflen){
2320 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2321 (byte_count - scsicmd->request_bufflen);
2322 psg->sg[i-1].count = cpu_to_le32(temp);
2323 byte_count = scsicmd->request_bufflen;
2325 /* Check for command underflow */
2326 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2327 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2328 byte_count, scsicmd->underflow);
2331 else if(scsicmd->request_bufflen) {
2333 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2334 scsicmd->request_buffer,
2335 scsicmd->request_bufflen,
2336 scsicmd->sc_data_direction);
2337 addr = scsicmd->SCp.dma_handle;
2338 psg->count = cpu_to_le32(1);
2339 psg->sg[0].addr = cpu_to_le32(addr);
2340 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2341 byte_count = scsicmd->request_bufflen;
2347 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2349 struct aac_dev *dev;
2350 unsigned long byte_count = 0;
2353 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2354 // Get rid of old data
2356 psg->sg[0].addr[0] = 0;
2357 psg->sg[0].addr[1] = 0;
2358 psg->sg[0].count = 0;
2359 if (scsicmd->use_sg) {
2360 struct scatterlist *sg;
2363 sg = (struct scatterlist *) scsicmd->request_buffer;
2365 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2366 scsicmd->sc_data_direction);
2368 for (i = 0; i < sg_count; i++) {
2369 int count = sg_dma_len(sg);
2370 addr = sg_dma_address(sg);
2371 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2372 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2373 psg->sg[i].count = cpu_to_le32(count);
2374 byte_count += count;
2377 psg->count = cpu_to_le32(sg_count);
2378 /* hba wants the size to be exact */
2379 if(byte_count > scsicmd->request_bufflen){
2380 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2381 (byte_count - scsicmd->request_bufflen);
2382 psg->sg[i-1].count = cpu_to_le32(temp);
2383 byte_count = scsicmd->request_bufflen;
2385 /* Check for command underflow */
2386 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2387 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2388 byte_count, scsicmd->underflow);
2391 else if(scsicmd->request_bufflen) {
2392 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2393 scsicmd->request_buffer,
2394 scsicmd->request_bufflen,
2395 scsicmd->sc_data_direction);
2396 addr = scsicmd->SCp.dma_handle;
2397 psg->count = cpu_to_le32(1);
2398 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2399 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2400 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2401 byte_count = scsicmd->request_bufflen;
2406 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2408 struct Scsi_Host *host = scsicmd->device->host;
2409 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2410 unsigned long byte_count = 0;
2412 // Get rid of old data
2414 psg->sg[0].next = 0;
2415 psg->sg[0].prev = 0;
2416 psg->sg[0].addr[0] = 0;
2417 psg->sg[0].addr[1] = 0;
2418 psg->sg[0].count = 0;
2419 psg->sg[0].flags = 0;
2420 if (scsicmd->use_sg) {
2421 struct scatterlist *sg;
2424 sg = (struct scatterlist *) scsicmd->request_buffer;
2426 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2427 scsicmd->sc_data_direction);
2429 for (i = 0; i < sg_count; i++) {
2430 int count = sg_dma_len(sg);
2431 u64 addr = sg_dma_address(sg);
2432 psg->sg[i].next = 0;
2433 psg->sg[i].prev = 0;
2434 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2435 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2436 psg->sg[i].count = cpu_to_le32(count);
2437 psg->sg[i].flags = 0;
2438 byte_count += count;
2441 psg->count = cpu_to_le32(sg_count);
2442 /* hba wants the size to be exact */
2443 if(byte_count > scsicmd->request_bufflen){
2444 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2445 (byte_count - scsicmd->request_bufflen);
2446 psg->sg[i-1].count = cpu_to_le32(temp);
2447 byte_count = scsicmd->request_bufflen;
2449 /* Check for command underflow */
2450 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2451 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2452 byte_count, scsicmd->underflow);
2455 else if(scsicmd->request_bufflen) {
2458 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2459 scsicmd->request_buffer,
2460 scsicmd->request_bufflen,
2461 scsicmd->sc_data_direction);
2462 addr = scsicmd->SCp.dma_handle;
2463 count = scsicmd->request_bufflen;
2464 psg->count = cpu_to_le32(1);
2465 psg->sg[0].next = 0;
2466 psg->sg[0].prev = 0;
2467 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2468 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2469 psg->sg[0].count = cpu_to_le32(count);
2470 psg->sg[0].flags = 0;
2471 byte_count = scsicmd->request_bufflen;
2476 #ifdef AAC_DETAILED_STATUS_INFO
2478 struct aac_srb_status_info {
2484 static struct aac_srb_status_info srb_status_info[] = {
2485 { SRB_STATUS_PENDING, "Pending Status"},
2486 { SRB_STATUS_SUCCESS, "Success"},
2487 { SRB_STATUS_ABORTED, "Aborted Command"},
2488 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
2489 { SRB_STATUS_ERROR, "Error Event"},
2490 { SRB_STATUS_BUSY, "Device Busy"},
2491 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2492 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2493 { SRB_STATUS_NO_DEVICE, "No Device"},
2494 { SRB_STATUS_TIMEOUT, "Timeout"},
2495 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2496 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2497 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2498 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2499 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2500 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2501 { SRB_STATUS_NO_HBA, "No HBA"},
2502 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2503 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2504 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2505 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2506 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2507 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
2508 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
2509 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2510 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2511 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2512 { SRB_STATUS_NOT_STARTED, "Not Started"},
2513 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2514 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2515 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2516 { 0xff, "Unknown Error"}
2519 char *aac_get_status_string(u32 status)
2523 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2524 if (srb_status_info[i].status == status)
2525 return srb_status_info[i].str;
2527 return "Bad Status Code";