1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Adaptec AAC series RAID controller driver
4 * (c) Copyright 2001 Red Hat Inc.
6 * based on the old aacraid driver that is..
7 * Adaptec aacraid device driver for Linux.
9 * Copyright (c) 2000-2010 Adaptec, Inc.
10 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
16 * Abstract: Contains Interfaces to manage IOs.
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/types.h>
22 #include <linux/pci.h>
23 #include <linux/spinlock.h>
24 #include <linux/slab.h>
25 #include <linux/completion.h>
26 #include <linux/blkdev.h>
27 #include <linux/uaccess.h>
28 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
29 #include <linux/module.h>
31 #include <asm/unaligned.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_cmnd.h>
35 #include <scsi/scsi_device.h>
36 #include <scsi/scsi_host.h>
40 /* values for inqd_pdt: Peripheral device type in plain English */
41 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
42 #define INQD_PDT_PROC 0x03 /* Processor device */
43 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
44 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
45 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
46 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
48 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
49 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
55 #define SENCODE_NO_SENSE 0x00
56 #define SENCODE_END_OF_DATA 0x00
57 #define SENCODE_BECOMING_READY 0x04
58 #define SENCODE_INIT_CMD_REQUIRED 0x04
59 #define SENCODE_UNRECOVERED_READ_ERROR 0x11
60 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
61 #define SENCODE_INVALID_COMMAND 0x20
62 #define SENCODE_LBA_OUT_OF_RANGE 0x21
63 #define SENCODE_INVALID_CDB_FIELD 0x24
64 #define SENCODE_LUN_NOT_SUPPORTED 0x25
65 #define SENCODE_INVALID_PARAM_FIELD 0x26
66 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
67 #define SENCODE_PARAM_VALUE_INVALID 0x26
68 #define SENCODE_RESET_OCCURRED 0x29
69 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
70 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
71 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
72 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
73 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
74 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
75 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
76 #define SENCODE_OVERLAPPED_COMMAND 0x4E
79 * Additional sense codes
82 #define ASENCODE_NO_SENSE 0x00
83 #define ASENCODE_END_OF_DATA 0x05
84 #define ASENCODE_BECOMING_READY 0x01
85 #define ASENCODE_INIT_CMD_REQUIRED 0x02
86 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
87 #define ASENCODE_INVALID_COMMAND 0x00
88 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
89 #define ASENCODE_INVALID_CDB_FIELD 0x00
90 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
91 #define ASENCODE_INVALID_PARAM_FIELD 0x00
92 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
93 #define ASENCODE_PARAM_VALUE_INVALID 0x02
94 #define ASENCODE_RESET_OCCURRED 0x00
95 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
96 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
97 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
98 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
99 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
100 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
101 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
102 #define ASENCODE_OVERLAPPED_COMMAND 0x00
104 #define BYTE0(x) (unsigned char)(x)
105 #define BYTE1(x) (unsigned char)((x) >> 8)
106 #define BYTE2(x) (unsigned char)((x) >> 16)
107 #define BYTE3(x) (unsigned char)((x) >> 24)
109 /* MODE_SENSE data format */
116 } __attribute__((packed
)) hd
;
122 } __attribute__((packed
)) bd
;
124 } __attribute__((packed
)) aac_modep_data
;
126 /* MODE_SENSE_10 data format */
134 } __attribute__((packed
)) hd
;
140 } __attribute__((packed
)) bd
;
142 } __attribute__((packed
)) aac_modep10_data
;
144 /*------------------------------------------------------------------------------
145 * S T R U C T S / T Y P E D E F S
146 *----------------------------------------------------------------------------*/
147 /* SCSI inquiry data */
148 struct inquiry_data
{
149 u8 inqd_pdt
; /* Peripheral qualifier | Peripheral Device Type */
150 u8 inqd_dtq
; /* RMB | Device Type Qualifier */
151 u8 inqd_ver
; /* ISO version | ECMA version | ANSI-approved version */
152 u8 inqd_rdf
; /* AENC | TrmIOP | Response data format */
153 u8 inqd_len
; /* Additional length (n-4) */
154 u8 inqd_pad1
[2];/* Reserved - must be zero */
155 u8 inqd_pad2
; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
156 u8 inqd_vid
[8]; /* Vendor ID */
157 u8 inqd_pid
[16];/* Product ID */
158 u8 inqd_prl
[4]; /* Product Revision Level */
161 /* Added for VPD 0x83 */
162 struct tvpd_id_descriptor_type_1
{
163 u8 codeset
:4; /* VPD_CODE_SET */
165 u8 identifiertype
:4; /* VPD_IDENTIFIER_TYPE */
171 u8 serialnumber
[8]; /* SN in ASCII */
175 struct tvpd_id_descriptor_type_2
{
176 u8 codeset
:4; /* VPD_CODE_SET */
178 u8 identifiertype
:4; /* VPD_IDENTIFIER_TYPE */
184 /* The serial number supposed to be 40 bits,
185 * bit we only support 32, so make the last byte zero. */
192 struct tvpd_id_descriptor_type_3
{
193 u8 codeset
: 4; /* VPD_CODE_SET */
195 u8 identifiertype
: 4; /* VPD_IDENTIFIER_TYPE */
204 u8 DeviceTypeQualifier
:3;
208 struct tvpd_id_descriptor_type_1 type1
;
209 struct tvpd_id_descriptor_type_2 type2
;
210 struct tvpd_id_descriptor_type_3 type3
;
214 * M O D U L E G L O B A L S
217 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*sgmap
);
218 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
);
219 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
);
220 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
221 struct aac_raw_io2
*rio2
, int sg_max
);
222 static long aac_build_sghba(struct scsi_cmnd
*scsicmd
,
223 struct aac_hba_cmd_req
*hbacmd
,
224 int sg_max
, u64 sg_address
);
225 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
,
226 int pages
, int nseg
, int nseg_new
);
227 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
);
228 static int aac_send_hba_fib(struct scsi_cmnd
*scsicmd
);
229 #ifdef AAC_DETAILED_STATUS_INFO
230 static char *aac_get_status_string(u32 status
);
234 * Non dasd selection is handled entirely in aachba now
237 static int nondasd
= -1;
238 static int aac_cache
= 2; /* WCE=0 to avoid performance problems */
239 static int dacmode
= -1;
242 int startup_timeout
= 180;
243 int aif_timeout
= 120;
244 int aac_sync_mode
; /* Only Sync. transfer - disabled */
245 static int aac_convert_sgl
= 1; /* convert non-conformable s/g list - enabled */
247 module_param(aac_sync_mode
, int, S_IRUGO
|S_IWUSR
);
248 MODULE_PARM_DESC(aac_sync_mode
, "Force sync. transfer mode"
250 module_param(aac_convert_sgl
, int, S_IRUGO
|S_IWUSR
);
251 MODULE_PARM_DESC(aac_convert_sgl
, "Convert non-conformable s/g list"
253 module_param(nondasd
, int, S_IRUGO
|S_IWUSR
);
254 MODULE_PARM_DESC(nondasd
, "Control scanning of hba for nondasd devices."
256 module_param_named(cache
, aac_cache
, int, S_IRUGO
|S_IWUSR
);
257 MODULE_PARM_DESC(cache
, "Disable Queue Flush commands:\n"
258 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
259 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
260 "\tbit 2 - Disable only if Battery is protecting Cache");
261 module_param(dacmode
, int, S_IRUGO
|S_IWUSR
);
262 MODULE_PARM_DESC(dacmode
, "Control whether dma addressing is using 64 bit DAC."
264 module_param_named(commit
, aac_commit
, int, S_IRUGO
|S_IWUSR
);
265 MODULE_PARM_DESC(commit
, "Control whether a COMMIT_CONFIG is issued to the"
266 " adapter for foreign arrays.\n"
267 "This is typically needed in systems that do not have a BIOS."
269 module_param_named(msi
, aac_msi
, int, S_IRUGO
|S_IWUSR
);
270 MODULE_PARM_DESC(msi
, "IRQ handling."
271 " 0=PIC(default), 1=MSI, 2=MSI-X)");
272 module_param(startup_timeout
, int, S_IRUGO
|S_IWUSR
);
273 MODULE_PARM_DESC(startup_timeout
, "The duration of time in seconds to wait for"
274 " adapter to have it's kernel up and\n"
275 "running. This is typically adjusted for large systems that do not"
277 module_param(aif_timeout
, int, S_IRUGO
|S_IWUSR
);
278 MODULE_PARM_DESC(aif_timeout
, "The duration of time in seconds to wait for"
279 " applications to pick up AIFs before\n"
280 "deregistering them. This is typically adjusted for heavily burdened"
284 module_param(aac_fib_dump
, int, 0644);
285 MODULE_PARM_DESC(aac_fib_dump
, "Dump controller fibs prior to IOP_RESET 0=off, 1=on");
288 module_param(numacb
, int, S_IRUGO
|S_IWUSR
);
289 MODULE_PARM_DESC(numacb
, "Request a limit to the number of adapter control"
290 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
291 " to use suggestion from Firmware.");
293 static int acbsize
= -1;
294 module_param(acbsize
, int, S_IRUGO
|S_IWUSR
);
295 MODULE_PARM_DESC(acbsize
, "Request a specific adapter control block (FIB)"
296 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
297 " suggestion from Firmware.");
299 int update_interval
= 30 * 60;
300 module_param(update_interval
, int, S_IRUGO
|S_IWUSR
);
301 MODULE_PARM_DESC(update_interval
, "Interval in seconds between time sync"
302 " updates issued to adapter.");
304 int check_interval
= 60;
305 module_param(check_interval
, int, S_IRUGO
|S_IWUSR
);
306 MODULE_PARM_DESC(check_interval
, "Interval in seconds between adapter health"
309 int aac_check_reset
= 1;
310 module_param_named(check_reset
, aac_check_reset
, int, S_IRUGO
|S_IWUSR
);
311 MODULE_PARM_DESC(check_reset
, "If adapter fails health check, reset the"
312 " adapter. a value of -1 forces the reset to adapters programmed to"
315 int expose_physicals
= -1;
316 module_param(expose_physicals
, int, S_IRUGO
|S_IWUSR
);
317 MODULE_PARM_DESC(expose_physicals
, "Expose physical components of the arrays."
318 " -1=protect 0=off, 1=on");
320 int aac_reset_devices
;
321 module_param_named(reset_devices
, aac_reset_devices
, int, S_IRUGO
|S_IWUSR
);
322 MODULE_PARM_DESC(reset_devices
, "Force an adapter reset at initialization.");
324 static int aac_wwn
= 1;
325 module_param_named(wwn
, aac_wwn
, int, S_IRUGO
|S_IWUSR
);
326 MODULE_PARM_DESC(wwn
, "Select a WWN type for the arrays:\n"
328 "\t1 - Array Meta Data Signature (default)\n"
329 "\t2 - Adapter Serial Number");
332 static inline int aac_valid_context(struct scsi_cmnd
*scsicmd
,
333 struct fib
*fibptr
) {
334 struct scsi_device
*device
;
336 if (unlikely(!scsicmd
|| !scsicmd
->scsi_done
)) {
337 dprintk((KERN_WARNING
"aac_valid_context: scsi command corrupt\n"));
338 aac_fib_complete(fibptr
);
341 scsicmd
->SCp
.phase
= AAC_OWNER_MIDLEVEL
;
342 device
= scsicmd
->device
;
343 if (unlikely(!device
)) {
344 dprintk((KERN_WARNING
"aac_valid_context: scsi device corrupt\n"));
345 aac_fib_complete(fibptr
);
352 * aac_get_config_status - check the adapter configuration
353 * @dev: aac driver data
354 * @commit_flag: force sending CT_COMMIT_CONFIG
356 * Query config status, and commit the configuration if needed.
358 int aac_get_config_status(struct aac_dev
*dev
, int commit_flag
)
363 if (!(fibptr
= aac_fib_alloc(dev
)))
366 aac_fib_init(fibptr
);
368 struct aac_get_config_status
*dinfo
;
369 dinfo
= (struct aac_get_config_status
*) fib_data(fibptr
);
371 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
372 dinfo
->type
= cpu_to_le32(CT_GET_CONFIG_STATUS
);
373 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_config_status_resp
*)NULL
)->data
));
376 status
= aac_fib_send(ContainerCommand
,
378 sizeof (struct aac_get_config_status
),
383 printk(KERN_WARNING
"aac_get_config_status: SendFIB failed.\n");
385 struct aac_get_config_status_resp
*reply
386 = (struct aac_get_config_status_resp
*) fib_data(fibptr
);
387 dprintk((KERN_WARNING
388 "aac_get_config_status: response=%d status=%d action=%d\n",
389 le32_to_cpu(reply
->response
),
390 le32_to_cpu(reply
->status
),
391 le32_to_cpu(reply
->data
.action
)));
392 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
393 (le32_to_cpu(reply
->status
) != CT_OK
) ||
394 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
395 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
399 /* Do not set XferState to zero unless receives a response from F/W */
401 aac_fib_complete(fibptr
);
403 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
405 if ((aac_commit
== 1) || commit_flag
) {
406 struct aac_commit_config
* dinfo
;
407 aac_fib_init(fibptr
);
408 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
410 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
411 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
413 status
= aac_fib_send(ContainerCommand
,
415 sizeof (struct aac_commit_config
),
419 /* Do not set XferState to zero unless
420 * receives a response from F/W */
422 aac_fib_complete(fibptr
);
423 } else if (aac_commit
== 0) {
425 "aac_get_config_status: Foreign device configurations are being ignored\n");
428 /* FIB should be freed only after getting the response from the F/W */
429 if (status
!= -ERESTARTSYS
)
430 aac_fib_free(fibptr
);
434 static void aac_expose_phy_device(struct scsi_cmnd
*scsicmd
)
437 scsi_sg_copy_to_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
438 if ((inq_data
& 0x20) && (inq_data
& 0x1f) == TYPE_DISK
) {
440 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
445 * aac_get_containers - list containers
446 * @dev: aac driver data
448 * Make a list of all containers on this controller
450 int aac_get_containers(struct aac_dev
*dev
)
452 struct fsa_dev_info
*fsa_dev_ptr
;
456 struct aac_get_container_count
*dinfo
;
457 struct aac_get_container_count_resp
*dresp
;
458 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
460 if (!(fibptr
= aac_fib_alloc(dev
)))
463 aac_fib_init(fibptr
);
464 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
465 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
466 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
468 status
= aac_fib_send(ContainerCommand
,
470 sizeof (struct aac_get_container_count
),
475 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
476 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
477 if (fibptr
->dev
->supplement_adapter_info
.supported_options2
&
478 AAC_OPTION_SUPPORTED_240_VOLUMES
) {
479 maximum_num_containers
=
480 le32_to_cpu(dresp
->MaxSimpleVolumes
);
482 aac_fib_complete(fibptr
);
484 /* FIB should be freed only after getting the response from the F/W */
485 if (status
!= -ERESTARTSYS
)
486 aac_fib_free(fibptr
);
488 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
489 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
490 if (dev
->fsa_dev
== NULL
||
491 dev
->maximum_num_containers
!= maximum_num_containers
) {
493 fsa_dev_ptr
= dev
->fsa_dev
;
495 dev
->fsa_dev
= kcalloc(maximum_num_containers
,
496 sizeof(*fsa_dev_ptr
), GFP_KERNEL
);
505 dev
->maximum_num_containers
= maximum_num_containers
;
507 for (index
= 0; index
< dev
->maximum_num_containers
; index
++) {
508 dev
->fsa_dev
[index
].devname
[0] = '\0';
509 dev
->fsa_dev
[index
].valid
= 0;
511 status
= aac_probe_container(dev
, index
);
514 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
521 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
523 struct aac_get_name_resp
* get_name_reply
;
524 struct scsi_cmnd
* scsicmd
;
526 scsicmd
= (struct scsi_cmnd
*) context
;
528 if (!aac_valid_context(scsicmd
, fibptr
))
531 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
532 BUG_ON(fibptr
== NULL
);
534 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
535 /* Failure is irrelevant, using default value instead */
536 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
537 && (get_name_reply
->data
[0] != '\0')) {
538 char *sp
= get_name_reply
->data
;
539 int data_size
= sizeof_field(struct aac_get_name_resp
, data
);
541 sp
[data_size
- 1] = '\0';
545 struct inquiry_data inq
;
546 char d
[sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
)];
547 int count
= sizeof(d
);
550 *dp
++ = (*sp
) ? *sp
++ : ' ';
551 } while (--count
> 0);
553 scsi_sg_copy_to_buffer(scsicmd
, &inq
, sizeof(inq
));
554 memcpy(inq
.inqd_pid
, d
, sizeof(d
));
555 scsi_sg_copy_from_buffer(scsicmd
, &inq
, sizeof(inq
));
559 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
561 aac_fib_complete(fibptr
);
562 scsicmd
->scsi_done(scsicmd
);
566 * aac_get_container_name - get container name, none blocking.
568 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
)
572 struct aac_get_name
*dinfo
;
573 struct fib
* cmd_fibcontext
;
574 struct aac_dev
* dev
;
576 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
578 data_size
= sizeof_field(struct aac_get_name_resp
, data
);
580 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
582 aac_fib_init(cmd_fibcontext
);
583 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
584 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
586 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
587 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
588 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
589 dinfo
->count
= cpu_to_le32(data_size
- 1);
591 status
= aac_fib_send(ContainerCommand
,
593 sizeof(struct aac_get_name_resp
),
596 (fib_callback
)get_container_name_callback
,
600 * Check that the command queued to the controller
602 if (status
== -EINPROGRESS
)
605 printk(KERN_WARNING
"aac_get_container_name: aac_fib_send failed with status: %d.\n", status
);
606 aac_fib_complete(cmd_fibcontext
);
610 static int aac_probe_container_callback2(struct scsi_cmnd
* scsicmd
)
612 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
614 if ((fsa_dev_ptr
[scmd_id(scsicmd
)].valid
& 1))
615 return aac_scsi_cmd(scsicmd
);
617 scsicmd
->result
= DID_NO_CONNECT
<< 16;
618 scsicmd
->scsi_done(scsicmd
);
622 static void _aac_probe_container2(void * context
, struct fib
* fibptr
)
624 struct fsa_dev_info
*fsa_dev_ptr
;
625 int (*callback
)(struct scsi_cmnd
*);
626 struct scsi_cmnd
* scsicmd
= (struct scsi_cmnd
*)context
;
630 if (!aac_valid_context(scsicmd
, fibptr
))
633 scsicmd
->SCp
.Status
= 0;
634 fsa_dev_ptr
= fibptr
->dev
->fsa_dev
;
636 struct aac_mount
* dresp
= (struct aac_mount
*) fib_data(fibptr
);
639 fsa_dev_ptr
+= scmd_id(scsicmd
);
641 fibptr
->dev
->supplement_adapter_info
.supported_options2
;
643 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
644 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
645 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
646 if (!(sup_options2
& AAC_OPTION_VARIABLE_BLOCK_SIZE
)) {
647 dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
= 0x200;
648 fsa_dev_ptr
->block_size
= 0x200;
650 fsa_dev_ptr
->block_size
=
651 le32_to_cpu(dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
);
653 for (i
= 0; i
< 16; i
++)
654 fsa_dev_ptr
->identifier
[i
] =
655 dresp
->mnt
[0].fileinfo
.bdevinfo
657 fsa_dev_ptr
->valid
= 1;
658 /* sense_key holds the current state of the spin-up */
659 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
660 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
661 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
662 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
663 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
665 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
666 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
667 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
669 if ((fsa_dev_ptr
->valid
& 1) == 0)
670 fsa_dev_ptr
->valid
= 0;
671 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
673 aac_fib_complete(fibptr
);
674 aac_fib_free(fibptr
);
675 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
676 scsicmd
->SCp
.ptr
= NULL
;
677 (*callback
)(scsicmd
);
681 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
683 struct scsi_cmnd
* scsicmd
;
684 struct aac_mount
* dresp
;
685 struct aac_query_mount
*dinfo
;
688 dresp
= (struct aac_mount
*) fib_data(fibptr
);
689 if (!aac_supports_2T(fibptr
->dev
)) {
690 dresp
->mnt
[0].capacityhigh
= 0;
691 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
692 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
693 _aac_probe_container2(context
, fibptr
);
697 scsicmd
= (struct scsi_cmnd
*) context
;
699 if (!aac_valid_context(scsicmd
, fibptr
))
702 aac_fib_init(fibptr
);
704 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
706 if (fibptr
->dev
->supplement_adapter_info
.supported_options2
&
707 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
708 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
710 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
712 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
713 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
714 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
716 status
= aac_fib_send(ContainerCommand
,
718 sizeof(struct aac_query_mount
),
721 _aac_probe_container2
,
724 * Check that the command queued to the controller
726 if (status
< 0 && status
!= -EINPROGRESS
) {
727 /* Inherit results from VM_NameServe, if any */
728 dresp
->status
= cpu_to_le32(ST_OK
);
729 _aac_probe_container2(context
, fibptr
);
733 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
736 int status
= -ENOMEM
;
738 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
739 struct aac_query_mount
*dinfo
;
741 aac_fib_init(fibptr
);
743 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
745 if (fibptr
->dev
->supplement_adapter_info
.supported_options2
&
746 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
747 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
749 dinfo
->command
= cpu_to_le32(VM_NameServe
);
751 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
752 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
753 scsicmd
->SCp
.ptr
= (char *)callback
;
754 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
756 status
= aac_fib_send(ContainerCommand
,
758 sizeof(struct aac_query_mount
),
761 _aac_probe_container1
,
764 * Check that the command queued to the controller
766 if (status
== -EINPROGRESS
)
770 scsicmd
->SCp
.ptr
= NULL
;
771 aac_fib_complete(fibptr
);
772 aac_fib_free(fibptr
);
776 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
778 fsa_dev_ptr
+= scmd_id(scsicmd
);
779 if ((fsa_dev_ptr
->valid
& 1) == 0) {
780 fsa_dev_ptr
->valid
= 0;
781 return (*callback
)(scsicmd
);
789 * aac_probe_container - query a logical volume
790 * @scsicmd: the scsi command block
792 * Queries the controller about the given volume. The volume information
793 * is updated in the struct fsa_dev_info structure rather than returned.
795 static int aac_probe_container_callback1(struct scsi_cmnd
* scsicmd
)
797 scsicmd
->device
= NULL
;
801 static void aac_probe_container_scsi_done(struct scsi_cmnd
*scsi_cmnd
)
803 aac_probe_container_callback1(scsi_cmnd
);
806 int aac_probe_container(struct aac_dev
*dev
, int cid
)
808 struct scsi_cmnd
*scsicmd
= kmalloc(sizeof(*scsicmd
), GFP_KERNEL
);
809 struct scsi_device
*scsidev
= kmalloc(sizeof(*scsidev
), GFP_KERNEL
);
812 if (!scsicmd
|| !scsidev
) {
817 scsicmd
->scsi_done
= aac_probe_container_scsi_done
;
819 scsicmd
->device
= scsidev
;
820 scsidev
->sdev_state
= 0;
822 scsidev
->host
= dev
->scsi_host_ptr
;
824 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
825 while (scsicmd
->device
== scsidev
)
828 status
= scsicmd
->SCp
.Status
;
833 /* Local Structure to set SCSI inquiry data strings */
835 char vid
[8]; /* Vendor ID */
836 char pid
[16]; /* Product ID */
837 char prl
[4]; /* Product Revision Level */
841 * InqStrCopy - string merge
842 * @a: string to copy from
843 * @b: string to copy to
845 * Copy a String from one location to another
849 static void inqstrcpy(char *a
, char *b
)
852 while (*a
!= (char)0)
856 static char *container_types
[] = {
880 char * get_container_type(unsigned tindex
)
882 if (tindex
>= ARRAY_SIZE(container_types
))
883 tindex
= ARRAY_SIZE(container_types
) - 1;
884 return container_types
[tindex
];
887 /* Function: setinqstr
889 * Arguments: [1] pointer to void [1] int
891 * Purpose: Sets SCSI inquiry data strings for vendor, product
892 * and revision level. Allows strings to be set in platform dependent
893 * files instead of in OS dependent driver source.
896 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
898 struct scsi_inq
*str
;
899 struct aac_supplement_adapter_info
*sup_adap_info
;
901 sup_adap_info
= &dev
->supplement_adapter_info
;
902 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
903 memset(str
, ' ', sizeof(*str
));
905 if (sup_adap_info
->adapter_type_text
[0]) {
908 char *cname
= kmemdup(sup_adap_info
->adapter_type_text
,
909 sizeof(sup_adap_info
->adapter_type_text
),
915 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
916 inqstrcpy("SMC", str
->vid
);
918 c
= sizeof(str
->vid
);
919 while (*cp
&& *cp
!= ' ' && --c
)
923 inqstrcpy(cname
, str
->vid
);
925 while (*cp
&& *cp
!= ' ')
930 /* last six chars reserved for vol type */
931 if (strlen(cp
) > sizeof(str
->pid
))
932 cp
[sizeof(str
->pid
)] = '\0';
933 inqstrcpy (cp
, str
->pid
);
937 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
939 inqstrcpy (mp
->vname
, str
->vid
);
940 /* last six chars reserved for vol type */
941 inqstrcpy (mp
->model
, str
->pid
);
944 if (tindex
< ARRAY_SIZE(container_types
)){
945 char *findit
= str
->pid
;
947 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
948 /* RAID is superfluous in the context of a RAID device */
949 if (memcmp(findit
-4, "RAID", 4) == 0)
950 *(findit
-= 4) = ' ';
951 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
952 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
953 inqstrcpy (container_types
[tindex
], findit
+ 1);
955 inqstrcpy ("V1.0", str
->prl
);
958 static void build_vpd83_type3(struct tvpd_page83
*vpdpage83data
,
959 struct aac_dev
*dev
, struct scsi_cmnd
*scsicmd
)
963 vpdpage83data
->type3
.codeset
= 1;
964 vpdpage83data
->type3
.identifiertype
= 3;
965 vpdpage83data
->type3
.identifierlength
= sizeof(vpdpage83data
->type3
)
968 for (container
= 0; container
< dev
->maximum_num_containers
;
971 if (scmd_id(scsicmd
) == container
) {
972 memcpy(vpdpage83data
->type3
.Identifier
,
973 dev
->fsa_dev
[container
].identifier
,
980 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
982 struct aac_get_serial_resp
* get_serial_reply
;
983 struct scsi_cmnd
* scsicmd
;
985 BUG_ON(fibptr
== NULL
);
987 scsicmd
= (struct scsi_cmnd
*) context
;
988 if (!aac_valid_context(scsicmd
, fibptr
))
991 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
992 /* Failure is irrelevant, using default value instead */
993 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
994 /*Check to see if it's for VPD 0x83 or 0x80 */
995 if (scsicmd
->cmnd
[2] == 0x83) {
996 /* vpd page 0x83 - Device Identification Page */
999 struct tvpd_page83 vpdpage83data
;
1001 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1003 memset(((u8
*)&vpdpage83data
), 0,
1004 sizeof(vpdpage83data
));
1006 /* DIRECT_ACCESS_DEVIC */
1007 vpdpage83data
.DeviceType
= 0;
1008 /* DEVICE_CONNECTED */
1009 vpdpage83data
.DeviceTypeQualifier
= 0;
1010 /* VPD_DEVICE_IDENTIFIERS */
1011 vpdpage83data
.PageCode
= 0x83;
1012 vpdpage83data
.reserved
= 0;
1013 vpdpage83data
.PageLength
=
1014 sizeof(vpdpage83data
.type1
) +
1015 sizeof(vpdpage83data
.type2
);
1017 /* VPD 83 Type 3 is not supported for ARC */
1018 if (dev
->sa_firmware
)
1019 vpdpage83data
.PageLength
+=
1020 sizeof(vpdpage83data
.type3
);
1022 /* T10 Vendor Identifier Field Format */
1023 /* VpdcodesetAscii */
1024 vpdpage83data
.type1
.codeset
= 2;
1025 /* VpdIdentifierTypeVendorId */
1026 vpdpage83data
.type1
.identifiertype
= 1;
1027 vpdpage83data
.type1
.identifierlength
=
1028 sizeof(vpdpage83data
.type1
) - 4;
1030 /* "ADAPTEC " for adaptec */
1031 memcpy(vpdpage83data
.type1
.venid
,
1033 sizeof(vpdpage83data
.type1
.venid
));
1034 memcpy(vpdpage83data
.type1
.productid
,
1037 vpdpage83data
.type1
.productid
));
1039 /* Convert to ascii based serial number.
1040 * The LSB is the the end.
1042 for (i
= 0; i
< 8; i
++) {
1044 (u8
)((get_serial_reply
->uid
>> ((7 - i
) * 4)) & 0xF);
1046 vpdpage83data
.type1
.serialnumber
[i
] =
1049 vpdpage83data
.type1
.serialnumber
[i
] =
1054 /* VpdCodeSetBinary */
1055 vpdpage83data
.type2
.codeset
= 1;
1056 /* VpdidentifiertypeEUI64 */
1057 vpdpage83data
.type2
.identifiertype
= 2;
1058 vpdpage83data
.type2
.identifierlength
=
1059 sizeof(vpdpage83data
.type2
) - 4;
1061 vpdpage83data
.type2
.eu64id
.venid
[0] = 0xD0;
1062 vpdpage83data
.type2
.eu64id
.venid
[1] = 0;
1063 vpdpage83data
.type2
.eu64id
.venid
[2] = 0;
1065 vpdpage83data
.type2
.eu64id
.Serial
=
1066 get_serial_reply
->uid
;
1067 vpdpage83data
.type2
.eu64id
.reserved
= 0;
1070 * VpdIdentifierTypeFCPHName
1071 * VPD 0x83 Type 3 not supported for ARC
1073 if (dev
->sa_firmware
) {
1074 build_vpd83_type3(&vpdpage83data
,
1078 /* Move the inquiry data to the response buffer. */
1079 scsi_sg_copy_from_buffer(scsicmd
, &vpdpage83data
,
1080 sizeof(vpdpage83data
));
1082 /* It must be for VPD 0x80 */
1085 sp
[0] = INQD_PDT_DA
;
1086 sp
[1] = scsicmd
->cmnd
[2];
1088 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
1089 le32_to_cpu(get_serial_reply
->uid
));
1090 scsi_sg_copy_from_buffer(scsicmd
, sp
,
1095 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1097 aac_fib_complete(fibptr
);
1098 scsicmd
->scsi_done(scsicmd
);
1102 * aac_get_container_serial - get container serial, none blocking.
1104 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
1107 struct aac_get_serial
*dinfo
;
1108 struct fib
* cmd_fibcontext
;
1109 struct aac_dev
* dev
;
1111 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1113 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
1115 aac_fib_init(cmd_fibcontext
);
1116 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
1118 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
1119 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
1120 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1121 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1123 status
= aac_fib_send(ContainerCommand
,
1125 sizeof(struct aac_get_serial_resp
),
1128 (fib_callback
) get_container_serial_callback
,
1132 * Check that the command queued to the controller
1134 if (status
== -EINPROGRESS
)
1137 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
1138 aac_fib_complete(cmd_fibcontext
);
1142 /* Function: setinqserial
1144 * Arguments: [1] pointer to void [1] int
1146 * Purpose: Sets SCSI Unit Serial number.
1147 * This is a fake. We should read a proper
1148 * serial number from the container. <SuSE>But
1149 * without docs it's quite hard to do it :-)
1150 * So this will have to do in the meantime.</SuSE>
1153 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
1156 * This breaks array migration.
1158 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
1159 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
1162 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
1163 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
1165 u8
*sense_buf
= (u8
*)sense_data
;
1166 /* Sense data valid, err code 70h */
1167 sense_buf
[0] = 0x70; /* No info field */
1168 sense_buf
[1] = 0; /* Segment number, always zero */
1170 sense_buf
[2] = sense_key
; /* Sense key */
1172 sense_buf
[12] = sense_code
; /* Additional sense code */
1173 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
1175 if (sense_key
== ILLEGAL_REQUEST
) {
1176 sense_buf
[7] = 10; /* Additional sense length */
1178 sense_buf
[15] = bit_pointer
;
1179 /* Illegal parameter is in the parameter block */
1180 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
1181 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
1182 /* Illegal parameter is in the CDB block */
1183 sense_buf
[16] = field_pointer
>> 8; /* MSB */
1184 sense_buf
[17] = field_pointer
; /* LSB */
1186 sense_buf
[7] = 6; /* Additional sense length */
1189 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1191 if (lba
& 0xffffffff00000000LL
) {
1192 int cid
= scmd_id(cmd
);
1193 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1194 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1195 SAM_STAT_CHECK_CONDITION
;
1196 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1197 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1198 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1199 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1200 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1201 SCSI_SENSE_BUFFERSIZE
));
1202 cmd
->scsi_done(cmd
);
1208 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1213 static void io_callback(void *context
, struct fib
* fibptr
);
1215 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1217 struct aac_dev
*dev
= fib
->dev
;
1218 u16 fibsize
, command
;
1222 if ((dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
1223 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) &&
1225 struct aac_raw_io2
*readcmd2
;
1226 readcmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1227 memset(readcmd2
, 0, sizeof(struct aac_raw_io2
));
1228 readcmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1229 readcmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1230 readcmd2
->byteCount
= cpu_to_le32(count
*
1231 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1232 readcmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1233 readcmd2
->flags
= cpu_to_le16(RIO2_IO_TYPE_READ
);
1234 ret
= aac_build_sgraw2(cmd
, readcmd2
,
1235 dev
->scsi_host_ptr
->sg_tablesize
);
1238 command
= ContainerRawIo2
;
1239 fibsize
= sizeof(struct aac_raw_io2
) +
1240 ((le32_to_cpu(readcmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1242 struct aac_raw_io
*readcmd
;
1243 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
1244 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1245 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1246 readcmd
->count
= cpu_to_le32(count
*
1247 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1248 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1249 readcmd
->flags
= cpu_to_le16(RIO_TYPE_READ
);
1250 readcmd
->bpTotal
= 0;
1251 readcmd
->bpComplete
= 0;
1252 ret
= aac_build_sgraw(cmd
, &readcmd
->sg
);
1255 command
= ContainerRawIo
;
1256 fibsize
= sizeof(struct aac_raw_io
) +
1257 ((le32_to_cpu(readcmd
->sg
.count
)-1) * sizeof(struct sgentryraw
));
1260 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1262 * Now send the Fib to the adapter
1264 return aac_fib_send(command
,
1269 (fib_callback
) io_callback
,
1273 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1276 struct aac_read64
*readcmd
;
1280 readcmd
= (struct aac_read64
*) fib_data(fib
);
1281 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
1282 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1283 readcmd
->sector_count
= cpu_to_le16(count
);
1284 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1288 ret
= aac_build_sg64(cmd
, &readcmd
->sg
);
1291 fibsize
= sizeof(struct aac_read64
) +
1292 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1293 sizeof (struct sgentry64
));
1294 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1295 sizeof(struct aac_fibhdr
)));
1297 * Now send the Fib to the adapter
1299 return aac_fib_send(ContainerCommand64
,
1304 (fib_callback
) io_callback
,
1308 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1311 struct aac_read
*readcmd
;
1312 struct aac_dev
*dev
= fib
->dev
;
1316 readcmd
= (struct aac_read
*) fib_data(fib
);
1317 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
1318 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1319 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1320 readcmd
->count
= cpu_to_le32(count
*
1321 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1323 ret
= aac_build_sg(cmd
, &readcmd
->sg
);
1326 fibsize
= sizeof(struct aac_read
) +
1327 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1328 sizeof (struct sgentry
));
1329 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1330 sizeof(struct aac_fibhdr
)));
1332 * Now send the Fib to the adapter
1334 return aac_fib_send(ContainerCommand
,
1339 (fib_callback
) io_callback
,
1343 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1345 struct aac_dev
*dev
= fib
->dev
;
1346 u16 fibsize
, command
;
1350 if ((dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
1351 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) &&
1353 struct aac_raw_io2
*writecmd2
;
1354 writecmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1355 memset(writecmd2
, 0, sizeof(struct aac_raw_io2
));
1356 writecmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1357 writecmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1358 writecmd2
->byteCount
= cpu_to_le32(count
*
1359 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1360 writecmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1361 writecmd2
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1362 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1363 cpu_to_le16(RIO2_IO_TYPE_WRITE
|RIO2_IO_SUREWRITE
) :
1364 cpu_to_le16(RIO2_IO_TYPE_WRITE
);
1365 ret
= aac_build_sgraw2(cmd
, writecmd2
,
1366 dev
->scsi_host_ptr
->sg_tablesize
);
1369 command
= ContainerRawIo2
;
1370 fibsize
= sizeof(struct aac_raw_io2
) +
1371 ((le32_to_cpu(writecmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1373 struct aac_raw_io
*writecmd
;
1374 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1375 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1376 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1377 writecmd
->count
= cpu_to_le32(count
*
1378 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1379 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1380 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1381 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1382 cpu_to_le16(RIO_TYPE_WRITE
|RIO_SUREWRITE
) :
1383 cpu_to_le16(RIO_TYPE_WRITE
);
1384 writecmd
->bpTotal
= 0;
1385 writecmd
->bpComplete
= 0;
1386 ret
= aac_build_sgraw(cmd
, &writecmd
->sg
);
1389 command
= ContainerRawIo
;
1390 fibsize
= sizeof(struct aac_raw_io
) +
1391 ((le32_to_cpu(writecmd
->sg
.count
)-1) * sizeof (struct sgentryraw
));
1394 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1396 * Now send the Fib to the adapter
1398 return aac_fib_send(command
,
1403 (fib_callback
) io_callback
,
1407 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1410 struct aac_write64
*writecmd
;
1414 writecmd
= (struct aac_write64
*) fib_data(fib
);
1415 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1416 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1417 writecmd
->sector_count
= cpu_to_le16(count
);
1418 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1420 writecmd
->flags
= 0;
1422 ret
= aac_build_sg64(cmd
, &writecmd
->sg
);
1425 fibsize
= sizeof(struct aac_write64
) +
1426 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1427 sizeof (struct sgentry64
));
1428 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1429 sizeof(struct aac_fibhdr
)));
1431 * Now send the Fib to the adapter
1433 return aac_fib_send(ContainerCommand64
,
1438 (fib_callback
) io_callback
,
1442 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1445 struct aac_write
*writecmd
;
1446 struct aac_dev
*dev
= fib
->dev
;
1450 writecmd
= (struct aac_write
*) fib_data(fib
);
1451 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1452 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1453 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1454 writecmd
->count
= cpu_to_le32(count
*
1455 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1456 writecmd
->sg
.count
= cpu_to_le32(1);
1457 /* ->stable is not used - it did mean which type of write */
1459 ret
= aac_build_sg(cmd
, &writecmd
->sg
);
1462 fibsize
= sizeof(struct aac_write
) +
1463 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1464 sizeof (struct sgentry
));
1465 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1466 sizeof(struct aac_fibhdr
)));
1468 * Now send the Fib to the adapter
1470 return aac_fib_send(ContainerCommand
,
1475 (fib_callback
) io_callback
,
1479 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1481 struct aac_srb
* srbcmd
;
1484 struct aac_dev
*dev
= fib
->dev
;
1487 switch(cmd
->sc_data_direction
){
1491 case DMA_BIDIRECTIONAL
:
1492 flag
= SRB_DataIn
| SRB_DataOut
;
1494 case DMA_FROM_DEVICE
:
1498 default: /* shuts up some versions of gcc */
1499 flag
= SRB_NoDataXfer
;
1503 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1504 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1505 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1506 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1507 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1508 srbcmd
->flags
= cpu_to_le32(flag
);
1509 timeout
= cmd
->request
->timeout
/HZ
;
1511 timeout
= (dev
->sa_firmware
? AAC_SA_TIMEOUT
: AAC_ARC_TIMEOUT
);
1512 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1513 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1514 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1518 static struct aac_hba_cmd_req
*aac_construct_hbacmd(struct fib
*fib
,
1519 struct scsi_cmnd
*cmd
)
1521 struct aac_hba_cmd_req
*hbacmd
;
1522 struct aac_dev
*dev
;
1526 dev
= (struct aac_dev
*)cmd
->device
->host
->hostdata
;
1528 hbacmd
= (struct aac_hba_cmd_req
*)fib
->hw_fib_va
;
1529 memset(hbacmd
, 0, 96); /* sizeof(*hbacmd) is not necessary */
1530 /* iu_type is a parameter of aac_hba_send */
1531 switch (cmd
->sc_data_direction
) {
1535 case DMA_FROM_DEVICE
:
1536 case DMA_BIDIRECTIONAL
:
1543 hbacmd
->lun
[1] = cpu_to_le32(cmd
->device
->lun
);
1545 bus
= aac_logical_to_phys(scmd_channel(cmd
));
1546 target
= scmd_id(cmd
);
1547 hbacmd
->it_nexus
= dev
->hba_map
[bus
][target
].rmw_nexus
;
1549 /* we fill in reply_qid later in aac_src_deliver_message */
1550 /* we fill in iu_type, request_id later in aac_hba_send */
1551 /* we fill in emb_data_desc_count later in aac_build_sghba */
1553 memcpy(hbacmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1554 hbacmd
->data_length
= cpu_to_le32(scsi_bufflen(cmd
));
1556 address
= (u64
)fib
->hw_error_pa
;
1557 hbacmd
->error_ptr_hi
= cpu_to_le32((u32
)(address
>> 32));
1558 hbacmd
->error_ptr_lo
= cpu_to_le32((u32
)(address
& 0xffffffff));
1559 hbacmd
->error_length
= cpu_to_le32(FW_ERROR_BUFFER_SIZE
);
1564 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1566 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1569 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1572 ret
= aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1575 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1577 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1578 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1580 * Build Scatter/Gather list
1582 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1583 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1584 sizeof (struct sgentry64
));
1585 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1586 sizeof(struct aac_fibhdr
)));
1589 * Now send the Fib to the adapter
1591 return aac_fib_send(ScsiPortCommand64
, fib
,
1592 fibsize
, FsaNormal
, 0, 1,
1593 (fib_callback
) aac_srb_callback
,
1597 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1600 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1603 ret
= aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1606 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1608 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1609 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1611 * Build Scatter/Gather list
1613 fibsize
= sizeof (struct aac_srb
) +
1614 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1615 sizeof (struct sgentry
));
1616 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1617 sizeof(struct aac_fibhdr
)));
1620 * Now send the Fib to the adapter
1622 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1623 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1626 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1628 if ((sizeof(dma_addr_t
) > 4) && fib
->dev
->needs_dac
&&
1629 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1631 return aac_scsi_32(fib
, cmd
);
1634 static int aac_adapter_hba(struct fib
*fib
, struct scsi_cmnd
*cmd
)
1636 struct aac_hba_cmd_req
*hbacmd
= aac_construct_hbacmd(fib
, cmd
);
1637 struct aac_dev
*dev
;
1640 dev
= (struct aac_dev
*)cmd
->device
->host
->hostdata
;
1642 ret
= aac_build_sghba(cmd
, hbacmd
,
1643 dev
->scsi_host_ptr
->sg_tablesize
, (u64
)fib
->hw_sgl_pa
);
1648 * Now send the HBA command to the adapter
1650 fib
->hbacmd_size
= 64 + le32_to_cpu(hbacmd
->emb_data_desc_count
) *
1651 sizeof(struct aac_hba_sgl
);
1653 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ
, fib
,
1654 (fib_callback
) aac_hba_callback
,
1658 static int aac_send_safw_bmic_cmd(struct aac_dev
*dev
,
1659 struct aac_srb_unit
*srbu
, void *xfer_buf
, int xfer_len
)
1665 struct aac_srb
*srb
;
1666 struct aac_srb_reply
*srb_reply
;
1667 struct sgmap64
*sg64
;
1671 if (!dev
->sa_firmware
)
1675 fibptr
= aac_fib_alloc(dev
);
1679 aac_fib_init(fibptr
);
1680 fibptr
->hw_fib_va
->header
.XferState
&=
1681 ~cpu_to_le32(FastResponseCapable
);
1683 fibsize
= sizeof(struct aac_srb
) - sizeof(struct sgentry
) +
1684 sizeof(struct sgentry64
);
1686 /* allocate DMA buffer for response */
1687 addr
= dma_map_single(&dev
->pdev
->dev
, xfer_buf
, xfer_len
,
1689 if (dma_mapping_error(&dev
->pdev
->dev
, addr
)) {
1694 srb
= fib_data(fibptr
);
1695 memcpy(srb
, &srbu
->srb
, sizeof(struct aac_srb
));
1697 vbus
= (u32
)le16_to_cpu(
1698 dev
->supplement_adapter_info
.virt_device_bus
);
1699 vid
= (u32
)le16_to_cpu(
1700 dev
->supplement_adapter_info
.virt_device_target
);
1702 /* set the common request fields */
1703 srb
->channel
= cpu_to_le32(vbus
);
1704 srb
->id
= cpu_to_le32(vid
);
1706 srb
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1708 srb
->retry_limit
= 0;
1709 srb
->cdb_size
= cpu_to_le32(16);
1710 srb
->count
= cpu_to_le32(xfer_len
);
1712 sg64
= (struct sgmap64
*)&srb
->sg
;
1713 sg64
->count
= cpu_to_le32(1);
1714 sg64
->sg
[0].addr
[1] = cpu_to_le32(upper_32_bits(addr
));
1715 sg64
->sg
[0].addr
[0] = cpu_to_le32(lower_32_bits(addr
));
1716 sg64
->sg
[0].count
= cpu_to_le32(xfer_len
);
1719 * Copy the updated data for other dumping or other usage if needed
1721 memcpy(&srbu
->srb
, srb
, sizeof(struct aac_srb
));
1723 /* issue request to the controller */
1724 rcode
= aac_fib_send(ScsiPortCommand64
, fibptr
, fibsize
, FsaNormal
,
1727 if (rcode
== -ERESTARTSYS
)
1730 if (unlikely(rcode
< 0))
1733 srb_reply
= (struct aac_srb_reply
*)fib_data(fibptr
);
1734 memcpy(&srbu
->srb_reply
, srb_reply
, sizeof(struct aac_srb_reply
));
1737 dma_unmap_single(&dev
->pdev
->dev
, addr
, xfer_len
, DMA_BIDIRECTIONAL
);
1739 aac_fib_complete(fibptr
);
1740 aac_fib_free(fibptr
);
1744 static void aac_set_safw_target_qd(struct aac_dev
*dev
, int bus
, int target
)
1747 struct aac_ciss_identify_pd
*identify_resp
;
1749 if (dev
->hba_map
[bus
][target
].devtype
!= AAC_DEVTYPE_NATIVE_RAW
)
1752 identify_resp
= dev
->hba_map
[bus
][target
].safw_identify_resp
;
1753 if (identify_resp
== NULL
) {
1754 dev
->hba_map
[bus
][target
].qd_limit
= 32;
1758 if (identify_resp
->current_queue_depth_limit
<= 0 ||
1759 identify_resp
->current_queue_depth_limit
> 255)
1760 dev
->hba_map
[bus
][target
].qd_limit
= 32;
1762 dev
->hba_map
[bus
][target
].qd_limit
=
1763 identify_resp
->current_queue_depth_limit
;
1766 static int aac_issue_safw_bmic_identify(struct aac_dev
*dev
,
1767 struct aac_ciss_identify_pd
**identify_resp
, u32 bus
, u32 target
)
1769 int rcode
= -ENOMEM
;
1771 struct aac_srb_unit srbu
;
1772 struct aac_srb
*srbcmd
;
1773 struct aac_ciss_identify_pd
*identify_reply
;
1775 datasize
= sizeof(struct aac_ciss_identify_pd
);
1776 identify_reply
= kmalloc(datasize
, GFP_KERNEL
);
1777 if (!identify_reply
)
1780 memset(&srbu
, 0, sizeof(struct aac_srb_unit
));
1783 srbcmd
->flags
= cpu_to_le32(SRB_DataIn
);
1784 srbcmd
->cdb
[0] = 0x26;
1785 srbcmd
->cdb
[2] = (u8
)((AAC_MAX_LUN
+ target
) & 0x00FF);
1786 srbcmd
->cdb
[6] = CISS_IDENTIFY_PHYSICAL_DEVICE
;
1788 rcode
= aac_send_safw_bmic_cmd(dev
, &srbu
, identify_reply
, datasize
);
1789 if (unlikely(rcode
< 0))
1792 *identify_resp
= identify_reply
;
1797 kfree(identify_reply
);
1801 static inline void aac_free_safw_ciss_luns(struct aac_dev
*dev
)
1803 kfree(dev
->safw_phys_luns
);
1804 dev
->safw_phys_luns
= NULL
;
1808 * aac_get_safw_ciss_luns() Process topology change
1809 * @dev: aac_dev structure
1811 * Execute a CISS REPORT PHYS LUNS and process the results into
1812 * the current hba_map.
1814 static int aac_get_safw_ciss_luns(struct aac_dev
*dev
)
1816 int rcode
= -ENOMEM
;
1818 struct aac_srb
*srbcmd
;
1819 struct aac_srb_unit srbu
;
1820 struct aac_ciss_phys_luns_resp
*phys_luns
;
1822 datasize
= sizeof(struct aac_ciss_phys_luns_resp
) +
1823 (AAC_MAX_TARGETS
- 1) * sizeof(struct _ciss_lun
);
1824 phys_luns
= kmalloc(datasize
, GFP_KERNEL
);
1825 if (phys_luns
== NULL
)
1828 memset(&srbu
, 0, sizeof(struct aac_srb_unit
));
1831 srbcmd
->flags
= cpu_to_le32(SRB_DataIn
);
1832 srbcmd
->cdb
[0] = CISS_REPORT_PHYSICAL_LUNS
;
1833 srbcmd
->cdb
[1] = 2; /* extended reporting */
1834 srbcmd
->cdb
[8] = (u8
)(datasize
>> 8);
1835 srbcmd
->cdb
[9] = (u8
)(datasize
);
1837 rcode
= aac_send_safw_bmic_cmd(dev
, &srbu
, phys_luns
, datasize
);
1838 if (unlikely(rcode
< 0))
1841 if (phys_luns
->resp_flag
!= 2) {
1846 dev
->safw_phys_luns
= phys_luns
;
1855 static inline u32
aac_get_safw_phys_lun_count(struct aac_dev
*dev
)
1857 return get_unaligned_be32(&dev
->safw_phys_luns
->list_length
[0])/24;
1860 static inline u32
aac_get_safw_phys_bus(struct aac_dev
*dev
, int lun
)
1862 return dev
->safw_phys_luns
->lun
[lun
].level2
[1] & 0x3f;
1865 static inline u32
aac_get_safw_phys_target(struct aac_dev
*dev
, int lun
)
1867 return dev
->safw_phys_luns
->lun
[lun
].level2
[0];
1870 static inline u32
aac_get_safw_phys_expose_flag(struct aac_dev
*dev
, int lun
)
1872 return dev
->safw_phys_luns
->lun
[lun
].bus
>> 6;
1875 static inline u32
aac_get_safw_phys_attribs(struct aac_dev
*dev
, int lun
)
1877 return dev
->safw_phys_luns
->lun
[lun
].node_ident
[9];
1880 static inline u32
aac_get_safw_phys_nexus(struct aac_dev
*dev
, int lun
)
1882 return *((u32
*)&dev
->safw_phys_luns
->lun
[lun
].node_ident
[12]);
1885 static inline u32
aac_get_safw_phys_device_type(struct aac_dev
*dev
, int lun
)
1887 return dev
->safw_phys_luns
->lun
[lun
].node_ident
[8];
1890 static inline void aac_free_safw_identify_resp(struct aac_dev
*dev
,
1891 int bus
, int target
)
1893 kfree(dev
->hba_map
[bus
][target
].safw_identify_resp
);
1894 dev
->hba_map
[bus
][target
].safw_identify_resp
= NULL
;
1897 static inline void aac_free_safw_all_identify_resp(struct aac_dev
*dev
,
1905 luns
= aac_get_safw_phys_lun_count(dev
);
1907 if (luns
< lun_count
)
1909 else if (lun_count
< 0)
1912 for (i
= 0; i
< lun_count
; i
++) {
1913 bus
= aac_get_safw_phys_bus(dev
, i
);
1914 target
= aac_get_safw_phys_target(dev
, i
);
1916 aac_free_safw_identify_resp(dev
, bus
, target
);
1920 static int aac_get_safw_attr_all_targets(struct aac_dev
*dev
)
1927 struct aac_ciss_identify_pd
*identify_resp
= NULL
;
1929 lun_count
= aac_get_safw_phys_lun_count(dev
);
1931 for (i
= 0; i
< lun_count
; ++i
) {
1933 bus
= aac_get_safw_phys_bus(dev
, i
);
1934 target
= aac_get_safw_phys_target(dev
, i
);
1936 rcode
= aac_issue_safw_bmic_identify(dev
,
1937 &identify_resp
, bus
, target
);
1939 if (unlikely(rcode
< 0))
1940 goto free_identify_resp
;
1942 dev
->hba_map
[bus
][target
].safw_identify_resp
= identify_resp
;
1948 aac_free_safw_all_identify_resp(dev
, i
);
1953 * aac_set_safw_attr_all_targets- update current hba map with data from FW
1954 * @dev: aac_dev structure
1956 * Update our hba map with the information gathered from the FW
1958 static void aac_set_safw_attr_all_targets(struct aac_dev
*dev
)
1960 /* ok and extended reporting */
1961 u32 lun_count
, nexus
;
1963 u8 expose_flag
, attribs
;
1965 lun_count
= aac_get_safw_phys_lun_count(dev
);
1967 dev
->scan_counter
++;
1969 for (i
= 0; i
< lun_count
; ++i
) {
1971 bus
= aac_get_safw_phys_bus(dev
, i
);
1972 target
= aac_get_safw_phys_target(dev
, i
);
1973 expose_flag
= aac_get_safw_phys_expose_flag(dev
, i
);
1974 attribs
= aac_get_safw_phys_attribs(dev
, i
);
1975 nexus
= aac_get_safw_phys_nexus(dev
, i
);
1977 if (bus
>= AAC_MAX_BUSES
|| target
>= AAC_MAX_TARGETS
)
1980 if (expose_flag
!= 0) {
1981 dev
->hba_map
[bus
][target
].devtype
=
1982 AAC_DEVTYPE_RAID_MEMBER
;
1986 if (nexus
!= 0 && (attribs
& 8)) {
1987 dev
->hba_map
[bus
][target
].devtype
=
1988 AAC_DEVTYPE_NATIVE_RAW
;
1989 dev
->hba_map
[bus
][target
].rmw_nexus
=
1992 dev
->hba_map
[bus
][target
].devtype
=
1993 AAC_DEVTYPE_ARC_RAW
;
1995 dev
->hba_map
[bus
][target
].scan_counter
= dev
->scan_counter
;
1997 aac_set_safw_target_qd(dev
, bus
, target
);
2001 static int aac_setup_safw_targets(struct aac_dev
*dev
)
2005 rcode
= aac_get_containers(dev
);
2006 if (unlikely(rcode
< 0))
2009 rcode
= aac_get_safw_ciss_luns(dev
);
2010 if (unlikely(rcode
< 0))
2013 rcode
= aac_get_safw_attr_all_targets(dev
);
2014 if (unlikely(rcode
< 0))
2015 goto free_ciss_luns
;
2017 aac_set_safw_attr_all_targets(dev
);
2019 aac_free_safw_all_identify_resp(dev
, -1);
2021 aac_free_safw_ciss_luns(dev
);
2026 int aac_setup_safw_adapter(struct aac_dev
*dev
)
2028 return aac_setup_safw_targets(dev
);
2031 int aac_get_adapter_info(struct aac_dev
* dev
)
2035 u32 tmp
, bus
, target
;
2036 struct aac_adapter_info
*info
;
2037 struct aac_bus_info
*command
;
2038 struct aac_bus_info_response
*bus_info
;
2040 if (!(fibptr
= aac_fib_alloc(dev
)))
2043 aac_fib_init(fibptr
);
2044 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
2045 memset(info
,0,sizeof(*info
));
2047 rcode
= aac_fib_send(RequestAdapterInfo
,
2051 -1, 1, /* First `interrupt' command uses special wait */
2056 /* FIB should be freed only after
2057 * getting the response from the F/W */
2058 if (rcode
!= -ERESTARTSYS
) {
2059 aac_fib_complete(fibptr
);
2060 aac_fib_free(fibptr
);
2064 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
2066 dev
->supplement_adapter_info
.virt_device_bus
= 0xffff;
2067 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
2068 struct aac_supplement_adapter_info
* sinfo
;
2070 aac_fib_init(fibptr
);
2072 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
2074 memset(sinfo
,0,sizeof(*sinfo
));
2076 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
2085 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
2086 if (rcode
== -ERESTARTSYS
) {
2087 fibptr
= aac_fib_alloc(dev
);
2094 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
2095 for (bus
= 0; bus
< AAC_MAX_BUSES
; bus
++) {
2096 for (target
= 0; target
< AAC_MAX_TARGETS
; target
++) {
2097 dev
->hba_map
[bus
][target
].devtype
= 0;
2098 dev
->hba_map
[bus
][target
].qd_limit
= 0;
2106 aac_fib_init(fibptr
);
2108 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
2110 memset(bus_info
, 0, sizeof(*bus_info
));
2112 command
= (struct aac_bus_info
*)bus_info
;
2114 command
->Command
= cpu_to_le32(VM_Ioctl
);
2115 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
2116 command
->MethodId
= cpu_to_le32(1);
2117 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
2119 rcode
= aac_fib_send(ContainerCommand
,
2126 /* reasoned default */
2127 dev
->maximum_num_physicals
= 16;
2128 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
2129 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
2130 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
2133 if (!dev
->in_reset
) {
2135 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
2136 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
2142 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
2143 (int)sizeof(dev
->supplement_adapter_info
.build_date
),
2144 dev
->supplement_adapter_info
.build_date
);
2145 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
2146 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
2148 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
2149 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
2150 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
2151 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
2153 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
2154 le32_to_cpu(dev
->adapter_info
.biosbuild
));
2156 if (aac_get_serial_number(
2157 shost_to_class(dev
->scsi_host_ptr
), buffer
))
2158 printk(KERN_INFO
"%s%d: serial %s",
2159 dev
->name
, dev
->id
, buffer
);
2160 if (dev
->supplement_adapter_info
.vpd_info
.tsid
[0]) {
2161 printk(KERN_INFO
"%s%d: TSID %.*s\n",
2163 (int)sizeof(dev
->supplement_adapter_info
2165 dev
->supplement_adapter_info
.vpd_info
.tsid
);
2167 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
2168 (dev
->supplement_adapter_info
.supported_options2
&
2169 AAC_OPTION_IGNORE_RESET
))) {
2170 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
2171 dev
->name
, dev
->id
);
2175 dev
->cache_protected
= 0;
2176 dev
->jbod
= ((dev
->supplement_adapter_info
.feature_bits
&
2177 AAC_FEATURE_JBOD
) != 0);
2178 dev
->nondasd_support
= 0;
2179 dev
->raid_scsi_mode
= 0;
2180 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
2181 dev
->nondasd_support
= 1;
2184 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2185 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2186 * force nondasd support on. If we decide to allow the non-dasd flag
2187 * additional changes changes will have to be made to support
2188 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2189 * changed to support the new dev->raid_scsi_mode flag instead of
2190 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2191 * function aac_detect will have to be modified where it sets up the
2192 * max number of channels based on the aac->nondasd_support flag only.
2194 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
2195 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
2196 dev
->nondasd_support
= 1;
2197 dev
->raid_scsi_mode
= 1;
2199 if (dev
->raid_scsi_mode
!= 0)
2200 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
2201 dev
->name
, dev
->id
);
2204 dev
->nondasd_support
= (nondasd
!=0);
2205 if (dev
->nondasd_support
&& !dev
->in_reset
)
2206 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
2208 if (dma_get_required_mask(&dev
->pdev
->dev
) > DMA_BIT_MASK(32))
2210 dev
->dac_support
= 0;
2211 if ((sizeof(dma_addr_t
) > 4) && dev
->needs_dac
&&
2212 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)) {
2214 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
2215 dev
->name
, dev
->id
);
2216 dev
->dac_support
= 1;
2220 dev
->dac_support
= (dacmode
!=0);
2223 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2224 if (dev
->dac_support
&& (aac_get_driver_ident(dev
->cardtype
)->quirks
2225 & AAC_QUIRK_SCSI_32
)) {
2226 dev
->nondasd_support
= 0;
2228 expose_physicals
= 0;
2231 if (dev
->dac_support
) {
2232 if (!dma_set_mask(&dev
->pdev
->dev
, DMA_BIT_MASK(64))) {
2234 dev_info(&dev
->pdev
->dev
, "64 Bit DAC enabled\n");
2235 } else if (!dma_set_mask(&dev
->pdev
->dev
, DMA_BIT_MASK(32))) {
2236 dev_info(&dev
->pdev
->dev
, "DMA mask set failed, 64 Bit DAC disabled\n");
2237 dev
->dac_support
= 0;
2239 dev_info(&dev
->pdev
->dev
, "No suitable DMA available\n");
2244 * Deal with configuring for the individualized limits of each packet
2247 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
2248 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
2252 if (dev
->raw_io_interface
) {
2253 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
2256 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
2257 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
2259 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
2260 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
2261 sizeof(struct aac_fibhdr
) -
2262 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
2263 sizeof(struct sgentry
);
2264 if (dev
->dac_support
) {
2265 dev
->a_ops
.adapter_read
= aac_read_block64
;
2266 dev
->a_ops
.adapter_write
= aac_write_block64
;
2268 * 38 scatter gather elements
2270 dev
->scsi_host_ptr
->sg_tablesize
=
2271 (dev
->max_fib_size
-
2272 sizeof(struct aac_fibhdr
) -
2273 sizeof(struct aac_write64
) +
2274 sizeof(struct sgentry64
)) /
2275 sizeof(struct sgentry64
);
2277 dev
->a_ops
.adapter_read
= aac_read_block
;
2278 dev
->a_ops
.adapter_write
= aac_write_block
;
2280 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
2281 if (!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
2283 * Worst case size that could cause sg overflow when
2284 * we break up SG elements that are larger than 64KB.
2285 * Would be nice if we could tell the SCSI layer what
2286 * the maximum SG element size can be. Worst case is
2287 * (sg_tablesize-1) 4KB elements with one 64KB
2289 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2291 dev
->scsi_host_ptr
->max_sectors
=
2292 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
2295 if (!dev
->sync_mode
&& dev
->sa_firmware
&&
2296 dev
->scsi_host_ptr
->sg_tablesize
> HBA_MAX_SG_SEPARATE
)
2297 dev
->scsi_host_ptr
->sg_tablesize
= dev
->sg_tablesize
=
2298 HBA_MAX_SG_SEPARATE
;
2300 /* FIB should be freed only after getting the response from the F/W */
2301 if (rcode
!= -ERESTARTSYS
) {
2302 aac_fib_complete(fibptr
);
2303 aac_fib_free(fibptr
);
2310 static void io_callback(void *context
, struct fib
* fibptr
)
2312 struct aac_dev
*dev
;
2313 struct aac_read_reply
*readreply
;
2314 struct scsi_cmnd
*scsicmd
;
2317 scsicmd
= (struct scsi_cmnd
*) context
;
2319 if (!aac_valid_context(scsicmd
, fibptr
))
2323 cid
= scmd_id(scsicmd
);
2325 if (nblank(dprintk(x
))) {
2327 switch (scsicmd
->cmnd
[0]) {
2330 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
2331 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2335 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2336 ((u64
)scsicmd
->cmnd
[3] << 48) |
2337 ((u64
)scsicmd
->cmnd
[4] << 40) |
2338 ((u64
)scsicmd
->cmnd
[5] << 32) |
2339 ((u64
)scsicmd
->cmnd
[6] << 24) |
2340 (scsicmd
->cmnd
[7] << 16) |
2341 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2345 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2346 (scsicmd
->cmnd
[3] << 16) |
2347 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2350 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2351 (scsicmd
->cmnd
[3] << 16) |
2352 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2356 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2357 smp_processor_id(), (unsigned long long)lba
, jiffies
);
2360 BUG_ON(fibptr
== NULL
);
2362 scsi_dma_unmap(scsicmd
);
2364 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
2365 switch (le32_to_cpu(readreply
->status
)) {
2367 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2369 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
2372 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2373 SAM_STAT_CHECK_CONDITION
;
2374 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
2375 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
2376 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2377 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2378 SCSI_SENSE_BUFFERSIZE
));
2381 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2382 SAM_STAT_CHECK_CONDITION
;
2383 set_sense(&dev
->fsa_dev
[cid
].sense_data
, MEDIUM_ERROR
,
2384 SENCODE_UNRECOVERED_READ_ERROR
, ASENCODE_NO_SENSE
, 0, 0);
2385 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2386 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2387 SCSI_SENSE_BUFFERSIZE
));
2390 #ifdef AAC_DETAILED_STATUS_INFO
2391 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
2392 le32_to_cpu(readreply
->status
));
2394 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2395 SAM_STAT_CHECK_CONDITION
;
2396 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2397 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2398 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2399 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2400 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2401 SCSI_SENSE_BUFFERSIZE
));
2404 aac_fib_complete(fibptr
);
2406 scsicmd
->scsi_done(scsicmd
);
2409 static int aac_read(struct scsi_cmnd
* scsicmd
)
2414 struct aac_dev
*dev
;
2415 struct fib
* cmd_fibcontext
;
2418 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2420 * Get block address and transfer length
2422 switch (scsicmd
->cmnd
[0]) {
2424 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
2426 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
2427 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2428 count
= scsicmd
->cmnd
[4];
2434 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
2436 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2437 ((u64
)scsicmd
->cmnd
[3] << 48) |
2438 ((u64
)scsicmd
->cmnd
[4] << 40) |
2439 ((u64
)scsicmd
->cmnd
[5] << 32) |
2440 ((u64
)scsicmd
->cmnd
[6] << 24) |
2441 (scsicmd
->cmnd
[7] << 16) |
2442 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2443 count
= (scsicmd
->cmnd
[10] << 24) |
2444 (scsicmd
->cmnd
[11] << 16) |
2445 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2448 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
2450 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2451 (scsicmd
->cmnd
[3] << 16) |
2452 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2453 count
= (scsicmd
->cmnd
[6] << 24) |
2454 (scsicmd
->cmnd
[7] << 16) |
2455 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2458 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
2460 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2461 (scsicmd
->cmnd
[3] << 16) |
2462 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2463 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2467 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2468 cid
= scmd_id(scsicmd
);
2469 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2470 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2471 SAM_STAT_CHECK_CONDITION
;
2472 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2473 ILLEGAL_REQUEST
, SENCODE_LBA_OUT_OF_RANGE
,
2474 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2475 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2476 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2477 SCSI_SENSE_BUFFERSIZE
));
2478 scsicmd
->scsi_done(scsicmd
);
2482 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
2483 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2484 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2487 * Alocate and initialize a Fib
2489 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2490 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2491 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
2494 * Check that the command queued to the controller
2496 if (status
== -EINPROGRESS
)
2499 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
2501 * For some reason, the Fib didn't queue, return QUEUE_FULL
2503 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2504 scsicmd
->scsi_done(scsicmd
);
2505 aac_fib_complete(cmd_fibcontext
);
2506 aac_fib_free(cmd_fibcontext
);
2510 static int aac_write(struct scsi_cmnd
* scsicmd
)
2516 struct aac_dev
*dev
;
2517 struct fib
* cmd_fibcontext
;
2520 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2522 * Get block address and transfer length
2524 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
2526 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2527 count
= scsicmd
->cmnd
[4];
2531 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
2532 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
2534 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2535 ((u64
)scsicmd
->cmnd
[3] << 48) |
2536 ((u64
)scsicmd
->cmnd
[4] << 40) |
2537 ((u64
)scsicmd
->cmnd
[5] << 32) |
2538 ((u64
)scsicmd
->cmnd
[6] << 24) |
2539 (scsicmd
->cmnd
[7] << 16) |
2540 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2541 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
2542 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2543 fua
= scsicmd
->cmnd
[1] & 0x8;
2544 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
2545 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
2547 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
2548 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2549 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
2550 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2551 fua
= scsicmd
->cmnd
[1] & 0x8;
2553 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
2554 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2555 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2556 fua
= scsicmd
->cmnd
[1] & 0x8;
2559 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2560 cid
= scmd_id(scsicmd
);
2561 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2562 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2563 SAM_STAT_CHECK_CONDITION
;
2564 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2565 ILLEGAL_REQUEST
, SENCODE_LBA_OUT_OF_RANGE
,
2566 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2567 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2568 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2569 SCSI_SENSE_BUFFERSIZE
));
2570 scsicmd
->scsi_done(scsicmd
);
2574 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2575 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2576 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2579 * Allocate and initialize a Fib then setup a BlockWrite command
2581 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2582 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2583 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
2586 * Check that the command queued to the controller
2588 if (status
== -EINPROGRESS
)
2591 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
2593 * For some reason, the Fib didn't queue, return QUEUE_FULL
2595 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2596 scsicmd
->scsi_done(scsicmd
);
2598 aac_fib_complete(cmd_fibcontext
);
2599 aac_fib_free(cmd_fibcontext
);
2603 static void synchronize_callback(void *context
, struct fib
*fibptr
)
2605 struct aac_synchronize_reply
*synchronizereply
;
2606 struct scsi_cmnd
*cmd
= context
;
2608 if (!aac_valid_context(cmd
, fibptr
))
2611 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
2612 smp_processor_id(), jiffies
));
2613 BUG_ON(fibptr
== NULL
);
2616 synchronizereply
= fib_data(fibptr
);
2617 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
2618 cmd
->result
= DID_OK
<< 16 |
2619 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2621 struct scsi_device
*sdev
= cmd
->device
;
2622 struct aac_dev
*dev
= fibptr
->dev
;
2623 u32 cid
= sdev_id(sdev
);
2625 "synchronize_callback: synchronize failed, status = %d\n",
2626 le32_to_cpu(synchronizereply
->status
));
2627 cmd
->result
= DID_OK
<< 16 |
2628 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2629 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2630 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2631 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2632 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2633 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2634 SCSI_SENSE_BUFFERSIZE
));
2637 aac_fib_complete(fibptr
);
2638 aac_fib_free(fibptr
);
2639 cmd
->scsi_done(cmd
);
2642 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
2645 struct fib
*cmd_fibcontext
;
2646 struct aac_synchronize
*synchronizecmd
;
2647 struct scsi_device
*sdev
= scsicmd
->device
;
2648 struct aac_dev
*aac
;
2650 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2652 return SCSI_MLQUEUE_HOST_BUSY
;
2655 * Allocate and initialize a Fib
2657 cmd_fibcontext
= aac_fib_alloc_tag(aac
, scsicmd
);
2659 aac_fib_init(cmd_fibcontext
);
2661 synchronizecmd
= fib_data(cmd_fibcontext
);
2662 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2663 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
2664 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
2665 synchronizecmd
->count
=
2666 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
2667 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2670 * Now send the Fib to the adapter
2672 status
= aac_fib_send(ContainerCommand
,
2674 sizeof(struct aac_synchronize
),
2677 (fib_callback
)synchronize_callback
,
2681 * Check that the command queued to the controller
2683 if (status
== -EINPROGRESS
)
2687 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
2688 aac_fib_complete(cmd_fibcontext
);
2689 aac_fib_free(cmd_fibcontext
);
2690 return SCSI_MLQUEUE_HOST_BUSY
;
2693 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
2695 struct scsi_cmnd
*scsicmd
= context
;
2697 if (!aac_valid_context(scsicmd
, fibptr
))
2700 BUG_ON(fibptr
== NULL
);
2702 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2704 aac_fib_complete(fibptr
);
2705 aac_fib_free(fibptr
);
2706 scsicmd
->scsi_done(scsicmd
);
2709 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
2712 struct fib
*cmd_fibcontext
;
2713 struct aac_power_management
*pmcmd
;
2714 struct scsi_device
*sdev
= scsicmd
->device
;
2715 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2717 if (!(aac
->supplement_adapter_info
.supported_options2
&
2718 AAC_OPTION_POWER_MANAGEMENT
)) {
2719 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2721 scsicmd
->scsi_done(scsicmd
);
2726 return SCSI_MLQUEUE_HOST_BUSY
;
2729 * Allocate and initialize a Fib
2731 cmd_fibcontext
= aac_fib_alloc_tag(aac
, scsicmd
);
2733 aac_fib_init(cmd_fibcontext
);
2735 pmcmd
= fib_data(cmd_fibcontext
);
2736 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2737 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
2738 /* Eject bit ignored, not relevant */
2739 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
2740 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
2741 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
2742 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
2743 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
2744 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2747 * Now send the Fib to the adapter
2749 status
= aac_fib_send(ContainerCommand
,
2751 sizeof(struct aac_power_management
),
2754 (fib_callback
)aac_start_stop_callback
,
2758 * Check that the command queued to the controller
2760 if (status
== -EINPROGRESS
)
2763 aac_fib_complete(cmd_fibcontext
);
2764 aac_fib_free(cmd_fibcontext
);
2765 return SCSI_MLQUEUE_HOST_BUSY
;
2769 * aac_scsi_cmd() - Process SCSI command
2770 * @scsicmd: SCSI command block
2772 * Emulate a SCSI command and queue the required request for the
2776 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
2779 struct Scsi_Host
*host
= scsicmd
->device
->host
;
2780 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
2781 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
2783 if (fsa_dev_ptr
== NULL
)
2786 * If the bus, id or lun is out of range, return fail
2787 * Test does not apply to ID 16, the pseudo id for the controller
2790 cid
= scmd_id(scsicmd
);
2791 if (cid
!= host
->this_id
) {
2792 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
2793 if((cid
>= dev
->maximum_num_containers
) ||
2794 (scsicmd
->device
->lun
!= 0)) {
2795 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2800 * If the target container doesn't exist, it may have
2801 * been newly created
2803 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2804 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2806 switch (scsicmd
->cmnd
[0]) {
2807 case SERVICE_ACTION_IN_16
:
2808 if (!(dev
->raw_io_interface
) ||
2809 !(dev
->raw_io_64
) ||
2810 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2815 case TEST_UNIT_READY
:
2818 return _aac_probe_container(scsicmd
,
2819 aac_probe_container_callback2
);
2824 } else { /* check for physical non-dasd devices */
2825 bus
= aac_logical_to_phys(scmd_channel(scsicmd
));
2827 if (bus
< AAC_MAX_BUSES
&& cid
< AAC_MAX_TARGETS
&&
2828 dev
->hba_map
[bus
][cid
].devtype
2829 == AAC_DEVTYPE_NATIVE_RAW
) {
2832 return aac_send_hba_fib(scsicmd
);
2833 } else if (dev
->nondasd_support
|| expose_physicals
||
2837 return aac_send_srb_fib(scsicmd
);
2839 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2845 * else Command for the controller itself
2847 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2848 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2850 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2851 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2852 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2853 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2854 ASENCODE_INVALID_COMMAND
, 0, 0);
2855 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2856 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2857 SCSI_SENSE_BUFFERSIZE
));
2861 switch (scsicmd
->cmnd
[0]) {
2868 return aac_read(scsicmd
);
2876 return aac_write(scsicmd
);
2878 case SYNCHRONIZE_CACHE
:
2879 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2880 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2884 /* Issue FIB to tell Firmware to flush it's cache */
2885 if ((aac_cache
& 6) != 2)
2886 return aac_synchronize(scsicmd
);
2890 struct inquiry_data inq_data
;
2892 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2893 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2895 if ((scsicmd
->cmnd
[1] & 0x1) && aac_wwn
) {
2896 char *arr
= (char *)&inq_data
;
2899 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2900 INQD_PDT_PROC
: INQD_PDT_DA
;
2901 if (scsicmd
->cmnd
[2] == 0) {
2902 /* supported vital product data pages */
2907 arr
[1] = scsicmd
->cmnd
[2];
2908 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2910 scsicmd
->result
= DID_OK
<< 16 |
2911 COMMAND_COMPLETE
<< 8 |
2913 } else if (scsicmd
->cmnd
[2] == 0x80) {
2914 /* unit serial number page */
2915 arr
[3] = setinqserial(dev
, &arr
[4],
2917 arr
[1] = scsicmd
->cmnd
[2];
2918 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2921 return aac_get_container_serial(
2923 scsicmd
->result
= DID_OK
<< 16 |
2924 COMMAND_COMPLETE
<< 8 |
2926 } else if (scsicmd
->cmnd
[2] == 0x83) {
2927 /* vpd page 0x83 - Device Identification Page */
2928 char *sno
= (char *)&inq_data
;
2929 sno
[3] = setinqserial(dev
, &sno
[4],
2932 return aac_get_container_serial(
2934 scsicmd
->result
= DID_OK
<< 16 |
2935 COMMAND_COMPLETE
<< 8 |
2938 /* vpd page not implemented */
2939 scsicmd
->result
= DID_OK
<< 16 |
2940 COMMAND_COMPLETE
<< 8 |
2941 SAM_STAT_CHECK_CONDITION
;
2942 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2943 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2944 ASENCODE_NO_SENSE
, 7, 2);
2945 memcpy(scsicmd
->sense_buffer
,
2946 &dev
->fsa_dev
[cid
].sense_data
,
2948 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2949 SCSI_SENSE_BUFFERSIZE
));
2953 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2954 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 */
2955 inq_data
.inqd_len
= 31;
2956 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2957 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2959 * Set the Vendor, Product, and Revision Level
2960 * see: <vendor>.c i.e. aac.c
2962 if (cid
== host
->this_id
) {
2963 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2964 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2965 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2967 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2973 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2974 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2975 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2976 return aac_get_container_name(scsicmd
);
2978 case SERVICE_ACTION_IN_16
:
2979 if (!(dev
->raw_io_interface
) ||
2980 !(dev
->raw_io_64
) ||
2981 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2986 unsigned int alloc_len
;
2988 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2989 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2990 cp
[0] = (capacity
>> 56) & 0xff;
2991 cp
[1] = (capacity
>> 48) & 0xff;
2992 cp
[2] = (capacity
>> 40) & 0xff;
2993 cp
[3] = (capacity
>> 32) & 0xff;
2994 cp
[4] = (capacity
>> 24) & 0xff;
2995 cp
[5] = (capacity
>> 16) & 0xff;
2996 cp
[6] = (capacity
>> 8) & 0xff;
2997 cp
[7] = (capacity
>> 0) & 0xff;
2998 cp
[8] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2999 cp
[9] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3000 cp
[10] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3001 cp
[11] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
3004 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
3005 + (scsicmd
->cmnd
[11] << 16)
3006 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
3008 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
3009 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
3010 if (alloc_len
< scsi_bufflen(scsicmd
))
3011 scsi_set_resid(scsicmd
,
3012 scsi_bufflen(scsicmd
) - alloc_len
);
3014 /* Do not cache partition table for arrays */
3015 scsicmd
->device
->removable
= 1;
3017 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3027 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
3028 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
3029 capacity
= fsa_dev_ptr
[cid
].size
- 1;
3033 cp
[0] = (capacity
>> 24) & 0xff;
3034 cp
[1] = (capacity
>> 16) & 0xff;
3035 cp
[2] = (capacity
>> 8) & 0xff;
3036 cp
[3] = (capacity
>> 0) & 0xff;
3037 cp
[4] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
3038 cp
[5] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3039 cp
[6] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3040 cp
[7] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
3041 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
3042 /* Do not cache partition table for arrays */
3043 scsicmd
->device
->removable
= 1;
3044 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3051 int mode_buf_length
= 4;
3055 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
3056 capacity
= fsa_dev_ptr
[cid
].size
- 1;
3060 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
3061 memset((char *)&mpd
, 0, sizeof(aac_modep_data
));
3063 /* Mode data length */
3064 mpd
.hd
.data_length
= sizeof(mpd
.hd
) - 1;
3065 /* Medium type - default */
3066 mpd
.hd
.med_type
= 0;
3067 /* Device-specific param,
3068 bit 8: 0/1 = write enabled/protected
3069 bit 4: 0/1 = FUA enabled */
3072 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
3073 mpd
.hd
.dev_par
= 0x10;
3074 if (scsicmd
->cmnd
[1] & 0x8)
3075 mpd
.hd
.bd_length
= 0; /* Block descriptor length */
3077 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
3078 mpd
.hd
.data_length
+= mpd
.hd
.bd_length
;
3079 mpd
.bd
.block_length
[0] =
3080 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3081 mpd
.bd
.block_length
[1] =
3082 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3083 mpd
.bd
.block_length
[2] =
3084 fsa_dev_ptr
[cid
].block_size
& 0xff;
3086 mpd
.mpc_buf
[0] = scsicmd
->cmnd
[2];
3087 if (scsicmd
->cmnd
[2] == 0x1C) {
3089 mpd
.mpc_buf
[1] = 0xa;
3090 /* Mode data length */
3091 mpd
.hd
.data_length
= 23;
3093 /* Mode data length */
3094 mpd
.hd
.data_length
= 15;
3097 if (capacity
> 0xffffff) {
3098 mpd
.bd
.block_count
[0] = 0xff;
3099 mpd
.bd
.block_count
[1] = 0xff;
3100 mpd
.bd
.block_count
[2] = 0xff;
3102 mpd
.bd
.block_count
[0] = (capacity
>> 16) & 0xff;
3103 mpd
.bd
.block_count
[1] = (capacity
>> 8) & 0xff;
3104 mpd
.bd
.block_count
[2] = capacity
& 0xff;
3107 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
3108 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
3109 mpd
.hd
.data_length
+= 3;
3112 mpd
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
3113 ? 0 : 0x04; /* WCE */
3114 mode_buf_length
= sizeof(mpd
);
3117 if (mode_buf_length
> scsicmd
->cmnd
[4])
3118 mode_buf_length
= scsicmd
->cmnd
[4];
3120 mode_buf_length
= sizeof(mpd
);
3121 scsi_sg_copy_from_buffer(scsicmd
,
3124 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3131 int mode_buf_length
= 8;
3132 aac_modep10_data mpd10
;
3134 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
3135 capacity
= fsa_dev_ptr
[cid
].size
- 1;
3139 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
3140 memset((char *)&mpd10
, 0, sizeof(aac_modep10_data
));
3141 /* Mode data length (MSB) */
3142 mpd10
.hd
.data_length
[0] = 0;
3143 /* Mode data length (LSB) */
3144 mpd10
.hd
.data_length
[1] = sizeof(mpd10
.hd
) - 1;
3145 /* Medium type - default */
3146 mpd10
.hd
.med_type
= 0;
3147 /* Device-specific param,
3148 bit 8: 0/1 = write enabled/protected
3149 bit 4: 0/1 = FUA enabled */
3150 mpd10
.hd
.dev_par
= 0;
3152 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
3153 mpd10
.hd
.dev_par
= 0x10;
3154 mpd10
.hd
.rsrvd
[0] = 0; /* reserved */
3155 mpd10
.hd
.rsrvd
[1] = 0; /* reserved */
3156 if (scsicmd
->cmnd
[1] & 0x8) {
3157 /* Block descriptor length (MSB) */
3158 mpd10
.hd
.bd_length
[0] = 0;
3159 /* Block descriptor length (LSB) */
3160 mpd10
.hd
.bd_length
[1] = 0;
3162 mpd10
.hd
.bd_length
[0] = 0;
3163 mpd10
.hd
.bd_length
[1] = sizeof(mpd10
.bd
);
3165 mpd10
.hd
.data_length
[1] += mpd10
.hd
.bd_length
[1];
3167 mpd10
.bd
.block_length
[0] =
3168 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3169 mpd10
.bd
.block_length
[1] =
3170 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3171 mpd10
.bd
.block_length
[2] =
3172 fsa_dev_ptr
[cid
].block_size
& 0xff;
3174 if (capacity
> 0xffffff) {
3175 mpd10
.bd
.block_count
[0] = 0xff;
3176 mpd10
.bd
.block_count
[1] = 0xff;
3177 mpd10
.bd
.block_count
[2] = 0xff;
3179 mpd10
.bd
.block_count
[0] =
3180 (capacity
>> 16) & 0xff;
3181 mpd10
.bd
.block_count
[1] =
3182 (capacity
>> 8) & 0xff;
3183 mpd10
.bd
.block_count
[2] =
3187 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
3188 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
3189 mpd10
.hd
.data_length
[1] += 3;
3190 mpd10
.mpc_buf
[0] = 8;
3191 mpd10
.mpc_buf
[1] = 1;
3192 mpd10
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
3193 ? 0 : 0x04; /* WCE */
3194 mode_buf_length
= sizeof(mpd10
);
3195 if (mode_buf_length
> scsicmd
->cmnd
[8])
3196 mode_buf_length
= scsicmd
->cmnd
[8];
3198 scsi_sg_copy_from_buffer(scsicmd
,
3202 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3207 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
3208 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
3209 sizeof(struct sense_data
));
3210 memset(&dev
->fsa_dev
[cid
].sense_data
, 0,
3211 sizeof(struct sense_data
));
3212 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3216 case ALLOW_MEDIUM_REMOVAL
:
3217 dprintk((KERN_DEBUG
"LOCK command.\n"));
3218 if (scsicmd
->cmnd
[4])
3219 fsa_dev_ptr
[cid
].locked
= 1;
3221 fsa_dev_ptr
[cid
].locked
= 0;
3223 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3227 * These commands are all No-Ops
3229 case TEST_UNIT_READY
:
3230 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
3231 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3232 SAM_STAT_CHECK_CONDITION
;
3233 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
3234 NOT_READY
, SENCODE_BECOMING_READY
,
3235 ASENCODE_BECOMING_READY
, 0, 0);
3236 memcpy(scsicmd
->sense_buffer
,
3237 &dev
->fsa_dev
[cid
].sense_data
,
3239 sizeof(dev
->fsa_dev
[cid
].sense_data
),
3240 SCSI_SENSE_BUFFERSIZE
));
3247 case REASSIGN_BLOCKS
:
3249 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3254 return aac_start_stop(scsicmd
);
3258 * Unhandled commands
3260 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n",
3262 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3263 SAM_STAT_CHECK_CONDITION
;
3264 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
3265 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
3266 ASENCODE_INVALID_COMMAND
, 0, 0);
3267 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
3269 sizeof(dev
->fsa_dev
[cid
].sense_data
),
3270 SCSI_SENSE_BUFFERSIZE
));
3275 scsicmd
->scsi_done(scsicmd
);
3279 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
3281 struct aac_query_disk qd
;
3282 struct fsa_dev_info
*fsa_dev_ptr
;
3284 fsa_dev_ptr
= dev
->fsa_dev
;
3287 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
3289 if (qd
.cnum
== -1) {
3290 if (qd
.id
< 0 || qd
.id
>= dev
->maximum_num_containers
)
3293 } else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1)) {
3294 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
3296 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
3298 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
3299 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
3301 else return -EINVAL
;
3303 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
3304 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
3305 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
3307 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
3312 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
3313 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
3315 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
3320 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
3322 struct aac_delete_disk dd
;
3323 struct fsa_dev_info
*fsa_dev_ptr
;
3325 fsa_dev_ptr
= dev
->fsa_dev
;
3329 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
3332 if (dd
.cnum
>= dev
->maximum_num_containers
)
3335 * Mark this container as being deleted.
3337 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
3339 * Mark the container as no longer valid
3341 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
3345 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
3347 struct aac_delete_disk dd
;
3348 struct fsa_dev_info
*fsa_dev_ptr
;
3350 fsa_dev_ptr
= dev
->fsa_dev
;
3354 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
3357 if (dd
.cnum
>= dev
->maximum_num_containers
)
3360 * If the container is locked, it can not be deleted by the API.
3362 if (fsa_dev_ptr
[dd
.cnum
].locked
)
3366 * Mark the container as no longer being valid.
3368 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
3369 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
3374 int aac_dev_ioctl(struct aac_dev
*dev
, unsigned int cmd
, void __user
*arg
)
3377 case FSACTL_QUERY_DISK
:
3378 return query_disk(dev
, arg
);
3379 case FSACTL_DELETE_DISK
:
3380 return delete_disk(dev
, arg
);
3381 case FSACTL_FORCE_DELETE_DISK
:
3382 return force_delete_disk(dev
, arg
);
3383 case FSACTL_GET_CONTAINERS
:
3384 return aac_get_containers(dev
);
3392 * @context: the context set in the fib - here it is scsi cmd
3393 * @fibptr: pointer to the fib
3395 * Handles the completion of a scsi command to a non dasd device
3397 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
3399 struct aac_srb_reply
*srbreply
;
3400 struct scsi_cmnd
*scsicmd
;
3402 scsicmd
= (struct scsi_cmnd
*) context
;
3404 if (!aac_valid_context(scsicmd
, fibptr
))
3407 BUG_ON(fibptr
== NULL
);
3409 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
3411 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
3413 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
3415 srbreply
->srb_status
= cpu_to_le32(SRB_STATUS_SUCCESS
);
3416 srbreply
->scsi_status
= cpu_to_le32(SAM_STAT_GOOD
);
3419 * Calculate resid for sg
3421 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
3422 - le32_to_cpu(srbreply
->data_xfer_length
));
3426 scsi_dma_unmap(scsicmd
);
3428 /* expose physical device if expose_physicald flag is on */
3429 if (scsicmd
->cmnd
[0] == INQUIRY
&& !(scsicmd
->cmnd
[1] & 0x01)
3430 && expose_physicals
> 0)
3431 aac_expose_phy_device(scsicmd
);
3434 * First check the fib status
3437 if (le32_to_cpu(srbreply
->status
) != ST_OK
) {
3440 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3441 le32_to_cpu(srbreply
->status
));
3442 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3443 SCSI_SENSE_BUFFERSIZE
);
3444 scsicmd
->result
= DID_ERROR
<< 16
3445 | COMMAND_COMPLETE
<< 8
3446 | SAM_STAT_CHECK_CONDITION
;
3447 memcpy(scsicmd
->sense_buffer
,
3448 srbreply
->sense_data
, len
);
3452 * Next check the srb status
3454 switch ((le32_to_cpu(srbreply
->srb_status
))&0x3f) {
3455 case SRB_STATUS_ERROR_RECOVERY
:
3456 case SRB_STATUS_PENDING
:
3457 case SRB_STATUS_SUCCESS
:
3458 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3460 case SRB_STATUS_DATA_OVERRUN
:
3461 switch (scsicmd
->cmnd
[0]) {
3470 if (le32_to_cpu(srbreply
->data_xfer_length
)
3471 < scsicmd
->underflow
)
3472 pr_warn("aacraid: SCSI CMD underflow\n");
3474 pr_warn("aacraid: SCSI CMD Data Overrun\n");
3475 scsicmd
->result
= DID_ERROR
<< 16
3476 | COMMAND_COMPLETE
<< 8;
3479 scsicmd
->result
= DID_OK
<< 16
3480 | COMMAND_COMPLETE
<< 8;
3483 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3487 case SRB_STATUS_ABORTED
:
3488 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3490 case SRB_STATUS_ABORT_FAILED
:
3492 * Not sure about this one - but assuming the
3493 * hba was trying to abort for some reason
3495 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
3497 case SRB_STATUS_PARITY_ERROR
:
3498 scsicmd
->result
= DID_PARITY
<< 16
3499 | MSG_PARITY_ERROR
<< 8;
3501 case SRB_STATUS_NO_DEVICE
:
3502 case SRB_STATUS_INVALID_PATH_ID
:
3503 case SRB_STATUS_INVALID_TARGET_ID
:
3504 case SRB_STATUS_INVALID_LUN
:
3505 case SRB_STATUS_SELECTION_TIMEOUT
:
3506 scsicmd
->result
= DID_NO_CONNECT
<< 16
3507 | COMMAND_COMPLETE
<< 8;
3510 case SRB_STATUS_COMMAND_TIMEOUT
:
3511 case SRB_STATUS_TIMEOUT
:
3512 scsicmd
->result
= DID_TIME_OUT
<< 16
3513 | COMMAND_COMPLETE
<< 8;
3516 case SRB_STATUS_BUSY
:
3517 scsicmd
->result
= DID_BUS_BUSY
<< 16
3518 | COMMAND_COMPLETE
<< 8;
3521 case SRB_STATUS_BUS_RESET
:
3522 scsicmd
->result
= DID_RESET
<< 16
3523 | COMMAND_COMPLETE
<< 8;
3526 case SRB_STATUS_MESSAGE_REJECTED
:
3527 scsicmd
->result
= DID_ERROR
<< 16
3528 | MESSAGE_REJECT
<< 8;
3530 case SRB_STATUS_REQUEST_FLUSHED
:
3531 case SRB_STATUS_ERROR
:
3532 case SRB_STATUS_INVALID_REQUEST
:
3533 case SRB_STATUS_REQUEST_SENSE_FAILED
:
3534 case SRB_STATUS_NO_HBA
:
3535 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
3536 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
3537 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
3538 case SRB_STATUS_DELAYED_RETRY
:
3539 case SRB_STATUS_BAD_FUNCTION
:
3540 case SRB_STATUS_NOT_STARTED
:
3541 case SRB_STATUS_NOT_IN_USE
:
3542 case SRB_STATUS_FORCE_ABORT
:
3543 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
3545 #ifdef AAC_DETAILED_STATUS_INFO
3546 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3547 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
3548 aac_get_status_string(
3549 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
3551 le32_to_cpu(srbreply
->scsi_status
));
3554 * When the CC bit is SET by the host in ATA pass thru CDB,
3555 * driver is supposed to return DID_OK
3557 * When the CC bit is RESET by the host, driver should
3560 if ((scsicmd
->cmnd
[0] == ATA_12
)
3561 || (scsicmd
->cmnd
[0] == ATA_16
)) {
3563 if (scsicmd
->cmnd
[2] & (0x01 << 5)) {
3564 scsicmd
->result
= DID_OK
<< 16
3565 | COMMAND_COMPLETE
<< 8;
3568 scsicmd
->result
= DID_ERROR
<< 16
3569 | COMMAND_COMPLETE
<< 8;
3573 scsicmd
->result
= DID_ERROR
<< 16
3574 | COMMAND_COMPLETE
<< 8;
3578 if (le32_to_cpu(srbreply
->scsi_status
)
3579 == SAM_STAT_CHECK_CONDITION
) {
3582 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
3583 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3584 SCSI_SENSE_BUFFERSIZE
);
3585 #ifdef AAC_DETAILED_STATUS_INFO
3586 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3587 le32_to_cpu(srbreply
->status
), len
);
3589 memcpy(scsicmd
->sense_buffer
,
3590 srbreply
->sense_data
, len
);
3594 * OR in the scsi status (already shifted up a bit)
3596 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
3598 aac_fib_complete(fibptr
);
3599 scsicmd
->scsi_done(scsicmd
);
3602 static void hba_resp_task_complete(struct aac_dev
*dev
,
3603 struct scsi_cmnd
*scsicmd
,
3604 struct aac_hba_resp
*err
) {
3606 scsicmd
->result
= err
->status
;
3607 /* set residual count */
3608 scsi_set_resid(scsicmd
, le32_to_cpu(err
->residual_count
));
3610 switch (err
->status
) {
3612 scsicmd
->result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3614 case SAM_STAT_CHECK_CONDITION
:
3618 len
= min_t(u8
, err
->sense_response_data_len
,
3619 SCSI_SENSE_BUFFERSIZE
);
3621 memcpy(scsicmd
->sense_buffer
,
3622 err
->sense_response_buf
, len
);
3623 scsicmd
->result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3627 scsicmd
->result
|= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
3629 case SAM_STAT_TASK_ABORTED
:
3630 scsicmd
->result
|= DID_ABORT
<< 16 | ABORT
<< 8;
3632 case SAM_STAT_RESERVATION_CONFLICT
:
3633 case SAM_STAT_TASK_SET_FULL
:
3635 scsicmd
->result
|= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3640 static void hba_resp_task_failure(struct aac_dev
*dev
,
3641 struct scsi_cmnd
*scsicmd
,
3642 struct aac_hba_resp
*err
)
3644 switch (err
->status
) {
3645 case HBA_RESP_STAT_HBAMODE_DISABLED
:
3649 bus
= aac_logical_to_phys(scmd_channel(scsicmd
));
3650 cid
= scmd_id(scsicmd
);
3651 if (dev
->hba_map
[bus
][cid
].devtype
== AAC_DEVTYPE_NATIVE_RAW
) {
3652 dev
->hba_map
[bus
][cid
].devtype
= AAC_DEVTYPE_ARC_RAW
;
3653 dev
->hba_map
[bus
][cid
].rmw_nexus
= 0xffffffff;
3655 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3658 case HBA_RESP_STAT_IO_ERROR
:
3659 case HBA_RESP_STAT_NO_PATH_TO_DEVICE
:
3660 scsicmd
->result
= DID_OK
<< 16 |
3661 COMMAND_COMPLETE
<< 8 | SAM_STAT_BUSY
;
3663 case HBA_RESP_STAT_IO_ABORTED
:
3664 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3666 case HBA_RESP_STAT_INVALID_DEVICE
:
3667 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3669 case HBA_RESP_STAT_UNDERRUN
:
3670 /* UNDERRUN is OK */
3671 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3673 case HBA_RESP_STAT_OVERRUN
:
3675 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3682 * @context: the context set in the fib - here it is scsi cmd
3683 * @fibptr: pointer to the fib
3685 * Handles the completion of a native HBA scsi command
3687 void aac_hba_callback(void *context
, struct fib
*fibptr
)
3689 struct aac_dev
*dev
;
3690 struct scsi_cmnd
*scsicmd
;
3692 struct aac_hba_resp
*err
=
3693 &((struct aac_native_hba
*)fibptr
->hw_fib_va
)->resp
.err
;
3695 scsicmd
= (struct scsi_cmnd
*) context
;
3697 if (!aac_valid_context(scsicmd
, fibptr
))
3700 WARN_ON(fibptr
== NULL
);
3703 if (!(fibptr
->flags
& FIB_CONTEXT_FLAG_NATIVE_HBA_TMF
))
3704 scsi_dma_unmap(scsicmd
);
3706 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
3708 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3712 switch (err
->service_response
) {
3713 case HBA_RESP_SVCRES_TASK_COMPLETE
:
3714 hba_resp_task_complete(dev
, scsicmd
, err
);
3716 case HBA_RESP_SVCRES_FAILURE
:
3717 hba_resp_task_failure(dev
, scsicmd
, err
);
3719 case HBA_RESP_SVCRES_TMF_REJECTED
:
3720 scsicmd
->result
= DID_ERROR
<< 16 | MESSAGE_REJECT
<< 8;
3722 case HBA_RESP_SVCRES_TMF_LUN_INVALID
:
3723 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3725 case HBA_RESP_SVCRES_TMF_COMPLETE
:
3726 case HBA_RESP_SVCRES_TMF_SUCCEEDED
:
3727 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3730 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3735 aac_fib_complete(fibptr
);
3737 if (fibptr
->flags
& FIB_CONTEXT_FLAG_NATIVE_HBA_TMF
)
3738 scsicmd
->SCp
.sent_command
= 1;
3740 scsicmd
->scsi_done(scsicmd
);
3745 * @scsicmd: the scsi command block
3747 * This routine will form a FIB and fill in the aac_srb from the
3748 * scsicmd passed in.
3750 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
3752 struct fib
* cmd_fibcontext
;
3753 struct aac_dev
* dev
;
3756 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3757 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3758 scsicmd
->device
->lun
> 7) {
3759 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3760 scsicmd
->scsi_done(scsicmd
);
3765 * Allocate and initialize a Fib then setup a BlockWrite command
3767 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3768 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3769 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
3772 * Check that the command queued to the controller
3774 if (status
== -EINPROGRESS
)
3777 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
3778 aac_fib_complete(cmd_fibcontext
);
3779 aac_fib_free(cmd_fibcontext
);
3786 * @scsicmd: the scsi command block
3788 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3789 * scsicmd passed in.
3791 static int aac_send_hba_fib(struct scsi_cmnd
*scsicmd
)
3793 struct fib
*cmd_fibcontext
;
3794 struct aac_dev
*dev
;
3797 dev
= shost_priv(scsicmd
->device
->host
);
3798 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3799 scsicmd
->device
->lun
> AAC_MAX_LUN
- 1) {
3800 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3801 scsicmd
->scsi_done(scsicmd
);
3806 * Allocate and initialize a Fib then setup a BlockWrite command
3808 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3809 if (!cmd_fibcontext
)
3812 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3813 status
= aac_adapter_hba(cmd_fibcontext
, scsicmd
);
3816 * Check that the command queued to the controller
3818 if (status
== -EINPROGRESS
)
3821 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3823 aac_fib_complete(cmd_fibcontext
);
3824 aac_fib_free(cmd_fibcontext
);
3830 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*psg
)
3832 unsigned long byte_count
= 0;
3834 struct scatterlist
*sg
;
3837 // Get rid of old data
3839 psg
->sg
[0].addr
= 0;
3840 psg
->sg
[0].count
= 0;
3842 nseg
= scsi_dma_map(scsicmd
);
3846 psg
->count
= cpu_to_le32(nseg
);
3848 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3849 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
3850 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
3851 byte_count
+= sg_dma_len(sg
);
3853 /* hba wants the size to be exact */
3854 if (byte_count
> scsi_bufflen(scsicmd
)) {
3855 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3856 (byte_count
- scsi_bufflen(scsicmd
));
3857 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3858 byte_count
= scsi_bufflen(scsicmd
);
3860 /* Check for command underflow */
3861 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3862 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3863 byte_count
, scsicmd
->underflow
);
3870 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
)
3872 unsigned long byte_count
= 0;
3875 struct scatterlist
*sg
;
3878 // Get rid of old data
3880 psg
->sg
[0].addr
[0] = 0;
3881 psg
->sg
[0].addr
[1] = 0;
3882 psg
->sg
[0].count
= 0;
3884 nseg
= scsi_dma_map(scsicmd
);
3888 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3889 int count
= sg_dma_len(sg
);
3890 addr
= sg_dma_address(sg
);
3891 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
3892 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
3893 psg
->sg
[i
].count
= cpu_to_le32(count
);
3894 byte_count
+= count
;
3896 psg
->count
= cpu_to_le32(nseg
);
3897 /* hba wants the size to be exact */
3898 if (byte_count
> scsi_bufflen(scsicmd
)) {
3899 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3900 (byte_count
- scsi_bufflen(scsicmd
));
3901 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3902 byte_count
= scsi_bufflen(scsicmd
);
3904 /* Check for command underflow */
3905 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3906 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3907 byte_count
, scsicmd
->underflow
);
3913 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
)
3915 unsigned long byte_count
= 0;
3917 struct scatterlist
*sg
;
3920 // Get rid of old data
3922 psg
->sg
[0].next
= 0;
3923 psg
->sg
[0].prev
= 0;
3924 psg
->sg
[0].addr
[0] = 0;
3925 psg
->sg
[0].addr
[1] = 0;
3926 psg
->sg
[0].count
= 0;
3927 psg
->sg
[0].flags
= 0;
3929 nseg
= scsi_dma_map(scsicmd
);
3933 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3934 int count
= sg_dma_len(sg
);
3935 u64 addr
= sg_dma_address(sg
);
3936 psg
->sg
[i
].next
= 0;
3937 psg
->sg
[i
].prev
= 0;
3938 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
3939 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
3940 psg
->sg
[i
].count
= cpu_to_le32(count
);
3941 psg
->sg
[i
].flags
= 0;
3942 byte_count
+= count
;
3944 psg
->count
= cpu_to_le32(nseg
);
3945 /* hba wants the size to be exact */
3946 if (byte_count
> scsi_bufflen(scsicmd
)) {
3947 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3948 (byte_count
- scsi_bufflen(scsicmd
));
3949 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3950 byte_count
= scsi_bufflen(scsicmd
);
3952 /* Check for command underflow */
3953 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3954 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3955 byte_count
, scsicmd
->underflow
);
3961 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
3962 struct aac_raw_io2
*rio2
, int sg_max
)
3964 unsigned long byte_count
= 0;
3966 struct scatterlist
*sg
;
3967 int i
, conformable
= 0;
3968 u32 min_size
= PAGE_SIZE
, cur_size
;
3970 nseg
= scsi_dma_map(scsicmd
);
3974 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3975 int count
= sg_dma_len(sg
);
3976 u64 addr
= sg_dma_address(sg
);
3978 BUG_ON(i
>= sg_max
);
3979 rio2
->sge
[i
].addrHigh
= cpu_to_le32((u32
)(addr
>>32));
3980 rio2
->sge
[i
].addrLow
= cpu_to_le32((u32
)(addr
& 0xffffffff));
3981 cur_size
= cpu_to_le32(count
);
3982 rio2
->sge
[i
].length
= cur_size
;
3983 rio2
->sge
[i
].flags
= 0;
3986 rio2
->sgeFirstSize
= cur_size
;
3987 } else if (i
== 1) {
3988 rio2
->sgeNominalSize
= cur_size
;
3989 min_size
= cur_size
;
3990 } else if ((i
+1) < nseg
&& cur_size
!= rio2
->sgeNominalSize
) {
3992 if (cur_size
< min_size
)
3993 min_size
= cur_size
;
3995 byte_count
+= count
;
3998 /* hba wants the size to be exact */
3999 if (byte_count
> scsi_bufflen(scsicmd
)) {
4000 u32 temp
= le32_to_cpu(rio2
->sge
[i
-1].length
) -
4001 (byte_count
- scsi_bufflen(scsicmd
));
4002 rio2
->sge
[i
-1].length
= cpu_to_le32(temp
);
4003 byte_count
= scsi_bufflen(scsicmd
);
4006 rio2
->sgeCnt
= cpu_to_le32(nseg
);
4007 rio2
->flags
|= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212
);
4008 /* not conformable: evaluate required sg elements */
4010 int j
, nseg_new
= nseg
, err_found
;
4011 for (i
= min_size
/ PAGE_SIZE
; i
>= 1; --i
) {
4014 for (j
= 1; j
< nseg
- 1; ++j
) {
4015 if (rio2
->sge
[j
].length
% (i
*PAGE_SIZE
)) {
4019 nseg_new
+= (rio2
->sge
[j
].length
/ (i
*PAGE_SIZE
));
4024 if (i
> 0 && nseg_new
<= sg_max
) {
4025 int ret
= aac_convert_sgraw2(rio2
, i
, nseg
, nseg_new
);
4031 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
4033 /* Check for command underflow */
4034 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
4035 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
4036 byte_count
, scsicmd
->underflow
);
4042 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
, int pages
, int nseg
, int nseg_new
)
4044 struct sge_ieee1212
*sge
;
4048 if (aac_convert_sgl
== 0)
4051 sge
= kmalloc_array(nseg_new
, sizeof(struct sge_ieee1212
), GFP_ATOMIC
);
4055 for (i
= 1, pos
= 1; i
< nseg
-1; ++i
) {
4056 for (j
= 0; j
< rio2
->sge
[i
].length
/ (pages
* PAGE_SIZE
); ++j
) {
4057 addr_low
= rio2
->sge
[i
].addrLow
+ j
* pages
* PAGE_SIZE
;
4058 sge
[pos
].addrLow
= addr_low
;
4059 sge
[pos
].addrHigh
= rio2
->sge
[i
].addrHigh
;
4060 if (addr_low
< rio2
->sge
[i
].addrLow
)
4061 sge
[pos
].addrHigh
++;
4062 sge
[pos
].length
= pages
* PAGE_SIZE
;
4067 sge
[pos
] = rio2
->sge
[nseg
-1];
4068 memcpy(&rio2
->sge
[1], &sge
[1], (nseg_new
-1)*sizeof(struct sge_ieee1212
));
4071 rio2
->sgeCnt
= cpu_to_le32(nseg_new
);
4072 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
4073 rio2
->sgeNominalSize
= pages
* PAGE_SIZE
;
4077 static long aac_build_sghba(struct scsi_cmnd
*scsicmd
,
4078 struct aac_hba_cmd_req
*hbacmd
,
4082 unsigned long byte_count
= 0;
4084 struct scatterlist
*sg
;
4087 struct aac_hba_sgl
*sge
;
4089 nseg
= scsi_dma_map(scsicmd
);
4095 if (nseg
> HBA_MAX_SG_EMBEDDED
)
4096 sge
= &hbacmd
->sge
[2];
4098 sge
= &hbacmd
->sge
[0];
4100 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
4101 int count
= sg_dma_len(sg
);
4102 u64 addr
= sg_dma_address(sg
);
4104 WARN_ON(i
>= sg_max
);
4105 sge
->addr_hi
= cpu_to_le32((u32
)(addr
>>32));
4106 sge
->addr_lo
= cpu_to_le32((u32
)(addr
& 0xffffffff));
4107 cur_size
= cpu_to_le32(count
);
4108 sge
->len
= cur_size
;
4110 byte_count
+= count
;
4115 /* hba wants the size to be exact */
4116 if (byte_count
> scsi_bufflen(scsicmd
)) {
4119 temp
= le32_to_cpu(sge
->len
) - byte_count
4120 - scsi_bufflen(scsicmd
);
4121 sge
->len
= cpu_to_le32(temp
);
4122 byte_count
= scsi_bufflen(scsicmd
);
4125 if (nseg
<= HBA_MAX_SG_EMBEDDED
) {
4126 hbacmd
->emb_data_desc_count
= cpu_to_le32(nseg
);
4127 sge
->flags
= cpu_to_le32(0x40000000);
4130 hbacmd
->sge
[0].flags
= cpu_to_le32(0x80000000);
4131 hbacmd
->emb_data_desc_count
= (u8
)cpu_to_le32(1);
4132 hbacmd
->sge
[0].addr_hi
= (u32
)cpu_to_le32(sg_address
>> 32);
4133 hbacmd
->sge
[0].addr_lo
=
4134 cpu_to_le32((u32
)(sg_address
& 0xffffffff));
4137 /* Check for command underflow */
4138 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
4139 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4140 byte_count
, scsicmd
->underflow
);
4146 #ifdef AAC_DETAILED_STATUS_INFO
4148 struct aac_srb_status_info
{
4154 static struct aac_srb_status_info srb_status_info
[] = {
4155 { SRB_STATUS_PENDING
, "Pending Status"},
4156 { SRB_STATUS_SUCCESS
, "Success"},
4157 { SRB_STATUS_ABORTED
, "Aborted Command"},
4158 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
4159 { SRB_STATUS_ERROR
, "Error Event"},
4160 { SRB_STATUS_BUSY
, "Device Busy"},
4161 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
4162 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
4163 { SRB_STATUS_NO_DEVICE
, "No Device"},
4164 { SRB_STATUS_TIMEOUT
, "Timeout"},
4165 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
4166 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
4167 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
4168 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
4169 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
4170 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
4171 { SRB_STATUS_NO_HBA
, "No HBA"},
4172 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
4173 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
4174 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
4175 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
4176 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
4177 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
4178 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
4179 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
4180 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
4181 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
4182 { SRB_STATUS_NOT_STARTED
, "Not Started"},
4183 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
4184 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
4185 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
4186 { 0xff, "Unknown Error"}
4189 char *aac_get_status_string(u32 status
)
4193 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
4194 if (srb_status_info
[i
].status
== status
)
4195 return srb_status_info
[i
].str
;
4197 return "Bad Status Code";