2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 #include <linux/slab.h>
33 #include <linux/completion.h>
34 #include <linux/blkdev.h>
35 #include <asm/uaccess.h>
36 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
37 #include <linux/module.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_cmnd.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_host.h>
46 /* values for inqd_pdt: Peripheral device type in plain English */
47 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
48 #define INQD_PDT_PROC 0x03 /* Processor device */
49 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
50 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
51 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
52 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
54 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
55 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
61 #define SENCODE_NO_SENSE 0x00
62 #define SENCODE_END_OF_DATA 0x00
63 #define SENCODE_BECOMING_READY 0x04
64 #define SENCODE_INIT_CMD_REQUIRED 0x04
65 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
66 #define SENCODE_INVALID_COMMAND 0x20
67 #define SENCODE_LBA_OUT_OF_RANGE 0x21
68 #define SENCODE_INVALID_CDB_FIELD 0x24
69 #define SENCODE_LUN_NOT_SUPPORTED 0x25
70 #define SENCODE_INVALID_PARAM_FIELD 0x26
71 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
72 #define SENCODE_PARAM_VALUE_INVALID 0x26
73 #define SENCODE_RESET_OCCURRED 0x29
74 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
75 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
76 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
77 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
78 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
79 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
80 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
81 #define SENCODE_OVERLAPPED_COMMAND 0x4E
84 * Additional sense codes
87 #define ASENCODE_NO_SENSE 0x00
88 #define ASENCODE_END_OF_DATA 0x05
89 #define ASENCODE_BECOMING_READY 0x01
90 #define ASENCODE_INIT_CMD_REQUIRED 0x02
91 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
92 #define ASENCODE_INVALID_COMMAND 0x00
93 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
94 #define ASENCODE_INVALID_CDB_FIELD 0x00
95 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
96 #define ASENCODE_INVALID_PARAM_FIELD 0x00
97 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
98 #define ASENCODE_PARAM_VALUE_INVALID 0x02
99 #define ASENCODE_RESET_OCCURRED 0x00
100 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
101 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
102 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
103 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
104 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
105 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
106 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
107 #define ASENCODE_OVERLAPPED_COMMAND 0x00
109 #define BYTE0(x) (unsigned char)(x)
110 #define BYTE1(x) (unsigned char)((x) >> 8)
111 #define BYTE2(x) (unsigned char)((x) >> 16)
112 #define BYTE3(x) (unsigned char)((x) >> 24)
114 /* MODE_SENSE data format */
121 } __attribute__((packed
)) hd
;
127 } __attribute__((packed
)) bd
;
129 } __attribute__((packed
)) aac_modep_data
;
131 /* MODE_SENSE_10 data format */
139 } __attribute__((packed
)) hd
;
145 } __attribute__((packed
)) bd
;
147 } __attribute__((packed
)) aac_modep10_data
;
149 /*------------------------------------------------------------------------------
150 * S T R U C T S / T Y P E D E F S
151 *----------------------------------------------------------------------------*/
152 /* SCSI inquiry data */
153 struct inquiry_data
{
154 u8 inqd_pdt
; /* Peripheral qualifier | Peripheral Device Type */
155 u8 inqd_dtq
; /* RMB | Device Type Qualifier */
156 u8 inqd_ver
; /* ISO version | ECMA version | ANSI-approved version */
157 u8 inqd_rdf
; /* AENC | TrmIOP | Response data format */
158 u8 inqd_len
; /* Additional length (n-4) */
159 u8 inqd_pad1
[2];/* Reserved - must be zero */
160 u8 inqd_pad2
; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
161 u8 inqd_vid
[8]; /* Vendor ID */
162 u8 inqd_pid
[16];/* Product ID */
163 u8 inqd_prl
[4]; /* Product Revision Level */
166 /* Added for VPD 0x83 */
168 u8 CodeSet
:4; /* VPD_CODE_SET */
170 u8 IdentifierType
:4; /* VPD_IDENTIFIER_TYPE */
176 u8 SerialNumber
[8]; /* SN in ASCII */
178 } TVPD_ID_Descriptor_Type_1
;
181 u8 CodeSet
:4; /* VPD_CODE_SET */
183 u8 IdentifierType
:4; /* VPD_IDENTIFIER_TYPE */
189 /* The serial number supposed to be 40 bits,
190 * bit we only support 32, so make the last byte zero. */
195 } TVPD_ID_Descriptor_Type_2
;
199 u8 DeviceTypeQualifier
:3;
203 TVPD_ID_Descriptor_Type_1 IdDescriptorType1
;
204 TVPD_ID_Descriptor_Type_2 IdDescriptorType2
;
209 * M O D U L E G L O B A L S
212 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*sgmap
);
213 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
);
214 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
);
215 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
216 struct aac_raw_io2
*rio2
, int sg_max
);
217 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
,
218 int pages
, int nseg
, int nseg_new
);
219 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
);
220 #ifdef AAC_DETAILED_STATUS_INFO
221 static char *aac_get_status_string(u32 status
);
225 * Non dasd selection is handled entirely in aachba now
228 static int nondasd
= -1;
229 static int aac_cache
= 2; /* WCE=0 to avoid performance problems */
230 static int dacmode
= -1;
233 int startup_timeout
= 180;
234 int aif_timeout
= 120;
235 int aac_sync_mode
; /* Only Sync. transfer - disabled */
236 int aac_convert_sgl
= 1; /* convert non-conformable s/g list - enabled */
238 module_param(aac_sync_mode
, int, S_IRUGO
|S_IWUSR
);
239 MODULE_PARM_DESC(aac_sync_mode
, "Force sync. transfer mode"
241 module_param(aac_convert_sgl
, int, S_IRUGO
|S_IWUSR
);
242 MODULE_PARM_DESC(aac_convert_sgl
, "Convert non-conformable s/g list"
244 module_param(nondasd
, int, S_IRUGO
|S_IWUSR
);
245 MODULE_PARM_DESC(nondasd
, "Control scanning of hba for nondasd devices."
247 module_param_named(cache
, aac_cache
, int, S_IRUGO
|S_IWUSR
);
248 MODULE_PARM_DESC(cache
, "Disable Queue Flush commands:\n"
249 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
250 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
251 "\tbit 2 - Disable only if Battery is protecting Cache");
252 module_param(dacmode
, int, S_IRUGO
|S_IWUSR
);
253 MODULE_PARM_DESC(dacmode
, "Control whether dma addressing is using 64 bit DAC."
255 module_param_named(commit
, aac_commit
, int, S_IRUGO
|S_IWUSR
);
256 MODULE_PARM_DESC(commit
, "Control whether a COMMIT_CONFIG is issued to the"
257 " adapter for foreign arrays.\n"
258 "This is typically needed in systems that do not have a BIOS."
260 module_param_named(msi
, aac_msi
, int, S_IRUGO
|S_IWUSR
);
261 MODULE_PARM_DESC(msi
, "IRQ handling."
262 " 0=PIC(default), 1=MSI, 2=MSI-X)");
263 module_param(startup_timeout
, int, S_IRUGO
|S_IWUSR
);
264 MODULE_PARM_DESC(startup_timeout
, "The duration of time in seconds to wait for"
265 " adapter to have it's kernel up and\n"
266 "running. This is typically adjusted for large systems that do not"
268 module_param(aif_timeout
, int, S_IRUGO
|S_IWUSR
);
269 MODULE_PARM_DESC(aif_timeout
, "The duration of time in seconds to wait for"
270 " applications to pick up AIFs before\n"
271 "deregistering them. This is typically adjusted for heavily burdened"
275 module_param(numacb
, int, S_IRUGO
|S_IWUSR
);
276 MODULE_PARM_DESC(numacb
, "Request a limit to the number of adapter control"
277 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
278 " to use suggestion from Firmware.");
281 module_param(acbsize
, int, S_IRUGO
|S_IWUSR
);
282 MODULE_PARM_DESC(acbsize
, "Request a specific adapter control block (FIB)"
283 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
284 " suggestion from Firmware.");
286 int update_interval
= 30 * 60;
287 module_param(update_interval
, int, S_IRUGO
|S_IWUSR
);
288 MODULE_PARM_DESC(update_interval
, "Interval in seconds between time sync"
289 " updates issued to adapter.");
291 int check_interval
= 24 * 60 * 60;
292 module_param(check_interval
, int, S_IRUGO
|S_IWUSR
);
293 MODULE_PARM_DESC(check_interval
, "Interval in seconds between adapter health"
296 int aac_check_reset
= 1;
297 module_param_named(check_reset
, aac_check_reset
, int, S_IRUGO
|S_IWUSR
);
298 MODULE_PARM_DESC(check_reset
, "If adapter fails health check, reset the"
299 " adapter. a value of -1 forces the reset to adapters programmed to"
302 int expose_physicals
= -1;
303 module_param(expose_physicals
, int, S_IRUGO
|S_IWUSR
);
304 MODULE_PARM_DESC(expose_physicals
, "Expose physical components of the arrays."
305 " -1=protect 0=off, 1=on");
307 int aac_reset_devices
;
308 module_param_named(reset_devices
, aac_reset_devices
, int, S_IRUGO
|S_IWUSR
);
309 MODULE_PARM_DESC(reset_devices
, "Force an adapter reset at initialization.");
312 module_param_named(wwn
, aac_wwn
, int, S_IRUGO
|S_IWUSR
);
313 MODULE_PARM_DESC(wwn
, "Select a WWN type for the arrays:\n"
315 "\t1 - Array Meta Data Signature (default)\n"
316 "\t2 - Adapter Serial Number");
319 static inline int aac_valid_context(struct scsi_cmnd
*scsicmd
,
320 struct fib
*fibptr
) {
321 struct scsi_device
*device
;
323 if (unlikely(!scsicmd
|| !scsicmd
->scsi_done
)) {
324 dprintk((KERN_WARNING
"aac_valid_context: scsi command corrupt\n"));
325 aac_fib_complete(fibptr
);
328 scsicmd
->SCp
.phase
= AAC_OWNER_MIDLEVEL
;
329 device
= scsicmd
->device
;
330 if (unlikely(!device
|| !scsi_device_online(device
))) {
331 dprintk((KERN_WARNING
"aac_valid_context: scsi device corrupt\n"));
332 aac_fib_complete(fibptr
);
339 * aac_get_config_status - check the adapter configuration
340 * @common: adapter to query
342 * Query config status, and commit the configuration if needed.
344 int aac_get_config_status(struct aac_dev
*dev
, int commit_flag
)
349 if (!(fibptr
= aac_fib_alloc(dev
)))
352 aac_fib_init(fibptr
);
354 struct aac_get_config_status
*dinfo
;
355 dinfo
= (struct aac_get_config_status
*) fib_data(fibptr
);
357 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
358 dinfo
->type
= cpu_to_le32(CT_GET_CONFIG_STATUS
);
359 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_config_status_resp
*)NULL
)->data
));
362 status
= aac_fib_send(ContainerCommand
,
364 sizeof (struct aac_get_config_status
),
369 printk(KERN_WARNING
"aac_get_config_status: SendFIB failed.\n");
371 struct aac_get_config_status_resp
*reply
372 = (struct aac_get_config_status_resp
*) fib_data(fibptr
);
373 dprintk((KERN_WARNING
374 "aac_get_config_status: response=%d status=%d action=%d\n",
375 le32_to_cpu(reply
->response
),
376 le32_to_cpu(reply
->status
),
377 le32_to_cpu(reply
->data
.action
)));
378 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
379 (le32_to_cpu(reply
->status
) != CT_OK
) ||
380 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
381 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
385 /* Do not set XferState to zero unless receives a response from F/W */
387 aac_fib_complete(fibptr
);
389 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
391 if ((aac_commit
== 1) || commit_flag
) {
392 struct aac_commit_config
* dinfo
;
393 aac_fib_init(fibptr
);
394 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
396 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
397 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
399 status
= aac_fib_send(ContainerCommand
,
401 sizeof (struct aac_commit_config
),
405 /* Do not set XferState to zero unless
406 * receives a response from F/W */
408 aac_fib_complete(fibptr
);
409 } else if (aac_commit
== 0) {
411 "aac_get_config_status: Foreign device configurations are being ignored\n");
414 /* FIB should be freed only after getting the response from the F/W */
415 if (status
!= -ERESTARTSYS
)
416 aac_fib_free(fibptr
);
420 static void aac_expose_phy_device(struct scsi_cmnd
*scsicmd
)
423 scsi_sg_copy_to_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
424 if ((inq_data
& 0x20) && (inq_data
& 0x1f) == TYPE_DISK
) {
426 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
431 * aac_get_containers - list containers
432 * @common: adapter to probe
434 * Make a list of all containers on this controller
436 int aac_get_containers(struct aac_dev
*dev
)
438 struct fsa_dev_info
*fsa_dev_ptr
;
442 struct aac_get_container_count
*dinfo
;
443 struct aac_get_container_count_resp
*dresp
;
444 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
446 if (!(fibptr
= aac_fib_alloc(dev
)))
449 aac_fib_init(fibptr
);
450 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
451 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
452 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
454 status
= aac_fib_send(ContainerCommand
,
456 sizeof (struct aac_get_container_count
),
461 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
462 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
463 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
464 AAC_OPTION_SUPPORTED_240_VOLUMES
) {
465 maximum_num_containers
=
466 le32_to_cpu(dresp
->MaxSimpleVolumes
);
468 aac_fib_complete(fibptr
);
470 /* FIB should be freed only after getting the response from the F/W */
471 if (status
!= -ERESTARTSYS
)
472 aac_fib_free(fibptr
);
474 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
475 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
476 fsa_dev_ptr
= kzalloc(sizeof(*fsa_dev_ptr
) * maximum_num_containers
,
481 dev
->fsa_dev
= fsa_dev_ptr
;
482 dev
->maximum_num_containers
= maximum_num_containers
;
484 for (index
= 0; index
< dev
->maximum_num_containers
; ) {
485 fsa_dev_ptr
[index
].devname
[0] = '\0';
487 status
= aac_probe_container(dev
, index
);
490 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
495 * If there are no more containers, then stop asking.
497 if (++index
>= status
)
503 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
505 struct aac_get_name_resp
* get_name_reply
;
506 struct scsi_cmnd
* scsicmd
;
508 scsicmd
= (struct scsi_cmnd
*) context
;
510 if (!aac_valid_context(scsicmd
, fibptr
))
513 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
514 BUG_ON(fibptr
== NULL
);
516 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
517 /* Failure is irrelevant, using default value instead */
518 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
519 && (get_name_reply
->data
[0] != '\0')) {
520 char *sp
= get_name_reply
->data
;
521 sp
[sizeof(((struct aac_get_name_resp
*)NULL
)->data
)] = '\0';
525 struct inquiry_data inq
;
526 char d
[sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
)];
527 int count
= sizeof(d
);
530 *dp
++ = (*sp
) ? *sp
++ : ' ';
531 } while (--count
> 0);
533 scsi_sg_copy_to_buffer(scsicmd
, &inq
, sizeof(inq
));
534 memcpy(inq
.inqd_pid
, d
, sizeof(d
));
535 scsi_sg_copy_from_buffer(scsicmd
, &inq
, sizeof(inq
));
539 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
541 aac_fib_complete(fibptr
);
542 scsicmd
->scsi_done(scsicmd
);
546 * aac_get_container_name - get container name, none blocking.
548 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
)
551 struct aac_get_name
*dinfo
;
552 struct fib
* cmd_fibcontext
;
553 struct aac_dev
* dev
;
555 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
557 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
561 aac_fib_init(cmd_fibcontext
);
562 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
564 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
565 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
566 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
567 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_name_resp
*)NULL
)->data
));
569 status
= aac_fib_send(ContainerCommand
,
571 sizeof(struct aac_get_name_resp
),
574 (fib_callback
)get_container_name_callback
,
578 * Check that the command queued to the controller
580 if (status
== -EINPROGRESS
) {
581 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
585 printk(KERN_WARNING
"aac_get_container_name: aac_fib_send failed with status: %d.\n", status
);
586 aac_fib_complete(cmd_fibcontext
);
590 static int aac_probe_container_callback2(struct scsi_cmnd
* scsicmd
)
592 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
594 if ((fsa_dev_ptr
[scmd_id(scsicmd
)].valid
& 1))
595 return aac_scsi_cmd(scsicmd
);
597 scsicmd
->result
= DID_NO_CONNECT
<< 16;
598 scsicmd
->scsi_done(scsicmd
);
602 static void _aac_probe_container2(void * context
, struct fib
* fibptr
)
604 struct fsa_dev_info
*fsa_dev_ptr
;
605 int (*callback
)(struct scsi_cmnd
*);
606 struct scsi_cmnd
* scsicmd
= (struct scsi_cmnd
*)context
;
609 if (!aac_valid_context(scsicmd
, fibptr
))
612 scsicmd
->SCp
.Status
= 0;
613 fsa_dev_ptr
= fibptr
->dev
->fsa_dev
;
615 struct aac_mount
* dresp
= (struct aac_mount
*) fib_data(fibptr
);
616 fsa_dev_ptr
+= scmd_id(scsicmd
);
618 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
619 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
620 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
621 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
622 AAC_OPTION_VARIABLE_BLOCK_SIZE
)) {
623 dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
= 0x200;
624 fsa_dev_ptr
->block_size
= 0x200;
626 fsa_dev_ptr
->block_size
=
627 le32_to_cpu(dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
);
629 fsa_dev_ptr
->valid
= 1;
630 /* sense_key holds the current state of the spin-up */
631 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
632 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
633 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
634 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
635 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
637 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
638 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
639 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
641 if ((fsa_dev_ptr
->valid
& 1) == 0)
642 fsa_dev_ptr
->valid
= 0;
643 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
645 aac_fib_complete(fibptr
);
646 aac_fib_free(fibptr
);
647 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
648 scsicmd
->SCp
.ptr
= NULL
;
649 (*callback
)(scsicmd
);
653 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
655 struct scsi_cmnd
* scsicmd
;
656 struct aac_mount
* dresp
;
657 struct aac_query_mount
*dinfo
;
660 dresp
= (struct aac_mount
*) fib_data(fibptr
);
661 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
662 AAC_OPTION_VARIABLE_BLOCK_SIZE
))
663 dresp
->mnt
[0].capacityhigh
= 0;
664 if ((le32_to_cpu(dresp
->status
) != ST_OK
) ||
665 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
666 _aac_probe_container2(context
, fibptr
);
669 scsicmd
= (struct scsi_cmnd
*) context
;
671 if (!aac_valid_context(scsicmd
, fibptr
))
674 aac_fib_init(fibptr
);
676 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
678 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
679 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
680 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
682 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
684 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
685 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
687 status
= aac_fib_send(ContainerCommand
,
689 sizeof(struct aac_query_mount
),
692 _aac_probe_container2
,
695 * Check that the command queued to the controller
697 if (status
== -EINPROGRESS
)
698 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
699 else if (status
< 0) {
700 /* Inherit results from VM_NameServe, if any */
701 dresp
->status
= cpu_to_le32(ST_OK
);
702 _aac_probe_container2(context
, fibptr
);
706 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
709 int status
= -ENOMEM
;
711 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
712 struct aac_query_mount
*dinfo
;
714 aac_fib_init(fibptr
);
716 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
718 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
719 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
720 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
722 dinfo
->command
= cpu_to_le32(VM_NameServe
);
724 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
725 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
726 scsicmd
->SCp
.ptr
= (char *)callback
;
728 status
= aac_fib_send(ContainerCommand
,
730 sizeof(struct aac_query_mount
),
733 _aac_probe_container1
,
736 * Check that the command queued to the controller
738 if (status
== -EINPROGRESS
) {
739 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
743 scsicmd
->SCp
.ptr
= NULL
;
744 aac_fib_complete(fibptr
);
745 aac_fib_free(fibptr
);
749 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
751 fsa_dev_ptr
+= scmd_id(scsicmd
);
752 if ((fsa_dev_ptr
->valid
& 1) == 0) {
753 fsa_dev_ptr
->valid
= 0;
754 return (*callback
)(scsicmd
);
762 * aac_probe_container - query a logical volume
763 * @dev: device to query
764 * @cid: container identifier
766 * Queries the controller about the given volume. The volume information
767 * is updated in the struct fsa_dev_info structure rather than returned.
769 static int aac_probe_container_callback1(struct scsi_cmnd
* scsicmd
)
771 scsicmd
->device
= NULL
;
775 int aac_probe_container(struct aac_dev
*dev
, int cid
)
777 struct scsi_cmnd
*scsicmd
= kmalloc(sizeof(*scsicmd
), GFP_KERNEL
);
778 struct scsi_device
*scsidev
= kmalloc(sizeof(*scsidev
), GFP_KERNEL
);
781 if (!scsicmd
|| !scsidev
) {
786 scsicmd
->list
.next
= NULL
;
787 scsicmd
->scsi_done
= (void (*)(struct scsi_cmnd
*))aac_probe_container_callback1
;
789 scsicmd
->device
= scsidev
;
790 scsidev
->sdev_state
= 0;
792 scsidev
->host
= dev
->scsi_host_ptr
;
794 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
795 while (scsicmd
->device
== scsidev
)
798 status
= scsicmd
->SCp
.Status
;
803 /* Local Structure to set SCSI inquiry data strings */
805 char vid
[8]; /* Vendor ID */
806 char pid
[16]; /* Product ID */
807 char prl
[4]; /* Product Revision Level */
811 * InqStrCopy - string merge
812 * @a: string to copy from
813 * @b: string to copy to
815 * Copy a String from one location to another
819 static void inqstrcpy(char *a
, char *b
)
822 while (*a
!= (char)0)
826 static char *container_types
[] = {
850 char * get_container_type(unsigned tindex
)
852 if (tindex
>= ARRAY_SIZE(container_types
))
853 tindex
= ARRAY_SIZE(container_types
) - 1;
854 return container_types
[tindex
];
857 /* Function: setinqstr
859 * Arguments: [1] pointer to void [1] int
861 * Purpose: Sets SCSI inquiry data strings for vendor, product
862 * and revision level. Allows strings to be set in platform dependent
863 * files instead of in OS dependent driver source.
866 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
868 struct scsi_inq
*str
;
870 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
871 memset(str
, ' ', sizeof(*str
));
873 if (dev
->supplement_adapter_info
.AdapterTypeText
[0]) {
874 char * cp
= dev
->supplement_adapter_info
.AdapterTypeText
;
876 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
877 inqstrcpy("SMC", str
->vid
);
879 c
= sizeof(str
->vid
);
880 while (*cp
&& *cp
!= ' ' && --c
)
884 inqstrcpy (dev
->supplement_adapter_info
.AdapterTypeText
,
887 while (*cp
&& *cp
!= ' ')
892 /* last six chars reserved for vol type */
894 if (strlen(cp
) > sizeof(str
->pid
)) {
895 c
= cp
[sizeof(str
->pid
)];
896 cp
[sizeof(str
->pid
)] = '\0';
898 inqstrcpy (cp
, str
->pid
);
900 cp
[sizeof(str
->pid
)] = c
;
902 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
904 inqstrcpy (mp
->vname
, str
->vid
);
905 /* last six chars reserved for vol type */
906 inqstrcpy (mp
->model
, str
->pid
);
909 if (tindex
< ARRAY_SIZE(container_types
)){
910 char *findit
= str
->pid
;
912 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
913 /* RAID is superfluous in the context of a RAID device */
914 if (memcmp(findit
-4, "RAID", 4) == 0)
915 *(findit
-= 4) = ' ';
916 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
917 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
918 inqstrcpy (container_types
[tindex
], findit
+ 1);
920 inqstrcpy ("V1.0", str
->prl
);
923 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
925 struct aac_get_serial_resp
* get_serial_reply
;
926 struct scsi_cmnd
* scsicmd
;
928 BUG_ON(fibptr
== NULL
);
930 scsicmd
= (struct scsi_cmnd
*) context
;
931 if (!aac_valid_context(scsicmd
, fibptr
))
934 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
935 /* Failure is irrelevant, using default value instead */
936 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
937 /*Check to see if it's for VPD 0x83 or 0x80 */
938 if (scsicmd
->cmnd
[2] == 0x83) {
939 /* vpd page 0x83 - Device Identification Page */
941 TVPD_Page83 VPDPage83Data
;
943 memset(((u8
*)&VPDPage83Data
), 0,
944 sizeof(VPDPage83Data
));
946 /* DIRECT_ACCESS_DEVIC */
947 VPDPage83Data
.DeviceType
= 0;
948 /* DEVICE_CONNECTED */
949 VPDPage83Data
.DeviceTypeQualifier
= 0;
950 /* VPD_DEVICE_IDENTIFIERS */
951 VPDPage83Data
.PageCode
= 0x83;
952 VPDPage83Data
.Reserved
= 0;
953 VPDPage83Data
.PageLength
=
954 sizeof(VPDPage83Data
.IdDescriptorType1
) +
955 sizeof(VPDPage83Data
.IdDescriptorType2
);
957 /* T10 Vendor Identifier Field Format */
958 /* VpdCodeSetAscii */
959 VPDPage83Data
.IdDescriptorType1
.CodeSet
= 2;
960 /* VpdIdentifierTypeVendorId */
961 VPDPage83Data
.IdDescriptorType1
.IdentifierType
= 1;
962 VPDPage83Data
.IdDescriptorType1
.IdentifierLength
=
963 sizeof(VPDPage83Data
.IdDescriptorType1
) - 4;
965 /* "ADAPTEC " for adaptec */
966 memcpy(VPDPage83Data
.IdDescriptorType1
.VendId
,
968 sizeof(VPDPage83Data
.IdDescriptorType1
.VendId
));
969 memcpy(VPDPage83Data
.IdDescriptorType1
.ProductId
,
972 VPDPage83Data
.IdDescriptorType1
.ProductId
));
974 /* Convert to ascii based serial number.
975 * The LSB is the the end.
977 for (i
= 0; i
< 8; i
++) {
979 (u8
)((get_serial_reply
->uid
>> ((7 - i
) * 4)) & 0xF);
981 VPDPage83Data
.IdDescriptorType1
.SerialNumber
[i
] =
984 VPDPage83Data
.IdDescriptorType1
.SerialNumber
[i
] =
989 /* VpdCodeSetBinary */
990 VPDPage83Data
.IdDescriptorType2
.CodeSet
= 1;
991 /* VpdIdentifierTypeEUI64 */
992 VPDPage83Data
.IdDescriptorType2
.IdentifierType
= 2;
993 VPDPage83Data
.IdDescriptorType2
.IdentifierLength
=
994 sizeof(VPDPage83Data
.IdDescriptorType2
) - 4;
996 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[0] = 0xD0;
997 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[1] = 0;
998 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[2] = 0;
1000 VPDPage83Data
.IdDescriptorType2
.EU64Id
.Serial
=
1001 get_serial_reply
->uid
;
1002 VPDPage83Data
.IdDescriptorType2
.EU64Id
.Reserved
= 0;
1004 /* Move the inquiry data to the response buffer. */
1005 scsi_sg_copy_from_buffer(scsicmd
, &VPDPage83Data
,
1006 sizeof(VPDPage83Data
));
1008 /* It must be for VPD 0x80 */
1011 sp
[0] = INQD_PDT_DA
;
1012 sp
[1] = scsicmd
->cmnd
[2];
1014 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
1015 le32_to_cpu(get_serial_reply
->uid
));
1016 scsi_sg_copy_from_buffer(scsicmd
, sp
,
1021 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1023 aac_fib_complete(fibptr
);
1024 scsicmd
->scsi_done(scsicmd
);
1028 * aac_get_container_serial - get container serial, none blocking.
1030 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
1033 struct aac_get_serial
*dinfo
;
1034 struct fib
* cmd_fibcontext
;
1035 struct aac_dev
* dev
;
1037 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1039 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
1040 if (!cmd_fibcontext
)
1043 aac_fib_init(cmd_fibcontext
);
1044 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
1046 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
1047 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
1048 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1050 status
= aac_fib_send(ContainerCommand
,
1052 sizeof(struct aac_get_serial_resp
),
1055 (fib_callback
) get_container_serial_callback
,
1059 * Check that the command queued to the controller
1061 if (status
== -EINPROGRESS
) {
1062 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1066 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
1067 aac_fib_complete(cmd_fibcontext
);
1071 /* Function: setinqserial
1073 * Arguments: [1] pointer to void [1] int
1075 * Purpose: Sets SCSI Unit Serial number.
1076 * This is a fake. We should read a proper
1077 * serial number from the container. <SuSE>But
1078 * without docs it's quite hard to do it :-)
1079 * So this will have to do in the meantime.</SuSE>
1082 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
1085 * This breaks array migration.
1087 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
1088 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
1091 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
1092 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
1094 u8
*sense_buf
= (u8
*)sense_data
;
1095 /* Sense data valid, err code 70h */
1096 sense_buf
[0] = 0x70; /* No info field */
1097 sense_buf
[1] = 0; /* Segment number, always zero */
1099 sense_buf
[2] = sense_key
; /* Sense key */
1101 sense_buf
[12] = sense_code
; /* Additional sense code */
1102 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
1104 if (sense_key
== ILLEGAL_REQUEST
) {
1105 sense_buf
[7] = 10; /* Additional sense length */
1107 sense_buf
[15] = bit_pointer
;
1108 /* Illegal parameter is in the parameter block */
1109 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
1110 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
1111 /* Illegal parameter is in the CDB block */
1112 sense_buf
[16] = field_pointer
>> 8; /* MSB */
1113 sense_buf
[17] = field_pointer
; /* LSB */
1115 sense_buf
[7] = 6; /* Additional sense length */
1118 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1120 if (lba
& 0xffffffff00000000LL
) {
1121 int cid
= scmd_id(cmd
);
1122 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1123 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1124 SAM_STAT_CHECK_CONDITION
;
1125 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1126 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1127 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1128 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1129 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1130 SCSI_SENSE_BUFFERSIZE
));
1131 cmd
->scsi_done(cmd
);
1137 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1142 static void io_callback(void *context
, struct fib
* fibptr
);
1144 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1146 struct aac_dev
*dev
= fib
->dev
;
1147 u16 fibsize
, command
;
1151 if (dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
&& !dev
->sync_mode
) {
1152 struct aac_raw_io2
*readcmd2
;
1153 readcmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1154 memset(readcmd2
, 0, sizeof(struct aac_raw_io2
));
1155 readcmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1156 readcmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1157 readcmd2
->byteCount
= cpu_to_le32(count
*
1158 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1159 readcmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1160 readcmd2
->flags
= cpu_to_le16(RIO2_IO_TYPE_READ
);
1161 ret
= aac_build_sgraw2(cmd
, readcmd2
,
1162 dev
->scsi_host_ptr
->sg_tablesize
);
1165 command
= ContainerRawIo2
;
1166 fibsize
= sizeof(struct aac_raw_io2
) +
1167 ((le32_to_cpu(readcmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1169 struct aac_raw_io
*readcmd
;
1170 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
1171 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1172 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1173 readcmd
->count
= cpu_to_le32(count
*
1174 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1175 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1176 readcmd
->flags
= cpu_to_le16(RIO_TYPE_READ
);
1177 readcmd
->bpTotal
= 0;
1178 readcmd
->bpComplete
= 0;
1179 ret
= aac_build_sgraw(cmd
, &readcmd
->sg
);
1182 command
= ContainerRawIo
;
1183 fibsize
= sizeof(struct aac_raw_io
) +
1184 ((le32_to_cpu(readcmd
->sg
.count
)-1) * sizeof(struct sgentryraw
));
1187 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1189 * Now send the Fib to the adapter
1191 return aac_fib_send(command
,
1196 (fib_callback
) io_callback
,
1200 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1203 struct aac_read64
*readcmd
;
1207 readcmd
= (struct aac_read64
*) fib_data(fib
);
1208 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
1209 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1210 readcmd
->sector_count
= cpu_to_le16(count
);
1211 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1215 ret
= aac_build_sg64(cmd
, &readcmd
->sg
);
1218 fibsize
= sizeof(struct aac_read64
) +
1219 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1220 sizeof (struct sgentry64
));
1221 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1222 sizeof(struct aac_fibhdr
)));
1224 * Now send the Fib to the adapter
1226 return aac_fib_send(ContainerCommand64
,
1231 (fib_callback
) io_callback
,
1235 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1238 struct aac_read
*readcmd
;
1239 struct aac_dev
*dev
= fib
->dev
;
1243 readcmd
= (struct aac_read
*) fib_data(fib
);
1244 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
1245 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1246 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1247 readcmd
->count
= cpu_to_le32(count
*
1248 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1250 ret
= aac_build_sg(cmd
, &readcmd
->sg
);
1253 fibsize
= sizeof(struct aac_read
) +
1254 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1255 sizeof (struct sgentry
));
1256 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1257 sizeof(struct aac_fibhdr
)));
1259 * Now send the Fib to the adapter
1261 return aac_fib_send(ContainerCommand
,
1266 (fib_callback
) io_callback
,
1270 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1272 struct aac_dev
*dev
= fib
->dev
;
1273 u16 fibsize
, command
;
1277 if (dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
&& !dev
->sync_mode
) {
1278 struct aac_raw_io2
*writecmd2
;
1279 writecmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1280 memset(writecmd2
, 0, sizeof(struct aac_raw_io2
));
1281 writecmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1282 writecmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1283 writecmd2
->byteCount
= cpu_to_le32(count
*
1284 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1285 writecmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1286 writecmd2
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1287 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1288 cpu_to_le16(RIO2_IO_TYPE_WRITE
|RIO2_IO_SUREWRITE
) :
1289 cpu_to_le16(RIO2_IO_TYPE_WRITE
);
1290 ret
= aac_build_sgraw2(cmd
, writecmd2
,
1291 dev
->scsi_host_ptr
->sg_tablesize
);
1294 command
= ContainerRawIo2
;
1295 fibsize
= sizeof(struct aac_raw_io2
) +
1296 ((le32_to_cpu(writecmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1298 struct aac_raw_io
*writecmd
;
1299 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1300 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1301 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1302 writecmd
->count
= cpu_to_le32(count
*
1303 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1304 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1305 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1306 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1307 cpu_to_le16(RIO_TYPE_WRITE
|RIO_SUREWRITE
) :
1308 cpu_to_le16(RIO_TYPE_WRITE
);
1309 writecmd
->bpTotal
= 0;
1310 writecmd
->bpComplete
= 0;
1311 ret
= aac_build_sgraw(cmd
, &writecmd
->sg
);
1314 command
= ContainerRawIo
;
1315 fibsize
= sizeof(struct aac_raw_io
) +
1316 ((le32_to_cpu(writecmd
->sg
.count
)-1) * sizeof (struct sgentryraw
));
1319 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1321 * Now send the Fib to the adapter
1323 return aac_fib_send(command
,
1328 (fib_callback
) io_callback
,
1332 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1335 struct aac_write64
*writecmd
;
1339 writecmd
= (struct aac_write64
*) fib_data(fib
);
1340 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1341 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1342 writecmd
->sector_count
= cpu_to_le16(count
);
1343 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1345 writecmd
->flags
= 0;
1347 ret
= aac_build_sg64(cmd
, &writecmd
->sg
);
1350 fibsize
= sizeof(struct aac_write64
) +
1351 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1352 sizeof (struct sgentry64
));
1353 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1354 sizeof(struct aac_fibhdr
)));
1356 * Now send the Fib to the adapter
1358 return aac_fib_send(ContainerCommand64
,
1363 (fib_callback
) io_callback
,
1367 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1370 struct aac_write
*writecmd
;
1371 struct aac_dev
*dev
= fib
->dev
;
1375 writecmd
= (struct aac_write
*) fib_data(fib
);
1376 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1377 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1378 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1379 writecmd
->count
= cpu_to_le32(count
*
1380 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1381 writecmd
->sg
.count
= cpu_to_le32(1);
1382 /* ->stable is not used - it did mean which type of write */
1384 ret
= aac_build_sg(cmd
, &writecmd
->sg
);
1387 fibsize
= sizeof(struct aac_write
) +
1388 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1389 sizeof (struct sgentry
));
1390 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1391 sizeof(struct aac_fibhdr
)));
1393 * Now send the Fib to the adapter
1395 return aac_fib_send(ContainerCommand
,
1400 (fib_callback
) io_callback
,
1404 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1406 struct aac_srb
* srbcmd
;
1411 switch(cmd
->sc_data_direction
){
1415 case DMA_BIDIRECTIONAL
:
1416 flag
= SRB_DataIn
| SRB_DataOut
;
1418 case DMA_FROM_DEVICE
:
1422 default: /* shuts up some versions of gcc */
1423 flag
= SRB_NoDataXfer
;
1427 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1428 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1429 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1430 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1431 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1432 srbcmd
->flags
= cpu_to_le32(flag
);
1433 timeout
= cmd
->request
->timeout
/HZ
;
1436 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1437 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1438 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1442 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1444 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1447 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1450 ret
= aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1453 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1455 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1456 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1458 * Build Scatter/Gather list
1460 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1461 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1462 sizeof (struct sgentry64
));
1463 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1464 sizeof(struct aac_fibhdr
)));
1467 * Now send the Fib to the adapter
1469 return aac_fib_send(ScsiPortCommand64
, fib
,
1470 fibsize
, FsaNormal
, 0, 1,
1471 (fib_callback
) aac_srb_callback
,
1475 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1478 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1481 ret
= aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1484 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1486 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1487 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1489 * Build Scatter/Gather list
1491 fibsize
= sizeof (struct aac_srb
) +
1492 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1493 sizeof (struct sgentry
));
1494 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1495 sizeof(struct aac_fibhdr
)));
1498 * Now send the Fib to the adapter
1500 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1501 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1504 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1506 if ((sizeof(dma_addr_t
) > 4) && fib
->dev
->needs_dac
&&
1507 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1509 return aac_scsi_32(fib
, cmd
);
1512 int aac_get_adapter_info(struct aac_dev
* dev
)
1517 struct aac_adapter_info
*info
;
1518 struct aac_bus_info
*command
;
1519 struct aac_bus_info_response
*bus_info
;
1521 if (!(fibptr
= aac_fib_alloc(dev
)))
1524 aac_fib_init(fibptr
);
1525 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
1526 memset(info
,0,sizeof(*info
));
1528 rcode
= aac_fib_send(RequestAdapterInfo
,
1532 -1, 1, /* First `interrupt' command uses special wait */
1537 /* FIB should be freed only after
1538 * getting the response from the F/W */
1539 if (rcode
!= -ERESTARTSYS
) {
1540 aac_fib_complete(fibptr
);
1541 aac_fib_free(fibptr
);
1545 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
1547 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
1548 struct aac_supplement_adapter_info
* sinfo
;
1550 aac_fib_init(fibptr
);
1552 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
1554 memset(sinfo
,0,sizeof(*sinfo
));
1556 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
1565 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
1566 if (rcode
== -ERESTARTSYS
) {
1567 fibptr
= aac_fib_alloc(dev
);
1579 aac_fib_init(fibptr
);
1581 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
1583 memset(bus_info
, 0, sizeof(*bus_info
));
1585 command
= (struct aac_bus_info
*)bus_info
;
1587 command
->Command
= cpu_to_le32(VM_Ioctl
);
1588 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
1589 command
->MethodId
= cpu_to_le32(1);
1590 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
1592 rcode
= aac_fib_send(ContainerCommand
,
1599 /* reasoned default */
1600 dev
->maximum_num_physicals
= 16;
1601 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
1602 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
1603 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
1606 if (!dev
->in_reset
) {
1608 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
1609 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
1615 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
1616 (int)sizeof(dev
->supplement_adapter_info
.BuildDate
),
1617 dev
->supplement_adapter_info
.BuildDate
);
1618 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
1619 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
1621 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1622 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
1623 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
1624 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
1626 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1627 le32_to_cpu(dev
->adapter_info
.biosbuild
));
1629 if (aac_get_serial_number(
1630 shost_to_class(dev
->scsi_host_ptr
), buffer
))
1631 printk(KERN_INFO
"%s%d: serial %s",
1632 dev
->name
, dev
->id
, buffer
);
1633 if (dev
->supplement_adapter_info
.VpdInfo
.Tsid
[0]) {
1634 printk(KERN_INFO
"%s%d: TSID %.*s\n",
1636 (int)sizeof(dev
->supplement_adapter_info
.VpdInfo
.Tsid
),
1637 dev
->supplement_adapter_info
.VpdInfo
.Tsid
);
1639 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
1640 (dev
->supplement_adapter_info
.SupportedOptions2
&
1641 AAC_OPTION_IGNORE_RESET
))) {
1642 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
1643 dev
->name
, dev
->id
);
1647 dev
->cache_protected
= 0;
1648 dev
->jbod
= ((dev
->supplement_adapter_info
.FeatureBits
&
1649 AAC_FEATURE_JBOD
) != 0);
1650 dev
->nondasd_support
= 0;
1651 dev
->raid_scsi_mode
= 0;
1652 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
1653 dev
->nondasd_support
= 1;
1656 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1657 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1658 * force nondasd support on. If we decide to allow the non-dasd flag
1659 * additional changes changes will have to be made to support
1660 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1661 * changed to support the new dev->raid_scsi_mode flag instead of
1662 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1663 * function aac_detect will have to be modified where it sets up the
1664 * max number of channels based on the aac->nondasd_support flag only.
1666 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
1667 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
1668 dev
->nondasd_support
= 1;
1669 dev
->raid_scsi_mode
= 1;
1671 if (dev
->raid_scsi_mode
!= 0)
1672 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
1673 dev
->name
, dev
->id
);
1676 dev
->nondasd_support
= (nondasd
!=0);
1677 if (dev
->nondasd_support
&& !dev
->in_reset
)
1678 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
1680 if (dma_get_required_mask(&dev
->pdev
->dev
) > DMA_BIT_MASK(32))
1682 dev
->dac_support
= 0;
1683 if ((sizeof(dma_addr_t
) > 4) && dev
->needs_dac
&&
1684 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)) {
1686 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
1687 dev
->name
, dev
->id
);
1688 dev
->dac_support
= 1;
1692 dev
->dac_support
= (dacmode
!=0);
1695 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1696 if (dev
->dac_support
&& (aac_get_driver_ident(dev
->cardtype
)->quirks
1697 & AAC_QUIRK_SCSI_32
)) {
1698 dev
->nondasd_support
= 0;
1700 expose_physicals
= 0;
1703 if(dev
->dac_support
!= 0) {
1704 if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(64)) &&
1705 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(64))) {
1707 printk(KERN_INFO
"%s%d: 64 Bit DAC enabled\n",
1708 dev
->name
, dev
->id
);
1709 } else if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(32)) &&
1710 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(32))) {
1711 printk(KERN_INFO
"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1712 dev
->name
, dev
->id
);
1713 dev
->dac_support
= 0;
1715 printk(KERN_WARNING
"%s%d: No suitable DMA available.\n",
1716 dev
->name
, dev
->id
);
1721 * Deal with configuring for the individualized limits of each packet
1724 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
1725 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
1729 if (dev
->raw_io_interface
) {
1730 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
1733 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
1734 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
1736 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
1737 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
1738 sizeof(struct aac_fibhdr
) -
1739 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
1740 sizeof(struct sgentry
);
1741 if (dev
->dac_support
) {
1742 dev
->a_ops
.adapter_read
= aac_read_block64
;
1743 dev
->a_ops
.adapter_write
= aac_write_block64
;
1745 * 38 scatter gather elements
1747 dev
->scsi_host_ptr
->sg_tablesize
=
1748 (dev
->max_fib_size
-
1749 sizeof(struct aac_fibhdr
) -
1750 sizeof(struct aac_write64
) +
1751 sizeof(struct sgentry64
)) /
1752 sizeof(struct sgentry64
);
1754 dev
->a_ops
.adapter_read
= aac_read_block
;
1755 dev
->a_ops
.adapter_write
= aac_write_block
;
1757 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
1758 if (!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
1760 * Worst case size that could cause sg overflow when
1761 * we break up SG elements that are larger than 64KB.
1762 * Would be nice if we could tell the SCSI layer what
1763 * the maximum SG element size can be. Worst case is
1764 * (sg_tablesize-1) 4KB elements with one 64KB
1766 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1768 dev
->scsi_host_ptr
->max_sectors
=
1769 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
1772 /* FIB should be freed only after getting the response from the F/W */
1773 if (rcode
!= -ERESTARTSYS
) {
1774 aac_fib_complete(fibptr
);
1775 aac_fib_free(fibptr
);
1782 static void io_callback(void *context
, struct fib
* fibptr
)
1784 struct aac_dev
*dev
;
1785 struct aac_read_reply
*readreply
;
1786 struct scsi_cmnd
*scsicmd
;
1789 scsicmd
= (struct scsi_cmnd
*) context
;
1791 if (!aac_valid_context(scsicmd
, fibptr
))
1795 cid
= scmd_id(scsicmd
);
1797 if (nblank(dprintk(x
))) {
1799 switch (scsicmd
->cmnd
[0]) {
1802 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1803 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1807 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1808 ((u64
)scsicmd
->cmnd
[3] << 48) |
1809 ((u64
)scsicmd
->cmnd
[4] << 40) |
1810 ((u64
)scsicmd
->cmnd
[5] << 32) |
1811 ((u64
)scsicmd
->cmnd
[6] << 24) |
1812 (scsicmd
->cmnd
[7] << 16) |
1813 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1817 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1818 (scsicmd
->cmnd
[3] << 16) |
1819 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1822 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1823 (scsicmd
->cmnd
[3] << 16) |
1824 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1828 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1829 smp_processor_id(), (unsigned long long)lba
, jiffies
);
1832 BUG_ON(fibptr
== NULL
);
1834 scsi_dma_unmap(scsicmd
);
1836 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
1837 switch (le32_to_cpu(readreply
->status
)) {
1839 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1841 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
1844 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1845 SAM_STAT_CHECK_CONDITION
;
1846 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
1847 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
1848 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1849 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1850 SCSI_SENSE_BUFFERSIZE
));
1853 #ifdef AAC_DETAILED_STATUS_INFO
1854 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
1855 le32_to_cpu(readreply
->status
));
1857 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1858 SAM_STAT_CHECK_CONDITION
;
1859 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1860 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1861 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1862 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1863 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1864 SCSI_SENSE_BUFFERSIZE
));
1867 aac_fib_complete(fibptr
);
1869 scsicmd
->scsi_done(scsicmd
);
1872 static int aac_read(struct scsi_cmnd
* scsicmd
)
1877 struct aac_dev
*dev
;
1878 struct fib
* cmd_fibcontext
;
1881 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1883 * Get block address and transfer length
1885 switch (scsicmd
->cmnd
[0]) {
1887 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
1889 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1890 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1891 count
= scsicmd
->cmnd
[4];
1897 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
1899 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1900 ((u64
)scsicmd
->cmnd
[3] << 48) |
1901 ((u64
)scsicmd
->cmnd
[4] << 40) |
1902 ((u64
)scsicmd
->cmnd
[5] << 32) |
1903 ((u64
)scsicmd
->cmnd
[6] << 24) |
1904 (scsicmd
->cmnd
[7] << 16) |
1905 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1906 count
= (scsicmd
->cmnd
[10] << 24) |
1907 (scsicmd
->cmnd
[11] << 16) |
1908 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
1911 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
1913 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1914 (scsicmd
->cmnd
[3] << 16) |
1915 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1916 count
= (scsicmd
->cmnd
[6] << 24) |
1917 (scsicmd
->cmnd
[7] << 16) |
1918 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1921 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
1923 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1924 (scsicmd
->cmnd
[3] << 16) |
1925 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1926 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1930 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
1931 cid
= scmd_id(scsicmd
);
1932 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1933 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1934 SAM_STAT_CHECK_CONDITION
;
1935 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1936 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1937 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1938 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1939 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1940 SCSI_SENSE_BUFFERSIZE
));
1941 scsicmd
->scsi_done(scsicmd
);
1945 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1946 smp_processor_id(), (unsigned long long)lba
, jiffies
));
1947 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
1950 * Alocate and initialize a Fib
1952 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
1953 if (!cmd_fibcontext
) {
1954 printk(KERN_WARNING
"aac_read: fib allocation failed\n");
1958 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
1961 * Check that the command queued to the controller
1963 if (status
== -EINPROGRESS
) {
1964 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1968 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
1970 * For some reason, the Fib didn't queue, return QUEUE_FULL
1972 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
1973 scsicmd
->scsi_done(scsicmd
);
1974 aac_fib_complete(cmd_fibcontext
);
1975 aac_fib_free(cmd_fibcontext
);
1979 static int aac_write(struct scsi_cmnd
* scsicmd
)
1985 struct aac_dev
*dev
;
1986 struct fib
* cmd_fibcontext
;
1989 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1991 * Get block address and transfer length
1993 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
1995 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1996 count
= scsicmd
->cmnd
[4];
2000 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
2001 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
2003 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
2004 ((u64
)scsicmd
->cmnd
[3] << 48) |
2005 ((u64
)scsicmd
->cmnd
[4] << 40) |
2006 ((u64
)scsicmd
->cmnd
[5] << 32) |
2007 ((u64
)scsicmd
->cmnd
[6] << 24) |
2008 (scsicmd
->cmnd
[7] << 16) |
2009 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2010 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
2011 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2012 fua
= scsicmd
->cmnd
[1] & 0x8;
2013 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
2014 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
2016 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
2017 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2018 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
2019 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2020 fua
= scsicmd
->cmnd
[1] & 0x8;
2022 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
2023 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2024 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2025 fua
= scsicmd
->cmnd
[1] & 0x8;
2028 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2029 cid
= scmd_id(scsicmd
);
2030 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2031 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2032 SAM_STAT_CHECK_CONDITION
;
2033 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2034 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2035 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2036 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2037 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2038 SCSI_SENSE_BUFFERSIZE
));
2039 scsicmd
->scsi_done(scsicmd
);
2043 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2044 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2045 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2048 * Allocate and initialize a Fib then setup a BlockWrite command
2050 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2051 if (!cmd_fibcontext
) {
2052 /* FIB temporarily unavailable,not catastrophic failure */
2054 /* scsicmd->result = DID_ERROR << 16;
2055 * scsicmd->scsi_done(scsicmd);
2058 printk(KERN_WARNING
"aac_write: fib allocation failed\n");
2062 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
2065 * Check that the command queued to the controller
2067 if (status
== -EINPROGRESS
) {
2068 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2072 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
2074 * For some reason, the Fib didn't queue, return QUEUE_FULL
2076 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2077 scsicmd
->scsi_done(scsicmd
);
2079 aac_fib_complete(cmd_fibcontext
);
2080 aac_fib_free(cmd_fibcontext
);
2084 static void synchronize_callback(void *context
, struct fib
*fibptr
)
2086 struct aac_synchronize_reply
*synchronizereply
;
2087 struct scsi_cmnd
*cmd
;
2091 if (!aac_valid_context(cmd
, fibptr
))
2094 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
2095 smp_processor_id(), jiffies
));
2096 BUG_ON(fibptr
== NULL
);
2099 synchronizereply
= fib_data(fibptr
);
2100 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
2101 cmd
->result
= DID_OK
<< 16 |
2102 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2104 struct scsi_device
*sdev
= cmd
->device
;
2105 struct aac_dev
*dev
= fibptr
->dev
;
2106 u32 cid
= sdev_id(sdev
);
2108 "synchronize_callback: synchronize failed, status = %d\n",
2109 le32_to_cpu(synchronizereply
->status
));
2110 cmd
->result
= DID_OK
<< 16 |
2111 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2112 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2113 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2114 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2115 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2116 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2117 SCSI_SENSE_BUFFERSIZE
));
2120 aac_fib_complete(fibptr
);
2121 aac_fib_free(fibptr
);
2122 cmd
->scsi_done(cmd
);
2125 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
2128 struct fib
*cmd_fibcontext
;
2129 struct aac_synchronize
*synchronizecmd
;
2130 struct scsi_cmnd
*cmd
;
2131 struct scsi_device
*sdev
= scsicmd
->device
;
2133 struct aac_dev
*aac
;
2134 u64 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) |
2135 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2136 u32 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2137 unsigned long flags
;
2140 * Wait for all outstanding queued commands to complete to this
2141 * specific target (block).
2143 spin_lock_irqsave(&sdev
->list_lock
, flags
);
2144 list_for_each_entry(cmd
, &sdev
->cmd_list
, list
)
2145 if (cmd
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
2149 if (cmd
->cmnd
[0] == WRITE_6
) {
2150 cmnd_lba
= ((cmd
->cmnd
[1] & 0x1F) << 16) |
2151 (cmd
->cmnd
[2] << 8) |
2153 cmnd_count
= cmd
->cmnd
[4];
2154 if (cmnd_count
== 0)
2156 } else if (cmd
->cmnd
[0] == WRITE_16
) {
2157 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 56) |
2158 ((u64
)cmd
->cmnd
[3] << 48) |
2159 ((u64
)cmd
->cmnd
[4] << 40) |
2160 ((u64
)cmd
->cmnd
[5] << 32) |
2161 ((u64
)cmd
->cmnd
[6] << 24) |
2162 (cmd
->cmnd
[7] << 16) |
2163 (cmd
->cmnd
[8] << 8) |
2165 cmnd_count
= (cmd
->cmnd
[10] << 24) |
2166 (cmd
->cmnd
[11] << 16) |
2167 (cmd
->cmnd
[12] << 8) |
2169 } else if (cmd
->cmnd
[0] == WRITE_12
) {
2170 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2171 (cmd
->cmnd
[3] << 16) |
2172 (cmd
->cmnd
[4] << 8) |
2174 cmnd_count
= (cmd
->cmnd
[6] << 24) |
2175 (cmd
->cmnd
[7] << 16) |
2176 (cmd
->cmnd
[8] << 8) |
2178 } else if (cmd
->cmnd
[0] == WRITE_10
) {
2179 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2180 (cmd
->cmnd
[3] << 16) |
2181 (cmd
->cmnd
[4] << 8) |
2183 cmnd_count
= (cmd
->cmnd
[7] << 8) |
2187 if (((cmnd_lba
+ cmnd_count
) < lba
) ||
2188 (count
&& ((lba
+ count
) < cmnd_lba
)))
2194 spin_unlock_irqrestore(&sdev
->list_lock
, flags
);
2197 * Yield the processor (requeue for later)
2200 return SCSI_MLQUEUE_DEVICE_BUSY
;
2202 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2204 return SCSI_MLQUEUE_HOST_BUSY
;
2207 * Allocate and initialize a Fib
2209 if (!(cmd_fibcontext
= aac_fib_alloc(aac
)))
2210 return SCSI_MLQUEUE_HOST_BUSY
;
2212 aac_fib_init(cmd_fibcontext
);
2214 synchronizecmd
= fib_data(cmd_fibcontext
);
2215 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2216 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
2217 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
2218 synchronizecmd
->count
=
2219 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
2222 * Now send the Fib to the adapter
2224 status
= aac_fib_send(ContainerCommand
,
2226 sizeof(struct aac_synchronize
),
2229 (fib_callback
)synchronize_callback
,
2233 * Check that the command queued to the controller
2235 if (status
== -EINPROGRESS
) {
2236 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2241 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
2242 aac_fib_complete(cmd_fibcontext
);
2243 aac_fib_free(cmd_fibcontext
);
2244 return SCSI_MLQUEUE_HOST_BUSY
;
2247 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
2249 struct scsi_cmnd
*scsicmd
= context
;
2251 if (!aac_valid_context(scsicmd
, fibptr
))
2254 BUG_ON(fibptr
== NULL
);
2256 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2258 aac_fib_complete(fibptr
);
2259 aac_fib_free(fibptr
);
2260 scsicmd
->scsi_done(scsicmd
);
2263 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
2266 struct fib
*cmd_fibcontext
;
2267 struct aac_power_management
*pmcmd
;
2268 struct scsi_device
*sdev
= scsicmd
->device
;
2269 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2271 if (!(aac
->supplement_adapter_info
.SupportedOptions2
&
2272 AAC_OPTION_POWER_MANAGEMENT
)) {
2273 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2275 scsicmd
->scsi_done(scsicmd
);
2280 return SCSI_MLQUEUE_HOST_BUSY
;
2283 * Allocate and initialize a Fib
2285 cmd_fibcontext
= aac_fib_alloc_tag(aac
, scsicmd
);
2286 if (!cmd_fibcontext
)
2287 return SCSI_MLQUEUE_HOST_BUSY
;
2289 aac_fib_init(cmd_fibcontext
);
2291 pmcmd
= fib_data(cmd_fibcontext
);
2292 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2293 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
2294 /* Eject bit ignored, not relevant */
2295 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
2296 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
2297 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
2298 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
2299 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
2302 * Now send the Fib to the adapter
2304 status
= aac_fib_send(ContainerCommand
,
2306 sizeof(struct aac_power_management
),
2309 (fib_callback
)aac_start_stop_callback
,
2313 * Check that the command queued to the controller
2315 if (status
== -EINPROGRESS
) {
2316 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2320 aac_fib_complete(cmd_fibcontext
);
2321 aac_fib_free(cmd_fibcontext
);
2322 return SCSI_MLQUEUE_HOST_BUSY
;
2326 * aac_scsi_cmd() - Process SCSI command
2327 * @scsicmd: SCSI command block
2329 * Emulate a SCSI command and queue the required request for the
2333 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
2336 struct Scsi_Host
*host
= scsicmd
->device
->host
;
2337 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
2338 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
2340 if (fsa_dev_ptr
== NULL
)
2343 * If the bus, id or lun is out of range, return fail
2344 * Test does not apply to ID 16, the pseudo id for the controller
2347 cid
= scmd_id(scsicmd
);
2348 if (cid
!= host
->this_id
) {
2349 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
2350 if((cid
>= dev
->maximum_num_containers
) ||
2351 (scsicmd
->device
->lun
!= 0)) {
2352 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2353 scsicmd
->scsi_done(scsicmd
);
2358 * If the target container doesn't exist, it may have
2359 * been newly created
2361 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2362 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2364 switch (scsicmd
->cmnd
[0]) {
2365 case SERVICE_ACTION_IN_16
:
2366 if (!(dev
->raw_io_interface
) ||
2367 !(dev
->raw_io_64
) ||
2368 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2372 case TEST_UNIT_READY
:
2375 return _aac_probe_container(scsicmd
,
2376 aac_probe_container_callback2
);
2381 } else { /* check for physical non-dasd devices */
2382 if (dev
->nondasd_support
|| expose_physicals
||
2386 return aac_send_srb_fib(scsicmd
);
2388 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2389 scsicmd
->scsi_done(scsicmd
);
2395 * else Command for the controller itself
2397 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2398 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2400 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2401 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2402 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2403 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2404 ASENCODE_INVALID_COMMAND
, 0, 0);
2405 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2406 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2407 SCSI_SENSE_BUFFERSIZE
));
2408 scsicmd
->scsi_done(scsicmd
);
2413 /* Handle commands here that don't really require going out to the adapter */
2414 switch (scsicmd
->cmnd
[0]) {
2417 struct inquiry_data inq_data
;
2419 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2420 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2422 if ((scsicmd
->cmnd
[1] & 0x1) && aac_wwn
) {
2423 char *arr
= (char *)&inq_data
;
2426 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2427 INQD_PDT_PROC
: INQD_PDT_DA
;
2428 if (scsicmd
->cmnd
[2] == 0) {
2429 /* supported vital product data pages */
2434 arr
[1] = scsicmd
->cmnd
[2];
2435 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2437 scsicmd
->result
= DID_OK
<< 16 |
2438 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2439 } else if (scsicmd
->cmnd
[2] == 0x80) {
2440 /* unit serial number page */
2441 arr
[3] = setinqserial(dev
, &arr
[4],
2443 arr
[1] = scsicmd
->cmnd
[2];
2444 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2447 return aac_get_container_serial(
2449 scsicmd
->result
= DID_OK
<< 16 |
2450 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2451 } else if (scsicmd
->cmnd
[2] == 0x83) {
2452 /* vpd page 0x83 - Device Identification Page */
2453 char *sno
= (char *)&inq_data
;
2454 sno
[3] = setinqserial(dev
, &sno
[4],
2457 return aac_get_container_serial(
2459 scsicmd
->result
= DID_OK
<< 16 |
2460 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2462 /* vpd page not implemented */
2463 scsicmd
->result
= DID_OK
<< 16 |
2464 COMMAND_COMPLETE
<< 8 |
2465 SAM_STAT_CHECK_CONDITION
;
2466 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2467 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2468 ASENCODE_NO_SENSE
, 7, 2);
2469 memcpy(scsicmd
->sense_buffer
,
2470 &dev
->fsa_dev
[cid
].sense_data
,
2472 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2473 SCSI_SENSE_BUFFERSIZE
));
2475 scsicmd
->scsi_done(scsicmd
);
2478 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2479 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 */
2480 inq_data
.inqd_len
= 31;
2481 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2482 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2484 * Set the Vendor, Product, and Revision Level
2485 * see: <vendor>.c i.e. aac.c
2487 if (cid
== host
->this_id
) {
2488 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2489 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2490 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2492 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2493 scsicmd
->scsi_done(scsicmd
);
2498 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2499 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2500 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2501 return aac_get_container_name(scsicmd
);
2503 case SERVICE_ACTION_IN_16
:
2504 if (!(dev
->raw_io_interface
) ||
2505 !(dev
->raw_io_64
) ||
2506 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2511 unsigned int alloc_len
;
2513 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2514 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2515 cp
[0] = (capacity
>> 56) & 0xff;
2516 cp
[1] = (capacity
>> 48) & 0xff;
2517 cp
[2] = (capacity
>> 40) & 0xff;
2518 cp
[3] = (capacity
>> 32) & 0xff;
2519 cp
[4] = (capacity
>> 24) & 0xff;
2520 cp
[5] = (capacity
>> 16) & 0xff;
2521 cp
[6] = (capacity
>> 8) & 0xff;
2522 cp
[7] = (capacity
>> 0) & 0xff;
2523 cp
[8] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2524 cp
[9] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2525 cp
[10] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2526 cp
[11] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2529 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
2530 + (scsicmd
->cmnd
[11] << 16)
2531 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
2533 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
2534 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
2535 if (alloc_len
< scsi_bufflen(scsicmd
))
2536 scsi_set_resid(scsicmd
,
2537 scsi_bufflen(scsicmd
) - alloc_len
);
2539 /* Do not cache partition table for arrays */
2540 scsicmd
->device
->removable
= 1;
2542 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2543 scsicmd
->scsi_done(scsicmd
);
2553 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
2554 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2555 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2559 cp
[0] = (capacity
>> 24) & 0xff;
2560 cp
[1] = (capacity
>> 16) & 0xff;
2561 cp
[2] = (capacity
>> 8) & 0xff;
2562 cp
[3] = (capacity
>> 0) & 0xff;
2563 cp
[4] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2564 cp
[5] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2565 cp
[6] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2566 cp
[7] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2567 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
2568 /* Do not cache partition table for arrays */
2569 scsicmd
->device
->removable
= 1;
2570 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2572 scsicmd
->scsi_done(scsicmd
);
2579 int mode_buf_length
= 4;
2583 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2584 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2588 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
2589 memset((char *)&mpd
, 0, sizeof(aac_modep_data
));
2591 /* Mode data length */
2592 mpd
.hd
.data_length
= sizeof(mpd
.hd
) - 1;
2593 /* Medium type - default */
2594 mpd
.hd
.med_type
= 0;
2595 /* Device-specific param,
2596 bit 8: 0/1 = write enabled/protected
2597 bit 4: 0/1 = FUA enabled */
2600 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2601 mpd
.hd
.dev_par
= 0x10;
2602 if (scsicmd
->cmnd
[1] & 0x8)
2603 mpd
.hd
.bd_length
= 0; /* Block descriptor length */
2605 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
2606 mpd
.hd
.data_length
+= mpd
.hd
.bd_length
;
2607 mpd
.bd
.block_length
[0] =
2608 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2609 mpd
.bd
.block_length
[1] =
2610 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2611 mpd
.bd
.block_length
[2] =
2612 fsa_dev_ptr
[cid
].block_size
& 0xff;
2614 mpd
.mpc_buf
[0] = scsicmd
->cmnd
[2];
2615 if (scsicmd
->cmnd
[2] == 0x1C) {
2617 mpd
.mpc_buf
[1] = 0xa;
2618 /* Mode data length */
2619 mpd
.hd
.data_length
= 23;
2621 /* Mode data length */
2622 mpd
.hd
.data_length
= 15;
2625 if (capacity
> 0xffffff) {
2626 mpd
.bd
.block_count
[0] = 0xff;
2627 mpd
.bd
.block_count
[1] = 0xff;
2628 mpd
.bd
.block_count
[2] = 0xff;
2630 mpd
.bd
.block_count
[0] = (capacity
>> 16) & 0xff;
2631 mpd
.bd
.block_count
[1] = (capacity
>> 8) & 0xff;
2632 mpd
.bd
.block_count
[2] = capacity
& 0xff;
2635 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2636 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2637 mpd
.hd
.data_length
+= 3;
2640 mpd
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
2641 ? 0 : 0x04; /* WCE */
2642 mode_buf_length
= sizeof(mpd
);
2645 if (mode_buf_length
> scsicmd
->cmnd
[4])
2646 mode_buf_length
= scsicmd
->cmnd
[4];
2648 mode_buf_length
= sizeof(mpd
);
2649 scsi_sg_copy_from_buffer(scsicmd
,
2652 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2653 scsicmd
->scsi_done(scsicmd
);
2660 int mode_buf_length
= 8;
2661 aac_modep10_data mpd10
;
2663 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2664 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2668 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
2669 memset((char *)&mpd10
, 0, sizeof(aac_modep10_data
));
2670 /* Mode data length (MSB) */
2671 mpd10
.hd
.data_length
[0] = 0;
2672 /* Mode data length (LSB) */
2673 mpd10
.hd
.data_length
[1] = sizeof(mpd10
.hd
) - 1;
2674 /* Medium type - default */
2675 mpd10
.hd
.med_type
= 0;
2676 /* Device-specific param,
2677 bit 8: 0/1 = write enabled/protected
2678 bit 4: 0/1 = FUA enabled */
2679 mpd10
.hd
.dev_par
= 0;
2681 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2682 mpd10
.hd
.dev_par
= 0x10;
2683 mpd10
.hd
.rsrvd
[0] = 0; /* reserved */
2684 mpd10
.hd
.rsrvd
[1] = 0; /* reserved */
2685 if (scsicmd
->cmnd
[1] & 0x8) {
2686 /* Block descriptor length (MSB) */
2687 mpd10
.hd
.bd_length
[0] = 0;
2688 /* Block descriptor length (LSB) */
2689 mpd10
.hd
.bd_length
[1] = 0;
2691 mpd10
.hd
.bd_length
[0] = 0;
2692 mpd10
.hd
.bd_length
[1] = sizeof(mpd10
.bd
);
2694 mpd10
.hd
.data_length
[1] += mpd10
.hd
.bd_length
[1];
2696 mpd10
.bd
.block_length
[0] =
2697 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2698 mpd10
.bd
.block_length
[1] =
2699 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2700 mpd10
.bd
.block_length
[2] =
2701 fsa_dev_ptr
[cid
].block_size
& 0xff;
2703 if (capacity
> 0xffffff) {
2704 mpd10
.bd
.block_count
[0] = 0xff;
2705 mpd10
.bd
.block_count
[1] = 0xff;
2706 mpd10
.bd
.block_count
[2] = 0xff;
2708 mpd10
.bd
.block_count
[0] =
2709 (capacity
>> 16) & 0xff;
2710 mpd10
.bd
.block_count
[1] =
2711 (capacity
>> 8) & 0xff;
2712 mpd10
.bd
.block_count
[2] =
2716 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2717 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2718 mpd10
.hd
.data_length
[1] += 3;
2719 mpd10
.mpc_buf
[0] = 8;
2720 mpd10
.mpc_buf
[1] = 1;
2721 mpd10
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
2722 ? 0 : 0x04; /* WCE */
2723 mode_buf_length
= sizeof(mpd10
);
2724 if (mode_buf_length
> scsicmd
->cmnd
[8])
2725 mode_buf_length
= scsicmd
->cmnd
[8];
2727 scsi_sg_copy_from_buffer(scsicmd
,
2731 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2732 scsicmd
->scsi_done(scsicmd
);
2737 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
2738 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
, sizeof (struct sense_data
));
2739 memset(&dev
->fsa_dev
[cid
].sense_data
, 0, sizeof (struct sense_data
));
2740 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2741 scsicmd
->scsi_done(scsicmd
);
2744 case ALLOW_MEDIUM_REMOVAL
:
2745 dprintk((KERN_DEBUG
"LOCK command.\n"));
2746 if (scsicmd
->cmnd
[4])
2747 fsa_dev_ptr
[cid
].locked
= 1;
2749 fsa_dev_ptr
[cid
].locked
= 0;
2751 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2752 scsicmd
->scsi_done(scsicmd
);
2755 * These commands are all No-Ops
2757 case TEST_UNIT_READY
:
2758 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
2759 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2760 SAM_STAT_CHECK_CONDITION
;
2761 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2762 NOT_READY
, SENCODE_BECOMING_READY
,
2763 ASENCODE_BECOMING_READY
, 0, 0);
2764 memcpy(scsicmd
->sense_buffer
,
2765 &dev
->fsa_dev
[cid
].sense_data
,
2767 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2768 SCSI_SENSE_BUFFERSIZE
));
2769 scsicmd
->scsi_done(scsicmd
);
2776 case REASSIGN_BLOCKS
:
2778 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2779 scsicmd
->scsi_done(scsicmd
);
2783 return aac_start_stop(scsicmd
);
2786 switch (scsicmd
->cmnd
[0])
2795 * Hack to keep track of ordinal number of the device that
2796 * corresponds to a container. Needed to convert
2797 * containers to /dev/sd device names
2800 if (scsicmd
->request
->rq_disk
)
2801 strlcpy(fsa_dev_ptr
[cid
].devname
,
2802 scsicmd
->request
->rq_disk
->disk_name
,
2803 min(sizeof(fsa_dev_ptr
[cid
].devname
),
2804 sizeof(scsicmd
->request
->rq_disk
->disk_name
) + 1));
2806 return aac_read(scsicmd
);
2814 return aac_write(scsicmd
);
2816 case SYNCHRONIZE_CACHE
:
2817 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2818 scsicmd
->result
= DID_OK
<< 16 |
2819 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2820 scsicmd
->scsi_done(scsicmd
);
2823 /* Issue FIB to tell Firmware to flush it's cache */
2824 if ((aac_cache
& 6) != 2)
2825 return aac_synchronize(scsicmd
);
2829 * Unhandled commands
2831 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n", scsicmd
->cmnd
[0]));
2832 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2833 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2834 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2835 ASENCODE_INVALID_COMMAND
, 0, 0);
2836 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2838 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2839 SCSI_SENSE_BUFFERSIZE
));
2840 scsicmd
->scsi_done(scsicmd
);
2845 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
2847 struct aac_query_disk qd
;
2848 struct fsa_dev_info
*fsa_dev_ptr
;
2850 fsa_dev_ptr
= dev
->fsa_dev
;
2853 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
2857 else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1))
2859 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
2861 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
2863 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
2864 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
2866 else return -EINVAL
;
2868 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
2869 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
2870 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
2872 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
2877 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
2878 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
2880 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
2885 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2887 struct aac_delete_disk dd
;
2888 struct fsa_dev_info
*fsa_dev_ptr
;
2890 fsa_dev_ptr
= dev
->fsa_dev
;
2894 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2897 if (dd
.cnum
>= dev
->maximum_num_containers
)
2900 * Mark this container as being deleted.
2902 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
2904 * Mark the container as no longer valid
2906 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2910 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2912 struct aac_delete_disk dd
;
2913 struct fsa_dev_info
*fsa_dev_ptr
;
2915 fsa_dev_ptr
= dev
->fsa_dev
;
2919 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2922 if (dd
.cnum
>= dev
->maximum_num_containers
)
2925 * If the container is locked, it can not be deleted by the API.
2927 if (fsa_dev_ptr
[dd
.cnum
].locked
)
2931 * Mark the container as no longer being valid.
2933 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2934 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
2939 int aac_dev_ioctl(struct aac_dev
*dev
, int cmd
, void __user
*arg
)
2942 case FSACTL_QUERY_DISK
:
2943 return query_disk(dev
, arg
);
2944 case FSACTL_DELETE_DISK
:
2945 return delete_disk(dev
, arg
);
2946 case FSACTL_FORCE_DELETE_DISK
:
2947 return force_delete_disk(dev
, arg
);
2948 case FSACTL_GET_CONTAINERS
:
2949 return aac_get_containers(dev
);
2958 * @context: the context set in the fib - here it is scsi cmd
2959 * @fibptr: pointer to the fib
2961 * Handles the completion of a scsi command to a non dasd device
2965 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
2967 struct aac_dev
*dev
;
2968 struct aac_srb_reply
*srbreply
;
2969 struct scsi_cmnd
*scsicmd
;
2971 scsicmd
= (struct scsi_cmnd
*) context
;
2973 if (!aac_valid_context(scsicmd
, fibptr
))
2976 BUG_ON(fibptr
== NULL
);
2979 scsi_dma_unmap(scsicmd
);
2981 /* expose physical device if expose_physicald flag is on */
2982 if (scsicmd
->cmnd
[0] == INQUIRY
&& !(scsicmd
->cmnd
[1] & 0x01)
2983 && expose_physicals
> 0)
2984 aac_expose_phy_device(scsicmd
);
2986 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
2987 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
2989 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
2991 srbreply
->srb_status
= cpu_to_le32(SRB_STATUS_SUCCESS
);
2992 srbreply
->scsi_status
= cpu_to_le32(SAM_STAT_GOOD
);
2995 * Calculate resid for sg
2997 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
2998 - le32_to_cpu(srbreply
->data_xfer_length
));
3000 * First check the fib status
3003 if (le32_to_cpu(srbreply
->status
) != ST_OK
) {
3006 printk(KERN_WARNING
"aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply
->status
));
3007 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3008 SCSI_SENSE_BUFFERSIZE
);
3009 scsicmd
->result
= DID_ERROR
<< 16
3010 | COMMAND_COMPLETE
<< 8
3011 | SAM_STAT_CHECK_CONDITION
;
3012 memcpy(scsicmd
->sense_buffer
,
3013 srbreply
->sense_data
, len
);
3017 * Next check the srb status
3019 switch ((le32_to_cpu(srbreply
->srb_status
))&0x3f) {
3020 case SRB_STATUS_ERROR_RECOVERY
:
3021 case SRB_STATUS_PENDING
:
3022 case SRB_STATUS_SUCCESS
:
3023 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3025 case SRB_STATUS_DATA_OVERRUN
:
3026 switch (scsicmd
->cmnd
[0]) {
3035 if (le32_to_cpu(srbreply
->data_xfer_length
)
3036 < scsicmd
->underflow
)
3037 printk(KERN_WARNING
"aacraid: SCSI CMD underflow\n");
3039 printk(KERN_WARNING
"aacraid: SCSI CMD Data Overrun\n");
3040 scsicmd
->result
= DID_ERROR
<< 16
3041 | COMMAND_COMPLETE
<< 8;
3044 scsicmd
->result
= DID_OK
<< 16
3045 | COMMAND_COMPLETE
<< 8;
3049 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3053 case SRB_STATUS_ABORTED
:
3054 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3056 case SRB_STATUS_ABORT_FAILED
:
3058 * Not sure about this one - but assuming the
3059 * hba was trying to abort for some reason
3061 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
3063 case SRB_STATUS_PARITY_ERROR
:
3064 scsicmd
->result
= DID_PARITY
<< 16
3065 | MSG_PARITY_ERROR
<< 8;
3067 case SRB_STATUS_NO_DEVICE
:
3068 case SRB_STATUS_INVALID_PATH_ID
:
3069 case SRB_STATUS_INVALID_TARGET_ID
:
3070 case SRB_STATUS_INVALID_LUN
:
3071 case SRB_STATUS_SELECTION_TIMEOUT
:
3072 scsicmd
->result
= DID_NO_CONNECT
<< 16
3073 | COMMAND_COMPLETE
<< 8;
3076 case SRB_STATUS_COMMAND_TIMEOUT
:
3077 case SRB_STATUS_TIMEOUT
:
3078 scsicmd
->result
= DID_TIME_OUT
<< 16
3079 | COMMAND_COMPLETE
<< 8;
3082 case SRB_STATUS_BUSY
:
3083 scsicmd
->result
= DID_BUS_BUSY
<< 16
3084 | COMMAND_COMPLETE
<< 8;
3087 case SRB_STATUS_BUS_RESET
:
3088 scsicmd
->result
= DID_RESET
<< 16
3089 | COMMAND_COMPLETE
<< 8;
3092 case SRB_STATUS_MESSAGE_REJECTED
:
3093 scsicmd
->result
= DID_ERROR
<< 16
3094 | MESSAGE_REJECT
<< 8;
3096 case SRB_STATUS_REQUEST_FLUSHED
:
3097 case SRB_STATUS_ERROR
:
3098 case SRB_STATUS_INVALID_REQUEST
:
3099 case SRB_STATUS_REQUEST_SENSE_FAILED
:
3100 case SRB_STATUS_NO_HBA
:
3101 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
3102 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
3103 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
3104 case SRB_STATUS_DELAYED_RETRY
:
3105 case SRB_STATUS_BAD_FUNCTION
:
3106 case SRB_STATUS_NOT_STARTED
:
3107 case SRB_STATUS_NOT_IN_USE
:
3108 case SRB_STATUS_FORCE_ABORT
:
3109 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
3111 #ifdef AAC_DETAILED_STATUS_INFO
3112 printk(KERN_INFO
"aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
3113 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
3114 aac_get_status_string(
3115 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
3117 le32_to_cpu(srbreply
->scsi_status
));
3119 if ((scsicmd
->cmnd
[0] == ATA_12
)
3120 || (scsicmd
->cmnd
[0] == ATA_16
)) {
3121 if (scsicmd
->cmnd
[2] & (0x01 << 5)) {
3122 scsicmd
->result
= DID_OK
<< 16
3123 | COMMAND_COMPLETE
<< 8;
3126 scsicmd
->result
= DID_ERROR
<< 16
3127 | COMMAND_COMPLETE
<< 8;
3131 scsicmd
->result
= DID_ERROR
<< 16
3132 | COMMAND_COMPLETE
<< 8;
3136 if (le32_to_cpu(srbreply
->scsi_status
)
3137 == SAM_STAT_CHECK_CONDITION
) {
3140 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
3141 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3142 SCSI_SENSE_BUFFERSIZE
);
3143 #ifdef AAC_DETAILED_STATUS_INFO
3144 printk(KERN_WARNING
"aac_srb_callback: check condition, status = %d len=%d\n",
3145 le32_to_cpu(srbreply
->status
), len
);
3147 memcpy(scsicmd
->sense_buffer
,
3148 srbreply
->sense_data
, len
);
3152 * OR in the scsi status (already shifted up a bit)
3154 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
3156 aac_fib_complete(fibptr
);
3157 scsicmd
->scsi_done(scsicmd
);
3163 * @scsicmd: the scsi command block
3165 * This routine will form a FIB and fill in the aac_srb from the
3166 * scsicmd passed in.
3169 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
3171 struct fib
* cmd_fibcontext
;
3172 struct aac_dev
* dev
;
3175 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3176 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3177 scsicmd
->device
->lun
> 7) {
3178 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3179 scsicmd
->scsi_done(scsicmd
);
3184 * Allocate and initialize a Fib then setup a BlockWrite command
3186 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3187 if (!cmd_fibcontext
)
3190 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
3193 * Check that the command queued to the controller
3195 if (status
== -EINPROGRESS
) {
3196 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3200 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
3201 aac_fib_complete(cmd_fibcontext
);
3202 aac_fib_free(cmd_fibcontext
);
3207 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*psg
)
3209 struct aac_dev
*dev
;
3210 unsigned long byte_count
= 0;
3213 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3214 // Get rid of old data
3216 psg
->sg
[0].addr
= 0;
3217 psg
->sg
[0].count
= 0;
3219 nseg
= scsi_dma_map(scsicmd
);
3223 struct scatterlist
*sg
;
3226 psg
->count
= cpu_to_le32(nseg
);
3228 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3229 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
3230 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
3231 byte_count
+= sg_dma_len(sg
);
3233 /* hba wants the size to be exact */
3234 if (byte_count
> scsi_bufflen(scsicmd
)) {
3235 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3236 (byte_count
- scsi_bufflen(scsicmd
));
3237 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3238 byte_count
= scsi_bufflen(scsicmd
);
3240 /* Check for command underflow */
3241 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3242 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3243 byte_count
, scsicmd
->underflow
);
3250 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
)
3252 struct aac_dev
*dev
;
3253 unsigned long byte_count
= 0;
3257 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3258 // Get rid of old data
3260 psg
->sg
[0].addr
[0] = 0;
3261 psg
->sg
[0].addr
[1] = 0;
3262 psg
->sg
[0].count
= 0;
3264 nseg
= scsi_dma_map(scsicmd
);
3268 struct scatterlist
*sg
;
3271 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3272 int count
= sg_dma_len(sg
);
3273 addr
= sg_dma_address(sg
);
3274 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
3275 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
3276 psg
->sg
[i
].count
= cpu_to_le32(count
);
3277 byte_count
+= count
;
3279 psg
->count
= cpu_to_le32(nseg
);
3280 /* hba wants the size to be exact */
3281 if (byte_count
> scsi_bufflen(scsicmd
)) {
3282 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3283 (byte_count
- scsi_bufflen(scsicmd
));
3284 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3285 byte_count
= scsi_bufflen(scsicmd
);
3287 /* Check for command underflow */
3288 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3289 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3290 byte_count
, scsicmd
->underflow
);
3296 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
)
3298 unsigned long byte_count
= 0;
3301 // Get rid of old data
3303 psg
->sg
[0].next
= 0;
3304 psg
->sg
[0].prev
= 0;
3305 psg
->sg
[0].addr
[0] = 0;
3306 psg
->sg
[0].addr
[1] = 0;
3307 psg
->sg
[0].count
= 0;
3308 psg
->sg
[0].flags
= 0;
3310 nseg
= scsi_dma_map(scsicmd
);
3314 struct scatterlist
*sg
;
3317 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3318 int count
= sg_dma_len(sg
);
3319 u64 addr
= sg_dma_address(sg
);
3320 psg
->sg
[i
].next
= 0;
3321 psg
->sg
[i
].prev
= 0;
3322 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
3323 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
3324 psg
->sg
[i
].count
= cpu_to_le32(count
);
3325 psg
->sg
[i
].flags
= 0;
3326 byte_count
+= count
;
3328 psg
->count
= cpu_to_le32(nseg
);
3329 /* hba wants the size to be exact */
3330 if (byte_count
> scsi_bufflen(scsicmd
)) {
3331 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3332 (byte_count
- scsi_bufflen(scsicmd
));
3333 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3334 byte_count
= scsi_bufflen(scsicmd
);
3336 /* Check for command underflow */
3337 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3338 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3339 byte_count
, scsicmd
->underflow
);
3345 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
3346 struct aac_raw_io2
*rio2
, int sg_max
)
3348 unsigned long byte_count
= 0;
3351 nseg
= scsi_dma_map(scsicmd
);
3355 struct scatterlist
*sg
;
3356 int i
, conformable
= 0;
3357 u32 min_size
= PAGE_SIZE
, cur_size
;
3359 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3360 int count
= sg_dma_len(sg
);
3361 u64 addr
= sg_dma_address(sg
);
3363 BUG_ON(i
>= sg_max
);
3364 rio2
->sge
[i
].addrHigh
= cpu_to_le32((u32
)(addr
>>32));
3365 rio2
->sge
[i
].addrLow
= cpu_to_le32((u32
)(addr
& 0xffffffff));
3366 cur_size
= cpu_to_le32(count
);
3367 rio2
->sge
[i
].length
= cur_size
;
3368 rio2
->sge
[i
].flags
= 0;
3371 rio2
->sgeFirstSize
= cur_size
;
3372 } else if (i
== 1) {
3373 rio2
->sgeNominalSize
= cur_size
;
3374 min_size
= cur_size
;
3375 } else if ((i
+1) < nseg
&& cur_size
!= rio2
->sgeNominalSize
) {
3377 if (cur_size
< min_size
)
3378 min_size
= cur_size
;
3380 byte_count
+= count
;
3383 /* hba wants the size to be exact */
3384 if (byte_count
> scsi_bufflen(scsicmd
)) {
3385 u32 temp
= le32_to_cpu(rio2
->sge
[i
-1].length
) -
3386 (byte_count
- scsi_bufflen(scsicmd
));
3387 rio2
->sge
[i
-1].length
= cpu_to_le32(temp
);
3388 byte_count
= scsi_bufflen(scsicmd
);
3391 rio2
->sgeCnt
= cpu_to_le32(nseg
);
3392 rio2
->flags
|= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212
);
3393 /* not conformable: evaluate required sg elements */
3395 int j
, nseg_new
= nseg
, err_found
;
3396 for (i
= min_size
/ PAGE_SIZE
; i
>= 1; --i
) {
3399 for (j
= 1; j
< nseg
- 1; ++j
) {
3400 if (rio2
->sge
[j
].length
% (i
*PAGE_SIZE
)) {
3404 nseg_new
+= (rio2
->sge
[j
].length
/ (i
*PAGE_SIZE
));
3409 if (i
> 0 && nseg_new
<= sg_max
)
3410 aac_convert_sgraw2(rio2
, i
, nseg
, nseg_new
);
3412 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3414 /* Check for command underflow */
3415 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3416 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3417 byte_count
, scsicmd
->underflow
);
3424 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
, int pages
, int nseg
, int nseg_new
)
3426 struct sge_ieee1212
*sge
;
3430 if (aac_convert_sgl
== 0)
3433 sge
= kmalloc(nseg_new
* sizeof(struct sge_ieee1212
), GFP_ATOMIC
);
3437 for (i
= 1, pos
= 1; i
< nseg
-1; ++i
) {
3438 for (j
= 0; j
< rio2
->sge
[i
].length
/ (pages
* PAGE_SIZE
); ++j
) {
3439 addr_low
= rio2
->sge
[i
].addrLow
+ j
* pages
* PAGE_SIZE
;
3440 sge
[pos
].addrLow
= addr_low
;
3441 sge
[pos
].addrHigh
= rio2
->sge
[i
].addrHigh
;
3442 if (addr_low
< rio2
->sge
[i
].addrLow
)
3443 sge
[pos
].addrHigh
++;
3444 sge
[pos
].length
= pages
* PAGE_SIZE
;
3449 sge
[pos
] = rio2
->sge
[nseg
-1];
3450 memcpy(&rio2
->sge
[1], &sge
[1], (nseg_new
-1)*sizeof(struct sge_ieee1212
));
3453 rio2
->sgeCnt
= cpu_to_le32(nseg_new
);
3454 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3455 rio2
->sgeNominalSize
= pages
* PAGE_SIZE
;
3459 #ifdef AAC_DETAILED_STATUS_INFO
3461 struct aac_srb_status_info
{
3467 static struct aac_srb_status_info srb_status_info
[] = {
3468 { SRB_STATUS_PENDING
, "Pending Status"},
3469 { SRB_STATUS_SUCCESS
, "Success"},
3470 { SRB_STATUS_ABORTED
, "Aborted Command"},
3471 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
3472 { SRB_STATUS_ERROR
, "Error Event"},
3473 { SRB_STATUS_BUSY
, "Device Busy"},
3474 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
3475 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
3476 { SRB_STATUS_NO_DEVICE
, "No Device"},
3477 { SRB_STATUS_TIMEOUT
, "Timeout"},
3478 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
3479 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
3480 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
3481 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
3482 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
3483 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
3484 { SRB_STATUS_NO_HBA
, "No HBA"},
3485 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
3486 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
3487 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
3488 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
3489 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
3490 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
3491 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
3492 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
3493 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
3494 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
3495 { SRB_STATUS_NOT_STARTED
, "Not Started"},
3496 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
3497 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
3498 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
3499 { 0xff, "Unknown Error"}
3502 char *aac_get_status_string(u32 status
)
3506 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
3507 if (srb_status_info
[i
].status
== status
)
3508 return srb_status_info
[i
].str
;
3510 return "Bad Status Code";