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 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.");
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.");
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 * @common: adapter to query
355 * Query config status, and commit the configuration if needed.
357 int aac_get_config_status(struct aac_dev
*dev
, int commit_flag
)
362 if (!(fibptr
= aac_fib_alloc(dev
)))
365 aac_fib_init(fibptr
);
367 struct aac_get_config_status
*dinfo
;
368 dinfo
= (struct aac_get_config_status
*) fib_data(fibptr
);
370 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
371 dinfo
->type
= cpu_to_le32(CT_GET_CONFIG_STATUS
);
372 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_config_status_resp
*)NULL
)->data
));
375 status
= aac_fib_send(ContainerCommand
,
377 sizeof (struct aac_get_config_status
),
382 printk(KERN_WARNING
"aac_get_config_status: SendFIB failed.\n");
384 struct aac_get_config_status_resp
*reply
385 = (struct aac_get_config_status_resp
*) fib_data(fibptr
);
386 dprintk((KERN_WARNING
387 "aac_get_config_status: response=%d status=%d action=%d\n",
388 le32_to_cpu(reply
->response
),
389 le32_to_cpu(reply
->status
),
390 le32_to_cpu(reply
->data
.action
)));
391 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
392 (le32_to_cpu(reply
->status
) != CT_OK
) ||
393 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
394 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
398 /* Do not set XferState to zero unless receives a response from F/W */
400 aac_fib_complete(fibptr
);
402 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
404 if ((aac_commit
== 1) || commit_flag
) {
405 struct aac_commit_config
* dinfo
;
406 aac_fib_init(fibptr
);
407 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
409 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
410 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
412 status
= aac_fib_send(ContainerCommand
,
414 sizeof (struct aac_commit_config
),
418 /* Do not set XferState to zero unless
419 * receives a response from F/W */
421 aac_fib_complete(fibptr
);
422 } else if (aac_commit
== 0) {
424 "aac_get_config_status: Foreign device configurations are being ignored\n");
427 /* FIB should be freed only after getting the response from the F/W */
428 if (status
!= -ERESTARTSYS
)
429 aac_fib_free(fibptr
);
433 static void aac_expose_phy_device(struct scsi_cmnd
*scsicmd
)
436 scsi_sg_copy_to_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
437 if ((inq_data
& 0x20) && (inq_data
& 0x1f) == TYPE_DISK
) {
439 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
444 * aac_get_containers - list containers
445 * @common: adapter to probe
447 * Make a list of all containers on this controller
449 int aac_get_containers(struct aac_dev
*dev
)
451 struct fsa_dev_info
*fsa_dev_ptr
;
455 struct aac_get_container_count
*dinfo
;
456 struct aac_get_container_count_resp
*dresp
;
457 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
459 if (!(fibptr
= aac_fib_alloc(dev
)))
462 aac_fib_init(fibptr
);
463 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
464 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
465 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
467 status
= aac_fib_send(ContainerCommand
,
469 sizeof (struct aac_get_container_count
),
474 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
475 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
476 if (fibptr
->dev
->supplement_adapter_info
.supported_options2
&
477 AAC_OPTION_SUPPORTED_240_VOLUMES
) {
478 maximum_num_containers
=
479 le32_to_cpu(dresp
->MaxSimpleVolumes
);
481 aac_fib_complete(fibptr
);
483 /* FIB should be freed only after getting the response from the F/W */
484 if (status
!= -ERESTARTSYS
)
485 aac_fib_free(fibptr
);
487 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
488 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
489 if (dev
->fsa_dev
== NULL
||
490 dev
->maximum_num_containers
!= maximum_num_containers
) {
492 fsa_dev_ptr
= dev
->fsa_dev
;
494 dev
->fsa_dev
= kcalloc(maximum_num_containers
,
495 sizeof(*fsa_dev_ptr
), GFP_KERNEL
);
504 dev
->maximum_num_containers
= maximum_num_containers
;
506 for (index
= 0; index
< dev
->maximum_num_containers
; index
++) {
507 dev
->fsa_dev
[index
].devname
[0] = '\0';
508 dev
->fsa_dev
[index
].valid
= 0;
510 status
= aac_probe_container(dev
, index
);
513 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
520 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
522 struct aac_get_name_resp
* get_name_reply
;
523 struct scsi_cmnd
* scsicmd
;
525 scsicmd
= (struct scsi_cmnd
*) context
;
527 if (!aac_valid_context(scsicmd
, fibptr
))
530 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
531 BUG_ON(fibptr
== NULL
);
533 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
534 /* Failure is irrelevant, using default value instead */
535 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
536 && (get_name_reply
->data
[0] != '\0')) {
537 char *sp
= get_name_reply
->data
;
538 int data_size
= sizeof_field(struct aac_get_name_resp
, data
);
540 sp
[data_size
- 1] = '\0';
544 struct inquiry_data inq
;
545 char d
[sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
)];
546 int count
= sizeof(d
);
549 *dp
++ = (*sp
) ? *sp
++ : ' ';
550 } while (--count
> 0);
552 scsi_sg_copy_to_buffer(scsicmd
, &inq
, sizeof(inq
));
553 memcpy(inq
.inqd_pid
, d
, sizeof(d
));
554 scsi_sg_copy_from_buffer(scsicmd
, &inq
, sizeof(inq
));
558 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
560 aac_fib_complete(fibptr
);
561 scsicmd
->scsi_done(scsicmd
);
565 * aac_get_container_name - get container name, none blocking.
567 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
)
571 struct aac_get_name
*dinfo
;
572 struct fib
* cmd_fibcontext
;
573 struct aac_dev
* dev
;
575 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
577 data_size
= sizeof_field(struct aac_get_name_resp
, data
);
579 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
581 aac_fib_init(cmd_fibcontext
);
582 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
583 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
585 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
586 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
587 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
588 dinfo
->count
= cpu_to_le32(data_size
- 1);
590 status
= aac_fib_send(ContainerCommand
,
592 sizeof(struct aac_get_name_resp
),
595 (fib_callback
)get_container_name_callback
,
599 * Check that the command queued to the controller
601 if (status
== -EINPROGRESS
)
604 printk(KERN_WARNING
"aac_get_container_name: aac_fib_send failed with status: %d.\n", status
);
605 aac_fib_complete(cmd_fibcontext
);
609 static int aac_probe_container_callback2(struct scsi_cmnd
* scsicmd
)
611 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
613 if ((fsa_dev_ptr
[scmd_id(scsicmd
)].valid
& 1))
614 return aac_scsi_cmd(scsicmd
);
616 scsicmd
->result
= DID_NO_CONNECT
<< 16;
617 scsicmd
->scsi_done(scsicmd
);
621 static void _aac_probe_container2(void * context
, struct fib
* fibptr
)
623 struct fsa_dev_info
*fsa_dev_ptr
;
624 int (*callback
)(struct scsi_cmnd
*);
625 struct scsi_cmnd
* scsicmd
= (struct scsi_cmnd
*)context
;
629 if (!aac_valid_context(scsicmd
, fibptr
))
632 scsicmd
->SCp
.Status
= 0;
633 fsa_dev_ptr
= fibptr
->dev
->fsa_dev
;
635 struct aac_mount
* dresp
= (struct aac_mount
*) fib_data(fibptr
);
638 fsa_dev_ptr
+= scmd_id(scsicmd
);
640 fibptr
->dev
->supplement_adapter_info
.supported_options2
;
642 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
643 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
644 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
645 if (!(sup_options2
& AAC_OPTION_VARIABLE_BLOCK_SIZE
)) {
646 dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
= 0x200;
647 fsa_dev_ptr
->block_size
= 0x200;
649 fsa_dev_ptr
->block_size
=
650 le32_to_cpu(dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
);
652 for (i
= 0; i
< 16; i
++)
653 fsa_dev_ptr
->identifier
[i
] =
654 dresp
->mnt
[0].fileinfo
.bdevinfo
656 fsa_dev_ptr
->valid
= 1;
657 /* sense_key holds the current state of the spin-up */
658 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
659 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
660 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
661 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
662 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
664 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
665 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
666 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
668 if ((fsa_dev_ptr
->valid
& 1) == 0)
669 fsa_dev_ptr
->valid
= 0;
670 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
672 aac_fib_complete(fibptr
);
673 aac_fib_free(fibptr
);
674 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
675 scsicmd
->SCp
.ptr
= NULL
;
676 (*callback
)(scsicmd
);
680 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
682 struct scsi_cmnd
* scsicmd
;
683 struct aac_mount
* dresp
;
684 struct aac_query_mount
*dinfo
;
687 dresp
= (struct aac_mount
*) fib_data(fibptr
);
688 if (!aac_supports_2T(fibptr
->dev
)) {
689 dresp
->mnt
[0].capacityhigh
= 0;
690 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
691 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
692 _aac_probe_container2(context
, fibptr
);
696 scsicmd
= (struct scsi_cmnd
*) context
;
698 if (!aac_valid_context(scsicmd
, fibptr
))
701 aac_fib_init(fibptr
);
703 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
705 if (fibptr
->dev
->supplement_adapter_info
.supported_options2
&
706 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
707 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
709 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
711 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
712 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
713 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
715 status
= aac_fib_send(ContainerCommand
,
717 sizeof(struct aac_query_mount
),
720 _aac_probe_container2
,
723 * Check that the command queued to the controller
725 if (status
< 0 && status
!= -EINPROGRESS
) {
726 /* Inherit results from VM_NameServe, if any */
727 dresp
->status
= cpu_to_le32(ST_OK
);
728 _aac_probe_container2(context
, fibptr
);
732 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
735 int status
= -ENOMEM
;
737 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
738 struct aac_query_mount
*dinfo
;
740 aac_fib_init(fibptr
);
742 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
744 if (fibptr
->dev
->supplement_adapter_info
.supported_options2
&
745 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
746 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
748 dinfo
->command
= cpu_to_le32(VM_NameServe
);
750 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
751 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
752 scsicmd
->SCp
.ptr
= (char *)callback
;
753 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
755 status
= aac_fib_send(ContainerCommand
,
757 sizeof(struct aac_query_mount
),
760 _aac_probe_container1
,
763 * Check that the command queued to the controller
765 if (status
== -EINPROGRESS
)
769 scsicmd
->SCp
.ptr
= NULL
;
770 aac_fib_complete(fibptr
);
771 aac_fib_free(fibptr
);
775 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
777 fsa_dev_ptr
+= scmd_id(scsicmd
);
778 if ((fsa_dev_ptr
->valid
& 1) == 0) {
779 fsa_dev_ptr
->valid
= 0;
780 return (*callback
)(scsicmd
);
788 * aac_probe_container - query a logical volume
789 * @dev: device to query
790 * @cid: container identifier
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
->list
.next
= NULL
;
818 scsicmd
->scsi_done
= aac_probe_container_scsi_done
;
820 scsicmd
->device
= scsidev
;
821 scsidev
->sdev_state
= 0;
823 scsidev
->host
= dev
->scsi_host_ptr
;
825 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
826 while (scsicmd
->device
== scsidev
)
829 status
= scsicmd
->SCp
.Status
;
834 /* Local Structure to set SCSI inquiry data strings */
836 char vid
[8]; /* Vendor ID */
837 char pid
[16]; /* Product ID */
838 char prl
[4]; /* Product Revision Level */
842 * InqStrCopy - string merge
843 * @a: string to copy from
844 * @b: string to copy to
846 * Copy a String from one location to another
850 static void inqstrcpy(char *a
, char *b
)
853 while (*a
!= (char)0)
857 static char *container_types
[] = {
881 char * get_container_type(unsigned tindex
)
883 if (tindex
>= ARRAY_SIZE(container_types
))
884 tindex
= ARRAY_SIZE(container_types
) - 1;
885 return container_types
[tindex
];
888 /* Function: setinqstr
890 * Arguments: [1] pointer to void [1] int
892 * Purpose: Sets SCSI inquiry data strings for vendor, product
893 * and revision level. Allows strings to be set in platform dependent
894 * files instead of in OS dependent driver source.
897 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
899 struct scsi_inq
*str
;
900 struct aac_supplement_adapter_info
*sup_adap_info
;
902 sup_adap_info
= &dev
->supplement_adapter_info
;
903 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
904 memset(str
, ' ', sizeof(*str
));
906 if (sup_adap_info
->adapter_type_text
[0]) {
909 char *cname
= kmemdup(sup_adap_info
->adapter_type_text
,
910 sizeof(sup_adap_info
->adapter_type_text
),
916 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
917 inqstrcpy("SMC", str
->vid
);
919 c
= sizeof(str
->vid
);
920 while (*cp
&& *cp
!= ' ' && --c
)
924 inqstrcpy(cname
, str
->vid
);
926 while (*cp
&& *cp
!= ' ')
931 /* last six chars reserved for vol type */
932 if (strlen(cp
) > sizeof(str
->pid
))
933 cp
[sizeof(str
->pid
)] = '\0';
934 inqstrcpy (cp
, str
->pid
);
938 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
940 inqstrcpy (mp
->vname
, str
->vid
);
941 /* last six chars reserved for vol type */
942 inqstrcpy (mp
->model
, str
->pid
);
945 if (tindex
< ARRAY_SIZE(container_types
)){
946 char *findit
= str
->pid
;
948 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
949 /* RAID is superfluous in the context of a RAID device */
950 if (memcmp(findit
-4, "RAID", 4) == 0)
951 *(findit
-= 4) = ' ';
952 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
953 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
954 inqstrcpy (container_types
[tindex
], findit
+ 1);
956 inqstrcpy ("V1.0", str
->prl
);
959 static void build_vpd83_type3(struct tvpd_page83
*vpdpage83data
,
960 struct aac_dev
*dev
, struct scsi_cmnd
*scsicmd
)
964 vpdpage83data
->type3
.codeset
= 1;
965 vpdpage83data
->type3
.identifiertype
= 3;
966 vpdpage83data
->type3
.identifierlength
= sizeof(vpdpage83data
->type3
)
969 for (container
= 0; container
< dev
->maximum_num_containers
;
972 if (scmd_id(scsicmd
) == container
) {
973 memcpy(vpdpage83data
->type3
.Identifier
,
974 dev
->fsa_dev
[container
].identifier
,
981 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
983 struct aac_get_serial_resp
* get_serial_reply
;
984 struct scsi_cmnd
* scsicmd
;
986 BUG_ON(fibptr
== NULL
);
988 scsicmd
= (struct scsi_cmnd
*) context
;
989 if (!aac_valid_context(scsicmd
, fibptr
))
992 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
993 /* Failure is irrelevant, using default value instead */
994 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
995 /*Check to see if it's for VPD 0x83 or 0x80 */
996 if (scsicmd
->cmnd
[2] == 0x83) {
997 /* vpd page 0x83 - Device Identification Page */
1000 struct tvpd_page83 vpdpage83data
;
1002 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1004 memset(((u8
*)&vpdpage83data
), 0,
1005 sizeof(vpdpage83data
));
1007 /* DIRECT_ACCESS_DEVIC */
1008 vpdpage83data
.DeviceType
= 0;
1009 /* DEVICE_CONNECTED */
1010 vpdpage83data
.DeviceTypeQualifier
= 0;
1011 /* VPD_DEVICE_IDENTIFIERS */
1012 vpdpage83data
.PageCode
= 0x83;
1013 vpdpage83data
.reserved
= 0;
1014 vpdpage83data
.PageLength
=
1015 sizeof(vpdpage83data
.type1
) +
1016 sizeof(vpdpage83data
.type2
);
1018 /* VPD 83 Type 3 is not supported for ARC */
1019 if (dev
->sa_firmware
)
1020 vpdpage83data
.PageLength
+=
1021 sizeof(vpdpage83data
.type3
);
1023 /* T10 Vendor Identifier Field Format */
1024 /* VpdcodesetAscii */
1025 vpdpage83data
.type1
.codeset
= 2;
1026 /* VpdIdentifierTypeVendorId */
1027 vpdpage83data
.type1
.identifiertype
= 1;
1028 vpdpage83data
.type1
.identifierlength
=
1029 sizeof(vpdpage83data
.type1
) - 4;
1031 /* "ADAPTEC " for adaptec */
1032 memcpy(vpdpage83data
.type1
.venid
,
1034 sizeof(vpdpage83data
.type1
.venid
));
1035 memcpy(vpdpage83data
.type1
.productid
,
1038 vpdpage83data
.type1
.productid
));
1040 /* Convert to ascii based serial number.
1041 * The LSB is the the end.
1043 for (i
= 0; i
< 8; i
++) {
1045 (u8
)((get_serial_reply
->uid
>> ((7 - i
) * 4)) & 0xF);
1047 vpdpage83data
.type1
.serialnumber
[i
] =
1050 vpdpage83data
.type1
.serialnumber
[i
] =
1055 /* VpdCodeSetBinary */
1056 vpdpage83data
.type2
.codeset
= 1;
1057 /* VpdidentifiertypeEUI64 */
1058 vpdpage83data
.type2
.identifiertype
= 2;
1059 vpdpage83data
.type2
.identifierlength
=
1060 sizeof(vpdpage83data
.type2
) - 4;
1062 vpdpage83data
.type2
.eu64id
.venid
[0] = 0xD0;
1063 vpdpage83data
.type2
.eu64id
.venid
[1] = 0;
1064 vpdpage83data
.type2
.eu64id
.venid
[2] = 0;
1066 vpdpage83data
.type2
.eu64id
.Serial
=
1067 get_serial_reply
->uid
;
1068 vpdpage83data
.type2
.eu64id
.reserved
= 0;
1071 * VpdIdentifierTypeFCPHName
1072 * VPD 0x83 Type 3 not supported for ARC
1074 if (dev
->sa_firmware
) {
1075 build_vpd83_type3(&vpdpage83data
,
1079 /* Move the inquiry data to the response buffer. */
1080 scsi_sg_copy_from_buffer(scsicmd
, &vpdpage83data
,
1081 sizeof(vpdpage83data
));
1083 /* It must be for VPD 0x80 */
1086 sp
[0] = INQD_PDT_DA
;
1087 sp
[1] = scsicmd
->cmnd
[2];
1089 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
1090 le32_to_cpu(get_serial_reply
->uid
));
1091 scsi_sg_copy_from_buffer(scsicmd
, sp
,
1096 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1098 aac_fib_complete(fibptr
);
1099 scsicmd
->scsi_done(scsicmd
);
1103 * aac_get_container_serial - get container serial, none blocking.
1105 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
1108 struct aac_get_serial
*dinfo
;
1109 struct fib
* cmd_fibcontext
;
1110 struct aac_dev
* dev
;
1112 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1114 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
1116 aac_fib_init(cmd_fibcontext
);
1117 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
1119 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
1120 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
1121 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1122 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1124 status
= aac_fib_send(ContainerCommand
,
1126 sizeof(struct aac_get_serial_resp
),
1129 (fib_callback
) get_container_serial_callback
,
1133 * Check that the command queued to the controller
1135 if (status
== -EINPROGRESS
)
1138 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
1139 aac_fib_complete(cmd_fibcontext
);
1143 /* Function: setinqserial
1145 * Arguments: [1] pointer to void [1] int
1147 * Purpose: Sets SCSI Unit Serial number.
1148 * This is a fake. We should read a proper
1149 * serial number from the container. <SuSE>But
1150 * without docs it's quite hard to do it :-)
1151 * So this will have to do in the meantime.</SuSE>
1154 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
1157 * This breaks array migration.
1159 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
1160 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
1163 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
1164 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
1166 u8
*sense_buf
= (u8
*)sense_data
;
1167 /* Sense data valid, err code 70h */
1168 sense_buf
[0] = 0x70; /* No info field */
1169 sense_buf
[1] = 0; /* Segment number, always zero */
1171 sense_buf
[2] = sense_key
; /* Sense key */
1173 sense_buf
[12] = sense_code
; /* Additional sense code */
1174 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
1176 if (sense_key
== ILLEGAL_REQUEST
) {
1177 sense_buf
[7] = 10; /* Additional sense length */
1179 sense_buf
[15] = bit_pointer
;
1180 /* Illegal parameter is in the parameter block */
1181 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
1182 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
1183 /* Illegal parameter is in the CDB block */
1184 sense_buf
[16] = field_pointer
>> 8; /* MSB */
1185 sense_buf
[17] = field_pointer
; /* LSB */
1187 sense_buf
[7] = 6; /* Additional sense length */
1190 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1192 if (lba
& 0xffffffff00000000LL
) {
1193 int cid
= scmd_id(cmd
);
1194 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1195 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1196 SAM_STAT_CHECK_CONDITION
;
1197 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1198 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1199 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1200 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1201 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1202 SCSI_SENSE_BUFFERSIZE
));
1203 cmd
->scsi_done(cmd
);
1209 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1214 static void io_callback(void *context
, struct fib
* fibptr
);
1216 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1218 struct aac_dev
*dev
= fib
->dev
;
1219 u16 fibsize
, command
;
1223 if ((dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
1224 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) &&
1226 struct aac_raw_io2
*readcmd2
;
1227 readcmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1228 memset(readcmd2
, 0, sizeof(struct aac_raw_io2
));
1229 readcmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1230 readcmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1231 readcmd2
->byteCount
= cpu_to_le32(count
*
1232 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1233 readcmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1234 readcmd2
->flags
= cpu_to_le16(RIO2_IO_TYPE_READ
);
1235 ret
= aac_build_sgraw2(cmd
, readcmd2
,
1236 dev
->scsi_host_ptr
->sg_tablesize
);
1239 command
= ContainerRawIo2
;
1240 fibsize
= sizeof(struct aac_raw_io2
) +
1241 ((le32_to_cpu(readcmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1243 struct aac_raw_io
*readcmd
;
1244 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
1245 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1246 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1247 readcmd
->count
= cpu_to_le32(count
*
1248 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1249 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1250 readcmd
->flags
= cpu_to_le16(RIO_TYPE_READ
);
1251 readcmd
->bpTotal
= 0;
1252 readcmd
->bpComplete
= 0;
1253 ret
= aac_build_sgraw(cmd
, &readcmd
->sg
);
1256 command
= ContainerRawIo
;
1257 fibsize
= sizeof(struct aac_raw_io
) +
1258 ((le32_to_cpu(readcmd
->sg
.count
)-1) * sizeof(struct sgentryraw
));
1261 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1263 * Now send the Fib to the adapter
1265 return aac_fib_send(command
,
1270 (fib_callback
) io_callback
,
1274 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1277 struct aac_read64
*readcmd
;
1281 readcmd
= (struct aac_read64
*) fib_data(fib
);
1282 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
1283 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1284 readcmd
->sector_count
= cpu_to_le16(count
);
1285 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1289 ret
= aac_build_sg64(cmd
, &readcmd
->sg
);
1292 fibsize
= sizeof(struct aac_read64
) +
1293 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1294 sizeof (struct sgentry64
));
1295 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1296 sizeof(struct aac_fibhdr
)));
1298 * Now send the Fib to the adapter
1300 return aac_fib_send(ContainerCommand64
,
1305 (fib_callback
) io_callback
,
1309 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1312 struct aac_read
*readcmd
;
1313 struct aac_dev
*dev
= fib
->dev
;
1317 readcmd
= (struct aac_read
*) fib_data(fib
);
1318 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
1319 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1320 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1321 readcmd
->count
= cpu_to_le32(count
*
1322 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1324 ret
= aac_build_sg(cmd
, &readcmd
->sg
);
1327 fibsize
= sizeof(struct aac_read
) +
1328 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1329 sizeof (struct sgentry
));
1330 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1331 sizeof(struct aac_fibhdr
)));
1333 * Now send the Fib to the adapter
1335 return aac_fib_send(ContainerCommand
,
1340 (fib_callback
) io_callback
,
1344 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1346 struct aac_dev
*dev
= fib
->dev
;
1347 u16 fibsize
, command
;
1351 if ((dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
1352 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) &&
1354 struct aac_raw_io2
*writecmd2
;
1355 writecmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1356 memset(writecmd2
, 0, sizeof(struct aac_raw_io2
));
1357 writecmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1358 writecmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1359 writecmd2
->byteCount
= cpu_to_le32(count
*
1360 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1361 writecmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1362 writecmd2
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1363 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1364 cpu_to_le16(RIO2_IO_TYPE_WRITE
|RIO2_IO_SUREWRITE
) :
1365 cpu_to_le16(RIO2_IO_TYPE_WRITE
);
1366 ret
= aac_build_sgraw2(cmd
, writecmd2
,
1367 dev
->scsi_host_ptr
->sg_tablesize
);
1370 command
= ContainerRawIo2
;
1371 fibsize
= sizeof(struct aac_raw_io2
) +
1372 ((le32_to_cpu(writecmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1374 struct aac_raw_io
*writecmd
;
1375 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1376 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1377 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1378 writecmd
->count
= cpu_to_le32(count
*
1379 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1380 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1381 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1382 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1383 cpu_to_le16(RIO_TYPE_WRITE
|RIO_SUREWRITE
) :
1384 cpu_to_le16(RIO_TYPE_WRITE
);
1385 writecmd
->bpTotal
= 0;
1386 writecmd
->bpComplete
= 0;
1387 ret
= aac_build_sgraw(cmd
, &writecmd
->sg
);
1390 command
= ContainerRawIo
;
1391 fibsize
= sizeof(struct aac_raw_io
) +
1392 ((le32_to_cpu(writecmd
->sg
.count
)-1) * sizeof (struct sgentryraw
));
1395 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1397 * Now send the Fib to the adapter
1399 return aac_fib_send(command
,
1404 (fib_callback
) io_callback
,
1408 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1411 struct aac_write64
*writecmd
;
1415 writecmd
= (struct aac_write64
*) fib_data(fib
);
1416 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1417 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1418 writecmd
->sector_count
= cpu_to_le16(count
);
1419 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1421 writecmd
->flags
= 0;
1423 ret
= aac_build_sg64(cmd
, &writecmd
->sg
);
1426 fibsize
= sizeof(struct aac_write64
) +
1427 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1428 sizeof (struct sgentry64
));
1429 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1430 sizeof(struct aac_fibhdr
)));
1432 * Now send the Fib to the adapter
1434 return aac_fib_send(ContainerCommand64
,
1439 (fib_callback
) io_callback
,
1443 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1446 struct aac_write
*writecmd
;
1447 struct aac_dev
*dev
= fib
->dev
;
1451 writecmd
= (struct aac_write
*) fib_data(fib
);
1452 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1453 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1454 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1455 writecmd
->count
= cpu_to_le32(count
*
1456 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1457 writecmd
->sg
.count
= cpu_to_le32(1);
1458 /* ->stable is not used - it did mean which type of write */
1460 ret
= aac_build_sg(cmd
, &writecmd
->sg
);
1463 fibsize
= sizeof(struct aac_write
) +
1464 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1465 sizeof (struct sgentry
));
1466 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1467 sizeof(struct aac_fibhdr
)));
1469 * Now send the Fib to the adapter
1471 return aac_fib_send(ContainerCommand
,
1476 (fib_callback
) io_callback
,
1480 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1482 struct aac_srb
* srbcmd
;
1485 struct aac_dev
*dev
= fib
->dev
;
1488 switch(cmd
->sc_data_direction
){
1492 case DMA_BIDIRECTIONAL
:
1493 flag
= SRB_DataIn
| SRB_DataOut
;
1495 case DMA_FROM_DEVICE
:
1499 default: /* shuts up some versions of gcc */
1500 flag
= SRB_NoDataXfer
;
1504 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1505 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1506 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1507 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1508 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1509 srbcmd
->flags
= cpu_to_le32(flag
);
1510 timeout
= cmd
->request
->timeout
/HZ
;
1512 timeout
= (dev
->sa_firmware
? AAC_SA_TIMEOUT
: AAC_ARC_TIMEOUT
);
1513 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1514 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1515 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1519 static struct aac_hba_cmd_req
*aac_construct_hbacmd(struct fib
*fib
,
1520 struct scsi_cmnd
*cmd
)
1522 struct aac_hba_cmd_req
*hbacmd
;
1523 struct aac_dev
*dev
;
1527 dev
= (struct aac_dev
*)cmd
->device
->host
->hostdata
;
1529 hbacmd
= (struct aac_hba_cmd_req
*)fib
->hw_fib_va
;
1530 memset(hbacmd
, 0, 96); /* sizeof(*hbacmd) is not necessary */
1531 /* iu_type is a parameter of aac_hba_send */
1532 switch (cmd
->sc_data_direction
) {
1536 case DMA_FROM_DEVICE
:
1537 case DMA_BIDIRECTIONAL
:
1544 hbacmd
->lun
[1] = cpu_to_le32(cmd
->device
->lun
);
1546 bus
= aac_logical_to_phys(scmd_channel(cmd
));
1547 target
= scmd_id(cmd
);
1548 hbacmd
->it_nexus
= dev
->hba_map
[bus
][target
].rmw_nexus
;
1550 /* we fill in reply_qid later in aac_src_deliver_message */
1551 /* we fill in iu_type, request_id later in aac_hba_send */
1552 /* we fill in emb_data_desc_count later in aac_build_sghba */
1554 memcpy(hbacmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1555 hbacmd
->data_length
= cpu_to_le32(scsi_bufflen(cmd
));
1557 address
= (u64
)fib
->hw_error_pa
;
1558 hbacmd
->error_ptr_hi
= cpu_to_le32((u32
)(address
>> 32));
1559 hbacmd
->error_ptr_lo
= cpu_to_le32((u32
)(address
& 0xffffffff));
1560 hbacmd
->error_length
= cpu_to_le32(FW_ERROR_BUFFER_SIZE
);
1565 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1567 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1570 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1573 ret
= aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1576 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1578 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1579 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1581 * Build Scatter/Gather list
1583 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1584 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1585 sizeof (struct sgentry64
));
1586 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1587 sizeof(struct aac_fibhdr
)));
1590 * Now send the Fib to the adapter
1592 return aac_fib_send(ScsiPortCommand64
, fib
,
1593 fibsize
, FsaNormal
, 0, 1,
1594 (fib_callback
) aac_srb_callback
,
1598 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1601 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1604 ret
= aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1607 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1609 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1610 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1612 * Build Scatter/Gather list
1614 fibsize
= sizeof (struct aac_srb
) +
1615 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1616 sizeof (struct sgentry
));
1617 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1618 sizeof(struct aac_fibhdr
)));
1621 * Now send the Fib to the adapter
1623 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1624 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1627 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1629 if ((sizeof(dma_addr_t
) > 4) && fib
->dev
->needs_dac
&&
1630 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1632 return aac_scsi_32(fib
, cmd
);
1635 static int aac_adapter_hba(struct fib
*fib
, struct scsi_cmnd
*cmd
)
1637 struct aac_hba_cmd_req
*hbacmd
= aac_construct_hbacmd(fib
, cmd
);
1638 struct aac_dev
*dev
;
1641 dev
= (struct aac_dev
*)cmd
->device
->host
->hostdata
;
1643 ret
= aac_build_sghba(cmd
, hbacmd
,
1644 dev
->scsi_host_ptr
->sg_tablesize
, (u64
)fib
->hw_sgl_pa
);
1649 * Now send the HBA command to the adapter
1651 fib
->hbacmd_size
= 64 + le32_to_cpu(hbacmd
->emb_data_desc_count
) *
1652 sizeof(struct aac_hba_sgl
);
1654 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ
, fib
,
1655 (fib_callback
) aac_hba_callback
,
1659 static int aac_send_safw_bmic_cmd(struct aac_dev
*dev
,
1660 struct aac_srb_unit
*srbu
, void *xfer_buf
, int xfer_len
)
1666 struct aac_srb
*srb
;
1667 struct aac_srb_reply
*srb_reply
;
1668 struct sgmap64
*sg64
;
1672 if (!dev
->sa_firmware
)
1676 fibptr
= aac_fib_alloc(dev
);
1680 aac_fib_init(fibptr
);
1681 fibptr
->hw_fib_va
->header
.XferState
&=
1682 ~cpu_to_le32(FastResponseCapable
);
1684 fibsize
= sizeof(struct aac_srb
) - sizeof(struct sgentry
) +
1685 sizeof(struct sgentry64
);
1687 /* allocate DMA buffer for response */
1688 addr
= dma_map_single(&dev
->pdev
->dev
, xfer_buf
, xfer_len
,
1690 if (dma_mapping_error(&dev
->pdev
->dev
, addr
)) {
1695 srb
= fib_data(fibptr
);
1696 memcpy(srb
, &srbu
->srb
, sizeof(struct aac_srb
));
1698 vbus
= (u32
)le16_to_cpu(
1699 dev
->supplement_adapter_info
.virt_device_bus
);
1700 vid
= (u32
)le16_to_cpu(
1701 dev
->supplement_adapter_info
.virt_device_target
);
1703 /* set the common request fields */
1704 srb
->channel
= cpu_to_le32(vbus
);
1705 srb
->id
= cpu_to_le32(vid
);
1707 srb
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1709 srb
->retry_limit
= 0;
1710 srb
->cdb_size
= cpu_to_le32(16);
1711 srb
->count
= cpu_to_le32(xfer_len
);
1713 sg64
= (struct sgmap64
*)&srb
->sg
;
1714 sg64
->count
= cpu_to_le32(1);
1715 sg64
->sg
[0].addr
[1] = cpu_to_le32(upper_32_bits(addr
));
1716 sg64
->sg
[0].addr
[0] = cpu_to_le32(lower_32_bits(addr
));
1717 sg64
->sg
[0].count
= cpu_to_le32(xfer_len
);
1720 * Copy the updated data for other dumping or other usage if needed
1722 memcpy(&srbu
->srb
, srb
, sizeof(struct aac_srb
));
1724 /* issue request to the controller */
1725 rcode
= aac_fib_send(ScsiPortCommand64
, fibptr
, fibsize
, FsaNormal
,
1728 if (rcode
== -ERESTARTSYS
)
1731 if (unlikely(rcode
< 0))
1734 srb_reply
= (struct aac_srb_reply
*)fib_data(fibptr
);
1735 memcpy(&srbu
->srb_reply
, srb_reply
, sizeof(struct aac_srb_reply
));
1738 dma_unmap_single(&dev
->pdev
->dev
, addr
, xfer_len
, DMA_BIDIRECTIONAL
);
1740 aac_fib_complete(fibptr
);
1741 aac_fib_free(fibptr
);
1745 static void aac_set_safw_target_qd(struct aac_dev
*dev
, int bus
, int target
)
1748 struct aac_ciss_identify_pd
*identify_resp
;
1750 if (dev
->hba_map
[bus
][target
].devtype
!= AAC_DEVTYPE_NATIVE_RAW
)
1753 identify_resp
= dev
->hba_map
[bus
][target
].safw_identify_resp
;
1754 if (identify_resp
== NULL
) {
1755 dev
->hba_map
[bus
][target
].qd_limit
= 32;
1759 if (identify_resp
->current_queue_depth_limit
<= 0 ||
1760 identify_resp
->current_queue_depth_limit
> 255)
1761 dev
->hba_map
[bus
][target
].qd_limit
= 32;
1763 dev
->hba_map
[bus
][target
].qd_limit
=
1764 identify_resp
->current_queue_depth_limit
;
1767 static int aac_issue_safw_bmic_identify(struct aac_dev
*dev
,
1768 struct aac_ciss_identify_pd
**identify_resp
, u32 bus
, u32 target
)
1770 int rcode
= -ENOMEM
;
1772 struct aac_srb_unit srbu
;
1773 struct aac_srb
*srbcmd
;
1774 struct aac_ciss_identify_pd
*identify_reply
;
1776 datasize
= sizeof(struct aac_ciss_identify_pd
);
1777 identify_reply
= kmalloc(datasize
, GFP_KERNEL
);
1778 if (!identify_reply
)
1781 memset(&srbu
, 0, sizeof(struct aac_srb_unit
));
1784 srbcmd
->flags
= cpu_to_le32(SRB_DataIn
);
1785 srbcmd
->cdb
[0] = 0x26;
1786 srbcmd
->cdb
[2] = (u8
)((AAC_MAX_LUN
+ target
) & 0x00FF);
1787 srbcmd
->cdb
[6] = CISS_IDENTIFY_PHYSICAL_DEVICE
;
1789 rcode
= aac_send_safw_bmic_cmd(dev
, &srbu
, identify_reply
, datasize
);
1790 if (unlikely(rcode
< 0))
1793 *identify_resp
= identify_reply
;
1798 kfree(identify_reply
);
1802 static inline void aac_free_safw_ciss_luns(struct aac_dev
*dev
)
1804 kfree(dev
->safw_phys_luns
);
1805 dev
->safw_phys_luns
= NULL
;
1809 * aac_get_safw_ciss_luns() Process topology change
1810 * @dev: aac_dev structure
1812 * Execute a CISS REPORT PHYS LUNS and process the results into
1813 * the current hba_map.
1815 static int aac_get_safw_ciss_luns(struct aac_dev
*dev
)
1817 int rcode
= -ENOMEM
;
1819 struct aac_srb
*srbcmd
;
1820 struct aac_srb_unit srbu
;
1821 struct aac_ciss_phys_luns_resp
*phys_luns
;
1823 datasize
= sizeof(struct aac_ciss_phys_luns_resp
) +
1824 (AAC_MAX_TARGETS
- 1) * sizeof(struct _ciss_lun
);
1825 phys_luns
= kmalloc(datasize
, GFP_KERNEL
);
1826 if (phys_luns
== NULL
)
1829 memset(&srbu
, 0, sizeof(struct aac_srb_unit
));
1832 srbcmd
->flags
= cpu_to_le32(SRB_DataIn
);
1833 srbcmd
->cdb
[0] = CISS_REPORT_PHYSICAL_LUNS
;
1834 srbcmd
->cdb
[1] = 2; /* extended reporting */
1835 srbcmd
->cdb
[8] = (u8
)(datasize
>> 8);
1836 srbcmd
->cdb
[9] = (u8
)(datasize
);
1838 rcode
= aac_send_safw_bmic_cmd(dev
, &srbu
, phys_luns
, datasize
);
1839 if (unlikely(rcode
< 0))
1842 if (phys_luns
->resp_flag
!= 2) {
1847 dev
->safw_phys_luns
= phys_luns
;
1856 static inline u32
aac_get_safw_phys_lun_count(struct aac_dev
*dev
)
1858 return get_unaligned_be32(&dev
->safw_phys_luns
->list_length
[0])/24;
1861 static inline u32
aac_get_safw_phys_bus(struct aac_dev
*dev
, int lun
)
1863 return dev
->safw_phys_luns
->lun
[lun
].level2
[1] & 0x3f;
1866 static inline u32
aac_get_safw_phys_target(struct aac_dev
*dev
, int lun
)
1868 return dev
->safw_phys_luns
->lun
[lun
].level2
[0];
1871 static inline u32
aac_get_safw_phys_expose_flag(struct aac_dev
*dev
, int lun
)
1873 return dev
->safw_phys_luns
->lun
[lun
].bus
>> 6;
1876 static inline u32
aac_get_safw_phys_attribs(struct aac_dev
*dev
, int lun
)
1878 return dev
->safw_phys_luns
->lun
[lun
].node_ident
[9];
1881 static inline u32
aac_get_safw_phys_nexus(struct aac_dev
*dev
, int lun
)
1883 return *((u32
*)&dev
->safw_phys_luns
->lun
[lun
].node_ident
[12]);
1886 static inline u32
aac_get_safw_phys_device_type(struct aac_dev
*dev
, int lun
)
1888 return dev
->safw_phys_luns
->lun
[lun
].node_ident
[8];
1891 static inline void aac_free_safw_identify_resp(struct aac_dev
*dev
,
1892 int bus
, int target
)
1894 kfree(dev
->hba_map
[bus
][target
].safw_identify_resp
);
1895 dev
->hba_map
[bus
][target
].safw_identify_resp
= NULL
;
1898 static inline void aac_free_safw_all_identify_resp(struct aac_dev
*dev
,
1906 luns
= aac_get_safw_phys_lun_count(dev
);
1908 if (luns
< lun_count
)
1910 else if (lun_count
< 0)
1913 for (i
= 0; i
< lun_count
; i
++) {
1914 bus
= aac_get_safw_phys_bus(dev
, i
);
1915 target
= aac_get_safw_phys_target(dev
, i
);
1917 aac_free_safw_identify_resp(dev
, bus
, target
);
1921 static int aac_get_safw_attr_all_targets(struct aac_dev
*dev
)
1928 struct aac_ciss_identify_pd
*identify_resp
= NULL
;
1930 lun_count
= aac_get_safw_phys_lun_count(dev
);
1932 for (i
= 0; i
< lun_count
; ++i
) {
1934 bus
= aac_get_safw_phys_bus(dev
, i
);
1935 target
= aac_get_safw_phys_target(dev
, i
);
1937 rcode
= aac_issue_safw_bmic_identify(dev
,
1938 &identify_resp
, bus
, target
);
1940 if (unlikely(rcode
< 0))
1941 goto free_identify_resp
;
1943 dev
->hba_map
[bus
][target
].safw_identify_resp
= identify_resp
;
1949 aac_free_safw_all_identify_resp(dev
, i
);
1954 * aac_set_safw_attr_all_targets- update current hba map with data from FW
1955 * @dev: aac_dev structure
1956 * @phys_luns: FW information from report phys luns
1957 * @rescan: Indicates scan type
1959 * Update our hba map with the information gathered from the FW
1961 static void aac_set_safw_attr_all_targets(struct aac_dev
*dev
)
1963 /* ok and extended reporting */
1964 u32 lun_count
, nexus
;
1966 u8 expose_flag
, attribs
;
1968 lun_count
= aac_get_safw_phys_lun_count(dev
);
1970 dev
->scan_counter
++;
1972 for (i
= 0; i
< lun_count
; ++i
) {
1974 bus
= aac_get_safw_phys_bus(dev
, i
);
1975 target
= aac_get_safw_phys_target(dev
, i
);
1976 expose_flag
= aac_get_safw_phys_expose_flag(dev
, i
);
1977 attribs
= aac_get_safw_phys_attribs(dev
, i
);
1978 nexus
= aac_get_safw_phys_nexus(dev
, i
);
1980 if (bus
>= AAC_MAX_BUSES
|| target
>= AAC_MAX_TARGETS
)
1983 if (expose_flag
!= 0) {
1984 dev
->hba_map
[bus
][target
].devtype
=
1985 AAC_DEVTYPE_RAID_MEMBER
;
1989 if (nexus
!= 0 && (attribs
& 8)) {
1990 dev
->hba_map
[bus
][target
].devtype
=
1991 AAC_DEVTYPE_NATIVE_RAW
;
1992 dev
->hba_map
[bus
][target
].rmw_nexus
=
1995 dev
->hba_map
[bus
][target
].devtype
=
1996 AAC_DEVTYPE_ARC_RAW
;
1998 dev
->hba_map
[bus
][target
].scan_counter
= dev
->scan_counter
;
2000 aac_set_safw_target_qd(dev
, bus
, target
);
2004 static int aac_setup_safw_targets(struct aac_dev
*dev
)
2008 rcode
= aac_get_containers(dev
);
2009 if (unlikely(rcode
< 0))
2012 rcode
= aac_get_safw_ciss_luns(dev
);
2013 if (unlikely(rcode
< 0))
2016 rcode
= aac_get_safw_attr_all_targets(dev
);
2017 if (unlikely(rcode
< 0))
2018 goto free_ciss_luns
;
2020 aac_set_safw_attr_all_targets(dev
);
2022 aac_free_safw_all_identify_resp(dev
, -1);
2024 aac_free_safw_ciss_luns(dev
);
2029 int aac_setup_safw_adapter(struct aac_dev
*dev
)
2031 return aac_setup_safw_targets(dev
);
2034 int aac_get_adapter_info(struct aac_dev
* dev
)
2038 u32 tmp
, bus
, target
;
2039 struct aac_adapter_info
*info
;
2040 struct aac_bus_info
*command
;
2041 struct aac_bus_info_response
*bus_info
;
2043 if (!(fibptr
= aac_fib_alloc(dev
)))
2046 aac_fib_init(fibptr
);
2047 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
2048 memset(info
,0,sizeof(*info
));
2050 rcode
= aac_fib_send(RequestAdapterInfo
,
2054 -1, 1, /* First `interrupt' command uses special wait */
2059 /* FIB should be freed only after
2060 * getting the response from the F/W */
2061 if (rcode
!= -ERESTARTSYS
) {
2062 aac_fib_complete(fibptr
);
2063 aac_fib_free(fibptr
);
2067 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
2069 dev
->supplement_adapter_info
.virt_device_bus
= 0xffff;
2070 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
2071 struct aac_supplement_adapter_info
* sinfo
;
2073 aac_fib_init(fibptr
);
2075 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
2077 memset(sinfo
,0,sizeof(*sinfo
));
2079 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
2088 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
2089 if (rcode
== -ERESTARTSYS
) {
2090 fibptr
= aac_fib_alloc(dev
);
2097 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
2098 for (bus
= 0; bus
< AAC_MAX_BUSES
; bus
++) {
2099 for (target
= 0; target
< AAC_MAX_TARGETS
; target
++) {
2100 dev
->hba_map
[bus
][target
].devtype
= 0;
2101 dev
->hba_map
[bus
][target
].qd_limit
= 0;
2109 aac_fib_init(fibptr
);
2111 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
2113 memset(bus_info
, 0, sizeof(*bus_info
));
2115 command
= (struct aac_bus_info
*)bus_info
;
2117 command
->Command
= cpu_to_le32(VM_Ioctl
);
2118 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
2119 command
->MethodId
= cpu_to_le32(1);
2120 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
2122 rcode
= aac_fib_send(ContainerCommand
,
2129 /* reasoned default */
2130 dev
->maximum_num_physicals
= 16;
2131 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
2132 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
2133 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
2136 if (!dev
->in_reset
) {
2138 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
2139 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
2145 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
2146 (int)sizeof(dev
->supplement_adapter_info
.build_date
),
2147 dev
->supplement_adapter_info
.build_date
);
2148 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
2149 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
2151 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
2152 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
2153 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
2154 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
2156 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
2157 le32_to_cpu(dev
->adapter_info
.biosbuild
));
2159 if (aac_get_serial_number(
2160 shost_to_class(dev
->scsi_host_ptr
), buffer
))
2161 printk(KERN_INFO
"%s%d: serial %s",
2162 dev
->name
, dev
->id
, buffer
);
2163 if (dev
->supplement_adapter_info
.vpd_info
.tsid
[0]) {
2164 printk(KERN_INFO
"%s%d: TSID %.*s\n",
2166 (int)sizeof(dev
->supplement_adapter_info
2168 dev
->supplement_adapter_info
.vpd_info
.tsid
);
2170 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
2171 (dev
->supplement_adapter_info
.supported_options2
&
2172 AAC_OPTION_IGNORE_RESET
))) {
2173 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
2174 dev
->name
, dev
->id
);
2178 dev
->cache_protected
= 0;
2179 dev
->jbod
= ((dev
->supplement_adapter_info
.feature_bits
&
2180 AAC_FEATURE_JBOD
) != 0);
2181 dev
->nondasd_support
= 0;
2182 dev
->raid_scsi_mode
= 0;
2183 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
2184 dev
->nondasd_support
= 1;
2187 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2188 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2189 * force nondasd support on. If we decide to allow the non-dasd flag
2190 * additional changes changes will have to be made to support
2191 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2192 * changed to support the new dev->raid_scsi_mode flag instead of
2193 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2194 * function aac_detect will have to be modified where it sets up the
2195 * max number of channels based on the aac->nondasd_support flag only.
2197 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
2198 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
2199 dev
->nondasd_support
= 1;
2200 dev
->raid_scsi_mode
= 1;
2202 if (dev
->raid_scsi_mode
!= 0)
2203 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
2204 dev
->name
, dev
->id
);
2207 dev
->nondasd_support
= (nondasd
!=0);
2208 if (dev
->nondasd_support
&& !dev
->in_reset
)
2209 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
2211 if (dma_get_required_mask(&dev
->pdev
->dev
) > DMA_BIT_MASK(32))
2213 dev
->dac_support
= 0;
2214 if ((sizeof(dma_addr_t
) > 4) && dev
->needs_dac
&&
2215 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)) {
2217 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
2218 dev
->name
, dev
->id
);
2219 dev
->dac_support
= 1;
2223 dev
->dac_support
= (dacmode
!=0);
2226 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2227 if (dev
->dac_support
&& (aac_get_driver_ident(dev
->cardtype
)->quirks
2228 & AAC_QUIRK_SCSI_32
)) {
2229 dev
->nondasd_support
= 0;
2231 expose_physicals
= 0;
2234 if (dev
->dac_support
) {
2235 if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(64))) {
2237 dev_info(&dev
->pdev
->dev
, "64 Bit DAC enabled\n");
2238 } else if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(32))) {
2239 dev_info(&dev
->pdev
->dev
, "DMA mask set failed, 64 Bit DAC disabled\n");
2240 dev
->dac_support
= 0;
2242 dev_info(&dev
->pdev
->dev
, "No suitable DMA available\n");
2247 * Deal with configuring for the individualized limits of each packet
2250 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
2251 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
2255 if (dev
->raw_io_interface
) {
2256 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
2259 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
2260 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
2262 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
2263 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
2264 sizeof(struct aac_fibhdr
) -
2265 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
2266 sizeof(struct sgentry
);
2267 if (dev
->dac_support
) {
2268 dev
->a_ops
.adapter_read
= aac_read_block64
;
2269 dev
->a_ops
.adapter_write
= aac_write_block64
;
2271 * 38 scatter gather elements
2273 dev
->scsi_host_ptr
->sg_tablesize
=
2274 (dev
->max_fib_size
-
2275 sizeof(struct aac_fibhdr
) -
2276 sizeof(struct aac_write64
) +
2277 sizeof(struct sgentry64
)) /
2278 sizeof(struct sgentry64
);
2280 dev
->a_ops
.adapter_read
= aac_read_block
;
2281 dev
->a_ops
.adapter_write
= aac_write_block
;
2283 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
2284 if (!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
2286 * Worst case size that could cause sg overflow when
2287 * we break up SG elements that are larger than 64KB.
2288 * Would be nice if we could tell the SCSI layer what
2289 * the maximum SG element size can be. Worst case is
2290 * (sg_tablesize-1) 4KB elements with one 64KB
2292 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2294 dev
->scsi_host_ptr
->max_sectors
=
2295 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
2298 if (!dev
->sync_mode
&& dev
->sa_firmware
&&
2299 dev
->scsi_host_ptr
->sg_tablesize
> HBA_MAX_SG_SEPARATE
)
2300 dev
->scsi_host_ptr
->sg_tablesize
= dev
->sg_tablesize
=
2301 HBA_MAX_SG_SEPARATE
;
2303 /* FIB should be freed only after getting the response from the F/W */
2304 if (rcode
!= -ERESTARTSYS
) {
2305 aac_fib_complete(fibptr
);
2306 aac_fib_free(fibptr
);
2313 static void io_callback(void *context
, struct fib
* fibptr
)
2315 struct aac_dev
*dev
;
2316 struct aac_read_reply
*readreply
;
2317 struct scsi_cmnd
*scsicmd
;
2320 scsicmd
= (struct scsi_cmnd
*) context
;
2322 if (!aac_valid_context(scsicmd
, fibptr
))
2326 cid
= scmd_id(scsicmd
);
2328 if (nblank(dprintk(x
))) {
2330 switch (scsicmd
->cmnd
[0]) {
2333 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
2334 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2338 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2339 ((u64
)scsicmd
->cmnd
[3] << 48) |
2340 ((u64
)scsicmd
->cmnd
[4] << 40) |
2341 ((u64
)scsicmd
->cmnd
[5] << 32) |
2342 ((u64
)scsicmd
->cmnd
[6] << 24) |
2343 (scsicmd
->cmnd
[7] << 16) |
2344 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2348 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2349 (scsicmd
->cmnd
[3] << 16) |
2350 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2353 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2354 (scsicmd
->cmnd
[3] << 16) |
2355 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2359 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2360 smp_processor_id(), (unsigned long long)lba
, jiffies
);
2363 BUG_ON(fibptr
== NULL
);
2365 scsi_dma_unmap(scsicmd
);
2367 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
2368 switch (le32_to_cpu(readreply
->status
)) {
2370 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2372 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
2375 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2376 SAM_STAT_CHECK_CONDITION
;
2377 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
2378 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
2379 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2380 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2381 SCSI_SENSE_BUFFERSIZE
));
2384 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2385 SAM_STAT_CHECK_CONDITION
;
2386 set_sense(&dev
->fsa_dev
[cid
].sense_data
, MEDIUM_ERROR
,
2387 SENCODE_UNRECOVERED_READ_ERROR
, ASENCODE_NO_SENSE
, 0, 0);
2388 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2389 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2390 SCSI_SENSE_BUFFERSIZE
));
2393 #ifdef AAC_DETAILED_STATUS_INFO
2394 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
2395 le32_to_cpu(readreply
->status
));
2397 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2398 SAM_STAT_CHECK_CONDITION
;
2399 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2400 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2401 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2402 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2403 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2404 SCSI_SENSE_BUFFERSIZE
));
2407 aac_fib_complete(fibptr
);
2409 scsicmd
->scsi_done(scsicmd
);
2412 static int aac_read(struct scsi_cmnd
* scsicmd
)
2417 struct aac_dev
*dev
;
2418 struct fib
* cmd_fibcontext
;
2421 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2423 * Get block address and transfer length
2425 switch (scsicmd
->cmnd
[0]) {
2427 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
2429 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
2430 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2431 count
= scsicmd
->cmnd
[4];
2437 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
2439 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2440 ((u64
)scsicmd
->cmnd
[3] << 48) |
2441 ((u64
)scsicmd
->cmnd
[4] << 40) |
2442 ((u64
)scsicmd
->cmnd
[5] << 32) |
2443 ((u64
)scsicmd
->cmnd
[6] << 24) |
2444 (scsicmd
->cmnd
[7] << 16) |
2445 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2446 count
= (scsicmd
->cmnd
[10] << 24) |
2447 (scsicmd
->cmnd
[11] << 16) |
2448 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2451 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
2453 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2454 (scsicmd
->cmnd
[3] << 16) |
2455 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2456 count
= (scsicmd
->cmnd
[6] << 24) |
2457 (scsicmd
->cmnd
[7] << 16) |
2458 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2461 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
2463 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2464 (scsicmd
->cmnd
[3] << 16) |
2465 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2466 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2470 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2471 cid
= scmd_id(scsicmd
);
2472 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2473 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2474 SAM_STAT_CHECK_CONDITION
;
2475 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2476 ILLEGAL_REQUEST
, SENCODE_LBA_OUT_OF_RANGE
,
2477 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2478 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2479 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2480 SCSI_SENSE_BUFFERSIZE
));
2481 scsicmd
->scsi_done(scsicmd
);
2485 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
2486 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2487 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2490 * Alocate and initialize a Fib
2492 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2493 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2494 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
2497 * Check that the command queued to the controller
2499 if (status
== -EINPROGRESS
)
2502 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
2504 * For some reason, the Fib didn't queue, return QUEUE_FULL
2506 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2507 scsicmd
->scsi_done(scsicmd
);
2508 aac_fib_complete(cmd_fibcontext
);
2509 aac_fib_free(cmd_fibcontext
);
2513 static int aac_write(struct scsi_cmnd
* scsicmd
)
2519 struct aac_dev
*dev
;
2520 struct fib
* cmd_fibcontext
;
2523 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2525 * Get block address and transfer length
2527 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
2529 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2530 count
= scsicmd
->cmnd
[4];
2534 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
2535 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
2537 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2538 ((u64
)scsicmd
->cmnd
[3] << 48) |
2539 ((u64
)scsicmd
->cmnd
[4] << 40) |
2540 ((u64
)scsicmd
->cmnd
[5] << 32) |
2541 ((u64
)scsicmd
->cmnd
[6] << 24) |
2542 (scsicmd
->cmnd
[7] << 16) |
2543 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2544 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
2545 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2546 fua
= scsicmd
->cmnd
[1] & 0x8;
2547 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
2548 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
2550 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
2551 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2552 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
2553 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2554 fua
= scsicmd
->cmnd
[1] & 0x8;
2556 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
2557 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2558 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2559 fua
= scsicmd
->cmnd
[1] & 0x8;
2562 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2563 cid
= scmd_id(scsicmd
);
2564 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2565 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2566 SAM_STAT_CHECK_CONDITION
;
2567 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2568 ILLEGAL_REQUEST
, SENCODE_LBA_OUT_OF_RANGE
,
2569 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2570 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2571 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2572 SCSI_SENSE_BUFFERSIZE
));
2573 scsicmd
->scsi_done(scsicmd
);
2577 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2578 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2579 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2582 * Allocate and initialize a Fib then setup a BlockWrite command
2584 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2585 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2586 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
2589 * Check that the command queued to the controller
2591 if (status
== -EINPROGRESS
)
2594 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
2596 * For some reason, the Fib didn't queue, return QUEUE_FULL
2598 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2599 scsicmd
->scsi_done(scsicmd
);
2601 aac_fib_complete(cmd_fibcontext
);
2602 aac_fib_free(cmd_fibcontext
);
2606 static void synchronize_callback(void *context
, struct fib
*fibptr
)
2608 struct aac_synchronize_reply
*synchronizereply
;
2609 struct scsi_cmnd
*cmd
= context
;
2611 if (!aac_valid_context(cmd
, fibptr
))
2614 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
2615 smp_processor_id(), jiffies
));
2616 BUG_ON(fibptr
== NULL
);
2619 synchronizereply
= fib_data(fibptr
);
2620 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
2621 cmd
->result
= DID_OK
<< 16 |
2622 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2624 struct scsi_device
*sdev
= cmd
->device
;
2625 struct aac_dev
*dev
= fibptr
->dev
;
2626 u32 cid
= sdev_id(sdev
);
2628 "synchronize_callback: synchronize failed, status = %d\n",
2629 le32_to_cpu(synchronizereply
->status
));
2630 cmd
->result
= DID_OK
<< 16 |
2631 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2632 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2633 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2634 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2635 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2636 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2637 SCSI_SENSE_BUFFERSIZE
));
2640 aac_fib_complete(fibptr
);
2641 aac_fib_free(fibptr
);
2642 cmd
->scsi_done(cmd
);
2645 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
2648 struct fib
*cmd_fibcontext
;
2649 struct aac_synchronize
*synchronizecmd
;
2650 struct scsi_device
*sdev
= scsicmd
->device
;
2651 struct aac_dev
*aac
;
2653 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2655 return SCSI_MLQUEUE_HOST_BUSY
;
2658 * Allocate and initialize a Fib
2660 cmd_fibcontext
= aac_fib_alloc_tag(aac
, scsicmd
);
2662 aac_fib_init(cmd_fibcontext
);
2664 synchronizecmd
= fib_data(cmd_fibcontext
);
2665 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2666 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
2667 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
2668 synchronizecmd
->count
=
2669 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
2670 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2673 * Now send the Fib to the adapter
2675 status
= aac_fib_send(ContainerCommand
,
2677 sizeof(struct aac_synchronize
),
2680 (fib_callback
)synchronize_callback
,
2684 * Check that the command queued to the controller
2686 if (status
== -EINPROGRESS
)
2690 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
2691 aac_fib_complete(cmd_fibcontext
);
2692 aac_fib_free(cmd_fibcontext
);
2693 return SCSI_MLQUEUE_HOST_BUSY
;
2696 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
2698 struct scsi_cmnd
*scsicmd
= context
;
2700 if (!aac_valid_context(scsicmd
, fibptr
))
2703 BUG_ON(fibptr
== NULL
);
2705 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2707 aac_fib_complete(fibptr
);
2708 aac_fib_free(fibptr
);
2709 scsicmd
->scsi_done(scsicmd
);
2712 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
2715 struct fib
*cmd_fibcontext
;
2716 struct aac_power_management
*pmcmd
;
2717 struct scsi_device
*sdev
= scsicmd
->device
;
2718 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2720 if (!(aac
->supplement_adapter_info
.supported_options2
&
2721 AAC_OPTION_POWER_MANAGEMENT
)) {
2722 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2724 scsicmd
->scsi_done(scsicmd
);
2729 return SCSI_MLQUEUE_HOST_BUSY
;
2732 * Allocate and initialize a Fib
2734 cmd_fibcontext
= aac_fib_alloc_tag(aac
, scsicmd
);
2736 aac_fib_init(cmd_fibcontext
);
2738 pmcmd
= fib_data(cmd_fibcontext
);
2739 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2740 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
2741 /* Eject bit ignored, not relevant */
2742 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
2743 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
2744 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
2745 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
2746 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
2747 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2750 * Now send the Fib to the adapter
2752 status
= aac_fib_send(ContainerCommand
,
2754 sizeof(struct aac_power_management
),
2757 (fib_callback
)aac_start_stop_callback
,
2761 * Check that the command queued to the controller
2763 if (status
== -EINPROGRESS
)
2766 aac_fib_complete(cmd_fibcontext
);
2767 aac_fib_free(cmd_fibcontext
);
2768 return SCSI_MLQUEUE_HOST_BUSY
;
2772 * aac_scsi_cmd() - Process SCSI command
2773 * @scsicmd: SCSI command block
2775 * Emulate a SCSI command and queue the required request for the
2779 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
2782 struct Scsi_Host
*host
= scsicmd
->device
->host
;
2783 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
2784 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
2786 if (fsa_dev_ptr
== NULL
)
2789 * If the bus, id or lun is out of range, return fail
2790 * Test does not apply to ID 16, the pseudo id for the controller
2793 cid
= scmd_id(scsicmd
);
2794 if (cid
!= host
->this_id
) {
2795 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
2796 if((cid
>= dev
->maximum_num_containers
) ||
2797 (scsicmd
->device
->lun
!= 0)) {
2798 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2803 * If the target container doesn't exist, it may have
2804 * been newly created
2806 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2807 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2809 switch (scsicmd
->cmnd
[0]) {
2810 case SERVICE_ACTION_IN_16
:
2811 if (!(dev
->raw_io_interface
) ||
2812 !(dev
->raw_io_64
) ||
2813 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2818 case TEST_UNIT_READY
:
2821 return _aac_probe_container(scsicmd
,
2822 aac_probe_container_callback2
);
2827 } else { /* check for physical non-dasd devices */
2828 bus
= aac_logical_to_phys(scmd_channel(scsicmd
));
2830 if (bus
< AAC_MAX_BUSES
&& cid
< AAC_MAX_TARGETS
&&
2831 dev
->hba_map
[bus
][cid
].devtype
2832 == AAC_DEVTYPE_NATIVE_RAW
) {
2835 return aac_send_hba_fib(scsicmd
);
2836 } else if (dev
->nondasd_support
|| expose_physicals
||
2840 return aac_send_srb_fib(scsicmd
);
2842 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2848 * else Command for the controller itself
2850 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2851 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2853 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2854 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2855 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2856 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2857 ASENCODE_INVALID_COMMAND
, 0, 0);
2858 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2859 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2860 SCSI_SENSE_BUFFERSIZE
));
2864 switch (scsicmd
->cmnd
[0]) {
2871 return aac_read(scsicmd
);
2879 return aac_write(scsicmd
);
2881 case SYNCHRONIZE_CACHE
:
2882 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2883 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2887 /* Issue FIB to tell Firmware to flush it's cache */
2888 if ((aac_cache
& 6) != 2)
2889 return aac_synchronize(scsicmd
);
2893 struct inquiry_data inq_data
;
2895 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2896 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2898 if ((scsicmd
->cmnd
[1] & 0x1) && aac_wwn
) {
2899 char *arr
= (char *)&inq_data
;
2902 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2903 INQD_PDT_PROC
: INQD_PDT_DA
;
2904 if (scsicmd
->cmnd
[2] == 0) {
2905 /* supported vital product data pages */
2910 arr
[1] = scsicmd
->cmnd
[2];
2911 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2913 scsicmd
->result
= DID_OK
<< 16 |
2914 COMMAND_COMPLETE
<< 8 |
2916 } else if (scsicmd
->cmnd
[2] == 0x80) {
2917 /* unit serial number page */
2918 arr
[3] = setinqserial(dev
, &arr
[4],
2920 arr
[1] = scsicmd
->cmnd
[2];
2921 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2924 return aac_get_container_serial(
2926 scsicmd
->result
= DID_OK
<< 16 |
2927 COMMAND_COMPLETE
<< 8 |
2929 } else if (scsicmd
->cmnd
[2] == 0x83) {
2930 /* vpd page 0x83 - Device Identification Page */
2931 char *sno
= (char *)&inq_data
;
2932 sno
[3] = setinqserial(dev
, &sno
[4],
2935 return aac_get_container_serial(
2937 scsicmd
->result
= DID_OK
<< 16 |
2938 COMMAND_COMPLETE
<< 8 |
2941 /* vpd page not implemented */
2942 scsicmd
->result
= DID_OK
<< 16 |
2943 COMMAND_COMPLETE
<< 8 |
2944 SAM_STAT_CHECK_CONDITION
;
2945 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2946 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2947 ASENCODE_NO_SENSE
, 7, 2);
2948 memcpy(scsicmd
->sense_buffer
,
2949 &dev
->fsa_dev
[cid
].sense_data
,
2951 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2952 SCSI_SENSE_BUFFERSIZE
));
2956 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2957 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 */
2958 inq_data
.inqd_len
= 31;
2959 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2960 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2962 * Set the Vendor, Product, and Revision Level
2963 * see: <vendor>.c i.e. aac.c
2965 if (cid
== host
->this_id
) {
2966 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2967 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2968 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2970 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2976 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2977 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2978 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2979 return aac_get_container_name(scsicmd
);
2981 case SERVICE_ACTION_IN_16
:
2982 if (!(dev
->raw_io_interface
) ||
2983 !(dev
->raw_io_64
) ||
2984 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2989 unsigned int alloc_len
;
2991 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2992 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2993 cp
[0] = (capacity
>> 56) & 0xff;
2994 cp
[1] = (capacity
>> 48) & 0xff;
2995 cp
[2] = (capacity
>> 40) & 0xff;
2996 cp
[3] = (capacity
>> 32) & 0xff;
2997 cp
[4] = (capacity
>> 24) & 0xff;
2998 cp
[5] = (capacity
>> 16) & 0xff;
2999 cp
[6] = (capacity
>> 8) & 0xff;
3000 cp
[7] = (capacity
>> 0) & 0xff;
3001 cp
[8] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
3002 cp
[9] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3003 cp
[10] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3004 cp
[11] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
3007 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
3008 + (scsicmd
->cmnd
[11] << 16)
3009 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
3011 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
3012 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
3013 if (alloc_len
< scsi_bufflen(scsicmd
))
3014 scsi_set_resid(scsicmd
,
3015 scsi_bufflen(scsicmd
) - alloc_len
);
3017 /* Do not cache partition table for arrays */
3018 scsicmd
->device
->removable
= 1;
3020 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3030 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
3031 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
3032 capacity
= fsa_dev_ptr
[cid
].size
- 1;
3036 cp
[0] = (capacity
>> 24) & 0xff;
3037 cp
[1] = (capacity
>> 16) & 0xff;
3038 cp
[2] = (capacity
>> 8) & 0xff;
3039 cp
[3] = (capacity
>> 0) & 0xff;
3040 cp
[4] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
3041 cp
[5] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3042 cp
[6] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3043 cp
[7] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
3044 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
3045 /* Do not cache partition table for arrays */
3046 scsicmd
->device
->removable
= 1;
3047 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3054 int mode_buf_length
= 4;
3058 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
3059 capacity
= fsa_dev_ptr
[cid
].size
- 1;
3063 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
3064 memset((char *)&mpd
, 0, sizeof(aac_modep_data
));
3066 /* Mode data length */
3067 mpd
.hd
.data_length
= sizeof(mpd
.hd
) - 1;
3068 /* Medium type - default */
3069 mpd
.hd
.med_type
= 0;
3070 /* Device-specific param,
3071 bit 8: 0/1 = write enabled/protected
3072 bit 4: 0/1 = FUA enabled */
3075 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
3076 mpd
.hd
.dev_par
= 0x10;
3077 if (scsicmd
->cmnd
[1] & 0x8)
3078 mpd
.hd
.bd_length
= 0; /* Block descriptor length */
3080 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
3081 mpd
.hd
.data_length
+= mpd
.hd
.bd_length
;
3082 mpd
.bd
.block_length
[0] =
3083 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3084 mpd
.bd
.block_length
[1] =
3085 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3086 mpd
.bd
.block_length
[2] =
3087 fsa_dev_ptr
[cid
].block_size
& 0xff;
3089 mpd
.mpc_buf
[0] = scsicmd
->cmnd
[2];
3090 if (scsicmd
->cmnd
[2] == 0x1C) {
3092 mpd
.mpc_buf
[1] = 0xa;
3093 /* Mode data length */
3094 mpd
.hd
.data_length
= 23;
3096 /* Mode data length */
3097 mpd
.hd
.data_length
= 15;
3100 if (capacity
> 0xffffff) {
3101 mpd
.bd
.block_count
[0] = 0xff;
3102 mpd
.bd
.block_count
[1] = 0xff;
3103 mpd
.bd
.block_count
[2] = 0xff;
3105 mpd
.bd
.block_count
[0] = (capacity
>> 16) & 0xff;
3106 mpd
.bd
.block_count
[1] = (capacity
>> 8) & 0xff;
3107 mpd
.bd
.block_count
[2] = capacity
& 0xff;
3110 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
3111 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
3112 mpd
.hd
.data_length
+= 3;
3115 mpd
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
3116 ? 0 : 0x04; /* WCE */
3117 mode_buf_length
= sizeof(mpd
);
3120 if (mode_buf_length
> scsicmd
->cmnd
[4])
3121 mode_buf_length
= scsicmd
->cmnd
[4];
3123 mode_buf_length
= sizeof(mpd
);
3124 scsi_sg_copy_from_buffer(scsicmd
,
3127 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3134 int mode_buf_length
= 8;
3135 aac_modep10_data mpd10
;
3137 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
3138 capacity
= fsa_dev_ptr
[cid
].size
- 1;
3142 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
3143 memset((char *)&mpd10
, 0, sizeof(aac_modep10_data
));
3144 /* Mode data length (MSB) */
3145 mpd10
.hd
.data_length
[0] = 0;
3146 /* Mode data length (LSB) */
3147 mpd10
.hd
.data_length
[1] = sizeof(mpd10
.hd
) - 1;
3148 /* Medium type - default */
3149 mpd10
.hd
.med_type
= 0;
3150 /* Device-specific param,
3151 bit 8: 0/1 = write enabled/protected
3152 bit 4: 0/1 = FUA enabled */
3153 mpd10
.hd
.dev_par
= 0;
3155 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
3156 mpd10
.hd
.dev_par
= 0x10;
3157 mpd10
.hd
.rsrvd
[0] = 0; /* reserved */
3158 mpd10
.hd
.rsrvd
[1] = 0; /* reserved */
3159 if (scsicmd
->cmnd
[1] & 0x8) {
3160 /* Block descriptor length (MSB) */
3161 mpd10
.hd
.bd_length
[0] = 0;
3162 /* Block descriptor length (LSB) */
3163 mpd10
.hd
.bd_length
[1] = 0;
3165 mpd10
.hd
.bd_length
[0] = 0;
3166 mpd10
.hd
.bd_length
[1] = sizeof(mpd10
.bd
);
3168 mpd10
.hd
.data_length
[1] += mpd10
.hd
.bd_length
[1];
3170 mpd10
.bd
.block_length
[0] =
3171 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3172 mpd10
.bd
.block_length
[1] =
3173 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3174 mpd10
.bd
.block_length
[2] =
3175 fsa_dev_ptr
[cid
].block_size
& 0xff;
3177 if (capacity
> 0xffffff) {
3178 mpd10
.bd
.block_count
[0] = 0xff;
3179 mpd10
.bd
.block_count
[1] = 0xff;
3180 mpd10
.bd
.block_count
[2] = 0xff;
3182 mpd10
.bd
.block_count
[0] =
3183 (capacity
>> 16) & 0xff;
3184 mpd10
.bd
.block_count
[1] =
3185 (capacity
>> 8) & 0xff;
3186 mpd10
.bd
.block_count
[2] =
3190 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
3191 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
3192 mpd10
.hd
.data_length
[1] += 3;
3193 mpd10
.mpc_buf
[0] = 8;
3194 mpd10
.mpc_buf
[1] = 1;
3195 mpd10
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
3196 ? 0 : 0x04; /* WCE */
3197 mode_buf_length
= sizeof(mpd10
);
3198 if (mode_buf_length
> scsicmd
->cmnd
[8])
3199 mode_buf_length
= scsicmd
->cmnd
[8];
3201 scsi_sg_copy_from_buffer(scsicmd
,
3205 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3210 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
3211 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
3212 sizeof(struct sense_data
));
3213 memset(&dev
->fsa_dev
[cid
].sense_data
, 0,
3214 sizeof(struct sense_data
));
3215 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3219 case ALLOW_MEDIUM_REMOVAL
:
3220 dprintk((KERN_DEBUG
"LOCK command.\n"));
3221 if (scsicmd
->cmnd
[4])
3222 fsa_dev_ptr
[cid
].locked
= 1;
3224 fsa_dev_ptr
[cid
].locked
= 0;
3226 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3230 * These commands are all No-Ops
3232 case TEST_UNIT_READY
:
3233 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
3234 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3235 SAM_STAT_CHECK_CONDITION
;
3236 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
3237 NOT_READY
, SENCODE_BECOMING_READY
,
3238 ASENCODE_BECOMING_READY
, 0, 0);
3239 memcpy(scsicmd
->sense_buffer
,
3240 &dev
->fsa_dev
[cid
].sense_data
,
3242 sizeof(dev
->fsa_dev
[cid
].sense_data
),
3243 SCSI_SENSE_BUFFERSIZE
));
3250 case REASSIGN_BLOCKS
:
3252 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3257 return aac_start_stop(scsicmd
);
3262 * Unhandled commands
3264 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n",
3266 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3267 SAM_STAT_CHECK_CONDITION
;
3268 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
3269 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
3270 ASENCODE_INVALID_COMMAND
, 0, 0);
3271 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
3273 sizeof(dev
->fsa_dev
[cid
].sense_data
),
3274 SCSI_SENSE_BUFFERSIZE
));
3279 scsicmd
->scsi_done(scsicmd
);
3283 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
3285 struct aac_query_disk qd
;
3286 struct fsa_dev_info
*fsa_dev_ptr
;
3288 fsa_dev_ptr
= dev
->fsa_dev
;
3291 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
3293 if (qd
.cnum
== -1) {
3294 if (qd
.id
< 0 || qd
.id
>= dev
->maximum_num_containers
)
3297 } else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1)) {
3298 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
3300 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
3302 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
3303 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
3305 else return -EINVAL
;
3307 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
3308 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
3309 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
3311 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
3316 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
3317 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
3319 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
3324 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
3326 struct aac_delete_disk dd
;
3327 struct fsa_dev_info
*fsa_dev_ptr
;
3329 fsa_dev_ptr
= dev
->fsa_dev
;
3333 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
3336 if (dd
.cnum
>= dev
->maximum_num_containers
)
3339 * Mark this container as being deleted.
3341 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
3343 * Mark the container as no longer valid
3345 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
3349 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
3351 struct aac_delete_disk dd
;
3352 struct fsa_dev_info
*fsa_dev_ptr
;
3354 fsa_dev_ptr
= dev
->fsa_dev
;
3358 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
3361 if (dd
.cnum
>= dev
->maximum_num_containers
)
3364 * If the container is locked, it can not be deleted by the API.
3366 if (fsa_dev_ptr
[dd
.cnum
].locked
)
3370 * Mark the container as no longer being valid.
3372 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
3373 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
3378 int aac_dev_ioctl(struct aac_dev
*dev
, unsigned int cmd
, void __user
*arg
)
3381 case FSACTL_QUERY_DISK
:
3382 return query_disk(dev
, arg
);
3383 case FSACTL_DELETE_DISK
:
3384 return delete_disk(dev
, arg
);
3385 case FSACTL_FORCE_DELETE_DISK
:
3386 return force_delete_disk(dev
, arg
);
3387 case FSACTL_GET_CONTAINERS
:
3388 return aac_get_containers(dev
);
3397 * @context: the context set in the fib - here it is scsi cmd
3398 * @fibptr: pointer to the fib
3400 * Handles the completion of a scsi command to a non dasd device
3404 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
3406 struct aac_srb_reply
*srbreply
;
3407 struct scsi_cmnd
*scsicmd
;
3409 scsicmd
= (struct scsi_cmnd
*) context
;
3411 if (!aac_valid_context(scsicmd
, fibptr
))
3414 BUG_ON(fibptr
== NULL
);
3416 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
3418 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
3420 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
3422 srbreply
->srb_status
= cpu_to_le32(SRB_STATUS_SUCCESS
);
3423 srbreply
->scsi_status
= cpu_to_le32(SAM_STAT_GOOD
);
3426 * Calculate resid for sg
3428 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
3429 - le32_to_cpu(srbreply
->data_xfer_length
));
3433 scsi_dma_unmap(scsicmd
);
3435 /* expose physical device if expose_physicald flag is on */
3436 if (scsicmd
->cmnd
[0] == INQUIRY
&& !(scsicmd
->cmnd
[1] & 0x01)
3437 && expose_physicals
> 0)
3438 aac_expose_phy_device(scsicmd
);
3441 * First check the fib status
3444 if (le32_to_cpu(srbreply
->status
) != ST_OK
) {
3447 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3448 le32_to_cpu(srbreply
->status
));
3449 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3450 SCSI_SENSE_BUFFERSIZE
);
3451 scsicmd
->result
= DID_ERROR
<< 16
3452 | COMMAND_COMPLETE
<< 8
3453 | SAM_STAT_CHECK_CONDITION
;
3454 memcpy(scsicmd
->sense_buffer
,
3455 srbreply
->sense_data
, len
);
3459 * Next check the srb status
3461 switch ((le32_to_cpu(srbreply
->srb_status
))&0x3f) {
3462 case SRB_STATUS_ERROR_RECOVERY
:
3463 case SRB_STATUS_PENDING
:
3464 case SRB_STATUS_SUCCESS
:
3465 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3467 case SRB_STATUS_DATA_OVERRUN
:
3468 switch (scsicmd
->cmnd
[0]) {
3477 if (le32_to_cpu(srbreply
->data_xfer_length
)
3478 < scsicmd
->underflow
)
3479 pr_warn("aacraid: SCSI CMD underflow\n");
3481 pr_warn("aacraid: SCSI CMD Data Overrun\n");
3482 scsicmd
->result
= DID_ERROR
<< 16
3483 | COMMAND_COMPLETE
<< 8;
3486 scsicmd
->result
= DID_OK
<< 16
3487 | COMMAND_COMPLETE
<< 8;
3490 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3494 case SRB_STATUS_ABORTED
:
3495 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3497 case SRB_STATUS_ABORT_FAILED
:
3499 * Not sure about this one - but assuming the
3500 * hba was trying to abort for some reason
3502 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
3504 case SRB_STATUS_PARITY_ERROR
:
3505 scsicmd
->result
= DID_PARITY
<< 16
3506 | MSG_PARITY_ERROR
<< 8;
3508 case SRB_STATUS_NO_DEVICE
:
3509 case SRB_STATUS_INVALID_PATH_ID
:
3510 case SRB_STATUS_INVALID_TARGET_ID
:
3511 case SRB_STATUS_INVALID_LUN
:
3512 case SRB_STATUS_SELECTION_TIMEOUT
:
3513 scsicmd
->result
= DID_NO_CONNECT
<< 16
3514 | COMMAND_COMPLETE
<< 8;
3517 case SRB_STATUS_COMMAND_TIMEOUT
:
3518 case SRB_STATUS_TIMEOUT
:
3519 scsicmd
->result
= DID_TIME_OUT
<< 16
3520 | COMMAND_COMPLETE
<< 8;
3523 case SRB_STATUS_BUSY
:
3524 scsicmd
->result
= DID_BUS_BUSY
<< 16
3525 | COMMAND_COMPLETE
<< 8;
3528 case SRB_STATUS_BUS_RESET
:
3529 scsicmd
->result
= DID_RESET
<< 16
3530 | COMMAND_COMPLETE
<< 8;
3533 case SRB_STATUS_MESSAGE_REJECTED
:
3534 scsicmd
->result
= DID_ERROR
<< 16
3535 | MESSAGE_REJECT
<< 8;
3537 case SRB_STATUS_REQUEST_FLUSHED
:
3538 case SRB_STATUS_ERROR
:
3539 case SRB_STATUS_INVALID_REQUEST
:
3540 case SRB_STATUS_REQUEST_SENSE_FAILED
:
3541 case SRB_STATUS_NO_HBA
:
3542 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
3543 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
3544 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
3545 case SRB_STATUS_DELAYED_RETRY
:
3546 case SRB_STATUS_BAD_FUNCTION
:
3547 case SRB_STATUS_NOT_STARTED
:
3548 case SRB_STATUS_NOT_IN_USE
:
3549 case SRB_STATUS_FORCE_ABORT
:
3550 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
3552 #ifdef AAC_DETAILED_STATUS_INFO
3553 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3554 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
3555 aac_get_status_string(
3556 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
3558 le32_to_cpu(srbreply
->scsi_status
));
3561 * When the CC bit is SET by the host in ATA pass thru CDB,
3562 * driver is supposed to return DID_OK
3564 * When the CC bit is RESET by the host, driver should
3567 if ((scsicmd
->cmnd
[0] == ATA_12
)
3568 || (scsicmd
->cmnd
[0] == ATA_16
)) {
3570 if (scsicmd
->cmnd
[2] & (0x01 << 5)) {
3571 scsicmd
->result
= DID_OK
<< 16
3572 | COMMAND_COMPLETE
<< 8;
3575 scsicmd
->result
= DID_ERROR
<< 16
3576 | COMMAND_COMPLETE
<< 8;
3580 scsicmd
->result
= DID_ERROR
<< 16
3581 | COMMAND_COMPLETE
<< 8;
3585 if (le32_to_cpu(srbreply
->scsi_status
)
3586 == SAM_STAT_CHECK_CONDITION
) {
3589 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
3590 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3591 SCSI_SENSE_BUFFERSIZE
);
3592 #ifdef AAC_DETAILED_STATUS_INFO
3593 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3594 le32_to_cpu(srbreply
->status
), len
);
3596 memcpy(scsicmd
->sense_buffer
,
3597 srbreply
->sense_data
, len
);
3601 * OR in the scsi status (already shifted up a bit)
3603 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
3605 aac_fib_complete(fibptr
);
3606 scsicmd
->scsi_done(scsicmd
);
3609 static void hba_resp_task_complete(struct aac_dev
*dev
,
3610 struct scsi_cmnd
*scsicmd
,
3611 struct aac_hba_resp
*err
) {
3613 scsicmd
->result
= err
->status
;
3614 /* set residual count */
3615 scsi_set_resid(scsicmd
, le32_to_cpu(err
->residual_count
));
3617 switch (err
->status
) {
3619 scsicmd
->result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3621 case SAM_STAT_CHECK_CONDITION
:
3625 len
= min_t(u8
, err
->sense_response_data_len
,
3626 SCSI_SENSE_BUFFERSIZE
);
3628 memcpy(scsicmd
->sense_buffer
,
3629 err
->sense_response_buf
, len
);
3630 scsicmd
->result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3634 scsicmd
->result
|= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
3636 case SAM_STAT_TASK_ABORTED
:
3637 scsicmd
->result
|= DID_ABORT
<< 16 | ABORT
<< 8;
3639 case SAM_STAT_RESERVATION_CONFLICT
:
3640 case SAM_STAT_TASK_SET_FULL
:
3642 scsicmd
->result
|= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3647 static void hba_resp_task_failure(struct aac_dev
*dev
,
3648 struct scsi_cmnd
*scsicmd
,
3649 struct aac_hba_resp
*err
)
3651 switch (err
->status
) {
3652 case HBA_RESP_STAT_HBAMODE_DISABLED
:
3656 bus
= aac_logical_to_phys(scmd_channel(scsicmd
));
3657 cid
= scmd_id(scsicmd
);
3658 if (dev
->hba_map
[bus
][cid
].devtype
== AAC_DEVTYPE_NATIVE_RAW
) {
3659 dev
->hba_map
[bus
][cid
].devtype
= AAC_DEVTYPE_ARC_RAW
;
3660 dev
->hba_map
[bus
][cid
].rmw_nexus
= 0xffffffff;
3662 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3665 case HBA_RESP_STAT_IO_ERROR
:
3666 case HBA_RESP_STAT_NO_PATH_TO_DEVICE
:
3667 scsicmd
->result
= DID_OK
<< 16 |
3668 COMMAND_COMPLETE
<< 8 | SAM_STAT_BUSY
;
3670 case HBA_RESP_STAT_IO_ABORTED
:
3671 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3673 case HBA_RESP_STAT_INVALID_DEVICE
:
3674 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3676 case HBA_RESP_STAT_UNDERRUN
:
3677 /* UNDERRUN is OK */
3678 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3680 case HBA_RESP_STAT_OVERRUN
:
3682 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3690 * @context: the context set in the fib - here it is scsi cmd
3691 * @fibptr: pointer to the fib
3693 * Handles the completion of a native HBA scsi command
3696 void aac_hba_callback(void *context
, struct fib
*fibptr
)
3698 struct aac_dev
*dev
;
3699 struct scsi_cmnd
*scsicmd
;
3701 struct aac_hba_resp
*err
=
3702 &((struct aac_native_hba
*)fibptr
->hw_fib_va
)->resp
.err
;
3704 scsicmd
= (struct scsi_cmnd
*) context
;
3706 if (!aac_valid_context(scsicmd
, fibptr
))
3709 WARN_ON(fibptr
== NULL
);
3712 if (!(fibptr
->flags
& FIB_CONTEXT_FLAG_NATIVE_HBA_TMF
))
3713 scsi_dma_unmap(scsicmd
);
3715 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
3717 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3721 switch (err
->service_response
) {
3722 case HBA_RESP_SVCRES_TASK_COMPLETE
:
3723 hba_resp_task_complete(dev
, scsicmd
, err
);
3725 case HBA_RESP_SVCRES_FAILURE
:
3726 hba_resp_task_failure(dev
, scsicmd
, err
);
3728 case HBA_RESP_SVCRES_TMF_REJECTED
:
3729 scsicmd
->result
= DID_ERROR
<< 16 | MESSAGE_REJECT
<< 8;
3731 case HBA_RESP_SVCRES_TMF_LUN_INVALID
:
3732 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3734 case HBA_RESP_SVCRES_TMF_COMPLETE
:
3735 case HBA_RESP_SVCRES_TMF_SUCCEEDED
:
3736 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3739 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3744 aac_fib_complete(fibptr
);
3746 if (fibptr
->flags
& FIB_CONTEXT_FLAG_NATIVE_HBA_TMF
)
3747 scsicmd
->SCp
.sent_command
= 1;
3749 scsicmd
->scsi_done(scsicmd
);
3755 * @scsicmd: the scsi command block
3757 * This routine will form a FIB and fill in the aac_srb from the
3758 * scsicmd passed in.
3761 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
3763 struct fib
* cmd_fibcontext
;
3764 struct aac_dev
* dev
;
3767 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3768 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3769 scsicmd
->device
->lun
> 7) {
3770 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3771 scsicmd
->scsi_done(scsicmd
);
3776 * Allocate and initialize a Fib then setup a BlockWrite command
3778 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3779 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3780 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
3783 * Check that the command queued to the controller
3785 if (status
== -EINPROGRESS
)
3788 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
3789 aac_fib_complete(cmd_fibcontext
);
3790 aac_fib_free(cmd_fibcontext
);
3798 * @scsicmd: the scsi command block
3800 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3801 * scsicmd passed in.
3803 static int aac_send_hba_fib(struct scsi_cmnd
*scsicmd
)
3805 struct fib
*cmd_fibcontext
;
3806 struct aac_dev
*dev
;
3809 dev
= shost_priv(scsicmd
->device
->host
);
3810 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3811 scsicmd
->device
->lun
> AAC_MAX_LUN
- 1) {
3812 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3813 scsicmd
->scsi_done(scsicmd
);
3818 * Allocate and initialize a Fib then setup a BlockWrite command
3820 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3821 if (!cmd_fibcontext
)
3824 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3825 status
= aac_adapter_hba(cmd_fibcontext
, scsicmd
);
3828 * Check that the command queued to the controller
3830 if (status
== -EINPROGRESS
)
3833 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3835 aac_fib_complete(cmd_fibcontext
);
3836 aac_fib_free(cmd_fibcontext
);
3842 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*psg
)
3844 unsigned long byte_count
= 0;
3846 struct scatterlist
*sg
;
3849 // Get rid of old data
3851 psg
->sg
[0].addr
= 0;
3852 psg
->sg
[0].count
= 0;
3854 nseg
= scsi_dma_map(scsicmd
);
3858 psg
->count
= cpu_to_le32(nseg
);
3860 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3861 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
3862 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
3863 byte_count
+= sg_dma_len(sg
);
3865 /* hba wants the size to be exact */
3866 if (byte_count
> scsi_bufflen(scsicmd
)) {
3867 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3868 (byte_count
- scsi_bufflen(scsicmd
));
3869 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3870 byte_count
= scsi_bufflen(scsicmd
);
3872 /* Check for command underflow */
3873 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3874 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3875 byte_count
, scsicmd
->underflow
);
3882 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
)
3884 unsigned long byte_count
= 0;
3887 struct scatterlist
*sg
;
3890 // Get rid of old data
3892 psg
->sg
[0].addr
[0] = 0;
3893 psg
->sg
[0].addr
[1] = 0;
3894 psg
->sg
[0].count
= 0;
3896 nseg
= scsi_dma_map(scsicmd
);
3900 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3901 int count
= sg_dma_len(sg
);
3902 addr
= sg_dma_address(sg
);
3903 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
3904 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
3905 psg
->sg
[i
].count
= cpu_to_le32(count
);
3906 byte_count
+= count
;
3908 psg
->count
= cpu_to_le32(nseg
);
3909 /* hba wants the size to be exact */
3910 if (byte_count
> scsi_bufflen(scsicmd
)) {
3911 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3912 (byte_count
- scsi_bufflen(scsicmd
));
3913 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3914 byte_count
= scsi_bufflen(scsicmd
);
3916 /* Check for command underflow */
3917 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3918 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3919 byte_count
, scsicmd
->underflow
);
3925 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
)
3927 unsigned long byte_count
= 0;
3929 struct scatterlist
*sg
;
3932 // Get rid of old data
3934 psg
->sg
[0].next
= 0;
3935 psg
->sg
[0].prev
= 0;
3936 psg
->sg
[0].addr
[0] = 0;
3937 psg
->sg
[0].addr
[1] = 0;
3938 psg
->sg
[0].count
= 0;
3939 psg
->sg
[0].flags
= 0;
3941 nseg
= scsi_dma_map(scsicmd
);
3945 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3946 int count
= sg_dma_len(sg
);
3947 u64 addr
= sg_dma_address(sg
);
3948 psg
->sg
[i
].next
= 0;
3949 psg
->sg
[i
].prev
= 0;
3950 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
3951 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
3952 psg
->sg
[i
].count
= cpu_to_le32(count
);
3953 psg
->sg
[i
].flags
= 0;
3954 byte_count
+= count
;
3956 psg
->count
= cpu_to_le32(nseg
);
3957 /* hba wants the size to be exact */
3958 if (byte_count
> scsi_bufflen(scsicmd
)) {
3959 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3960 (byte_count
- scsi_bufflen(scsicmd
));
3961 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3962 byte_count
= scsi_bufflen(scsicmd
);
3964 /* Check for command underflow */
3965 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3966 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3967 byte_count
, scsicmd
->underflow
);
3973 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
3974 struct aac_raw_io2
*rio2
, int sg_max
)
3976 unsigned long byte_count
= 0;
3978 struct scatterlist
*sg
;
3979 int i
, conformable
= 0;
3980 u32 min_size
= PAGE_SIZE
, cur_size
;
3982 nseg
= scsi_dma_map(scsicmd
);
3986 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3987 int count
= sg_dma_len(sg
);
3988 u64 addr
= sg_dma_address(sg
);
3990 BUG_ON(i
>= sg_max
);
3991 rio2
->sge
[i
].addrHigh
= cpu_to_le32((u32
)(addr
>>32));
3992 rio2
->sge
[i
].addrLow
= cpu_to_le32((u32
)(addr
& 0xffffffff));
3993 cur_size
= cpu_to_le32(count
);
3994 rio2
->sge
[i
].length
= cur_size
;
3995 rio2
->sge
[i
].flags
= 0;
3998 rio2
->sgeFirstSize
= cur_size
;
3999 } else if (i
== 1) {
4000 rio2
->sgeNominalSize
= cur_size
;
4001 min_size
= cur_size
;
4002 } else if ((i
+1) < nseg
&& cur_size
!= rio2
->sgeNominalSize
) {
4004 if (cur_size
< min_size
)
4005 min_size
= cur_size
;
4007 byte_count
+= count
;
4010 /* hba wants the size to be exact */
4011 if (byte_count
> scsi_bufflen(scsicmd
)) {
4012 u32 temp
= le32_to_cpu(rio2
->sge
[i
-1].length
) -
4013 (byte_count
- scsi_bufflen(scsicmd
));
4014 rio2
->sge
[i
-1].length
= cpu_to_le32(temp
);
4015 byte_count
= scsi_bufflen(scsicmd
);
4018 rio2
->sgeCnt
= cpu_to_le32(nseg
);
4019 rio2
->flags
|= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212
);
4020 /* not conformable: evaluate required sg elements */
4022 int j
, nseg_new
= nseg
, err_found
;
4023 for (i
= min_size
/ PAGE_SIZE
; i
>= 1; --i
) {
4026 for (j
= 1; j
< nseg
- 1; ++j
) {
4027 if (rio2
->sge
[j
].length
% (i
*PAGE_SIZE
)) {
4031 nseg_new
+= (rio2
->sge
[j
].length
/ (i
*PAGE_SIZE
));
4036 if (i
> 0 && nseg_new
<= sg_max
) {
4037 int ret
= aac_convert_sgraw2(rio2
, i
, nseg
, nseg_new
);
4043 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
4045 /* Check for command underflow */
4046 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
4047 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
4048 byte_count
, scsicmd
->underflow
);
4054 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
, int pages
, int nseg
, int nseg_new
)
4056 struct sge_ieee1212
*sge
;
4060 if (aac_convert_sgl
== 0)
4063 sge
= kmalloc_array(nseg_new
, sizeof(struct sge_ieee1212
), GFP_ATOMIC
);
4067 for (i
= 1, pos
= 1; i
< nseg
-1; ++i
) {
4068 for (j
= 0; j
< rio2
->sge
[i
].length
/ (pages
* PAGE_SIZE
); ++j
) {
4069 addr_low
= rio2
->sge
[i
].addrLow
+ j
* pages
* PAGE_SIZE
;
4070 sge
[pos
].addrLow
= addr_low
;
4071 sge
[pos
].addrHigh
= rio2
->sge
[i
].addrHigh
;
4072 if (addr_low
< rio2
->sge
[i
].addrLow
)
4073 sge
[pos
].addrHigh
++;
4074 sge
[pos
].length
= pages
* PAGE_SIZE
;
4079 sge
[pos
] = rio2
->sge
[nseg
-1];
4080 memcpy(&rio2
->sge
[1], &sge
[1], (nseg_new
-1)*sizeof(struct sge_ieee1212
));
4083 rio2
->sgeCnt
= cpu_to_le32(nseg_new
);
4084 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
4085 rio2
->sgeNominalSize
= pages
* PAGE_SIZE
;
4089 static long aac_build_sghba(struct scsi_cmnd
*scsicmd
,
4090 struct aac_hba_cmd_req
*hbacmd
,
4094 unsigned long byte_count
= 0;
4096 struct scatterlist
*sg
;
4099 struct aac_hba_sgl
*sge
;
4101 nseg
= scsi_dma_map(scsicmd
);
4107 if (nseg
> HBA_MAX_SG_EMBEDDED
)
4108 sge
= &hbacmd
->sge
[2];
4110 sge
= &hbacmd
->sge
[0];
4112 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
4113 int count
= sg_dma_len(sg
);
4114 u64 addr
= sg_dma_address(sg
);
4116 WARN_ON(i
>= sg_max
);
4117 sge
->addr_hi
= cpu_to_le32((u32
)(addr
>>32));
4118 sge
->addr_lo
= cpu_to_le32((u32
)(addr
& 0xffffffff));
4119 cur_size
= cpu_to_le32(count
);
4120 sge
->len
= cur_size
;
4122 byte_count
+= count
;
4127 /* hba wants the size to be exact */
4128 if (byte_count
> scsi_bufflen(scsicmd
)) {
4131 temp
= le32_to_cpu(sge
->len
) - byte_count
4132 - scsi_bufflen(scsicmd
);
4133 sge
->len
= cpu_to_le32(temp
);
4134 byte_count
= scsi_bufflen(scsicmd
);
4137 if (nseg
<= HBA_MAX_SG_EMBEDDED
) {
4138 hbacmd
->emb_data_desc_count
= cpu_to_le32(nseg
);
4139 sge
->flags
= cpu_to_le32(0x40000000);
4142 hbacmd
->sge
[0].flags
= cpu_to_le32(0x80000000);
4143 hbacmd
->emb_data_desc_count
= (u8
)cpu_to_le32(1);
4144 hbacmd
->sge
[0].addr_hi
= (u32
)cpu_to_le32(sg_address
>> 32);
4145 hbacmd
->sge
[0].addr_lo
=
4146 cpu_to_le32((u32
)(sg_address
& 0xffffffff));
4149 /* Check for command underflow */
4150 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
4151 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4152 byte_count
, scsicmd
->underflow
);
4158 #ifdef AAC_DETAILED_STATUS_INFO
4160 struct aac_srb_status_info
{
4166 static struct aac_srb_status_info srb_status_info
[] = {
4167 { SRB_STATUS_PENDING
, "Pending Status"},
4168 { SRB_STATUS_SUCCESS
, "Success"},
4169 { SRB_STATUS_ABORTED
, "Aborted Command"},
4170 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
4171 { SRB_STATUS_ERROR
, "Error Event"},
4172 { SRB_STATUS_BUSY
, "Device Busy"},
4173 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
4174 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
4175 { SRB_STATUS_NO_DEVICE
, "No Device"},
4176 { SRB_STATUS_TIMEOUT
, "Timeout"},
4177 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
4178 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
4179 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
4180 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
4181 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
4182 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
4183 { SRB_STATUS_NO_HBA
, "No HBA"},
4184 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
4185 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
4186 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
4187 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
4188 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
4189 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
4190 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
4191 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
4192 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
4193 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
4194 { SRB_STATUS_NOT_STARTED
, "Not Started"},
4195 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
4196 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
4197 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
4198 { 0xff, "Unknown Error"}
4201 char *aac_get_status_string(u32 status
)
4205 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
4206 if (srb_status_info
[i
].status
== status
)
4207 return srb_status_info
[i
].str
;
4209 return "Bad Status Code";