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-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 * Abstract: Contains Interfaces to manage IOs.
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
37 #include <linux/spinlock.h>
38 #include <linux/slab.h>
39 #include <linux/completion.h>
40 #include <linux/blkdev.h>
41 #include <linux/uaccess.h>
42 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
43 #include <linux/module.h>
45 #include <scsi/scsi.h>
46 #include <scsi/scsi_cmnd.h>
47 #include <scsi/scsi_device.h>
48 #include <scsi/scsi_host.h>
52 /* values for inqd_pdt: Peripheral device type in plain English */
53 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
54 #define INQD_PDT_PROC 0x03 /* Processor device */
55 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
56 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
57 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
58 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
60 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
61 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
67 #define SENCODE_NO_SENSE 0x00
68 #define SENCODE_END_OF_DATA 0x00
69 #define SENCODE_BECOMING_READY 0x04
70 #define SENCODE_INIT_CMD_REQUIRED 0x04
71 #define SENCODE_UNRECOVERED_READ_ERROR 0x11
72 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
73 #define SENCODE_INVALID_COMMAND 0x20
74 #define SENCODE_LBA_OUT_OF_RANGE 0x21
75 #define SENCODE_INVALID_CDB_FIELD 0x24
76 #define SENCODE_LUN_NOT_SUPPORTED 0x25
77 #define SENCODE_INVALID_PARAM_FIELD 0x26
78 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
79 #define SENCODE_PARAM_VALUE_INVALID 0x26
80 #define SENCODE_RESET_OCCURRED 0x29
81 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
82 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
83 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
84 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
85 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
86 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
87 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
88 #define SENCODE_OVERLAPPED_COMMAND 0x4E
91 * Additional sense codes
94 #define ASENCODE_NO_SENSE 0x00
95 #define ASENCODE_END_OF_DATA 0x05
96 #define ASENCODE_BECOMING_READY 0x01
97 #define ASENCODE_INIT_CMD_REQUIRED 0x02
98 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
99 #define ASENCODE_INVALID_COMMAND 0x00
100 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
101 #define ASENCODE_INVALID_CDB_FIELD 0x00
102 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
103 #define ASENCODE_INVALID_PARAM_FIELD 0x00
104 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
105 #define ASENCODE_PARAM_VALUE_INVALID 0x02
106 #define ASENCODE_RESET_OCCURRED 0x00
107 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
108 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
109 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
110 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
111 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
112 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
113 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
114 #define ASENCODE_OVERLAPPED_COMMAND 0x00
116 #define AAC_STAT_GOOD (DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD)
118 #define BYTE0(x) (unsigned char)(x)
119 #define BYTE1(x) (unsigned char)((x) >> 8)
120 #define BYTE2(x) (unsigned char)((x) >> 16)
121 #define BYTE3(x) (unsigned char)((x) >> 24)
123 /* MODE_SENSE data format */
130 } __attribute__((packed
)) hd
;
136 } __attribute__((packed
)) bd
;
138 } __attribute__((packed
)) aac_modep_data
;
140 /* MODE_SENSE_10 data format */
148 } __attribute__((packed
)) hd
;
154 } __attribute__((packed
)) bd
;
156 } __attribute__((packed
)) aac_modep10_data
;
158 /*------------------------------------------------------------------------------
159 * S T R U C T S / T Y P E D E F S
160 *----------------------------------------------------------------------------*/
161 /* SCSI inquiry data */
162 struct inquiry_data
{
163 u8 inqd_pdt
; /* Peripheral qualifier | Peripheral Device Type */
164 u8 inqd_dtq
; /* RMB | Device Type Qualifier */
165 u8 inqd_ver
; /* ISO version | ECMA version | ANSI-approved version */
166 u8 inqd_rdf
; /* AENC | TrmIOP | Response data format */
167 u8 inqd_len
; /* Additional length (n-4) */
168 u8 inqd_pad1
[2];/* Reserved - must be zero */
169 u8 inqd_pad2
; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
170 u8 inqd_vid
[8]; /* Vendor ID */
171 u8 inqd_pid
[16];/* Product ID */
172 u8 inqd_prl
[4]; /* Product Revision Level */
175 /* Added for VPD 0x83 */
176 struct tvpd_id_descriptor_type_1
{
177 u8 codeset
:4; /* VPD_CODE_SET */
179 u8 identifiertype
:4; /* VPD_IDENTIFIER_TYPE */
185 u8 serialnumber
[8]; /* SN in ASCII */
189 struct tvpd_id_descriptor_type_2
{
190 u8 codeset
:4; /* VPD_CODE_SET */
192 u8 identifiertype
:4; /* VPD_IDENTIFIER_TYPE */
198 /* The serial number supposed to be 40 bits,
199 * bit we only support 32, so make the last byte zero. */
206 struct tvpd_id_descriptor_type_3
{
207 u8 codeset
: 4; /* VPD_CODE_SET */
209 u8 identifiertype
: 4; /* VPD_IDENTIFIER_TYPE */
218 u8 DeviceTypeQualifier
:3;
222 struct tvpd_id_descriptor_type_1 type1
;
223 struct tvpd_id_descriptor_type_2 type2
;
224 struct tvpd_id_descriptor_type_3 type3
;
228 * M O D U L E G L O B A L S
231 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*sgmap
);
232 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
);
233 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
);
234 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
235 struct aac_raw_io2
*rio2
, int sg_max
);
236 static long aac_build_sghba(struct scsi_cmnd
*scsicmd
,
237 struct aac_hba_cmd_req
*hbacmd
,
238 int sg_max
, u64 sg_address
);
239 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
,
240 int pages
, int nseg
, int nseg_new
);
241 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
);
242 static int aac_send_hba_fib(struct scsi_cmnd
*scsicmd
);
243 #ifdef AAC_DETAILED_STATUS_INFO
244 static char *aac_get_status_string(u32 status
);
248 * Non dasd selection is handled entirely in aachba now
251 static int nondasd
= -1;
252 static int aac_cache
= 2; /* WCE=0 to avoid performance problems */
253 static int dacmode
= -1;
256 int startup_timeout
= 180;
257 int aif_timeout
= 120;
258 int aac_sync_mode
; /* Only Sync. transfer - disabled */
259 int aac_convert_sgl
= 1; /* convert non-conformable s/g list - enabled */
261 module_param(aac_sync_mode
, int, S_IRUGO
|S_IWUSR
);
262 MODULE_PARM_DESC(aac_sync_mode
, "Force sync. transfer mode"
264 module_param(aac_convert_sgl
, int, S_IRUGO
|S_IWUSR
);
265 MODULE_PARM_DESC(aac_convert_sgl
, "Convert non-conformable s/g list"
267 module_param(nondasd
, int, S_IRUGO
|S_IWUSR
);
268 MODULE_PARM_DESC(nondasd
, "Control scanning of hba for nondasd devices."
270 module_param_named(cache
, aac_cache
, int, S_IRUGO
|S_IWUSR
);
271 MODULE_PARM_DESC(cache
, "Disable Queue Flush commands:\n"
272 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
273 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
274 "\tbit 2 - Disable only if Battery is protecting Cache");
275 module_param(dacmode
, int, S_IRUGO
|S_IWUSR
);
276 MODULE_PARM_DESC(dacmode
, "Control whether dma addressing is using 64 bit DAC."
278 module_param_named(commit
, aac_commit
, int, S_IRUGO
|S_IWUSR
);
279 MODULE_PARM_DESC(commit
, "Control whether a COMMIT_CONFIG is issued to the"
280 " adapter for foreign arrays.\n"
281 "This is typically needed in systems that do not have a BIOS."
283 module_param_named(msi
, aac_msi
, int, S_IRUGO
|S_IWUSR
);
284 MODULE_PARM_DESC(msi
, "IRQ handling."
285 " 0=PIC(default), 1=MSI, 2=MSI-X)");
286 module_param(startup_timeout
, int, S_IRUGO
|S_IWUSR
);
287 MODULE_PARM_DESC(startup_timeout
, "The duration of time in seconds to wait for"
288 " adapter to have it's kernel up and\n"
289 "running. This is typically adjusted for large systems that do not"
291 module_param(aif_timeout
, int, S_IRUGO
|S_IWUSR
);
292 MODULE_PARM_DESC(aif_timeout
, "The duration of time in seconds to wait for"
293 " applications to pick up AIFs before\n"
294 "deregistering them. This is typically adjusted for heavily burdened"
298 module_param(numacb
, int, S_IRUGO
|S_IWUSR
);
299 MODULE_PARM_DESC(numacb
, "Request a limit to the number of adapter control"
300 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
301 " to use suggestion from Firmware.");
304 module_param(acbsize
, int, S_IRUGO
|S_IWUSR
);
305 MODULE_PARM_DESC(acbsize
, "Request a specific adapter control block (FIB)"
306 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
307 " suggestion from Firmware.");
309 int update_interval
= 30 * 60;
310 module_param(update_interval
, int, S_IRUGO
|S_IWUSR
);
311 MODULE_PARM_DESC(update_interval
, "Interval in seconds between time sync"
312 " updates issued to adapter.");
314 int check_interval
= 24 * 60 * 60;
315 module_param(check_interval
, int, S_IRUGO
|S_IWUSR
);
316 MODULE_PARM_DESC(check_interval
, "Interval in seconds between adapter health"
319 int aac_check_reset
= 1;
320 module_param_named(check_reset
, aac_check_reset
, int, S_IRUGO
|S_IWUSR
);
321 MODULE_PARM_DESC(check_reset
, "If adapter fails health check, reset the"
322 " adapter. a value of -1 forces the reset to adapters programmed to"
325 int expose_physicals
= -1;
326 module_param(expose_physicals
, int, S_IRUGO
|S_IWUSR
);
327 MODULE_PARM_DESC(expose_physicals
, "Expose physical components of the arrays."
328 " -1=protect 0=off, 1=on");
330 int aac_reset_devices
;
331 module_param_named(reset_devices
, aac_reset_devices
, int, S_IRUGO
|S_IWUSR
);
332 MODULE_PARM_DESC(reset_devices
, "Force an adapter reset at initialization.");
335 module_param_named(wwn
, aac_wwn
, int, S_IRUGO
|S_IWUSR
);
336 MODULE_PARM_DESC(wwn
, "Select a WWN type for the arrays:\n"
338 "\t1 - Array Meta Data Signature (default)\n"
339 "\t2 - Adapter Serial Number");
342 static inline int aac_valid_context(struct scsi_cmnd
*scsicmd
,
343 struct fib
*fibptr
) {
344 struct scsi_device
*device
;
346 if (unlikely(!scsicmd
|| !scsicmd
->scsi_done
)) {
347 dprintk((KERN_WARNING
"aac_valid_context: scsi command corrupt\n"));
348 aac_fib_complete(fibptr
);
351 scsicmd
->SCp
.phase
= AAC_OWNER_MIDLEVEL
;
352 device
= scsicmd
->device
;
353 if (unlikely(!device
)) {
354 dprintk((KERN_WARNING
"aac_valid_context: scsi device corrupt\n"));
355 aac_fib_complete(fibptr
);
362 * aac_get_config_status - check the adapter configuration
363 * @common: adapter to query
365 * Query config status, and commit the configuration if needed.
367 int aac_get_config_status(struct aac_dev
*dev
, int commit_flag
)
372 if (!(fibptr
= aac_fib_alloc(dev
)))
375 aac_fib_init(fibptr
);
377 struct aac_get_config_status
*dinfo
;
378 dinfo
= (struct aac_get_config_status
*) fib_data(fibptr
);
380 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
381 dinfo
->type
= cpu_to_le32(CT_GET_CONFIG_STATUS
);
382 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_config_status_resp
*)NULL
)->data
));
385 status
= aac_fib_send(ContainerCommand
,
387 sizeof (struct aac_get_config_status
),
392 printk(KERN_WARNING
"aac_get_config_status: SendFIB failed.\n");
394 struct aac_get_config_status_resp
*reply
395 = (struct aac_get_config_status_resp
*) fib_data(fibptr
);
396 dprintk((KERN_WARNING
397 "aac_get_config_status: response=%d status=%d action=%d\n",
398 le32_to_cpu(reply
->response
),
399 le32_to_cpu(reply
->status
),
400 le32_to_cpu(reply
->data
.action
)));
401 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
402 (le32_to_cpu(reply
->status
) != CT_OK
) ||
403 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
404 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
408 /* Do not set XferState to zero unless receives a response from F/W */
410 aac_fib_complete(fibptr
);
412 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
414 if ((aac_commit
== 1) || commit_flag
) {
415 struct aac_commit_config
* dinfo
;
416 aac_fib_init(fibptr
);
417 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
419 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
420 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
422 status
= aac_fib_send(ContainerCommand
,
424 sizeof (struct aac_commit_config
),
428 /* Do not set XferState to zero unless
429 * receives a response from F/W */
431 aac_fib_complete(fibptr
);
432 } else if (aac_commit
== 0) {
434 "aac_get_config_status: Foreign device configurations are being ignored\n");
437 /* FIB should be freed only after getting the response from the F/W */
438 if (status
!= -ERESTARTSYS
)
439 aac_fib_free(fibptr
);
443 static void aac_expose_phy_device(struct scsi_cmnd
*scsicmd
)
446 scsi_sg_copy_to_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
447 if ((inq_data
& 0x20) && (inq_data
& 0x1f) == TYPE_DISK
) {
449 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
454 * aac_get_containers - list containers
455 * @common: adapter to probe
457 * Make a list of all containers on this controller
459 int aac_get_containers(struct aac_dev
*dev
)
461 struct fsa_dev_info
*fsa_dev_ptr
;
465 struct aac_get_container_count
*dinfo
;
466 struct aac_get_container_count_resp
*dresp
;
467 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
469 if (!(fibptr
= aac_fib_alloc(dev
)))
472 aac_fib_init(fibptr
);
473 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
474 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
475 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
477 status
= aac_fib_send(ContainerCommand
,
479 sizeof (struct aac_get_container_count
),
484 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
485 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
486 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
487 AAC_OPTION_SUPPORTED_240_VOLUMES
) {
488 maximum_num_containers
=
489 le32_to_cpu(dresp
->MaxSimpleVolumes
);
491 aac_fib_complete(fibptr
);
493 /* FIB should be freed only after getting the response from the F/W */
494 if (status
!= -ERESTARTSYS
)
495 aac_fib_free(fibptr
);
497 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
498 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
499 if (dev
->fsa_dev
== NULL
||
500 dev
->maximum_num_containers
!= maximum_num_containers
) {
502 fsa_dev_ptr
= dev
->fsa_dev
;
504 dev
->fsa_dev
= kcalloc(maximum_num_containers
,
505 sizeof(*fsa_dev_ptr
), GFP_KERNEL
);
514 dev
->maximum_num_containers
= maximum_num_containers
;
516 for (index
= 0; index
< dev
->maximum_num_containers
; index
++) {
517 dev
->fsa_dev
[index
].devname
[0] = '\0';
518 dev
->fsa_dev
[index
].valid
= 0;
520 status
= aac_probe_container(dev
, index
);
523 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
530 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
532 struct aac_get_name_resp
* get_name_reply
;
533 struct scsi_cmnd
* scsicmd
;
535 scsicmd
= (struct scsi_cmnd
*) context
;
537 if (!aac_valid_context(scsicmd
, fibptr
))
540 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
541 BUG_ON(fibptr
== NULL
);
543 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
544 /* Failure is irrelevant, using default value instead */
545 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
546 && (get_name_reply
->data
[0] != '\0')) {
547 char *sp
= get_name_reply
->data
;
548 sp
[sizeof(((struct aac_get_name_resp
*)NULL
)->data
)] = '\0';
552 struct inquiry_data inq
;
553 char d
[sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
)];
554 int count
= sizeof(d
);
557 *dp
++ = (*sp
) ? *sp
++ : ' ';
558 } while (--count
> 0);
560 scsi_sg_copy_to_buffer(scsicmd
, &inq
, sizeof(inq
));
561 memcpy(inq
.inqd_pid
, d
, sizeof(d
));
562 scsi_sg_copy_from_buffer(scsicmd
, &inq
, sizeof(inq
));
566 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
568 aac_fib_complete(fibptr
);
569 scsicmd
->scsi_done(scsicmd
);
573 * aac_get_container_name - get container name, none blocking.
575 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
)
578 struct aac_get_name
*dinfo
;
579 struct fib
* cmd_fibcontext
;
580 struct aac_dev
* dev
;
582 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
584 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
586 aac_fib_init(cmd_fibcontext
);
587 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
589 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
590 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
591 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
592 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_name_resp
*)NULL
)->data
));
594 status
= aac_fib_send(ContainerCommand
,
596 sizeof(struct aac_get_name_resp
),
599 (fib_callback
)get_container_name_callback
,
603 * Check that the command queued to the controller
605 if (status
== -EINPROGRESS
) {
606 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
610 printk(KERN_WARNING
"aac_get_container_name: aac_fib_send failed with status: %d.\n", status
);
611 aac_fib_complete(cmd_fibcontext
);
615 static int aac_probe_container_callback2(struct scsi_cmnd
* scsicmd
)
617 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
619 if ((fsa_dev_ptr
[scmd_id(scsicmd
)].valid
& 1))
620 return aac_scsi_cmd(scsicmd
);
622 scsicmd
->result
= DID_NO_CONNECT
<< 16;
623 scsicmd
->scsi_done(scsicmd
);
627 static void _aac_probe_container2(void * context
, struct fib
* fibptr
)
629 struct fsa_dev_info
*fsa_dev_ptr
;
630 int (*callback
)(struct scsi_cmnd
*);
631 struct scsi_cmnd
* scsicmd
= (struct scsi_cmnd
*)context
;
635 if (!aac_valid_context(scsicmd
, fibptr
))
638 scsicmd
->SCp
.Status
= 0;
639 fsa_dev_ptr
= fibptr
->dev
->fsa_dev
;
641 struct aac_mount
* dresp
= (struct aac_mount
*) fib_data(fibptr
);
642 fsa_dev_ptr
+= scmd_id(scsicmd
);
644 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
645 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
646 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
647 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
648 AAC_OPTION_VARIABLE_BLOCK_SIZE
)) {
649 dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
= 0x200;
650 fsa_dev_ptr
->block_size
= 0x200;
652 fsa_dev_ptr
->block_size
=
653 le32_to_cpu(dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
);
655 for (i
= 0; i
< 16; i
++)
656 fsa_dev_ptr
->identifier
[i
] =
657 dresp
->mnt
[0].fileinfo
.bdevinfo
659 fsa_dev_ptr
->valid
= 1;
660 /* sense_key holds the current state of the spin-up */
661 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
662 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
663 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
664 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
665 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
667 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
668 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
669 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
671 if ((fsa_dev_ptr
->valid
& 1) == 0)
672 fsa_dev_ptr
->valid
= 0;
673 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
675 aac_fib_complete(fibptr
);
676 aac_fib_free(fibptr
);
677 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
678 scsicmd
->SCp
.ptr
= NULL
;
679 (*callback
)(scsicmd
);
683 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
685 struct scsi_cmnd
* scsicmd
;
686 struct aac_mount
* dresp
;
687 struct aac_query_mount
*dinfo
;
690 dresp
= (struct aac_mount
*) fib_data(fibptr
);
691 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
692 AAC_OPTION_VARIABLE_BLOCK_SIZE
))
693 dresp
->mnt
[0].capacityhigh
= 0;
694 if ((le32_to_cpu(dresp
->status
) != ST_OK
) ||
695 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
696 _aac_probe_container2(context
, fibptr
);
699 scsicmd
= (struct scsi_cmnd
*) context
;
701 if (!aac_valid_context(scsicmd
, fibptr
))
704 aac_fib_init(fibptr
);
706 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
708 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
709 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
710 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
712 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
714 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
715 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
717 status
= aac_fib_send(ContainerCommand
,
719 sizeof(struct aac_query_mount
),
722 _aac_probe_container2
,
725 * Check that the command queued to the controller
727 if (status
== -EINPROGRESS
)
728 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
729 else if (status
< 0) {
730 /* Inherit results from VM_NameServe, if any */
731 dresp
->status
= cpu_to_le32(ST_OK
);
732 _aac_probe_container2(context
, fibptr
);
736 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
739 int status
= -ENOMEM
;
741 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
742 struct aac_query_mount
*dinfo
;
744 aac_fib_init(fibptr
);
746 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
748 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
749 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
750 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
752 dinfo
->command
= cpu_to_le32(VM_NameServe
);
754 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
755 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
756 scsicmd
->SCp
.ptr
= (char *)callback
;
758 status
= aac_fib_send(ContainerCommand
,
760 sizeof(struct aac_query_mount
),
763 _aac_probe_container1
,
766 * Check that the command queued to the controller
768 if (status
== -EINPROGRESS
) {
769 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
773 scsicmd
->SCp
.ptr
= NULL
;
774 aac_fib_complete(fibptr
);
775 aac_fib_free(fibptr
);
779 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
781 fsa_dev_ptr
+= scmd_id(scsicmd
);
782 if ((fsa_dev_ptr
->valid
& 1) == 0) {
783 fsa_dev_ptr
->valid
= 0;
784 return (*callback
)(scsicmd
);
792 * aac_probe_container - query a logical volume
793 * @dev: device to query
794 * @cid: container identifier
796 * Queries the controller about the given volume. The volume information
797 * is updated in the struct fsa_dev_info structure rather than returned.
799 static int aac_probe_container_callback1(struct scsi_cmnd
* scsicmd
)
801 scsicmd
->device
= NULL
;
805 int aac_probe_container(struct aac_dev
*dev
, int cid
)
807 struct scsi_cmnd
*scsicmd
= kmalloc(sizeof(*scsicmd
), GFP_KERNEL
);
808 struct scsi_device
*scsidev
= kmalloc(sizeof(*scsidev
), GFP_KERNEL
);
811 if (!scsicmd
|| !scsidev
) {
816 scsicmd
->list
.next
= NULL
;
817 scsicmd
->scsi_done
= (void (*)(struct scsi_cmnd
*))aac_probe_container_callback1
;
819 scsicmd
->device
= scsidev
;
820 scsidev
->sdev_state
= 0;
822 scsidev
->host
= dev
->scsi_host_ptr
;
824 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
825 while (scsicmd
->device
== scsidev
)
828 status
= scsicmd
->SCp
.Status
;
833 /* Local Structure to set SCSI inquiry data strings */
835 char vid
[8]; /* Vendor ID */
836 char pid
[16]; /* Product ID */
837 char prl
[4]; /* Product Revision Level */
841 * InqStrCopy - string merge
842 * @a: string to copy from
843 * @b: string to copy to
845 * Copy a String from one location to another
849 static void inqstrcpy(char *a
, char *b
)
852 while (*a
!= (char)0)
856 static char *container_types
[] = {
880 char * get_container_type(unsigned tindex
)
882 if (tindex
>= ARRAY_SIZE(container_types
))
883 tindex
= ARRAY_SIZE(container_types
) - 1;
884 return container_types
[tindex
];
887 /* Function: setinqstr
889 * Arguments: [1] pointer to void [1] int
891 * Purpose: Sets SCSI inquiry data strings for vendor, product
892 * and revision level. Allows strings to be set in platform dependent
893 * files instead of in OS dependent driver source.
896 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
898 struct scsi_inq
*str
;
900 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
901 memset(str
, ' ', sizeof(*str
));
903 if (dev
->supplement_adapter_info
.AdapterTypeText
[0]) {
904 char * cp
= dev
->supplement_adapter_info
.AdapterTypeText
;
906 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
907 inqstrcpy("SMC", str
->vid
);
909 c
= sizeof(str
->vid
);
910 while (*cp
&& *cp
!= ' ' && --c
)
914 inqstrcpy (dev
->supplement_adapter_info
.AdapterTypeText
,
917 while (*cp
&& *cp
!= ' ')
922 /* last six chars reserved for vol type */
924 if (strlen(cp
) > sizeof(str
->pid
)) {
925 c
= cp
[sizeof(str
->pid
)];
926 cp
[sizeof(str
->pid
)] = '\0';
928 inqstrcpy (cp
, str
->pid
);
930 cp
[sizeof(str
->pid
)] = c
;
932 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
934 inqstrcpy (mp
->vname
, str
->vid
);
935 /* last six chars reserved for vol type */
936 inqstrcpy (mp
->model
, str
->pid
);
939 if (tindex
< ARRAY_SIZE(container_types
)){
940 char *findit
= str
->pid
;
942 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
943 /* RAID is superfluous in the context of a RAID device */
944 if (memcmp(findit
-4, "RAID", 4) == 0)
945 *(findit
-= 4) = ' ';
946 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
947 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
948 inqstrcpy (container_types
[tindex
], findit
+ 1);
950 inqstrcpy ("V1.0", str
->prl
);
953 static void build_vpd83_type3(struct tvpd_page83
*vpdpage83data
,
954 struct aac_dev
*dev
, struct scsi_cmnd
*scsicmd
)
958 vpdpage83data
->type3
.codeset
= 1;
959 vpdpage83data
->type3
.identifiertype
= 3;
960 vpdpage83data
->type3
.identifierlength
= sizeof(vpdpage83data
->type3
)
963 for (container
= 0; container
< dev
->maximum_num_containers
;
966 if (scmd_id(scsicmd
) == container
) {
967 memcpy(vpdpage83data
->type3
.Identifier
,
968 dev
->fsa_dev
[container
].identifier
,
975 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
977 struct aac_get_serial_resp
* get_serial_reply
;
978 struct scsi_cmnd
* scsicmd
;
980 BUG_ON(fibptr
== NULL
);
982 scsicmd
= (struct scsi_cmnd
*) context
;
983 if (!aac_valid_context(scsicmd
, fibptr
))
986 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
987 /* Failure is irrelevant, using default value instead */
988 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
989 /*Check to see if it's for VPD 0x83 or 0x80 */
990 if (scsicmd
->cmnd
[2] == 0x83) {
991 /* vpd page 0x83 - Device Identification Page */
994 struct tvpd_page83 vpdpage83data
;
996 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
998 memset(((u8
*)&vpdpage83data
), 0,
999 sizeof(vpdpage83data
));
1001 /* DIRECT_ACCESS_DEVIC */
1002 vpdpage83data
.DeviceType
= 0;
1003 /* DEVICE_CONNECTED */
1004 vpdpage83data
.DeviceTypeQualifier
= 0;
1005 /* VPD_DEVICE_IDENTIFIERS */
1006 vpdpage83data
.PageCode
= 0x83;
1007 vpdpage83data
.reserved
= 0;
1008 vpdpage83data
.PageLength
=
1009 sizeof(vpdpage83data
.type1
) +
1010 sizeof(vpdpage83data
.type2
);
1012 /* VPD 83 Type 3 is not supported for ARC */
1013 if (dev
->sa_firmware
)
1014 vpdpage83data
.PageLength
+=
1015 sizeof(vpdpage83data
.type3
);
1017 /* T10 Vendor Identifier Field Format */
1018 /* VpdcodesetAscii */
1019 vpdpage83data
.type1
.codeset
= 2;
1020 /* VpdIdentifierTypeVendorId */
1021 vpdpage83data
.type1
.identifiertype
= 1;
1022 vpdpage83data
.type1
.identifierlength
=
1023 sizeof(vpdpage83data
.type1
) - 4;
1025 /* "ADAPTEC " for adaptec */
1026 memcpy(vpdpage83data
.type1
.venid
,
1028 sizeof(vpdpage83data
.type1
.venid
));
1029 memcpy(vpdpage83data
.type1
.productid
,
1032 vpdpage83data
.type1
.productid
));
1034 /* Convert to ascii based serial number.
1035 * The LSB is the the end.
1037 for (i
= 0; i
< 8; i
++) {
1039 (u8
)((get_serial_reply
->uid
>> ((7 - i
) * 4)) & 0xF);
1041 vpdpage83data
.type1
.serialnumber
[i
] =
1044 vpdpage83data
.type1
.serialnumber
[i
] =
1049 /* VpdCodeSetBinary */
1050 vpdpage83data
.type2
.codeset
= 1;
1051 /* VpdidentifiertypeEUI64 */
1052 vpdpage83data
.type2
.identifiertype
= 2;
1053 vpdpage83data
.type2
.identifierlength
=
1054 sizeof(vpdpage83data
.type2
) - 4;
1056 vpdpage83data
.type2
.eu64id
.venid
[0] = 0xD0;
1057 vpdpage83data
.type2
.eu64id
.venid
[1] = 0;
1058 vpdpage83data
.type2
.eu64id
.venid
[2] = 0;
1060 vpdpage83data
.type2
.eu64id
.Serial
=
1061 get_serial_reply
->uid
;
1062 vpdpage83data
.type2
.eu64id
.reserved
= 0;
1065 * VpdIdentifierTypeFCPHName
1066 * VPD 0x83 Type 3 not supported for ARC
1068 if (dev
->sa_firmware
) {
1069 build_vpd83_type3(&vpdpage83data
,
1073 /* Move the inquiry data to the response buffer. */
1074 scsi_sg_copy_from_buffer(scsicmd
, &vpdpage83data
,
1075 sizeof(vpdpage83data
));
1077 /* It must be for VPD 0x80 */
1080 sp
[0] = INQD_PDT_DA
;
1081 sp
[1] = scsicmd
->cmnd
[2];
1083 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
1084 le32_to_cpu(get_serial_reply
->uid
));
1085 scsi_sg_copy_from_buffer(scsicmd
, sp
,
1090 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1092 aac_fib_complete(fibptr
);
1093 scsicmd
->scsi_done(scsicmd
);
1097 * aac_get_container_serial - get container serial, none blocking.
1099 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
1102 struct aac_get_serial
*dinfo
;
1103 struct fib
* cmd_fibcontext
;
1104 struct aac_dev
* dev
;
1106 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1108 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
1110 aac_fib_init(cmd_fibcontext
);
1111 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
1113 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
1114 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
1115 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1117 status
= aac_fib_send(ContainerCommand
,
1119 sizeof(struct aac_get_serial_resp
),
1122 (fib_callback
) get_container_serial_callback
,
1126 * Check that the command queued to the controller
1128 if (status
== -EINPROGRESS
) {
1129 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1133 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
1134 aac_fib_complete(cmd_fibcontext
);
1138 /* Function: setinqserial
1140 * Arguments: [1] pointer to void [1] int
1142 * Purpose: Sets SCSI Unit Serial number.
1143 * This is a fake. We should read a proper
1144 * serial number from the container. <SuSE>But
1145 * without docs it's quite hard to do it :-)
1146 * So this will have to do in the meantime.</SuSE>
1149 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
1152 * This breaks array migration.
1154 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
1155 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
1158 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
1159 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
1161 u8
*sense_buf
= (u8
*)sense_data
;
1162 /* Sense data valid, err code 70h */
1163 sense_buf
[0] = 0x70; /* No info field */
1164 sense_buf
[1] = 0; /* Segment number, always zero */
1166 sense_buf
[2] = sense_key
; /* Sense key */
1168 sense_buf
[12] = sense_code
; /* Additional sense code */
1169 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
1171 if (sense_key
== ILLEGAL_REQUEST
) {
1172 sense_buf
[7] = 10; /* Additional sense length */
1174 sense_buf
[15] = bit_pointer
;
1175 /* Illegal parameter is in the parameter block */
1176 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
1177 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
1178 /* Illegal parameter is in the CDB block */
1179 sense_buf
[16] = field_pointer
>> 8; /* MSB */
1180 sense_buf
[17] = field_pointer
; /* LSB */
1182 sense_buf
[7] = 6; /* Additional sense length */
1185 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1187 if (lba
& 0xffffffff00000000LL
) {
1188 int cid
= scmd_id(cmd
);
1189 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1190 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1191 SAM_STAT_CHECK_CONDITION
;
1192 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1193 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1194 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1195 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1196 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1197 SCSI_SENSE_BUFFERSIZE
));
1198 cmd
->scsi_done(cmd
);
1204 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1209 static void io_callback(void *context
, struct fib
* fibptr
);
1211 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1213 struct aac_dev
*dev
= fib
->dev
;
1214 u16 fibsize
, command
;
1218 if ((dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
1219 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) &&
1221 struct aac_raw_io2
*readcmd2
;
1222 readcmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1223 memset(readcmd2
, 0, sizeof(struct aac_raw_io2
));
1224 readcmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1225 readcmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1226 readcmd2
->byteCount
= cpu_to_le32(count
*
1227 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1228 readcmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1229 readcmd2
->flags
= cpu_to_le16(RIO2_IO_TYPE_READ
);
1230 ret
= aac_build_sgraw2(cmd
, readcmd2
,
1231 dev
->scsi_host_ptr
->sg_tablesize
);
1234 command
= ContainerRawIo2
;
1235 fibsize
= sizeof(struct aac_raw_io2
) +
1236 ((le32_to_cpu(readcmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1238 struct aac_raw_io
*readcmd
;
1239 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
1240 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1241 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1242 readcmd
->count
= cpu_to_le32(count
*
1243 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1244 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1245 readcmd
->flags
= cpu_to_le16(RIO_TYPE_READ
);
1246 readcmd
->bpTotal
= 0;
1247 readcmd
->bpComplete
= 0;
1248 ret
= aac_build_sgraw(cmd
, &readcmd
->sg
);
1251 command
= ContainerRawIo
;
1252 fibsize
= sizeof(struct aac_raw_io
) +
1253 ((le32_to_cpu(readcmd
->sg
.count
)-1) * sizeof(struct sgentryraw
));
1256 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1258 * Now send the Fib to the adapter
1260 return aac_fib_send(command
,
1265 (fib_callback
) io_callback
,
1269 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1272 struct aac_read64
*readcmd
;
1276 readcmd
= (struct aac_read64
*) fib_data(fib
);
1277 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
1278 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1279 readcmd
->sector_count
= cpu_to_le16(count
);
1280 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1284 ret
= aac_build_sg64(cmd
, &readcmd
->sg
);
1287 fibsize
= sizeof(struct aac_read64
) +
1288 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1289 sizeof (struct sgentry64
));
1290 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1291 sizeof(struct aac_fibhdr
)));
1293 * Now send the Fib to the adapter
1295 return aac_fib_send(ContainerCommand64
,
1300 (fib_callback
) io_callback
,
1304 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1307 struct aac_read
*readcmd
;
1308 struct aac_dev
*dev
= fib
->dev
;
1312 readcmd
= (struct aac_read
*) fib_data(fib
);
1313 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
1314 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1315 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1316 readcmd
->count
= cpu_to_le32(count
*
1317 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1319 ret
= aac_build_sg(cmd
, &readcmd
->sg
);
1322 fibsize
= sizeof(struct aac_read
) +
1323 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1324 sizeof (struct sgentry
));
1325 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1326 sizeof(struct aac_fibhdr
)));
1328 * Now send the Fib to the adapter
1330 return aac_fib_send(ContainerCommand
,
1335 (fib_callback
) io_callback
,
1339 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1341 struct aac_dev
*dev
= fib
->dev
;
1342 u16 fibsize
, command
;
1346 if ((dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
||
1347 dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE3
) &&
1349 struct aac_raw_io2
*writecmd2
;
1350 writecmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1351 memset(writecmd2
, 0, sizeof(struct aac_raw_io2
));
1352 writecmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1353 writecmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1354 writecmd2
->byteCount
= cpu_to_le32(count
*
1355 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1356 writecmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1357 writecmd2
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1358 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1359 cpu_to_le16(RIO2_IO_TYPE_WRITE
|RIO2_IO_SUREWRITE
) :
1360 cpu_to_le16(RIO2_IO_TYPE_WRITE
);
1361 ret
= aac_build_sgraw2(cmd
, writecmd2
,
1362 dev
->scsi_host_ptr
->sg_tablesize
);
1365 command
= ContainerRawIo2
;
1366 fibsize
= sizeof(struct aac_raw_io2
) +
1367 ((le32_to_cpu(writecmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1369 struct aac_raw_io
*writecmd
;
1370 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1371 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1372 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1373 writecmd
->count
= cpu_to_le32(count
*
1374 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1375 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1376 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1377 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1378 cpu_to_le16(RIO_TYPE_WRITE
|RIO_SUREWRITE
) :
1379 cpu_to_le16(RIO_TYPE_WRITE
);
1380 writecmd
->bpTotal
= 0;
1381 writecmd
->bpComplete
= 0;
1382 ret
= aac_build_sgraw(cmd
, &writecmd
->sg
);
1385 command
= ContainerRawIo
;
1386 fibsize
= sizeof(struct aac_raw_io
) +
1387 ((le32_to_cpu(writecmd
->sg
.count
)-1) * sizeof (struct sgentryraw
));
1390 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1392 * Now send the Fib to the adapter
1394 return aac_fib_send(command
,
1399 (fib_callback
) io_callback
,
1403 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1406 struct aac_write64
*writecmd
;
1410 writecmd
= (struct aac_write64
*) fib_data(fib
);
1411 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1412 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1413 writecmd
->sector_count
= cpu_to_le16(count
);
1414 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1416 writecmd
->flags
= 0;
1418 ret
= aac_build_sg64(cmd
, &writecmd
->sg
);
1421 fibsize
= sizeof(struct aac_write64
) +
1422 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1423 sizeof (struct sgentry64
));
1424 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1425 sizeof(struct aac_fibhdr
)));
1427 * Now send the Fib to the adapter
1429 return aac_fib_send(ContainerCommand64
,
1434 (fib_callback
) io_callback
,
1438 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1441 struct aac_write
*writecmd
;
1442 struct aac_dev
*dev
= fib
->dev
;
1446 writecmd
= (struct aac_write
*) fib_data(fib
);
1447 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1448 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1449 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1450 writecmd
->count
= cpu_to_le32(count
*
1451 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1452 writecmd
->sg
.count
= cpu_to_le32(1);
1453 /* ->stable is not used - it did mean which type of write */
1455 ret
= aac_build_sg(cmd
, &writecmd
->sg
);
1458 fibsize
= sizeof(struct aac_write
) +
1459 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1460 sizeof (struct sgentry
));
1461 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1462 sizeof(struct aac_fibhdr
)));
1464 * Now send the Fib to the adapter
1466 return aac_fib_send(ContainerCommand
,
1471 (fib_callback
) io_callback
,
1475 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1477 struct aac_srb
* srbcmd
;
1482 switch(cmd
->sc_data_direction
){
1486 case DMA_BIDIRECTIONAL
:
1487 flag
= SRB_DataIn
| SRB_DataOut
;
1489 case DMA_FROM_DEVICE
:
1493 default: /* shuts up some versions of gcc */
1494 flag
= SRB_NoDataXfer
;
1498 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1499 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1500 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1501 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1502 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1503 srbcmd
->flags
= cpu_to_le32(flag
);
1504 timeout
= cmd
->request
->timeout
/HZ
;
1507 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1508 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1509 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1513 static struct aac_hba_cmd_req
*aac_construct_hbacmd(struct fib
*fib
,
1514 struct scsi_cmnd
*cmd
)
1516 struct aac_hba_cmd_req
*hbacmd
;
1517 struct aac_dev
*dev
;
1521 dev
= (struct aac_dev
*)cmd
->device
->host
->hostdata
;
1523 hbacmd
= (struct aac_hba_cmd_req
*)fib
->hw_fib_va
;
1524 memset(hbacmd
, 0, 96); /* sizeof(*hbacmd) is not necessary */
1525 /* iu_type is a parameter of aac_hba_send */
1526 switch (cmd
->sc_data_direction
) {
1530 case DMA_FROM_DEVICE
:
1531 case DMA_BIDIRECTIONAL
:
1538 hbacmd
->lun
[1] = cpu_to_le32(cmd
->device
->lun
);
1540 bus
= aac_logical_to_phys(scmd_channel(cmd
));
1541 target
= scmd_id(cmd
);
1542 hbacmd
->it_nexus
= dev
->hba_map
[bus
][target
].rmw_nexus
;
1544 /* we fill in reply_qid later in aac_src_deliver_message */
1545 /* we fill in iu_type, request_id later in aac_hba_send */
1546 /* we fill in emb_data_desc_count later in aac_build_sghba */
1548 memcpy(hbacmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1549 hbacmd
->data_length
= cpu_to_le32(scsi_bufflen(cmd
));
1551 address
= (u64
)fib
->hw_error_pa
;
1552 hbacmd
->error_ptr_hi
= cpu_to_le32((u32
)(address
>> 32));
1553 hbacmd
->error_ptr_lo
= cpu_to_le32((u32
)(address
& 0xffffffff));
1554 hbacmd
->error_length
= cpu_to_le32(FW_ERROR_BUFFER_SIZE
);
1559 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1561 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1564 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1567 ret
= aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1570 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1572 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1573 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1575 * Build Scatter/Gather list
1577 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1578 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1579 sizeof (struct sgentry64
));
1580 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1581 sizeof(struct aac_fibhdr
)));
1584 * Now send the Fib to the adapter
1586 return aac_fib_send(ScsiPortCommand64
, fib
,
1587 fibsize
, FsaNormal
, 0, 1,
1588 (fib_callback
) aac_srb_callback
,
1592 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1595 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1598 ret
= aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1601 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1603 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1604 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1606 * Build Scatter/Gather list
1608 fibsize
= sizeof (struct aac_srb
) +
1609 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1610 sizeof (struct sgentry
));
1611 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1612 sizeof(struct aac_fibhdr
)));
1615 * Now send the Fib to the adapter
1617 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1618 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1621 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1623 if ((sizeof(dma_addr_t
) > 4) && fib
->dev
->needs_dac
&&
1624 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1626 return aac_scsi_32(fib
, cmd
);
1629 static int aac_adapter_hba(struct fib
*fib
, struct scsi_cmnd
*cmd
)
1631 struct aac_hba_cmd_req
*hbacmd
= aac_construct_hbacmd(fib
, cmd
);
1632 struct aac_dev
*dev
;
1635 dev
= (struct aac_dev
*)cmd
->device
->host
->hostdata
;
1637 ret
= aac_build_sghba(cmd
, hbacmd
,
1638 dev
->scsi_host_ptr
->sg_tablesize
, (u64
)fib
->hw_sgl_pa
);
1643 * Now send the HBA command to the adapter
1645 fib
->hbacmd_size
= 64 + le32_to_cpu(hbacmd
->emb_data_desc_count
) *
1646 sizeof(struct aac_hba_sgl
);
1648 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ
, fib
,
1649 (fib_callback
) aac_hba_callback
,
1653 int aac_issue_bmic_identify(struct aac_dev
*dev
, u32 bus
, u32 target
)
1656 struct aac_srb
*srbcmd
;
1657 struct sgmap64
*sg64
;
1658 struct aac_ciss_identify_pd
*identify_resp
;
1661 u16 fibsize
, datasize
;
1662 int rcode
= -ENOMEM
;
1665 fibptr
= aac_fib_alloc(dev
);
1669 fibsize
= sizeof(struct aac_srb
) -
1670 sizeof(struct sgentry
) + sizeof(struct sgentry64
);
1671 datasize
= sizeof(struct aac_ciss_identify_pd
);
1673 identify_resp
= pci_alloc_consistent(dev
->pdev
, datasize
, &addr
);
1678 vbus
= (u32
)le16_to_cpu(dev
->supplement_adapter_info
.VirtDeviceBus
);
1679 vid
= (u32
)le16_to_cpu(dev
->supplement_adapter_info
.VirtDeviceTarget
);
1681 aac_fib_init(fibptr
);
1683 srbcmd
= (struct aac_srb
*) fib_data(fibptr
);
1684 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1685 srbcmd
->channel
= cpu_to_le32(vbus
);
1686 srbcmd
->id
= cpu_to_le32(vid
);
1688 srbcmd
->flags
= cpu_to_le32(SRB_DataIn
);
1689 srbcmd
->timeout
= cpu_to_le32(10);
1690 srbcmd
->retry_limit
= 0;
1691 srbcmd
->cdb_size
= cpu_to_le32(12);
1692 srbcmd
->count
= cpu_to_le32(datasize
);
1694 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1695 srbcmd
->cdb
[0] = 0x26;
1696 srbcmd
->cdb
[2] = (u8
)((AAC_MAX_LUN
+ target
) & 0x00FF);
1697 srbcmd
->cdb
[6] = CISS_IDENTIFY_PHYSICAL_DEVICE
;
1699 sg64
= (struct sgmap64
*)&srbcmd
->sg
;
1700 sg64
->count
= cpu_to_le32(1);
1701 sg64
->sg
[0].addr
[1] = cpu_to_le32((u32
)(((addr
) >> 16) >> 16));
1702 sg64
->sg
[0].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
1703 sg64
->sg
[0].count
= cpu_to_le32(datasize
);
1705 rcode
= aac_fib_send(ScsiPortCommand64
,
1706 fibptr
, fibsize
, FsaNormal
, 1, 1, NULL
, NULL
);
1708 if (identify_resp
->current_queue_depth_limit
<= 0 ||
1709 identify_resp
->current_queue_depth_limit
> 32)
1710 dev
->hba_map
[bus
][target
].qd_limit
= 32;
1712 dev
->hba_map
[bus
][target
].qd_limit
=
1713 identify_resp
->current_queue_depth_limit
;
1715 pci_free_consistent(dev
->pdev
, datasize
, (void *)identify_resp
, addr
);
1717 aac_fib_complete(fibptr
);
1720 aac_fib_free(fibptr
);
1726 * aac_update hba_map()- update current hba map with data from FW
1727 * @dev: aac_dev structure
1728 * @phys_luns: FW information from report phys luns
1730 * Update our hba map with the information gathered from the FW
1732 void aac_update_hba_map(struct aac_dev
*dev
,
1733 struct aac_ciss_phys_luns_resp
*phys_luns
, int rescan
)
1735 /* ok and extended reporting */
1736 u32 lun_count
, nexus
;
1738 u8 expose_flag
, attribs
;
1741 lun_count
= ((phys_luns
->list_length
[0] << 24)
1742 + (phys_luns
->list_length
[1] << 16)
1743 + (phys_luns
->list_length
[2] << 8)
1744 + (phys_luns
->list_length
[3])) / 24;
1746 for (i
= 0; i
< lun_count
; ++i
) {
1748 bus
= phys_luns
->lun
[i
].level2
[1] & 0x3f;
1749 target
= phys_luns
->lun
[i
].level2
[0];
1750 expose_flag
= phys_luns
->lun
[i
].bus
>> 6;
1751 attribs
= phys_luns
->lun
[i
].node_ident
[9];
1752 nexus
= *((u32
*) &phys_luns
->lun
[i
].node_ident
[12]);
1754 if (bus
>= AAC_MAX_BUSES
|| target
>= AAC_MAX_TARGETS
)
1757 dev
->hba_map
[bus
][target
].expose
= expose_flag
;
1759 if (expose_flag
!= 0) {
1760 devtype
= AAC_DEVTYPE_RAID_MEMBER
;
1761 goto update_devtype
;
1764 if (nexus
!= 0 && (attribs
& 8)) {
1765 devtype
= AAC_DEVTYPE_NATIVE_RAW
;
1766 dev
->hba_map
[bus
][target
].rmw_nexus
=
1769 devtype
= AAC_DEVTYPE_ARC_RAW
;
1771 if (devtype
!= AAC_DEVTYPE_NATIVE_RAW
)
1772 goto update_devtype
;
1774 if (aac_issue_bmic_identify(dev
, bus
, target
) < 0)
1775 dev
->hba_map
[bus
][target
].qd_limit
= 32;
1778 if (rescan
== AAC_INIT
)
1779 dev
->hba_map
[bus
][target
].devtype
= devtype
;
1781 dev
->hba_map
[bus
][target
].new_devtype
= devtype
;
1786 * aac_report_phys_luns() Process topology change
1787 * @dev: aac_dev structure
1788 * @fibptr: fib pointer
1790 * Execute a CISS REPORT PHYS LUNS and process the results into
1791 * the current hba_map.
1793 int aac_report_phys_luns(struct aac_dev
*dev
, struct fib
*fibptr
, int rescan
)
1795 int fibsize
, datasize
;
1796 struct aac_ciss_phys_luns_resp
*phys_luns
;
1797 struct aac_srb
*srbcmd
;
1798 struct sgmap64
*sg64
;
1803 /* Thor SA Firmware -> CISS_REPORT_PHYSICAL_LUNS */
1804 fibsize
= sizeof(struct aac_srb
) - sizeof(struct sgentry
)
1805 + sizeof(struct sgentry64
);
1806 datasize
= sizeof(struct aac_ciss_phys_luns_resp
)
1807 + (AAC_MAX_TARGETS
- 1) * sizeof(struct _ciss_lun
);
1809 phys_luns
= (struct aac_ciss_phys_luns_resp
*) pci_alloc_consistent(
1810 dev
->pdev
, datasize
, &addr
);
1812 if (phys_luns
== NULL
) {
1817 vbus
= (u32
) le16_to_cpu(
1818 dev
->supplement_adapter_info
.VirtDeviceBus
);
1819 vid
= (u32
) le16_to_cpu(
1820 dev
->supplement_adapter_info
.VirtDeviceTarget
);
1822 aac_fib_init(fibptr
);
1824 srbcmd
= (struct aac_srb
*) fib_data(fibptr
);
1825 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1826 srbcmd
->channel
= cpu_to_le32(vbus
);
1827 srbcmd
->id
= cpu_to_le32(vid
);
1829 srbcmd
->flags
= cpu_to_le32(SRB_DataIn
);
1830 srbcmd
->timeout
= cpu_to_le32(10);
1831 srbcmd
->retry_limit
= 0;
1832 srbcmd
->cdb_size
= cpu_to_le32(12);
1833 srbcmd
->count
= cpu_to_le32(datasize
);
1835 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1836 srbcmd
->cdb
[0] = CISS_REPORT_PHYSICAL_LUNS
;
1837 srbcmd
->cdb
[1] = 2; /* extended reporting */
1838 srbcmd
->cdb
[8] = (u8
)(datasize
>> 8);
1839 srbcmd
->cdb
[9] = (u8
)(datasize
);
1841 sg64
= (struct sgmap64
*) &srbcmd
->sg
;
1842 sg64
->count
= cpu_to_le32(1);
1843 sg64
->sg
[0].addr
[1] = cpu_to_le32(upper_32_bits(addr
));
1844 sg64
->sg
[0].addr
[0] = cpu_to_le32(lower_32_bits(addr
));
1845 sg64
->sg
[0].count
= cpu_to_le32(datasize
);
1847 rcode
= aac_fib_send(ScsiPortCommand64
, fibptr
, fibsize
,
1848 FsaNormal
, 1, 1, NULL
, NULL
);
1851 if (rcode
>= 0 && phys_luns
->resp_flag
== 2) {
1852 /* ok and extended reporting */
1853 aac_update_hba_map(dev
, phys_luns
, rescan
);
1856 pci_free_consistent(dev
->pdev
, datasize
, (void *) phys_luns
, addr
);
1861 int aac_get_adapter_info(struct aac_dev
* dev
)
1865 u32 tmp
, bus
, target
;
1866 struct aac_adapter_info
*info
;
1867 struct aac_bus_info
*command
;
1868 struct aac_bus_info_response
*bus_info
;
1870 if (!(fibptr
= aac_fib_alloc(dev
)))
1873 aac_fib_init(fibptr
);
1874 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
1875 memset(info
,0,sizeof(*info
));
1877 rcode
= aac_fib_send(RequestAdapterInfo
,
1881 -1, 1, /* First `interrupt' command uses special wait */
1886 /* FIB should be freed only after
1887 * getting the response from the F/W */
1888 if (rcode
!= -ERESTARTSYS
) {
1889 aac_fib_complete(fibptr
);
1890 aac_fib_free(fibptr
);
1894 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
1896 dev
->supplement_adapter_info
.VirtDeviceBus
= 0xffff;
1897 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
1898 struct aac_supplement_adapter_info
* sinfo
;
1900 aac_fib_init(fibptr
);
1902 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
1904 memset(sinfo
,0,sizeof(*sinfo
));
1906 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
1915 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
1916 if (rcode
== -ERESTARTSYS
) {
1917 fibptr
= aac_fib_alloc(dev
);
1924 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
1925 for (bus
= 0; bus
< AAC_MAX_BUSES
; bus
++) {
1926 for (target
= 0; target
< AAC_MAX_TARGETS
; target
++) {
1927 dev
->hba_map
[bus
][target
].devtype
= 0;
1928 dev
->hba_map
[bus
][target
].qd_limit
= 0;
1936 aac_fib_init(fibptr
);
1938 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
1940 memset(bus_info
, 0, sizeof(*bus_info
));
1942 command
= (struct aac_bus_info
*)bus_info
;
1944 command
->Command
= cpu_to_le32(VM_Ioctl
);
1945 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
1946 command
->MethodId
= cpu_to_le32(1);
1947 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
1949 rcode
= aac_fib_send(ContainerCommand
,
1956 /* reasoned default */
1957 dev
->maximum_num_physicals
= 16;
1958 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
1959 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
1960 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
1963 if (!dev
->sync_mode
&& dev
->sa_firmware
&&
1964 dev
->supplement_adapter_info
.VirtDeviceBus
!= 0xffff) {
1965 /* Thor SA Firmware -> CISS_REPORT_PHYSICAL_LUNS */
1966 rcode
= aac_report_phys_luns(dev
, fibptr
, AAC_INIT
);
1969 if (!dev
->in_reset
) {
1971 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
1972 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
1978 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
1979 (int)sizeof(dev
->supplement_adapter_info
.BuildDate
),
1980 dev
->supplement_adapter_info
.BuildDate
);
1981 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
1982 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
1984 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1985 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
1986 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
1987 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
1989 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1990 le32_to_cpu(dev
->adapter_info
.biosbuild
));
1992 if (aac_get_serial_number(
1993 shost_to_class(dev
->scsi_host_ptr
), buffer
))
1994 printk(KERN_INFO
"%s%d: serial %s",
1995 dev
->name
, dev
->id
, buffer
);
1996 if (dev
->supplement_adapter_info
.VpdInfo
.Tsid
[0]) {
1997 printk(KERN_INFO
"%s%d: TSID %.*s\n",
1999 (int)sizeof(dev
->supplement_adapter_info
.VpdInfo
.Tsid
),
2000 dev
->supplement_adapter_info
.VpdInfo
.Tsid
);
2002 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
2003 (dev
->supplement_adapter_info
.SupportedOptions2
&
2004 AAC_OPTION_IGNORE_RESET
))) {
2005 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
2006 dev
->name
, dev
->id
);
2010 dev
->cache_protected
= 0;
2011 dev
->jbod
= ((dev
->supplement_adapter_info
.FeatureBits
&
2012 AAC_FEATURE_JBOD
) != 0);
2013 dev
->nondasd_support
= 0;
2014 dev
->raid_scsi_mode
= 0;
2015 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
2016 dev
->nondasd_support
= 1;
2019 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2020 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2021 * force nondasd support on. If we decide to allow the non-dasd flag
2022 * additional changes changes will have to be made to support
2023 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2024 * changed to support the new dev->raid_scsi_mode flag instead of
2025 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2026 * function aac_detect will have to be modified where it sets up the
2027 * max number of channels based on the aac->nondasd_support flag only.
2029 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
2030 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
2031 dev
->nondasd_support
= 1;
2032 dev
->raid_scsi_mode
= 1;
2034 if (dev
->raid_scsi_mode
!= 0)
2035 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
2036 dev
->name
, dev
->id
);
2039 dev
->nondasd_support
= (nondasd
!=0);
2040 if (dev
->nondasd_support
&& !dev
->in_reset
)
2041 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
2043 if (dma_get_required_mask(&dev
->pdev
->dev
) > DMA_BIT_MASK(32))
2045 dev
->dac_support
= 0;
2046 if ((sizeof(dma_addr_t
) > 4) && dev
->needs_dac
&&
2047 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)) {
2049 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
2050 dev
->name
, dev
->id
);
2051 dev
->dac_support
= 1;
2055 dev
->dac_support
= (dacmode
!=0);
2058 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2059 if (dev
->dac_support
&& (aac_get_driver_ident(dev
->cardtype
)->quirks
2060 & AAC_QUIRK_SCSI_32
)) {
2061 dev
->nondasd_support
= 0;
2063 expose_physicals
= 0;
2066 if(dev
->dac_support
!= 0) {
2067 if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(64)) &&
2068 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(64))) {
2070 printk(KERN_INFO
"%s%d: 64 Bit DAC enabled\n",
2071 dev
->name
, dev
->id
);
2072 } else if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(32)) &&
2073 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(32))) {
2074 printk(KERN_INFO
"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
2075 dev
->name
, dev
->id
);
2076 dev
->dac_support
= 0;
2078 printk(KERN_WARNING
"%s%d: No suitable DMA available.\n",
2079 dev
->name
, dev
->id
);
2084 * Deal with configuring for the individualized limits of each packet
2087 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
2088 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
2092 if (dev
->raw_io_interface
) {
2093 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
2096 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
2097 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
2099 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
2100 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
2101 sizeof(struct aac_fibhdr
) -
2102 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
2103 sizeof(struct sgentry
);
2104 if (dev
->dac_support
) {
2105 dev
->a_ops
.adapter_read
= aac_read_block64
;
2106 dev
->a_ops
.adapter_write
= aac_write_block64
;
2108 * 38 scatter gather elements
2110 dev
->scsi_host_ptr
->sg_tablesize
=
2111 (dev
->max_fib_size
-
2112 sizeof(struct aac_fibhdr
) -
2113 sizeof(struct aac_write64
) +
2114 sizeof(struct sgentry64
)) /
2115 sizeof(struct sgentry64
);
2117 dev
->a_ops
.adapter_read
= aac_read_block
;
2118 dev
->a_ops
.adapter_write
= aac_write_block
;
2120 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
2121 if (!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
2123 * Worst case size that could cause sg overflow when
2124 * we break up SG elements that are larger than 64KB.
2125 * Would be nice if we could tell the SCSI layer what
2126 * the maximum SG element size can be. Worst case is
2127 * (sg_tablesize-1) 4KB elements with one 64KB
2129 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2131 dev
->scsi_host_ptr
->max_sectors
=
2132 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
2135 if (!dev
->sync_mode
&& dev
->sa_firmware
&&
2136 dev
->scsi_host_ptr
->sg_tablesize
> HBA_MAX_SG_SEPARATE
)
2137 dev
->scsi_host_ptr
->sg_tablesize
= dev
->sg_tablesize
=
2138 HBA_MAX_SG_SEPARATE
;
2140 /* FIB should be freed only after getting the response from the F/W */
2141 if (rcode
!= -ERESTARTSYS
) {
2142 aac_fib_complete(fibptr
);
2143 aac_fib_free(fibptr
);
2150 static void io_callback(void *context
, struct fib
* fibptr
)
2152 struct aac_dev
*dev
;
2153 struct aac_read_reply
*readreply
;
2154 struct scsi_cmnd
*scsicmd
;
2157 scsicmd
= (struct scsi_cmnd
*) context
;
2159 if (!aac_valid_context(scsicmd
, fibptr
))
2163 cid
= scmd_id(scsicmd
);
2165 if (nblank(dprintk(x
))) {
2167 switch (scsicmd
->cmnd
[0]) {
2170 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
2171 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2175 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2176 ((u64
)scsicmd
->cmnd
[3] << 48) |
2177 ((u64
)scsicmd
->cmnd
[4] << 40) |
2178 ((u64
)scsicmd
->cmnd
[5] << 32) |
2179 ((u64
)scsicmd
->cmnd
[6] << 24) |
2180 (scsicmd
->cmnd
[7] << 16) |
2181 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2185 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2186 (scsicmd
->cmnd
[3] << 16) |
2187 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2190 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2191 (scsicmd
->cmnd
[3] << 16) |
2192 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2196 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2197 smp_processor_id(), (unsigned long long)lba
, jiffies
);
2200 BUG_ON(fibptr
== NULL
);
2202 scsi_dma_unmap(scsicmd
);
2204 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
2205 switch (le32_to_cpu(readreply
->status
)) {
2207 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2209 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
2212 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2213 SAM_STAT_CHECK_CONDITION
;
2214 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
2215 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
2216 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2217 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2218 SCSI_SENSE_BUFFERSIZE
));
2221 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2222 SAM_STAT_CHECK_CONDITION
;
2223 set_sense(&dev
->fsa_dev
[cid
].sense_data
, MEDIUM_ERROR
,
2224 SENCODE_UNRECOVERED_READ_ERROR
, ASENCODE_NO_SENSE
, 0, 0);
2225 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2226 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2227 SCSI_SENSE_BUFFERSIZE
));
2230 #ifdef AAC_DETAILED_STATUS_INFO
2231 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
2232 le32_to_cpu(readreply
->status
));
2234 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2235 SAM_STAT_CHECK_CONDITION
;
2236 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2237 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2238 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2239 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2240 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2241 SCSI_SENSE_BUFFERSIZE
));
2244 aac_fib_complete(fibptr
);
2246 scsicmd
->scsi_done(scsicmd
);
2249 static int aac_read(struct scsi_cmnd
* scsicmd
)
2254 struct aac_dev
*dev
;
2255 struct fib
* cmd_fibcontext
;
2258 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2260 * Get block address and transfer length
2262 switch (scsicmd
->cmnd
[0]) {
2264 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
2266 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
2267 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2268 count
= scsicmd
->cmnd
[4];
2274 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
2276 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2277 ((u64
)scsicmd
->cmnd
[3] << 48) |
2278 ((u64
)scsicmd
->cmnd
[4] << 40) |
2279 ((u64
)scsicmd
->cmnd
[5] << 32) |
2280 ((u64
)scsicmd
->cmnd
[6] << 24) |
2281 (scsicmd
->cmnd
[7] << 16) |
2282 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2283 count
= (scsicmd
->cmnd
[10] << 24) |
2284 (scsicmd
->cmnd
[11] << 16) |
2285 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2288 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
2290 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2291 (scsicmd
->cmnd
[3] << 16) |
2292 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2293 count
= (scsicmd
->cmnd
[6] << 24) |
2294 (scsicmd
->cmnd
[7] << 16) |
2295 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2298 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
2300 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
2301 (scsicmd
->cmnd
[3] << 16) |
2302 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2303 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2307 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2308 cid
= scmd_id(scsicmd
);
2309 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2310 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2311 SAM_STAT_CHECK_CONDITION
;
2312 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2313 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2314 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2315 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2316 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2317 SCSI_SENSE_BUFFERSIZE
));
2318 scsicmd
->scsi_done(scsicmd
);
2322 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
2323 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2324 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2327 * Alocate and initialize a Fib
2329 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2331 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
2334 * Check that the command queued to the controller
2336 if (status
== -EINPROGRESS
) {
2337 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2341 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
2343 * For some reason, the Fib didn't queue, return QUEUE_FULL
2345 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2346 scsicmd
->scsi_done(scsicmd
);
2347 aac_fib_complete(cmd_fibcontext
);
2348 aac_fib_free(cmd_fibcontext
);
2352 static int aac_write(struct scsi_cmnd
* scsicmd
)
2358 struct aac_dev
*dev
;
2359 struct fib
* cmd_fibcontext
;
2362 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2364 * Get block address and transfer length
2366 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
2368 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
2369 count
= scsicmd
->cmnd
[4];
2373 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
2374 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
2376 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2377 ((u64
)scsicmd
->cmnd
[3] << 48) |
2378 ((u64
)scsicmd
->cmnd
[4] << 40) |
2379 ((u64
)scsicmd
->cmnd
[5] << 32) |
2380 ((u64
)scsicmd
->cmnd
[6] << 24) |
2381 (scsicmd
->cmnd
[7] << 16) |
2382 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2383 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
2384 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2385 fua
= scsicmd
->cmnd
[1] & 0x8;
2386 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
2387 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
2389 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
2390 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2391 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
2392 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2393 fua
= scsicmd
->cmnd
[1] & 0x8;
2395 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
2396 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2397 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2398 fua
= scsicmd
->cmnd
[1] & 0x8;
2401 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2402 cid
= scmd_id(scsicmd
);
2403 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2404 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2405 SAM_STAT_CHECK_CONDITION
;
2406 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2407 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2408 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2409 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2410 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2411 SCSI_SENSE_BUFFERSIZE
));
2412 scsicmd
->scsi_done(scsicmd
);
2416 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2417 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2418 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2421 * Allocate and initialize a Fib then setup a BlockWrite command
2423 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2425 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
2428 * Check that the command queued to the controller
2430 if (status
== -EINPROGRESS
) {
2431 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2435 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
2437 * For some reason, the Fib didn't queue, return QUEUE_FULL
2439 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2440 scsicmd
->scsi_done(scsicmd
);
2442 aac_fib_complete(cmd_fibcontext
);
2443 aac_fib_free(cmd_fibcontext
);
2447 static void synchronize_callback(void *context
, struct fib
*fibptr
)
2449 struct aac_synchronize_reply
*synchronizereply
;
2450 struct scsi_cmnd
*cmd
;
2454 if (!aac_valid_context(cmd
, fibptr
))
2457 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
2458 smp_processor_id(), jiffies
));
2459 BUG_ON(fibptr
== NULL
);
2462 synchronizereply
= fib_data(fibptr
);
2463 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
2464 cmd
->result
= DID_OK
<< 16 |
2465 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2467 struct scsi_device
*sdev
= cmd
->device
;
2468 struct aac_dev
*dev
= fibptr
->dev
;
2469 u32 cid
= sdev_id(sdev
);
2471 "synchronize_callback: synchronize failed, status = %d\n",
2472 le32_to_cpu(synchronizereply
->status
));
2473 cmd
->result
= DID_OK
<< 16 |
2474 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2475 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2476 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2477 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2478 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2479 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2480 SCSI_SENSE_BUFFERSIZE
));
2483 aac_fib_complete(fibptr
);
2484 aac_fib_free(fibptr
);
2485 cmd
->scsi_done(cmd
);
2488 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
2491 struct fib
*cmd_fibcontext
;
2492 struct aac_synchronize
*synchronizecmd
;
2493 struct scsi_cmnd
*cmd
;
2494 struct scsi_device
*sdev
= scsicmd
->device
;
2496 struct aac_dev
*aac
;
2497 u64 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) |
2498 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2499 u32 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2500 unsigned long flags
;
2503 * Wait for all outstanding queued commands to complete to this
2504 * specific target (block).
2506 spin_lock_irqsave(&sdev
->list_lock
, flags
);
2507 list_for_each_entry(cmd
, &sdev
->cmd_list
, list
)
2508 if (cmd
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
2512 if (cmd
->cmnd
[0] == WRITE_6
) {
2513 cmnd_lba
= ((cmd
->cmnd
[1] & 0x1F) << 16) |
2514 (cmd
->cmnd
[2] << 8) |
2516 cmnd_count
= cmd
->cmnd
[4];
2517 if (cmnd_count
== 0)
2519 } else if (cmd
->cmnd
[0] == WRITE_16
) {
2520 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 56) |
2521 ((u64
)cmd
->cmnd
[3] << 48) |
2522 ((u64
)cmd
->cmnd
[4] << 40) |
2523 ((u64
)cmd
->cmnd
[5] << 32) |
2524 ((u64
)cmd
->cmnd
[6] << 24) |
2525 (cmd
->cmnd
[7] << 16) |
2526 (cmd
->cmnd
[8] << 8) |
2528 cmnd_count
= (cmd
->cmnd
[10] << 24) |
2529 (cmd
->cmnd
[11] << 16) |
2530 (cmd
->cmnd
[12] << 8) |
2532 } else if (cmd
->cmnd
[0] == WRITE_12
) {
2533 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2534 (cmd
->cmnd
[3] << 16) |
2535 (cmd
->cmnd
[4] << 8) |
2537 cmnd_count
= (cmd
->cmnd
[6] << 24) |
2538 (cmd
->cmnd
[7] << 16) |
2539 (cmd
->cmnd
[8] << 8) |
2541 } else if (cmd
->cmnd
[0] == WRITE_10
) {
2542 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2543 (cmd
->cmnd
[3] << 16) |
2544 (cmd
->cmnd
[4] << 8) |
2546 cmnd_count
= (cmd
->cmnd
[7] << 8) |
2550 if (((cmnd_lba
+ cmnd_count
) < lba
) ||
2551 (count
&& ((lba
+ count
) < cmnd_lba
)))
2557 spin_unlock_irqrestore(&sdev
->list_lock
, flags
);
2560 * Yield the processor (requeue for later)
2563 return SCSI_MLQUEUE_DEVICE_BUSY
;
2565 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2567 return SCSI_MLQUEUE_HOST_BUSY
;
2570 * Allocate and initialize a Fib
2572 if (!(cmd_fibcontext
= aac_fib_alloc(aac
)))
2573 return SCSI_MLQUEUE_HOST_BUSY
;
2575 aac_fib_init(cmd_fibcontext
);
2577 synchronizecmd
= fib_data(cmd_fibcontext
);
2578 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2579 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
2580 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
2581 synchronizecmd
->count
=
2582 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
2585 * Now send the Fib to the adapter
2587 status
= aac_fib_send(ContainerCommand
,
2589 sizeof(struct aac_synchronize
),
2592 (fib_callback
)synchronize_callback
,
2596 * Check that the command queued to the controller
2598 if (status
== -EINPROGRESS
) {
2599 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2604 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
2605 aac_fib_complete(cmd_fibcontext
);
2606 aac_fib_free(cmd_fibcontext
);
2607 return SCSI_MLQUEUE_HOST_BUSY
;
2610 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
2612 struct scsi_cmnd
*scsicmd
= context
;
2614 if (!aac_valid_context(scsicmd
, fibptr
))
2617 BUG_ON(fibptr
== NULL
);
2619 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2621 aac_fib_complete(fibptr
);
2622 aac_fib_free(fibptr
);
2623 scsicmd
->scsi_done(scsicmd
);
2626 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
2629 struct fib
*cmd_fibcontext
;
2630 struct aac_power_management
*pmcmd
;
2631 struct scsi_device
*sdev
= scsicmd
->device
;
2632 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2634 if (!(aac
->supplement_adapter_info
.SupportedOptions2
&
2635 AAC_OPTION_POWER_MANAGEMENT
)) {
2636 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2638 scsicmd
->scsi_done(scsicmd
);
2643 return SCSI_MLQUEUE_HOST_BUSY
;
2646 * Allocate and initialize a Fib
2648 cmd_fibcontext
= aac_fib_alloc_tag(aac
, scsicmd
);
2650 aac_fib_init(cmd_fibcontext
);
2652 pmcmd
= fib_data(cmd_fibcontext
);
2653 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2654 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
2655 /* Eject bit ignored, not relevant */
2656 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
2657 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
2658 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
2659 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
2660 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
2663 * Now send the Fib to the adapter
2665 status
= aac_fib_send(ContainerCommand
,
2667 sizeof(struct aac_power_management
),
2670 (fib_callback
)aac_start_stop_callback
,
2674 * Check that the command queued to the controller
2676 if (status
== -EINPROGRESS
) {
2677 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2681 aac_fib_complete(cmd_fibcontext
);
2682 aac_fib_free(cmd_fibcontext
);
2683 return SCSI_MLQUEUE_HOST_BUSY
;
2687 * aac_scsi_cmd() - Process SCSI command
2688 * @scsicmd: SCSI command block
2690 * Emulate a SCSI command and queue the required request for the
2694 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
2697 struct Scsi_Host
*host
= scsicmd
->device
->host
;
2698 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
2699 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
2701 if (fsa_dev_ptr
== NULL
)
2704 * If the bus, id or lun is out of range, return fail
2705 * Test does not apply to ID 16, the pseudo id for the controller
2708 cid
= scmd_id(scsicmd
);
2709 if (cid
!= host
->this_id
) {
2710 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
2711 if((cid
>= dev
->maximum_num_containers
) ||
2712 (scsicmd
->device
->lun
!= 0)) {
2713 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2718 * If the target container doesn't exist, it may have
2719 * been newly created
2721 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2722 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2724 switch (scsicmd
->cmnd
[0]) {
2725 case SERVICE_ACTION_IN_16
:
2726 if (!(dev
->raw_io_interface
) ||
2727 !(dev
->raw_io_64
) ||
2728 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2732 case TEST_UNIT_READY
:
2735 return _aac_probe_container(scsicmd
,
2736 aac_probe_container_callback2
);
2741 } else { /* check for physical non-dasd devices */
2742 bus
= aac_logical_to_phys(scmd_channel(scsicmd
));
2743 if (bus
< AAC_MAX_BUSES
&& cid
< AAC_MAX_TARGETS
&&
2744 (dev
->hba_map
[bus
][cid
].expose
2746 if (scsicmd
->cmnd
[0] == INQUIRY
) {
2747 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2752 if (bus
< AAC_MAX_BUSES
&& cid
< AAC_MAX_TARGETS
&&
2753 dev
->hba_map
[bus
][cid
].devtype
2754 == AAC_DEVTYPE_NATIVE_RAW
) {
2757 return aac_send_hba_fib(scsicmd
);
2758 } else if (dev
->nondasd_support
|| expose_physicals
||
2762 return aac_send_srb_fib(scsicmd
);
2764 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2770 * else Command for the controller itself
2772 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2773 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2775 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2776 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2777 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2778 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2779 ASENCODE_INVALID_COMMAND
, 0, 0);
2780 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2781 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2782 SCSI_SENSE_BUFFERSIZE
));
2786 switch (scsicmd
->cmnd
[0]) {
2793 return aac_read(scsicmd
);
2801 return aac_write(scsicmd
);
2803 case SYNCHRONIZE_CACHE
:
2804 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2805 scsicmd
->result
= AAC_STAT_GOOD
;
2808 /* Issue FIB to tell Firmware to flush it's cache */
2809 if ((aac_cache
& 6) != 2)
2810 return aac_synchronize(scsicmd
);
2813 struct inquiry_data inq_data
;
2815 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2816 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2818 if ((scsicmd
->cmnd
[1] & 0x1) && aac_wwn
) {
2819 char *arr
= (char *)&inq_data
;
2822 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2823 INQD_PDT_PROC
: INQD_PDT_DA
;
2824 if (scsicmd
->cmnd
[2] == 0) {
2825 /* supported vital product data pages */
2830 arr
[1] = scsicmd
->cmnd
[2];
2831 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2833 scsicmd
->result
= AAC_STAT_GOOD
;
2834 } else if (scsicmd
->cmnd
[2] == 0x80) {
2835 /* unit serial number page */
2836 arr
[3] = setinqserial(dev
, &arr
[4],
2838 arr
[1] = scsicmd
->cmnd
[2];
2839 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2842 return aac_get_container_serial(
2844 scsicmd
->result
= AAC_STAT_GOOD
;
2845 } else if (scsicmd
->cmnd
[2] == 0x83) {
2846 /* vpd page 0x83 - Device Identification Page */
2847 char *sno
= (char *)&inq_data
;
2848 sno
[3] = setinqserial(dev
, &sno
[4],
2851 return aac_get_container_serial(
2853 scsicmd
->result
= AAC_STAT_GOOD
;
2855 /* vpd page not implemented */
2856 scsicmd
->result
= DID_OK
<< 16 |
2857 COMMAND_COMPLETE
<< 8 |
2858 SAM_STAT_CHECK_CONDITION
;
2859 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2860 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2861 ASENCODE_NO_SENSE
, 7, 2);
2862 memcpy(scsicmd
->sense_buffer
,
2863 &dev
->fsa_dev
[cid
].sense_data
,
2865 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2866 SCSI_SENSE_BUFFERSIZE
));
2870 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2871 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 */
2872 inq_data
.inqd_len
= 31;
2873 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2874 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2876 * Set the Vendor, Product, and Revision Level
2877 * see: <vendor>.c i.e. aac.c
2879 if (cid
== host
->this_id
) {
2880 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2881 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2882 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2884 scsicmd
->result
= AAC_STAT_GOOD
;
2889 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2890 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2891 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2892 return aac_get_container_name(scsicmd
);
2894 case SERVICE_ACTION_IN_16
:
2895 if (!(dev
->raw_io_interface
) ||
2896 !(dev
->raw_io_64
) ||
2897 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2902 unsigned int alloc_len
;
2904 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2905 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2906 cp
[0] = (capacity
>> 56) & 0xff;
2907 cp
[1] = (capacity
>> 48) & 0xff;
2908 cp
[2] = (capacity
>> 40) & 0xff;
2909 cp
[3] = (capacity
>> 32) & 0xff;
2910 cp
[4] = (capacity
>> 24) & 0xff;
2911 cp
[5] = (capacity
>> 16) & 0xff;
2912 cp
[6] = (capacity
>> 8) & 0xff;
2913 cp
[7] = (capacity
>> 0) & 0xff;
2914 cp
[8] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2915 cp
[9] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2916 cp
[10] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2917 cp
[11] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2920 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
2921 + (scsicmd
->cmnd
[11] << 16)
2922 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
2924 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
2925 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
2926 if (alloc_len
< scsi_bufflen(scsicmd
))
2927 scsi_set_resid(scsicmd
,
2928 scsi_bufflen(scsicmd
) - alloc_len
);
2930 /* Do not cache partition table for arrays */
2931 scsicmd
->device
->removable
= 1;
2933 scsicmd
->result
= AAC_STAT_GOOD
;
2942 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
2943 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2944 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2948 cp
[0] = (capacity
>> 24) & 0xff;
2949 cp
[1] = (capacity
>> 16) & 0xff;
2950 cp
[2] = (capacity
>> 8) & 0xff;
2951 cp
[3] = (capacity
>> 0) & 0xff;
2952 cp
[4] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2953 cp
[5] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2954 cp
[6] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2955 cp
[7] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2956 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
2957 /* Do not cache partition table for arrays */
2958 scsicmd
->device
->removable
= 1;
2959 scsicmd
->result
= AAC_STAT_GOOD
;
2965 int mode_buf_length
= 4;
2969 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2970 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2974 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
2975 memset((char *)&mpd
, 0, sizeof(aac_modep_data
));
2977 /* Mode data length */
2978 mpd
.hd
.data_length
= sizeof(mpd
.hd
) - 1;
2979 /* Medium type - default */
2980 mpd
.hd
.med_type
= 0;
2981 /* Device-specific param,
2982 bit 8: 0/1 = write enabled/protected
2983 bit 4: 0/1 = FUA enabled */
2986 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2987 mpd
.hd
.dev_par
= 0x10;
2988 if (scsicmd
->cmnd
[1] & 0x8)
2989 mpd
.hd
.bd_length
= 0; /* Block descriptor length */
2991 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
2992 mpd
.hd
.data_length
+= mpd
.hd
.bd_length
;
2993 mpd
.bd
.block_length
[0] =
2994 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2995 mpd
.bd
.block_length
[1] =
2996 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2997 mpd
.bd
.block_length
[2] =
2998 fsa_dev_ptr
[cid
].block_size
& 0xff;
3000 mpd
.mpc_buf
[0] = scsicmd
->cmnd
[2];
3001 if (scsicmd
->cmnd
[2] == 0x1C) {
3003 mpd
.mpc_buf
[1] = 0xa;
3004 /* Mode data length */
3005 mpd
.hd
.data_length
= 23;
3007 /* Mode data length */
3008 mpd
.hd
.data_length
= 15;
3011 if (capacity
> 0xffffff) {
3012 mpd
.bd
.block_count
[0] = 0xff;
3013 mpd
.bd
.block_count
[1] = 0xff;
3014 mpd
.bd
.block_count
[2] = 0xff;
3016 mpd
.bd
.block_count
[0] = (capacity
>> 16) & 0xff;
3017 mpd
.bd
.block_count
[1] = (capacity
>> 8) & 0xff;
3018 mpd
.bd
.block_count
[2] = capacity
& 0xff;
3021 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
3022 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
3023 mpd
.hd
.data_length
+= 3;
3026 mpd
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
3027 ? 0 : 0x04; /* WCE */
3028 mode_buf_length
= sizeof(mpd
);
3031 if (mode_buf_length
> scsicmd
->cmnd
[4])
3032 mode_buf_length
= scsicmd
->cmnd
[4];
3034 mode_buf_length
= sizeof(mpd
);
3035 scsi_sg_copy_from_buffer(scsicmd
,
3038 scsicmd
->result
= AAC_STAT_GOOD
;
3044 int mode_buf_length
= 8;
3045 aac_modep10_data mpd10
;
3047 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
3048 capacity
= fsa_dev_ptr
[cid
].size
- 1;
3052 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
3053 memset((char *)&mpd10
, 0, sizeof(aac_modep10_data
));
3054 /* Mode data length (MSB) */
3055 mpd10
.hd
.data_length
[0] = 0;
3056 /* Mode data length (LSB) */
3057 mpd10
.hd
.data_length
[1] = sizeof(mpd10
.hd
) - 1;
3058 /* Medium type - default */
3059 mpd10
.hd
.med_type
= 0;
3060 /* Device-specific param,
3061 bit 8: 0/1 = write enabled/protected
3062 bit 4: 0/1 = FUA enabled */
3063 mpd10
.hd
.dev_par
= 0;
3065 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
3066 mpd10
.hd
.dev_par
= 0x10;
3067 mpd10
.hd
.rsrvd
[0] = 0; /* reserved */
3068 mpd10
.hd
.rsrvd
[1] = 0; /* reserved */
3069 if (scsicmd
->cmnd
[1] & 0x8) {
3070 /* Block descriptor length (MSB) */
3071 mpd10
.hd
.bd_length
[0] = 0;
3072 /* Block descriptor length (LSB) */
3073 mpd10
.hd
.bd_length
[1] = 0;
3075 mpd10
.hd
.bd_length
[0] = 0;
3076 mpd10
.hd
.bd_length
[1] = sizeof(mpd10
.bd
);
3078 mpd10
.hd
.data_length
[1] += mpd10
.hd
.bd_length
[1];
3080 mpd10
.bd
.block_length
[0] =
3081 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
3082 mpd10
.bd
.block_length
[1] =
3083 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
3084 mpd10
.bd
.block_length
[2] =
3085 fsa_dev_ptr
[cid
].block_size
& 0xff;
3087 if (capacity
> 0xffffff) {
3088 mpd10
.bd
.block_count
[0] = 0xff;
3089 mpd10
.bd
.block_count
[1] = 0xff;
3090 mpd10
.bd
.block_count
[2] = 0xff;
3092 mpd10
.bd
.block_count
[0] =
3093 (capacity
>> 16) & 0xff;
3094 mpd10
.bd
.block_count
[1] =
3095 (capacity
>> 8) & 0xff;
3096 mpd10
.bd
.block_count
[2] =
3100 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
3101 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
3102 mpd10
.hd
.data_length
[1] += 3;
3103 mpd10
.mpc_buf
[0] = 8;
3104 mpd10
.mpc_buf
[1] = 1;
3105 mpd10
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
3106 ? 0 : 0x04; /* WCE */
3107 mode_buf_length
= sizeof(mpd10
);
3108 if (mode_buf_length
> scsicmd
->cmnd
[8])
3109 mode_buf_length
= scsicmd
->cmnd
[8];
3111 scsi_sg_copy_from_buffer(scsicmd
,
3115 scsicmd
->result
= AAC_STAT_GOOD
;
3119 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
3120 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
3121 sizeof(struct sense_data
));
3122 memset(&dev
->fsa_dev
[cid
].sense_data
, 0,
3123 sizeof(struct sense_data
));
3124 scsicmd
->result
= AAC_STAT_GOOD
;
3127 case ALLOW_MEDIUM_REMOVAL
:
3128 dprintk((KERN_DEBUG
"LOCK command.\n"));
3129 if (scsicmd
->cmnd
[4])
3130 fsa_dev_ptr
[cid
].locked
= 1;
3132 fsa_dev_ptr
[cid
].locked
= 0;
3134 scsicmd
->result
= AAC_STAT_GOOD
;
3137 * These commands are all No-Ops
3139 case TEST_UNIT_READY
:
3140 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
3141 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3142 SAM_STAT_CHECK_CONDITION
;
3143 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
3144 NOT_READY
, SENCODE_BECOMING_READY
,
3145 ASENCODE_BECOMING_READY
, 0, 0);
3146 memcpy(scsicmd
->sense_buffer
,
3147 &dev
->fsa_dev
[cid
].sense_data
,
3149 sizeof(dev
->fsa_dev
[cid
].sense_data
),
3150 SCSI_SENSE_BUFFERSIZE
));
3156 case REASSIGN_BLOCKS
:
3158 scsicmd
->result
= AAC_STAT_GOOD
;
3162 return aac_start_stop(scsicmd
);
3167 * Unhandled commands
3169 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n",
3171 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
3172 SAM_STAT_CHECK_CONDITION
;
3173 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
3174 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
3175 ASENCODE_INVALID_COMMAND
, 0, 0);
3176 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
3178 sizeof(dev
->fsa_dev
[cid
].sense_data
),
3179 SCSI_SENSE_BUFFERSIZE
));
3184 scsicmd
->scsi_done(scsicmd
);
3188 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
3190 struct aac_query_disk qd
;
3191 struct fsa_dev_info
*fsa_dev_ptr
;
3193 fsa_dev_ptr
= dev
->fsa_dev
;
3196 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
3200 else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1))
3202 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
3204 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
3206 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
3207 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
3209 else return -EINVAL
;
3211 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
3212 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
3213 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
3215 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
3220 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
3221 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
3223 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
3228 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
3230 struct aac_delete_disk dd
;
3231 struct fsa_dev_info
*fsa_dev_ptr
;
3233 fsa_dev_ptr
= dev
->fsa_dev
;
3237 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
3240 if (dd
.cnum
>= dev
->maximum_num_containers
)
3243 * Mark this container as being deleted.
3245 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
3247 * Mark the container as no longer valid
3249 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
3253 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
3255 struct aac_delete_disk dd
;
3256 struct fsa_dev_info
*fsa_dev_ptr
;
3258 fsa_dev_ptr
= dev
->fsa_dev
;
3262 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
3265 if (dd
.cnum
>= dev
->maximum_num_containers
)
3268 * If the container is locked, it can not be deleted by the API.
3270 if (fsa_dev_ptr
[dd
.cnum
].locked
)
3274 * Mark the container as no longer being valid.
3276 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
3277 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
3282 int aac_dev_ioctl(struct aac_dev
*dev
, int cmd
, void __user
*arg
)
3285 case FSACTL_QUERY_DISK
:
3286 return query_disk(dev
, arg
);
3287 case FSACTL_DELETE_DISK
:
3288 return delete_disk(dev
, arg
);
3289 case FSACTL_FORCE_DELETE_DISK
:
3290 return force_delete_disk(dev
, arg
);
3291 case FSACTL_GET_CONTAINERS
:
3292 return aac_get_containers(dev
);
3301 * @context: the context set in the fib - here it is scsi cmd
3302 * @fibptr: pointer to the fib
3304 * Handles the completion of a scsi command to a non dasd device
3308 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
3310 struct aac_dev
*dev
;
3311 struct aac_srb_reply
*srbreply
;
3312 struct scsi_cmnd
*scsicmd
;
3314 scsicmd
= (struct scsi_cmnd
*) context
;
3316 if (!aac_valid_context(scsicmd
, fibptr
))
3319 BUG_ON(fibptr
== NULL
);
3323 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
3325 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
3327 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
3329 srbreply
->srb_status
= cpu_to_le32(SRB_STATUS_SUCCESS
);
3330 srbreply
->scsi_status
= cpu_to_le32(SAM_STAT_GOOD
);
3333 * Calculate resid for sg
3335 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
3336 - le32_to_cpu(srbreply
->data_xfer_length
));
3340 scsi_dma_unmap(scsicmd
);
3342 /* expose physical device if expose_physicald flag is on */
3343 if (scsicmd
->cmnd
[0] == INQUIRY
&& !(scsicmd
->cmnd
[1] & 0x01)
3344 && expose_physicals
> 0)
3345 aac_expose_phy_device(scsicmd
);
3348 * First check the fib status
3351 if (le32_to_cpu(srbreply
->status
) != ST_OK
) {
3354 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3355 le32_to_cpu(srbreply
->status
));
3356 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3357 SCSI_SENSE_BUFFERSIZE
);
3358 scsicmd
->result
= DID_ERROR
<< 16
3359 | COMMAND_COMPLETE
<< 8
3360 | SAM_STAT_CHECK_CONDITION
;
3361 memcpy(scsicmd
->sense_buffer
,
3362 srbreply
->sense_data
, len
);
3366 * Next check the srb status
3368 switch ((le32_to_cpu(srbreply
->srb_status
))&0x3f) {
3369 case SRB_STATUS_ERROR_RECOVERY
:
3370 case SRB_STATUS_PENDING
:
3371 case SRB_STATUS_SUCCESS
:
3372 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3374 case SRB_STATUS_DATA_OVERRUN
:
3375 switch (scsicmd
->cmnd
[0]) {
3384 if (le32_to_cpu(srbreply
->data_xfer_length
)
3385 < scsicmd
->underflow
)
3386 pr_warn("aacraid: SCSI CMD underflow\n");
3388 pr_warn("aacraid: SCSI CMD Data Overrun\n");
3389 scsicmd
->result
= DID_ERROR
<< 16
3390 | COMMAND_COMPLETE
<< 8;
3393 scsicmd
->result
= DID_OK
<< 16
3394 | COMMAND_COMPLETE
<< 8;
3397 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3401 case SRB_STATUS_ABORTED
:
3402 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3404 case SRB_STATUS_ABORT_FAILED
:
3406 * Not sure about this one - but assuming the
3407 * hba was trying to abort for some reason
3409 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
3411 case SRB_STATUS_PARITY_ERROR
:
3412 scsicmd
->result
= DID_PARITY
<< 16
3413 | MSG_PARITY_ERROR
<< 8;
3415 case SRB_STATUS_NO_DEVICE
:
3416 case SRB_STATUS_INVALID_PATH_ID
:
3417 case SRB_STATUS_INVALID_TARGET_ID
:
3418 case SRB_STATUS_INVALID_LUN
:
3419 case SRB_STATUS_SELECTION_TIMEOUT
:
3420 scsicmd
->result
= DID_NO_CONNECT
<< 16
3421 | COMMAND_COMPLETE
<< 8;
3424 case SRB_STATUS_COMMAND_TIMEOUT
:
3425 case SRB_STATUS_TIMEOUT
:
3426 scsicmd
->result
= DID_TIME_OUT
<< 16
3427 | COMMAND_COMPLETE
<< 8;
3430 case SRB_STATUS_BUSY
:
3431 scsicmd
->result
= DID_BUS_BUSY
<< 16
3432 | COMMAND_COMPLETE
<< 8;
3435 case SRB_STATUS_BUS_RESET
:
3436 scsicmd
->result
= DID_RESET
<< 16
3437 | COMMAND_COMPLETE
<< 8;
3440 case SRB_STATUS_MESSAGE_REJECTED
:
3441 scsicmd
->result
= DID_ERROR
<< 16
3442 | MESSAGE_REJECT
<< 8;
3444 case SRB_STATUS_REQUEST_FLUSHED
:
3445 case SRB_STATUS_ERROR
:
3446 case SRB_STATUS_INVALID_REQUEST
:
3447 case SRB_STATUS_REQUEST_SENSE_FAILED
:
3448 case SRB_STATUS_NO_HBA
:
3449 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
3450 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
3451 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
3452 case SRB_STATUS_DELAYED_RETRY
:
3453 case SRB_STATUS_BAD_FUNCTION
:
3454 case SRB_STATUS_NOT_STARTED
:
3455 case SRB_STATUS_NOT_IN_USE
:
3456 case SRB_STATUS_FORCE_ABORT
:
3457 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
3459 #ifdef AAC_DETAILED_STATUS_INFO
3460 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3461 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
3462 aac_get_status_string(
3463 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
3465 le32_to_cpu(srbreply
->scsi_status
));
3468 * When the CC bit is SET by the host in ATA pass thru CDB,
3469 * driver is supposed to return DID_OK
3471 * When the CC bit is RESET by the host, driver should
3474 if ((scsicmd
->cmnd
[0] == ATA_12
)
3475 || (scsicmd
->cmnd
[0] == ATA_16
)) {
3477 if (scsicmd
->cmnd
[2] & (0x01 << 5)) {
3478 scsicmd
->result
= DID_OK
<< 16
3479 | COMMAND_COMPLETE
<< 8;
3482 scsicmd
->result
= DID_ERROR
<< 16
3483 | COMMAND_COMPLETE
<< 8;
3487 scsicmd
->result
= DID_ERROR
<< 16
3488 | COMMAND_COMPLETE
<< 8;
3492 if (le32_to_cpu(srbreply
->scsi_status
)
3493 == SAM_STAT_CHECK_CONDITION
) {
3496 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
3497 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3498 SCSI_SENSE_BUFFERSIZE
);
3499 #ifdef AAC_DETAILED_STATUS_INFO
3500 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3501 le32_to_cpu(srbreply
->status
), len
);
3503 memcpy(scsicmd
->sense_buffer
,
3504 srbreply
->sense_data
, len
);
3508 * OR in the scsi status (already shifted up a bit)
3510 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
3512 aac_fib_complete(fibptr
);
3513 scsicmd
->scsi_done(scsicmd
);
3516 static void hba_resp_task_complete(struct aac_dev
*dev
,
3517 struct scsi_cmnd
*scsicmd
,
3518 struct aac_hba_resp
*err
) {
3520 scsicmd
->result
= err
->status
;
3521 /* set residual count */
3522 scsi_set_resid(scsicmd
, le32_to_cpu(err
->residual_count
));
3524 switch (err
->status
) {
3526 scsicmd
->result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3528 case SAM_STAT_CHECK_CONDITION
:
3532 len
= min_t(u8
, err
->sense_response_data_len
,
3533 SCSI_SENSE_BUFFERSIZE
);
3535 memcpy(scsicmd
->sense_buffer
,
3536 err
->sense_response_buf
, len
);
3537 scsicmd
->result
|= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3541 scsicmd
->result
|= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
3543 case SAM_STAT_TASK_ABORTED
:
3544 scsicmd
->result
|= DID_ABORT
<< 16 | ABORT
<< 8;
3546 case SAM_STAT_RESERVATION_CONFLICT
:
3547 case SAM_STAT_TASK_SET_FULL
:
3549 scsicmd
->result
|= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3554 static void hba_resp_task_failure(struct aac_dev
*dev
,
3555 struct scsi_cmnd
*scsicmd
,
3556 struct aac_hba_resp
*err
)
3558 switch (err
->status
) {
3559 case HBA_RESP_STAT_HBAMODE_DISABLED
:
3563 bus
= aac_logical_to_phys(scmd_channel(scsicmd
));
3564 cid
= scmd_id(scsicmd
);
3565 if (dev
->hba_map
[bus
][cid
].devtype
== AAC_DEVTYPE_NATIVE_RAW
) {
3566 dev
->hba_map
[bus
][cid
].devtype
= AAC_DEVTYPE_ARC_RAW
;
3567 dev
->hba_map
[bus
][cid
].rmw_nexus
= 0xffffffff;
3569 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3572 case HBA_RESP_STAT_IO_ERROR
:
3573 case HBA_RESP_STAT_NO_PATH_TO_DEVICE
:
3574 scsicmd
->result
= DID_OK
<< 16 |
3575 COMMAND_COMPLETE
<< 8 | SAM_STAT_BUSY
;
3577 case HBA_RESP_STAT_IO_ABORTED
:
3578 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3580 case HBA_RESP_STAT_INVALID_DEVICE
:
3581 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3583 case HBA_RESP_STAT_UNDERRUN
:
3584 /* UNDERRUN is OK */
3585 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3587 case HBA_RESP_STAT_OVERRUN
:
3589 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3597 * @context: the context set in the fib - here it is scsi cmd
3598 * @fibptr: pointer to the fib
3600 * Handles the completion of a native HBA scsi command
3603 void aac_hba_callback(void *context
, struct fib
*fibptr
)
3605 struct aac_dev
*dev
;
3606 struct scsi_cmnd
*scsicmd
;
3608 struct aac_hba_resp
*err
=
3609 &((struct aac_native_hba
*)fibptr
->hw_fib_va
)->resp
.err
;
3611 scsicmd
= (struct scsi_cmnd
*) context
;
3613 if (!aac_valid_context(scsicmd
, fibptr
))
3616 WARN_ON(fibptr
== NULL
);
3619 if (!(fibptr
->flags
& FIB_CONTEXT_FLAG_NATIVE_HBA_TMF
))
3620 scsi_dma_unmap(scsicmd
);
3622 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
3624 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3628 switch (err
->service_response
) {
3629 case HBA_RESP_SVCRES_TASK_COMPLETE
:
3630 hba_resp_task_complete(dev
, scsicmd
, err
);
3632 case HBA_RESP_SVCRES_FAILURE
:
3633 hba_resp_task_failure(dev
, scsicmd
, err
);
3635 case HBA_RESP_SVCRES_TMF_REJECTED
:
3636 scsicmd
->result
= DID_ERROR
<< 16 | MESSAGE_REJECT
<< 8;
3638 case HBA_RESP_SVCRES_TMF_LUN_INVALID
:
3639 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
3641 case HBA_RESP_SVCRES_TMF_COMPLETE
:
3642 case HBA_RESP_SVCRES_TMF_SUCCEEDED
:
3643 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3646 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
3651 aac_fib_complete(fibptr
);
3653 if (fibptr
->flags
& FIB_CONTEXT_FLAG_NATIVE_HBA_TMF
)
3654 scsicmd
->SCp
.sent_command
= 1;
3656 scsicmd
->scsi_done(scsicmd
);
3662 * @scsicmd: the scsi command block
3664 * This routine will form a FIB and fill in the aac_srb from the
3665 * scsicmd passed in.
3668 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
3670 struct fib
* cmd_fibcontext
;
3671 struct aac_dev
* dev
;
3674 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3675 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3676 scsicmd
->device
->lun
> 7) {
3677 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3678 scsicmd
->scsi_done(scsicmd
);
3683 * Allocate and initialize a Fib then setup a BlockWrite command
3685 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3687 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
3690 * Check that the command queued to the controller
3692 if (status
== -EINPROGRESS
) {
3693 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3697 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
3698 aac_fib_complete(cmd_fibcontext
);
3699 aac_fib_free(cmd_fibcontext
);
3707 * @scsicmd: the scsi command block
3709 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3710 * scsicmd passed in.
3712 static int aac_send_hba_fib(struct scsi_cmnd
*scsicmd
)
3714 struct fib
*cmd_fibcontext
;
3715 struct aac_dev
*dev
;
3718 dev
= shost_priv(scsicmd
->device
->host
);
3719 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3720 scsicmd
->device
->lun
> AAC_MAX_LUN
- 1) {
3721 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3722 scsicmd
->scsi_done(scsicmd
);
3727 * Allocate and initialize a Fib then setup a BlockWrite command
3729 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3730 if (!cmd_fibcontext
)
3733 status
= aac_adapter_hba(cmd_fibcontext
, scsicmd
);
3736 * Check that the command queued to the controller
3738 if (status
== -EINPROGRESS
) {
3739 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3743 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3745 aac_fib_complete(cmd_fibcontext
);
3746 aac_fib_free(cmd_fibcontext
);
3752 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*psg
)
3754 struct aac_dev
*dev
;
3755 unsigned long byte_count
= 0;
3758 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3759 // Get rid of old data
3761 psg
->sg
[0].addr
= 0;
3762 psg
->sg
[0].count
= 0;
3764 nseg
= scsi_dma_map(scsicmd
);
3768 struct scatterlist
*sg
;
3771 psg
->count
= cpu_to_le32(nseg
);
3773 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3774 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
3775 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
3776 byte_count
+= sg_dma_len(sg
);
3778 /* hba wants the size to be exact */
3779 if (byte_count
> scsi_bufflen(scsicmd
)) {
3780 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3781 (byte_count
- scsi_bufflen(scsicmd
));
3782 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3783 byte_count
= scsi_bufflen(scsicmd
);
3785 /* Check for command underflow */
3786 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3787 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3788 byte_count
, scsicmd
->underflow
);
3795 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
)
3797 struct aac_dev
*dev
;
3798 unsigned long byte_count
= 0;
3802 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3803 // Get rid of old data
3805 psg
->sg
[0].addr
[0] = 0;
3806 psg
->sg
[0].addr
[1] = 0;
3807 psg
->sg
[0].count
= 0;
3809 nseg
= scsi_dma_map(scsicmd
);
3813 struct scatterlist
*sg
;
3816 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3817 int count
= sg_dma_len(sg
);
3818 addr
= sg_dma_address(sg
);
3819 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
3820 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
3821 psg
->sg
[i
].count
= cpu_to_le32(count
);
3822 byte_count
+= count
;
3824 psg
->count
= cpu_to_le32(nseg
);
3825 /* hba wants the size to be exact */
3826 if (byte_count
> scsi_bufflen(scsicmd
)) {
3827 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3828 (byte_count
- scsi_bufflen(scsicmd
));
3829 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3830 byte_count
= scsi_bufflen(scsicmd
);
3832 /* Check for command underflow */
3833 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3834 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3835 byte_count
, scsicmd
->underflow
);
3841 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
)
3843 unsigned long byte_count
= 0;
3846 // Get rid of old data
3848 psg
->sg
[0].next
= 0;
3849 psg
->sg
[0].prev
= 0;
3850 psg
->sg
[0].addr
[0] = 0;
3851 psg
->sg
[0].addr
[1] = 0;
3852 psg
->sg
[0].count
= 0;
3853 psg
->sg
[0].flags
= 0;
3855 nseg
= scsi_dma_map(scsicmd
);
3859 struct scatterlist
*sg
;
3862 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3863 int count
= sg_dma_len(sg
);
3864 u64 addr
= sg_dma_address(sg
);
3865 psg
->sg
[i
].next
= 0;
3866 psg
->sg
[i
].prev
= 0;
3867 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
3868 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
3869 psg
->sg
[i
].count
= cpu_to_le32(count
);
3870 psg
->sg
[i
].flags
= 0;
3871 byte_count
+= count
;
3873 psg
->count
= cpu_to_le32(nseg
);
3874 /* hba wants the size to be exact */
3875 if (byte_count
> scsi_bufflen(scsicmd
)) {
3876 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3877 (byte_count
- scsi_bufflen(scsicmd
));
3878 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3879 byte_count
= scsi_bufflen(scsicmd
);
3881 /* Check for command underflow */
3882 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3883 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3884 byte_count
, scsicmd
->underflow
);
3890 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
3891 struct aac_raw_io2
*rio2
, int sg_max
)
3893 unsigned long byte_count
= 0;
3896 nseg
= scsi_dma_map(scsicmd
);
3900 struct scatterlist
*sg
;
3901 int i
, conformable
= 0;
3902 u32 min_size
= PAGE_SIZE
, cur_size
;
3904 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3905 int count
= sg_dma_len(sg
);
3906 u64 addr
= sg_dma_address(sg
);
3908 BUG_ON(i
>= sg_max
);
3909 rio2
->sge
[i
].addrHigh
= cpu_to_le32((u32
)(addr
>>32));
3910 rio2
->sge
[i
].addrLow
= cpu_to_le32((u32
)(addr
& 0xffffffff));
3911 cur_size
= cpu_to_le32(count
);
3912 rio2
->sge
[i
].length
= cur_size
;
3913 rio2
->sge
[i
].flags
= 0;
3916 rio2
->sgeFirstSize
= cur_size
;
3917 } else if (i
== 1) {
3918 rio2
->sgeNominalSize
= cur_size
;
3919 min_size
= cur_size
;
3920 } else if ((i
+1) < nseg
&& cur_size
!= rio2
->sgeNominalSize
) {
3922 if (cur_size
< min_size
)
3923 min_size
= cur_size
;
3925 byte_count
+= count
;
3928 /* hba wants the size to be exact */
3929 if (byte_count
> scsi_bufflen(scsicmd
)) {
3930 u32 temp
= le32_to_cpu(rio2
->sge
[i
-1].length
) -
3931 (byte_count
- scsi_bufflen(scsicmd
));
3932 rio2
->sge
[i
-1].length
= cpu_to_le32(temp
);
3933 byte_count
= scsi_bufflen(scsicmd
);
3936 rio2
->sgeCnt
= cpu_to_le32(nseg
);
3937 rio2
->flags
|= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212
);
3938 /* not conformable: evaluate required sg elements */
3940 int j
, nseg_new
= nseg
, err_found
;
3941 for (i
= min_size
/ PAGE_SIZE
; i
>= 1; --i
) {
3944 for (j
= 1; j
< nseg
- 1; ++j
) {
3945 if (rio2
->sge
[j
].length
% (i
*PAGE_SIZE
)) {
3949 nseg_new
+= (rio2
->sge
[j
].length
/ (i
*PAGE_SIZE
));
3954 if (i
> 0 && nseg_new
<= sg_max
)
3955 aac_convert_sgraw2(rio2
, i
, nseg
, nseg_new
);
3957 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3959 /* Check for command underflow */
3960 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3961 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3962 byte_count
, scsicmd
->underflow
);
3969 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
, int pages
, int nseg
, int nseg_new
)
3971 struct sge_ieee1212
*sge
;
3975 if (aac_convert_sgl
== 0)
3978 sge
= kmalloc(nseg_new
* sizeof(struct sge_ieee1212
), GFP_ATOMIC
);
3982 for (i
= 1, pos
= 1; i
< nseg
-1; ++i
) {
3983 for (j
= 0; j
< rio2
->sge
[i
].length
/ (pages
* PAGE_SIZE
); ++j
) {
3984 addr_low
= rio2
->sge
[i
].addrLow
+ j
* pages
* PAGE_SIZE
;
3985 sge
[pos
].addrLow
= addr_low
;
3986 sge
[pos
].addrHigh
= rio2
->sge
[i
].addrHigh
;
3987 if (addr_low
< rio2
->sge
[i
].addrLow
)
3988 sge
[pos
].addrHigh
++;
3989 sge
[pos
].length
= pages
* PAGE_SIZE
;
3994 sge
[pos
] = rio2
->sge
[nseg
-1];
3995 memcpy(&rio2
->sge
[1], &sge
[1], (nseg_new
-1)*sizeof(struct sge_ieee1212
));
3998 rio2
->sgeCnt
= cpu_to_le32(nseg_new
);
3999 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
4000 rio2
->sgeNominalSize
= pages
* PAGE_SIZE
;
4004 static long aac_build_sghba(struct scsi_cmnd
*scsicmd
,
4005 struct aac_hba_cmd_req
*hbacmd
,
4009 unsigned long byte_count
= 0;
4011 struct scatterlist
*sg
;
4014 struct aac_hba_sgl
*sge
;
4016 nseg
= scsi_dma_map(scsicmd
);
4022 if (nseg
> HBA_MAX_SG_EMBEDDED
)
4023 sge
= &hbacmd
->sge
[2];
4025 sge
= &hbacmd
->sge
[0];
4027 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
4028 int count
= sg_dma_len(sg
);
4029 u64 addr
= sg_dma_address(sg
);
4031 WARN_ON(i
>= sg_max
);
4032 sge
->addr_hi
= cpu_to_le32((u32
)(addr
>>32));
4033 sge
->addr_lo
= cpu_to_le32((u32
)(addr
& 0xffffffff));
4034 cur_size
= cpu_to_le32(count
);
4035 sge
->len
= cur_size
;
4037 byte_count
+= count
;
4042 /* hba wants the size to be exact */
4043 if (byte_count
> scsi_bufflen(scsicmd
)) {
4046 temp
= le32_to_cpu(sge
->len
) - byte_count
4047 - scsi_bufflen(scsicmd
);
4048 sge
->len
= cpu_to_le32(temp
);
4049 byte_count
= scsi_bufflen(scsicmd
);
4052 if (nseg
<= HBA_MAX_SG_EMBEDDED
) {
4053 hbacmd
->emb_data_desc_count
= cpu_to_le32(nseg
);
4054 sge
->flags
= cpu_to_le32(0x40000000);
4057 hbacmd
->sge
[0].flags
= cpu_to_le32(0x80000000);
4058 hbacmd
->emb_data_desc_count
= (u8
)cpu_to_le32(1);
4059 hbacmd
->sge
[0].addr_hi
= (u32
)cpu_to_le32(sg_address
>> 32);
4060 hbacmd
->sge
[0].addr_lo
=
4061 cpu_to_le32((u32
)(sg_address
& 0xffffffff));
4064 /* Check for command underflow */
4065 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
4066 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4067 byte_count
, scsicmd
->underflow
);
4073 #ifdef AAC_DETAILED_STATUS_INFO
4075 struct aac_srb_status_info
{
4081 static struct aac_srb_status_info srb_status_info
[] = {
4082 { SRB_STATUS_PENDING
, "Pending Status"},
4083 { SRB_STATUS_SUCCESS
, "Success"},
4084 { SRB_STATUS_ABORTED
, "Aborted Command"},
4085 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
4086 { SRB_STATUS_ERROR
, "Error Event"},
4087 { SRB_STATUS_BUSY
, "Device Busy"},
4088 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
4089 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
4090 { SRB_STATUS_NO_DEVICE
, "No Device"},
4091 { SRB_STATUS_TIMEOUT
, "Timeout"},
4092 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
4093 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
4094 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
4095 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
4096 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
4097 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
4098 { SRB_STATUS_NO_HBA
, "No HBA"},
4099 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
4100 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
4101 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
4102 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
4103 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
4104 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
4105 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
4106 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
4107 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
4108 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
4109 { SRB_STATUS_NOT_STARTED
, "Not Started"},
4110 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
4111 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
4112 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
4113 { 0xff, "Unknown Error"}
4116 char *aac_get_status_string(u32 status
)
4120 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
4121 if (srb_status_info
[i
].status
== status
)
4122 return srb_status_info
[i
].str
;
4124 return "Bad Status Code";