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/sched.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 #include <linux/slab.h>
33 #include <linux/completion.h>
34 #include <linux/blkdev.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 */
56 #define MAX_FIB_DATA (sizeof(struct hw_fib) - sizeof(FIB_HEADER))
58 #define MAX_DRIVER_SG_SEGMENT_COUNT 17
64 #define SENCODE_NO_SENSE 0x00
65 #define SENCODE_END_OF_DATA 0x00
66 #define SENCODE_BECOMING_READY 0x04
67 #define SENCODE_INIT_CMD_REQUIRED 0x04
68 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
69 #define SENCODE_INVALID_COMMAND 0x20
70 #define SENCODE_LBA_OUT_OF_RANGE 0x21
71 #define SENCODE_INVALID_CDB_FIELD 0x24
72 #define SENCODE_LUN_NOT_SUPPORTED 0x25
73 #define SENCODE_INVALID_PARAM_FIELD 0x26
74 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
75 #define SENCODE_PARAM_VALUE_INVALID 0x26
76 #define SENCODE_RESET_OCCURRED 0x29
77 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
78 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
79 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
80 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
81 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
82 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
83 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
84 #define SENCODE_OVERLAPPED_COMMAND 0x4E
87 * Additional sense codes
90 #define ASENCODE_NO_SENSE 0x00
91 #define ASENCODE_END_OF_DATA 0x05
92 #define ASENCODE_BECOMING_READY 0x01
93 #define ASENCODE_INIT_CMD_REQUIRED 0x02
94 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
95 #define ASENCODE_INVALID_COMMAND 0x00
96 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
97 #define ASENCODE_INVALID_CDB_FIELD 0x00
98 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
99 #define ASENCODE_INVALID_PARAM_FIELD 0x00
100 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
101 #define ASENCODE_PARAM_VALUE_INVALID 0x02
102 #define ASENCODE_RESET_OCCURRED 0x00
103 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
104 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
105 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
106 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
107 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
108 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
109 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
110 #define ASENCODE_OVERLAPPED_COMMAND 0x00
112 #define BYTE0(x) (unsigned char)(x)
113 #define BYTE1(x) (unsigned char)((x) >> 8)
114 #define BYTE2(x) (unsigned char)((x) >> 16)
115 #define BYTE3(x) (unsigned char)((x) >> 24)
117 /*------------------------------------------------------------------------------
118 * S T R U C T S / T Y P E D E F S
119 *----------------------------------------------------------------------------*/
120 /* SCSI inquiry data */
121 struct inquiry_data {
122 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
123 u8 inqd_dtq; /* RMB | Device Type Qualifier */
124 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
125 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
126 u8 inqd_len; /* Additional length (n-4) */
127 u8 inqd_pad1[2];/* Reserved - must be zero */
128 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
129 u8 inqd_vid[8]; /* Vendor ID */
130 u8 inqd_pid[16];/* Product ID */
131 u8 inqd_prl[4]; /* Product Revision Level */
135 * M O D U L E G L O B A L S
138 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
139 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
140 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
141 #ifdef AAC_DETAILED_STATUS_INFO
142 static char *aac_get_status_string(u32 status);
146 * Non dasd selection is handled entirely in aachba now
149 MODULE_PARM(nondasd, "i");
150 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
151 MODULE_PARM(dacmode, "i");
152 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
153 MODULE_PARM(commit, "i");
154 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");
156 static int nondasd = -1;
157 static int dacmode = -1;
159 static int commit = -1;
162 * aac_get_config_status - check the adapter configuration
163 * @common: adapter to query
165 * Query config status, and commit the configuration if needed.
167 int aac_get_config_status(struct aac_dev *dev)
172 if (!(fibptr = fib_alloc(dev)))
177 struct aac_get_config_status *dinfo;
178 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
180 dinfo->command = cpu_to_le32(VM_ContainerConfig);
181 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
182 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
185 status = fib_send(ContainerCommand,
187 sizeof (struct aac_get_config_status),
192 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
194 struct aac_get_config_status_resp *reply
195 = (struct aac_get_config_status_resp *) fib_data(fibptr);
196 dprintk((KERN_WARNING
197 "aac_get_config_status: response=%d status=%d action=%d\n",
198 reply->response, reply->status, reply->data.action));
199 if ((reply->response != ST_OK)
200 || (reply->status != CT_OK)
201 || (reply->data.action > CFACT_PAUSE)) {
202 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
206 fib_complete(fibptr);
207 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
210 struct aac_commit_config * dinfo;
212 dinfo = (struct aac_commit_config *) fib_data(fibptr);
214 dinfo->command = cpu_to_le32(VM_ContainerConfig);
215 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
217 status = fib_send(ContainerCommand,
219 sizeof (struct aac_commit_config),
223 fib_complete(fibptr);
224 } else if (commit == 0) {
226 "aac_get_config_status: Foreign device configurations are being ignored\n");
234 * aac_get_containers - list containers
235 * @common: adapter to probe
237 * Make a list of all containers on this controller
239 int aac_get_containers(struct aac_dev *dev)
241 struct fsa_dev_info *fsa_dev_ptr;
246 struct aac_get_container_count *dinfo;
247 struct aac_get_container_count_resp *dresp;
248 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
250 instance = dev->scsi_host_ptr->unique_id;
252 if (!(fibptr = fib_alloc(dev)))
256 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
257 dinfo->command = cpu_to_le32(VM_ContainerConfig);
258 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
260 status = fib_send(ContainerCommand,
262 sizeof (struct aac_get_container_count),
267 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
268 maximum_num_containers = dresp->ContainerSwitchEntries;
269 fib_complete(fibptr);
272 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
273 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
275 fsa_dev_ptr = (struct fsa_dev_info *) kmalloc(
276 sizeof(*fsa_dev_ptr) * maximum_num_containers, GFP_KERNEL);
281 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
283 dev->fsa_dev = fsa_dev_ptr;
284 dev->maximum_num_containers = maximum_num_containers;
286 for (index = 0; index < dev->maximum_num_containers; index++) {
287 struct aac_query_mount *dinfo;
288 struct aac_mount *dresp;
290 fsa_dev_ptr[index].devname[0] = '\0';
293 dinfo = (struct aac_query_mount *) fib_data(fibptr);
295 dinfo->command = cpu_to_le32(VM_NameServe);
296 dinfo->count = cpu_to_le32(index);
297 dinfo->type = cpu_to_le32(FT_FILESYS);
299 status = fib_send(ContainerCommand,
301 sizeof (struct aac_query_mount),
306 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
309 dresp = (struct aac_mount *)fib_data(fibptr);
312 "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%u\n",
313 (int)index, (int)le32_to_cpu(dresp->status),
314 (int)le32_to_cpu(dresp->mnt[0].vol),
315 (int)le32_to_cpu(dresp->mnt[0].state),
316 (unsigned)le32_to_cpu(dresp->mnt[0].capacity)));
317 if ((le32_to_cpu(dresp->status) == ST_OK) &&
318 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
319 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
320 fsa_dev_ptr[index].valid = 1;
321 fsa_dev_ptr[index].type = le32_to_cpu(dresp->mnt[0].vol);
322 fsa_dev_ptr[index].size = le32_to_cpu(dresp->mnt[0].capacity);
323 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
324 fsa_dev_ptr[index].ro = 1;
326 fib_complete(fibptr);
328 * If there are no more containers, then stop asking.
330 if ((index + 1) >= le32_to_cpu(dresp->count)){
338 static void aac_io_done(struct scsi_cmnd * scsicmd)
340 unsigned long cpu_flags;
341 struct Scsi_Host *host = scsicmd->device->host;
342 spin_lock_irqsave(host->host_lock, cpu_flags);
343 scsicmd->scsi_done(scsicmd);
344 spin_unlock_irqrestore(host->host_lock, cpu_flags);
347 static void get_container_name_callback(void *context, struct fib * fibptr)
349 struct aac_get_name_resp * get_name_reply;
350 struct scsi_cmnd * scsicmd;
352 scsicmd = (struct scsi_cmnd *) context;
354 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
358 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
359 /* Failure is irrelevant, using default value instead */
360 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
361 && (get_name_reply->data[0] != '\0')) {
364 char * sp = get_name_reply->data;
365 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
368 count = sizeof(((struct inquiry_data *)NULL)->inqd_pid);
369 dp = ((struct inquiry_data *)scsicmd->request_buffer)->inqd_pid;
371 *dp++ = (*sp) ? *sp++ : ' ';
372 } while (--count > 0);
374 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
376 fib_complete(fibptr);
378 aac_io_done(scsicmd);
382 * aac_get_container_name - get container name, none blocking.
384 static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
387 struct aac_get_name *dinfo;
388 struct fib * cmd_fibcontext;
389 struct aac_dev * dev;
391 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
393 if (!(cmd_fibcontext = fib_alloc(dev)))
396 fib_init(cmd_fibcontext);
397 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
399 dinfo->command = cpu_to_le32(VM_ContainerConfig);
400 dinfo->type = cpu_to_le32(CT_READ_NAME);
401 dinfo->cid = cpu_to_le32(cid);
402 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
404 status = fib_send(ContainerCommand,
406 sizeof (struct aac_get_name),
409 (fib_callback) get_container_name_callback,
413 * Check that the command queued to the controller
415 if (status == -EINPROGRESS)
418 printk(KERN_WARNING "aac_get_container_name: fib_send failed with status: %d.\n", status);
419 fib_complete(cmd_fibcontext);
420 fib_free(cmd_fibcontext);
425 * probe_container - query a logical volume
426 * @dev: device to query
427 * @cid: container identifier
429 * Queries the controller about the given volume. The volume information
430 * is updated in the struct fsa_dev_info structure rather than returned.
433 static int probe_container(struct aac_dev *dev, int cid)
435 struct fsa_dev_info *fsa_dev_ptr;
437 struct aac_query_mount *dinfo;
438 struct aac_mount *dresp;
442 fsa_dev_ptr = dev->fsa_dev;
443 instance = dev->scsi_host_ptr->unique_id;
445 if (!(fibptr = fib_alloc(dev)))
450 dinfo = (struct aac_query_mount *)fib_data(fibptr);
452 dinfo->command = cpu_to_le32(VM_NameServe);
453 dinfo->count = cpu_to_le32(cid);
454 dinfo->type = cpu_to_le32(FT_FILESYS);
456 status = fib_send(ContainerCommand,
458 sizeof(struct aac_query_mount),
463 printk(KERN_WARNING "aacraid: probe_containers query failed.\n");
467 dresp = (struct aac_mount *) fib_data(fibptr);
469 if ((le32_to_cpu(dresp->status) == ST_OK) &&
470 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
471 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
472 fsa_dev_ptr[cid].valid = 1;
473 fsa_dev_ptr[cid].type = le32_to_cpu(dresp->mnt[0].vol);
474 fsa_dev_ptr[cid].size = le32_to_cpu(dresp->mnt[0].capacity);
475 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
476 fsa_dev_ptr[cid].ro = 1;
480 fib_complete(fibptr);
486 /* Local Structure to set SCSI inquiry data strings */
488 char vid[8]; /* Vendor ID */
489 char pid[16]; /* Product ID */
490 char prl[4]; /* Product Revision Level */
494 * InqStrCopy - string merge
495 * @a: string to copy from
496 * @b: string to copy to
498 * Copy a String from one location to another
502 static void inqstrcpy(char *a, char *b)
509 static char *container_types[] = {
530 /* Function: setinqstr
532 * Arguments: [1] pointer to void [1] int
534 * Purpose: Sets SCSI inquiry data strings for vendor, product
535 * and revision level. Allows strings to be set in platform dependant
536 * files instead of in OS dependant driver source.
539 static void setinqstr(int devtype, void *data, int tindex)
541 struct scsi_inq *str;
542 struct aac_driver_ident *mp;
544 mp = aac_get_driver_ident(devtype);
546 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
548 inqstrcpy (mp->vname, str->vid);
549 inqstrcpy (mp->model, str->pid); /* last six chars reserved for vol type */
551 if (tindex < (sizeof(container_types)/sizeof(char *))){
552 char *findit = str->pid;
554 for ( ; *findit != ' '; findit++); /* walk till we find a space */
555 /* RAID is superfluous in the context of a RAID device */
556 if (memcmp(findit-4, "RAID", 4) == 0)
557 *(findit -= 4) = ' ';
558 inqstrcpy (container_types[tindex], findit + 1);
560 inqstrcpy ("V1.0", str->prl);
563 void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
564 u8 a_sense_code, u8 incorrect_length,
565 u8 bit_pointer, u16 field_pointer,
568 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
569 sense_buf[1] = 0; /* Segment number, always zero */
571 if (incorrect_length) {
572 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
573 sense_buf[3] = BYTE3(residue);
574 sense_buf[4] = BYTE2(residue);
575 sense_buf[5] = BYTE1(residue);
576 sense_buf[6] = BYTE0(residue);
578 sense_buf[2] = sense_key; /* Sense key */
580 if (sense_key == ILLEGAL_REQUEST)
581 sense_buf[7] = 10; /* Additional sense length */
583 sense_buf[7] = 6; /* Additional sense length */
585 sense_buf[12] = sense_code; /* Additional sense code */
586 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
587 if (sense_key == ILLEGAL_REQUEST) {
590 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
591 sense_buf[15] = 0x80;/* Std sense key specific field */
592 /* Illegal parameter is in the parameter block */
594 if (sense_code == SENCODE_INVALID_CDB_FIELD)
595 sense_buf[15] = 0xc0;/* Std sense key specific field */
596 /* Illegal parameter is in the CDB block */
597 sense_buf[15] |= bit_pointer;
598 sense_buf[16] = field_pointer >> 8; /* MSB */
599 sense_buf[17] = field_pointer; /* LSB */
603 int aac_get_adapter_info(struct aac_dev* dev)
606 struct aac_adapter_info* info;
609 if (!(fibptr = fib_alloc(dev)))
613 info = (struct aac_adapter_info*) fib_data(fibptr);
615 memset(info,0,sizeof(struct aac_adapter_info));
617 rcode = fib_send(RequestAdapterInfo,
619 sizeof(struct aac_adapter_info),
625 memcpy(&dev->adapter_info, info, sizeof(struct aac_adapter_info));
627 tmp = dev->adapter_info.kernelrev;
628 printk(KERN_INFO"%s%d: kernel %d.%d.%d build %d\n",
630 tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
631 dev->adapter_info.kernelbuild);
632 tmp = dev->adapter_info.monitorrev;
633 printk(KERN_INFO"%s%d: monitor %d.%d.%d build %d\n",
635 tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
636 dev->adapter_info.monitorbuild);
637 tmp = dev->adapter_info.biosrev;
638 printk(KERN_INFO"%s%d: bios %d.%d.%d build %d\n",
640 tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
641 dev->adapter_info.biosbuild);
642 printk(KERN_INFO"%s%d: serial %x%x\n",
644 dev->adapter_info.serial[0],
645 dev->adapter_info.serial[1]);
647 dev->nondasd_support = 0;
648 dev->raid_scsi_mode = 0;
649 if(dev->adapter_info.options & AAC_OPT_NONDASD){
650 dev->nondasd_support = 1;
654 * If the firmware supports ROMB RAID/SCSI mode and we are currently
655 * in RAID/SCSI mode, set the flag. For now if in this mode we will
656 * force nondasd support on. If we decide to allow the non-dasd flag
657 * additional changes changes will have to be made to support
658 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
659 * changed to support the new dev->raid_scsi_mode flag instead of
660 * leaching off of the dev->nondasd_support flag. Also in linit.c the
661 * function aac_detect will have to be modified where it sets up the
662 * max number of channels based on the aac->nondasd_support flag only.
664 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
665 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
666 dev->nondasd_support = 1;
667 dev->raid_scsi_mode = 1;
669 if (dev->raid_scsi_mode != 0)
670 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
674 dev->nondasd_support = (nondasd!=0);
676 if(dev->nondasd_support != 0){
677 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
680 dev->dac_support = 0;
681 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
682 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
683 dev->dac_support = 1;
687 dev->dac_support = (dacmode!=0);
689 if(dev->dac_support != 0) {
690 if (!pci_set_dma_mask(dev->pdev, 0xFFFFFFFFFFFFFFFFULL) &&
691 !pci_set_consistent_dma_mask(dev->pdev, 0xFFFFFFFFFFFFFFFFULL)) {
692 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
694 } else if (!pci_set_dma_mask(dev->pdev, 0xFFFFFFFFULL) &&
695 !pci_set_consistent_dma_mask(dev->pdev, 0xFFFFFFFFULL)) {
696 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
698 dev->dac_support = 0;
700 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
706 fib_complete(fibptr);
713 static void read_callback(void *context, struct fib * fibptr)
716 struct aac_read_reply *readreply;
717 struct scsi_cmnd *scsicmd;
721 scsicmd = (struct scsi_cmnd *) context;
723 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
724 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
726 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
727 dprintk((KERN_DEBUG "read_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
733 pci_unmap_sg(dev->pdev,
734 (struct scatterlist *)scsicmd->buffer,
736 scsicmd->sc_data_direction);
737 else if(scsicmd->request_bufflen)
738 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
739 scsicmd->request_bufflen,
740 scsicmd->sc_data_direction);
741 readreply = (struct aac_read_reply *)fib_data(fibptr);
742 if (le32_to_cpu(readreply->status) == ST_OK)
743 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
745 printk(KERN_WARNING "read_callback: read failed, status = %d\n", readreply->status);
746 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
747 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
749 SENCODE_INTERNAL_TARGET_FAILURE,
750 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
752 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
753 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
754 ? sizeof(scsicmd->sense_buffer)
755 : sizeof(dev->fsa_dev[cid].sense_data));
757 fib_complete(fibptr);
760 aac_io_done(scsicmd);
763 static void write_callback(void *context, struct fib * fibptr)
766 struct aac_write_reply *writereply;
767 struct scsi_cmnd *scsicmd;
771 scsicmd = (struct scsi_cmnd *) context;
772 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
773 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
775 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
776 dprintk((KERN_DEBUG "write_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
781 pci_unmap_sg(dev->pdev,
782 (struct scatterlist *)scsicmd->buffer,
784 scsicmd->sc_data_direction);
785 else if(scsicmd->request_bufflen)
786 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
787 scsicmd->request_bufflen,
788 scsicmd->sc_data_direction);
790 writereply = (struct aac_write_reply *) fib_data(fibptr);
791 if (le32_to_cpu(writereply->status) == ST_OK)
792 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
794 printk(KERN_WARNING "write_callback: write failed, status = %d\n", writereply->status);
795 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
796 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
798 SENCODE_INTERNAL_TARGET_FAILURE,
799 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
801 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
802 sizeof(struct sense_data));
805 fib_complete(fibptr);
807 aac_io_done(scsicmd);
810 int aac_read(struct scsi_cmnd * scsicmd, int cid)
818 struct fib * cmd_fibcontext;
820 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
822 * Get block address and transfer length
824 if (scsicmd->cmnd[0] == READ_6) /* 6 byte command */
826 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
828 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
829 count = scsicmd->cmnd[4];
834 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
836 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
837 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
839 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
841 * Alocate and initialize a Fib
843 if (!(cmd_fibcontext = fib_alloc(dev))) {
847 fib_init(cmd_fibcontext);
849 if(dev->dac_support == 1) {
850 struct aac_read64 *readcmd;
851 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
852 readcmd->command = cpu_to_le32(VM_CtHostRead64);
853 readcmd->cid = cpu_to_le16(cid);
854 readcmd->sector_count = cpu_to_le16(count);
855 readcmd->block = cpu_to_le32(lba);
856 readcmd->pad = cpu_to_le16(0);
857 readcmd->flags = cpu_to_le16(0);
859 aac_build_sg64(scsicmd, &readcmd->sg);
860 if(readcmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
862 fibsize = sizeof(struct aac_read64) + ((readcmd->sg.count - 1) * sizeof (struct sgentry64));
864 * Now send the Fib to the adapter
866 status = fib_send(ContainerCommand64,
871 (fib_callback) read_callback,
874 struct aac_read *readcmd;
875 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
876 readcmd->command = cpu_to_le32(VM_CtBlockRead);
877 readcmd->cid = cpu_to_le32(cid);
878 readcmd->block = cpu_to_le32(lba);
879 readcmd->count = cpu_to_le32(count * 512);
881 if (count * 512 > (64 * 1024))
884 aac_build_sg(scsicmd, &readcmd->sg);
885 if(readcmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
887 fibsize = sizeof(struct aac_read) + ((readcmd->sg.count - 1) * sizeof (struct sgentry));
889 * Now send the Fib to the adapter
891 status = fib_send(ContainerCommand,
896 (fib_callback) read_callback,
903 * Check that the command queued to the controller
905 if (status == -EINPROGRESS)
907 dprintk("read queued.\n");
911 printk(KERN_WARNING "aac_read: fib_send failed with status: %d.\n", status);
913 * For some reason, the Fib didn't queue, return QUEUE_FULL
915 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
916 aac_io_done(scsicmd);
917 fib_complete(cmd_fibcontext);
918 fib_free(cmd_fibcontext);
922 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
929 struct fib * cmd_fibcontext;
931 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
933 * Get block address and transfer length
935 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
937 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
938 count = scsicmd->cmnd[4];
942 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
943 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
944 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
946 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
948 * Allocate and initialize a Fib then setup a BlockWrite command
950 if (!(cmd_fibcontext = fib_alloc(dev))) {
951 scsicmd->result = DID_ERROR << 16;
952 aac_io_done(scsicmd);
955 fib_init(cmd_fibcontext);
957 if(dev->dac_support == 1) {
958 struct aac_write64 *writecmd;
959 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
960 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
961 writecmd->cid = cpu_to_le16(cid);
962 writecmd->sector_count = cpu_to_le16(count);
963 writecmd->block = cpu_to_le32(lba);
964 writecmd->pad = cpu_to_le16(0);
965 writecmd->flags = cpu_to_le16(0);
967 aac_build_sg64(scsicmd, &writecmd->sg);
968 if(writecmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
970 fibsize = sizeof(struct aac_write64) + ((writecmd->sg.count - 1) * sizeof (struct sgentry64));
972 * Now send the Fib to the adapter
974 status = fib_send(ContainerCommand64,
979 (fib_callback) write_callback,
982 struct aac_write *writecmd;
983 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
984 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
985 writecmd->cid = cpu_to_le32(cid);
986 writecmd->block = cpu_to_le32(lba);
987 writecmd->count = cpu_to_le32(count * 512);
988 writecmd->sg.count = cpu_to_le32(1);
989 /* ->stable is not used - it did mean which type of write */
991 if (count * 512 > (64 * 1024)) {
995 aac_build_sg(scsicmd, &writecmd->sg);
996 if(writecmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
998 fibsize = sizeof(struct aac_write) + ((writecmd->sg.count - 1) * sizeof (struct sgentry));
1000 * Now send the Fib to the adapter
1002 status = fib_send(ContainerCommand,
1007 (fib_callback) write_callback,
1012 * Check that the command queued to the controller
1014 if (status == -EINPROGRESS)
1016 dprintk("write queued.\n");
1020 printk(KERN_WARNING "aac_write: fib_send failed with status: %d\n", status);
1022 * For some reason, the Fib didn't queue, return QUEUE_FULL
1024 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1025 aac_io_done(scsicmd);
1027 fib_complete(cmd_fibcontext);
1028 fib_free(cmd_fibcontext);
1034 * aac_scsi_cmd() - Process SCSI command
1035 * @scsicmd: SCSI command block
1037 * Emulate a SCSI command and queue the required request for the
1041 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1044 struct Scsi_Host *host = scsicmd->device->host;
1045 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1046 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1047 int cardtype = dev->cardtype;
1051 * If the bus, id or lun is out of range, return fail
1052 * Test does not apply to ID 16, the pseudo id for the controller
1055 if (scsicmd->device->id != host->this_id) {
1056 if ((scsicmd->device->channel == 0) ){
1057 if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){
1058 scsicmd->result = DID_NO_CONNECT << 16;
1059 scsicmd->scsi_done(scsicmd);
1062 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
1065 * If the target container doesn't exist, it may have
1066 * been newly created
1068 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1069 switch (scsicmd->cmnd[0]) {
1072 case TEST_UNIT_READY:
1073 spin_unlock_irq(host->host_lock);
1074 probe_container(dev, cid);
1075 spin_lock_irq(host->host_lock);
1076 if (fsa_dev_ptr[cid].valid == 0) {
1077 scsicmd->result = DID_NO_CONNECT << 16;
1078 scsicmd->scsi_done(scsicmd);
1086 * If the target container still doesn't exist,
1089 if (fsa_dev_ptr[cid].valid == 0) {
1090 scsicmd->result = DID_BAD_TARGET << 16;
1091 scsicmd->scsi_done(scsicmd);
1094 } else { /* check for physical non-dasd devices */
1095 if(dev->nondasd_support == 1){
1096 return aac_send_srb_fib(scsicmd);
1098 scsicmd->result = DID_NO_CONNECT << 16;
1099 scsicmd->scsi_done(scsicmd);
1105 * else Command for the controller itself
1107 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1108 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1110 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1111 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1112 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1114 SENCODE_INVALID_COMMAND,
1115 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1116 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1117 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1118 ? sizeof(scsicmd->sense_buffer)
1119 : sizeof(dev->fsa_dev[cid].sense_data));
1120 scsicmd->scsi_done(scsicmd);
1125 /* Handle commands here that don't really require going out to the adapter */
1126 switch (scsicmd->cmnd[0]) {
1129 struct inquiry_data *inq_data_ptr;
1131 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
1132 inq_data_ptr = (struct inquiry_data *)scsicmd->request_buffer;
1133 memset(inq_data_ptr, 0, sizeof (struct inquiry_data));
1135 inq_data_ptr->inqd_ver = 2; /* claim compliance to SCSI-2 */
1136 inq_data_ptr->inqd_dtq = 0x80; /* set RMB bit to one indicating that the medium is removable */
1137 inq_data_ptr->inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
1138 inq_data_ptr->inqd_len = 31;
1139 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1140 inq_data_ptr->inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1142 * Set the Vendor, Product, and Revision Level
1143 * see: <vendor>.c i.e. aac.c
1145 if (scsicmd->device->id == host->this_id) {
1146 setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), (sizeof(container_types)/sizeof(char *)));
1147 inq_data_ptr->inqd_pdt = INQD_PDT_PROC; /* Processor device */
1148 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1149 scsicmd->scsi_done(scsicmd);
1152 setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr[cid].type);
1153 inq_data_ptr->inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1154 return aac_get_container_name(scsicmd, cid);
1161 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1162 if (fsa_dev_ptr[cid].size <= 0x100000000LL)
1163 capacity = fsa_dev_ptr[cid].size - 1;
1166 cp = scsicmd->request_buffer;
1167 cp[0] = (capacity >> 24) & 0xff;
1168 cp[1] = (capacity >> 16) & 0xff;
1169 cp[2] = (capacity >> 8) & 0xff;
1170 cp[3] = (capacity >> 0) & 0xff;
1176 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1177 scsicmd->scsi_done(scsicmd);
1186 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1187 mode_buf = scsicmd->request_buffer;
1188 mode_buf[0] = 3; /* Mode data length */
1189 mode_buf[1] = 0; /* Medium type - default */
1190 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1191 mode_buf[3] = 0; /* Block descriptor length */
1193 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1194 scsicmd->scsi_done(scsicmd);
1202 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1203 mode_buf = scsicmd->request_buffer;
1204 mode_buf[0] = 0; /* Mode data length (MSB) */
1205 mode_buf[1] = 6; /* Mode data length (LSB) */
1206 mode_buf[2] = 0; /* Medium type - default */
1207 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1208 mode_buf[4] = 0; /* reserved */
1209 mode_buf[5] = 0; /* reserved */
1210 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1211 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1213 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1214 scsicmd->scsi_done(scsicmd);
1219 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1220 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1221 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1222 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1223 scsicmd->scsi_done(scsicmd);
1226 case ALLOW_MEDIUM_REMOVAL:
1227 dprintk((KERN_DEBUG "LOCK command.\n"));
1228 if (scsicmd->cmnd[4])
1229 fsa_dev_ptr[cid].locked = 1;
1231 fsa_dev_ptr[cid].locked = 0;
1233 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1234 scsicmd->scsi_done(scsicmd);
1237 * These commands are all No-Ops
1239 case TEST_UNIT_READY:
1243 case REASSIGN_BLOCKS:
1246 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1247 scsicmd->scsi_done(scsicmd);
1251 switch (scsicmd->cmnd[0])
1256 * Hack to keep track of ordinal number of the device that
1257 * corresponds to a container. Needed to convert
1258 * containers to /dev/sd device names
1261 spin_unlock_irq(host->host_lock);
1262 if (scsicmd->request->rq_disk)
1263 memcpy(fsa_dev_ptr[cid].devname,
1264 scsicmd->request->rq_disk->disk_name,
1267 ret = aac_read(scsicmd, cid);
1268 spin_lock_irq(host->host_lock);
1273 spin_unlock_irq(host->host_lock);
1274 ret = aac_write(scsicmd, cid);
1275 spin_lock_irq(host->host_lock);
1279 * Unhandled commands
1281 printk(KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]);
1282 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1283 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1284 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1285 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1286 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1287 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1288 ? sizeof(scsicmd->sense_buffer)
1289 : sizeof(dev->fsa_dev[cid].sense_data));
1290 scsicmd->scsi_done(scsicmd);
1295 static int query_disk(struct aac_dev *dev, void __user *arg)
1297 struct aac_query_disk qd;
1298 struct fsa_dev_info *fsa_dev_ptr;
1300 fsa_dev_ptr = dev->fsa_dev;
1301 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1304 qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
1305 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1307 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
1309 qd.instance = dev->scsi_host_ptr->host_no;
1311 qd.id = CONTAINER_TO_ID(qd.cnum);
1312 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1314 else return -EINVAL;
1316 qd.valid = fsa_dev_ptr[qd.cnum].valid;
1317 qd.locked = fsa_dev_ptr[qd.cnum].locked;
1318 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
1320 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
1325 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
1326 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
1328 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1333 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1335 struct aac_delete_disk dd;
1336 struct fsa_dev_info *fsa_dev_ptr;
1338 fsa_dev_ptr = dev->fsa_dev;
1340 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1343 if (dd.cnum >= dev->maximum_num_containers)
1346 * Mark this container as being deleted.
1348 fsa_dev_ptr[dd.cnum].deleted = 1;
1350 * Mark the container as no longer valid
1352 fsa_dev_ptr[dd.cnum].valid = 0;
1356 static int delete_disk(struct aac_dev *dev, void __user *arg)
1358 struct aac_delete_disk dd;
1359 struct fsa_dev_info *fsa_dev_ptr;
1361 fsa_dev_ptr = dev->fsa_dev;
1363 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1366 if (dd.cnum >= dev->maximum_num_containers)
1369 * If the container is locked, it can not be deleted by the API.
1371 if (fsa_dev_ptr[dd.cnum].locked)
1375 * Mark the container as no longer being valid.
1377 fsa_dev_ptr[dd.cnum].valid = 0;
1378 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
1383 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1386 case FSACTL_QUERY_DISK:
1387 return query_disk(dev, arg);
1388 case FSACTL_DELETE_DISK:
1389 return delete_disk(dev, arg);
1390 case FSACTL_FORCE_DELETE_DISK:
1391 return force_delete_disk(dev, arg);
1392 case FSACTL_GET_CONTAINERS:
1393 return aac_get_containers(dev);
1402 * @context: the context set in the fib - here it is scsi cmd
1403 * @fibptr: pointer to the fib
1405 * Handles the completion of a scsi command to a non dasd device
1409 static void aac_srb_callback(void *context, struct fib * fibptr)
1411 struct aac_dev *dev;
1412 struct aac_srb_reply *srbreply;
1413 struct scsi_cmnd *scsicmd;
1415 scsicmd = (struct scsi_cmnd *) context;
1416 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1421 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1423 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
1425 * Calculate resid for sg
1428 scsicmd->resid = scsicmd->request_bufflen - srbreply->data_xfer_length;
1431 pci_unmap_sg(dev->pdev,
1432 (struct scatterlist *)scsicmd->buffer,
1434 scsicmd->sc_data_direction);
1435 else if(scsicmd->request_bufflen)
1436 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle, scsicmd->request_bufflen,
1437 scsicmd->sc_data_direction);
1440 * First check the fib status
1443 if (le32_to_cpu(srbreply->status) != ST_OK){
1445 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1446 len = (srbreply->sense_data_size > sizeof(scsicmd->sense_buffer))?
1447 sizeof(scsicmd->sense_buffer):srbreply->sense_data_size;
1448 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1449 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1453 * Next check the srb status
1455 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1456 case SRB_STATUS_ERROR_RECOVERY:
1457 case SRB_STATUS_PENDING:
1458 case SRB_STATUS_SUCCESS:
1459 if(scsicmd->cmnd[0] == INQUIRY ){
1462 /* We can't expose disk devices because we can't tell whether they
1463 * are the raw container drives or stand alone drives. If they have
1464 * the removable bit set then we should expose them though.
1466 b = (*(u8*)scsicmd->buffer)&0x1f;
1467 b1 = ((u8*)scsicmd->buffer)[1];
1468 if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1469 || (b==TYPE_DISK && (b1&0x80)) ){
1470 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1472 * We will allow disk devices if in RAID/SCSI mode and
1475 } else if ((dev->raid_scsi_mode) &&
1476 (scsicmd->device->channel == 2)) {
1477 scsicmd->result = DID_OK << 16 |
1478 COMMAND_COMPLETE << 8;
1480 scsicmd->result = DID_NO_CONNECT << 16 |
1481 COMMAND_COMPLETE << 8;
1484 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1487 case SRB_STATUS_DATA_OVERRUN:
1488 switch(scsicmd->cmnd[0]){
1495 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1496 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1498 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1500 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1505 /* We can't expose disk devices because we can't tell whether they
1506 * are the raw container drives or stand alone drives
1508 b = (*(u8*)scsicmd->buffer)&0x0f;
1509 b1 = ((u8*)scsicmd->buffer)[1];
1510 if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1511 || (b==TYPE_DISK && (b1&0x80)) ){
1512 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1514 * We will allow disk devices if in RAID/SCSI mode and
1517 } else if ((dev->raid_scsi_mode) &&
1518 (scsicmd->device->channel == 2)) {
1519 scsicmd->result = DID_OK << 16 |
1520 COMMAND_COMPLETE << 8;
1522 scsicmd->result = DID_NO_CONNECT << 16 |
1523 COMMAND_COMPLETE << 8;
1528 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1532 case SRB_STATUS_ABORTED:
1533 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
1535 case SRB_STATUS_ABORT_FAILED:
1536 // Not sure about this one - but assuming the hba was trying to abort for some reason
1537 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
1539 case SRB_STATUS_PARITY_ERROR:
1540 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
1542 case SRB_STATUS_NO_DEVICE:
1543 case SRB_STATUS_INVALID_PATH_ID:
1544 case SRB_STATUS_INVALID_TARGET_ID:
1545 case SRB_STATUS_INVALID_LUN:
1546 case SRB_STATUS_SELECTION_TIMEOUT:
1547 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1550 case SRB_STATUS_COMMAND_TIMEOUT:
1551 case SRB_STATUS_TIMEOUT:
1552 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
1555 case SRB_STATUS_BUSY:
1556 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1559 case SRB_STATUS_BUS_RESET:
1560 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
1563 case SRB_STATUS_MESSAGE_REJECTED:
1564 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
1566 case SRB_STATUS_REQUEST_FLUSHED:
1567 case SRB_STATUS_ERROR:
1568 case SRB_STATUS_INVALID_REQUEST:
1569 case SRB_STATUS_REQUEST_SENSE_FAILED:
1570 case SRB_STATUS_NO_HBA:
1571 case SRB_STATUS_UNEXPECTED_BUS_FREE:
1572 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
1573 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
1574 case SRB_STATUS_DELAYED_RETRY:
1575 case SRB_STATUS_BAD_FUNCTION:
1576 case SRB_STATUS_NOT_STARTED:
1577 case SRB_STATUS_NOT_IN_USE:
1578 case SRB_STATUS_FORCE_ABORT:
1579 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
1581 #ifdef AAC_DETAILED_STATUS_INFO
1582 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
1583 le32_to_cpu(srbreply->srb_status & 0x3F),
1584 aac_get_status_string(
1585 le32_to_cpu(srbreply->srb_status) & 0x3F),
1587 le32_to_cpu(srbreply->scsi_status));
1589 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1592 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
1594 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
1595 len = (srbreply->sense_data_size > sizeof(scsicmd->sense_buffer))?
1596 sizeof(scsicmd->sense_buffer):srbreply->sense_data_size;
1597 #ifdef AAC_DETAILED_STATUS_INFO
1598 dprintk((KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
1599 le32_to_cpu(srbreply->status), len));
1601 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1605 * OR in the scsi status (already shifted up a bit)
1607 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
1609 fib_complete(fibptr);
1611 aac_io_done(scsicmd);
1617 * @scsicmd: the scsi command block
1619 * This routine will form a FIB and fill in the aac_srb from the
1620 * scsicmd passed in.
1623 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
1625 struct fib* cmd_fibcontext;
1626 struct aac_dev* dev;
1628 struct aac_srb *srbcmd;
1633 if( scsicmd->device->id > 15 || scsicmd->device->lun > 7) {
1634 scsicmd->result = DID_NO_CONNECT << 16;
1635 scsicmd->scsi_done(scsicmd);
1639 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1640 switch(scsicmd->sc_data_direction){
1644 case DMA_BIDIRECTIONAL:
1645 flag = SRB_DataIn | SRB_DataOut;
1647 case DMA_FROM_DEVICE:
1651 default: /* shuts up some versions of gcc */
1652 flag = SRB_NoDataXfer;
1658 * Allocate and initialize a Fib then setup a BlockWrite command
1660 if (!(cmd_fibcontext = fib_alloc(dev))) {
1663 fib_init(cmd_fibcontext);
1665 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
1666 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1667 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel));
1668 srbcmd->id = cpu_to_le32(scsicmd->device->id);
1669 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
1670 srbcmd->flags = cpu_to_le32(flag);
1671 timeout = (scsicmd->timeout-jiffies)/HZ;
1675 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1676 srbcmd->retry_limit =cpu_to_le32(0); // Obsolete parameter
1677 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
1679 if( dev->dac_support == 1 ) {
1680 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
1681 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1683 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1684 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1686 * Build Scatter/Gather list
1688 fibsize = sizeof (struct aac_srb) + (((srbcmd->sg.count & 0xff) - 1) * sizeof (struct sgentry64));
1691 * Now send the Fib to the adapter
1693 status = fib_send(ScsiPortCommand64, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
1694 (fib_callback) aac_srb_callback, (void *) scsicmd);
1696 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
1697 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1699 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1700 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1702 * Build Scatter/Gather list
1704 fibsize = sizeof (struct aac_srb) + (((srbcmd->sg.count & 0xff) - 1) * sizeof (struct sgentry));
1707 * Now send the Fib to the adapter
1709 status = fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
1710 (fib_callback) aac_srb_callback, (void *) scsicmd);
1713 * Check that the command queued to the controller
1715 if (status == -EINPROGRESS){
1719 printk(KERN_WARNING "aac_srb: fib_send failed with status: %d\n", status);
1720 fib_complete(cmd_fibcontext);
1721 fib_free(cmd_fibcontext);
1726 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
1728 struct aac_dev *dev;
1729 unsigned long byte_count = 0;
1731 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1732 // Get rid of old data
1733 psg->count = cpu_to_le32(0);
1734 psg->sg[0].addr = cpu_to_le32(0);
1735 psg->sg[0].count = cpu_to_le32(0);
1736 if (scsicmd->use_sg) {
1737 struct scatterlist *sg;
1740 sg = (struct scatterlist *) scsicmd->request_buffer;
1742 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
1743 scsicmd->sc_data_direction);
1744 psg->count = cpu_to_le32(sg_count);
1748 for (i = 0; i < sg_count; i++) {
1749 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
1750 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
1751 byte_count += sg_dma_len(sg);
1754 /* hba wants the size to be exact */
1755 if(byte_count > scsicmd->request_bufflen){
1756 psg->sg[i-1].count -= (byte_count - scsicmd->request_bufflen);
1757 byte_count = scsicmd->request_bufflen;
1759 /* Check for command underflow */
1760 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
1761 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
1762 byte_count, scsicmd->underflow);
1765 else if(scsicmd->request_bufflen) {
1767 addr = pci_map_single(dev->pdev,
1768 scsicmd->request_buffer,
1769 scsicmd->request_bufflen,
1770 scsicmd->sc_data_direction);
1771 psg->count = cpu_to_le32(1);
1772 psg->sg[0].addr = cpu_to_le32(addr);
1773 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
1774 scsicmd->SCp.dma_handle = addr;
1775 byte_count = scsicmd->request_bufflen;
1781 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
1783 struct aac_dev *dev;
1784 unsigned long byte_count = 0;
1787 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1788 // Get rid of old data
1789 psg->count = cpu_to_le32(0);
1790 psg->sg[0].addr[0] = cpu_to_le32(0);
1791 psg->sg[0].addr[1] = cpu_to_le32(0);
1792 psg->sg[0].count = cpu_to_le32(0);
1793 if (scsicmd->use_sg) {
1794 struct scatterlist *sg;
1797 sg = (struct scatterlist *) scsicmd->request_buffer;
1799 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
1800 scsicmd->sc_data_direction);
1801 psg->count = cpu_to_le32(sg_count);
1805 for (i = 0; i < sg_count; i++) {
1806 le_addr = cpu_to_le64(sg_dma_address(sg));
1807 psg->sg[i].addr[1] = (u32)(le_addr>>32);
1808 psg->sg[i].addr[0] = (u32)(le_addr & 0xffffffff);
1809 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
1810 byte_count += sg_dma_len(sg);
1813 /* hba wants the size to be exact */
1814 if(byte_count > scsicmd->request_bufflen){
1815 psg->sg[i-1].count -= (byte_count - scsicmd->request_bufflen);
1816 byte_count = scsicmd->request_bufflen;
1818 /* Check for command underflow */
1819 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
1820 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
1821 byte_count, scsicmd->underflow);
1824 else if(scsicmd->request_bufflen) {
1826 addr = pci_map_single(dev->pdev,
1827 scsicmd->request_buffer,
1828 scsicmd->request_bufflen,
1829 scsicmd->sc_data_direction);
1830 psg->count = cpu_to_le32(1);
1831 le_addr = cpu_to_le64(addr);
1832 psg->sg[0].addr[1] = (u32)(le_addr>>32);
1833 psg->sg[0].addr[0] = (u32)(le_addr & 0xffffffff);
1834 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
1835 scsicmd->SCp.dma_handle = addr;
1836 byte_count = scsicmd->request_bufflen;
1841 #ifdef AAC_DETAILED_STATUS_INFO
1843 struct aac_srb_status_info {
1849 static struct aac_srb_status_info srb_status_info[] = {
1850 { SRB_STATUS_PENDING, "Pending Status"},
1851 { SRB_STATUS_SUCCESS, "Success"},
1852 { SRB_STATUS_ABORTED, "Aborted Command"},
1853 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
1854 { SRB_STATUS_ERROR, "Error Event"},
1855 { SRB_STATUS_BUSY, "Device Busy"},
1856 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
1857 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
1858 { SRB_STATUS_NO_DEVICE, "No Device"},
1859 { SRB_STATUS_TIMEOUT, "Timeout"},
1860 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
1861 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
1862 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
1863 { SRB_STATUS_BUS_RESET, "Bus Reset"},
1864 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
1865 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
1866 { SRB_STATUS_NO_HBA, "No HBA"},
1867 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
1868 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
1869 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
1870 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
1871 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
1872 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
1873 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
1874 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
1875 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
1876 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
1877 { SRB_STATUS_NOT_STARTED, "Not Started"},
1878 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
1879 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
1880 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
1881 { 0xff, "Unknown Error"}
1884 char *aac_get_status_string(u32 status)
1888 for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
1889 if(srb_status_info[i].status == status){
1890 return srb_status_info[i].str;
1894 return "Bad Status Code";