2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/types.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/uaccess.h>
36 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
37 #include <linux/module.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_cmnd.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_host.h>
46 /* values for inqd_pdt: Peripheral device type in plain English */
47 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
48 #define INQD_PDT_PROC 0x03 /* Processor device */
49 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
50 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
51 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
52 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
54 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
55 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
61 #define SENCODE_NO_SENSE 0x00
62 #define SENCODE_END_OF_DATA 0x00
63 #define SENCODE_BECOMING_READY 0x04
64 #define SENCODE_INIT_CMD_REQUIRED 0x04
65 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
66 #define SENCODE_INVALID_COMMAND 0x20
67 #define SENCODE_LBA_OUT_OF_RANGE 0x21
68 #define SENCODE_INVALID_CDB_FIELD 0x24
69 #define SENCODE_LUN_NOT_SUPPORTED 0x25
70 #define SENCODE_INVALID_PARAM_FIELD 0x26
71 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
72 #define SENCODE_PARAM_VALUE_INVALID 0x26
73 #define SENCODE_RESET_OCCURRED 0x29
74 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
75 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
76 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
77 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
78 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
79 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
80 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
81 #define SENCODE_OVERLAPPED_COMMAND 0x4E
84 * Additional sense codes
87 #define ASENCODE_NO_SENSE 0x00
88 #define ASENCODE_END_OF_DATA 0x05
89 #define ASENCODE_BECOMING_READY 0x01
90 #define ASENCODE_INIT_CMD_REQUIRED 0x02
91 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
92 #define ASENCODE_INVALID_COMMAND 0x00
93 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
94 #define ASENCODE_INVALID_CDB_FIELD 0x00
95 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
96 #define ASENCODE_INVALID_PARAM_FIELD 0x00
97 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
98 #define ASENCODE_PARAM_VALUE_INVALID 0x02
99 #define ASENCODE_RESET_OCCURRED 0x00
100 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
101 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
102 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
103 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
104 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
105 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
106 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
107 #define ASENCODE_OVERLAPPED_COMMAND 0x00
109 #define BYTE0(x) (unsigned char)(x)
110 #define BYTE1(x) (unsigned char)((x) >> 8)
111 #define BYTE2(x) (unsigned char)((x) >> 16)
112 #define BYTE3(x) (unsigned char)((x) >> 24)
114 /* MODE_SENSE data format */
121 } __attribute__((packed
)) hd
;
127 } __attribute__((packed
)) bd
;
129 } __attribute__((packed
)) aac_modep_data
;
131 /* MODE_SENSE_10 data format */
139 } __attribute__((packed
)) hd
;
145 } __attribute__((packed
)) bd
;
147 } __attribute__((packed
)) aac_modep10_data
;
149 /*------------------------------------------------------------------------------
150 * S T R U C T S / T Y P E D E F S
151 *----------------------------------------------------------------------------*/
152 /* SCSI inquiry data */
153 struct inquiry_data
{
154 u8 inqd_pdt
; /* Peripheral qualifier | Peripheral Device Type */
155 u8 inqd_dtq
; /* RMB | Device Type Qualifier */
156 u8 inqd_ver
; /* ISO version | ECMA version | ANSI-approved version */
157 u8 inqd_rdf
; /* AENC | TrmIOP | Response data format */
158 u8 inqd_len
; /* Additional length (n-4) */
159 u8 inqd_pad1
[2];/* Reserved - must be zero */
160 u8 inqd_pad2
; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
161 u8 inqd_vid
[8]; /* Vendor ID */
162 u8 inqd_pid
[16];/* Product ID */
163 u8 inqd_prl
[4]; /* Product Revision Level */
166 /* Added for VPD 0x83 */
168 u8 CodeSet
:4; /* VPD_CODE_SET */
170 u8 IdentifierType
:4; /* VPD_IDENTIFIER_TYPE */
176 u8 SerialNumber
[8]; /* SN in ASCII */
178 } TVPD_ID_Descriptor_Type_1
;
181 u8 CodeSet
:4; /* VPD_CODE_SET */
183 u8 IdentifierType
:4; /* VPD_IDENTIFIER_TYPE */
189 /* The serial number supposed to be 40 bits,
190 * bit we only support 32, so make the last byte zero. */
195 } TVPD_ID_Descriptor_Type_2
;
199 u8 DeviceTypeQualifier
:3;
203 TVPD_ID_Descriptor_Type_1 IdDescriptorType1
;
204 TVPD_ID_Descriptor_Type_2 IdDescriptorType2
;
209 * M O D U L E G L O B A L S
212 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*sgmap
);
213 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
);
214 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
);
215 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
216 struct aac_raw_io2
*rio2
, int sg_max
);
217 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
,
218 int pages
, int nseg
, int nseg_new
);
219 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
);
220 #ifdef AAC_DETAILED_STATUS_INFO
221 static char *aac_get_status_string(u32 status
);
225 * Non dasd selection is handled entirely in aachba now
228 static int nondasd
= -1;
229 static int aac_cache
= 2; /* WCE=0 to avoid performance problems */
230 static int dacmode
= -1;
233 int startup_timeout
= 180;
234 int aif_timeout
= 120;
235 int aac_sync_mode
; /* Only Sync. transfer - disabled */
236 int aac_convert_sgl
= 1; /* convert non-conformable s/g list - enabled */
238 module_param(aac_sync_mode
, int, S_IRUGO
|S_IWUSR
);
239 MODULE_PARM_DESC(aac_sync_mode
, "Force sync. transfer mode"
241 module_param(aac_convert_sgl
, int, S_IRUGO
|S_IWUSR
);
242 MODULE_PARM_DESC(aac_convert_sgl
, "Convert non-conformable s/g list"
244 module_param(nondasd
, int, S_IRUGO
|S_IWUSR
);
245 MODULE_PARM_DESC(nondasd
, "Control scanning of hba for nondasd devices."
247 module_param_named(cache
, aac_cache
, int, S_IRUGO
|S_IWUSR
);
248 MODULE_PARM_DESC(cache
, "Disable Queue Flush commands:\n"
249 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
250 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
251 "\tbit 2 - Disable only if Battery is protecting Cache");
252 module_param(dacmode
, int, S_IRUGO
|S_IWUSR
);
253 MODULE_PARM_DESC(dacmode
, "Control whether dma addressing is using 64 bit DAC."
255 module_param_named(commit
, aac_commit
, int, S_IRUGO
|S_IWUSR
);
256 MODULE_PARM_DESC(commit
, "Control whether a COMMIT_CONFIG is issued to the"
257 " adapter for foreign arrays.\n"
258 "This is typically needed in systems that do not have a BIOS."
260 module_param_named(msi
, aac_msi
, int, S_IRUGO
|S_IWUSR
);
261 MODULE_PARM_DESC(msi
, "IRQ handling."
262 " 0=PIC(default), 1=MSI, 2=MSI-X)");
263 module_param(startup_timeout
, int, S_IRUGO
|S_IWUSR
);
264 MODULE_PARM_DESC(startup_timeout
, "The duration of time in seconds to wait for"
265 " adapter to have it's kernel up and\n"
266 "running. This is typically adjusted for large systems that do not"
268 module_param(aif_timeout
, int, S_IRUGO
|S_IWUSR
);
269 MODULE_PARM_DESC(aif_timeout
, "The duration of time in seconds to wait for"
270 " applications to pick up AIFs before\n"
271 "deregistering them. This is typically adjusted for heavily burdened"
275 module_param(numacb
, int, S_IRUGO
|S_IWUSR
);
276 MODULE_PARM_DESC(numacb
, "Request a limit to the number of adapter control"
277 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
278 " to use suggestion from Firmware.");
281 module_param(acbsize
, int, S_IRUGO
|S_IWUSR
);
282 MODULE_PARM_DESC(acbsize
, "Request a specific adapter control block (FIB)"
283 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
284 " suggestion from Firmware.");
286 int update_interval
= 30 * 60;
287 module_param(update_interval
, int, S_IRUGO
|S_IWUSR
);
288 MODULE_PARM_DESC(update_interval
, "Interval in seconds between time sync"
289 " updates issued to adapter.");
291 int check_interval
= 24 * 60 * 60;
292 module_param(check_interval
, int, S_IRUGO
|S_IWUSR
);
293 MODULE_PARM_DESC(check_interval
, "Interval in seconds between adapter health"
296 int aac_check_reset
= 1;
297 module_param_named(check_reset
, aac_check_reset
, int, S_IRUGO
|S_IWUSR
);
298 MODULE_PARM_DESC(check_reset
, "If adapter fails health check, reset the"
299 " adapter. a value of -1 forces the reset to adapters programmed to"
302 int expose_physicals
= -1;
303 module_param(expose_physicals
, int, S_IRUGO
|S_IWUSR
);
304 MODULE_PARM_DESC(expose_physicals
, "Expose physical components of the arrays."
305 " -1=protect 0=off, 1=on");
307 int aac_reset_devices
;
308 module_param_named(reset_devices
, aac_reset_devices
, int, S_IRUGO
|S_IWUSR
);
309 MODULE_PARM_DESC(reset_devices
, "Force an adapter reset at initialization.");
312 module_param_named(wwn
, aac_wwn
, int, S_IRUGO
|S_IWUSR
);
313 MODULE_PARM_DESC(wwn
, "Select a WWN type for the arrays:\n"
315 "\t1 - Array Meta Data Signature (default)\n"
316 "\t2 - Adapter Serial Number");
319 static inline int aac_valid_context(struct scsi_cmnd
*scsicmd
,
320 struct fib
*fibptr
) {
321 struct scsi_device
*device
;
323 if (unlikely(!scsicmd
|| !scsicmd
->scsi_done
)) {
324 dprintk((KERN_WARNING
"aac_valid_context: scsi command corrupt\n"));
325 aac_fib_complete(fibptr
);
326 aac_fib_free(fibptr
);
329 scsicmd
->SCp
.phase
= AAC_OWNER_MIDLEVEL
;
330 device
= scsicmd
->device
;
331 if (unlikely(!device
|| !scsi_device_online(device
))) {
332 dprintk((KERN_WARNING
"aac_valid_context: scsi device corrupt\n"));
333 aac_fib_complete(fibptr
);
334 aac_fib_free(fibptr
);
341 * aac_get_config_status - check the adapter configuration
342 * @common: adapter to query
344 * Query config status, and commit the configuration if needed.
346 int aac_get_config_status(struct aac_dev
*dev
, int commit_flag
)
351 if (!(fibptr
= aac_fib_alloc(dev
)))
354 aac_fib_init(fibptr
);
356 struct aac_get_config_status
*dinfo
;
357 dinfo
= (struct aac_get_config_status
*) fib_data(fibptr
);
359 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
360 dinfo
->type
= cpu_to_le32(CT_GET_CONFIG_STATUS
);
361 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_config_status_resp
*)NULL
)->data
));
364 status
= aac_fib_send(ContainerCommand
,
366 sizeof (struct aac_get_config_status
),
371 printk(KERN_WARNING
"aac_get_config_status: SendFIB failed.\n");
373 struct aac_get_config_status_resp
*reply
374 = (struct aac_get_config_status_resp
*) fib_data(fibptr
);
375 dprintk((KERN_WARNING
376 "aac_get_config_status: response=%d status=%d action=%d\n",
377 le32_to_cpu(reply
->response
),
378 le32_to_cpu(reply
->status
),
379 le32_to_cpu(reply
->data
.action
)));
380 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
381 (le32_to_cpu(reply
->status
) != CT_OK
) ||
382 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
383 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
387 /* Do not set XferState to zero unless receives a response from F/W */
389 aac_fib_complete(fibptr
);
391 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
393 if ((aac_commit
== 1) || commit_flag
) {
394 struct aac_commit_config
* dinfo
;
395 aac_fib_init(fibptr
);
396 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
398 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
399 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
401 status
= aac_fib_send(ContainerCommand
,
403 sizeof (struct aac_commit_config
),
407 /* Do not set XferState to zero unless
408 * receives a response from F/W */
410 aac_fib_complete(fibptr
);
411 } else if (aac_commit
== 0) {
413 "aac_get_config_status: Foreign device configurations are being ignored\n");
416 /* FIB should be freed only after getting the response from the F/W */
417 if (status
!= -ERESTARTSYS
)
418 aac_fib_free(fibptr
);
422 static void aac_expose_phy_device(struct scsi_cmnd
*scsicmd
)
425 scsi_sg_copy_to_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
426 if ((inq_data
& 0x20) && (inq_data
& 0x1f) == TYPE_DISK
) {
428 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
433 * aac_get_containers - list containers
434 * @common: adapter to probe
436 * Make a list of all containers on this controller
438 int aac_get_containers(struct aac_dev
*dev
)
440 struct fsa_dev_info
*fsa_dev_ptr
;
444 struct aac_get_container_count
*dinfo
;
445 struct aac_get_container_count_resp
*dresp
;
446 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
448 if (!(fibptr
= aac_fib_alloc(dev
)))
451 aac_fib_init(fibptr
);
452 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
453 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
454 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
456 status
= aac_fib_send(ContainerCommand
,
458 sizeof (struct aac_get_container_count
),
463 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
464 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
465 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
466 AAC_OPTION_SUPPORTED_240_VOLUMES
) {
467 maximum_num_containers
=
468 le32_to_cpu(dresp
->MaxSimpleVolumes
);
470 aac_fib_complete(fibptr
);
472 /* FIB should be freed only after getting the response from the F/W */
473 if (status
!= -ERESTARTSYS
)
474 aac_fib_free(fibptr
);
476 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
477 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
478 fsa_dev_ptr
= kzalloc(sizeof(*fsa_dev_ptr
) * maximum_num_containers
,
483 dev
->fsa_dev
= fsa_dev_ptr
;
484 dev
->maximum_num_containers
= maximum_num_containers
;
486 for (index
= 0; index
< dev
->maximum_num_containers
; ) {
487 fsa_dev_ptr
[index
].devname
[0] = '\0';
489 status
= aac_probe_container(dev
, index
);
492 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
497 * If there are no more containers, then stop asking.
499 if (++index
>= status
)
505 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
507 struct aac_get_name_resp
* get_name_reply
;
508 struct scsi_cmnd
* scsicmd
;
510 scsicmd
= (struct scsi_cmnd
*) context
;
512 if (!aac_valid_context(scsicmd
, fibptr
))
515 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
516 BUG_ON(fibptr
== NULL
);
518 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
519 /* Failure is irrelevant, using default value instead */
520 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
521 && (get_name_reply
->data
[0] != '\0')) {
522 char *sp
= get_name_reply
->data
;
523 sp
[sizeof(((struct aac_get_name_resp
*)NULL
)->data
)] = '\0';
527 struct inquiry_data inq
;
528 char d
[sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
)];
529 int count
= sizeof(d
);
532 *dp
++ = (*sp
) ? *sp
++ : ' ';
533 } while (--count
> 0);
535 scsi_sg_copy_to_buffer(scsicmd
, &inq
, sizeof(inq
));
536 memcpy(inq
.inqd_pid
, d
, sizeof(d
));
537 scsi_sg_copy_from_buffer(scsicmd
, &inq
, sizeof(inq
));
541 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
543 aac_fib_complete(fibptr
);
544 aac_fib_free(fibptr
);
545 scsicmd
->scsi_done(scsicmd
);
549 * aac_get_container_name - get container name, none blocking.
551 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
)
554 struct aac_get_name
*dinfo
;
555 struct fib
* cmd_fibcontext
;
556 struct aac_dev
* dev
;
558 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
560 if (!(cmd_fibcontext
= aac_fib_alloc(dev
)))
563 aac_fib_init(cmd_fibcontext
);
564 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
566 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
567 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
568 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
569 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_name_resp
*)NULL
)->data
));
571 status
= aac_fib_send(ContainerCommand
,
573 sizeof(struct aac_get_name_resp
),
576 (fib_callback
)get_container_name_callback
,
580 * Check that the command queued to the controller
582 if (status
== -EINPROGRESS
) {
583 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
587 printk(KERN_WARNING
"aac_get_container_name: aac_fib_send failed with status: %d.\n", status
);
588 aac_fib_complete(cmd_fibcontext
);
589 aac_fib_free(cmd_fibcontext
);
593 static int aac_probe_container_callback2(struct scsi_cmnd
* scsicmd
)
595 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
597 if ((fsa_dev_ptr
[scmd_id(scsicmd
)].valid
& 1))
598 return aac_scsi_cmd(scsicmd
);
600 scsicmd
->result
= DID_NO_CONNECT
<< 16;
601 scsicmd
->scsi_done(scsicmd
);
605 static void _aac_probe_container2(void * context
, struct fib
* fibptr
)
607 struct fsa_dev_info
*fsa_dev_ptr
;
608 int (*callback
)(struct scsi_cmnd
*);
609 struct scsi_cmnd
* scsicmd
= (struct scsi_cmnd
*)context
;
612 if (!aac_valid_context(scsicmd
, fibptr
))
615 scsicmd
->SCp
.Status
= 0;
616 fsa_dev_ptr
= fibptr
->dev
->fsa_dev
;
618 struct aac_mount
* dresp
= (struct aac_mount
*) fib_data(fibptr
);
619 fsa_dev_ptr
+= scmd_id(scsicmd
);
621 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
622 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
623 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
624 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
625 AAC_OPTION_VARIABLE_BLOCK_SIZE
)) {
626 dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
= 0x200;
627 fsa_dev_ptr
->block_size
= 0x200;
629 fsa_dev_ptr
->block_size
=
630 le32_to_cpu(dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
);
632 fsa_dev_ptr
->valid
= 1;
633 /* sense_key holds the current state of the spin-up */
634 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
635 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
636 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
637 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
638 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
640 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
641 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
642 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
644 if ((fsa_dev_ptr
->valid
& 1) == 0)
645 fsa_dev_ptr
->valid
= 0;
646 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
648 aac_fib_complete(fibptr
);
649 aac_fib_free(fibptr
);
650 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
651 scsicmd
->SCp
.ptr
= NULL
;
652 (*callback
)(scsicmd
);
656 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
658 struct scsi_cmnd
* scsicmd
;
659 struct aac_mount
* dresp
;
660 struct aac_query_mount
*dinfo
;
663 dresp
= (struct aac_mount
*) fib_data(fibptr
);
664 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
665 AAC_OPTION_VARIABLE_BLOCK_SIZE
))
666 dresp
->mnt
[0].capacityhigh
= 0;
667 if ((le32_to_cpu(dresp
->status
) != ST_OK
) ||
668 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
669 _aac_probe_container2(context
, fibptr
);
672 scsicmd
= (struct scsi_cmnd
*) context
;
674 if (!aac_valid_context(scsicmd
, fibptr
))
677 aac_fib_init(fibptr
);
679 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
681 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
682 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
683 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
685 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
687 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
688 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
690 status
= aac_fib_send(ContainerCommand
,
692 sizeof(struct aac_query_mount
),
695 _aac_probe_container2
,
698 * Check that the command queued to the controller
700 if (status
== -EINPROGRESS
)
701 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
702 else if (status
< 0) {
703 /* Inherit results from VM_NameServe, if any */
704 dresp
->status
= cpu_to_le32(ST_OK
);
705 _aac_probe_container2(context
, fibptr
);
709 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
712 int status
= -ENOMEM
;
714 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
715 struct aac_query_mount
*dinfo
;
717 aac_fib_init(fibptr
);
719 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
721 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
722 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
723 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
725 dinfo
->command
= cpu_to_le32(VM_NameServe
);
727 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
728 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
729 scsicmd
->SCp
.ptr
= (char *)callback
;
731 status
= aac_fib_send(ContainerCommand
,
733 sizeof(struct aac_query_mount
),
736 _aac_probe_container1
,
739 * Check that the command queued to the controller
741 if (status
== -EINPROGRESS
) {
742 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
746 scsicmd
->SCp
.ptr
= NULL
;
747 aac_fib_complete(fibptr
);
748 aac_fib_free(fibptr
);
752 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
754 fsa_dev_ptr
+= scmd_id(scsicmd
);
755 if ((fsa_dev_ptr
->valid
& 1) == 0) {
756 fsa_dev_ptr
->valid
= 0;
757 return (*callback
)(scsicmd
);
765 * aac_probe_container - query a logical volume
766 * @dev: device to query
767 * @cid: container identifier
769 * Queries the controller about the given volume. The volume information
770 * is updated in the struct fsa_dev_info structure rather than returned.
772 static int aac_probe_container_callback1(struct scsi_cmnd
* scsicmd
)
774 scsicmd
->device
= NULL
;
778 int aac_probe_container(struct aac_dev
*dev
, int cid
)
780 struct scsi_cmnd
*scsicmd
= kmalloc(sizeof(*scsicmd
), GFP_KERNEL
);
781 struct scsi_device
*scsidev
= kmalloc(sizeof(*scsidev
), GFP_KERNEL
);
784 if (!scsicmd
|| !scsidev
) {
789 scsicmd
->list
.next
= NULL
;
790 scsicmd
->scsi_done
= (void (*)(struct scsi_cmnd
*))aac_probe_container_callback1
;
792 scsicmd
->device
= scsidev
;
793 scsidev
->sdev_state
= 0;
795 scsidev
->host
= dev
->scsi_host_ptr
;
797 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
798 while (scsicmd
->device
== scsidev
)
801 status
= scsicmd
->SCp
.Status
;
806 /* Local Structure to set SCSI inquiry data strings */
808 char vid
[8]; /* Vendor ID */
809 char pid
[16]; /* Product ID */
810 char prl
[4]; /* Product Revision Level */
814 * InqStrCopy - string merge
815 * @a: string to copy from
816 * @b: string to copy to
818 * Copy a String from one location to another
822 static void inqstrcpy(char *a
, char *b
)
825 while (*a
!= (char)0)
829 static char *container_types
[] = {
853 char * get_container_type(unsigned tindex
)
855 if (tindex
>= ARRAY_SIZE(container_types
))
856 tindex
= ARRAY_SIZE(container_types
) - 1;
857 return container_types
[tindex
];
860 /* Function: setinqstr
862 * Arguments: [1] pointer to void [1] int
864 * Purpose: Sets SCSI inquiry data strings for vendor, product
865 * and revision level. Allows strings to be set in platform dependent
866 * files instead of in OS dependent driver source.
869 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
871 struct scsi_inq
*str
;
873 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
874 memset(str
, ' ', sizeof(*str
));
876 if (dev
->supplement_adapter_info
.AdapterTypeText
[0]) {
877 char * cp
= dev
->supplement_adapter_info
.AdapterTypeText
;
879 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
880 inqstrcpy("SMC", str
->vid
);
882 c
= sizeof(str
->vid
);
883 while (*cp
&& *cp
!= ' ' && --c
)
887 inqstrcpy (dev
->supplement_adapter_info
.AdapterTypeText
,
890 while (*cp
&& *cp
!= ' ')
895 /* last six chars reserved for vol type */
897 if (strlen(cp
) > sizeof(str
->pid
)) {
898 c
= cp
[sizeof(str
->pid
)];
899 cp
[sizeof(str
->pid
)] = '\0';
901 inqstrcpy (cp
, str
->pid
);
903 cp
[sizeof(str
->pid
)] = c
;
905 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
907 inqstrcpy (mp
->vname
, str
->vid
);
908 /* last six chars reserved for vol type */
909 inqstrcpy (mp
->model
, str
->pid
);
912 if (tindex
< ARRAY_SIZE(container_types
)){
913 char *findit
= str
->pid
;
915 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
916 /* RAID is superfluous in the context of a RAID device */
917 if (memcmp(findit
-4, "RAID", 4) == 0)
918 *(findit
-= 4) = ' ';
919 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
920 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
921 inqstrcpy (container_types
[tindex
], findit
+ 1);
923 inqstrcpy ("V1.0", str
->prl
);
926 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
928 struct aac_get_serial_resp
* get_serial_reply
;
929 struct scsi_cmnd
* scsicmd
;
931 BUG_ON(fibptr
== NULL
);
933 scsicmd
= (struct scsi_cmnd
*) context
;
934 if (!aac_valid_context(scsicmd
, fibptr
))
937 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
938 /* Failure is irrelevant, using default value instead */
939 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
940 /*Check to see if it's for VPD 0x83 or 0x80 */
941 if (scsicmd
->cmnd
[2] == 0x83) {
942 /* vpd page 0x83 - Device Identification Page */
944 TVPD_Page83 VPDPage83Data
;
946 memset(((u8
*)&VPDPage83Data
), 0,
947 sizeof(VPDPage83Data
));
949 /* DIRECT_ACCESS_DEVIC */
950 VPDPage83Data
.DeviceType
= 0;
951 /* DEVICE_CONNECTED */
952 VPDPage83Data
.DeviceTypeQualifier
= 0;
953 /* VPD_DEVICE_IDENTIFIERS */
954 VPDPage83Data
.PageCode
= 0x83;
955 VPDPage83Data
.Reserved
= 0;
956 VPDPage83Data
.PageLength
=
957 sizeof(VPDPage83Data
.IdDescriptorType1
) +
958 sizeof(VPDPage83Data
.IdDescriptorType2
);
960 /* T10 Vendor Identifier Field Format */
961 /* VpdCodeSetAscii */
962 VPDPage83Data
.IdDescriptorType1
.CodeSet
= 2;
963 /* VpdIdentifierTypeVendorId */
964 VPDPage83Data
.IdDescriptorType1
.IdentifierType
= 1;
965 VPDPage83Data
.IdDescriptorType1
.IdentifierLength
=
966 sizeof(VPDPage83Data
.IdDescriptorType1
) - 4;
968 /* "ADAPTEC " for adaptec */
969 memcpy(VPDPage83Data
.IdDescriptorType1
.VendId
,
971 sizeof(VPDPage83Data
.IdDescriptorType1
.VendId
));
972 memcpy(VPDPage83Data
.IdDescriptorType1
.ProductId
,
975 VPDPage83Data
.IdDescriptorType1
.ProductId
));
977 /* Convert to ascii based serial number.
978 * The LSB is the the end.
980 for (i
= 0; i
< 8; i
++) {
982 (u8
)((get_serial_reply
->uid
>> ((7 - i
) * 4)) & 0xF);
984 VPDPage83Data
.IdDescriptorType1
.SerialNumber
[i
] =
987 VPDPage83Data
.IdDescriptorType1
.SerialNumber
[i
] =
992 /* VpdCodeSetBinary */
993 VPDPage83Data
.IdDescriptorType2
.CodeSet
= 1;
994 /* VpdIdentifierTypeEUI64 */
995 VPDPage83Data
.IdDescriptorType2
.IdentifierType
= 2;
996 VPDPage83Data
.IdDescriptorType2
.IdentifierLength
=
997 sizeof(VPDPage83Data
.IdDescriptorType2
) - 4;
999 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[0] = 0xD0;
1000 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[1] = 0;
1001 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[2] = 0;
1003 VPDPage83Data
.IdDescriptorType2
.EU64Id
.Serial
=
1004 get_serial_reply
->uid
;
1005 VPDPage83Data
.IdDescriptorType2
.EU64Id
.Reserved
= 0;
1007 /* Move the inquiry data to the response buffer. */
1008 scsi_sg_copy_from_buffer(scsicmd
, &VPDPage83Data
,
1009 sizeof(VPDPage83Data
));
1011 /* It must be for VPD 0x80 */
1014 sp
[0] = INQD_PDT_DA
;
1015 sp
[1] = scsicmd
->cmnd
[2];
1017 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
1018 le32_to_cpu(get_serial_reply
->uid
));
1019 scsi_sg_copy_from_buffer(scsicmd
, sp
,
1024 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1026 aac_fib_complete(fibptr
);
1027 aac_fib_free(fibptr
);
1028 scsicmd
->scsi_done(scsicmd
);
1032 * aac_get_container_serial - get container serial, none blocking.
1034 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
1037 struct aac_get_serial
*dinfo
;
1038 struct fib
* cmd_fibcontext
;
1039 struct aac_dev
* dev
;
1041 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1043 if (!(cmd_fibcontext
= aac_fib_alloc(dev
)))
1046 aac_fib_init(cmd_fibcontext
);
1047 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
1049 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
1050 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
1051 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1053 status
= aac_fib_send(ContainerCommand
,
1055 sizeof(struct aac_get_serial_resp
),
1058 (fib_callback
) get_container_serial_callback
,
1062 * Check that the command queued to the controller
1064 if (status
== -EINPROGRESS
) {
1065 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1069 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
1070 aac_fib_complete(cmd_fibcontext
);
1071 aac_fib_free(cmd_fibcontext
);
1075 /* Function: setinqserial
1077 * Arguments: [1] pointer to void [1] int
1079 * Purpose: Sets SCSI Unit Serial number.
1080 * This is a fake. We should read a proper
1081 * serial number from the container. <SuSE>But
1082 * without docs it's quite hard to do it :-)
1083 * So this will have to do in the meantime.</SuSE>
1086 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
1089 * This breaks array migration.
1091 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
1092 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
1095 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
1096 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
1098 u8
*sense_buf
= (u8
*)sense_data
;
1099 /* Sense data valid, err code 70h */
1100 sense_buf
[0] = 0x70; /* No info field */
1101 sense_buf
[1] = 0; /* Segment number, always zero */
1103 sense_buf
[2] = sense_key
; /* Sense key */
1105 sense_buf
[12] = sense_code
; /* Additional sense code */
1106 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
1108 if (sense_key
== ILLEGAL_REQUEST
) {
1109 sense_buf
[7] = 10; /* Additional sense length */
1111 sense_buf
[15] = bit_pointer
;
1112 /* Illegal parameter is in the parameter block */
1113 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
1114 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
1115 /* Illegal parameter is in the CDB block */
1116 sense_buf
[16] = field_pointer
>> 8; /* MSB */
1117 sense_buf
[17] = field_pointer
; /* LSB */
1119 sense_buf
[7] = 6; /* Additional sense length */
1122 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1124 if (lba
& 0xffffffff00000000LL
) {
1125 int cid
= scmd_id(cmd
);
1126 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1127 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1128 SAM_STAT_CHECK_CONDITION
;
1129 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1130 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1131 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1132 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1133 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1134 SCSI_SENSE_BUFFERSIZE
));
1135 cmd
->scsi_done(cmd
);
1141 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1146 static void io_callback(void *context
, struct fib
* fibptr
);
1148 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1150 struct aac_dev
*dev
= fib
->dev
;
1151 u16 fibsize
, command
;
1155 if (dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
&& !dev
->sync_mode
) {
1156 struct aac_raw_io2
*readcmd2
;
1157 readcmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1158 memset(readcmd2
, 0, sizeof(struct aac_raw_io2
));
1159 readcmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1160 readcmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1161 readcmd2
->byteCount
= cpu_to_le32(count
*
1162 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1163 readcmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1164 readcmd2
->flags
= cpu_to_le16(RIO2_IO_TYPE_READ
);
1165 ret
= aac_build_sgraw2(cmd
, readcmd2
,
1166 dev
->scsi_host_ptr
->sg_tablesize
);
1169 command
= ContainerRawIo2
;
1170 fibsize
= sizeof(struct aac_raw_io2
) +
1171 ((le32_to_cpu(readcmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1173 struct aac_raw_io
*readcmd
;
1174 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
1175 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1176 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1177 readcmd
->count
= cpu_to_le32(count
*
1178 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1179 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1180 readcmd
->flags
= cpu_to_le16(RIO_TYPE_READ
);
1181 readcmd
->bpTotal
= 0;
1182 readcmd
->bpComplete
= 0;
1183 ret
= aac_build_sgraw(cmd
, &readcmd
->sg
);
1186 command
= ContainerRawIo
;
1187 fibsize
= sizeof(struct aac_raw_io
) +
1188 ((le32_to_cpu(readcmd
->sg
.count
)-1) * sizeof(struct sgentryraw
));
1191 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1193 * Now send the Fib to the adapter
1195 return aac_fib_send(command
,
1200 (fib_callback
) io_callback
,
1204 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1207 struct aac_read64
*readcmd
;
1211 readcmd
= (struct aac_read64
*) fib_data(fib
);
1212 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
1213 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1214 readcmd
->sector_count
= cpu_to_le16(count
);
1215 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1219 ret
= aac_build_sg64(cmd
, &readcmd
->sg
);
1222 fibsize
= sizeof(struct aac_read64
) +
1223 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1224 sizeof (struct sgentry64
));
1225 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1226 sizeof(struct aac_fibhdr
)));
1228 * Now send the Fib to the adapter
1230 return aac_fib_send(ContainerCommand64
,
1235 (fib_callback
) io_callback
,
1239 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1242 struct aac_read
*readcmd
;
1243 struct aac_dev
*dev
= fib
->dev
;
1247 readcmd
= (struct aac_read
*) fib_data(fib
);
1248 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
1249 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1250 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1251 readcmd
->count
= cpu_to_le32(count
*
1252 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1254 ret
= aac_build_sg(cmd
, &readcmd
->sg
);
1257 fibsize
= sizeof(struct aac_read
) +
1258 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1259 sizeof (struct sgentry
));
1260 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1261 sizeof(struct aac_fibhdr
)));
1263 * Now send the Fib to the adapter
1265 return aac_fib_send(ContainerCommand
,
1270 (fib_callback
) io_callback
,
1274 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1276 struct aac_dev
*dev
= fib
->dev
;
1277 u16 fibsize
, command
;
1281 if (dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
&& !dev
->sync_mode
) {
1282 struct aac_raw_io2
*writecmd2
;
1283 writecmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1284 memset(writecmd2
, 0, sizeof(struct aac_raw_io2
));
1285 writecmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1286 writecmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1287 writecmd2
->byteCount
= cpu_to_le32(count
*
1288 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1289 writecmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1290 writecmd2
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1291 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1292 cpu_to_le16(RIO2_IO_TYPE_WRITE
|RIO2_IO_SUREWRITE
) :
1293 cpu_to_le16(RIO2_IO_TYPE_WRITE
);
1294 ret
= aac_build_sgraw2(cmd
, writecmd2
,
1295 dev
->scsi_host_ptr
->sg_tablesize
);
1298 command
= ContainerRawIo2
;
1299 fibsize
= sizeof(struct aac_raw_io2
) +
1300 ((le32_to_cpu(writecmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1302 struct aac_raw_io
*writecmd
;
1303 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1304 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1305 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1306 writecmd
->count
= cpu_to_le32(count
*
1307 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1308 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1309 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1310 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1311 cpu_to_le16(RIO_TYPE_WRITE
|RIO_SUREWRITE
) :
1312 cpu_to_le16(RIO_TYPE_WRITE
);
1313 writecmd
->bpTotal
= 0;
1314 writecmd
->bpComplete
= 0;
1315 ret
= aac_build_sgraw(cmd
, &writecmd
->sg
);
1318 command
= ContainerRawIo
;
1319 fibsize
= sizeof(struct aac_raw_io
) +
1320 ((le32_to_cpu(writecmd
->sg
.count
)-1) * sizeof (struct sgentryraw
));
1323 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1325 * Now send the Fib to the adapter
1327 return aac_fib_send(command
,
1332 (fib_callback
) io_callback
,
1336 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1339 struct aac_write64
*writecmd
;
1343 writecmd
= (struct aac_write64
*) fib_data(fib
);
1344 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1345 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1346 writecmd
->sector_count
= cpu_to_le16(count
);
1347 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1349 writecmd
->flags
= 0;
1351 ret
= aac_build_sg64(cmd
, &writecmd
->sg
);
1354 fibsize
= sizeof(struct aac_write64
) +
1355 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1356 sizeof (struct sgentry64
));
1357 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1358 sizeof(struct aac_fibhdr
)));
1360 * Now send the Fib to the adapter
1362 return aac_fib_send(ContainerCommand64
,
1367 (fib_callback
) io_callback
,
1371 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1374 struct aac_write
*writecmd
;
1375 struct aac_dev
*dev
= fib
->dev
;
1379 writecmd
= (struct aac_write
*) fib_data(fib
);
1380 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1381 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1382 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1383 writecmd
->count
= cpu_to_le32(count
*
1384 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1385 writecmd
->sg
.count
= cpu_to_le32(1);
1386 /* ->stable is not used - it did mean which type of write */
1388 ret
= aac_build_sg(cmd
, &writecmd
->sg
);
1391 fibsize
= sizeof(struct aac_write
) +
1392 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1393 sizeof (struct sgentry
));
1394 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1395 sizeof(struct aac_fibhdr
)));
1397 * Now send the Fib to the adapter
1399 return aac_fib_send(ContainerCommand
,
1404 (fib_callback
) io_callback
,
1408 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1410 struct aac_srb
* srbcmd
;
1415 switch(cmd
->sc_data_direction
){
1419 case DMA_BIDIRECTIONAL
:
1420 flag
= SRB_DataIn
| SRB_DataOut
;
1422 case DMA_FROM_DEVICE
:
1426 default: /* shuts up some versions of gcc */
1427 flag
= SRB_NoDataXfer
;
1431 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1432 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1433 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1434 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1435 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1436 srbcmd
->flags
= cpu_to_le32(flag
);
1437 timeout
= cmd
->request
->timeout
/HZ
;
1440 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1441 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1442 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1446 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1448 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1451 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1454 ret
= aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1457 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1459 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1460 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1462 * Build Scatter/Gather list
1464 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1465 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1466 sizeof (struct sgentry64
));
1467 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1468 sizeof(struct aac_fibhdr
)));
1471 * Now send the Fib to the adapter
1473 return aac_fib_send(ScsiPortCommand64
, fib
,
1474 fibsize
, FsaNormal
, 0, 1,
1475 (fib_callback
) aac_srb_callback
,
1479 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1482 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1485 ret
= aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1488 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1490 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1491 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1493 * Build Scatter/Gather list
1495 fibsize
= sizeof (struct aac_srb
) +
1496 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1497 sizeof (struct sgentry
));
1498 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1499 sizeof(struct aac_fibhdr
)));
1502 * Now send the Fib to the adapter
1504 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1505 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1508 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1510 if ((sizeof(dma_addr_t
) > 4) && fib
->dev
->needs_dac
&&
1511 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1513 return aac_scsi_32(fib
, cmd
);
1516 int aac_get_adapter_info(struct aac_dev
* dev
)
1521 struct aac_adapter_info
*info
;
1522 struct aac_bus_info
*command
;
1523 struct aac_bus_info_response
*bus_info
;
1525 if (!(fibptr
= aac_fib_alloc(dev
)))
1528 aac_fib_init(fibptr
);
1529 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
1530 memset(info
,0,sizeof(*info
));
1532 rcode
= aac_fib_send(RequestAdapterInfo
,
1536 -1, 1, /* First `interrupt' command uses special wait */
1541 /* FIB should be freed only after
1542 * getting the response from the F/W */
1543 if (rcode
!= -ERESTARTSYS
) {
1544 aac_fib_complete(fibptr
);
1545 aac_fib_free(fibptr
);
1549 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
1551 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
1552 struct aac_supplement_adapter_info
* sinfo
;
1554 aac_fib_init(fibptr
);
1556 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
1558 memset(sinfo
,0,sizeof(*sinfo
));
1560 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
1569 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
1570 if (rcode
== -ERESTARTSYS
) {
1571 fibptr
= aac_fib_alloc(dev
);
1583 aac_fib_init(fibptr
);
1585 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
1587 memset(bus_info
, 0, sizeof(*bus_info
));
1589 command
= (struct aac_bus_info
*)bus_info
;
1591 command
->Command
= cpu_to_le32(VM_Ioctl
);
1592 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
1593 command
->MethodId
= cpu_to_le32(1);
1594 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
1596 rcode
= aac_fib_send(ContainerCommand
,
1603 /* reasoned default */
1604 dev
->maximum_num_physicals
= 16;
1605 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
1606 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
1607 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
1610 if (!dev
->in_reset
) {
1612 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
1613 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
1619 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
1620 (int)sizeof(dev
->supplement_adapter_info
.BuildDate
),
1621 dev
->supplement_adapter_info
.BuildDate
);
1622 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
1623 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
1625 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1626 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
1627 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
1628 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
1630 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1631 le32_to_cpu(dev
->adapter_info
.biosbuild
));
1633 if (aac_get_serial_number(
1634 shost_to_class(dev
->scsi_host_ptr
), buffer
))
1635 printk(KERN_INFO
"%s%d: serial %s",
1636 dev
->name
, dev
->id
, buffer
);
1637 if (dev
->supplement_adapter_info
.VpdInfo
.Tsid
[0]) {
1638 printk(KERN_INFO
"%s%d: TSID %.*s\n",
1640 (int)sizeof(dev
->supplement_adapter_info
.VpdInfo
.Tsid
),
1641 dev
->supplement_adapter_info
.VpdInfo
.Tsid
);
1643 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
1644 (dev
->supplement_adapter_info
.SupportedOptions2
&
1645 AAC_OPTION_IGNORE_RESET
))) {
1646 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
1647 dev
->name
, dev
->id
);
1651 dev
->cache_protected
= 0;
1652 dev
->jbod
= ((dev
->supplement_adapter_info
.FeatureBits
&
1653 AAC_FEATURE_JBOD
) != 0);
1654 dev
->nondasd_support
= 0;
1655 dev
->raid_scsi_mode
= 0;
1656 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
1657 dev
->nondasd_support
= 1;
1660 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1661 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1662 * force nondasd support on. If we decide to allow the non-dasd flag
1663 * additional changes changes will have to be made to support
1664 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1665 * changed to support the new dev->raid_scsi_mode flag instead of
1666 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1667 * function aac_detect will have to be modified where it sets up the
1668 * max number of channels based on the aac->nondasd_support flag only.
1670 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
1671 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
1672 dev
->nondasd_support
= 1;
1673 dev
->raid_scsi_mode
= 1;
1675 if (dev
->raid_scsi_mode
!= 0)
1676 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
1677 dev
->name
, dev
->id
);
1680 dev
->nondasd_support
= (nondasd
!=0);
1681 if (dev
->nondasd_support
&& !dev
->in_reset
)
1682 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
1684 if (dma_get_required_mask(&dev
->pdev
->dev
) > DMA_BIT_MASK(32))
1686 dev
->dac_support
= 0;
1687 if ((sizeof(dma_addr_t
) > 4) && dev
->needs_dac
&&
1688 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)) {
1690 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
1691 dev
->name
, dev
->id
);
1692 dev
->dac_support
= 1;
1696 dev
->dac_support
= (dacmode
!=0);
1699 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1700 if (dev
->dac_support
&& (aac_get_driver_ident(dev
->cardtype
)->quirks
1701 & AAC_QUIRK_SCSI_32
)) {
1702 dev
->nondasd_support
= 0;
1704 expose_physicals
= 0;
1707 if(dev
->dac_support
!= 0) {
1708 if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(64)) &&
1709 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(64))) {
1711 printk(KERN_INFO
"%s%d: 64 Bit DAC enabled\n",
1712 dev
->name
, dev
->id
);
1713 } else if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(32)) &&
1714 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(32))) {
1715 printk(KERN_INFO
"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1716 dev
->name
, dev
->id
);
1717 dev
->dac_support
= 0;
1719 printk(KERN_WARNING
"%s%d: No suitable DMA available.\n",
1720 dev
->name
, dev
->id
);
1725 * Deal with configuring for the individualized limits of each packet
1728 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
1729 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
1733 if (dev
->raw_io_interface
) {
1734 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
1737 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
1738 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
1740 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
1741 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
1742 sizeof(struct aac_fibhdr
) -
1743 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
1744 sizeof(struct sgentry
);
1745 if (dev
->dac_support
) {
1746 dev
->a_ops
.adapter_read
= aac_read_block64
;
1747 dev
->a_ops
.adapter_write
= aac_write_block64
;
1749 * 38 scatter gather elements
1751 dev
->scsi_host_ptr
->sg_tablesize
=
1752 (dev
->max_fib_size
-
1753 sizeof(struct aac_fibhdr
) -
1754 sizeof(struct aac_write64
) +
1755 sizeof(struct sgentry64
)) /
1756 sizeof(struct sgentry64
);
1758 dev
->a_ops
.adapter_read
= aac_read_block
;
1759 dev
->a_ops
.adapter_write
= aac_write_block
;
1761 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
1762 if (!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
1764 * Worst case size that could cause sg overflow when
1765 * we break up SG elements that are larger than 64KB.
1766 * Would be nice if we could tell the SCSI layer what
1767 * the maximum SG element size can be. Worst case is
1768 * (sg_tablesize-1) 4KB elements with one 64KB
1770 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1772 dev
->scsi_host_ptr
->max_sectors
=
1773 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
1776 /* FIB should be freed only after getting the response from the F/W */
1777 if (rcode
!= -ERESTARTSYS
) {
1778 aac_fib_complete(fibptr
);
1779 aac_fib_free(fibptr
);
1786 static void io_callback(void *context
, struct fib
* fibptr
)
1788 struct aac_dev
*dev
;
1789 struct aac_read_reply
*readreply
;
1790 struct scsi_cmnd
*scsicmd
;
1793 scsicmd
= (struct scsi_cmnd
*) context
;
1795 if (!aac_valid_context(scsicmd
, fibptr
))
1799 cid
= scmd_id(scsicmd
);
1801 if (nblank(dprintk(x
))) {
1803 switch (scsicmd
->cmnd
[0]) {
1806 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1807 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1811 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1812 ((u64
)scsicmd
->cmnd
[3] << 48) |
1813 ((u64
)scsicmd
->cmnd
[4] << 40) |
1814 ((u64
)scsicmd
->cmnd
[5] << 32) |
1815 ((u64
)scsicmd
->cmnd
[6] << 24) |
1816 (scsicmd
->cmnd
[7] << 16) |
1817 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1821 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1822 (scsicmd
->cmnd
[3] << 16) |
1823 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1826 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1827 (scsicmd
->cmnd
[3] << 16) |
1828 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1832 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1833 smp_processor_id(), (unsigned long long)lba
, jiffies
);
1836 BUG_ON(fibptr
== NULL
);
1838 scsi_dma_unmap(scsicmd
);
1840 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
1841 switch (le32_to_cpu(readreply
->status
)) {
1843 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1845 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
1848 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1849 SAM_STAT_CHECK_CONDITION
;
1850 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
1851 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
1852 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1853 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1854 SCSI_SENSE_BUFFERSIZE
));
1857 #ifdef AAC_DETAILED_STATUS_INFO
1858 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
1859 le32_to_cpu(readreply
->status
));
1861 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1862 SAM_STAT_CHECK_CONDITION
;
1863 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1864 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1865 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1866 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1867 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1868 SCSI_SENSE_BUFFERSIZE
));
1871 aac_fib_complete(fibptr
);
1872 aac_fib_free(fibptr
);
1874 scsicmd
->scsi_done(scsicmd
);
1877 static int aac_read(struct scsi_cmnd
* scsicmd
)
1882 struct aac_dev
*dev
;
1883 struct fib
* cmd_fibcontext
;
1886 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1888 * Get block address and transfer length
1890 switch (scsicmd
->cmnd
[0]) {
1892 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
1894 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1895 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1896 count
= scsicmd
->cmnd
[4];
1902 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
1904 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1905 ((u64
)scsicmd
->cmnd
[3] << 48) |
1906 ((u64
)scsicmd
->cmnd
[4] << 40) |
1907 ((u64
)scsicmd
->cmnd
[5] << 32) |
1908 ((u64
)scsicmd
->cmnd
[6] << 24) |
1909 (scsicmd
->cmnd
[7] << 16) |
1910 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1911 count
= (scsicmd
->cmnd
[10] << 24) |
1912 (scsicmd
->cmnd
[11] << 16) |
1913 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
1916 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
1918 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1919 (scsicmd
->cmnd
[3] << 16) |
1920 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1921 count
= (scsicmd
->cmnd
[6] << 24) |
1922 (scsicmd
->cmnd
[7] << 16) |
1923 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1926 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
1928 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1929 (scsicmd
->cmnd
[3] << 16) |
1930 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1931 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1935 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
1936 cid
= scmd_id(scsicmd
);
1937 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1938 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1939 SAM_STAT_CHECK_CONDITION
;
1940 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1941 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1942 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1943 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1944 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1945 SCSI_SENSE_BUFFERSIZE
));
1946 scsicmd
->scsi_done(scsicmd
);
1950 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1951 smp_processor_id(), (unsigned long long)lba
, jiffies
));
1952 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
1955 * Alocate and initialize a Fib
1957 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
1958 printk(KERN_WARNING
"aac_read: fib allocation failed\n");
1962 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
1965 * Check that the command queued to the controller
1967 if (status
== -EINPROGRESS
) {
1968 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1972 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
1974 * For some reason, the Fib didn't queue, return QUEUE_FULL
1976 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
1977 scsicmd
->scsi_done(scsicmd
);
1978 aac_fib_complete(cmd_fibcontext
);
1979 aac_fib_free(cmd_fibcontext
);
1983 static int aac_write(struct scsi_cmnd
* scsicmd
)
1989 struct aac_dev
*dev
;
1990 struct fib
* cmd_fibcontext
;
1993 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1995 * Get block address and transfer length
1997 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
1999 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2000 count
= scsicmd
->cmnd
[4];
2004 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
2005 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
2007 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2008 ((u64
)scsicmd
->cmnd
[3] << 48) |
2009 ((u64
)scsicmd
->cmnd
[4] << 40) |
2010 ((u64
)scsicmd
->cmnd
[5] << 32) |
2011 ((u64
)scsicmd
->cmnd
[6] << 24) |
2012 (scsicmd
->cmnd
[7] << 16) |
2013 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2014 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
2015 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2016 fua
= scsicmd
->cmnd
[1] & 0x8;
2017 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
2018 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
2020 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
2021 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2022 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
2023 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2024 fua
= scsicmd
->cmnd
[1] & 0x8;
2026 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
2027 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2028 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2029 fua
= scsicmd
->cmnd
[1] & 0x8;
2032 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2033 cid
= scmd_id(scsicmd
);
2034 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2035 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2036 SAM_STAT_CHECK_CONDITION
;
2037 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2038 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2039 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2040 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2041 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2042 SCSI_SENSE_BUFFERSIZE
));
2043 scsicmd
->scsi_done(scsicmd
);
2047 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2048 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2049 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2052 * Allocate and initialize a Fib then setup a BlockWrite command
2054 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
2055 /* FIB temporarily unavailable,not catastrophic failure */
2057 /* scsicmd->result = DID_ERROR << 16;
2058 * scsicmd->scsi_done(scsicmd);
2061 printk(KERN_WARNING
"aac_write: fib allocation failed\n");
2065 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
2068 * Check that the command queued to the controller
2070 if (status
== -EINPROGRESS
) {
2071 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2075 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
2077 * For some reason, the Fib didn't queue, return QUEUE_FULL
2079 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2080 scsicmd
->scsi_done(scsicmd
);
2082 aac_fib_complete(cmd_fibcontext
);
2083 aac_fib_free(cmd_fibcontext
);
2087 static void synchronize_callback(void *context
, struct fib
*fibptr
)
2089 struct aac_synchronize_reply
*synchronizereply
;
2090 struct scsi_cmnd
*cmd
;
2094 if (!aac_valid_context(cmd
, fibptr
))
2097 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
2098 smp_processor_id(), jiffies
));
2099 BUG_ON(fibptr
== NULL
);
2102 synchronizereply
= fib_data(fibptr
);
2103 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
2104 cmd
->result
= DID_OK
<< 16 |
2105 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2107 struct scsi_device
*sdev
= cmd
->device
;
2108 struct aac_dev
*dev
= fibptr
->dev
;
2109 u32 cid
= sdev_id(sdev
);
2111 "synchronize_callback: synchronize failed, status = %d\n",
2112 le32_to_cpu(synchronizereply
->status
));
2113 cmd
->result
= DID_OK
<< 16 |
2114 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2115 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2116 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2117 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2118 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2119 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2120 SCSI_SENSE_BUFFERSIZE
));
2123 aac_fib_complete(fibptr
);
2124 aac_fib_free(fibptr
);
2125 cmd
->scsi_done(cmd
);
2128 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
2131 struct fib
*cmd_fibcontext
;
2132 struct aac_synchronize
*synchronizecmd
;
2133 struct scsi_cmnd
*cmd
;
2134 struct scsi_device
*sdev
= scsicmd
->device
;
2136 struct aac_dev
*aac
;
2137 u64 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) |
2138 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2139 u32 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2140 unsigned long flags
;
2143 * Wait for all outstanding queued commands to complete to this
2144 * specific target (block).
2146 spin_lock_irqsave(&sdev
->list_lock
, flags
);
2147 list_for_each_entry(cmd
, &sdev
->cmd_list
, list
)
2148 if (cmd
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
2152 if (cmd
->cmnd
[0] == WRITE_6
) {
2153 cmnd_lba
= ((cmd
->cmnd
[1] & 0x1F) << 16) |
2154 (cmd
->cmnd
[2] << 8) |
2156 cmnd_count
= cmd
->cmnd
[4];
2157 if (cmnd_count
== 0)
2159 } else if (cmd
->cmnd
[0] == WRITE_16
) {
2160 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 56) |
2161 ((u64
)cmd
->cmnd
[3] << 48) |
2162 ((u64
)cmd
->cmnd
[4] << 40) |
2163 ((u64
)cmd
->cmnd
[5] << 32) |
2164 ((u64
)cmd
->cmnd
[6] << 24) |
2165 (cmd
->cmnd
[7] << 16) |
2166 (cmd
->cmnd
[8] << 8) |
2168 cmnd_count
= (cmd
->cmnd
[10] << 24) |
2169 (cmd
->cmnd
[11] << 16) |
2170 (cmd
->cmnd
[12] << 8) |
2172 } else if (cmd
->cmnd
[0] == WRITE_12
) {
2173 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2174 (cmd
->cmnd
[3] << 16) |
2175 (cmd
->cmnd
[4] << 8) |
2177 cmnd_count
= (cmd
->cmnd
[6] << 24) |
2178 (cmd
->cmnd
[7] << 16) |
2179 (cmd
->cmnd
[8] << 8) |
2181 } else if (cmd
->cmnd
[0] == WRITE_10
) {
2182 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2183 (cmd
->cmnd
[3] << 16) |
2184 (cmd
->cmnd
[4] << 8) |
2186 cmnd_count
= (cmd
->cmnd
[7] << 8) |
2190 if (((cmnd_lba
+ cmnd_count
) < lba
) ||
2191 (count
&& ((lba
+ count
) < cmnd_lba
)))
2197 spin_unlock_irqrestore(&sdev
->list_lock
, flags
);
2200 * Yield the processor (requeue for later)
2203 return SCSI_MLQUEUE_DEVICE_BUSY
;
2205 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2207 return SCSI_MLQUEUE_HOST_BUSY
;
2210 * Allocate and initialize a Fib
2212 if (!(cmd_fibcontext
= aac_fib_alloc(aac
)))
2213 return SCSI_MLQUEUE_HOST_BUSY
;
2215 aac_fib_init(cmd_fibcontext
);
2217 synchronizecmd
= fib_data(cmd_fibcontext
);
2218 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2219 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
2220 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
2221 synchronizecmd
->count
=
2222 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
2225 * Now send the Fib to the adapter
2227 status
= aac_fib_send(ContainerCommand
,
2229 sizeof(struct aac_synchronize
),
2232 (fib_callback
)synchronize_callback
,
2236 * Check that the command queued to the controller
2238 if (status
== -EINPROGRESS
) {
2239 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2244 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
2245 aac_fib_complete(cmd_fibcontext
);
2246 aac_fib_free(cmd_fibcontext
);
2247 return SCSI_MLQUEUE_HOST_BUSY
;
2250 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
2252 struct scsi_cmnd
*scsicmd
= context
;
2254 if (!aac_valid_context(scsicmd
, fibptr
))
2257 BUG_ON(fibptr
== NULL
);
2259 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2261 aac_fib_complete(fibptr
);
2262 aac_fib_free(fibptr
);
2263 scsicmd
->scsi_done(scsicmd
);
2266 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
2269 struct fib
*cmd_fibcontext
;
2270 struct aac_power_management
*pmcmd
;
2271 struct scsi_device
*sdev
= scsicmd
->device
;
2272 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2274 if (!(aac
->supplement_adapter_info
.SupportedOptions2
&
2275 AAC_OPTION_POWER_MANAGEMENT
)) {
2276 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2278 scsicmd
->scsi_done(scsicmd
);
2283 return SCSI_MLQUEUE_HOST_BUSY
;
2286 * Allocate and initialize a Fib
2288 cmd_fibcontext
= aac_fib_alloc(aac
);
2289 if (!cmd_fibcontext
)
2290 return SCSI_MLQUEUE_HOST_BUSY
;
2292 aac_fib_init(cmd_fibcontext
);
2294 pmcmd
= fib_data(cmd_fibcontext
);
2295 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2296 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
2297 /* Eject bit ignored, not relevant */
2298 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
2299 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
2300 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
2301 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
2302 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
2305 * Now send the Fib to the adapter
2307 status
= aac_fib_send(ContainerCommand
,
2309 sizeof(struct aac_power_management
),
2312 (fib_callback
)aac_start_stop_callback
,
2316 * Check that the command queued to the controller
2318 if (status
== -EINPROGRESS
) {
2319 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2323 aac_fib_complete(cmd_fibcontext
);
2324 aac_fib_free(cmd_fibcontext
);
2325 return SCSI_MLQUEUE_HOST_BUSY
;
2329 * aac_scsi_cmd() - Process SCSI command
2330 * @scsicmd: SCSI command block
2332 * Emulate a SCSI command and queue the required request for the
2336 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
2339 struct Scsi_Host
*host
= scsicmd
->device
->host
;
2340 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
2341 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
2343 if (fsa_dev_ptr
== NULL
)
2346 * If the bus, id or lun is out of range, return fail
2347 * Test does not apply to ID 16, the pseudo id for the controller
2350 cid
= scmd_id(scsicmd
);
2351 if (cid
!= host
->this_id
) {
2352 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
2353 if((cid
>= dev
->maximum_num_containers
) ||
2354 (scsicmd
->device
->lun
!= 0)) {
2355 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2356 scsicmd
->scsi_done(scsicmd
);
2361 * If the target container doesn't exist, it may have
2362 * been newly created
2364 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2365 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2367 switch (scsicmd
->cmnd
[0]) {
2368 case SERVICE_ACTION_IN_16
:
2369 if (!(dev
->raw_io_interface
) ||
2370 !(dev
->raw_io_64
) ||
2371 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2375 case TEST_UNIT_READY
:
2378 return _aac_probe_container(scsicmd
,
2379 aac_probe_container_callback2
);
2384 } else { /* check for physical non-dasd devices */
2385 if (dev
->nondasd_support
|| expose_physicals
||
2389 return aac_send_srb_fib(scsicmd
);
2391 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2392 scsicmd
->scsi_done(scsicmd
);
2398 * else Command for the controller itself
2400 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2401 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2403 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2404 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2405 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2406 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2407 ASENCODE_INVALID_COMMAND
, 0, 0);
2408 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2409 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2410 SCSI_SENSE_BUFFERSIZE
));
2411 scsicmd
->scsi_done(scsicmd
);
2416 /* Handle commands here that don't really require going out to the adapter */
2417 switch (scsicmd
->cmnd
[0]) {
2420 struct inquiry_data inq_data
;
2422 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2423 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2425 if ((scsicmd
->cmnd
[1] & 0x1) && aac_wwn
) {
2426 char *arr
= (char *)&inq_data
;
2429 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2430 INQD_PDT_PROC
: INQD_PDT_DA
;
2431 if (scsicmd
->cmnd
[2] == 0) {
2432 /* supported vital product data pages */
2437 arr
[1] = scsicmd
->cmnd
[2];
2438 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2440 scsicmd
->result
= DID_OK
<< 16 |
2441 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2442 } else if (scsicmd
->cmnd
[2] == 0x80) {
2443 /* unit serial number page */
2444 arr
[3] = setinqserial(dev
, &arr
[4],
2446 arr
[1] = scsicmd
->cmnd
[2];
2447 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2450 return aac_get_container_serial(
2452 scsicmd
->result
= DID_OK
<< 16 |
2453 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2454 } else if (scsicmd
->cmnd
[2] == 0x83) {
2455 /* vpd page 0x83 - Device Identification Page */
2456 char *sno
= (char *)&inq_data
;
2457 sno
[3] = setinqserial(dev
, &sno
[4],
2460 return aac_get_container_serial(
2462 scsicmd
->result
= DID_OK
<< 16 |
2463 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2465 /* vpd page not implemented */
2466 scsicmd
->result
= DID_OK
<< 16 |
2467 COMMAND_COMPLETE
<< 8 |
2468 SAM_STAT_CHECK_CONDITION
;
2469 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2470 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2471 ASENCODE_NO_SENSE
, 7, 2);
2472 memcpy(scsicmd
->sense_buffer
,
2473 &dev
->fsa_dev
[cid
].sense_data
,
2475 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2476 SCSI_SENSE_BUFFERSIZE
));
2478 scsicmd
->scsi_done(scsicmd
);
2481 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2482 inq_data
.inqd_rdf
= 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
2483 inq_data
.inqd_len
= 31;
2484 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2485 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2487 * Set the Vendor, Product, and Revision Level
2488 * see: <vendor>.c i.e. aac.c
2490 if (cid
== host
->this_id
) {
2491 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2492 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2493 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2495 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2496 scsicmd
->scsi_done(scsicmd
);
2501 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2502 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2503 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2504 return aac_get_container_name(scsicmd
);
2506 case SERVICE_ACTION_IN_16
:
2507 if (!(dev
->raw_io_interface
) ||
2508 !(dev
->raw_io_64
) ||
2509 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2514 unsigned int alloc_len
;
2516 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2517 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2518 cp
[0] = (capacity
>> 56) & 0xff;
2519 cp
[1] = (capacity
>> 48) & 0xff;
2520 cp
[2] = (capacity
>> 40) & 0xff;
2521 cp
[3] = (capacity
>> 32) & 0xff;
2522 cp
[4] = (capacity
>> 24) & 0xff;
2523 cp
[5] = (capacity
>> 16) & 0xff;
2524 cp
[6] = (capacity
>> 8) & 0xff;
2525 cp
[7] = (capacity
>> 0) & 0xff;
2526 cp
[8] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2527 cp
[9] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2528 cp
[10] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2529 cp
[11] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2532 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
2533 + (scsicmd
->cmnd
[11] << 16)
2534 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
2536 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
2537 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
2538 if (alloc_len
< scsi_bufflen(scsicmd
))
2539 scsi_set_resid(scsicmd
,
2540 scsi_bufflen(scsicmd
) - alloc_len
);
2542 /* Do not cache partition table for arrays */
2543 scsicmd
->device
->removable
= 1;
2545 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2546 scsicmd
->scsi_done(scsicmd
);
2556 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
2557 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2558 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2562 cp
[0] = (capacity
>> 24) & 0xff;
2563 cp
[1] = (capacity
>> 16) & 0xff;
2564 cp
[2] = (capacity
>> 8) & 0xff;
2565 cp
[3] = (capacity
>> 0) & 0xff;
2566 cp
[4] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2567 cp
[5] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2568 cp
[6] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2569 cp
[7] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2570 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
2571 /* Do not cache partition table for arrays */
2572 scsicmd
->device
->removable
= 1;
2573 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2575 scsicmd
->scsi_done(scsicmd
);
2582 int mode_buf_length
= 4;
2586 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2587 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2591 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
2592 memset((char *)&mpd
, 0, sizeof(aac_modep_data
));
2594 /* Mode data length */
2595 mpd
.hd
.data_length
= sizeof(mpd
.hd
) - 1;
2596 /* Medium type - default */
2597 mpd
.hd
.med_type
= 0;
2598 /* Device-specific param,
2599 bit 8: 0/1 = write enabled/protected
2600 bit 4: 0/1 = FUA enabled */
2603 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2604 mpd
.hd
.dev_par
= 0x10;
2605 if (scsicmd
->cmnd
[1] & 0x8)
2606 mpd
.hd
.bd_length
= 0; /* Block descriptor length */
2608 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
2609 mpd
.hd
.data_length
+= mpd
.hd
.bd_length
;
2610 mpd
.bd
.block_length
[0] =
2611 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2612 mpd
.bd
.block_length
[1] =
2613 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2614 mpd
.bd
.block_length
[2] =
2615 fsa_dev_ptr
[cid
].block_size
& 0xff;
2617 mpd
.mpc_buf
[0] = scsicmd
->cmnd
[2];
2618 if (scsicmd
->cmnd
[2] == 0x1C) {
2620 mpd
.mpc_buf
[1] = 0xa;
2621 /* Mode data length */
2622 mpd
.hd
.data_length
= 23;
2624 /* Mode data length */
2625 mpd
.hd
.data_length
= 15;
2628 if (capacity
> 0xffffff) {
2629 mpd
.bd
.block_count
[0] = 0xff;
2630 mpd
.bd
.block_count
[1] = 0xff;
2631 mpd
.bd
.block_count
[2] = 0xff;
2633 mpd
.bd
.block_count
[0] = (capacity
>> 16) & 0xff;
2634 mpd
.bd
.block_count
[1] = (capacity
>> 8) & 0xff;
2635 mpd
.bd
.block_count
[2] = capacity
& 0xff;
2638 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2639 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2640 mpd
.hd
.data_length
+= 3;
2643 mpd
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
2644 ? 0 : 0x04; /* WCE */
2645 mode_buf_length
= sizeof(mpd
);
2648 if (mode_buf_length
> scsicmd
->cmnd
[4])
2649 mode_buf_length
= scsicmd
->cmnd
[4];
2651 mode_buf_length
= sizeof(mpd
);
2652 scsi_sg_copy_from_buffer(scsicmd
,
2655 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2656 scsicmd
->scsi_done(scsicmd
);
2663 int mode_buf_length
= 8;
2664 aac_modep10_data mpd10
;
2666 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2667 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2671 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
2672 memset((char *)&mpd10
, 0, sizeof(aac_modep10_data
));
2673 /* Mode data length (MSB) */
2674 mpd10
.hd
.data_length
[0] = 0;
2675 /* Mode data length (LSB) */
2676 mpd10
.hd
.data_length
[1] = sizeof(mpd10
.hd
) - 1;
2677 /* Medium type - default */
2678 mpd10
.hd
.med_type
= 0;
2679 /* Device-specific param,
2680 bit 8: 0/1 = write enabled/protected
2681 bit 4: 0/1 = FUA enabled */
2682 mpd10
.hd
.dev_par
= 0;
2684 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2685 mpd10
.hd
.dev_par
= 0x10;
2686 mpd10
.hd
.rsrvd
[0] = 0; /* reserved */
2687 mpd10
.hd
.rsrvd
[1] = 0; /* reserved */
2688 if (scsicmd
->cmnd
[1] & 0x8) {
2689 /* Block descriptor length (MSB) */
2690 mpd10
.hd
.bd_length
[0] = 0;
2691 /* Block descriptor length (LSB) */
2692 mpd10
.hd
.bd_length
[1] = 0;
2694 mpd10
.hd
.bd_length
[0] = 0;
2695 mpd10
.hd
.bd_length
[1] = sizeof(mpd10
.bd
);
2697 mpd10
.hd
.data_length
[1] += mpd10
.hd
.bd_length
[1];
2699 mpd10
.bd
.block_length
[0] =
2700 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2701 mpd10
.bd
.block_length
[1] =
2702 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2703 mpd10
.bd
.block_length
[2] =
2704 fsa_dev_ptr
[cid
].block_size
& 0xff;
2706 if (capacity
> 0xffffff) {
2707 mpd10
.bd
.block_count
[0] = 0xff;
2708 mpd10
.bd
.block_count
[1] = 0xff;
2709 mpd10
.bd
.block_count
[2] = 0xff;
2711 mpd10
.bd
.block_count
[0] =
2712 (capacity
>> 16) & 0xff;
2713 mpd10
.bd
.block_count
[1] =
2714 (capacity
>> 8) & 0xff;
2715 mpd10
.bd
.block_count
[2] =
2719 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2720 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2721 mpd10
.hd
.data_length
[1] += 3;
2722 mpd10
.mpc_buf
[0] = 8;
2723 mpd10
.mpc_buf
[1] = 1;
2724 mpd10
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
2725 ? 0 : 0x04; /* WCE */
2726 mode_buf_length
= sizeof(mpd10
);
2727 if (mode_buf_length
> scsicmd
->cmnd
[8])
2728 mode_buf_length
= scsicmd
->cmnd
[8];
2730 scsi_sg_copy_from_buffer(scsicmd
,
2734 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2735 scsicmd
->scsi_done(scsicmd
);
2740 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
2741 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
, sizeof (struct sense_data
));
2742 memset(&dev
->fsa_dev
[cid
].sense_data
, 0, sizeof (struct sense_data
));
2743 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2744 scsicmd
->scsi_done(scsicmd
);
2747 case ALLOW_MEDIUM_REMOVAL
:
2748 dprintk((KERN_DEBUG
"LOCK command.\n"));
2749 if (scsicmd
->cmnd
[4])
2750 fsa_dev_ptr
[cid
].locked
= 1;
2752 fsa_dev_ptr
[cid
].locked
= 0;
2754 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2755 scsicmd
->scsi_done(scsicmd
);
2758 * These commands are all No-Ops
2760 case TEST_UNIT_READY
:
2761 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
2762 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2763 SAM_STAT_CHECK_CONDITION
;
2764 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2765 NOT_READY
, SENCODE_BECOMING_READY
,
2766 ASENCODE_BECOMING_READY
, 0, 0);
2767 memcpy(scsicmd
->sense_buffer
,
2768 &dev
->fsa_dev
[cid
].sense_data
,
2770 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2771 SCSI_SENSE_BUFFERSIZE
));
2772 scsicmd
->scsi_done(scsicmd
);
2779 case REASSIGN_BLOCKS
:
2781 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2782 scsicmd
->scsi_done(scsicmd
);
2786 return aac_start_stop(scsicmd
);
2789 switch (scsicmd
->cmnd
[0])
2798 * Hack to keep track of ordinal number of the device that
2799 * corresponds to a container. Needed to convert
2800 * containers to /dev/sd device names
2803 if (scsicmd
->request
->rq_disk
)
2804 strlcpy(fsa_dev_ptr
[cid
].devname
,
2805 scsicmd
->request
->rq_disk
->disk_name
,
2806 min(sizeof(fsa_dev_ptr
[cid
].devname
),
2807 sizeof(scsicmd
->request
->rq_disk
->disk_name
) + 1));
2809 return aac_read(scsicmd
);
2817 return aac_write(scsicmd
);
2819 case SYNCHRONIZE_CACHE
:
2820 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2821 scsicmd
->result
= DID_OK
<< 16 |
2822 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2823 scsicmd
->scsi_done(scsicmd
);
2826 /* Issue FIB to tell Firmware to flush it's cache */
2827 if ((aac_cache
& 6) != 2)
2828 return aac_synchronize(scsicmd
);
2832 * Unhandled commands
2834 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n", scsicmd
->cmnd
[0]));
2835 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2836 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2837 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2838 ASENCODE_INVALID_COMMAND
, 0, 0);
2839 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2841 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2842 SCSI_SENSE_BUFFERSIZE
));
2843 scsicmd
->scsi_done(scsicmd
);
2848 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
2850 struct aac_query_disk qd
;
2851 struct fsa_dev_info
*fsa_dev_ptr
;
2853 fsa_dev_ptr
= dev
->fsa_dev
;
2856 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
2860 else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1))
2862 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
2864 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
2866 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
2867 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
2869 else return -EINVAL
;
2871 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
2872 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
2873 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
2875 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
2880 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
2881 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
2883 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
2888 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2890 struct aac_delete_disk dd
;
2891 struct fsa_dev_info
*fsa_dev_ptr
;
2893 fsa_dev_ptr
= dev
->fsa_dev
;
2897 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2900 if (dd
.cnum
>= dev
->maximum_num_containers
)
2903 * Mark this container as being deleted.
2905 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
2907 * Mark the container as no longer valid
2909 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2913 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2915 struct aac_delete_disk dd
;
2916 struct fsa_dev_info
*fsa_dev_ptr
;
2918 fsa_dev_ptr
= dev
->fsa_dev
;
2922 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2925 if (dd
.cnum
>= dev
->maximum_num_containers
)
2928 * If the container is locked, it can not be deleted by the API.
2930 if (fsa_dev_ptr
[dd
.cnum
].locked
)
2934 * Mark the container as no longer being valid.
2936 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2937 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
2942 int aac_dev_ioctl(struct aac_dev
*dev
, int cmd
, void __user
*arg
)
2945 case FSACTL_QUERY_DISK
:
2946 return query_disk(dev
, arg
);
2947 case FSACTL_DELETE_DISK
:
2948 return delete_disk(dev
, arg
);
2949 case FSACTL_FORCE_DELETE_DISK
:
2950 return force_delete_disk(dev
, arg
);
2951 case FSACTL_GET_CONTAINERS
:
2952 return aac_get_containers(dev
);
2961 * @context: the context set in the fib - here it is scsi cmd
2962 * @fibptr: pointer to the fib
2964 * Handles the completion of a scsi command to a non dasd device
2968 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
2970 struct aac_dev
*dev
;
2971 struct aac_srb_reply
*srbreply
;
2972 struct scsi_cmnd
*scsicmd
;
2974 scsicmd
= (struct scsi_cmnd
*) context
;
2976 if (!aac_valid_context(scsicmd
, fibptr
))
2979 BUG_ON(fibptr
== NULL
);
2982 scsi_dma_unmap(scsicmd
);
2984 /* expose physical device if expose_physicald flag is on */
2985 if (scsicmd
->cmnd
[0] == INQUIRY
&& !(scsicmd
->cmnd
[1] & 0x01)
2986 && expose_physicals
> 0)
2987 aac_expose_phy_device(scsicmd
);
2989 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
2990 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
2992 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
2994 srbreply
->srb_status
= cpu_to_le32(SRB_STATUS_SUCCESS
);
2995 srbreply
->scsi_status
= cpu_to_le32(SAM_STAT_GOOD
);
2998 * Calculate resid for sg
3000 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
3001 - le32_to_cpu(srbreply
->data_xfer_length
));
3003 * First check the fib status
3006 if (le32_to_cpu(srbreply
->status
) != ST_OK
) {
3009 printk(KERN_WARNING
"aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply
->status
));
3010 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3011 SCSI_SENSE_BUFFERSIZE
);
3012 scsicmd
->result
= DID_ERROR
<< 16
3013 | COMMAND_COMPLETE
<< 8
3014 | SAM_STAT_CHECK_CONDITION
;
3015 memcpy(scsicmd
->sense_buffer
,
3016 srbreply
->sense_data
, len
);
3020 * Next check the srb status
3022 switch ((le32_to_cpu(srbreply
->srb_status
))&0x3f) {
3023 case SRB_STATUS_ERROR_RECOVERY
:
3024 case SRB_STATUS_PENDING
:
3025 case SRB_STATUS_SUCCESS
:
3026 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3028 case SRB_STATUS_DATA_OVERRUN
:
3029 switch (scsicmd
->cmnd
[0]) {
3038 if (le32_to_cpu(srbreply
->data_xfer_length
)
3039 < scsicmd
->underflow
)
3040 printk(KERN_WARNING
"aacraid: SCSI CMD underflow\n");
3042 printk(KERN_WARNING
"aacraid: SCSI CMD Data Overrun\n");
3043 scsicmd
->result
= DID_ERROR
<< 16
3044 | COMMAND_COMPLETE
<< 8;
3047 scsicmd
->result
= DID_OK
<< 16
3048 | COMMAND_COMPLETE
<< 8;
3052 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3056 case SRB_STATUS_ABORTED
:
3057 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3059 case SRB_STATUS_ABORT_FAILED
:
3061 * Not sure about this one - but assuming the
3062 * hba was trying to abort for some reason
3064 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
3066 case SRB_STATUS_PARITY_ERROR
:
3067 scsicmd
->result
= DID_PARITY
<< 16
3068 | MSG_PARITY_ERROR
<< 8;
3070 case SRB_STATUS_NO_DEVICE
:
3071 case SRB_STATUS_INVALID_PATH_ID
:
3072 case SRB_STATUS_INVALID_TARGET_ID
:
3073 case SRB_STATUS_INVALID_LUN
:
3074 case SRB_STATUS_SELECTION_TIMEOUT
:
3075 scsicmd
->result
= DID_NO_CONNECT
<< 16
3076 | COMMAND_COMPLETE
<< 8;
3079 case SRB_STATUS_COMMAND_TIMEOUT
:
3080 case SRB_STATUS_TIMEOUT
:
3081 scsicmd
->result
= DID_TIME_OUT
<< 16
3082 | COMMAND_COMPLETE
<< 8;
3085 case SRB_STATUS_BUSY
:
3086 scsicmd
->result
= DID_BUS_BUSY
<< 16
3087 | COMMAND_COMPLETE
<< 8;
3090 case SRB_STATUS_BUS_RESET
:
3091 scsicmd
->result
= DID_RESET
<< 16
3092 | COMMAND_COMPLETE
<< 8;
3095 case SRB_STATUS_MESSAGE_REJECTED
:
3096 scsicmd
->result
= DID_ERROR
<< 16
3097 | MESSAGE_REJECT
<< 8;
3099 case SRB_STATUS_REQUEST_FLUSHED
:
3100 case SRB_STATUS_ERROR
:
3101 case SRB_STATUS_INVALID_REQUEST
:
3102 case SRB_STATUS_REQUEST_SENSE_FAILED
:
3103 case SRB_STATUS_NO_HBA
:
3104 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
3105 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
3106 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
3107 case SRB_STATUS_DELAYED_RETRY
:
3108 case SRB_STATUS_BAD_FUNCTION
:
3109 case SRB_STATUS_NOT_STARTED
:
3110 case SRB_STATUS_NOT_IN_USE
:
3111 case SRB_STATUS_FORCE_ABORT
:
3112 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
3114 #ifdef AAC_DETAILED_STATUS_INFO
3115 printk(KERN_INFO
"aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
3116 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
3117 aac_get_status_string(
3118 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
3120 le32_to_cpu(srbreply
->scsi_status
));
3122 if ((scsicmd
->cmnd
[0] == ATA_12
)
3123 || (scsicmd
->cmnd
[0] == ATA_16
)) {
3124 if (scsicmd
->cmnd
[2] & (0x01 << 5)) {
3125 scsicmd
->result
= DID_OK
<< 16
3126 | COMMAND_COMPLETE
<< 8;
3129 scsicmd
->result
= DID_ERROR
<< 16
3130 | COMMAND_COMPLETE
<< 8;
3134 scsicmd
->result
= DID_ERROR
<< 16
3135 | COMMAND_COMPLETE
<< 8;
3139 if (le32_to_cpu(srbreply
->scsi_status
)
3140 == SAM_STAT_CHECK_CONDITION
) {
3143 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
3144 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3145 SCSI_SENSE_BUFFERSIZE
);
3146 #ifdef AAC_DETAILED_STATUS_INFO
3147 printk(KERN_WARNING
"aac_srb_callback: check condition, status = %d len=%d\n",
3148 le32_to_cpu(srbreply
->status
), len
);
3150 memcpy(scsicmd
->sense_buffer
,
3151 srbreply
->sense_data
, len
);
3155 * OR in the scsi status (already shifted up a bit)
3157 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
3159 aac_fib_complete(fibptr
);
3160 aac_fib_free(fibptr
);
3161 scsicmd
->scsi_done(scsicmd
);
3167 * @scsicmd: the scsi command block
3169 * This routine will form a FIB and fill in the aac_srb from the
3170 * scsicmd passed in.
3173 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
3175 struct fib
* cmd_fibcontext
;
3176 struct aac_dev
* dev
;
3179 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3180 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3181 scsicmd
->device
->lun
> 7) {
3182 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3183 scsicmd
->scsi_done(scsicmd
);
3188 * Allocate and initialize a Fib then setup a BlockWrite command
3190 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
3193 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
3196 * Check that the command queued to the controller
3198 if (status
== -EINPROGRESS
) {
3199 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3203 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
3204 aac_fib_complete(cmd_fibcontext
);
3205 aac_fib_free(cmd_fibcontext
);
3210 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*psg
)
3212 struct aac_dev
*dev
;
3213 unsigned long byte_count
= 0;
3216 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3217 // Get rid of old data
3219 psg
->sg
[0].addr
= 0;
3220 psg
->sg
[0].count
= 0;
3222 nseg
= scsi_dma_map(scsicmd
);
3226 struct scatterlist
*sg
;
3229 psg
->count
= cpu_to_le32(nseg
);
3231 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3232 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
3233 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
3234 byte_count
+= sg_dma_len(sg
);
3236 /* hba wants the size to be exact */
3237 if (byte_count
> scsi_bufflen(scsicmd
)) {
3238 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3239 (byte_count
- scsi_bufflen(scsicmd
));
3240 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3241 byte_count
= scsi_bufflen(scsicmd
);
3243 /* Check for command underflow */
3244 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3245 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3246 byte_count
, scsicmd
->underflow
);
3253 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
)
3255 struct aac_dev
*dev
;
3256 unsigned long byte_count
= 0;
3260 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3261 // Get rid of old data
3263 psg
->sg
[0].addr
[0] = 0;
3264 psg
->sg
[0].addr
[1] = 0;
3265 psg
->sg
[0].count
= 0;
3267 nseg
= scsi_dma_map(scsicmd
);
3271 struct scatterlist
*sg
;
3274 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3275 int count
= sg_dma_len(sg
);
3276 addr
= sg_dma_address(sg
);
3277 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
3278 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
3279 psg
->sg
[i
].count
= cpu_to_le32(count
);
3280 byte_count
+= count
;
3282 psg
->count
= cpu_to_le32(nseg
);
3283 /* hba wants the size to be exact */
3284 if (byte_count
> scsi_bufflen(scsicmd
)) {
3285 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3286 (byte_count
- scsi_bufflen(scsicmd
));
3287 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3288 byte_count
= scsi_bufflen(scsicmd
);
3290 /* Check for command underflow */
3291 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3292 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3293 byte_count
, scsicmd
->underflow
);
3299 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
)
3301 unsigned long byte_count
= 0;
3304 // Get rid of old data
3306 psg
->sg
[0].next
= 0;
3307 psg
->sg
[0].prev
= 0;
3308 psg
->sg
[0].addr
[0] = 0;
3309 psg
->sg
[0].addr
[1] = 0;
3310 psg
->sg
[0].count
= 0;
3311 psg
->sg
[0].flags
= 0;
3313 nseg
= scsi_dma_map(scsicmd
);
3317 struct scatterlist
*sg
;
3320 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3321 int count
= sg_dma_len(sg
);
3322 u64 addr
= sg_dma_address(sg
);
3323 psg
->sg
[i
].next
= 0;
3324 psg
->sg
[i
].prev
= 0;
3325 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
3326 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
3327 psg
->sg
[i
].count
= cpu_to_le32(count
);
3328 psg
->sg
[i
].flags
= 0;
3329 byte_count
+= count
;
3331 psg
->count
= cpu_to_le32(nseg
);
3332 /* hba wants the size to be exact */
3333 if (byte_count
> scsi_bufflen(scsicmd
)) {
3334 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3335 (byte_count
- scsi_bufflen(scsicmd
));
3336 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3337 byte_count
= scsi_bufflen(scsicmd
);
3339 /* Check for command underflow */
3340 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3341 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3342 byte_count
, scsicmd
->underflow
);
3348 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
3349 struct aac_raw_io2
*rio2
, int sg_max
)
3351 unsigned long byte_count
= 0;
3354 nseg
= scsi_dma_map(scsicmd
);
3358 struct scatterlist
*sg
;
3359 int i
, conformable
= 0;
3360 u32 min_size
= PAGE_SIZE
, cur_size
;
3362 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3363 int count
= sg_dma_len(sg
);
3364 u64 addr
= sg_dma_address(sg
);
3366 BUG_ON(i
>= sg_max
);
3367 rio2
->sge
[i
].addrHigh
= cpu_to_le32((u32
)(addr
>>32));
3368 rio2
->sge
[i
].addrLow
= cpu_to_le32((u32
)(addr
& 0xffffffff));
3369 cur_size
= cpu_to_le32(count
);
3370 rio2
->sge
[i
].length
= cur_size
;
3371 rio2
->sge
[i
].flags
= 0;
3374 rio2
->sgeFirstSize
= cur_size
;
3375 } else if (i
== 1) {
3376 rio2
->sgeNominalSize
= cur_size
;
3377 min_size
= cur_size
;
3378 } else if ((i
+1) < nseg
&& cur_size
!= rio2
->sgeNominalSize
) {
3380 if (cur_size
< min_size
)
3381 min_size
= cur_size
;
3383 byte_count
+= count
;
3386 /* hba wants the size to be exact */
3387 if (byte_count
> scsi_bufflen(scsicmd
)) {
3388 u32 temp
= le32_to_cpu(rio2
->sge
[i
-1].length
) -
3389 (byte_count
- scsi_bufflen(scsicmd
));
3390 rio2
->sge
[i
-1].length
= cpu_to_le32(temp
);
3391 byte_count
= scsi_bufflen(scsicmd
);
3394 rio2
->sgeCnt
= cpu_to_le32(nseg
);
3395 rio2
->flags
|= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212
);
3396 /* not conformable: evaluate required sg elements */
3398 int j
, nseg_new
= nseg
, err_found
;
3399 for (i
= min_size
/ PAGE_SIZE
; i
>= 1; --i
) {
3402 for (j
= 1; j
< nseg
- 1; ++j
) {
3403 if (rio2
->sge
[j
].length
% (i
*PAGE_SIZE
)) {
3407 nseg_new
+= (rio2
->sge
[j
].length
/ (i
*PAGE_SIZE
));
3412 if (i
> 0 && nseg_new
<= sg_max
)
3413 aac_convert_sgraw2(rio2
, i
, nseg
, nseg_new
);
3415 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3417 /* Check for command underflow */
3418 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3419 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3420 byte_count
, scsicmd
->underflow
);
3427 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
, int pages
, int nseg
, int nseg_new
)
3429 struct sge_ieee1212
*sge
;
3433 if (aac_convert_sgl
== 0)
3436 sge
= kmalloc(nseg_new
* sizeof(struct sge_ieee1212
), GFP_ATOMIC
);
3440 for (i
= 1, pos
= 1; i
< nseg
-1; ++i
) {
3441 for (j
= 0; j
< rio2
->sge
[i
].length
/ (pages
* PAGE_SIZE
); ++j
) {
3442 addr_low
= rio2
->sge
[i
].addrLow
+ j
* pages
* PAGE_SIZE
;
3443 sge
[pos
].addrLow
= addr_low
;
3444 sge
[pos
].addrHigh
= rio2
->sge
[i
].addrHigh
;
3445 if (addr_low
< rio2
->sge
[i
].addrLow
)
3446 sge
[pos
].addrHigh
++;
3447 sge
[pos
].length
= pages
* PAGE_SIZE
;
3452 sge
[pos
] = rio2
->sge
[nseg
-1];
3453 memcpy(&rio2
->sge
[1], &sge
[1], (nseg_new
-1)*sizeof(struct sge_ieee1212
));
3456 rio2
->sgeCnt
= cpu_to_le32(nseg_new
);
3457 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3458 rio2
->sgeNominalSize
= pages
* PAGE_SIZE
;
3462 #ifdef AAC_DETAILED_STATUS_INFO
3464 struct aac_srb_status_info
{
3470 static struct aac_srb_status_info srb_status_info
[] = {
3471 { SRB_STATUS_PENDING
, "Pending Status"},
3472 { SRB_STATUS_SUCCESS
, "Success"},
3473 { SRB_STATUS_ABORTED
, "Aborted Command"},
3474 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
3475 { SRB_STATUS_ERROR
, "Error Event"},
3476 { SRB_STATUS_BUSY
, "Device Busy"},
3477 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
3478 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
3479 { SRB_STATUS_NO_DEVICE
, "No Device"},
3480 { SRB_STATUS_TIMEOUT
, "Timeout"},
3481 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
3482 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
3483 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
3484 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
3485 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
3486 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
3487 { SRB_STATUS_NO_HBA
, "No HBA"},
3488 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
3489 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
3490 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
3491 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
3492 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
3493 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
3494 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
3495 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
3496 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
3497 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
3498 { SRB_STATUS_NOT_STARTED
, "Not Started"},
3499 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
3500 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
3501 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
3502 { 0xff, "Unknown Error"}
3505 char *aac_get_status_string(u32 status
)
3509 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
3510 if (srb_status_info
[i
].status
== status
)
3511 return srb_status_info
[i
].str
;
3513 return "Bad Status Code";