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 static int nondasd
= -1;
150 static int dacmode
= -1;
152 static int commit
= -1;
154 module_param(nondasd
, int, 0);
155 MODULE_PARM_DESC(nondasd
, "Control scanning of hba for nondasd devices. 0=off, 1=on");
156 module_param(dacmode
, int, 0);
157 MODULE_PARM_DESC(dacmode
, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
158 module_param(commit
, int, 0);
159 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");
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 le32_to_cpu(reply
->response
),
199 le32_to_cpu(reply
->status
),
200 le32_to_cpu(reply
->data
.action
)));
201 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
202 (le32_to_cpu(reply
->status
) != CT_OK
) ||
203 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
204 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
208 fib_complete(fibptr
);
209 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
212 struct aac_commit_config
* dinfo
;
214 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
216 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
217 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
219 status
= fib_send(ContainerCommand
,
221 sizeof (struct aac_commit_config
),
225 fib_complete(fibptr
);
226 } else if (commit
== 0) {
228 "aac_get_config_status: Foreign device configurations are being ignored\n");
236 * aac_get_containers - list containers
237 * @common: adapter to probe
239 * Make a list of all containers on this controller
241 int aac_get_containers(struct aac_dev
*dev
)
243 struct fsa_dev_info
*fsa_dev_ptr
;
248 struct aac_get_container_count
*dinfo
;
249 struct aac_get_container_count_resp
*dresp
;
250 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
252 instance
= dev
->scsi_host_ptr
->unique_id
;
254 if (!(fibptr
= fib_alloc(dev
)))
258 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
259 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
260 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
262 status
= fib_send(ContainerCommand
,
264 sizeof (struct aac_get_container_count
),
269 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
270 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
271 fib_complete(fibptr
);
274 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
275 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
277 fsa_dev_ptr
= (struct fsa_dev_info
*) kmalloc(
278 sizeof(*fsa_dev_ptr
) * maximum_num_containers
, GFP_KERNEL
);
283 memset(fsa_dev_ptr
, 0, sizeof(*fsa_dev_ptr
) * maximum_num_containers
);
285 dev
->fsa_dev
= fsa_dev_ptr
;
286 dev
->maximum_num_containers
= maximum_num_containers
;
288 for (index
= 0; index
< dev
->maximum_num_containers
; index
++) {
289 struct aac_query_mount
*dinfo
;
290 struct aac_mount
*dresp
;
292 fsa_dev_ptr
[index
].devname
[0] = '\0';
295 dinfo
= (struct aac_query_mount
*) fib_data(fibptr
);
297 dinfo
->command
= cpu_to_le32(VM_NameServe
);
298 dinfo
->count
= cpu_to_le32(index
);
299 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
301 status
= fib_send(ContainerCommand
,
303 sizeof (struct aac_query_mount
),
308 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
311 dresp
= (struct aac_mount
*)fib_data(fibptr
);
314 "VM_NameServe cid=%d status=%d vol=%d state=%d cap=%u\n",
315 (int)index
, (int)le32_to_cpu(dresp
->status
),
316 (int)le32_to_cpu(dresp
->mnt
[0].vol
),
317 (int)le32_to_cpu(dresp
->mnt
[0].state
),
318 (unsigned)le32_to_cpu(dresp
->mnt
[0].capacity
)));
319 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
320 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
321 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
322 fsa_dev_ptr
[index
].valid
= 1;
323 fsa_dev_ptr
[index
].type
= le32_to_cpu(dresp
->mnt
[0].vol
);
324 fsa_dev_ptr
[index
].size
= le32_to_cpu(dresp
->mnt
[0].capacity
);
325 if (le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
)
326 fsa_dev_ptr
[index
].ro
= 1;
328 fib_complete(fibptr
);
330 * If there are no more containers, then stop asking.
332 if ((index
+ 1) >= le32_to_cpu(dresp
->count
)){
340 static void aac_io_done(struct scsi_cmnd
* scsicmd
)
342 unsigned long cpu_flags
;
343 struct Scsi_Host
*host
= scsicmd
->device
->host
;
344 spin_lock_irqsave(host
->host_lock
, cpu_flags
);
345 scsicmd
->scsi_done(scsicmd
);
346 spin_unlock_irqrestore(host
->host_lock
, cpu_flags
);
349 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
351 struct aac_get_name_resp
* get_name_reply
;
352 struct scsi_cmnd
* scsicmd
;
354 scsicmd
= (struct scsi_cmnd
*) context
;
356 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
360 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
361 /* Failure is irrelevant, using default value instead */
362 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
363 && (get_name_reply
->data
[0] != '\0')) {
366 char * sp
= get_name_reply
->data
;
367 sp
[sizeof(((struct aac_get_name_resp
*)NULL
)->data
)-1] = '\0';
370 count
= sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
);
371 dp
= ((struct inquiry_data
*)scsicmd
->request_buffer
)->inqd_pid
;
373 *dp
++ = (*sp
) ? *sp
++ : ' ';
374 } while (--count
> 0);
376 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
378 fib_complete(fibptr
);
380 aac_io_done(scsicmd
);
384 * aac_get_container_name - get container name, none blocking.
386 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
, int cid
)
389 struct aac_get_name
*dinfo
;
390 struct fib
* cmd_fibcontext
;
391 struct aac_dev
* dev
;
393 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
395 if (!(cmd_fibcontext
= fib_alloc(dev
)))
398 fib_init(cmd_fibcontext
);
399 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
401 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
402 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
403 dinfo
->cid
= cpu_to_le32(cid
);
404 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_name_resp
*)NULL
)->data
));
406 status
= fib_send(ContainerCommand
,
408 sizeof (struct aac_get_name
),
411 (fib_callback
) get_container_name_callback
,
415 * Check that the command queued to the controller
417 if (status
== -EINPROGRESS
)
420 printk(KERN_WARNING
"aac_get_container_name: fib_send failed with status: %d.\n", status
);
421 fib_complete(cmd_fibcontext
);
422 fib_free(cmd_fibcontext
);
427 * probe_container - query a logical volume
428 * @dev: device to query
429 * @cid: container identifier
431 * Queries the controller about the given volume. The volume information
432 * is updated in the struct fsa_dev_info structure rather than returned.
435 static int probe_container(struct aac_dev
*dev
, int cid
)
437 struct fsa_dev_info
*fsa_dev_ptr
;
439 struct aac_query_mount
*dinfo
;
440 struct aac_mount
*dresp
;
444 fsa_dev_ptr
= dev
->fsa_dev
;
445 instance
= dev
->scsi_host_ptr
->unique_id
;
447 if (!(fibptr
= fib_alloc(dev
)))
452 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
454 dinfo
->command
= cpu_to_le32(VM_NameServe
);
455 dinfo
->count
= cpu_to_le32(cid
);
456 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
458 status
= fib_send(ContainerCommand
,
460 sizeof(struct aac_query_mount
),
465 printk(KERN_WARNING
"aacraid: probe_containers query failed.\n");
469 dresp
= (struct aac_mount
*) fib_data(fibptr
);
471 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
472 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
473 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
474 fsa_dev_ptr
[cid
].valid
= 1;
475 fsa_dev_ptr
[cid
].type
= le32_to_cpu(dresp
->mnt
[0].vol
);
476 fsa_dev_ptr
[cid
].size
= le32_to_cpu(dresp
->mnt
[0].capacity
);
477 if (le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
)
478 fsa_dev_ptr
[cid
].ro
= 1;
482 fib_complete(fibptr
);
488 /* Local Structure to set SCSI inquiry data strings */
490 char vid
[8]; /* Vendor ID */
491 char pid
[16]; /* Product ID */
492 char prl
[4]; /* Product Revision Level */
496 * InqStrCopy - string merge
497 * @a: string to copy from
498 * @b: string to copy to
500 * Copy a String from one location to another
504 static void inqstrcpy(char *a
, char *b
)
511 static char *container_types
[] = {
532 /* Function: setinqstr
534 * Arguments: [1] pointer to void [1] int
536 * Purpose: Sets SCSI inquiry data strings for vendor, product
537 * and revision level. Allows strings to be set in platform dependant
538 * files instead of in OS dependant driver source.
541 static void setinqstr(int devtype
, void *data
, int tindex
)
543 struct scsi_inq
*str
;
544 struct aac_driver_ident
*mp
;
546 mp
= aac_get_driver_ident(devtype
);
548 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
550 inqstrcpy (mp
->vname
, str
->vid
);
551 inqstrcpy (mp
->model
, str
->pid
); /* last six chars reserved for vol type */
553 if (tindex
< (sizeof(container_types
)/sizeof(char *))){
554 char *findit
= str
->pid
;
556 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
557 /* RAID is superfluous in the context of a RAID device */
558 if (memcmp(findit
-4, "RAID", 4) == 0)
559 *(findit
-= 4) = ' ';
560 inqstrcpy (container_types
[tindex
], findit
+ 1);
562 inqstrcpy ("V1.0", str
->prl
);
565 void set_sense(u8
*sense_buf
, u8 sense_key
, u8 sense_code
,
566 u8 a_sense_code
, u8 incorrect_length
,
567 u8 bit_pointer
, u16 field_pointer
,
570 sense_buf
[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
571 sense_buf
[1] = 0; /* Segment number, always zero */
573 if (incorrect_length
) {
574 sense_buf
[2] = sense_key
| 0x20;/* Set ILI bit | sense key */
575 sense_buf
[3] = BYTE3(residue
);
576 sense_buf
[4] = BYTE2(residue
);
577 sense_buf
[5] = BYTE1(residue
);
578 sense_buf
[6] = BYTE0(residue
);
580 sense_buf
[2] = sense_key
; /* Sense key */
582 if (sense_key
== ILLEGAL_REQUEST
)
583 sense_buf
[7] = 10; /* Additional sense length */
585 sense_buf
[7] = 6; /* Additional sense length */
587 sense_buf
[12] = sense_code
; /* Additional sense code */
588 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
589 if (sense_key
== ILLEGAL_REQUEST
) {
592 if (sense_code
== SENCODE_INVALID_PARAM_FIELD
)
593 sense_buf
[15] = 0x80;/* Std sense key specific field */
594 /* Illegal parameter is in the parameter block */
596 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
597 sense_buf
[15] = 0xc0;/* Std sense key specific field */
598 /* Illegal parameter is in the CDB block */
599 sense_buf
[15] |= bit_pointer
;
600 sense_buf
[16] = field_pointer
>> 8; /* MSB */
601 sense_buf
[17] = field_pointer
; /* LSB */
605 int aac_get_adapter_info(struct aac_dev
* dev
)
608 struct aac_adapter_info
* info
;
611 if (!(fibptr
= fib_alloc(dev
)))
615 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
617 memset(info
,0,sizeof(struct aac_adapter_info
));
619 rcode
= fib_send(RequestAdapterInfo
,
621 sizeof(struct aac_adapter_info
),
627 memcpy(&dev
->adapter_info
, info
, sizeof(struct aac_adapter_info
));
629 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
630 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d]\n",
636 le32_to_cpu(dev
->adapter_info
.kernelbuild
));
637 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
638 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
640 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
641 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
642 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
643 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
645 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
646 le32_to_cpu(dev
->adapter_info
.biosbuild
));
647 if (le32_to_cpu(dev
->adapter_info
.serial
[0]) != 0xBAD0)
648 printk(KERN_INFO
"%s%d: serial %x\n",
650 le32_to_cpu(dev
->adapter_info
.serial
[0]));
652 dev
->nondasd_support
= 0;
653 dev
->raid_scsi_mode
= 0;
654 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
){
655 dev
->nondasd_support
= 1;
659 * If the firmware supports ROMB RAID/SCSI mode and we are currently
660 * in RAID/SCSI mode, set the flag. For now if in this mode we will
661 * force nondasd support on. If we decide to allow the non-dasd flag
662 * additional changes changes will have to be made to support
663 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
664 * changed to support the new dev->raid_scsi_mode flag instead of
665 * leaching off of the dev->nondasd_support flag. Also in linit.c the
666 * function aac_detect will have to be modified where it sets up the
667 * max number of channels based on the aac->nondasd_support flag only.
669 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
670 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
671 dev
->nondasd_support
= 1;
672 dev
->raid_scsi_mode
= 1;
674 if (dev
->raid_scsi_mode
!= 0)
675 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
679 dev
->nondasd_support
= (nondasd
!=0);
681 if(dev
->nondasd_support
!= 0){
682 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
685 dev
->dac_support
= 0;
686 if( (sizeof(dma_addr_t
) > 4) && (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)){
687 printk(KERN_INFO
"%s%d: 64bit support enabled.\n", dev
->name
, dev
->id
);
688 dev
->dac_support
= 1;
692 dev
->dac_support
= (dacmode
!=0);
694 if(dev
->dac_support
!= 0) {
695 if (!pci_set_dma_mask(dev
->pdev
, 0xFFFFFFFFFFFFFFFFULL
) &&
696 !pci_set_consistent_dma_mask(dev
->pdev
, 0xFFFFFFFFFFFFFFFFULL
)) {
697 printk(KERN_INFO
"%s%d: 64 Bit DAC enabled\n",
699 } else if (!pci_set_dma_mask(dev
->pdev
, 0xFFFFFFFFULL
) &&
700 !pci_set_consistent_dma_mask(dev
->pdev
, 0xFFFFFFFFULL
)) {
701 printk(KERN_INFO
"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
703 dev
->dac_support
= 0;
705 printk(KERN_WARNING
"%s%d: No suitable DMA available.\n",
711 fib_complete(fibptr
);
718 static void read_callback(void *context
, struct fib
* fibptr
)
721 struct aac_read_reply
*readreply
;
722 struct scsi_cmnd
*scsicmd
;
726 scsicmd
= (struct scsi_cmnd
*) context
;
728 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
729 cid
= ID_LUN_TO_CONTAINER(scsicmd
->device
->id
, scsicmd
->device
->lun
);
731 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
732 dprintk((KERN_DEBUG
"read_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba
, jiffies
));
738 pci_unmap_sg(dev
->pdev
,
739 (struct scatterlist
*)scsicmd
->buffer
,
741 scsicmd
->sc_data_direction
);
742 else if(scsicmd
->request_bufflen
)
743 pci_unmap_single(dev
->pdev
, scsicmd
->SCp
.dma_handle
,
744 scsicmd
->request_bufflen
,
745 scsicmd
->sc_data_direction
);
746 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
747 if (le32_to_cpu(readreply
->status
) == ST_OK
)
748 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
750 printk(KERN_WARNING
"read_callback: read failed, status = %d\n",
751 le32_to_cpu(readreply
->status
));
752 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
753 set_sense((u8
*) &dev
->fsa_dev
[cid
].sense_data
,
755 SENCODE_INTERNAL_TARGET_FAILURE
,
756 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0,
758 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
759 (sizeof(dev
->fsa_dev
[cid
].sense_data
) > sizeof(scsicmd
->sense_buffer
))
760 ? sizeof(scsicmd
->sense_buffer
)
761 : sizeof(dev
->fsa_dev
[cid
].sense_data
));
763 fib_complete(fibptr
);
766 aac_io_done(scsicmd
);
769 static void write_callback(void *context
, struct fib
* fibptr
)
772 struct aac_write_reply
*writereply
;
773 struct scsi_cmnd
*scsicmd
;
777 scsicmd
= (struct scsi_cmnd
*) context
;
778 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
779 cid
= ID_LUN_TO_CONTAINER(scsicmd
->device
->id
, scsicmd
->device
->lun
);
781 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
782 dprintk((KERN_DEBUG
"write_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba
, jiffies
));
787 pci_unmap_sg(dev
->pdev
,
788 (struct scatterlist
*)scsicmd
->buffer
,
790 scsicmd
->sc_data_direction
);
791 else if(scsicmd
->request_bufflen
)
792 pci_unmap_single(dev
->pdev
, scsicmd
->SCp
.dma_handle
,
793 scsicmd
->request_bufflen
,
794 scsicmd
->sc_data_direction
);
796 writereply
= (struct aac_write_reply
*) fib_data(fibptr
);
797 if (le32_to_cpu(writereply
->status
) == ST_OK
)
798 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
800 printk(KERN_WARNING
"write_callback: write failed, status = %d\n", writereply
->status
);
801 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
802 set_sense((u8
*) &dev
->fsa_dev
[cid
].sense_data
,
804 SENCODE_INTERNAL_TARGET_FAILURE
,
805 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0,
807 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
808 sizeof(struct sense_data
));
811 fib_complete(fibptr
);
813 aac_io_done(scsicmd
);
816 int aac_read(struct scsi_cmnd
* scsicmd
, int cid
)
824 struct fib
* cmd_fibcontext
;
826 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
828 * Get block address and transfer length
830 if (scsicmd
->cmnd
[0] == READ_6
) /* 6 byte command */
832 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", cid
));
834 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
835 count
= scsicmd
->cmnd
[4];
840 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", cid
));
842 lba
= (scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
843 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
845 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba
, jiffies
));
847 * Alocate and initialize a Fib
849 if (!(cmd_fibcontext
= fib_alloc(dev
))) {
853 fib_init(cmd_fibcontext
);
855 if(dev
->dac_support
== 1) {
856 struct aac_read64
*readcmd
;
857 readcmd
= (struct aac_read64
*) fib_data(cmd_fibcontext
);
858 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
859 readcmd
->cid
= cpu_to_le16(cid
);
860 readcmd
->sector_count
= cpu_to_le16(count
);
861 readcmd
->block
= cpu_to_le32(lba
);
865 aac_build_sg64(scsicmd
, &readcmd
->sg
);
866 fibsize
= sizeof(struct aac_read64
) +
867 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
868 sizeof (struct sgentry64
));
869 BUG_ON (fibsize
> (sizeof(struct hw_fib
) -
870 sizeof(struct aac_fibhdr
)));
872 * Now send the Fib to the adapter
874 status
= fib_send(ContainerCommand64
,
879 (fib_callback
) read_callback
,
882 struct aac_read
*readcmd
;
883 readcmd
= (struct aac_read
*) fib_data(cmd_fibcontext
);
884 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
885 readcmd
->cid
= cpu_to_le32(cid
);
886 readcmd
->block
= cpu_to_le32(lba
);
887 readcmd
->count
= cpu_to_le32(count
* 512);
889 if (count
* 512 > (64 * 1024))
892 aac_build_sg(scsicmd
, &readcmd
->sg
);
893 fibsize
= sizeof(struct aac_read
) +
894 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
895 sizeof (struct sgentry
));
896 BUG_ON (fibsize
> (sizeof(struct hw_fib
) -
897 sizeof(struct aac_fibhdr
)));
899 * Now send the Fib to the adapter
901 status
= fib_send(ContainerCommand
,
906 (fib_callback
) read_callback
,
913 * Check that the command queued to the controller
915 if (status
== -EINPROGRESS
)
918 printk(KERN_WARNING
"aac_read: fib_send failed with status: %d.\n", status
);
920 * For some reason, the Fib didn't queue, return QUEUE_FULL
922 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
923 aac_io_done(scsicmd
);
924 fib_complete(cmd_fibcontext
);
925 fib_free(cmd_fibcontext
);
929 static int aac_write(struct scsi_cmnd
* scsicmd
, int cid
)
936 struct fib
* cmd_fibcontext
;
938 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
940 * Get block address and transfer length
942 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
944 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
945 count
= scsicmd
->cmnd
[4];
949 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", cid
));
950 lba
= (scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
951 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
953 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %u, t = %ld.\n",
954 smp_processor_id(), (unsigned long long)lba
, jiffies
));
956 * Allocate and initialize a Fib then setup a BlockWrite command
958 if (!(cmd_fibcontext
= fib_alloc(dev
))) {
959 scsicmd
->result
= DID_ERROR
<< 16;
960 aac_io_done(scsicmd
);
963 fib_init(cmd_fibcontext
);
965 if(dev
->dac_support
== 1) {
966 struct aac_write64
*writecmd
;
967 writecmd
= (struct aac_write64
*) fib_data(cmd_fibcontext
);
968 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
969 writecmd
->cid
= cpu_to_le16(cid
);
970 writecmd
->sector_count
= cpu_to_le16(count
);
971 writecmd
->block
= cpu_to_le32(lba
);
975 aac_build_sg64(scsicmd
, &writecmd
->sg
);
976 fibsize
= sizeof(struct aac_write64
) +
977 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
978 sizeof (struct sgentry64
));
979 BUG_ON (fibsize
> (sizeof(struct hw_fib
) -
980 sizeof(struct aac_fibhdr
)));
982 * Now send the Fib to the adapter
984 status
= fib_send(ContainerCommand64
,
989 (fib_callback
) write_callback
,
992 struct aac_write
*writecmd
;
993 writecmd
= (struct aac_write
*) fib_data(cmd_fibcontext
);
994 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
995 writecmd
->cid
= cpu_to_le32(cid
);
996 writecmd
->block
= cpu_to_le32(lba
);
997 writecmd
->count
= cpu_to_le32(count
* 512);
998 writecmd
->sg
.count
= cpu_to_le32(1);
999 /* ->stable is not used - it did mean which type of write */
1001 if (count
* 512 > (64 * 1024)) {
1005 aac_build_sg(scsicmd
, &writecmd
->sg
);
1006 fibsize
= sizeof(struct aac_write
) +
1007 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1008 sizeof (struct sgentry
));
1009 BUG_ON (fibsize
> (sizeof(struct hw_fib
) -
1010 sizeof(struct aac_fibhdr
)));
1012 * Now send the Fib to the adapter
1014 status
= fib_send(ContainerCommand
,
1019 (fib_callback
) write_callback
,
1024 * Check that the command queued to the controller
1026 if (status
== -EINPROGRESS
)
1028 dprintk("write queued.\n");
1032 printk(KERN_WARNING
"aac_write: fib_send failed with status: %d\n", status
);
1034 * For some reason, the Fib didn't queue, return QUEUE_FULL
1036 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
1037 aac_io_done(scsicmd
);
1039 fib_complete(cmd_fibcontext
);
1040 fib_free(cmd_fibcontext
);
1044 static void synchronize_callback(void *context
, struct fib
*fibptr
)
1046 struct aac_synchronize_reply
*synchronizereply
;
1047 struct scsi_cmnd
*cmd
;
1051 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
1052 smp_processor_id(), jiffies
));
1053 BUG_ON(fibptr
== NULL
);
1056 synchronizereply
= fib_data(fibptr
);
1057 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
1058 cmd
->result
= DID_OK
<< 16 |
1059 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1061 struct scsi_device
*sdev
= cmd
->device
;
1062 struct aac_dev
*dev
= (struct aac_dev
*)sdev
->host
->hostdata
;
1063 u32 cid
= ID_LUN_TO_CONTAINER(sdev
->id
, sdev
->lun
);
1065 "synchronize_callback: synchronize failed, status = %d\n",
1066 le32_to_cpu(synchronizereply
->status
));
1067 cmd
->result
= DID_OK
<< 16 |
1068 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
1069 set_sense((u8
*)&dev
->fsa_dev
[cid
].sense_data
,
1071 SENCODE_INTERNAL_TARGET_FAILURE
,
1072 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0,
1074 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1075 min(sizeof(dev
->fsa_dev
[cid
].sense_data
),
1076 sizeof(cmd
->sense_buffer
)));
1079 fib_complete(fibptr
);
1084 static int aac_synchronize(struct scsi_cmnd
*scsicmd
, int cid
)
1087 struct fib
*cmd_fibcontext
;
1088 struct aac_synchronize
*synchronizecmd
;
1089 struct scsi_cmnd
*cmd
;
1090 struct scsi_device
*sdev
= scsicmd
->device
;
1092 unsigned long flags
;
1095 * Wait for all commands to complete to this specific
1098 spin_lock_irqsave(&sdev
->list_lock
, flags
);
1099 list_for_each_entry(cmd
, &sdev
->cmd_list
, list
)
1100 if (cmd
!= scsicmd
&& cmd
->serial_number
!= 0) {
1105 spin_unlock_irqrestore(&sdev
->list_lock
, flags
);
1108 * Yield the processor (requeue for later)
1111 return SCSI_MLQUEUE_DEVICE_BUSY
;
1114 * Alocate and initialize a Fib
1116 if (!(cmd_fibcontext
=
1117 fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
)))
1118 return SCSI_MLQUEUE_HOST_BUSY
;
1120 fib_init(cmd_fibcontext
);
1122 synchronizecmd
= fib_data(cmd_fibcontext
);
1123 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
1124 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
1125 synchronizecmd
->cid
= cpu_to_le32(cid
);
1126 synchronizecmd
->count
=
1127 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
1130 * Now send the Fib to the adapter
1132 status
= fib_send(ContainerCommand
,
1134 sizeof(struct aac_synchronize
),
1137 (fib_callback
)synchronize_callback
,
1141 * Check that the command queued to the controller
1143 if (status
== -EINPROGRESS
)
1147 "aac_synchronize: fib_send failed with status: %d.\n", status
);
1148 fib_complete(cmd_fibcontext
);
1149 fib_free(cmd_fibcontext
);
1150 return SCSI_MLQUEUE_HOST_BUSY
;
1154 * aac_scsi_cmd() - Process SCSI command
1155 * @scsicmd: SCSI command block
1157 * Emulate a SCSI command and queue the required request for the
1161 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
1164 struct Scsi_Host
*host
= scsicmd
->device
->host
;
1165 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
1166 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
1167 int cardtype
= dev
->cardtype
;
1171 * If the bus, id or lun is out of range, return fail
1172 * Test does not apply to ID 16, the pseudo id for the controller
1175 if (scsicmd
->device
->id
!= host
->this_id
) {
1176 if ((scsicmd
->device
->channel
== 0) ){
1177 if( (scsicmd
->device
->id
>= dev
->maximum_num_containers
) || (scsicmd
->device
->lun
!= 0)){
1178 scsicmd
->result
= DID_NO_CONNECT
<< 16;
1179 scsicmd
->scsi_done(scsicmd
);
1182 cid
= ID_LUN_TO_CONTAINER(scsicmd
->device
->id
, scsicmd
->device
->lun
);
1185 * If the target container doesn't exist, it may have
1186 * been newly created
1188 if ((fsa_dev_ptr
[cid
].valid
& 1) == 0) {
1189 switch (scsicmd
->cmnd
[0]) {
1192 case TEST_UNIT_READY
:
1193 spin_unlock_irq(host
->host_lock
);
1194 probe_container(dev
, cid
);
1195 spin_lock_irq(host
->host_lock
);
1196 if (fsa_dev_ptr
[cid
].valid
== 0) {
1197 scsicmd
->result
= DID_NO_CONNECT
<< 16;
1198 scsicmd
->scsi_done(scsicmd
);
1206 * If the target container still doesn't exist,
1209 if (fsa_dev_ptr
[cid
].valid
== 0) {
1210 scsicmd
->result
= DID_BAD_TARGET
<< 16;
1211 scsicmd
->scsi_done(scsicmd
);
1214 } else { /* check for physical non-dasd devices */
1215 if(dev
->nondasd_support
== 1){
1216 return aac_send_srb_fib(scsicmd
);
1218 scsicmd
->result
= DID_NO_CONNECT
<< 16;
1219 scsicmd
->scsi_done(scsicmd
);
1225 * else Command for the controller itself
1227 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
1228 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
1230 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
1231 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
1232 set_sense((u8
*) &dev
->fsa_dev
[cid
].sense_data
,
1234 SENCODE_INVALID_COMMAND
,
1235 ASENCODE_INVALID_COMMAND
, 0, 0, 0, 0);
1236 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1237 (sizeof(dev
->fsa_dev
[cid
].sense_data
) > sizeof(scsicmd
->sense_buffer
))
1238 ? sizeof(scsicmd
->sense_buffer
)
1239 : sizeof(dev
->fsa_dev
[cid
].sense_data
));
1240 scsicmd
->scsi_done(scsicmd
);
1245 /* Handle commands here that don't really require going out to the adapter */
1246 switch (scsicmd
->cmnd
[0]) {
1249 struct inquiry_data
*inq_data_ptr
;
1251 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", scsicmd
->device
->id
));
1252 inq_data_ptr
= (struct inquiry_data
*)scsicmd
->request_buffer
;
1253 memset(inq_data_ptr
, 0, sizeof (struct inquiry_data
));
1255 inq_data_ptr
->inqd_ver
= 2; /* claim compliance to SCSI-2 */
1256 inq_data_ptr
->inqd_dtq
= 0x80; /* set RMB bit to one indicating that the medium is removable */
1257 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 */
1258 inq_data_ptr
->inqd_len
= 31;
1259 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1260 inq_data_ptr
->inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
1262 * Set the Vendor, Product, and Revision Level
1263 * see: <vendor>.c i.e. aac.c
1265 if (scsicmd
->device
->id
== host
->this_id
) {
1266 setinqstr(cardtype
, (void *) (inq_data_ptr
->inqd_vid
), (sizeof(container_types
)/sizeof(char *)));
1267 inq_data_ptr
->inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
1268 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1269 scsicmd
->scsi_done(scsicmd
);
1272 setinqstr(cardtype
, (void *) (inq_data_ptr
->inqd_vid
), fsa_dev_ptr
[cid
].type
);
1273 inq_data_ptr
->inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
1274 return aac_get_container_name(scsicmd
, cid
);
1281 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
1282 if (fsa_dev_ptr
[cid
].size
<= 0x100000000LL
)
1283 capacity
= fsa_dev_ptr
[cid
].size
- 1;
1286 cp
= scsicmd
->request_buffer
;
1287 cp
[0] = (capacity
>> 24) & 0xff;
1288 cp
[1] = (capacity
>> 16) & 0xff;
1289 cp
[2] = (capacity
>> 8) & 0xff;
1290 cp
[3] = (capacity
>> 0) & 0xff;
1296 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1297 scsicmd
->scsi_done(scsicmd
);
1306 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
1307 mode_buf
= scsicmd
->request_buffer
;
1308 mode_buf
[0] = 3; /* Mode data length */
1309 mode_buf
[1] = 0; /* Medium type - default */
1310 mode_buf
[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1311 mode_buf
[3] = 0; /* Block descriptor length */
1313 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1314 scsicmd
->scsi_done(scsicmd
);
1322 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
1323 mode_buf
= scsicmd
->request_buffer
;
1324 mode_buf
[0] = 0; /* Mode data length (MSB) */
1325 mode_buf
[1] = 6; /* Mode data length (LSB) */
1326 mode_buf
[2] = 0; /* Medium type - default */
1327 mode_buf
[3] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1328 mode_buf
[4] = 0; /* reserved */
1329 mode_buf
[5] = 0; /* reserved */
1330 mode_buf
[6] = 0; /* Block descriptor length (MSB) */
1331 mode_buf
[7] = 0; /* Block descriptor length (LSB) */
1333 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1334 scsicmd
->scsi_done(scsicmd
);
1339 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
1340 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
, sizeof (struct sense_data
));
1341 memset(&dev
->fsa_dev
[cid
].sense_data
, 0, sizeof (struct sense_data
));
1342 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1343 scsicmd
->scsi_done(scsicmd
);
1346 case ALLOW_MEDIUM_REMOVAL
:
1347 dprintk((KERN_DEBUG
"LOCK command.\n"));
1348 if (scsicmd
->cmnd
[4])
1349 fsa_dev_ptr
[cid
].locked
= 1;
1351 fsa_dev_ptr
[cid
].locked
= 0;
1353 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1354 scsicmd
->scsi_done(scsicmd
);
1357 * These commands are all No-Ops
1359 case TEST_UNIT_READY
:
1363 case REASSIGN_BLOCKS
:
1366 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1367 scsicmd
->scsi_done(scsicmd
);
1371 switch (scsicmd
->cmnd
[0])
1376 * Hack to keep track of ordinal number of the device that
1377 * corresponds to a container. Needed to convert
1378 * containers to /dev/sd device names
1381 spin_unlock_irq(host
->host_lock
);
1382 if (scsicmd
->request
->rq_disk
)
1383 memcpy(fsa_dev_ptr
[cid
].devname
,
1384 scsicmd
->request
->rq_disk
->disk_name
,
1387 ret
= aac_read(scsicmd
, cid
);
1388 spin_lock_irq(host
->host_lock
);
1393 spin_unlock_irq(host
->host_lock
);
1394 ret
= aac_write(scsicmd
, cid
);
1395 spin_lock_irq(host
->host_lock
);
1398 case SYNCHRONIZE_CACHE
:
1399 /* Issue FIB to tell Firmware to flush it's cache */
1400 return aac_synchronize(scsicmd
, cid
);
1404 * Unhandled commands
1406 printk(KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n", scsicmd
->cmnd
[0]);
1407 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
1408 set_sense((u8
*) &dev
->fsa_dev
[cid
].sense_data
,
1409 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
1410 ASENCODE_INVALID_COMMAND
, 0, 0, 0, 0);
1411 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1412 (sizeof(dev
->fsa_dev
[cid
].sense_data
) > sizeof(scsicmd
->sense_buffer
))
1413 ? sizeof(scsicmd
->sense_buffer
)
1414 : sizeof(dev
->fsa_dev
[cid
].sense_data
));
1415 scsicmd
->scsi_done(scsicmd
);
1420 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
1422 struct aac_query_disk qd
;
1423 struct fsa_dev_info
*fsa_dev_ptr
;
1425 fsa_dev_ptr
= dev
->fsa_dev
;
1426 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
1429 qd
.cnum
= ID_LUN_TO_CONTAINER(qd
.id
, qd
.lun
);
1430 else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1))
1432 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
1434 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
1436 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
1437 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
1439 else return -EINVAL
;
1441 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
;
1442 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
1443 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
1445 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
1450 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
1451 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
1453 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
1458 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
1460 struct aac_delete_disk dd
;
1461 struct fsa_dev_info
*fsa_dev_ptr
;
1463 fsa_dev_ptr
= dev
->fsa_dev
;
1465 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
1468 if (dd
.cnum
>= dev
->maximum_num_containers
)
1471 * Mark this container as being deleted.
1473 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
1475 * Mark the container as no longer valid
1477 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
1481 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
1483 struct aac_delete_disk dd
;
1484 struct fsa_dev_info
*fsa_dev_ptr
;
1486 fsa_dev_ptr
= dev
->fsa_dev
;
1488 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
1491 if (dd
.cnum
>= dev
->maximum_num_containers
)
1494 * If the container is locked, it can not be deleted by the API.
1496 if (fsa_dev_ptr
[dd
.cnum
].locked
)
1500 * Mark the container as no longer being valid.
1502 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
1503 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
1508 int aac_dev_ioctl(struct aac_dev
*dev
, int cmd
, void __user
*arg
)
1511 case FSACTL_QUERY_DISK
:
1512 return query_disk(dev
, arg
);
1513 case FSACTL_DELETE_DISK
:
1514 return delete_disk(dev
, arg
);
1515 case FSACTL_FORCE_DELETE_DISK
:
1516 return force_delete_disk(dev
, arg
);
1517 case FSACTL_GET_CONTAINERS
:
1518 return aac_get_containers(dev
);
1527 * @context: the context set in the fib - here it is scsi cmd
1528 * @fibptr: pointer to the fib
1530 * Handles the completion of a scsi command to a non dasd device
1534 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
1536 struct aac_dev
*dev
;
1537 struct aac_srb_reply
*srbreply
;
1538 struct scsi_cmnd
*scsicmd
;
1540 scsicmd
= (struct scsi_cmnd
*) context
;
1541 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1546 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
1548 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
1550 * Calculate resid for sg
1553 scsicmd
->resid
= scsicmd
->request_bufflen
-
1554 le32_to_cpu(srbreply
->data_xfer_length
);
1557 pci_unmap_sg(dev
->pdev
,
1558 (struct scatterlist
*)scsicmd
->buffer
,
1560 scsicmd
->sc_data_direction
);
1561 else if(scsicmd
->request_bufflen
)
1562 pci_unmap_single(dev
->pdev
, scsicmd
->SCp
.dma_handle
, scsicmd
->request_bufflen
,
1563 scsicmd
->sc_data_direction
);
1566 * First check the fib status
1569 if (le32_to_cpu(srbreply
->status
) != ST_OK
){
1571 printk(KERN_WARNING
"aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply
->status
));
1572 len
= (le32_to_cpu(srbreply
->sense_data_size
) >
1573 sizeof(scsicmd
->sense_buffer
)) ?
1574 sizeof(scsicmd
->sense_buffer
) :
1575 le32_to_cpu(srbreply
->sense_data_size
);
1576 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
1577 memcpy(scsicmd
->sense_buffer
, srbreply
->sense_data
, len
);
1581 * Next check the srb status
1583 switch( (le32_to_cpu(srbreply
->srb_status
))&0x3f){
1584 case SRB_STATUS_ERROR_RECOVERY
:
1585 case SRB_STATUS_PENDING
:
1586 case SRB_STATUS_SUCCESS
:
1587 if(scsicmd
->cmnd
[0] == INQUIRY
){
1590 /* We can't expose disk devices because we can't tell whether they
1591 * are the raw container drives or stand alone drives. If they have
1592 * the removable bit set then we should expose them though.
1594 b
= (*(u8
*)scsicmd
->buffer
)&0x1f;
1595 b1
= ((u8
*)scsicmd
->buffer
)[1];
1596 if( b
==TYPE_TAPE
|| b
==TYPE_WORM
|| b
==TYPE_ROM
|| b
==TYPE_MOD
|| b
==TYPE_MEDIUM_CHANGER
1597 || (b
==TYPE_DISK
&& (b1
&0x80)) ){
1598 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
1600 * We will allow disk devices if in RAID/SCSI mode and
1603 } else if ((dev
->raid_scsi_mode
) &&
1604 (scsicmd
->device
->channel
== 2)) {
1605 scsicmd
->result
= DID_OK
<< 16 |
1606 COMMAND_COMPLETE
<< 8;
1608 scsicmd
->result
= DID_NO_CONNECT
<< 16 |
1609 COMMAND_COMPLETE
<< 8;
1612 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
1615 case SRB_STATUS_DATA_OVERRUN
:
1616 switch(scsicmd
->cmnd
[0]){
1623 if(le32_to_cpu(srbreply
->data_xfer_length
) < scsicmd
->underflow
) {
1624 printk(KERN_WARNING
"aacraid: SCSI CMD underflow\n");
1626 printk(KERN_WARNING
"aacraid: SCSI CMD Data Overrun\n");
1628 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
1633 /* We can't expose disk devices because we can't tell whether they
1634 * are the raw container drives or stand alone drives
1636 b
= (*(u8
*)scsicmd
->buffer
)&0x0f;
1637 b1
= ((u8
*)scsicmd
->buffer
)[1];
1638 if( b
==TYPE_TAPE
|| b
==TYPE_WORM
|| b
==TYPE_ROM
|| b
==TYPE_MOD
|| b
==TYPE_MEDIUM_CHANGER
1639 || (b
==TYPE_DISK
&& (b1
&0x80)) ){
1640 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
1642 * We will allow disk devices if in RAID/SCSI mode and
1645 } else if ((dev
->raid_scsi_mode
) &&
1646 (scsicmd
->device
->channel
== 2)) {
1647 scsicmd
->result
= DID_OK
<< 16 |
1648 COMMAND_COMPLETE
<< 8;
1650 scsicmd
->result
= DID_NO_CONNECT
<< 16 |
1651 COMMAND_COMPLETE
<< 8;
1656 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
1660 case SRB_STATUS_ABORTED
:
1661 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
1663 case SRB_STATUS_ABORT_FAILED
:
1664 // Not sure about this one - but assuming the hba was trying to abort for some reason
1665 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
1667 case SRB_STATUS_PARITY_ERROR
:
1668 scsicmd
->result
= DID_PARITY
<< 16 | MSG_PARITY_ERROR
<< 8;
1670 case SRB_STATUS_NO_DEVICE
:
1671 case SRB_STATUS_INVALID_PATH_ID
:
1672 case SRB_STATUS_INVALID_TARGET_ID
:
1673 case SRB_STATUS_INVALID_LUN
:
1674 case SRB_STATUS_SELECTION_TIMEOUT
:
1675 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
1678 case SRB_STATUS_COMMAND_TIMEOUT
:
1679 case SRB_STATUS_TIMEOUT
:
1680 scsicmd
->result
= DID_TIME_OUT
<< 16 | COMMAND_COMPLETE
<< 8;
1683 case SRB_STATUS_BUSY
:
1684 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
1687 case SRB_STATUS_BUS_RESET
:
1688 scsicmd
->result
= DID_RESET
<< 16 | COMMAND_COMPLETE
<< 8;
1691 case SRB_STATUS_MESSAGE_REJECTED
:
1692 scsicmd
->result
= DID_ERROR
<< 16 | MESSAGE_REJECT
<< 8;
1694 case SRB_STATUS_REQUEST_FLUSHED
:
1695 case SRB_STATUS_ERROR
:
1696 case SRB_STATUS_INVALID_REQUEST
:
1697 case SRB_STATUS_REQUEST_SENSE_FAILED
:
1698 case SRB_STATUS_NO_HBA
:
1699 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
1700 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
1701 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
1702 case SRB_STATUS_DELAYED_RETRY
:
1703 case SRB_STATUS_BAD_FUNCTION
:
1704 case SRB_STATUS_NOT_STARTED
:
1705 case SRB_STATUS_NOT_IN_USE
:
1706 case SRB_STATUS_FORCE_ABORT
:
1707 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
1709 #ifdef AAC_DETAILED_STATUS_INFO
1710 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
1711 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
1712 aac_get_status_string(
1713 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
1715 le32_to_cpu(srbreply
->scsi_status
));
1717 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
1720 if (le32_to_cpu(srbreply
->scsi_status
) == 0x02 ){ // Check Condition
1722 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
1723 len
= (le32_to_cpu(srbreply
->sense_data_size
) >
1724 sizeof(scsicmd
->sense_buffer
)) ?
1725 sizeof(scsicmd
->sense_buffer
) :
1726 le32_to_cpu(srbreply
->sense_data_size
);
1727 #ifdef AAC_DETAILED_STATUS_INFO
1728 dprintk((KERN_WARNING
"aac_srb_callback: check condition, status = %d len=%d\n",
1729 le32_to_cpu(srbreply
->status
), len
));
1731 memcpy(scsicmd
->sense_buffer
, srbreply
->sense_data
, len
);
1735 * OR in the scsi status (already shifted up a bit)
1737 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
1739 fib_complete(fibptr
);
1741 aac_io_done(scsicmd
);
1747 * @scsicmd: the scsi command block
1749 * This routine will form a FIB and fill in the aac_srb from the
1750 * scsicmd passed in.
1753 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
1755 struct fib
* cmd_fibcontext
;
1756 struct aac_dev
* dev
;
1758 struct aac_srb
*srbcmd
;
1763 if( scsicmd
->device
->id
> 15 || scsicmd
->device
->lun
> 7) {
1764 scsicmd
->result
= DID_NO_CONNECT
<< 16;
1765 scsicmd
->scsi_done(scsicmd
);
1769 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1770 switch(scsicmd
->sc_data_direction
){
1774 case DMA_BIDIRECTIONAL
:
1775 flag
= SRB_DataIn
| SRB_DataOut
;
1777 case DMA_FROM_DEVICE
:
1781 default: /* shuts up some versions of gcc */
1782 flag
= SRB_NoDataXfer
;
1788 * Allocate and initialize a Fib then setup a BlockWrite command
1790 if (!(cmd_fibcontext
= fib_alloc(dev
))) {
1793 fib_init(cmd_fibcontext
);
1795 srbcmd
= (struct aac_srb
*) fib_data(cmd_fibcontext
);
1796 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1797 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scsicmd
->device
->channel
));
1798 srbcmd
->id
= cpu_to_le32(scsicmd
->device
->id
);
1799 srbcmd
->lun
= cpu_to_le32(scsicmd
->device
->lun
);
1800 srbcmd
->flags
= cpu_to_le32(flag
);
1801 timeout
= (scsicmd
->timeout
-jiffies
)/HZ
;
1805 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1806 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1807 srbcmd
->cdb_size
= cpu_to_le32(scsicmd
->cmd_len
);
1809 if( dev
->dac_support
== 1 ) {
1810 aac_build_sg64(scsicmd
, (struct sgmap64
*) &srbcmd
->sg
);
1811 srbcmd
->count
= cpu_to_le32(scsicmd
->request_bufflen
);
1813 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1814 memcpy(srbcmd
->cdb
, scsicmd
->cmnd
, scsicmd
->cmd_len
);
1816 * Build Scatter/Gather list
1818 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1819 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1820 sizeof (struct sgentry64
));
1821 BUG_ON (fibsize
> (sizeof(struct hw_fib
) -
1822 sizeof(struct aac_fibhdr
)));
1825 * Now send the Fib to the adapter
1827 status
= fib_send(ScsiPortCommand64
, cmd_fibcontext
,
1828 fibsize
, FsaNormal
, 0, 1,
1829 (fib_callback
) aac_srb_callback
,
1832 aac_build_sg(scsicmd
, (struct sgmap
*)&srbcmd
->sg
);
1833 srbcmd
->count
= cpu_to_le32(scsicmd
->request_bufflen
);
1835 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1836 memcpy(srbcmd
->cdb
, scsicmd
->cmnd
, scsicmd
->cmd_len
);
1838 * Build Scatter/Gather list
1840 fibsize
= sizeof (struct aac_srb
) +
1841 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1842 sizeof (struct sgentry
));
1843 BUG_ON (fibsize
> (sizeof(struct hw_fib
) -
1844 sizeof(struct aac_fibhdr
)));
1847 * Now send the Fib to the adapter
1849 status
= fib_send(ScsiPortCommand
, cmd_fibcontext
, fibsize
, FsaNormal
, 0, 1,
1850 (fib_callback
) aac_srb_callback
, (void *) scsicmd
);
1853 * Check that the command queued to the controller
1855 if (status
== -EINPROGRESS
){
1859 printk(KERN_WARNING
"aac_srb: fib_send failed with status: %d\n", status
);
1860 fib_complete(cmd_fibcontext
);
1861 fib_free(cmd_fibcontext
);
1866 static unsigned long aac_build_sg(struct scsi_cmnd
* scsicmd
, struct sgmap
* psg
)
1868 struct aac_dev
*dev
;
1869 unsigned long byte_count
= 0;
1871 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1872 // Get rid of old data
1874 psg
->sg
[0].addr
= 0;
1875 psg
->sg
[0].count
= 0;
1876 if (scsicmd
->use_sg
) {
1877 struct scatterlist
*sg
;
1880 sg
= (struct scatterlist
*) scsicmd
->request_buffer
;
1882 sg_count
= pci_map_sg(dev
->pdev
, sg
, scsicmd
->use_sg
,
1883 scsicmd
->sc_data_direction
);
1884 psg
->count
= cpu_to_le32(sg_count
);
1888 for (i
= 0; i
< sg_count
; i
++) {
1889 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
1890 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
1891 byte_count
+= sg_dma_len(sg
);
1894 /* hba wants the size to be exact */
1895 if(byte_count
> scsicmd
->request_bufflen
){
1896 psg
->sg
[i
-1].count
-= (byte_count
- scsicmd
->request_bufflen
);
1897 byte_count
= scsicmd
->request_bufflen
;
1899 /* Check for command underflow */
1900 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
1901 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
1902 byte_count
, scsicmd
->underflow
);
1905 else if(scsicmd
->request_bufflen
) {
1907 addr
= pci_map_single(dev
->pdev
,
1908 scsicmd
->request_buffer
,
1909 scsicmd
->request_bufflen
,
1910 scsicmd
->sc_data_direction
);
1911 psg
->count
= cpu_to_le32(1);
1912 psg
->sg
[0].addr
= cpu_to_le32(addr
);
1913 psg
->sg
[0].count
= cpu_to_le32(scsicmd
->request_bufflen
);
1914 scsicmd
->SCp
.dma_handle
= addr
;
1915 byte_count
= scsicmd
->request_bufflen
;
1921 static unsigned long aac_build_sg64(struct scsi_cmnd
* scsicmd
, struct sgmap64
* psg
)
1923 struct aac_dev
*dev
;
1924 unsigned long byte_count
= 0;
1927 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1928 // Get rid of old data
1930 psg
->sg
[0].addr
[0] = 0;
1931 psg
->sg
[0].addr
[1] = 0;
1932 psg
->sg
[0].count
= 0;
1933 if (scsicmd
->use_sg
) {
1934 struct scatterlist
*sg
;
1937 sg
= (struct scatterlist
*) scsicmd
->request_buffer
;
1939 sg_count
= pci_map_sg(dev
->pdev
, sg
, scsicmd
->use_sg
,
1940 scsicmd
->sc_data_direction
);
1941 psg
->count
= cpu_to_le32(sg_count
);
1945 for (i
= 0; i
< sg_count
; i
++) {
1946 le_addr
= cpu_to_le64(sg_dma_address(sg
));
1947 psg
->sg
[i
].addr
[1] = (u32
)(le_addr
>>32);
1948 psg
->sg
[i
].addr
[0] = (u32
)(le_addr
& 0xffffffff);
1949 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
1950 byte_count
+= sg_dma_len(sg
);
1953 /* hba wants the size to be exact */
1954 if(byte_count
> scsicmd
->request_bufflen
){
1955 psg
->sg
[i
-1].count
-= (byte_count
- scsicmd
->request_bufflen
);
1956 byte_count
= scsicmd
->request_bufflen
;
1958 /* Check for command underflow */
1959 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
1960 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
1961 byte_count
, scsicmd
->underflow
);
1964 else if(scsicmd
->request_bufflen
) {
1966 addr
= pci_map_single(dev
->pdev
,
1967 scsicmd
->request_buffer
,
1968 scsicmd
->request_bufflen
,
1969 scsicmd
->sc_data_direction
);
1970 psg
->count
= cpu_to_le32(1);
1971 le_addr
= cpu_to_le64(addr
);
1972 psg
->sg
[0].addr
[1] = (u32
)(le_addr
>>32);
1973 psg
->sg
[0].addr
[0] = (u32
)(le_addr
& 0xffffffff);
1974 psg
->sg
[0].count
= cpu_to_le32(scsicmd
->request_bufflen
);
1975 scsicmd
->SCp
.dma_handle
= addr
;
1976 byte_count
= scsicmd
->request_bufflen
;
1981 #ifdef AAC_DETAILED_STATUS_INFO
1983 struct aac_srb_status_info
{
1989 static struct aac_srb_status_info srb_status_info
[] = {
1990 { SRB_STATUS_PENDING
, "Pending Status"},
1991 { SRB_STATUS_SUCCESS
, "Success"},
1992 { SRB_STATUS_ABORTED
, "Aborted Command"},
1993 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
1994 { SRB_STATUS_ERROR
, "Error Event"},
1995 { SRB_STATUS_BUSY
, "Device Busy"},
1996 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
1997 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
1998 { SRB_STATUS_NO_DEVICE
, "No Device"},
1999 { SRB_STATUS_TIMEOUT
, "Timeout"},
2000 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
2001 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
2002 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
2003 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
2004 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
2005 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
2006 { SRB_STATUS_NO_HBA
, "No HBA"},
2007 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
2008 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
2009 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
2010 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
2011 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
2012 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
2013 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
2014 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
2015 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
2016 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
2017 { SRB_STATUS_NOT_STARTED
, "Not Started"},
2018 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
2019 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
2020 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
2021 { 0xff, "Unknown Error"}
2024 char *aac_get_status_string(u32 status
)
2028 for(i
=0; i
< (sizeof(srb_status_info
)/sizeof(struct aac_srb_status_info
)); i
++ ){
2029 if(srb_status_info
[i
].status
== status
){
2030 return srb_status_info
[i
].str
;
2034 return "Bad Status Code";