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 u8 error_code; /* 70h (current errors), 71h(deferred errors) */
136 u8 valid:1; /* A valid bit of one indicates that the information */
137 /* field contains valid information as defined in the
140 u8 segment_number; /* Only used for COPY, COMPARE, or COPY AND VERIFY Commands */
141 u8 sense_key:4; /* Sense Key */
143 u8 ILI:1; /* Incorrect Length Indicator */
144 u8 EOM:1; /* End Of Medium - reserved for random access devices */
145 u8 filemark:1; /* Filemark - reserved for random access devices */
147 u8 information[4]; /* for direct-access devices, contains the unsigned
148 * logical block address or residue associated with
151 u8 add_sense_len; /* number of additional sense bytes to follow this field */
152 u8 cmnd_info[4]; /* not used */
153 u8 ASC; /* Additional Sense Code */
154 u8 ASCQ; /* Additional Sense Code Qualifier */
155 u8 FRUC; /* Field Replaceable Unit Code - not used */
156 u8 bit_ptr:3; /* indicates which byte of the CDB or parameter data
159 u8 BPV:1; /* bit pointer valid (BPV): 1- indicates that
160 * the bit_ptr field has valid value
163 u8 CD:1; /* command data bit: 1- illegal parameter in CDB.
164 * 0- illegal parameter in data.
167 u8 field_ptr[2]; /* byte of the CDB or parameter data in error */
171 * M O D U L E G L O B A L S
174 static struct sense_data sense_data[MAXIMUM_NUM_CONTAINERS];
175 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
176 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
177 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
178 #ifdef AAC_DETAILED_STATUS_INFO
179 static char *aac_get_status_string(u32 status);
183 * aac_get_containers - list containers
184 * @common: adapter to probe
186 * Make a list of all containers on this controller
188 int aac_get_containers(struct aac_dev *dev)
190 struct fsa_scsi_hba *fsa_dev_ptr;
193 struct aac_query_mount *dinfo;
194 struct aac_mount *dresp;
198 fsa_dev_ptr = &(dev->fsa_dev);
199 instance = dev->scsi_host_ptr->unique_id;
201 if (!(fibptr = fib_alloc(dev)))
204 for (index = 0; index < MAXIMUM_NUM_CONTAINERS; index++) {
206 dinfo = (struct aac_query_mount *) fib_data(fibptr);
208 dinfo->command = cpu_to_le32(VM_NameServe);
209 dinfo->count = cpu_to_le32(index);
210 dinfo->type = cpu_to_le32(FT_FILESYS);
212 status = fib_send(ContainerCommand,
214 sizeof (struct aac_query_mount),
219 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
222 dresp = (struct aac_mount *)fib_data(fibptr);
224 if ((le32_to_cpu(dresp->status) == ST_OK) &&
225 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
226 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
227 fsa_dev_ptr->valid[index] = 1;
228 fsa_dev_ptr->type[index] = le32_to_cpu(dresp->mnt[0].vol);
229 fsa_dev_ptr->size[index] = le32_to_cpu(dresp->mnt[0].capacity);
230 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
231 fsa_dev_ptr->ro[index] = 1;
233 fib_complete(fibptr);
235 * If there are no more containers, then stop asking.
237 if ((index + 1) >= le32_to_cpu(dresp->count)){
246 * probe_container - query a logical volume
247 * @dev: device to query
248 * @cid: container identifier
250 * Queries the controller about the given volume. The volume information
251 * is updated in the struct fsa_scsi_hba structure rather than returned.
254 static int probe_container(struct aac_dev *dev, int cid)
256 struct fsa_scsi_hba *fsa_dev_ptr;
258 struct aac_query_mount *dinfo;
259 struct aac_mount *dresp;
263 fsa_dev_ptr = &(dev->fsa_dev);
264 instance = dev->scsi_host_ptr->unique_id;
266 if (!(fibptr = fib_alloc(dev)))
271 dinfo = (struct aac_query_mount *)fib_data(fibptr);
273 dinfo->command = cpu_to_le32(VM_NameServe);
274 dinfo->count = cpu_to_le32(cid);
275 dinfo->type = cpu_to_le32(FT_FILESYS);
277 status = fib_send(ContainerCommand,
279 sizeof(struct aac_query_mount),
284 printk(KERN_WARNING "aacraid: probe_containers query failed.\n");
288 dresp = (struct aac_mount *) fib_data(fibptr);
290 if ((le32_to_cpu(dresp->status) == ST_OK) &&
291 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
292 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
293 fsa_dev_ptr->valid[cid] = 1;
294 fsa_dev_ptr->type[cid] = le32_to_cpu(dresp->mnt[0].vol);
295 fsa_dev_ptr->size[cid] = le32_to_cpu(dresp->mnt[0].capacity);
296 if (le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY)
297 fsa_dev_ptr->ro[cid] = 1;
301 fib_complete(fibptr);
307 /* Local Structure to set SCSI inquiry data strings */
309 char vid[8]; /* Vendor ID */
310 char pid[16]; /* Product ID */
311 char prl[4]; /* Product Revision Level */
315 * InqStrCopy - string merge
316 * @a: string to copy from
317 * @b: string to copy to
319 * Copy a String from one location to another
323 static void inqstrcpy(char *a, char *b)
330 static char *container_types[] = {
351 /* Function: setinqstr
353 * Arguments: [1] pointer to void [1] int
355 * Purpose: Sets SCSI inquiry data strings for vendor, product
356 * and revision level. Allows strings to be set in platform dependent
357 * files instead of in OS dependent driver source.
360 static void setinqstr(int devtype, void *data, int tindex)
362 struct scsi_inq *str;
364 struct aac_driver_ident *mp;
366 mp = aac_get_driver_ident(devtype);
368 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
370 inqstrcpy (mp->vname, str->vid);
371 inqstrcpy (mp->model, str->pid); /* last six chars reserved for vol type */
375 for ( ; *findit != ' '; findit++); /* walk till we find a space then incr by 1 */
378 if (tindex < (sizeof(container_types)/sizeof(char *))){
379 inqstrcpy (container_types[tindex], findit);
381 inqstrcpy ("V1.0", str->prl);
384 void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
385 u8 a_sense_code, u8 incorrect_length,
386 u8 bit_pointer, u16 field_pointer,
389 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
390 sense_buf[1] = 0; /* Segment number, always zero */
392 if (incorrect_length) {
393 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
394 sense_buf[3] = BYTE3(residue);
395 sense_buf[4] = BYTE2(residue);
396 sense_buf[5] = BYTE1(residue);
397 sense_buf[6] = BYTE0(residue);
399 sense_buf[2] = sense_key; /* Sense key */
401 if (sense_key == ILLEGAL_REQUEST)
402 sense_buf[7] = 10; /* Additional sense length */
404 sense_buf[7] = 6; /* Additional sense length */
406 sense_buf[12] = sense_code; /* Additional sense code */
407 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
408 if (sense_key == ILLEGAL_REQUEST) {
411 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
412 sense_buf[15] = 0x80;/* Std sense key specific field */
413 /* Illegal parameter is in the parameter block */
415 if (sense_code == SENCODE_INVALID_CDB_FIELD)
416 sense_buf[15] = 0xc0;/* Std sense key specific field */
417 /* Illegal parameter is in the CDB block */
418 sense_buf[15] |= bit_pointer;
419 sense_buf[16] = field_pointer >> 8; /* MSB */
420 sense_buf[17] = field_pointer; /* LSB */
424 static void aac_io_done(struct scsi_cmnd * scsicmd)
426 unsigned long cpu_flags;
427 struct Scsi_Host *host = scsicmd->device->host;
428 spin_lock_irqsave(host->host_lock, cpu_flags);
429 scsicmd->scsi_done(scsicmd);
430 spin_unlock_irqrestore(host->host_lock, cpu_flags);
433 static void __aac_io_done(struct scsi_cmnd * scsicmd)
435 scsicmd->scsi_done(scsicmd);
438 int aac_get_adapter_info(struct aac_dev* dev)
441 struct aac_adapter_info* info;
444 if (!(fibptr = fib_alloc(dev)))
448 info = (struct aac_adapter_info*) fib_data(fibptr);
450 memset(info,0,sizeof(struct aac_adapter_info));
452 rcode = fib_send(RequestAdapterInfo,
454 sizeof(struct aac_adapter_info),
460 memcpy(&dev->adapter_info, info, sizeof(struct aac_adapter_info));
462 tmp = dev->adapter_info.kernelrev;
463 printk(KERN_INFO"%s%d: kernel %d.%d.%d build %d\n",
465 tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
466 dev->adapter_info.kernelbuild);
467 tmp = dev->adapter_info.monitorrev;
468 printk(KERN_INFO"%s%d: monitor %d.%d.%d build %d\n",
470 tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
471 dev->adapter_info.monitorbuild);
472 tmp = dev->adapter_info.biosrev;
473 printk(KERN_INFO"%s%d: bios %d.%d.%d build %d\n",
475 tmp>>24,(tmp>>16)&0xff,(tmp>>8)&0xff,
476 dev->adapter_info.biosbuild);
477 printk(KERN_INFO"%s%d: serial %x%x\n",
479 dev->adapter_info.serial[0],
480 dev->adapter_info.serial[1]);
482 dev->nondasd_support = 0;
483 if(dev->adapter_info.options & AAC_OPT_NONDASD){
484 // dev->nondasd_support = 1;
485 // dmb - temporarily disable nondasd
488 dev->nondasd_support = (nondasd!=0);
490 if(dev->nondasd_support != 0){
491 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
494 dev->pae_support = 0;
495 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
496 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
497 dev->pae_support = 1;
501 dev->pae_support = (paemode!=0);
503 if(dev->pae_support != 0) {
504 printk(KERN_INFO"%s%d: 64 Bit PAE enabled\n", dev->name, dev->id);
505 pci_set_dma_mask(dev->pdev, (dma_addr_t)0xFFFFFFFFFFFFFFFFULL);
508 fib_complete(fibptr);
515 static void read_callback(void *context, struct fib * fibptr)
518 struct aac_read_reply *readreply;
519 struct scsi_cmnd *scsicmd;
523 scsicmd = (struct scsi_cmnd *) context;
525 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
526 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
528 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
529 dprintk((KERN_DEBUG "read_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
535 pci_unmap_sg(dev->pdev,
536 (struct scatterlist *)scsicmd->buffer,
538 scsicmd->sc_data_direction);
539 else if(scsicmd->request_bufflen)
540 pci_unmap_single(dev->pdev, (dma_addr_t)(ulong)scsicmd->SCp.ptr,
541 scsicmd->request_bufflen,
542 scsicmd->sc_data_direction);
543 readreply = (struct aac_read_reply *)fib_data(fibptr);
544 if (le32_to_cpu(readreply->status) == ST_OK)
545 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
547 printk(KERN_WARNING "read_callback: read failed, status = %d\n", readreply->status);
548 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
549 set_sense((u8 *) &sense_data[cid],
551 SENCODE_INTERNAL_TARGET_FAILURE,
552 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
554 memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof(struct sense_data));
556 fib_complete(fibptr);
559 aac_io_done(scsicmd);
562 static void write_callback(void *context, struct fib * fibptr)
565 struct aac_write_reply *writereply;
566 struct scsi_cmnd *scsicmd;
570 scsicmd = (struct scsi_cmnd *) context;
571 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
572 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
574 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
575 dprintk((KERN_DEBUG "write_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
580 pci_unmap_sg(dev->pdev,
581 (struct scatterlist *)scsicmd->buffer,
583 scsicmd->sc_data_direction);
584 else if(scsicmd->request_bufflen)
585 pci_unmap_single(dev->pdev, (dma_addr_t)(ulong)scsicmd->SCp.ptr,
586 scsicmd->request_bufflen,
587 scsicmd->sc_data_direction);
589 writereply = (struct aac_write_reply *) fib_data(fibptr);
590 if (le32_to_cpu(writereply->status) == ST_OK)
591 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
593 printk(KERN_WARNING "write_callback: write failed, status = %d\n", writereply->status);
594 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
595 set_sense((u8 *) &sense_data[cid],
597 SENCODE_INTERNAL_TARGET_FAILURE,
598 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
600 memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof(struct sense_data));
603 fib_complete(fibptr);
605 aac_io_done(scsicmd);
608 int aac_read(struct scsi_cmnd * scsicmd, int cid)
616 struct fib * cmd_fibcontext;
618 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
620 * Get block address and transfer length
622 if (scsicmd->cmnd[0] == READ_6) /* 6 byte command */
624 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", cid));
626 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
627 count = scsicmd->cmnd[4];
632 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", cid));
634 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
635 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
637 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
639 * Alocate and initialize a Fib
641 if (!(cmd_fibcontext = fib_alloc(dev))) {
645 fib_init(cmd_fibcontext);
647 if(dev->pae_support == 1){
648 struct aac_read64 *readcmd;
649 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
650 readcmd->command = cpu_to_le32(VM_CtHostRead64);
651 readcmd->cid = cpu_to_le16(cid);
652 readcmd->sector_count = cpu_to_le16(count);
653 readcmd->block = cpu_to_le32(lba);
654 readcmd->pad = cpu_to_le16(0);
655 readcmd->flags = cpu_to_le16(0);
657 aac_build_sg64(scsicmd, &readcmd->sg);
658 if(readcmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
660 fibsize = sizeof(struct aac_read64) + ((readcmd->sg.count - 1) * sizeof (struct sgentry64));
662 * Now send the Fib to the adapter
664 status = fib_send(ContainerCommand64,
669 (fib_callback) read_callback,
672 struct aac_read *readcmd;
673 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
674 readcmd->command = cpu_to_le32(VM_CtBlockRead);
675 readcmd->cid = cpu_to_le32(cid);
676 readcmd->block = cpu_to_le32(lba);
677 readcmd->count = cpu_to_le32(count * 512);
679 if (count * 512 > (64 * 1024))
682 aac_build_sg(scsicmd, &readcmd->sg);
683 if(readcmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
685 fibsize = sizeof(struct aac_read) + ((readcmd->sg.count - 1) * sizeof (struct sgentry));
687 * Now send the Fib to the adapter
689 status = fib_send(ContainerCommand,
694 (fib_callback) read_callback,
701 * Check that the command queued to the controller
703 if (status == -EINPROGRESS)
705 dprintk("read queued.\n");
709 printk(KERN_WARNING "aac_read: fib_send failed with status: %d.\n", status);
711 * For some reason, the Fib didn't queue, return QUEUE_FULL
713 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
714 aac_io_done(scsicmd);
715 fib_complete(cmd_fibcontext);
716 fib_free(cmd_fibcontext);
720 static int aac_write(struct scsi_cmnd * scsicmd, int cid)
727 struct fib * cmd_fibcontext;
729 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
731 * Get block address and transfer length
733 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
735 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
736 count = scsicmd->cmnd[4];
740 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", cid));
741 lba = (scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
742 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
744 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
746 * Allocate and initialize a Fib then setup a BlockWrite command
748 if (!(cmd_fibcontext = fib_alloc(dev))) {
749 scsicmd->result = DID_ERROR << 16;
750 aac_io_done(scsicmd);
753 fib_init(cmd_fibcontext);
755 if(dev->pae_support == 1){
756 struct aac_write64 *writecmd;
757 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
758 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
759 writecmd->cid = cpu_to_le16(cid);
760 writecmd->sector_count = cpu_to_le16(count);
761 writecmd->block = cpu_to_le32(lba);
762 writecmd->pad = cpu_to_le16(0);
763 writecmd->flags = cpu_to_le16(0);
765 aac_build_sg64(scsicmd, &writecmd->sg);
766 if(writecmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
768 fibsize = sizeof(struct aac_write64) + ((writecmd->sg.count - 1) * sizeof (struct sgentry64));
770 * Now send the Fib to the adapter
772 status = fib_send(ContainerCommand64,
777 (fib_callback) write_callback,
780 struct aac_write *writecmd;
781 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
782 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
783 writecmd->cid = cpu_to_le32(cid);
784 writecmd->block = cpu_to_le32(lba);
785 writecmd->count = cpu_to_le32(count * 512);
786 writecmd->sg.count = cpu_to_le32(1);
787 /* ->stable is not used - it did mean which type of write */
789 if (count * 512 > (64 * 1024)) {
793 aac_build_sg(scsicmd, &writecmd->sg);
794 if(writecmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)
796 fibsize = sizeof(struct aac_write) + ((writecmd->sg.count - 1) * sizeof (struct sgentry));
798 * Now send the Fib to the adapter
800 status = fib_send(ContainerCommand,
805 (fib_callback) write_callback,
810 * Check that the command queued to the controller
812 if (status == -EINPROGRESS)
814 dprintk("write queued.\n");
818 printk(KERN_WARNING "aac_write: fib_send failed with status: %d\n", status);
820 * For some reason, the Fib didn't queue, return QUEUE_FULL
822 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
823 aac_io_done(scsicmd);
825 fib_complete(cmd_fibcontext);
826 fib_free(cmd_fibcontext);
832 * aac_scsi_cmd() - Process SCSI command
833 * @scsicmd: SCSI command block
835 * Emulate a SCSI command and queue the required request for the
839 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
843 struct Scsi_Host *host = scsicmd->device->host;
844 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
845 struct fsa_scsi_hba *fsa_dev_ptr = &dev->fsa_dev;
846 int cardtype = dev->cardtype;
849 * If the bus, id or lun is out of range, return fail
850 * Test does not apply to ID 16, the pseudo id for the controller
853 if (scsicmd->device->id != host->this_id) {
854 if ((scsicmd->device->channel == 0) ){
855 if( (scsicmd->device->id >= MAXIMUM_NUM_CONTAINERS) || (scsicmd->device->lun != 0)){
856 scsicmd->result = DID_NO_CONNECT << 16;
857 __aac_io_done(scsicmd);
860 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
863 * If the target container doesn't exist, it may have
866 if (fsa_dev_ptr->valid[cid] == 0) {
867 switch (scsicmd->cmnd[0]) {
870 case TEST_UNIT_READY:
871 spin_unlock_irq(host->host_lock);
872 probe_container(dev, cid);
873 spin_lock_irq(host->host_lock);
874 if (fsa_dev_ptr->valid[cid] == 0) {
875 scsicmd->result = DID_NO_CONNECT << 16;
876 __aac_io_done(scsicmd);
884 * If the target container still doesn't exist,
887 if (fsa_dev_ptr->valid[cid] == 0) {
888 scsicmd->result = DID_BAD_TARGET << 16;
889 __aac_io_done(scsicmd);
892 } else { /* check for physical non-dasd devices */
893 if(dev->nondasd_support == 1){
894 return aac_send_srb_fib(scsicmd);
896 scsicmd->result = DID_NO_CONNECT << 16;
897 __aac_io_done(scsicmd);
903 * else Command for the controller itself
905 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
906 (scsicmd->cmnd[0] != TEST_UNIT_READY))
908 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
909 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
910 set_sense((u8 *) &sense_data[cid],
912 SENCODE_INVALID_COMMAND,
913 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
914 __aac_io_done(scsicmd);
915 memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof(struct sense_data));
920 /* Handle commands here that don't really require going out to the adapter */
921 switch (scsicmd->cmnd[0]) {
924 struct inquiry_data *inq_data_ptr;
926 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
927 inq_data_ptr = (struct inquiry_data *)scsicmd->request_buffer;
928 memset(inq_data_ptr, 0, sizeof (struct inquiry_data));
930 inq_data_ptr->inqd_ver = 2; /* claim compliance to SCSI-2 */
931 inq_data_ptr->inqd_dtq = 0x80; /* set RMB bit to one indicating that the medium is removable */
932 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 */
933 inq_data_ptr->inqd_len = 31;
934 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
935 inq_data_ptr->inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
937 * Set the Vendor, Product, and Revision Level
938 * see: <vendor>.c i.e. aac.c
940 setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr->type[cid]);
941 if (scsicmd->device->id == host->this_id)
942 inq_data_ptr->inqd_pdt = INQD_PDT_PROC; /* Processor device */
944 inq_data_ptr->inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
945 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
946 __aac_io_done(scsicmd);
954 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
955 capacity = fsa_dev_ptr->size[cid] - 1;
956 cp = scsicmd->request_buffer;
957 cp[0] = (capacity >> 24) & 0xff;
958 cp[1] = (capacity >> 16) & 0xff;
959 cp[2] = (capacity >> 8) & 0xff;
960 cp[3] = (capacity >> 0) & 0xff;
966 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
967 __aac_io_done(scsicmd);
976 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
977 mode_buf = scsicmd->request_buffer;
978 mode_buf[0] = 3; /* Mode data length */
979 mode_buf[1] = 0; /* Medium type - default */
980 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
981 mode_buf[3] = 0; /* Block descriptor length */
983 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
984 __aac_io_done(scsicmd);
992 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
993 mode_buf = scsicmd->request_buffer;
994 mode_buf[0] = 0; /* Mode data length (MSB) */
995 mode_buf[1] = 6; /* Mode data length (LSB) */
996 mode_buf[2] = 0; /* Medium type - default */
997 mode_buf[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
998 mode_buf[4] = 0; /* reserved */
999 mode_buf[5] = 0; /* reserved */
1000 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1001 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1003 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1004 __aac_io_done(scsicmd);
1009 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1010 memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof (struct sense_data));
1011 memset(&sense_data[cid], 0, sizeof (struct sense_data));
1012 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1013 __aac_io_done(scsicmd);
1016 case ALLOW_MEDIUM_REMOVAL:
1017 dprintk((KERN_DEBUG "LOCK command.\n"));
1018 if (scsicmd->cmnd[4])
1019 fsa_dev_ptr->locked[cid] = 1;
1021 fsa_dev_ptr->locked[cid] = 0;
1023 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1024 __aac_io_done(scsicmd);
1027 * These commands are all No-Ops
1029 case TEST_UNIT_READY:
1033 case REASSIGN_BLOCKS:
1036 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1037 __aac_io_done(scsicmd);
1041 switch (scsicmd->cmnd[0])
1046 * Hack to keep track of ordinal number of the device that
1047 * corresponds to a container. Needed to convert
1048 * containers to /dev/sd device names
1051 spin_unlock_irq(host->host_lock);
1052 if (scsicmd->request->rq_disk)
1053 memcpy(fsa_dev_ptr->devname[cid],
1054 scsicmd->request->rq_disk->disk_name,
1057 ret = aac_read(scsicmd, cid);
1058 spin_lock_irq(host->host_lock);
1063 spin_unlock_irq(host->host_lock);
1064 ret = aac_write(scsicmd, cid);
1065 spin_lock_irq(host->host_lock);
1069 * Unhandled commands
1071 printk(KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]);
1072 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1073 set_sense((u8 *) &sense_data[cid],
1074 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1075 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1076 memcpy(scsicmd->sense_buffer, &sense_data[cid],
1077 sizeof(struct sense_data));
1078 __aac_io_done(scsicmd);
1083 static int query_disk(struct aac_dev *dev, void __user *arg)
1085 struct aac_query_disk qd;
1086 struct fsa_scsi_hba *fsa_dev_ptr;
1088 fsa_dev_ptr = &(dev->fsa_dev);
1089 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1092 qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun);
1093 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1095 if (qd.cnum < 0 || qd.cnum >= MAXIMUM_NUM_CONTAINERS)
1097 qd.instance = dev->scsi_host_ptr->host_no;
1099 qd.id = CONTAINER_TO_ID(qd.cnum);
1100 qd.lun = CONTAINER_TO_LUN(qd.cnum);
1102 else return -EINVAL;
1104 qd.valid = fsa_dev_ptr->valid[qd.cnum];
1105 qd.locked = fsa_dev_ptr->locked[qd.cnum];
1106 qd.deleted = fsa_dev_ptr->deleted[qd.cnum];
1108 if (fsa_dev_ptr->devname[qd.cnum][0] == '\0')
1113 strlcpy(qd.name, fsa_dev_ptr->devname[qd.cnum], sizeof(qd.name));
1115 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
1120 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
1122 struct aac_delete_disk dd;
1123 struct fsa_scsi_hba *fsa_dev_ptr;
1125 fsa_dev_ptr = &(dev->fsa_dev);
1127 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1130 if (dd.cnum >= MAXIMUM_NUM_CONTAINERS)
1133 * Mark this container as being deleted.
1135 fsa_dev_ptr->deleted[dd.cnum] = 1;
1137 * Mark the container as no longer valid
1139 fsa_dev_ptr->valid[dd.cnum] = 0;
1143 static int delete_disk(struct aac_dev *dev, void __user *arg)
1145 struct aac_delete_disk dd;
1146 struct fsa_scsi_hba *fsa_dev_ptr;
1148 fsa_dev_ptr = &(dev->fsa_dev);
1150 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
1153 if (dd.cnum >= MAXIMUM_NUM_CONTAINERS)
1156 * If the container is locked, it can not be deleted by the API.
1158 if (fsa_dev_ptr->locked[dd.cnum])
1162 * Mark the container as no longer being valid.
1164 fsa_dev_ptr->valid[dd.cnum] = 0;
1165 fsa_dev_ptr->devname[dd.cnum][0] = '\0';
1170 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
1173 case FSACTL_QUERY_DISK:
1174 return query_disk(dev, arg);
1175 case FSACTL_DELETE_DISK:
1176 return delete_disk(dev, arg);
1177 case FSACTL_FORCE_DELETE_DISK:
1178 return force_delete_disk(dev, arg);
1179 case FSACTL_GET_CONTAINERS:
1180 return aac_get_containers(dev);
1189 * @context: the context set in the fib - here it is scsi cmd
1190 * @fibptr: pointer to the fib
1192 * Handles the completion of a scsi command to a non dasd device
1196 static void aac_srb_callback(void *context, struct fib * fibptr)
1198 struct aac_dev *dev;
1199 struct aac_srb_reply *srbreply;
1200 struct scsi_cmnd *scsicmd;
1202 scsicmd = (struct scsi_cmnd *) context;
1203 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1208 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
1210 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
1212 * Calculate resid for sg
1215 scsicmd->resid = scsicmd->request_bufflen - srbreply->data_xfer_length;
1218 pci_unmap_sg(dev->pdev,
1219 (struct scatterlist *)scsicmd->buffer,
1221 scsicmd->sc_data_direction);
1222 else if(scsicmd->request_bufflen)
1223 pci_unmap_single(dev->pdev, (ulong)scsicmd->SCp.ptr, scsicmd->request_bufflen,
1224 scsicmd->sc_data_direction);
1227 * First check the fib status
1230 if (le32_to_cpu(srbreply->status) != ST_OK){
1232 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
1233 len = (srbreply->sense_data_size > sizeof(scsicmd->sense_buffer))?
1234 sizeof(scsicmd->sense_buffer):srbreply->sense_data_size;
1235 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1236 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1240 * Next check the srb status
1242 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
1243 case SRB_STATUS_ERROR_RECOVERY:
1244 case SRB_STATUS_PENDING:
1245 case SRB_STATUS_SUCCESS:
1246 if(scsicmd->cmnd[0] == INQUIRY ){
1249 /* We can't expose disk devices because we can't tell whether they
1250 * are the raw container drives or stand alone drives. If they have
1251 * the removable bit set then we should expose them though.
1253 b = (*(u8*)scsicmd->buffer)&0x1f;
1254 b1 = ((u8*)scsicmd->buffer)[1];
1255 if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1256 || (b==TYPE_DISK && (b1&0x80)) ){
1257 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1259 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1262 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1265 case SRB_STATUS_DATA_OVERRUN:
1266 switch(scsicmd->cmnd[0]){
1273 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
1274 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
1276 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
1278 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1283 /* We can't expose disk devices because we can't tell whether they
1284 * are the raw container drives or stand alone drives
1286 b = (*(u8*)scsicmd->buffer)&0x0f;
1287 b1 = ((u8*)scsicmd->buffer)[1];
1288 if( b==TYPE_TAPE || b==TYPE_WORM || b==TYPE_ROM || b==TYPE_MOD|| b==TYPE_MEDIUM_CHANGER
1289 || (b==TYPE_DISK && (b1&0x80)) ){
1290 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1292 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1297 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
1301 case SRB_STATUS_ABORTED:
1302 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
1304 case SRB_STATUS_ABORT_FAILED:
1305 // Not sure about this one - but assuming the hba was trying to abort for some reason
1306 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
1308 case SRB_STATUS_PARITY_ERROR:
1309 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
1311 case SRB_STATUS_NO_DEVICE:
1312 case SRB_STATUS_INVALID_PATH_ID:
1313 case SRB_STATUS_INVALID_TARGET_ID:
1314 case SRB_STATUS_INVALID_LUN:
1315 case SRB_STATUS_SELECTION_TIMEOUT:
1316 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1319 case SRB_STATUS_COMMAND_TIMEOUT:
1320 case SRB_STATUS_TIMEOUT:
1321 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
1324 case SRB_STATUS_BUSY:
1325 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
1328 case SRB_STATUS_BUS_RESET:
1329 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
1332 case SRB_STATUS_MESSAGE_REJECTED:
1333 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
1335 case SRB_STATUS_REQUEST_FLUSHED:
1336 case SRB_STATUS_ERROR:
1337 case SRB_STATUS_INVALID_REQUEST:
1338 case SRB_STATUS_REQUEST_SENSE_FAILED:
1339 case SRB_STATUS_NO_HBA:
1340 case SRB_STATUS_UNEXPECTED_BUS_FREE:
1341 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
1342 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
1343 case SRB_STATUS_DELAYED_RETRY:
1344 case SRB_STATUS_BAD_FUNCTION:
1345 case SRB_STATUS_NOT_STARTED:
1346 case SRB_STATUS_NOT_IN_USE:
1347 case SRB_STATUS_FORCE_ABORT:
1348 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
1350 #ifdef AAC_DETAILED_STATUS_INFO
1351 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",le32_to_cpu(srbreply->srb_status&0x3f),aac_get_status_string(le32_to_cpu(srbreply->srb_status)), scsicmd->cmnd[0], le32_to_cpu(srbreply->scsi_status) );
1353 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
1356 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
1358 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
1359 len = (srbreply->sense_data_size > sizeof(scsicmd->sense_buffer))?
1360 sizeof(scsicmd->sense_buffer):srbreply->sense_data_size;
1361 dprintk((KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n", le32_to_cpu(srbreply->status), len));
1362 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
1366 * OR in the scsi status (already shifted up a bit)
1368 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
1370 fib_complete(fibptr);
1372 aac_io_done(scsicmd);
1378 * @scsicmd: the scsi command block
1380 * This routine will form a FIB and fill in the aac_srb from the
1381 * scsicmd passed in.
1384 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
1386 struct fib* cmd_fibcontext;
1387 struct aac_dev* dev;
1389 struct aac_srb *srbcmd;
1394 if( scsicmd->device->id > 15 || scsicmd->device->lun > 7) {
1395 scsicmd->result = DID_NO_CONNECT << 16;
1396 __aac_io_done(scsicmd);
1400 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1401 switch(scsicmd->sc_data_direction){
1405 case DMA_BIDIRECTIONAL:
1406 flag = SRB_DataIn | SRB_DataOut;
1408 case DMA_FROM_DEVICE:
1412 default: /* shuts up some versions of gcc */
1413 flag = SRB_NoDataXfer;
1419 * Allocate and initialize a Fib then setup a BlockWrite command
1421 if (!(cmd_fibcontext = fib_alloc(dev))) {
1424 fib_init(cmd_fibcontext);
1426 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
1427 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1428 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel));
1429 srbcmd->id = cpu_to_le32(scsicmd->device->id);
1430 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
1431 srbcmd->flags = cpu_to_le32(flag);
1432 timeout = (scsicmd->timeout-jiffies)/HZ;
1436 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1437 srbcmd->retry_limit =cpu_to_le32(0); // Obsolete parameter
1438 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
1440 if( dev->pae_support ==1 ) {
1441 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
1442 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1444 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1445 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1447 * Build Scatter/Gather list
1449 fibsize = sizeof (struct aac_srb) + (((srbcmd->sg.count & 0xff) - 1) * sizeof (struct sgentry64));
1452 * Now send the Fib to the adapter
1454 status = fib_send(ScsiPortCommand64, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
1455 (fib_callback) aac_srb_callback, (void *) scsicmd);
1457 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
1458 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
1460 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1461 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
1463 * Build Scatter/Gather list
1465 fibsize = sizeof (struct aac_srb) + (((srbcmd->sg.count & 0xff) - 1) * sizeof (struct sgentry));
1468 * Now send the Fib to the adapter
1470 status = fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
1471 (fib_callback) aac_srb_callback, (void *) scsicmd);
1474 * Check that the command queued to the controller
1476 if (status == -EINPROGRESS){
1480 printk(KERN_WARNING "aac_srb: fib_send failed with status: %d\n", status);
1481 fib_complete(cmd_fibcontext);
1482 fib_free(cmd_fibcontext);
1487 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
1489 struct aac_dev *dev;
1490 unsigned long byte_count = 0;
1492 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1493 // Get rid of old data
1494 psg->count = cpu_to_le32(0);
1495 psg->sg[0].addr = cpu_to_le32(0);
1496 psg->sg[0].count = cpu_to_le32(0);
1497 if (scsicmd->use_sg) {
1498 struct scatterlist *sg;
1501 sg = (struct scatterlist *) scsicmd->request_buffer;
1503 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
1504 scsicmd->sc_data_direction);
1505 psg->count = cpu_to_le32(sg_count);
1509 for (i = 0; i < sg_count; i++) {
1510 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
1511 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
1512 byte_count += sg_dma_len(sg);
1515 /* hba wants the size to be exact */
1516 if(byte_count > scsicmd->request_bufflen){
1517 psg->sg[i-1].count -= (byte_count - scsicmd->request_bufflen);
1518 byte_count = scsicmd->request_bufflen;
1520 /* Check for command underflow */
1521 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
1522 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
1523 byte_count, scsicmd->underflow);
1526 else if(scsicmd->request_bufflen) {
1528 addr = pci_map_single(dev->pdev,
1529 scsicmd->request_buffer,
1530 scsicmd->request_bufflen,
1531 scsicmd->sc_data_direction);
1532 psg->count = cpu_to_le32(1);
1533 psg->sg[0].addr = cpu_to_le32(addr);
1534 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
1535 scsicmd->SCp.ptr = (char *)(ulong)addr;
1536 byte_count = scsicmd->request_bufflen;
1542 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
1544 struct aac_dev *dev;
1545 unsigned long byte_count = 0;
1548 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1549 // Get rid of old data
1550 psg->count = cpu_to_le32(0);
1551 psg->sg[0].addr[0] = cpu_to_le32(0);
1552 psg->sg[0].addr[1] = cpu_to_le32(0);
1553 psg->sg[0].count = cpu_to_le32(0);
1554 if (scsicmd->use_sg) {
1555 struct scatterlist *sg;
1558 sg = (struct scatterlist *) scsicmd->request_buffer;
1560 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
1561 scsicmd->sc_data_direction);
1562 psg->count = cpu_to_le32(sg_count);
1566 for (i = 0; i < sg_count; i++) {
1567 le_addr = cpu_to_le64(sg_dma_address(sg));
1568 psg->sg[i].addr[1] = (u32)(le_addr>>32);
1569 psg->sg[i].addr[0] = (u32)(le_addr & 0xffffffff);
1570 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
1571 byte_count += sg_dma_len(sg);
1574 /* hba wants the size to be exact */
1575 if(byte_count > scsicmd->request_bufflen){
1576 psg->sg[i-1].count -= (byte_count - scsicmd->request_bufflen);
1577 byte_count = scsicmd->request_bufflen;
1579 /* Check for command underflow */
1580 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
1581 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
1582 byte_count, scsicmd->underflow);
1585 else if(scsicmd->request_bufflen) {
1587 addr = pci_map_single(dev->pdev,
1588 scsicmd->request_buffer,
1589 scsicmd->request_bufflen,
1590 scsicmd->sc_data_direction);
1591 psg->count = cpu_to_le32(1);
1592 le_addr = cpu_to_le64(addr);
1593 psg->sg[0].addr[1] = (u32)(le_addr>>32);
1594 psg->sg[0].addr[0] = (u32)(le_addr & 0xffffffff);
1595 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
1596 scsicmd->SCp.ptr = (char *)(ulong)addr;
1597 byte_count = scsicmd->request_bufflen;
1602 #ifdef AAC_DETAILED_STATUS_INFO
1604 struct aac_srb_status_info {
1610 static struct aac_srb_status_info srb_status_info[] = {
1611 { SRB_STATUS_PENDING, "Pending Status"},
1612 { SRB_STATUS_SUCCESS, "Success"},
1613 { SRB_STATUS_ABORTED, "Aborted Command"},
1614 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
1615 { SRB_STATUS_ERROR, "Error Event"},
1616 { SRB_STATUS_BUSY, "Device Busy"},
1617 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
1618 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
1619 { SRB_STATUS_NO_DEVICE, "No Device"},
1620 { SRB_STATUS_TIMEOUT, "Timeout"},
1621 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
1622 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
1623 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
1624 { SRB_STATUS_BUS_RESET, "Bus Reset"},
1625 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
1626 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
1627 { SRB_STATUS_NO_HBA, "No HBA"},
1628 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
1629 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
1630 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
1631 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
1632 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
1633 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
1634 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
1635 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
1636 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
1637 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
1638 { SRB_STATUS_NOT_STARTED, "Not Started"},
1639 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
1640 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
1641 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
1642 { 0xff, "Unknown Error"}
1645 char *aac_get_status_string(u32 status)
1649 for(i=0; i < (sizeof(srb_status_info)/sizeof(struct aac_srb_status_info)); i++ ){
1650 if(srb_status_info[i].status == status){
1651 return srb_status_info[i].str;
1655 return "Bad Status Code";