2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 #include <linux/slab.h>
33 #include <linux/completion.h>
34 #include <linux/blkdev.h>
35 #include <linux/uaccess.h>
36 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
37 #include <linux/module.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_cmnd.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_host.h>
46 /* values for inqd_pdt: Peripheral device type in plain English */
47 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
48 #define INQD_PDT_PROC 0x03 /* Processor device */
49 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
50 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
51 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
52 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
54 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
55 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
61 #define SENCODE_NO_SENSE 0x00
62 #define SENCODE_END_OF_DATA 0x00
63 #define SENCODE_BECOMING_READY 0x04
64 #define SENCODE_INIT_CMD_REQUIRED 0x04
65 #define SENCODE_UNRECOVERED_READ_ERROR 0x11
66 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
67 #define SENCODE_INVALID_COMMAND 0x20
68 #define SENCODE_LBA_OUT_OF_RANGE 0x21
69 #define SENCODE_INVALID_CDB_FIELD 0x24
70 #define SENCODE_LUN_NOT_SUPPORTED 0x25
71 #define SENCODE_INVALID_PARAM_FIELD 0x26
72 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
73 #define SENCODE_PARAM_VALUE_INVALID 0x26
74 #define SENCODE_RESET_OCCURRED 0x29
75 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
76 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
77 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
78 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
79 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
80 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
81 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
82 #define SENCODE_OVERLAPPED_COMMAND 0x4E
85 * Additional sense codes
88 #define ASENCODE_NO_SENSE 0x00
89 #define ASENCODE_END_OF_DATA 0x05
90 #define ASENCODE_BECOMING_READY 0x01
91 #define ASENCODE_INIT_CMD_REQUIRED 0x02
92 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
93 #define ASENCODE_INVALID_COMMAND 0x00
94 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
95 #define ASENCODE_INVALID_CDB_FIELD 0x00
96 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
97 #define ASENCODE_INVALID_PARAM_FIELD 0x00
98 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
99 #define ASENCODE_PARAM_VALUE_INVALID 0x02
100 #define ASENCODE_RESET_OCCURRED 0x00
101 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
102 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
103 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
104 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
105 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
106 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
107 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
108 #define ASENCODE_OVERLAPPED_COMMAND 0x00
110 #define AAC_STAT_GOOD (DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD)
112 #define BYTE0(x) (unsigned char)(x)
113 #define BYTE1(x) (unsigned char)((x) >> 8)
114 #define BYTE2(x) (unsigned char)((x) >> 16)
115 #define BYTE3(x) (unsigned char)((x) >> 24)
117 /* MODE_SENSE data format */
124 } __attribute__((packed
)) hd
;
130 } __attribute__((packed
)) bd
;
132 } __attribute__((packed
)) aac_modep_data
;
134 /* MODE_SENSE_10 data format */
142 } __attribute__((packed
)) hd
;
148 } __attribute__((packed
)) bd
;
150 } __attribute__((packed
)) aac_modep10_data
;
152 /*------------------------------------------------------------------------------
153 * S T R U C T S / T Y P E D E F S
154 *----------------------------------------------------------------------------*/
155 /* SCSI inquiry data */
156 struct inquiry_data
{
157 u8 inqd_pdt
; /* Peripheral qualifier | Peripheral Device Type */
158 u8 inqd_dtq
; /* RMB | Device Type Qualifier */
159 u8 inqd_ver
; /* ISO version | ECMA version | ANSI-approved version */
160 u8 inqd_rdf
; /* AENC | TrmIOP | Response data format */
161 u8 inqd_len
; /* Additional length (n-4) */
162 u8 inqd_pad1
[2];/* Reserved - must be zero */
163 u8 inqd_pad2
; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
164 u8 inqd_vid
[8]; /* Vendor ID */
165 u8 inqd_pid
[16];/* Product ID */
166 u8 inqd_prl
[4]; /* Product Revision Level */
169 /* Added for VPD 0x83 */
170 struct tvpd_id_descriptor_type_1
{
171 u8 codeset
:4; /* VPD_CODE_SET */
173 u8 identifiertype
:4; /* VPD_IDENTIFIER_TYPE */
179 u8 serialnumber
[8]; /* SN in ASCII */
183 struct tvpd_id_descriptor_type_2
{
184 u8 codeset
:4; /* VPD_CODE_SET */
186 u8 identifiertype
:4; /* VPD_IDENTIFIER_TYPE */
192 /* The serial number supposed to be 40 bits,
193 * bit we only support 32, so make the last byte zero. */
200 struct tvpd_id_descriptor_type_3
{
201 u8 codeset
: 4; /* VPD_CODE_SET */
203 u8 identifiertype
: 4; /* VPD_IDENTIFIER_TYPE */
212 u8 DeviceTypeQualifier
:3;
216 struct tvpd_id_descriptor_type_1 type1
;
217 struct tvpd_id_descriptor_type_2 type2
;
218 struct tvpd_id_descriptor_type_3 type3
;
222 * M O D U L E G L O B A L S
225 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*sgmap
);
226 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
);
227 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
);
228 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
229 struct aac_raw_io2
*rio2
, int sg_max
);
230 static long aac_build_sghba(struct scsi_cmnd
*scsicmd
,
231 struct aac_hba_cmd_req
*hbacmd
,
232 int sg_max
, u64 sg_address
);
233 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
,
234 int pages
, int nseg
, int nseg_new
);
235 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
);
236 static int aac_send_hba_fib(struct scsi_cmnd
*scsicmd
);
237 #ifdef AAC_DETAILED_STATUS_INFO
238 static char *aac_get_status_string(u32 status
);
242 * Non dasd selection is handled entirely in aachba now
245 static int nondasd
= -1;
246 static int aac_cache
= 2; /* WCE=0 to avoid performance problems */
247 static int dacmode
= -1;
250 int startup_timeout
= 180;
251 int aif_timeout
= 120;
252 int aac_sync_mode
; /* Only Sync. transfer - disabled */
253 int aac_convert_sgl
= 1; /* convert non-conformable s/g list - enabled */
255 module_param(aac_sync_mode
, int, S_IRUGO
|S_IWUSR
);
256 MODULE_PARM_DESC(aac_sync_mode
, "Force sync. transfer mode"
258 module_param(aac_convert_sgl
, int, S_IRUGO
|S_IWUSR
);
259 MODULE_PARM_DESC(aac_convert_sgl
, "Convert non-conformable s/g list"
261 module_param(nondasd
, int, S_IRUGO
|S_IWUSR
);
262 MODULE_PARM_DESC(nondasd
, "Control scanning of hba for nondasd devices."
264 module_param_named(cache
, aac_cache
, int, S_IRUGO
|S_IWUSR
);
265 MODULE_PARM_DESC(cache
, "Disable Queue Flush commands:\n"
266 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
267 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
268 "\tbit 2 - Disable only if Battery is protecting Cache");
269 module_param(dacmode
, int, S_IRUGO
|S_IWUSR
);
270 MODULE_PARM_DESC(dacmode
, "Control whether dma addressing is using 64 bit DAC."
272 module_param_named(commit
, aac_commit
, int, S_IRUGO
|S_IWUSR
);
273 MODULE_PARM_DESC(commit
, "Control whether a COMMIT_CONFIG is issued to the"
274 " adapter for foreign arrays.\n"
275 "This is typically needed in systems that do not have a BIOS."
277 module_param_named(msi
, aac_msi
, int, S_IRUGO
|S_IWUSR
);
278 MODULE_PARM_DESC(msi
, "IRQ handling."
279 " 0=PIC(default), 1=MSI, 2=MSI-X)");
280 module_param(startup_timeout
, int, S_IRUGO
|S_IWUSR
);
281 MODULE_PARM_DESC(startup_timeout
, "The duration of time in seconds to wait for"
282 " adapter to have it's kernel up and\n"
283 "running. This is typically adjusted for large systems that do not"
285 module_param(aif_timeout
, int, S_IRUGO
|S_IWUSR
);
286 MODULE_PARM_DESC(aif_timeout
, "The duration of time in seconds to wait for"
287 " applications to pick up AIFs before\n"
288 "deregistering them. This is typically adjusted for heavily burdened"
292 module_param(numacb
, int, S_IRUGO
|S_IWUSR
);
293 MODULE_PARM_DESC(numacb
, "Request a limit to the number of adapter control"
294 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
295 " to use suggestion from Firmware.");
298 module_param(acbsize
, int, S_IRUGO
|S_IWUSR
);
299 MODULE_PARM_DESC(acbsize
, "Request a specific adapter control block (FIB)"
300 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
301 " suggestion from Firmware.");
303 int update_interval
= 30 * 60;
304 module_param(update_interval
, int, S_IRUGO
|S_IWUSR
);
305 MODULE_PARM_DESC(update_interval
, "Interval in seconds between time sync"
306 " updates issued to adapter.");
308 int check_interval
= 24 * 60 * 60;
309 module_param(check_interval
, int, S_IRUGO
|S_IWUSR
);
310 MODULE_PARM_DESC(check_interval
, "Interval in seconds between adapter health"
313 int aac_check_reset
= 1;
314 module_param_named(check_reset
, aac_check_reset
, int, S_IRUGO
|S_IWUSR
);
315 MODULE_PARM_DESC(check_reset
, "If adapter fails health check, reset the"
316 " adapter. a value of -1 forces the reset to adapters programmed to"
319 int expose_physicals
= -1;
320 module_param(expose_physicals
, int, S_IRUGO
|S_IWUSR
);
321 MODULE_PARM_DESC(expose_physicals
, "Expose physical components of the arrays."
322 " -1=protect 0=off, 1=on");
324 int aac_reset_devices
;
325 module_param_named(reset_devices
, aac_reset_devices
, int, S_IRUGO
|S_IWUSR
);
326 MODULE_PARM_DESC(reset_devices
, "Force an adapter reset at initialization.");
329 module_param_named(wwn
, aac_wwn
, int, S_IRUGO
|S_IWUSR
);
330 MODULE_PARM_DESC(wwn
, "Select a WWN type for the arrays:\n"
332 "\t1 - Array Meta Data Signature (default)\n"
333 "\t2 - Adapter Serial Number");
336 static inline int aac_valid_context(struct scsi_cmnd
*scsicmd
,
337 struct fib
*fibptr
) {
338 struct scsi_device
*device
;
340 if (unlikely(!scsicmd
|| !scsicmd
->scsi_done
)) {
341 dprintk((KERN_WARNING
"aac_valid_context: scsi command corrupt\n"));
342 aac_fib_complete(fibptr
);
345 scsicmd
->SCp
.phase
= AAC_OWNER_MIDLEVEL
;
346 device
= scsicmd
->device
;
347 if (unlikely(!device
)) {
348 dprintk((KERN_WARNING
"aac_valid_context: scsi device corrupt\n"));
349 aac_fib_complete(fibptr
);
356 * aac_get_config_status - check the adapter configuration
357 * @common: adapter to query
359 * Query config status, and commit the configuration if needed.
361 int aac_get_config_status(struct aac_dev
*dev
, int commit_flag
)
366 if (!(fibptr
= aac_fib_alloc(dev
)))
369 aac_fib_init(fibptr
);
371 struct aac_get_config_status
*dinfo
;
372 dinfo
= (struct aac_get_config_status
*) fib_data(fibptr
);
374 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
375 dinfo
->type
= cpu_to_le32(CT_GET_CONFIG_STATUS
);
376 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_config_status_resp
*)NULL
)->data
));
379 status
= aac_fib_send(ContainerCommand
,
381 sizeof (struct aac_get_config_status
),
386 printk(KERN_WARNING
"aac_get_config_status: SendFIB failed.\n");
388 struct aac_get_config_status_resp
*reply
389 = (struct aac_get_config_status_resp
*) fib_data(fibptr
);
390 dprintk((KERN_WARNING
391 "aac_get_config_status: response=%d status=%d action=%d\n",
392 le32_to_cpu(reply
->response
),
393 le32_to_cpu(reply
->status
),
394 le32_to_cpu(reply
->data
.action
)));
395 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
396 (le32_to_cpu(reply
->status
) != CT_OK
) ||
397 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
398 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
402 /* Do not set XferState to zero unless receives a response from F/W */
404 aac_fib_complete(fibptr
);
406 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
408 if ((aac_commit
== 1) || commit_flag
) {
409 struct aac_commit_config
* dinfo
;
410 aac_fib_init(fibptr
);
411 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
413 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
414 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
416 status
= aac_fib_send(ContainerCommand
,
418 sizeof (struct aac_commit_config
),
422 /* Do not set XferState to zero unless
423 * receives a response from F/W */
425 aac_fib_complete(fibptr
);
426 } else if (aac_commit
== 0) {
428 "aac_get_config_status: Foreign device configurations are being ignored\n");
431 /* FIB should be freed only after getting the response from the F/W */
432 if (status
!= -ERESTARTSYS
)
433 aac_fib_free(fibptr
);
437 static void aac_expose_phy_device(struct scsi_cmnd
*scsicmd
)
440 scsi_sg_copy_to_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
441 if ((inq_data
& 0x20) && (inq_data
& 0x1f) == TYPE_DISK
) {
443 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
448 * aac_get_containers - list containers
449 * @common: adapter to probe
451 * Make a list of all containers on this controller
453 int aac_get_containers(struct aac_dev
*dev
)
455 struct fsa_dev_info
*fsa_dev_ptr
;
459 struct aac_get_container_count
*dinfo
;
460 struct aac_get_container_count_resp
*dresp
;
461 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
463 if (!(fibptr
= aac_fib_alloc(dev
)))
466 aac_fib_init(fibptr
);
467 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
468 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
469 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
471 status
= aac_fib_send(ContainerCommand
,
473 sizeof (struct aac_get_container_count
),
478 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
479 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
480 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
481 AAC_OPTION_SUPPORTED_240_VOLUMES
) {
482 maximum_num_containers
=
483 le32_to_cpu(dresp
->MaxSimpleVolumes
);
485 aac_fib_complete(fibptr
);
487 /* FIB should be freed only after getting the response from the F/W */
488 if (status
!= -ERESTARTSYS
)
489 aac_fib_free(fibptr
);
491 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
492 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
493 if (dev
->fsa_dev
== NULL
||
494 dev
->maximum_num_containers
!= maximum_num_containers
) {
496 fsa_dev_ptr
= dev
->fsa_dev
;
498 dev
->fsa_dev
= kcalloc(maximum_num_containers
,
499 sizeof(*fsa_dev_ptr
), GFP_KERNEL
);
508 dev
->maximum_num_containers
= maximum_num_containers
;
510 for (index
= 0; index
< dev
->maximum_num_containers
; index
++) {
511 dev
->fsa_dev
[index
].devname
[0] = '\0';
512 dev
->fsa_dev
[index
].valid
= 0;
514 status
= aac_probe_container(dev
, index
);
517 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
524 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
526 struct aac_get_name_resp
* get_name_reply
;
527 struct scsi_cmnd
* scsicmd
;
529 scsicmd
= (struct scsi_cmnd
*) context
;
531 if (!aac_valid_context(scsicmd
, fibptr
))
534 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
535 BUG_ON(fibptr
== NULL
);
537 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
538 /* Failure is irrelevant, using default value instead */
539 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
540 && (get_name_reply
->data
[0] != '\0')) {
541 char *sp
= get_name_reply
->data
;
542 sp
[sizeof(((struct aac_get_name_resp
*)NULL
)->data
)] = '\0';
546 struct inquiry_data inq
;
547 char d
[sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
)];
548 int count
= sizeof(d
);
551 *dp
++ = (*sp
) ? *sp
++ : ' ';
552 } while (--count
> 0);
554 scsi_sg_copy_to_buffer(scsicmd
, &inq
, sizeof(inq
));
555 memcpy(inq
.inqd_pid
, d
, sizeof(d
));
556 scsi_sg_copy_from_buffer(scsicmd
, &inq
, sizeof(inq
));
560 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
562 aac_fib_complete(fibptr
);
563 scsicmd
->scsi_done(scsicmd
);
567 * aac_get_container_name - get container name, none blocking.
569 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
)
572 struct aac_get_name
*dinfo
;
573 struct fib
* cmd_fibcontext
;
574 struct aac_dev
* dev
;
576 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
578 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
580 aac_fib_init(cmd_fibcontext
);
581 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
583 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
584 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
585 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
586 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_name_resp
*)NULL
)->data
));
588 status
= aac_fib_send(ContainerCommand
,
590 sizeof(struct aac_get_name_resp
),
593 (fib_callback
)get_container_name_callback
,
597 * Check that the command queued to the controller
599 if (status
== -EINPROGRESS
) {
600 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
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
);
636 fsa_dev_ptr
+= scmd_id(scsicmd
);
638 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
639 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
640 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
641 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
642 AAC_OPTION_VARIABLE_BLOCK_SIZE
)) {
643 dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
= 0x200;
644 fsa_dev_ptr
->block_size
= 0x200;
646 fsa_dev_ptr
->block_size
=
647 le32_to_cpu(dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
);
649 for (i
= 0; i
< 16; i
++)
650 fsa_dev_ptr
->identifier
[i
] =
651 dresp
->mnt
[0].fileinfo
.bdevinfo
653 fsa_dev_ptr
->valid
= 1;
654 /* sense_key holds the current state of the spin-up */
655 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
656 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
657 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
658 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
659 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
661 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
662 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
663 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
665 if ((fsa_dev_ptr
->valid
& 1) == 0)
666 fsa_dev_ptr
->valid
= 0;
667 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
669 aac_fib_complete(fibptr
);
670 aac_fib_free(fibptr
);
671 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
672 scsicmd
->SCp
.ptr
= NULL
;
673 (*callback
)(scsicmd
);
677 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
679 struct scsi_cmnd
* scsicmd
;
680 struct aac_mount
* dresp
;
681 struct aac_query_mount
*dinfo
;
684 dresp
= (struct aac_mount
*) fib_data(fibptr
);
685 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
686 AAC_OPTION_VARIABLE_BLOCK_SIZE
))
687 dresp
->mnt
[0].capacityhigh
= 0;
688 if ((le32_to_cpu(dresp
->status
) != ST_OK
) ||
689 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
690 _aac_probe_container2(context
, fibptr
);
693 scsicmd
= (struct scsi_cmnd
*) context
;
695 if (!aac_valid_context(scsicmd
, fibptr
))
698 aac_fib_init(fibptr
);
700 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
702 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
703 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
704 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
706 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
708 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
709 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
711 status
= aac_fib_send(ContainerCommand
,
713 sizeof(struct aac_query_mount
),
716 _aac_probe_container2
,
719 * Check that the command queued to the controller
721 if (status
== -EINPROGRESS
)
722 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
723 else if (status
< 0) {
724 /* Inherit results from VM_NameServe, if any */
725 dresp
->status
= cpu_to_le32(ST_OK
);
726 _aac_probe_container2(context
, fibptr
);
730 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
733 int status
= -ENOMEM
;
735 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
736 struct aac_query_mount
*dinfo
;
738 aac_fib_init(fibptr
);
740 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
742 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
743 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
744 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
746 dinfo
->command
= cpu_to_le32(VM_NameServe
);
748 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
749 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
750 scsicmd
->SCp
.ptr
= (char *)callback
;
752 status
= aac_fib_send(ContainerCommand
,
754 sizeof(struct aac_query_mount
),
757 _aac_probe_container1
,
760 * Check that the command queued to the controller
762 if (status
== -EINPROGRESS
) {
763 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
767 scsicmd
->SCp
.ptr
= NULL
;
768 aac_fib_complete(fibptr
);
769 aac_fib_free(fibptr
);
773 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
775 fsa_dev_ptr
+= scmd_id(scsicmd
);
776 if ((fsa_dev_ptr
->valid
& 1) == 0) {
777 fsa_dev_ptr
->valid
= 0;
778 return (*callback
)(scsicmd
);
786 * aac_probe_container - query a logical volume
787 * @dev: device to query
788 * @cid: container identifier
790 * Queries the controller about the given volume. The volume information
791 * is updated in the struct fsa_dev_info structure rather than returned.
793 static int aac_probe_container_callback1(struct scsi_cmnd
* scsicmd
)
795 scsicmd
->device
= NULL
;
799 int aac_probe_container(struct aac_dev
*dev
, int cid
)
801 struct scsi_cmnd
*scsicmd
= kmalloc(sizeof(*scsicmd
), GFP_KERNEL
);
802 struct scsi_device
*scsidev
= kmalloc(sizeof(*scsidev
), GFP_KERNEL
);
805 if (!scsicmd
|| !scsidev
) {
810 scsicmd
->list
.next
= NULL
;
811 scsicmd
->scsi_done
= (void (*)(struct scsi_cmnd
*))aac_probe_container_callback1
;
813 scsicmd
->device
= scsidev
;
814 scsidev
->sdev_state
= 0;
816 scsidev
->host
= dev
->scsi_host_ptr
;
818 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
819 while (scsicmd
->device
== scsidev
)
822 status
= scsicmd
->SCp
.Status
;
827 /* Local Structure to set SCSI inquiry data strings */
829 char vid
[8]; /* Vendor ID */
830 char pid
[16]; /* Product ID */
831 char prl
[4]; /* Product Revision Level */
835 * InqStrCopy - string merge
836 * @a: string to copy from
837 * @b: string to copy to
839 * Copy a String from one location to another
843 static void inqstrcpy(char *a
, char *b
)
846 while (*a
!= (char)0)
850 static char *container_types
[] = {
874 char * get_container_type(unsigned tindex
)
876 if (tindex
>= ARRAY_SIZE(container_types
))
877 tindex
= ARRAY_SIZE(container_types
) - 1;
878 return container_types
[tindex
];
881 /* Function: setinqstr
883 * Arguments: [1] pointer to void [1] int
885 * Purpose: Sets SCSI inquiry data strings for vendor, product
886 * and revision level. Allows strings to be set in platform dependent
887 * files instead of in OS dependent driver source.
890 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
892 struct scsi_inq
*str
;
894 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
895 memset(str
, ' ', sizeof(*str
));
897 if (dev
->supplement_adapter_info
.AdapterTypeText
[0]) {
898 char * cp
= dev
->supplement_adapter_info
.AdapterTypeText
;
900 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
901 inqstrcpy("SMC", str
->vid
);
903 c
= sizeof(str
->vid
);
904 while (*cp
&& *cp
!= ' ' && --c
)
908 inqstrcpy (dev
->supplement_adapter_info
.AdapterTypeText
,
911 while (*cp
&& *cp
!= ' ')
916 /* last six chars reserved for vol type */
918 if (strlen(cp
) > sizeof(str
->pid
)) {
919 c
= cp
[sizeof(str
->pid
)];
920 cp
[sizeof(str
->pid
)] = '\0';
922 inqstrcpy (cp
, str
->pid
);
924 cp
[sizeof(str
->pid
)] = c
;
926 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
928 inqstrcpy (mp
->vname
, str
->vid
);
929 /* last six chars reserved for vol type */
930 inqstrcpy (mp
->model
, str
->pid
);
933 if (tindex
< ARRAY_SIZE(container_types
)){
934 char *findit
= str
->pid
;
936 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
937 /* RAID is superfluous in the context of a RAID device */
938 if (memcmp(findit
-4, "RAID", 4) == 0)
939 *(findit
-= 4) = ' ';
940 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
941 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
942 inqstrcpy (container_types
[tindex
], findit
+ 1);
944 inqstrcpy ("V1.0", str
->prl
);
947 static void build_vpd83_type3(struct tvpd_page83
*vpdpage83data
,
948 struct aac_dev
*dev
, struct scsi_cmnd
*scsicmd
)
952 vpdpage83data
->type3
.codeset
= 1;
953 vpdpage83data
->type3
.identifiertype
= 3;
954 vpdpage83data
->type3
.identifierlength
= sizeof(vpdpage83data
->type3
)
957 for (container
= 0; container
< dev
->maximum_num_containers
;
960 if (scmd_id(scsicmd
) == container
) {
961 memcpy(vpdpage83data
->type3
.Identifier
,
962 dev
->fsa_dev
[container
].identifier
,
969 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
971 struct aac_get_serial_resp
* get_serial_reply
;
972 struct scsi_cmnd
* scsicmd
;
974 BUG_ON(fibptr
== NULL
);
976 scsicmd
= (struct scsi_cmnd
*) context
;
977 if (!aac_valid_context(scsicmd
, fibptr
))
980 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
981 /* Failure is irrelevant, using default value instead */
982 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
983 /*Check to see if it's for VPD 0x83 or 0x80 */
984 if (scsicmd
->cmnd
[2] == 0x83) {
985 /* vpd page 0x83 - Device Identification Page */
988 struct tvpd_page83 vpdpage83data
;
990 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
992 memset(((u8
*)&vpdpage83data
), 0,
993 sizeof(vpdpage83data
));
995 /* DIRECT_ACCESS_DEVIC */
996 vpdpage83data
.DeviceType
= 0;
997 /* DEVICE_CONNECTED */
998 vpdpage83data
.DeviceTypeQualifier
= 0;
999 /* VPD_DEVICE_IDENTIFIERS */
1000 vpdpage83data
.PageCode
= 0x83;
1001 vpdpage83data
.reserved
= 0;
1002 vpdpage83data
.PageLength
=
1003 sizeof(vpdpage83data
.type1
) +
1004 sizeof(vpdpage83data
.type2
);
1006 /* VPD 83 Type 3 is not supported for ARC */
1007 if (dev
->sa_firmware
)
1008 vpdpage83data
.PageLength
+=
1009 sizeof(vpdpage83data
.type3
);
1011 /* T10 Vendor Identifier Field Format */
1012 /* VpdcodesetAscii */
1013 vpdpage83data
.type1
.codeset
= 2;
1014 /* VpdIdentifierTypeVendorId */
1015 vpdpage83data
.type1
.identifiertype
= 1;
1016 vpdpage83data
.type1
.identifierlength
=
1017 sizeof(vpdpage83data
.type1
) - 4;
1019 /* "ADAPTEC " for adaptec */
1020 memcpy(vpdpage83data
.type1
.venid
,
1022 sizeof(vpdpage83data
.type1
.venid
));
1023 memcpy(vpdpage83data
.type1
.productid
,
1026 vpdpage83data
.type1
.productid
));
1028 /* Convert to ascii based serial number.
1029 * The LSB is the the end.
1031 for (i
= 0; i
< 8; i
++) {
1033 (u8
)((get_serial_reply
->uid
>> ((7 - i
) * 4)) & 0xF);
1035 vpdpage83data
.type1
.serialnumber
[i
] =
1038 vpdpage83data
.type1
.serialnumber
[i
] =
1043 /* VpdCodeSetBinary */
1044 vpdpage83data
.type2
.codeset
= 1;
1045 /* VpdidentifiertypeEUI64 */
1046 vpdpage83data
.type2
.identifiertype
= 2;
1047 vpdpage83data
.type2
.identifierlength
=
1048 sizeof(vpdpage83data
.type2
) - 4;
1050 vpdpage83data
.type2
.eu64id
.venid
[0] = 0xD0;
1051 vpdpage83data
.type2
.eu64id
.venid
[1] = 0;
1052 vpdpage83data
.type2
.eu64id
.venid
[2] = 0;
1054 vpdpage83data
.type2
.eu64id
.Serial
=
1055 get_serial_reply
->uid
;
1056 vpdpage83data
.type2
.eu64id
.reserved
= 0;
1059 * VpdIdentifierTypeFCPHName
1060 * VPD 0x83 Type 3 not supported for ARC
1062 if (dev
->sa_firmware
) {
1063 build_vpd83_type3(&vpdpage83data
,
1067 /* Move the inquiry data to the response buffer. */
1068 scsi_sg_copy_from_buffer(scsicmd
, &vpdpage83data
,
1069 sizeof(vpdpage83data
));
1071 /* It must be for VPD 0x80 */
1074 sp
[0] = INQD_PDT_DA
;
1075 sp
[1] = scsicmd
->cmnd
[2];
1077 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
1078 le32_to_cpu(get_serial_reply
->uid
));
1079 scsi_sg_copy_from_buffer(scsicmd
, sp
,
1084 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1086 aac_fib_complete(fibptr
);
1087 scsicmd
->scsi_done(scsicmd
);
1091 * aac_get_container_serial - get container serial, none blocking.
1093 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
1096 struct aac_get_serial
*dinfo
;
1097 struct fib
* cmd_fibcontext
;
1098 struct aac_dev
* dev
;
1100 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1102 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
1104 aac_fib_init(cmd_fibcontext
);
1105 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
1107 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
1108 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
1109 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1111 status
= aac_fib_send(ContainerCommand
,
1113 sizeof(struct aac_get_serial_resp
),
1116 (fib_callback
) get_container_serial_callback
,
1120 * Check that the command queued to the controller
1122 if (status
== -EINPROGRESS
) {
1123 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1127 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
1128 aac_fib_complete(cmd_fibcontext
);
1132 /* Function: setinqserial
1134 * Arguments: [1] pointer to void [1] int
1136 * Purpose: Sets SCSI Unit Serial number.
1137 * This is a fake. We should read a proper
1138 * serial number from the container. <SuSE>But
1139 * without docs it's quite hard to do it :-)
1140 * So this will have to do in the meantime.</SuSE>
1143 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
1146 * This breaks array migration.
1148 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
1149 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
1152 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
1153 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
1155 u8
*sense_buf
= (u8
*)sense_data
;
1156 /* Sense data valid, err code 70h */
1157 sense_buf
[0] = 0x70; /* No info field */
1158 sense_buf
[1] = 0; /* Segment number, always zero */
1160 sense_buf
[2] = sense_key
; /* Sense key */
1162 sense_buf
[12] = sense_code
; /* Additional sense code */
1163 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
1165 if (sense_key
== ILLEGAL_REQUEST
) {
1166 sense_buf
[7] = 10; /* Additional sense length */
1168 sense_buf
[15] = bit_pointer
;
1169 /* Illegal parameter is in the parameter block */
1170 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
1171 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
1172 /* Illegal parameter is in the CDB block */
1173 sense_buf
[16] = field_pointer
>> 8; /* MSB */
1174 sense_buf
[17] = field_pointer
; /* LSB */
1176 sense_buf
[7] = 6; /* Additional sense length */
1179 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1181 if (lba
& 0xffffffff00000000LL
) {
1182 int cid
= scmd_id(cmd
);
1183 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1184 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1185 SAM_STAT_CHECK_CONDITION
;
1186 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1187 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1188 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1189 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1190 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1191 SCSI_SENSE_BUFFERSIZE
));
1192 cmd
->scsi_done(cmd
);
1198 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1203 static void io_callback(void *context
, struct fib
* fibptr
);
1205 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1207 struct aac_dev
*dev
= fib
->dev
;
1208 u16 fibsize
, command
;
1212 if ((dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
1213 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) &&
1215 struct aac_raw_io2
*readcmd2
;
1216 readcmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1217 memset(readcmd2
, 0, sizeof(struct aac_raw_io2
));
1218 readcmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1219 readcmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1220 readcmd2
->byteCount
= cpu_to_le32(count
*
1221 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1222 readcmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1223 readcmd2
->flags
= cpu_to_le16(RIO2_IO_TYPE_READ
);
1224 ret
= aac_build_sgraw2(cmd
, readcmd2
,
1225 dev
->scsi_host_ptr
->sg_tablesize
);
1228 command
= ContainerRawIo2
;
1229 fibsize
= sizeof(struct aac_raw_io2
) +
1230 ((le32_to_cpu(readcmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1232 struct aac_raw_io
*readcmd
;
1233 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
1234 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1235 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1236 readcmd
->count
= cpu_to_le32(count
*
1237 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1238 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1239 readcmd
->flags
= cpu_to_le16(RIO_TYPE_READ
);
1240 readcmd
->bpTotal
= 0;
1241 readcmd
->bpComplete
= 0;
1242 ret
= aac_build_sgraw(cmd
, &readcmd
->sg
);
1245 command
= ContainerRawIo
;
1246 fibsize
= sizeof(struct aac_raw_io
) +
1247 ((le32_to_cpu(readcmd
->sg
.count
)-1) * sizeof(struct sgentryraw
));
1250 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1252 * Now send the Fib to the adapter
1254 return aac_fib_send(command
,
1259 (fib_callback
) io_callback
,
1263 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1266 struct aac_read64
*readcmd
;
1270 readcmd
= (struct aac_read64
*) fib_data(fib
);
1271 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
1272 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1273 readcmd
->sector_count
= cpu_to_le16(count
);
1274 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1278 ret
= aac_build_sg64(cmd
, &readcmd
->sg
);
1281 fibsize
= sizeof(struct aac_read64
) +
1282 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1283 sizeof (struct sgentry64
));
1284 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1285 sizeof(struct aac_fibhdr
)));
1287 * Now send the Fib to the adapter
1289 return aac_fib_send(ContainerCommand64
,
1294 (fib_callback
) io_callback
,
1298 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1301 struct aac_read
*readcmd
;
1302 struct aac_dev
*dev
= fib
->dev
;
1306 readcmd
= (struct aac_read
*) fib_data(fib
);
1307 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
1308 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1309 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1310 readcmd
->count
= cpu_to_le32(count
*
1311 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1313 ret
= aac_build_sg(cmd
, &readcmd
->sg
);
1316 fibsize
= sizeof(struct aac_read
) +
1317 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1318 sizeof (struct sgentry
));
1319 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1320 sizeof(struct aac_fibhdr
)));
1322 * Now send the Fib to the adapter
1324 return aac_fib_send(ContainerCommand
,
1329 (fib_callback
) io_callback
,
1333 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1335 struct aac_dev
*dev
= fib
->dev
;
1336 u16 fibsize
, command
;
1340 if ((dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
1341 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) &&
1343 struct aac_raw_io2
*writecmd2
;
1344 writecmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1345 memset(writecmd2
, 0, sizeof(struct aac_raw_io2
));
1346 writecmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1347 writecmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1348 writecmd2
->byteCount
= cpu_to_le32(count
*
1349 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1350 writecmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1351 writecmd2
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1352 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1353 cpu_to_le16(RIO2_IO_TYPE_WRITE
|RIO2_IO_SUREWRITE
) :
1354 cpu_to_le16(RIO2_IO_TYPE_WRITE
);
1355 ret
= aac_build_sgraw2(cmd
, writecmd2
,
1356 dev
->scsi_host_ptr
->sg_tablesize
);
1359 command
= ContainerRawIo2
;
1360 fibsize
= sizeof(struct aac_raw_io2
) +
1361 ((le32_to_cpu(writecmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1363 struct aac_raw_io
*writecmd
;
1364 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1365 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1366 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1367 writecmd
->count
= cpu_to_le32(count
*
1368 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1369 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1370 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1371 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1372 cpu_to_le16(RIO_TYPE_WRITE
|RIO_SUREWRITE
) :
1373 cpu_to_le16(RIO_TYPE_WRITE
);
1374 writecmd
->bpTotal
= 0;
1375 writecmd
->bpComplete
= 0;
1376 ret
= aac_build_sgraw(cmd
, &writecmd
->sg
);
1379 command
= ContainerRawIo
;
1380 fibsize
= sizeof(struct aac_raw_io
) +
1381 ((le32_to_cpu(writecmd
->sg
.count
)-1) * sizeof (struct sgentryraw
));
1384 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1386 * Now send the Fib to the adapter
1388 return aac_fib_send(command
,
1393 (fib_callback
) io_callback
,
1397 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1400 struct aac_write64
*writecmd
;
1404 writecmd
= (struct aac_write64
*) fib_data(fib
);
1405 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1406 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1407 writecmd
->sector_count
= cpu_to_le16(count
);
1408 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1410 writecmd
->flags
= 0;
1412 ret
= aac_build_sg64(cmd
, &writecmd
->sg
);
1415 fibsize
= sizeof(struct aac_write64
) +
1416 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1417 sizeof (struct sgentry64
));
1418 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1419 sizeof(struct aac_fibhdr
)));
1421 * Now send the Fib to the adapter
1423 return aac_fib_send(ContainerCommand64
,
1428 (fib_callback
) io_callback
,
1432 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1435 struct aac_write
*writecmd
;
1436 struct aac_dev
*dev
= fib
->dev
;
1440 writecmd
= (struct aac_write
*) fib_data(fib
);
1441 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1442 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1443 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1444 writecmd
->count
= cpu_to_le32(count
*
1445 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1446 writecmd
->sg
.count
= cpu_to_le32(1);
1447 /* ->stable is not used - it did mean which type of write */
1449 ret
= aac_build_sg(cmd
, &writecmd
->sg
);
1452 fibsize
= sizeof(struct aac_write
) +
1453 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1454 sizeof (struct sgentry
));
1455 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1456 sizeof(struct aac_fibhdr
)));
1458 * Now send the Fib to the adapter
1460 return aac_fib_send(ContainerCommand
,
1465 (fib_callback
) io_callback
,
1469 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1471 struct aac_srb
* srbcmd
;
1476 switch(cmd
->sc_data_direction
){
1480 case DMA_BIDIRECTIONAL
:
1481 flag
= SRB_DataIn
| SRB_DataOut
;
1483 case DMA_FROM_DEVICE
:
1487 default: /* shuts up some versions of gcc */
1488 flag
= SRB_NoDataXfer
;
1492 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1493 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1494 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1495 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1496 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1497 srbcmd
->flags
= cpu_to_le32(flag
);
1498 timeout
= cmd
->request
->timeout
/HZ
;
1501 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1502 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1503 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1507 static struct aac_hba_cmd_req
*aac_construct_hbacmd(struct fib
*fib
,
1508 struct scsi_cmnd
*cmd
)
1510 struct aac_hba_cmd_req
*hbacmd
;
1511 struct aac_dev
*dev
;
1515 dev
= (struct aac_dev
*)cmd
->device
->host
->hostdata
;
1517 hbacmd
= (struct aac_hba_cmd_req
*)fib
->hw_fib_va
;
1518 memset(hbacmd
, 0, 96); /* sizeof(*hbacmd) is not necessary */
1519 /* iu_type is a parameter of aac_hba_send */
1520 switch (cmd
->sc_data_direction
) {
1524 case DMA_FROM_DEVICE
:
1525 case DMA_BIDIRECTIONAL
:
1532 hbacmd
->lun
[1] = cpu_to_le32(cmd
->device
->lun
);
1534 bus
= aac_logical_to_phys(scmd_channel(cmd
));
1535 target
= scmd_id(cmd
);
1536 hbacmd
->it_nexus
= dev
->hba_map
[bus
][target
].rmw_nexus
;
1538 /* we fill in reply_qid later in aac_src_deliver_message */
1539 /* we fill in iu_type, request_id later in aac_hba_send */
1540 /* we fill in emb_data_desc_count later in aac_build_sghba */
1542 memcpy(hbacmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1543 hbacmd
->data_length
= cpu_to_le32(scsi_bufflen(cmd
));
1545 address
= (u64
)fib
->hw_error_pa
;
1546 hbacmd
->error_ptr_hi
= cpu_to_le32((u32
)(address
>> 32));
1547 hbacmd
->error_ptr_lo
= cpu_to_le32((u32
)(address
& 0xffffffff));
1548 hbacmd
->error_length
= cpu_to_le32(FW_ERROR_BUFFER_SIZE
);
1553 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1555 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1558 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1561 ret
= aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1564 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1566 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1567 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1569 * Build Scatter/Gather list
1571 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1572 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1573 sizeof (struct sgentry64
));
1574 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1575 sizeof(struct aac_fibhdr
)));
1578 * Now send the Fib to the adapter
1580 return aac_fib_send(ScsiPortCommand64
, fib
,
1581 fibsize
, FsaNormal
, 0, 1,
1582 (fib_callback
) aac_srb_callback
,
1586 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1589 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1592 ret
= aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1595 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1597 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1598 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1600 * Build Scatter/Gather list
1602 fibsize
= sizeof (struct aac_srb
) +
1603 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1604 sizeof (struct sgentry
));
1605 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1606 sizeof(struct aac_fibhdr
)));
1609 * Now send the Fib to the adapter
1611 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1612 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1615 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1617 if ((sizeof(dma_addr_t
) > 4) && fib
->dev
->needs_dac
&&
1618 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1620 return aac_scsi_32(fib
, cmd
);
1623 static int aac_adapter_hba(struct fib
*fib
, struct scsi_cmnd
*cmd
)
1625 struct aac_hba_cmd_req
*hbacmd
= aac_construct_hbacmd(fib
, cmd
);
1626 struct aac_dev
*dev
;
1629 dev
= (struct aac_dev
*)cmd
->device
->host
->hostdata
;
1631 ret
= aac_build_sghba(cmd
, hbacmd
,
1632 dev
->scsi_host_ptr
->sg_tablesize
, (u64
)fib
->hw_sgl_pa
);
1637 * Now send the HBA command to the adapter
1639 fib
->hbacmd_size
= 64 + le32_to_cpu(hbacmd
->emb_data_desc_count
) *
1640 sizeof(struct aac_hba_sgl
);
1642 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ
, fib
,
1643 (fib_callback
) aac_hba_callback
,
1647 int aac_issue_bmic_identify(struct aac_dev
*dev
, u32 bus
, u32 target
)
1650 struct aac_srb
*srbcmd
;
1651 struct sgmap64
*sg64
;
1652 struct aac_ciss_identify_pd
*identify_resp
;
1655 u16 fibsize
, datasize
;
1656 int rcode
= -ENOMEM
;
1659 fibptr
= aac_fib_alloc(dev
);
1663 fibsize
= sizeof(struct aac_srb
) -
1664 sizeof(struct sgentry
) + sizeof(struct sgentry64
);
1665 datasize
= sizeof(struct aac_ciss_identify_pd
);
1667 identify_resp
= pci_alloc_consistent(dev
->pdev
, datasize
, &addr
);
1672 vbus
= (u32
)le16_to_cpu(dev
->supplement_adapter_info
.VirtDeviceBus
);
1673 vid
= (u32
)le16_to_cpu(dev
->supplement_adapter_info
.VirtDeviceTarget
);
1675 aac_fib_init(fibptr
);
1677 srbcmd
= (struct aac_srb
*) fib_data(fibptr
);
1678 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1679 srbcmd
->channel
= cpu_to_le32(vbus
);
1680 srbcmd
->id
= cpu_to_le32(vid
);
1682 srbcmd
->flags
= cpu_to_le32(SRB_DataIn
);
1683 srbcmd
->timeout
= cpu_to_le32(10);
1684 srbcmd
->retry_limit
= 0;
1685 srbcmd
->cdb_size
= cpu_to_le32(12);
1686 srbcmd
->count
= cpu_to_le32(datasize
);
1688 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1689 srbcmd
->cdb
[0] = 0x26;
1690 srbcmd
->cdb
[2] = (u8
)((AAC_MAX_LUN
+ target
) & 0x00FF);
1691 srbcmd
->cdb
[6] = CISS_IDENTIFY_PHYSICAL_DEVICE
;
1693 sg64
= (struct sgmap64
*)&srbcmd
->sg
;
1694 sg64
->count
= cpu_to_le32(1);
1695 sg64
->sg
[0].addr
[1] = cpu_to_le32((u32
)(((addr
) >> 16) >> 16));
1696 sg64
->sg
[0].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
1697 sg64
->sg
[0].count
= cpu_to_le32(datasize
);
1699 rcode
= aac_fib_send(ScsiPortCommand64
,
1700 fibptr
, fibsize
, FsaNormal
, 1, 1, NULL
, NULL
);
1702 if (identify_resp
->current_queue_depth_limit
<= 0 ||
1703 identify_resp
->current_queue_depth_limit
> 32)
1704 dev
->hba_map
[bus
][target
].qd_limit
= 32;
1706 dev
->hba_map
[bus
][target
].qd_limit
=
1707 identify_resp
->current_queue_depth_limit
;
1709 pci_free_consistent(dev
->pdev
, datasize
, (void *)identify_resp
, addr
);
1711 aac_fib_complete(fibptr
);
1714 aac_fib_free(fibptr
);
1720 * aac_update hba_map()- update current hba map with data from FW
1721 * @dev: aac_dev structure
1722 * @phys_luns: FW information from report phys luns
1724 * Update our hba map with the information gathered from the FW
1726 void aac_update_hba_map(struct aac_dev
*dev
,
1727 struct aac_ciss_phys_luns_resp
*phys_luns
, int rescan
)
1729 /* ok and extended reporting */
1730 u32 lun_count
, nexus
;
1732 u8 expose_flag
, attribs
;
1735 lun_count
= ((phys_luns
->list_length
[0] << 24)
1736 + (phys_luns
->list_length
[1] << 16)
1737 + (phys_luns
->list_length
[2] << 8)
1738 + (phys_luns
->list_length
[3])) / 24;
1740 for (i
= 0; i
< lun_count
; ++i
) {
1742 bus
= phys_luns
->lun
[i
].level2
[1] & 0x3f;
1743 target
= phys_luns
->lun
[i
].level2
[0];
1744 expose_flag
= phys_luns
->lun
[i
].bus
>> 6;
1745 attribs
= phys_luns
->lun
[i
].node_ident
[9];
1746 nexus
= *((u32
*) &phys_luns
->lun
[i
].node_ident
[12]);
1748 if (bus
>= AAC_MAX_BUSES
|| target
>= AAC_MAX_TARGETS
)
1751 dev
->hba_map
[bus
][target
].expose
= expose_flag
;
1753 if (expose_flag
!= 0) {
1754 devtype
= AAC_DEVTYPE_RAID_MEMBER
;
1755 goto update_devtype
;
1758 if (nexus
!= 0 && (attribs
& 8)) {
1759 devtype
= AAC_DEVTYPE_NATIVE_RAW
;
1760 dev
->hba_map
[bus
][target
].rmw_nexus
=
1763 devtype
= AAC_DEVTYPE_ARC_RAW
;
1765 if (devtype
!= AAC_DEVTYPE_NATIVE_RAW
)
1766 goto update_devtype
;
1768 if (aac_issue_bmic_identify(dev
, bus
, target
) < 0)
1769 dev
->hba_map
[bus
][target
].qd_limit
= 32;
1772 if (rescan
== AAC_INIT
)
1773 dev
->hba_map
[bus
][target
].devtype
= devtype
;
1775 dev
->hba_map
[bus
][target
].new_devtype
= devtype
;
1780 * aac_report_phys_luns() Process topology change
1781 * @dev: aac_dev structure
1782 * @fibptr: fib pointer
1784 * Execute a CISS REPORT PHYS LUNS and process the results into
1785 * the current hba_map.
1787 int aac_report_phys_luns(struct aac_dev
*dev
, struct fib
*fibptr
, int rescan
)
1789 int fibsize
, datasize
;
1790 struct aac_ciss_phys_luns_resp
*phys_luns
;
1791 struct aac_srb
*srbcmd
;
1792 struct sgmap64
*sg64
;
1797 /* Thor SA Firmware -> CISS_REPORT_PHYSICAL_LUNS */
1798 fibsize
= sizeof(struct aac_srb
) - sizeof(struct sgentry
)
1799 + sizeof(struct sgentry64
);
1800 datasize
= sizeof(struct aac_ciss_phys_luns_resp
)
1801 + (AAC_MAX_TARGETS
- 1) * sizeof(struct _ciss_lun
);
1803 phys_luns
= (struct aac_ciss_phys_luns_resp
*) pci_alloc_consistent(
1804 dev
->pdev
, datasize
, &addr
);
1806 if (phys_luns
== NULL
) {
1811 vbus
= (u32
) le16_to_cpu(
1812 dev
->supplement_adapter_info
.VirtDeviceBus
);
1813 vid
= (u32
) le16_to_cpu(
1814 dev
->supplement_adapter_info
.VirtDeviceTarget
);
1816 aac_fib_init(fibptr
);
1818 srbcmd
= (struct aac_srb
*) fib_data(fibptr
);
1819 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1820 srbcmd
->channel
= cpu_to_le32(vbus
);
1821 srbcmd
->id
= cpu_to_le32(vid
);
1823 srbcmd
->flags
= cpu_to_le32(SRB_DataIn
);
1824 srbcmd
->timeout
= cpu_to_le32(10);
1825 srbcmd
->retry_limit
= 0;
1826 srbcmd
->cdb_size
= cpu_to_le32(12);
1827 srbcmd
->count
= cpu_to_le32(datasize
);
1829 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1830 srbcmd
->cdb
[0] = CISS_REPORT_PHYSICAL_LUNS
;
1831 srbcmd
->cdb
[1] = 2; /* extended reporting */
1832 srbcmd
->cdb
[8] = (u8
)(datasize
>> 8);
1833 srbcmd
->cdb
[9] = (u8
)(datasize
);
1835 sg64
= (struct sgmap64
*) &srbcmd
->sg
;
1836 sg64
->count
= cpu_to_le32(1);
1837 sg64
->sg
[0].addr
[1] = cpu_to_le32(upper_32_bits(addr
));
1838 sg64
->sg
[0].addr
[0] = cpu_to_le32(lower_32_bits(addr
));
1839 sg64
->sg
[0].count
= cpu_to_le32(datasize
);
1841 rcode
= aac_fib_send(ScsiPortCommand64
, fibptr
, fibsize
,
1842 FsaNormal
, 1, 1, NULL
, NULL
);
1845 if (rcode
>= 0 && phys_luns
->resp_flag
== 2) {
1846 /* ok and extended reporting */
1847 aac_update_hba_map(dev
, phys_luns
, rescan
);
1850 pci_free_consistent(dev
->pdev
, datasize
, (void *) phys_luns
, addr
);
1855 int aac_get_adapter_info(struct aac_dev
* dev
)
1859 u32 tmp
, bus
, target
;
1860 struct aac_adapter_info
*info
;
1861 struct aac_bus_info
*command
;
1862 struct aac_bus_info_response
*bus_info
;
1864 if (!(fibptr
= aac_fib_alloc(dev
)))
1867 aac_fib_init(fibptr
);
1868 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
1869 memset(info
,0,sizeof(*info
));
1871 rcode
= aac_fib_send(RequestAdapterInfo
,
1875 -1, 1, /* First `interrupt' command uses special wait */
1880 /* FIB should be freed only after
1881 * getting the response from the F/W */
1882 if (rcode
!= -ERESTARTSYS
) {
1883 aac_fib_complete(fibptr
);
1884 aac_fib_free(fibptr
);
1888 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
1890 dev
->supplement_adapter_info
.VirtDeviceBus
= 0xffff;
1891 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
1892 struct aac_supplement_adapter_info
* sinfo
;
1894 aac_fib_init(fibptr
);
1896 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
1898 memset(sinfo
,0,sizeof(*sinfo
));
1900 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
1909 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
1910 if (rcode
== -ERESTARTSYS
) {
1911 fibptr
= aac_fib_alloc(dev
);
1918 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
1919 for (bus
= 0; bus
< AAC_MAX_BUSES
; bus
++) {
1920 for (target
= 0; target
< AAC_MAX_TARGETS
; target
++) {
1921 dev
->hba_map
[bus
][target
].devtype
= 0;
1922 dev
->hba_map
[bus
][target
].qd_limit
= 0;
1930 aac_fib_init(fibptr
);
1932 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
1934 memset(bus_info
, 0, sizeof(*bus_info
));
1936 command
= (struct aac_bus_info
*)bus_info
;
1938 command
->Command
= cpu_to_le32(VM_Ioctl
);
1939 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
1940 command
->MethodId
= cpu_to_le32(1);
1941 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
1943 rcode
= aac_fib_send(ContainerCommand
,
1950 /* reasoned default */
1951 dev
->maximum_num_physicals
= 16;
1952 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
1953 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
1954 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
1957 if (!dev
->sync_mode
&& dev
->sa_firmware
&&
1958 dev
->supplement_adapter_info
.VirtDeviceBus
!= 0xffff) {
1959 /* Thor SA Firmware -> CISS_REPORT_PHYSICAL_LUNS */
1960 rcode
= aac_report_phys_luns(dev
, fibptr
, AAC_INIT
);
1963 if (!dev
->in_reset
) {
1965 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
1966 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
1972 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
1973 (int)sizeof(dev
->supplement_adapter_info
.BuildDate
),
1974 dev
->supplement_adapter_info
.BuildDate
);
1975 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
1976 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
1978 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1979 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
1980 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
1981 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
1983 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1984 le32_to_cpu(dev
->adapter_info
.biosbuild
));
1986 if (aac_get_serial_number(
1987 shost_to_class(dev
->scsi_host_ptr
), buffer
))
1988 printk(KERN_INFO
"%s%d: serial %s",
1989 dev
->name
, dev
->id
, buffer
);
1990 if (dev
->supplement_adapter_info
.VpdInfo
.Tsid
[0]) {
1991 printk(KERN_INFO
"%s%d: TSID %.*s\n",
1993 (int)sizeof(dev
->supplement_adapter_info
.VpdInfo
.Tsid
),
1994 dev
->supplement_adapter_info
.VpdInfo
.Tsid
);
1996 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
1997 (dev
->supplement_adapter_info
.SupportedOptions2
&
1998 AAC_OPTION_IGNORE_RESET
))) {
1999 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
2000 dev
->name
, dev
->id
);
2004 dev
->cache_protected
= 0;
2005 dev
->jbod
= ((dev
->supplement_adapter_info
.FeatureBits
&
2006 AAC_FEATURE_JBOD
) != 0);
2007 dev
->nondasd_support
= 0;
2008 dev
->raid_scsi_mode
= 0;
2009 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
2010 dev
->nondasd_support
= 1;
2013 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2014 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2015 * force nondasd support on. If we decide to allow the non-dasd flag
2016 * additional changes changes will have to be made to support
2017 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2018 * changed to support the new dev->raid_scsi_mode flag instead of
2019 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2020 * function aac_detect will have to be modified where it sets up the
2021 * max number of channels based on the aac->nondasd_support flag only.
2023 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
2024 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
2025 dev
->nondasd_support
= 1;
2026 dev
->raid_scsi_mode
= 1;
2028 if (dev
->raid_scsi_mode
!= 0)
2029 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
2030 dev
->name
, dev
->id
);
2033 dev
->nondasd_support
= (nondasd
!=0);
2034 if (dev
->nondasd_support
&& !dev
->in_reset
)
2035 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
2037 if (dma_get_required_mask(&dev
->pdev
->dev
) > DMA_BIT_MASK(32))
2039 dev
->dac_support
= 0;
2040 if ((sizeof(dma_addr_t
) > 4) && dev
->needs_dac
&&
2041 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)) {
2043 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
2044 dev
->name
, dev
->id
);
2045 dev
->dac_support
= 1;
2049 dev
->dac_support
= (dacmode
!=0);
2052 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2053 if (dev
->dac_support
&& (aac_get_driver_ident(dev
->cardtype
)->quirks
2054 & AAC_QUIRK_SCSI_32
)) {
2055 dev
->nondasd_support
= 0;
2057 expose_physicals
= 0;
2060 if(dev
->dac_support
!= 0) {
2061 if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(64)) &&
2062 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(64))) {
2064 printk(KERN_INFO
"%s%d: 64 Bit DAC enabled\n",
2065 dev
->name
, dev
->id
);
2066 } else if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(32)) &&
2067 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(32))) {
2068 printk(KERN_INFO
"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
2069 dev
->name
, dev
->id
);
2070 dev
->dac_support
= 0;
2072 printk(KERN_WARNING
"%s%d: No suitable DMA available.\n",
2073 dev
->name
, dev
->id
);
2078 * Deal with configuring for the individualized limits of each packet
2081 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
2082 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
2086 if (dev
->raw_io_interface
) {
2087 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
2090 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
2091 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
2093 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
2094 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
2095 sizeof(struct aac_fibhdr
) -
2096 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
2097 sizeof(struct sgentry
);
2098 if (dev
->dac_support
) {
2099 dev
->a_ops
.adapter_read
= aac_read_block64
;
2100 dev
->a_ops
.adapter_write
= aac_write_block64
;
2102 * 38 scatter gather elements
2104 dev
->scsi_host_ptr
->sg_tablesize
=
2105 (dev
->max_fib_size
-
2106 sizeof(struct aac_fibhdr
) -
2107 sizeof(struct aac_write64
) +
2108 sizeof(struct sgentry64
)) /
2109 sizeof(struct sgentry64
);
2111 dev
->a_ops
.adapter_read
= aac_read_block
;
2112 dev
->a_ops
.adapter_write
= aac_write_block
;
2114 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
2115 if (!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
2117 * Worst case size that could cause sg overflow when
2118 * we break up SG elements that are larger than 64KB.
2119 * Would be nice if we could tell the SCSI layer what
2120 * the maximum SG element size can be. Worst case is
2121 * (sg_tablesize-1) 4KB elements with one 64KB
2123 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2125 dev
->scsi_host_ptr
->max_sectors
=
2126 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
2129 if (!dev
->sync_mode
&& dev
->sa_firmware
&&
2130 dev
->scsi_host_ptr
->sg_tablesize
> HBA_MAX_SG_SEPARATE
)
2131 dev
->scsi_host_ptr
->sg_tablesize
= dev
->sg_tablesize
=
2132 HBA_MAX_SG_SEPARATE
;
2134 /* FIB should be freed only after getting the response from the F/W */
2135 if (rcode
!= -ERESTARTSYS
) {
2136 aac_fib_complete(fibptr
);
2137 aac_fib_free(fibptr
);
2144 static void io_callback(void *context
, struct fib
* fibptr
)
2146 struct aac_dev
*dev
;
2147 struct aac_read_reply
*readreply
;
2148 struct scsi_cmnd
*scsicmd
;
2151 scsicmd
= (struct scsi_cmnd
*) context
;
2153 if (!aac_valid_context(scsicmd
, fibptr
))
2157 cid
= scmd_id(scsicmd
);
2159 if (nblank(dprintk(x
))) {
2161 switch (scsicmd
->cmnd
[0]) {
2164 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
2165 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2169 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2170 ((u64
)scsicmd
->cmnd
[3] << 48) |
2171 ((u64
)scsicmd
->cmnd
[4] << 40) |
2172 ((u64
)scsicmd
->cmnd
[5] << 32) |
2173 ((u64
)scsicmd
->cmnd
[6] << 24) |
2174 (scsicmd
->cmnd
[7] << 16) |
2175 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2179 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2180 (scsicmd
->cmnd
[3] << 16) |
2181 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2184 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2185 (scsicmd
->cmnd
[3] << 16) |
2186 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2190 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2191 smp_processor_id(), (unsigned long long)lba
, jiffies
);
2194 BUG_ON(fibptr
== NULL
);
2196 scsi_dma_unmap(scsicmd
);
2198 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
2199 switch (le32_to_cpu(readreply
->status
)) {
2201 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2203 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
2206 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2207 SAM_STAT_CHECK_CONDITION
;
2208 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
2209 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
2210 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2211 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2212 SCSI_SENSE_BUFFERSIZE
));
2215 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2216 SAM_STAT_CHECK_CONDITION
;
2217 set_sense(&dev
->fsa_dev
[cid
].sense_data
, MEDIUM_ERROR
,
2218 SENCODE_UNRECOVERED_READ_ERROR
, ASENCODE_NO_SENSE
, 0, 0);
2219 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2220 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2221 SCSI_SENSE_BUFFERSIZE
));
2224 #ifdef AAC_DETAILED_STATUS_INFO
2225 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
2226 le32_to_cpu(readreply
->status
));
2228 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2229 SAM_STAT_CHECK_CONDITION
;
2230 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2231 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2232 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2233 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2234 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2235 SCSI_SENSE_BUFFERSIZE
));
2238 aac_fib_complete(fibptr
);
2240 scsicmd
->scsi_done(scsicmd
);
2243 static int aac_read(struct scsi_cmnd
* scsicmd
)
2248 struct aac_dev
*dev
;
2249 struct fib
* cmd_fibcontext
;
2252 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2254 * Get block address and transfer length
2256 switch (scsicmd
->cmnd
[0]) {
2258 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
2260 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
2261 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2262 count
= scsicmd
->cmnd
[4];
2268 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
2270 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2271 ((u64
)scsicmd
->cmnd
[3] << 48) |
2272 ((u64
)scsicmd
->cmnd
[4] << 40) |
2273 ((u64
)scsicmd
->cmnd
[5] << 32) |
2274 ((u64
)scsicmd
->cmnd
[6] << 24) |
2275 (scsicmd
->cmnd
[7] << 16) |
2276 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2277 count
= (scsicmd
->cmnd
[10] << 24) |
2278 (scsicmd
->cmnd
[11] << 16) |
2279 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2282 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
2284 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2285 (scsicmd
->cmnd
[3] << 16) |
2286 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2287 count
= (scsicmd
->cmnd
[6] << 24) |
2288 (scsicmd
->cmnd
[7] << 16) |
2289 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2292 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
2294 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2295 (scsicmd
->cmnd
[3] << 16) |
2296 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2297 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2301 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2302 cid
= scmd_id(scsicmd
);
2303 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2304 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2305 SAM_STAT_CHECK_CONDITION
;
2306 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2307 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2308 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2309 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2310 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2311 SCSI_SENSE_BUFFERSIZE
));
2312 scsicmd
->scsi_done(scsicmd
);
2316 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
2317 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2318 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2321 * Alocate and initialize a Fib
2323 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2325 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
2328 * Check that the command queued to the controller
2330 if (status
== -EINPROGRESS
) {
2331 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2335 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
2337 * For some reason, the Fib didn't queue, return QUEUE_FULL
2339 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2340 scsicmd
->scsi_done(scsicmd
);
2341 aac_fib_complete(cmd_fibcontext
);
2342 aac_fib_free(cmd_fibcontext
);
2346 static int aac_write(struct scsi_cmnd
* scsicmd
)
2352 struct aac_dev
*dev
;
2353 struct fib
* cmd_fibcontext
;
2356 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2358 * Get block address and transfer length
2360 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
2362 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2363 count
= scsicmd
->cmnd
[4];
2367 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
2368 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
2370 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2371 ((u64
)scsicmd
->cmnd
[3] << 48) |
2372 ((u64
)scsicmd
->cmnd
[4] << 40) |
2373 ((u64
)scsicmd
->cmnd
[5] << 32) |
2374 ((u64
)scsicmd
->cmnd
[6] << 24) |
2375 (scsicmd
->cmnd
[7] << 16) |
2376 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2377 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
2378 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2379 fua
= scsicmd
->cmnd
[1] & 0x8;
2380 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
2381 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
2383 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
2384 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2385 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
2386 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2387 fua
= scsicmd
->cmnd
[1] & 0x8;
2389 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
2390 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2391 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2392 fua
= scsicmd
->cmnd
[1] & 0x8;
2395 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2396 cid
= scmd_id(scsicmd
);
2397 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2398 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2399 SAM_STAT_CHECK_CONDITION
;
2400 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2401 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2402 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2403 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2404 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2405 SCSI_SENSE_BUFFERSIZE
));
2406 scsicmd
->scsi_done(scsicmd
);
2410 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2411 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2412 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2415 * Allocate and initialize a Fib then setup a BlockWrite command
2417 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2419 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
2422 * Check that the command queued to the controller
2424 if (status
== -EINPROGRESS
) {
2425 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2429 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
2431 * For some reason, the Fib didn't queue, return QUEUE_FULL
2433 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2434 scsicmd
->scsi_done(scsicmd
);
2436 aac_fib_complete(cmd_fibcontext
);
2437 aac_fib_free(cmd_fibcontext
);
2441 static void synchronize_callback(void *context
, struct fib
*fibptr
)
2443 struct aac_synchronize_reply
*synchronizereply
;
2444 struct scsi_cmnd
*cmd
;
2448 if (!aac_valid_context(cmd
, fibptr
))
2451 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
2452 smp_processor_id(), jiffies
));
2453 BUG_ON(fibptr
== NULL
);
2456 synchronizereply
= fib_data(fibptr
);
2457 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
2458 cmd
->result
= DID_OK
<< 16 |
2459 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2461 struct scsi_device
*sdev
= cmd
->device
;
2462 struct aac_dev
*dev
= fibptr
->dev
;
2463 u32 cid
= sdev_id(sdev
);
2465 "synchronize_callback: synchronize failed, status = %d\n",
2466 le32_to_cpu(synchronizereply
->status
));
2467 cmd
->result
= DID_OK
<< 16 |
2468 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2469 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2470 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2471 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2472 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2473 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2474 SCSI_SENSE_BUFFERSIZE
));
2477 aac_fib_complete(fibptr
);
2478 aac_fib_free(fibptr
);
2479 cmd
->scsi_done(cmd
);
2482 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
2485 struct fib
*cmd_fibcontext
;
2486 struct aac_synchronize
*synchronizecmd
;
2487 struct scsi_cmnd
*cmd
;
2488 struct scsi_device
*sdev
= scsicmd
->device
;
2490 struct aac_dev
*aac
;
2491 u64 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) |
2492 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2493 u32 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2494 unsigned long flags
;
2497 * Wait for all outstanding queued commands to complete to this
2498 * specific target (block).
2500 spin_lock_irqsave(&sdev
->list_lock
, flags
);
2501 list_for_each_entry(cmd
, &sdev
->cmd_list
, list
)
2502 if (cmd
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
2506 if (cmd
->cmnd
[0] == WRITE_6
) {
2507 cmnd_lba
= ((cmd
->cmnd
[1] & 0x1F) << 16) |
2508 (cmd
->cmnd
[2] << 8) |
2510 cmnd_count
= cmd
->cmnd
[4];
2511 if (cmnd_count
== 0)
2513 } else if (cmd
->cmnd
[0] == WRITE_16
) {
2514 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 56) |
2515 ((u64
)cmd
->cmnd
[3] << 48) |
2516 ((u64
)cmd
->cmnd
[4] << 40) |
2517 ((u64
)cmd
->cmnd
[5] << 32) |
2518 ((u64
)cmd
->cmnd
[6] << 24) |
2519 (cmd
->cmnd
[7] << 16) |
2520 (cmd
->cmnd
[8] << 8) |
2522 cmnd_count
= (cmd
->cmnd
[10] << 24) |
2523 (cmd
->cmnd
[11] << 16) |
2524 (cmd
->cmnd
[12] << 8) |
2526 } else if (cmd
->cmnd
[0] == WRITE_12
) {
2527 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2528 (cmd
->cmnd
[3] << 16) |
2529 (cmd
->cmnd
[4] << 8) |
2531 cmnd_count
= (cmd
->cmnd
[6] << 24) |
2532 (cmd
->cmnd
[7] << 16) |
2533 (cmd
->cmnd
[8] << 8) |
2535 } else if (cmd
->cmnd
[0] == WRITE_10
) {
2536 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2537 (cmd
->cmnd
[3] << 16) |
2538 (cmd
->cmnd
[4] << 8) |
2540 cmnd_count
= (cmd
->cmnd
[7] << 8) |
2544 if (((cmnd_lba
+ cmnd_count
) < lba
) ||
2545 (count
&& ((lba
+ count
) < cmnd_lba
)))
2551 spin_unlock_irqrestore(&sdev
->list_lock
, flags
);
2554 * Yield the processor (requeue for later)
2557 return SCSI_MLQUEUE_DEVICE_BUSY
;
2559 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2561 return SCSI_MLQUEUE_HOST_BUSY
;
2564 * Allocate and initialize a Fib
2566 if (!(cmd_fibcontext
= aac_fib_alloc(aac
)))
2567 return SCSI_MLQUEUE_HOST_BUSY
;
2569 aac_fib_init(cmd_fibcontext
);
2571 synchronizecmd
= fib_data(cmd_fibcontext
);
2572 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2573 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
2574 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
2575 synchronizecmd
->count
=
2576 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
2579 * Now send the Fib to the adapter
2581 status
= aac_fib_send(ContainerCommand
,
2583 sizeof(struct aac_synchronize
),
2586 (fib_callback
)synchronize_callback
,
2590 * Check that the command queued to the controller
2592 if (status
== -EINPROGRESS
) {
2593 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2598 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
2599 aac_fib_complete(cmd_fibcontext
);
2600 aac_fib_free(cmd_fibcontext
);
2601 return SCSI_MLQUEUE_HOST_BUSY
;
2604 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
2606 struct scsi_cmnd
*scsicmd
= context
;
2608 if (!aac_valid_context(scsicmd
, fibptr
))
2611 BUG_ON(fibptr
== NULL
);
2613 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2615 aac_fib_complete(fibptr
);
2616 aac_fib_free(fibptr
);
2617 scsicmd
->scsi_done(scsicmd
);
2620 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
2623 struct fib
*cmd_fibcontext
;
2624 struct aac_power_management
*pmcmd
;
2625 struct scsi_device
*sdev
= scsicmd
->device
;
2626 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2628 if (!(aac
->supplement_adapter_info
.SupportedOptions2
&
2629 AAC_OPTION_POWER_MANAGEMENT
)) {
2630 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2632 scsicmd
->scsi_done(scsicmd
);
2637 return SCSI_MLQUEUE_HOST_BUSY
;
2640 * Allocate and initialize a Fib
2642 cmd_fibcontext
= aac_fib_alloc_tag(aac
, scsicmd
);
2644 aac_fib_init(cmd_fibcontext
);
2646 pmcmd
= fib_data(cmd_fibcontext
);
2647 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2648 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
2649 /* Eject bit ignored, not relevant */
2650 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
2651 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
2652 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
2653 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
2654 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
2657 * Now send the Fib to the adapter
2659 status
= aac_fib_send(ContainerCommand
,
2661 sizeof(struct aac_power_management
),
2664 (fib_callback
)aac_start_stop_callback
,
2668 * Check that the command queued to the controller
2670 if (status
== -EINPROGRESS
) {
2671 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2675 aac_fib_complete(cmd_fibcontext
);
2676 aac_fib_free(cmd_fibcontext
);
2677 return SCSI_MLQUEUE_HOST_BUSY
;
2681 * aac_scsi_cmd() - Process SCSI command
2682 * @scsicmd: SCSI command block
2684 * Emulate a SCSI command and queue the required request for the
2688 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
2691 struct Scsi_Host
*host
= scsicmd
->device
->host
;
2692 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
2693 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
2695 if (fsa_dev_ptr
== NULL
)
2698 * If the bus, id or lun is out of range, return fail
2699 * Test does not apply to ID 16, the pseudo id for the controller
2702 cid
= scmd_id(scsicmd
);
2703 if (cid
!= host
->this_id
) {
2704 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
2705 if((cid
>= dev
->maximum_num_containers
) ||
2706 (scsicmd
->device
->lun
!= 0)) {
2707 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2712 * If the target container doesn't exist, it may have
2713 * been newly created
2715 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2716 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2718 switch (scsicmd
->cmnd
[0]) {
2719 case SERVICE_ACTION_IN_16
:
2720 if (!(dev
->raw_io_interface
) ||
2721 !(dev
->raw_io_64
) ||
2722 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2726 case TEST_UNIT_READY
:
2729 return _aac_probe_container(scsicmd
,
2730 aac_probe_container_callback2
);
2735 } else { /* check for physical non-dasd devices */
2736 bus
= aac_logical_to_phys(scmd_channel(scsicmd
));
2737 if (bus
< AAC_MAX_BUSES
&& cid
< AAC_MAX_TARGETS
&&
2738 (dev
->hba_map
[bus
][cid
].expose
2740 if (scsicmd
->cmnd
[0] == INQUIRY
) {
2741 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2746 if (bus
< AAC_MAX_BUSES
&& cid
< AAC_MAX_TARGETS
&&
2747 dev
->hba_map
[bus
][cid
].devtype
2748 == AAC_DEVTYPE_NATIVE_RAW
) {
2751 return aac_send_hba_fib(scsicmd
);
2752 } else if (dev
->nondasd_support
|| expose_physicals
||
2756 return aac_send_srb_fib(scsicmd
);
2758 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2764 * else Command for the controller itself
2766 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2767 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2769 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2770 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2771 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2772 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2773 ASENCODE_INVALID_COMMAND
, 0, 0);
2774 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2775 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2776 SCSI_SENSE_BUFFERSIZE
));
2780 switch (scsicmd
->cmnd
[0]) {
2787 return aac_read(scsicmd
);
2795 return aac_write(scsicmd
);
2797 case SYNCHRONIZE_CACHE
:
2798 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2799 scsicmd
->result
= AAC_STAT_GOOD
;
2802 /* Issue FIB to tell Firmware to flush it's cache */
2803 if ((aac_cache
& 6) != 2)
2804 return aac_synchronize(scsicmd
);
2807 struct inquiry_data inq_data
;
2809 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2810 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2812 if ((scsicmd
->cmnd
[1] & 0x1) && aac_wwn
) {
2813 char *arr
= (char *)&inq_data
;
2816 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2817 INQD_PDT_PROC
: INQD_PDT_DA
;
2818 if (scsicmd
->cmnd
[2] == 0) {
2819 /* supported vital product data pages */
2824 arr
[1] = scsicmd
->cmnd
[2];
2825 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2827 scsicmd
->result
= AAC_STAT_GOOD
;
2828 } else if (scsicmd
->cmnd
[2] == 0x80) {
2829 /* unit serial number page */
2830 arr
[3] = setinqserial(dev
, &arr
[4],
2832 arr
[1] = scsicmd
->cmnd
[2];
2833 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2836 return aac_get_container_serial(
2838 scsicmd
->result
= AAC_STAT_GOOD
;
2839 } else if (scsicmd
->cmnd
[2] == 0x83) {
2840 /* vpd page 0x83 - Device Identification Page */
2841 char *sno
= (char *)&inq_data
;
2842 sno
[3] = setinqserial(dev
, &sno
[4],
2845 return aac_get_container_serial(
2847 scsicmd
->result
= AAC_STAT_GOOD
;
2849 /* vpd page not implemented */
2850 scsicmd
->result
= DID_OK
<< 16 |
2851 COMMAND_COMPLETE
<< 8 |
2852 SAM_STAT_CHECK_CONDITION
;
2853 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2854 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2855 ASENCODE_NO_SENSE
, 7, 2);
2856 memcpy(scsicmd
->sense_buffer
,
2857 &dev
->fsa_dev
[cid
].sense_data
,
2859 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2860 SCSI_SENSE_BUFFERSIZE
));
2864 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2865 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 */
2866 inq_data
.inqd_len
= 31;
2867 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2868 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2870 * Set the Vendor, Product, and Revision Level
2871 * see: <vendor>.c i.e. aac.c
2873 if (cid
== host
->this_id
) {
2874 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2875 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2876 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2878 scsicmd
->result
= AAC_STAT_GOOD
;
2883 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2884 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2885 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2886 return aac_get_container_name(scsicmd
);
2888 case SERVICE_ACTION_IN_16
:
2889 if (!(dev
->raw_io_interface
) ||
2890 !(dev
->raw_io_64
) ||
2891 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2896 unsigned int alloc_len
;
2898 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2899 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2900 cp
[0] = (capacity
>> 56) & 0xff;
2901 cp
[1] = (capacity
>> 48) & 0xff;
2902 cp
[2] = (capacity
>> 40) & 0xff;
2903 cp
[3] = (capacity
>> 32) & 0xff;
2904 cp
[4] = (capacity
>> 24) & 0xff;
2905 cp
[5] = (capacity
>> 16) & 0xff;
2906 cp
[6] = (capacity
>> 8) & 0xff;
2907 cp
[7] = (capacity
>> 0) & 0xff;
2908 cp
[8] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2909 cp
[9] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2910 cp
[10] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2911 cp
[11] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2914 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
2915 + (scsicmd
->cmnd
[11] << 16)
2916 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
2918 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
2919 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
2920 if (alloc_len
< scsi_bufflen(scsicmd
))
2921 scsi_set_resid(scsicmd
,
2922 scsi_bufflen(scsicmd
) - alloc_len
);
2924 /* Do not cache partition table for arrays */
2925 scsicmd
->device
->removable
= 1;
2927 scsicmd
->result
= AAC_STAT_GOOD
;
2936 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
2937 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2938 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2942 cp
[0] = (capacity
>> 24) & 0xff;
2943 cp
[1] = (capacity
>> 16) & 0xff;
2944 cp
[2] = (capacity
>> 8) & 0xff;
2945 cp
[3] = (capacity
>> 0) & 0xff;
2946 cp
[4] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2947 cp
[5] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2948 cp
[6] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2949 cp
[7] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2950 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
2951 /* Do not cache partition table for arrays */
2952 scsicmd
->device
->removable
= 1;
2953 scsicmd
->result
= AAC_STAT_GOOD
;
2959 int mode_buf_length
= 4;
2963 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2964 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2968 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
2969 memset((char *)&mpd
, 0, sizeof(aac_modep_data
));
2971 /* Mode data length */
2972 mpd
.hd
.data_length
= sizeof(mpd
.hd
) - 1;
2973 /* Medium type - default */
2974 mpd
.hd
.med_type
= 0;
2975 /* Device-specific param,
2976 bit 8: 0/1 = write enabled/protected
2977 bit 4: 0/1 = FUA enabled */
2980 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2981 mpd
.hd
.dev_par
= 0x10;
2982 if (scsicmd
->cmnd
[1] & 0x8)
2983 mpd
.hd
.bd_length
= 0; /* Block descriptor length */
2985 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
2986 mpd
.hd
.data_length
+= mpd
.hd
.bd_length
;
2987 mpd
.bd
.block_length
[0] =
2988 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2989 mpd
.bd
.block_length
[1] =
2990 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2991 mpd
.bd
.block_length
[2] =
2992 fsa_dev_ptr
[cid
].block_size
& 0xff;
2994 mpd
.mpc_buf
[0] = scsicmd
->cmnd
[2];
2995 if (scsicmd
->cmnd
[2] == 0x1C) {
2997 mpd
.mpc_buf
[1] = 0xa;
2998 /* Mode data length */
2999 mpd
.hd
.data_length
= 23;
3001 /* Mode data length */
3002 mpd
.hd
.data_length
= 15;
3005 if (capacity
> 0xffffff) {
3006 mpd
.bd
.block_count
[0] = 0xff;
3007 mpd
.bd
.block_count
[1] = 0xff;
3008 mpd
.bd
.block_count
[2] = 0xff;
3010 mpd
.bd
.block_count
[0] = (capacity
>> 16) & 0xff;
3011 mpd
.bd
.block_count
[1] = (capacity
>> 8) & 0xff;
3012 mpd
.bd
.block_count
[2] = capacity
& 0xff;
3015 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
3016 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
3017 mpd
.hd
.data_length
+= 3;
3020 mpd
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
3021 ? 0 : 0x04; /* WCE */
3022 mode_buf_length
= sizeof(mpd
);
3025 if (mode_buf_length
> scsicmd
->cmnd
[4])
3026 mode_buf_length
= scsicmd
->cmnd
[4];
3028 mode_buf_length
= sizeof(mpd
);
3029 scsi_sg_copy_from_buffer(scsicmd
,
3032 scsicmd
->result
= AAC_STAT_GOOD
;
3038 int mode_buf_length
= 8;
3039 aac_modep10_data mpd10
;
3041 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
3042 capacity
= fsa_dev_ptr
[cid
].size
- 1;
3046 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
3047 memset((char *)&mpd10
, 0, sizeof(aac_modep10_data
));
3048 /* Mode data length (MSB) */
3049 mpd10
.hd
.data_length
[0] = 0;
3050 /* Mode data length (LSB) */
3051 mpd10
.hd
.data_length
[1] = sizeof(mpd10
.hd
) - 1;
3052 /* Medium type - default */
3053 mpd10
.hd
.med_type
= 0;
3054 /* Device-specific param,
3055 bit 8: 0/1 = write enabled/protected
3056 bit 4: 0/1 = FUA enabled */
3057 mpd10
.hd
.dev_par
= 0;
3059 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
3060 mpd10
.hd
.dev_par
= 0x10;
3061 mpd10
.hd
.rsrvd
[0] = 0; /* reserved */
3062 mpd10
.hd
.rsrvd
[1] = 0; /* reserved */
3063 if (scsicmd
->cmnd
[1] & 0x8) {
3064 /* Block descriptor length (MSB) */
3065 mpd10
.hd
.bd_length
[0] = 0;
3066 /* Block descriptor length (LSB) */
3067 mpd10
.hd
.bd_length
[1] = 0;
3069 mpd10
.hd
.bd_length
[0] = 0;
3070 mpd10
.hd
.bd_length
[1] = sizeof(mpd10
.bd
);
3072 mpd10
.hd
.data_length
[1] += mpd10
.hd
.bd_length
[1];
3074 mpd10
.bd
.block_length
[0] =
3075 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3076 mpd10
.bd
.block_length
[1] =
3077 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3078 mpd10
.bd
.block_length
[2] =
3079 fsa_dev_ptr
[cid
].block_size
& 0xff;
3081 if (capacity
> 0xffffff) {
3082 mpd10
.bd
.block_count
[0] = 0xff;
3083 mpd10
.bd
.block_count
[1] = 0xff;
3084 mpd10
.bd
.block_count
[2] = 0xff;
3086 mpd10
.bd
.block_count
[0] =
3087 (capacity
>> 16) & 0xff;
3088 mpd10
.bd
.block_count
[1] =
3089 (capacity
>> 8) & 0xff;
3090 mpd10
.bd
.block_count
[2] =
3094 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
3095 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
3096 mpd10
.hd
.data_length
[1] += 3;
3097 mpd10
.mpc_buf
[0] = 8;
3098 mpd10
.mpc_buf
[1] = 1;
3099 mpd10
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
3100 ? 0 : 0x04; /* WCE */
3101 mode_buf_length
= sizeof(mpd10
);
3102 if (mode_buf_length
> scsicmd
->cmnd
[8])
3103 mode_buf_length
= scsicmd
->cmnd
[8];
3105 scsi_sg_copy_from_buffer(scsicmd
,
3109 scsicmd
->result
= AAC_STAT_GOOD
;
3113 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
3114 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
3115 sizeof(struct sense_data
));
3116 memset(&dev
->fsa_dev
[cid
].sense_data
, 0,
3117 sizeof(struct sense_data
));
3118 scsicmd
->result
= AAC_STAT_GOOD
;
3121 case ALLOW_MEDIUM_REMOVAL
:
3122 dprintk((KERN_DEBUG
"LOCK command.\n"));
3123 if (scsicmd
->cmnd
[4])
3124 fsa_dev_ptr
[cid
].locked
= 1;
3126 fsa_dev_ptr
[cid
].locked
= 0;
3128 scsicmd
->result
= AAC_STAT_GOOD
;
3131 * These commands are all No-Ops
3133 case TEST_UNIT_READY
:
3134 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
3135 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3136 SAM_STAT_CHECK_CONDITION
;
3137 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
3138 NOT_READY
, SENCODE_BECOMING_READY
,
3139 ASENCODE_BECOMING_READY
, 0, 0);
3140 memcpy(scsicmd
->sense_buffer
,
3141 &dev
->fsa_dev
[cid
].sense_data
,
3143 sizeof(dev
->fsa_dev
[cid
].sense_data
),
3144 SCSI_SENSE_BUFFERSIZE
));
3150 case REASSIGN_BLOCKS
:
3152 scsicmd
->result
= AAC_STAT_GOOD
;
3156 return aac_start_stop(scsicmd
);
3161 * Unhandled commands
3163 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n",
3165 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3166 SAM_STAT_CHECK_CONDITION
;
3167 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
3168 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
3169 ASENCODE_INVALID_COMMAND
, 0, 0);
3170 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
3172 sizeof(dev
->fsa_dev
[cid
].sense_data
),
3173 SCSI_SENSE_BUFFERSIZE
));
3178 scsicmd
->scsi_done(scsicmd
);
3182 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
3184 struct aac_query_disk qd
;
3185 struct fsa_dev_info
*fsa_dev_ptr
;
3187 fsa_dev_ptr
= dev
->fsa_dev
;
3190 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
3194 else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1))
3196 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
3198 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
3200 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
3201 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
3203 else return -EINVAL
;
3205 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
3206 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
3207 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
3209 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
3214 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
3215 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
3217 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
3222 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
3224 struct aac_delete_disk dd
;
3225 struct fsa_dev_info
*fsa_dev_ptr
;
3227 fsa_dev_ptr
= dev
->fsa_dev
;
3231 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
3234 if (dd
.cnum
>= dev
->maximum_num_containers
)
3237 * Mark this container as being deleted.
3239 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
3241 * Mark the container as no longer valid
3243 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
3247 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
3249 struct aac_delete_disk dd
;
3250 struct fsa_dev_info
*fsa_dev_ptr
;
3252 fsa_dev_ptr
= dev
->fsa_dev
;
3256 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
3259 if (dd
.cnum
>= dev
->maximum_num_containers
)
3262 * If the container is locked, it can not be deleted by the API.
3264 if (fsa_dev_ptr
[dd
.cnum
].locked
)
3268 * Mark the container as no longer being valid.
3270 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
3271 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
3276 int aac_dev_ioctl(struct aac_dev
*dev
, int cmd
, void __user
*arg
)
3279 case FSACTL_QUERY_DISK
:
3280 return query_disk(dev
, arg
);
3281 case FSACTL_DELETE_DISK
:
3282 return delete_disk(dev
, arg
);
3283 case FSACTL_FORCE_DELETE_DISK
:
3284 return force_delete_disk(dev
, arg
);
3285 case FSACTL_GET_CONTAINERS
:
3286 return aac_get_containers(dev
);
3295 * @context: the context set in the fib - here it is scsi cmd
3296 * @fibptr: pointer to the fib
3298 * Handles the completion of a scsi command to a non dasd device
3302 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
3304 struct aac_dev
*dev
;
3305 struct aac_srb_reply
*srbreply
;
3306 struct scsi_cmnd
*scsicmd
;
3308 scsicmd
= (struct scsi_cmnd
*) context
;
3310 if (!aac_valid_context(scsicmd
, fibptr
))
3313 BUG_ON(fibptr
== NULL
);
3317 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
3319 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
3321 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
3323 srbreply
->srb_status
= cpu_to_le32(SRB_STATUS_SUCCESS
);
3324 srbreply
->scsi_status
= cpu_to_le32(SAM_STAT_GOOD
);
3327 * Calculate resid for sg
3329 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
3330 - le32_to_cpu(srbreply
->data_xfer_length
));
3334 scsi_dma_unmap(scsicmd
);
3336 /* expose physical device if expose_physicald flag is on */
3337 if (scsicmd
->cmnd
[0] == INQUIRY
&& !(scsicmd
->cmnd
[1] & 0x01)
3338 && expose_physicals
> 0)
3339 aac_expose_phy_device(scsicmd
);
3342 * First check the fib status
3345 if (le32_to_cpu(srbreply
->status
) != ST_OK
) {
3348 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3349 le32_to_cpu(srbreply
->status
));
3350 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3351 SCSI_SENSE_BUFFERSIZE
);
3352 scsicmd
->result
= DID_ERROR
<< 16
3353 | COMMAND_COMPLETE
<< 8
3354 | SAM_STAT_CHECK_CONDITION
;
3355 memcpy(scsicmd
->sense_buffer
,
3356 srbreply
->sense_data
, len
);
3360 * Next check the srb status
3362 switch ((le32_to_cpu(srbreply
->srb_status
))&0x3f) {
3363 case SRB_STATUS_ERROR_RECOVERY
:
3364 case SRB_STATUS_PENDING
:
3365 case SRB_STATUS_SUCCESS
:
3366 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3368 case SRB_STATUS_DATA_OVERRUN
:
3369 switch (scsicmd
->cmnd
[0]) {
3378 if (le32_to_cpu(srbreply
->data_xfer_length
)
3379 < scsicmd
->underflow
)
3380 pr_warn("aacraid: SCSI CMD underflow\n");
3382 pr_warn("aacraid: SCSI CMD Data Overrun\n");
3383 scsicmd
->result
= DID_ERROR
<< 16
3384 | COMMAND_COMPLETE
<< 8;
3387 scsicmd
->result
= DID_OK
<< 16
3388 | COMMAND_COMPLETE
<< 8;
3391 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3395 case SRB_STATUS_ABORTED
:
3396 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3398 case SRB_STATUS_ABORT_FAILED
:
3400 * Not sure about this one - but assuming the
3401 * hba was trying to abort for some reason
3403 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
3405 case SRB_STATUS_PARITY_ERROR
:
3406 scsicmd
->result
= DID_PARITY
<< 16
3407 | MSG_PARITY_ERROR
<< 8;
3409 case SRB_STATUS_NO_DEVICE
:
3410 case SRB_STATUS_INVALID_PATH_ID
:
3411 case SRB_STATUS_INVALID_TARGET_ID
:
3412 case SRB_STATUS_INVALID_LUN
:
3413 case SRB_STATUS_SELECTION_TIMEOUT
:
3414 scsicmd
->result
= DID_NO_CONNECT
<< 16
3415 | COMMAND_COMPLETE
<< 8;
3418 case SRB_STATUS_COMMAND_TIMEOUT
:
3419 case SRB_STATUS_TIMEOUT
:
3420 scsicmd
->result
= DID_TIME_OUT
<< 16
3421 | COMMAND_COMPLETE
<< 8;
3424 case SRB_STATUS_BUSY
:
3425 scsicmd
->result
= DID_BUS_BUSY
<< 16
3426 | COMMAND_COMPLETE
<< 8;
3429 case SRB_STATUS_BUS_RESET
:
3430 scsicmd
->result
= DID_RESET
<< 16
3431 | COMMAND_COMPLETE
<< 8;
3434 case SRB_STATUS_MESSAGE_REJECTED
:
3435 scsicmd
->result
= DID_ERROR
<< 16
3436 | MESSAGE_REJECT
<< 8;
3438 case SRB_STATUS_REQUEST_FLUSHED
:
3439 case SRB_STATUS_ERROR
:
3440 case SRB_STATUS_INVALID_REQUEST
:
3441 case SRB_STATUS_REQUEST_SENSE_FAILED
:
3442 case SRB_STATUS_NO_HBA
:
3443 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
3444 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
3445 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
3446 case SRB_STATUS_DELAYED_RETRY
:
3447 case SRB_STATUS_BAD_FUNCTION
:
3448 case SRB_STATUS_NOT_STARTED
:
3449 case SRB_STATUS_NOT_IN_USE
:
3450 case SRB_STATUS_FORCE_ABORT
:
3451 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
3453 #ifdef AAC_DETAILED_STATUS_INFO
3454 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3455 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
3456 aac_get_status_string(
3457 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
3459 le32_to_cpu(srbreply
->scsi_status
));
3462 * When the CC bit is SET by the host in ATA pass thru CDB,
3463 * driver is supposed to return DID_OK
3465 * When the CC bit is RESET by the host, driver should
3468 if ((scsicmd
->cmnd
[0] == ATA_12
)
3469 || (scsicmd
->cmnd
[0] == ATA_16
)) {
3471 if (scsicmd
->cmnd
[2] & (0x01 << 5)) {
3472 scsicmd
->result
= DID_OK
<< 16
3473 | COMMAND_COMPLETE
<< 8;
3476 scsicmd
->result
= DID_ERROR
<< 16
3477 | COMMAND_COMPLETE
<< 8;
3481 scsicmd
->result
= DID_ERROR
<< 16
3482 | COMMAND_COMPLETE
<< 8;
3486 if (le32_to_cpu(srbreply
->scsi_status
)
3487 == SAM_STAT_CHECK_CONDITION
) {
3490 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
3491 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3492 SCSI_SENSE_BUFFERSIZE
);
3493 #ifdef AAC_DETAILED_STATUS_INFO
3494 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3495 le32_to_cpu(srbreply
->status
), len
);
3497 memcpy(scsicmd
->sense_buffer
,
3498 srbreply
->sense_data
, len
);
3502 * OR in the scsi status (already shifted up a bit)
3504 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
3506 aac_fib_complete(fibptr
);
3507 scsicmd
->scsi_done(scsicmd
);
3510 static void hba_resp_task_complete(struct aac_dev
*dev
,
3511 struct scsi_cmnd
*scsicmd
,
3512 struct aac_hba_resp
*err
) {
3514 scsicmd
->result
= err
->status
;
3515 /* set residual count */
3516 scsi_set_resid(scsicmd
, le32_to_cpu(err
->residual_count
));
3518 switch (err
->status
) {
3520 scsicmd
->result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3522 case SAM_STAT_CHECK_CONDITION
:
3526 len
= min_t(u8
, err
->sense_response_data_len
,
3527 SCSI_SENSE_BUFFERSIZE
);
3529 memcpy(scsicmd
->sense_buffer
,
3530 err
->sense_response_buf
, len
);
3531 scsicmd
->result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3535 scsicmd
->result
|= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
3537 case SAM_STAT_TASK_ABORTED
:
3538 scsicmd
->result
|= DID_ABORT
<< 16 | ABORT
<< 8;
3540 case SAM_STAT_RESERVATION_CONFLICT
:
3541 case SAM_STAT_TASK_SET_FULL
:
3543 scsicmd
->result
|= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3548 static void hba_resp_task_failure(struct aac_dev
*dev
,
3549 struct scsi_cmnd
*scsicmd
,
3550 struct aac_hba_resp
*err
)
3552 switch (err
->status
) {
3553 case HBA_RESP_STAT_HBAMODE_DISABLED
:
3557 bus
= aac_logical_to_phys(scmd_channel(scsicmd
));
3558 cid
= scmd_id(scsicmd
);
3559 if (dev
->hba_map
[bus
][cid
].devtype
== AAC_DEVTYPE_NATIVE_RAW
) {
3560 dev
->hba_map
[bus
][cid
].devtype
= AAC_DEVTYPE_ARC_RAW
;
3561 dev
->hba_map
[bus
][cid
].rmw_nexus
= 0xffffffff;
3563 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3566 case HBA_RESP_STAT_IO_ERROR
:
3567 case HBA_RESP_STAT_NO_PATH_TO_DEVICE
:
3568 scsicmd
->result
= DID_OK
<< 16 |
3569 COMMAND_COMPLETE
<< 8 | SAM_STAT_BUSY
;
3571 case HBA_RESP_STAT_IO_ABORTED
:
3572 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3574 case HBA_RESP_STAT_INVALID_DEVICE
:
3575 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3577 case HBA_RESP_STAT_UNDERRUN
:
3578 /* UNDERRUN is OK */
3579 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3581 case HBA_RESP_STAT_OVERRUN
:
3583 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3591 * @context: the context set in the fib - here it is scsi cmd
3592 * @fibptr: pointer to the fib
3594 * Handles the completion of a native HBA scsi command
3597 void aac_hba_callback(void *context
, struct fib
*fibptr
)
3599 struct aac_dev
*dev
;
3600 struct scsi_cmnd
*scsicmd
;
3602 struct aac_hba_resp
*err
=
3603 &((struct aac_native_hba
*)fibptr
->hw_fib_va
)->resp
.err
;
3605 scsicmd
= (struct scsi_cmnd
*) context
;
3607 if (!aac_valid_context(scsicmd
, fibptr
))
3610 WARN_ON(fibptr
== NULL
);
3613 if (!(fibptr
->flags
& FIB_CONTEXT_FLAG_NATIVE_HBA_TMF
))
3614 scsi_dma_unmap(scsicmd
);
3616 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
3618 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3622 switch (err
->service_response
) {
3623 case HBA_RESP_SVCRES_TASK_COMPLETE
:
3624 hba_resp_task_complete(dev
, scsicmd
, err
);
3626 case HBA_RESP_SVCRES_FAILURE
:
3627 hba_resp_task_failure(dev
, scsicmd
, err
);
3629 case HBA_RESP_SVCRES_TMF_REJECTED
:
3630 scsicmd
->result
= DID_ERROR
<< 16 | MESSAGE_REJECT
<< 8;
3632 case HBA_RESP_SVCRES_TMF_LUN_INVALID
:
3633 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3635 case HBA_RESP_SVCRES_TMF_COMPLETE
:
3636 case HBA_RESP_SVCRES_TMF_SUCCEEDED
:
3637 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3640 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3645 aac_fib_complete(fibptr
);
3647 if (fibptr
->flags
& FIB_CONTEXT_FLAG_NATIVE_HBA_TMF
)
3648 scsicmd
->SCp
.sent_command
= 1;
3650 scsicmd
->scsi_done(scsicmd
);
3656 * @scsicmd: the scsi command block
3658 * This routine will form a FIB and fill in the aac_srb from the
3659 * scsicmd passed in.
3662 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
3664 struct fib
* cmd_fibcontext
;
3665 struct aac_dev
* dev
;
3668 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3669 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3670 scsicmd
->device
->lun
> 7) {
3671 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3672 scsicmd
->scsi_done(scsicmd
);
3677 * Allocate and initialize a Fib then setup a BlockWrite command
3679 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3681 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
3684 * Check that the command queued to the controller
3686 if (status
== -EINPROGRESS
) {
3687 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3691 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
3692 aac_fib_complete(cmd_fibcontext
);
3693 aac_fib_free(cmd_fibcontext
);
3701 * @scsicmd: the scsi command block
3703 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3704 * scsicmd passed in.
3706 static int aac_send_hba_fib(struct scsi_cmnd
*scsicmd
)
3708 struct fib
*cmd_fibcontext
;
3709 struct aac_dev
*dev
;
3712 dev
= shost_priv(scsicmd
->device
->host
);
3713 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3714 scsicmd
->device
->lun
> AAC_MAX_LUN
- 1) {
3715 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3716 scsicmd
->scsi_done(scsicmd
);
3721 * Allocate and initialize a Fib then setup a BlockWrite command
3723 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3724 if (!cmd_fibcontext
)
3727 status
= aac_adapter_hba(cmd_fibcontext
, scsicmd
);
3730 * Check that the command queued to the controller
3732 if (status
== -EINPROGRESS
) {
3733 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3737 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3739 aac_fib_complete(cmd_fibcontext
);
3740 aac_fib_free(cmd_fibcontext
);
3746 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*psg
)
3748 struct aac_dev
*dev
;
3749 unsigned long byte_count
= 0;
3752 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3753 // Get rid of old data
3755 psg
->sg
[0].addr
= 0;
3756 psg
->sg
[0].count
= 0;
3758 nseg
= scsi_dma_map(scsicmd
);
3762 struct scatterlist
*sg
;
3765 psg
->count
= cpu_to_le32(nseg
);
3767 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3768 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
3769 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
3770 byte_count
+= sg_dma_len(sg
);
3772 /* hba wants the size to be exact */
3773 if (byte_count
> scsi_bufflen(scsicmd
)) {
3774 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3775 (byte_count
- scsi_bufflen(scsicmd
));
3776 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3777 byte_count
= scsi_bufflen(scsicmd
);
3779 /* Check for command underflow */
3780 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3781 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3782 byte_count
, scsicmd
->underflow
);
3789 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
)
3791 struct aac_dev
*dev
;
3792 unsigned long byte_count
= 0;
3796 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3797 // Get rid of old data
3799 psg
->sg
[0].addr
[0] = 0;
3800 psg
->sg
[0].addr
[1] = 0;
3801 psg
->sg
[0].count
= 0;
3803 nseg
= scsi_dma_map(scsicmd
);
3807 struct scatterlist
*sg
;
3810 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3811 int count
= sg_dma_len(sg
);
3812 addr
= sg_dma_address(sg
);
3813 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
3814 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
3815 psg
->sg
[i
].count
= cpu_to_le32(count
);
3816 byte_count
+= count
;
3818 psg
->count
= cpu_to_le32(nseg
);
3819 /* hba wants the size to be exact */
3820 if (byte_count
> scsi_bufflen(scsicmd
)) {
3821 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3822 (byte_count
- scsi_bufflen(scsicmd
));
3823 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3824 byte_count
= scsi_bufflen(scsicmd
);
3826 /* Check for command underflow */
3827 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3828 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3829 byte_count
, scsicmd
->underflow
);
3835 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
)
3837 unsigned long byte_count
= 0;
3840 // Get rid of old data
3842 psg
->sg
[0].next
= 0;
3843 psg
->sg
[0].prev
= 0;
3844 psg
->sg
[0].addr
[0] = 0;
3845 psg
->sg
[0].addr
[1] = 0;
3846 psg
->sg
[0].count
= 0;
3847 psg
->sg
[0].flags
= 0;
3849 nseg
= scsi_dma_map(scsicmd
);
3853 struct scatterlist
*sg
;
3856 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3857 int count
= sg_dma_len(sg
);
3858 u64 addr
= sg_dma_address(sg
);
3859 psg
->sg
[i
].next
= 0;
3860 psg
->sg
[i
].prev
= 0;
3861 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
3862 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
3863 psg
->sg
[i
].count
= cpu_to_le32(count
);
3864 psg
->sg
[i
].flags
= 0;
3865 byte_count
+= count
;
3867 psg
->count
= cpu_to_le32(nseg
);
3868 /* hba wants the size to be exact */
3869 if (byte_count
> scsi_bufflen(scsicmd
)) {
3870 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3871 (byte_count
- scsi_bufflen(scsicmd
));
3872 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3873 byte_count
= scsi_bufflen(scsicmd
);
3875 /* Check for command underflow */
3876 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3877 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3878 byte_count
, scsicmd
->underflow
);
3884 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
3885 struct aac_raw_io2
*rio2
, int sg_max
)
3887 unsigned long byte_count
= 0;
3890 nseg
= scsi_dma_map(scsicmd
);
3894 struct scatterlist
*sg
;
3895 int i
, conformable
= 0;
3896 u32 min_size
= PAGE_SIZE
, cur_size
;
3898 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3899 int count
= sg_dma_len(sg
);
3900 u64 addr
= sg_dma_address(sg
);
3902 BUG_ON(i
>= sg_max
);
3903 rio2
->sge
[i
].addrHigh
= cpu_to_le32((u32
)(addr
>>32));
3904 rio2
->sge
[i
].addrLow
= cpu_to_le32((u32
)(addr
& 0xffffffff));
3905 cur_size
= cpu_to_le32(count
);
3906 rio2
->sge
[i
].length
= cur_size
;
3907 rio2
->sge
[i
].flags
= 0;
3910 rio2
->sgeFirstSize
= cur_size
;
3911 } else if (i
== 1) {
3912 rio2
->sgeNominalSize
= cur_size
;
3913 min_size
= cur_size
;
3914 } else if ((i
+1) < nseg
&& cur_size
!= rio2
->sgeNominalSize
) {
3916 if (cur_size
< min_size
)
3917 min_size
= cur_size
;
3919 byte_count
+= count
;
3922 /* hba wants the size to be exact */
3923 if (byte_count
> scsi_bufflen(scsicmd
)) {
3924 u32 temp
= le32_to_cpu(rio2
->sge
[i
-1].length
) -
3925 (byte_count
- scsi_bufflen(scsicmd
));
3926 rio2
->sge
[i
-1].length
= cpu_to_le32(temp
);
3927 byte_count
= scsi_bufflen(scsicmd
);
3930 rio2
->sgeCnt
= cpu_to_le32(nseg
);
3931 rio2
->flags
|= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212
);
3932 /* not conformable: evaluate required sg elements */
3934 int j
, nseg_new
= nseg
, err_found
;
3935 for (i
= min_size
/ PAGE_SIZE
; i
>= 1; --i
) {
3938 for (j
= 1; j
< nseg
- 1; ++j
) {
3939 if (rio2
->sge
[j
].length
% (i
*PAGE_SIZE
)) {
3943 nseg_new
+= (rio2
->sge
[j
].length
/ (i
*PAGE_SIZE
));
3948 if (i
> 0 && nseg_new
<= sg_max
)
3949 aac_convert_sgraw2(rio2
, i
, nseg
, nseg_new
);
3951 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3953 /* Check for command underflow */
3954 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3955 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3956 byte_count
, scsicmd
->underflow
);
3963 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
, int pages
, int nseg
, int nseg_new
)
3965 struct sge_ieee1212
*sge
;
3969 if (aac_convert_sgl
== 0)
3972 sge
= kmalloc(nseg_new
* sizeof(struct sge_ieee1212
), GFP_ATOMIC
);
3976 for (i
= 1, pos
= 1; i
< nseg
-1; ++i
) {
3977 for (j
= 0; j
< rio2
->sge
[i
].length
/ (pages
* PAGE_SIZE
); ++j
) {
3978 addr_low
= rio2
->sge
[i
].addrLow
+ j
* pages
* PAGE_SIZE
;
3979 sge
[pos
].addrLow
= addr_low
;
3980 sge
[pos
].addrHigh
= rio2
->sge
[i
].addrHigh
;
3981 if (addr_low
< rio2
->sge
[i
].addrLow
)
3982 sge
[pos
].addrHigh
++;
3983 sge
[pos
].length
= pages
* PAGE_SIZE
;
3988 sge
[pos
] = rio2
->sge
[nseg
-1];
3989 memcpy(&rio2
->sge
[1], &sge
[1], (nseg_new
-1)*sizeof(struct sge_ieee1212
));
3992 rio2
->sgeCnt
= cpu_to_le32(nseg_new
);
3993 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3994 rio2
->sgeNominalSize
= pages
* PAGE_SIZE
;
3998 static long aac_build_sghba(struct scsi_cmnd
*scsicmd
,
3999 struct aac_hba_cmd_req
*hbacmd
,
4003 unsigned long byte_count
= 0;
4005 struct scatterlist
*sg
;
4008 struct aac_hba_sgl
*sge
;
4012 nseg
= scsi_dma_map(scsicmd
);
4018 if (nseg
> HBA_MAX_SG_EMBEDDED
)
4019 sge
= &hbacmd
->sge
[2];
4021 sge
= &hbacmd
->sge
[0];
4023 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
4024 int count
= sg_dma_len(sg
);
4025 u64 addr
= sg_dma_address(sg
);
4027 WARN_ON(i
>= sg_max
);
4028 sge
->addr_hi
= cpu_to_le32((u32
)(addr
>>32));
4029 sge
->addr_lo
= cpu_to_le32((u32
)(addr
& 0xffffffff));
4030 cur_size
= cpu_to_le32(count
);
4031 sge
->len
= cur_size
;
4033 byte_count
+= count
;
4038 /* hba wants the size to be exact */
4039 if (byte_count
> scsi_bufflen(scsicmd
)) {
4042 temp
= le32_to_cpu(sge
->len
) - byte_count
4043 - scsi_bufflen(scsicmd
);
4044 sge
->len
= cpu_to_le32(temp
);
4045 byte_count
= scsi_bufflen(scsicmd
);
4048 if (nseg
<= HBA_MAX_SG_EMBEDDED
) {
4049 hbacmd
->emb_data_desc_count
= cpu_to_le32(nseg
);
4050 sge
->flags
= cpu_to_le32(0x40000000);
4053 hbacmd
->sge
[0].flags
= cpu_to_le32(0x80000000);
4054 hbacmd
->emb_data_desc_count
= (u8
)cpu_to_le32(1);
4055 hbacmd
->sge
[0].addr_hi
= (u32
)cpu_to_le32(sg_address
>> 32);
4056 hbacmd
->sge
[0].addr_lo
=
4057 cpu_to_le32((u32
)(sg_address
& 0xffffffff));
4060 /* Check for command underflow */
4061 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
4062 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4063 byte_count
, scsicmd
->underflow
);
4069 #ifdef AAC_DETAILED_STATUS_INFO
4071 struct aac_srb_status_info
{
4077 static struct aac_srb_status_info srb_status_info
[] = {
4078 { SRB_STATUS_PENDING
, "Pending Status"},
4079 { SRB_STATUS_SUCCESS
, "Success"},
4080 { SRB_STATUS_ABORTED
, "Aborted Command"},
4081 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
4082 { SRB_STATUS_ERROR
, "Error Event"},
4083 { SRB_STATUS_BUSY
, "Device Busy"},
4084 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
4085 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
4086 { SRB_STATUS_NO_DEVICE
, "No Device"},
4087 { SRB_STATUS_TIMEOUT
, "Timeout"},
4088 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
4089 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
4090 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
4091 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
4092 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
4093 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
4094 { SRB_STATUS_NO_HBA
, "No HBA"},
4095 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
4096 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
4097 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
4098 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
4099 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
4100 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
4101 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
4102 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
4103 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
4104 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
4105 { SRB_STATUS_NOT_STARTED
, "Not Started"},
4106 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
4107 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
4108 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
4109 { 0xff, "Unknown Error"}
4112 char *aac_get_status_string(u32 status
)
4116 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
4117 if (srb_status_info
[i
].status
== status
)
4118 return srb_status_info
[i
].str
;
4120 return "Bad Status Code";