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
);
559 aac_fib_init(cmd_fibcontext
);
560 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
562 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
563 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
564 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
565 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_name_resp
*)NULL
)->data
));
567 status
= aac_fib_send(ContainerCommand
,
569 sizeof(struct aac_get_name_resp
),
572 (fib_callback
)get_container_name_callback
,
576 * Check that the command queued to the controller
578 if (status
== -EINPROGRESS
) {
579 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
583 printk(KERN_WARNING
"aac_get_container_name: aac_fib_send failed with status: %d.\n", status
);
584 aac_fib_complete(cmd_fibcontext
);
588 static int aac_probe_container_callback2(struct scsi_cmnd
* scsicmd
)
590 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
592 if ((fsa_dev_ptr
[scmd_id(scsicmd
)].valid
& 1))
593 return aac_scsi_cmd(scsicmd
);
595 scsicmd
->result
= DID_NO_CONNECT
<< 16;
596 scsicmd
->scsi_done(scsicmd
);
600 static void _aac_probe_container2(void * context
, struct fib
* fibptr
)
602 struct fsa_dev_info
*fsa_dev_ptr
;
603 int (*callback
)(struct scsi_cmnd
*);
604 struct scsi_cmnd
* scsicmd
= (struct scsi_cmnd
*)context
;
607 if (!aac_valid_context(scsicmd
, fibptr
))
610 scsicmd
->SCp
.Status
= 0;
611 fsa_dev_ptr
= fibptr
->dev
->fsa_dev
;
613 struct aac_mount
* dresp
= (struct aac_mount
*) fib_data(fibptr
);
614 fsa_dev_ptr
+= scmd_id(scsicmd
);
616 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
617 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
618 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
619 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
620 AAC_OPTION_VARIABLE_BLOCK_SIZE
)) {
621 dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
= 0x200;
622 fsa_dev_ptr
->block_size
= 0x200;
624 fsa_dev_ptr
->block_size
=
625 le32_to_cpu(dresp
->mnt
[0].fileinfo
.bdevinfo
.block_size
);
627 fsa_dev_ptr
->valid
= 1;
628 /* sense_key holds the current state of the spin-up */
629 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
630 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
631 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
632 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
633 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
635 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
636 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
637 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
639 if ((fsa_dev_ptr
->valid
& 1) == 0)
640 fsa_dev_ptr
->valid
= 0;
641 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
643 aac_fib_complete(fibptr
);
644 aac_fib_free(fibptr
);
645 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
646 scsicmd
->SCp
.ptr
= NULL
;
647 (*callback
)(scsicmd
);
651 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
653 struct scsi_cmnd
* scsicmd
;
654 struct aac_mount
* dresp
;
655 struct aac_query_mount
*dinfo
;
658 dresp
= (struct aac_mount
*) fib_data(fibptr
);
659 if (!(fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
660 AAC_OPTION_VARIABLE_BLOCK_SIZE
))
661 dresp
->mnt
[0].capacityhigh
= 0;
662 if ((le32_to_cpu(dresp
->status
) != ST_OK
) ||
663 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
664 _aac_probe_container2(context
, fibptr
);
667 scsicmd
= (struct scsi_cmnd
*) context
;
669 if (!aac_valid_context(scsicmd
, fibptr
))
672 aac_fib_init(fibptr
);
674 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
676 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
677 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
678 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
680 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
682 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
683 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
685 status
= aac_fib_send(ContainerCommand
,
687 sizeof(struct aac_query_mount
),
690 _aac_probe_container2
,
693 * Check that the command queued to the controller
695 if (status
== -EINPROGRESS
)
696 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
697 else if (status
< 0) {
698 /* Inherit results from VM_NameServe, if any */
699 dresp
->status
= cpu_to_le32(ST_OK
);
700 _aac_probe_container2(context
, fibptr
);
704 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
707 int status
= -ENOMEM
;
709 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
710 struct aac_query_mount
*dinfo
;
712 aac_fib_init(fibptr
);
714 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
716 if (fibptr
->dev
->supplement_adapter_info
.SupportedOptions2
&
717 AAC_OPTION_VARIABLE_BLOCK_SIZE
)
718 dinfo
->command
= cpu_to_le32(VM_NameServeAllBlk
);
720 dinfo
->command
= cpu_to_le32(VM_NameServe
);
722 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
723 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
724 scsicmd
->SCp
.ptr
= (char *)callback
;
726 status
= aac_fib_send(ContainerCommand
,
728 sizeof(struct aac_query_mount
),
731 _aac_probe_container1
,
734 * Check that the command queued to the controller
736 if (status
== -EINPROGRESS
) {
737 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
741 scsicmd
->SCp
.ptr
= NULL
;
742 aac_fib_complete(fibptr
);
743 aac_fib_free(fibptr
);
747 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
749 fsa_dev_ptr
+= scmd_id(scsicmd
);
750 if ((fsa_dev_ptr
->valid
& 1) == 0) {
751 fsa_dev_ptr
->valid
= 0;
752 return (*callback
)(scsicmd
);
760 * aac_probe_container - query a logical volume
761 * @dev: device to query
762 * @cid: container identifier
764 * Queries the controller about the given volume. The volume information
765 * is updated in the struct fsa_dev_info structure rather than returned.
767 static int aac_probe_container_callback1(struct scsi_cmnd
* scsicmd
)
769 scsicmd
->device
= NULL
;
773 int aac_probe_container(struct aac_dev
*dev
, int cid
)
775 struct scsi_cmnd
*scsicmd
= kmalloc(sizeof(*scsicmd
), GFP_KERNEL
);
776 struct scsi_device
*scsidev
= kmalloc(sizeof(*scsidev
), GFP_KERNEL
);
779 if (!scsicmd
|| !scsidev
) {
784 scsicmd
->list
.next
= NULL
;
785 scsicmd
->scsi_done
= (void (*)(struct scsi_cmnd
*))aac_probe_container_callback1
;
787 scsicmd
->device
= scsidev
;
788 scsidev
->sdev_state
= 0;
790 scsidev
->host
= dev
->scsi_host_ptr
;
792 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
793 while (scsicmd
->device
== scsidev
)
796 status
= scsicmd
->SCp
.Status
;
801 /* Local Structure to set SCSI inquiry data strings */
803 char vid
[8]; /* Vendor ID */
804 char pid
[16]; /* Product ID */
805 char prl
[4]; /* Product Revision Level */
809 * InqStrCopy - string merge
810 * @a: string to copy from
811 * @b: string to copy to
813 * Copy a String from one location to another
817 static void inqstrcpy(char *a
, char *b
)
820 while (*a
!= (char)0)
824 static char *container_types
[] = {
848 char * get_container_type(unsigned tindex
)
850 if (tindex
>= ARRAY_SIZE(container_types
))
851 tindex
= ARRAY_SIZE(container_types
) - 1;
852 return container_types
[tindex
];
855 /* Function: setinqstr
857 * Arguments: [1] pointer to void [1] int
859 * Purpose: Sets SCSI inquiry data strings for vendor, product
860 * and revision level. Allows strings to be set in platform dependent
861 * files instead of in OS dependent driver source.
864 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
866 struct scsi_inq
*str
;
868 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
869 memset(str
, ' ', sizeof(*str
));
871 if (dev
->supplement_adapter_info
.AdapterTypeText
[0]) {
872 char * cp
= dev
->supplement_adapter_info
.AdapterTypeText
;
874 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
875 inqstrcpy("SMC", str
->vid
);
877 c
= sizeof(str
->vid
);
878 while (*cp
&& *cp
!= ' ' && --c
)
882 inqstrcpy (dev
->supplement_adapter_info
.AdapterTypeText
,
885 while (*cp
&& *cp
!= ' ')
890 /* last six chars reserved for vol type */
892 if (strlen(cp
) > sizeof(str
->pid
)) {
893 c
= cp
[sizeof(str
->pid
)];
894 cp
[sizeof(str
->pid
)] = '\0';
896 inqstrcpy (cp
, str
->pid
);
898 cp
[sizeof(str
->pid
)] = c
;
900 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
902 inqstrcpy (mp
->vname
, str
->vid
);
903 /* last six chars reserved for vol type */
904 inqstrcpy (mp
->model
, str
->pid
);
907 if (tindex
< ARRAY_SIZE(container_types
)){
908 char *findit
= str
->pid
;
910 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
911 /* RAID is superfluous in the context of a RAID device */
912 if (memcmp(findit
-4, "RAID", 4) == 0)
913 *(findit
-= 4) = ' ';
914 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
915 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
916 inqstrcpy (container_types
[tindex
], findit
+ 1);
918 inqstrcpy ("V1.0", str
->prl
);
921 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
923 struct aac_get_serial_resp
* get_serial_reply
;
924 struct scsi_cmnd
* scsicmd
;
926 BUG_ON(fibptr
== NULL
);
928 scsicmd
= (struct scsi_cmnd
*) context
;
929 if (!aac_valid_context(scsicmd
, fibptr
))
932 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
933 /* Failure is irrelevant, using default value instead */
934 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
935 /*Check to see if it's for VPD 0x83 or 0x80 */
936 if (scsicmd
->cmnd
[2] == 0x83) {
937 /* vpd page 0x83 - Device Identification Page */
939 TVPD_Page83 VPDPage83Data
;
941 memset(((u8
*)&VPDPage83Data
), 0,
942 sizeof(VPDPage83Data
));
944 /* DIRECT_ACCESS_DEVIC */
945 VPDPage83Data
.DeviceType
= 0;
946 /* DEVICE_CONNECTED */
947 VPDPage83Data
.DeviceTypeQualifier
= 0;
948 /* VPD_DEVICE_IDENTIFIERS */
949 VPDPage83Data
.PageCode
= 0x83;
950 VPDPage83Data
.Reserved
= 0;
951 VPDPage83Data
.PageLength
=
952 sizeof(VPDPage83Data
.IdDescriptorType1
) +
953 sizeof(VPDPage83Data
.IdDescriptorType2
);
955 /* T10 Vendor Identifier Field Format */
956 /* VpdCodeSetAscii */
957 VPDPage83Data
.IdDescriptorType1
.CodeSet
= 2;
958 /* VpdIdentifierTypeVendorId */
959 VPDPage83Data
.IdDescriptorType1
.IdentifierType
= 1;
960 VPDPage83Data
.IdDescriptorType1
.IdentifierLength
=
961 sizeof(VPDPage83Data
.IdDescriptorType1
) - 4;
963 /* "ADAPTEC " for adaptec */
964 memcpy(VPDPage83Data
.IdDescriptorType1
.VendId
,
966 sizeof(VPDPage83Data
.IdDescriptorType1
.VendId
));
967 memcpy(VPDPage83Data
.IdDescriptorType1
.ProductId
,
970 VPDPage83Data
.IdDescriptorType1
.ProductId
));
972 /* Convert to ascii based serial number.
973 * The LSB is the the end.
975 for (i
= 0; i
< 8; i
++) {
977 (u8
)((get_serial_reply
->uid
>> ((7 - i
) * 4)) & 0xF);
979 VPDPage83Data
.IdDescriptorType1
.SerialNumber
[i
] =
982 VPDPage83Data
.IdDescriptorType1
.SerialNumber
[i
] =
987 /* VpdCodeSetBinary */
988 VPDPage83Data
.IdDescriptorType2
.CodeSet
= 1;
989 /* VpdIdentifierTypeEUI64 */
990 VPDPage83Data
.IdDescriptorType2
.IdentifierType
= 2;
991 VPDPage83Data
.IdDescriptorType2
.IdentifierLength
=
992 sizeof(VPDPage83Data
.IdDescriptorType2
) - 4;
994 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[0] = 0xD0;
995 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[1] = 0;
996 VPDPage83Data
.IdDescriptorType2
.EU64Id
.VendId
[2] = 0;
998 VPDPage83Data
.IdDescriptorType2
.EU64Id
.Serial
=
999 get_serial_reply
->uid
;
1000 VPDPage83Data
.IdDescriptorType2
.EU64Id
.Reserved
= 0;
1002 /* Move the inquiry data to the response buffer. */
1003 scsi_sg_copy_from_buffer(scsicmd
, &VPDPage83Data
,
1004 sizeof(VPDPage83Data
));
1006 /* It must be for VPD 0x80 */
1009 sp
[0] = INQD_PDT_DA
;
1010 sp
[1] = scsicmd
->cmnd
[2];
1012 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
1013 le32_to_cpu(get_serial_reply
->uid
));
1014 scsi_sg_copy_from_buffer(scsicmd
, sp
,
1019 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1021 aac_fib_complete(fibptr
);
1022 scsicmd
->scsi_done(scsicmd
);
1026 * aac_get_container_serial - get container serial, none blocking.
1028 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
1031 struct aac_get_serial
*dinfo
;
1032 struct fib
* cmd_fibcontext
;
1033 struct aac_dev
* dev
;
1035 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1037 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
1039 aac_fib_init(cmd_fibcontext
);
1040 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
1042 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
1043 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
1044 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1046 status
= aac_fib_send(ContainerCommand
,
1048 sizeof(struct aac_get_serial_resp
),
1051 (fib_callback
) get_container_serial_callback
,
1055 * Check that the command queued to the controller
1057 if (status
== -EINPROGRESS
) {
1058 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1062 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
1063 aac_fib_complete(cmd_fibcontext
);
1067 /* Function: setinqserial
1069 * Arguments: [1] pointer to void [1] int
1071 * Purpose: Sets SCSI Unit Serial number.
1072 * This is a fake. We should read a proper
1073 * serial number from the container. <SuSE>But
1074 * without docs it's quite hard to do it :-)
1075 * So this will have to do in the meantime.</SuSE>
1078 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
1081 * This breaks array migration.
1083 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
1084 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
1087 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
1088 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
1090 u8
*sense_buf
= (u8
*)sense_data
;
1091 /* Sense data valid, err code 70h */
1092 sense_buf
[0] = 0x70; /* No info field */
1093 sense_buf
[1] = 0; /* Segment number, always zero */
1095 sense_buf
[2] = sense_key
; /* Sense key */
1097 sense_buf
[12] = sense_code
; /* Additional sense code */
1098 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
1100 if (sense_key
== ILLEGAL_REQUEST
) {
1101 sense_buf
[7] = 10; /* Additional sense length */
1103 sense_buf
[15] = bit_pointer
;
1104 /* Illegal parameter is in the parameter block */
1105 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
1106 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
1107 /* Illegal parameter is in the CDB block */
1108 sense_buf
[16] = field_pointer
>> 8; /* MSB */
1109 sense_buf
[17] = field_pointer
; /* LSB */
1111 sense_buf
[7] = 6; /* Additional sense length */
1114 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1116 if (lba
& 0xffffffff00000000LL
) {
1117 int cid
= scmd_id(cmd
);
1118 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1119 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1120 SAM_STAT_CHECK_CONDITION
;
1121 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1122 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1123 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1124 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1125 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1126 SCSI_SENSE_BUFFERSIZE
));
1127 cmd
->scsi_done(cmd
);
1133 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
1138 static void io_callback(void *context
, struct fib
* fibptr
);
1140 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1142 struct aac_dev
*dev
= fib
->dev
;
1143 u16 fibsize
, command
;
1147 if (dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
&& !dev
->sync_mode
) {
1148 struct aac_raw_io2
*readcmd2
;
1149 readcmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1150 memset(readcmd2
, 0, sizeof(struct aac_raw_io2
));
1151 readcmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1152 readcmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1153 readcmd2
->byteCount
= cpu_to_le32(count
*
1154 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1155 readcmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1156 readcmd2
->flags
= cpu_to_le16(RIO2_IO_TYPE_READ
);
1157 ret
= aac_build_sgraw2(cmd
, readcmd2
,
1158 dev
->scsi_host_ptr
->sg_tablesize
);
1161 command
= ContainerRawIo2
;
1162 fibsize
= sizeof(struct aac_raw_io2
) +
1163 ((le32_to_cpu(readcmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1165 struct aac_raw_io
*readcmd
;
1166 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
1167 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1168 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1169 readcmd
->count
= cpu_to_le32(count
*
1170 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1171 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1172 readcmd
->flags
= cpu_to_le16(RIO_TYPE_READ
);
1173 readcmd
->bpTotal
= 0;
1174 readcmd
->bpComplete
= 0;
1175 ret
= aac_build_sgraw(cmd
, &readcmd
->sg
);
1178 command
= ContainerRawIo
;
1179 fibsize
= sizeof(struct aac_raw_io
) +
1180 ((le32_to_cpu(readcmd
->sg
.count
)-1) * sizeof(struct sgentryraw
));
1183 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1185 * Now send the Fib to the adapter
1187 return aac_fib_send(command
,
1192 (fib_callback
) io_callback
,
1196 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1199 struct aac_read64
*readcmd
;
1203 readcmd
= (struct aac_read64
*) fib_data(fib
);
1204 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
1205 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1206 readcmd
->sector_count
= cpu_to_le16(count
);
1207 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1211 ret
= aac_build_sg64(cmd
, &readcmd
->sg
);
1214 fibsize
= sizeof(struct aac_read64
) +
1215 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1216 sizeof (struct sgentry64
));
1217 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1218 sizeof(struct aac_fibhdr
)));
1220 * Now send the Fib to the adapter
1222 return aac_fib_send(ContainerCommand64
,
1227 (fib_callback
) io_callback
,
1231 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1234 struct aac_read
*readcmd
;
1235 struct aac_dev
*dev
= fib
->dev
;
1239 readcmd
= (struct aac_read
*) fib_data(fib
);
1240 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
1241 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1242 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1243 readcmd
->count
= cpu_to_le32(count
*
1244 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1246 ret
= aac_build_sg(cmd
, &readcmd
->sg
);
1249 fibsize
= sizeof(struct aac_read
) +
1250 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1251 sizeof (struct sgentry
));
1252 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1253 sizeof(struct aac_fibhdr
)));
1255 * Now send the Fib to the adapter
1257 return aac_fib_send(ContainerCommand
,
1262 (fib_callback
) io_callback
,
1266 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1268 struct aac_dev
*dev
= fib
->dev
;
1269 u16 fibsize
, command
;
1273 if (dev
->comm_interface
== AAC_COMM_MESSAGE_TYPE2
&& !dev
->sync_mode
) {
1274 struct aac_raw_io2
*writecmd2
;
1275 writecmd2
= (struct aac_raw_io2
*) fib_data(fib
);
1276 memset(writecmd2
, 0, sizeof(struct aac_raw_io2
));
1277 writecmd2
->blockLow
= cpu_to_le32((u32
)(lba
&0xffffffff));
1278 writecmd2
->blockHigh
= cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1279 writecmd2
->byteCount
= cpu_to_le32(count
*
1280 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1281 writecmd2
->cid
= cpu_to_le16(scmd_id(cmd
));
1282 writecmd2
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1283 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1284 cpu_to_le16(RIO2_IO_TYPE_WRITE
|RIO2_IO_SUREWRITE
) :
1285 cpu_to_le16(RIO2_IO_TYPE_WRITE
);
1286 ret
= aac_build_sgraw2(cmd
, writecmd2
,
1287 dev
->scsi_host_ptr
->sg_tablesize
);
1290 command
= ContainerRawIo2
;
1291 fibsize
= sizeof(struct aac_raw_io2
) +
1292 ((le32_to_cpu(writecmd2
->sgeCnt
)-1) * sizeof(struct sge_ieee1212
));
1294 struct aac_raw_io
*writecmd
;
1295 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1296 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1297 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1298 writecmd
->count
= cpu_to_le32(count
*
1299 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1300 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1301 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1302 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1303 cpu_to_le16(RIO_TYPE_WRITE
|RIO_SUREWRITE
) :
1304 cpu_to_le16(RIO_TYPE_WRITE
);
1305 writecmd
->bpTotal
= 0;
1306 writecmd
->bpComplete
= 0;
1307 ret
= aac_build_sgraw(cmd
, &writecmd
->sg
);
1310 command
= ContainerRawIo
;
1311 fibsize
= sizeof(struct aac_raw_io
) +
1312 ((le32_to_cpu(writecmd
->sg
.count
)-1) * sizeof (struct sgentryraw
));
1315 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1317 * Now send the Fib to the adapter
1319 return aac_fib_send(command
,
1324 (fib_callback
) io_callback
,
1328 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1331 struct aac_write64
*writecmd
;
1335 writecmd
= (struct aac_write64
*) fib_data(fib
);
1336 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1337 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1338 writecmd
->sector_count
= cpu_to_le16(count
);
1339 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1341 writecmd
->flags
= 0;
1343 ret
= aac_build_sg64(cmd
, &writecmd
->sg
);
1346 fibsize
= sizeof(struct aac_write64
) +
1347 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1348 sizeof (struct sgentry64
));
1349 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1350 sizeof(struct aac_fibhdr
)));
1352 * Now send the Fib to the adapter
1354 return aac_fib_send(ContainerCommand64
,
1359 (fib_callback
) io_callback
,
1363 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1366 struct aac_write
*writecmd
;
1367 struct aac_dev
*dev
= fib
->dev
;
1371 writecmd
= (struct aac_write
*) fib_data(fib
);
1372 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1373 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1374 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1375 writecmd
->count
= cpu_to_le32(count
*
1376 dev
->fsa_dev
[scmd_id(cmd
)].block_size
);
1377 writecmd
->sg
.count
= cpu_to_le32(1);
1378 /* ->stable is not used - it did mean which type of write */
1380 ret
= aac_build_sg(cmd
, &writecmd
->sg
);
1383 fibsize
= sizeof(struct aac_write
) +
1384 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1385 sizeof (struct sgentry
));
1386 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1387 sizeof(struct aac_fibhdr
)));
1389 * Now send the Fib to the adapter
1391 return aac_fib_send(ContainerCommand
,
1396 (fib_callback
) io_callback
,
1400 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1402 struct aac_srb
* srbcmd
;
1407 switch(cmd
->sc_data_direction
){
1411 case DMA_BIDIRECTIONAL
:
1412 flag
= SRB_DataIn
| SRB_DataOut
;
1414 case DMA_FROM_DEVICE
:
1418 default: /* shuts up some versions of gcc */
1419 flag
= SRB_NoDataXfer
;
1423 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1424 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1425 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1426 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1427 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1428 srbcmd
->flags
= cpu_to_le32(flag
);
1429 timeout
= cmd
->request
->timeout
/HZ
;
1432 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1433 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1434 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1438 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1440 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1443 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1446 ret
= aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1449 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1451 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1452 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1454 * Build Scatter/Gather list
1456 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1457 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1458 sizeof (struct sgentry64
));
1459 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1460 sizeof(struct aac_fibhdr
)));
1463 * Now send the Fib to the adapter
1465 return aac_fib_send(ScsiPortCommand64
, fib
,
1466 fibsize
, FsaNormal
, 0, 1,
1467 (fib_callback
) aac_srb_callback
,
1471 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1474 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1477 ret
= aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1480 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1482 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1483 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1485 * Build Scatter/Gather list
1487 fibsize
= sizeof (struct aac_srb
) +
1488 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1489 sizeof (struct sgentry
));
1490 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1491 sizeof(struct aac_fibhdr
)));
1494 * Now send the Fib to the adapter
1496 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1497 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1500 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1502 if ((sizeof(dma_addr_t
) > 4) && fib
->dev
->needs_dac
&&
1503 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1505 return aac_scsi_32(fib
, cmd
);
1508 int aac_get_adapter_info(struct aac_dev
* dev
)
1513 struct aac_adapter_info
*info
;
1514 struct aac_bus_info
*command
;
1515 struct aac_bus_info_response
*bus_info
;
1517 if (!(fibptr
= aac_fib_alloc(dev
)))
1520 aac_fib_init(fibptr
);
1521 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
1522 memset(info
,0,sizeof(*info
));
1524 rcode
= aac_fib_send(RequestAdapterInfo
,
1528 -1, 1, /* First `interrupt' command uses special wait */
1533 /* FIB should be freed only after
1534 * getting the response from the F/W */
1535 if (rcode
!= -ERESTARTSYS
) {
1536 aac_fib_complete(fibptr
);
1537 aac_fib_free(fibptr
);
1541 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
1543 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
1544 struct aac_supplement_adapter_info
* sinfo
;
1546 aac_fib_init(fibptr
);
1548 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
1550 memset(sinfo
,0,sizeof(*sinfo
));
1552 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
1561 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
1562 if (rcode
== -ERESTARTSYS
) {
1563 fibptr
= aac_fib_alloc(dev
);
1575 aac_fib_init(fibptr
);
1577 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
1579 memset(bus_info
, 0, sizeof(*bus_info
));
1581 command
= (struct aac_bus_info
*)bus_info
;
1583 command
->Command
= cpu_to_le32(VM_Ioctl
);
1584 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
1585 command
->MethodId
= cpu_to_le32(1);
1586 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
1588 rcode
= aac_fib_send(ContainerCommand
,
1595 /* reasoned default */
1596 dev
->maximum_num_physicals
= 16;
1597 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
1598 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
1599 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
1602 if (!dev
->in_reset
) {
1604 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
1605 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
1611 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
1612 (int)sizeof(dev
->supplement_adapter_info
.BuildDate
),
1613 dev
->supplement_adapter_info
.BuildDate
);
1614 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
1615 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
1617 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1618 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
1619 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
1620 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
1622 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1623 le32_to_cpu(dev
->adapter_info
.biosbuild
));
1625 if (aac_get_serial_number(
1626 shost_to_class(dev
->scsi_host_ptr
), buffer
))
1627 printk(KERN_INFO
"%s%d: serial %s",
1628 dev
->name
, dev
->id
, buffer
);
1629 if (dev
->supplement_adapter_info
.VpdInfo
.Tsid
[0]) {
1630 printk(KERN_INFO
"%s%d: TSID %.*s\n",
1632 (int)sizeof(dev
->supplement_adapter_info
.VpdInfo
.Tsid
),
1633 dev
->supplement_adapter_info
.VpdInfo
.Tsid
);
1635 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
1636 (dev
->supplement_adapter_info
.SupportedOptions2
&
1637 AAC_OPTION_IGNORE_RESET
))) {
1638 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
1639 dev
->name
, dev
->id
);
1643 dev
->cache_protected
= 0;
1644 dev
->jbod
= ((dev
->supplement_adapter_info
.FeatureBits
&
1645 AAC_FEATURE_JBOD
) != 0);
1646 dev
->nondasd_support
= 0;
1647 dev
->raid_scsi_mode
= 0;
1648 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
1649 dev
->nondasd_support
= 1;
1652 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1653 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1654 * force nondasd support on. If we decide to allow the non-dasd flag
1655 * additional changes changes will have to be made to support
1656 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1657 * changed to support the new dev->raid_scsi_mode flag instead of
1658 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1659 * function aac_detect will have to be modified where it sets up the
1660 * max number of channels based on the aac->nondasd_support flag only.
1662 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
1663 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
1664 dev
->nondasd_support
= 1;
1665 dev
->raid_scsi_mode
= 1;
1667 if (dev
->raid_scsi_mode
!= 0)
1668 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
1669 dev
->name
, dev
->id
);
1672 dev
->nondasd_support
= (nondasd
!=0);
1673 if (dev
->nondasd_support
&& !dev
->in_reset
)
1674 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
1676 if (dma_get_required_mask(&dev
->pdev
->dev
) > DMA_BIT_MASK(32))
1678 dev
->dac_support
= 0;
1679 if ((sizeof(dma_addr_t
) > 4) && dev
->needs_dac
&&
1680 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)) {
1682 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
1683 dev
->name
, dev
->id
);
1684 dev
->dac_support
= 1;
1688 dev
->dac_support
= (dacmode
!=0);
1691 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1692 if (dev
->dac_support
&& (aac_get_driver_ident(dev
->cardtype
)->quirks
1693 & AAC_QUIRK_SCSI_32
)) {
1694 dev
->nondasd_support
= 0;
1696 expose_physicals
= 0;
1699 if(dev
->dac_support
!= 0) {
1700 if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(64)) &&
1701 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(64))) {
1703 printk(KERN_INFO
"%s%d: 64 Bit DAC enabled\n",
1704 dev
->name
, dev
->id
);
1705 } else if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(32)) &&
1706 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(32))) {
1707 printk(KERN_INFO
"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1708 dev
->name
, dev
->id
);
1709 dev
->dac_support
= 0;
1711 printk(KERN_WARNING
"%s%d: No suitable DMA available.\n",
1712 dev
->name
, dev
->id
);
1717 * Deal with configuring for the individualized limits of each packet
1720 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
1721 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
1725 if (dev
->raw_io_interface
) {
1726 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
1729 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
1730 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
1732 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
1733 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
1734 sizeof(struct aac_fibhdr
) -
1735 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
1736 sizeof(struct sgentry
);
1737 if (dev
->dac_support
) {
1738 dev
->a_ops
.adapter_read
= aac_read_block64
;
1739 dev
->a_ops
.adapter_write
= aac_write_block64
;
1741 * 38 scatter gather elements
1743 dev
->scsi_host_ptr
->sg_tablesize
=
1744 (dev
->max_fib_size
-
1745 sizeof(struct aac_fibhdr
) -
1746 sizeof(struct aac_write64
) +
1747 sizeof(struct sgentry64
)) /
1748 sizeof(struct sgentry64
);
1750 dev
->a_ops
.adapter_read
= aac_read_block
;
1751 dev
->a_ops
.adapter_write
= aac_write_block
;
1753 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
1754 if (!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
1756 * Worst case size that could cause sg overflow when
1757 * we break up SG elements that are larger than 64KB.
1758 * Would be nice if we could tell the SCSI layer what
1759 * the maximum SG element size can be. Worst case is
1760 * (sg_tablesize-1) 4KB elements with one 64KB
1762 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1764 dev
->scsi_host_ptr
->max_sectors
=
1765 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
1768 /* FIB should be freed only after getting the response from the F/W */
1769 if (rcode
!= -ERESTARTSYS
) {
1770 aac_fib_complete(fibptr
);
1771 aac_fib_free(fibptr
);
1778 static void io_callback(void *context
, struct fib
* fibptr
)
1780 struct aac_dev
*dev
;
1781 struct aac_read_reply
*readreply
;
1782 struct scsi_cmnd
*scsicmd
;
1785 scsicmd
= (struct scsi_cmnd
*) context
;
1787 if (!aac_valid_context(scsicmd
, fibptr
))
1791 cid
= scmd_id(scsicmd
);
1793 if (nblank(dprintk(x
))) {
1795 switch (scsicmd
->cmnd
[0]) {
1798 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1799 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1803 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1804 ((u64
)scsicmd
->cmnd
[3] << 48) |
1805 ((u64
)scsicmd
->cmnd
[4] << 40) |
1806 ((u64
)scsicmd
->cmnd
[5] << 32) |
1807 ((u64
)scsicmd
->cmnd
[6] << 24) |
1808 (scsicmd
->cmnd
[7] << 16) |
1809 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1813 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1814 (scsicmd
->cmnd
[3] << 16) |
1815 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1818 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1819 (scsicmd
->cmnd
[3] << 16) |
1820 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1824 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1825 smp_processor_id(), (unsigned long long)lba
, jiffies
);
1828 BUG_ON(fibptr
== NULL
);
1830 scsi_dma_unmap(scsicmd
);
1832 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
1833 switch (le32_to_cpu(readreply
->status
)) {
1835 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1837 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
1840 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1841 SAM_STAT_CHECK_CONDITION
;
1842 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
1843 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
1844 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1845 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1846 SCSI_SENSE_BUFFERSIZE
));
1849 #ifdef AAC_DETAILED_STATUS_INFO
1850 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
1851 le32_to_cpu(readreply
->status
));
1853 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1854 SAM_STAT_CHECK_CONDITION
;
1855 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1856 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1857 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1858 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1859 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1860 SCSI_SENSE_BUFFERSIZE
));
1863 aac_fib_complete(fibptr
);
1865 scsicmd
->scsi_done(scsicmd
);
1868 static int aac_read(struct scsi_cmnd
* scsicmd
)
1873 struct aac_dev
*dev
;
1874 struct fib
* cmd_fibcontext
;
1877 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1879 * Get block address and transfer length
1881 switch (scsicmd
->cmnd
[0]) {
1883 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
1885 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1886 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1887 count
= scsicmd
->cmnd
[4];
1893 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
1895 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1896 ((u64
)scsicmd
->cmnd
[3] << 48) |
1897 ((u64
)scsicmd
->cmnd
[4] << 40) |
1898 ((u64
)scsicmd
->cmnd
[5] << 32) |
1899 ((u64
)scsicmd
->cmnd
[6] << 24) |
1900 (scsicmd
->cmnd
[7] << 16) |
1901 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1902 count
= (scsicmd
->cmnd
[10] << 24) |
1903 (scsicmd
->cmnd
[11] << 16) |
1904 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
1907 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
1909 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1910 (scsicmd
->cmnd
[3] << 16) |
1911 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1912 count
= (scsicmd
->cmnd
[6] << 24) |
1913 (scsicmd
->cmnd
[7] << 16) |
1914 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1917 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
1919 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1920 (scsicmd
->cmnd
[3] << 16) |
1921 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1922 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1926 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
1927 cid
= scmd_id(scsicmd
);
1928 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1929 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1930 SAM_STAT_CHECK_CONDITION
;
1931 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1932 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1933 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1934 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1935 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1936 SCSI_SENSE_BUFFERSIZE
));
1937 scsicmd
->scsi_done(scsicmd
);
1941 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1942 smp_processor_id(), (unsigned long long)lba
, jiffies
));
1943 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
1946 * Alocate and initialize a Fib
1948 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
1950 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
1953 * Check that the command queued to the controller
1955 if (status
== -EINPROGRESS
) {
1956 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1960 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
1962 * For some reason, the Fib didn't queue, return QUEUE_FULL
1964 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
1965 scsicmd
->scsi_done(scsicmd
);
1966 aac_fib_complete(cmd_fibcontext
);
1967 aac_fib_free(cmd_fibcontext
);
1971 static int aac_write(struct scsi_cmnd
* scsicmd
)
1977 struct aac_dev
*dev
;
1978 struct fib
* cmd_fibcontext
;
1981 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1983 * Get block address and transfer length
1985 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
1987 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1988 count
= scsicmd
->cmnd
[4];
1992 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
1993 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
1995 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1996 ((u64
)scsicmd
->cmnd
[3] << 48) |
1997 ((u64
)scsicmd
->cmnd
[4] << 40) |
1998 ((u64
)scsicmd
->cmnd
[5] << 32) |
1999 ((u64
)scsicmd
->cmnd
[6] << 24) |
2000 (scsicmd
->cmnd
[7] << 16) |
2001 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2002 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
2003 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
2004 fua
= scsicmd
->cmnd
[1] & 0x8;
2005 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
2006 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
2008 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
2009 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2010 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
2011 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
2012 fua
= scsicmd
->cmnd
[1] & 0x8;
2014 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
2015 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2016 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2017 fua
= scsicmd
->cmnd
[1] & 0x8;
2020 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
2021 cid
= scmd_id(scsicmd
);
2022 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
2023 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2024 SAM_STAT_CHECK_CONDITION
;
2025 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2026 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2027 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2028 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2029 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2030 SCSI_SENSE_BUFFERSIZE
));
2031 scsicmd
->scsi_done(scsicmd
);
2035 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2036 smp_processor_id(), (unsigned long long)lba
, jiffies
));
2037 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
2040 * Allocate and initialize a Fib then setup a BlockWrite command
2042 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
2044 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
2047 * Check that the command queued to the controller
2049 if (status
== -EINPROGRESS
) {
2050 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2054 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
2056 * For some reason, the Fib didn't queue, return QUEUE_FULL
2058 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
2059 scsicmd
->scsi_done(scsicmd
);
2061 aac_fib_complete(cmd_fibcontext
);
2062 aac_fib_free(cmd_fibcontext
);
2066 static void synchronize_callback(void *context
, struct fib
*fibptr
)
2068 struct aac_synchronize_reply
*synchronizereply
;
2069 struct scsi_cmnd
*cmd
;
2073 if (!aac_valid_context(cmd
, fibptr
))
2076 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
2077 smp_processor_id(), jiffies
));
2078 BUG_ON(fibptr
== NULL
);
2081 synchronizereply
= fib_data(fibptr
);
2082 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
2083 cmd
->result
= DID_OK
<< 16 |
2084 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2086 struct scsi_device
*sdev
= cmd
->device
;
2087 struct aac_dev
*dev
= fibptr
->dev
;
2088 u32 cid
= sdev_id(sdev
);
2090 "synchronize_callback: synchronize failed, status = %d\n",
2091 le32_to_cpu(synchronizereply
->status
));
2092 cmd
->result
= DID_OK
<< 16 |
2093 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2094 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2095 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
2096 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
2097 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2098 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2099 SCSI_SENSE_BUFFERSIZE
));
2102 aac_fib_complete(fibptr
);
2103 aac_fib_free(fibptr
);
2104 cmd
->scsi_done(cmd
);
2107 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
2110 struct fib
*cmd_fibcontext
;
2111 struct aac_synchronize
*synchronizecmd
;
2112 struct scsi_cmnd
*cmd
;
2113 struct scsi_device
*sdev
= scsicmd
->device
;
2115 struct aac_dev
*aac
;
2116 u64 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) |
2117 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
2118 u32 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
2119 unsigned long flags
;
2122 * Wait for all outstanding queued commands to complete to this
2123 * specific target (block).
2125 spin_lock_irqsave(&sdev
->list_lock
, flags
);
2126 list_for_each_entry(cmd
, &sdev
->cmd_list
, list
)
2127 if (cmd
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
2131 if (cmd
->cmnd
[0] == WRITE_6
) {
2132 cmnd_lba
= ((cmd
->cmnd
[1] & 0x1F) << 16) |
2133 (cmd
->cmnd
[2] << 8) |
2135 cmnd_count
= cmd
->cmnd
[4];
2136 if (cmnd_count
== 0)
2138 } else if (cmd
->cmnd
[0] == WRITE_16
) {
2139 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 56) |
2140 ((u64
)cmd
->cmnd
[3] << 48) |
2141 ((u64
)cmd
->cmnd
[4] << 40) |
2142 ((u64
)cmd
->cmnd
[5] << 32) |
2143 ((u64
)cmd
->cmnd
[6] << 24) |
2144 (cmd
->cmnd
[7] << 16) |
2145 (cmd
->cmnd
[8] << 8) |
2147 cmnd_count
= (cmd
->cmnd
[10] << 24) |
2148 (cmd
->cmnd
[11] << 16) |
2149 (cmd
->cmnd
[12] << 8) |
2151 } else if (cmd
->cmnd
[0] == WRITE_12
) {
2152 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2153 (cmd
->cmnd
[3] << 16) |
2154 (cmd
->cmnd
[4] << 8) |
2156 cmnd_count
= (cmd
->cmnd
[6] << 24) |
2157 (cmd
->cmnd
[7] << 16) |
2158 (cmd
->cmnd
[8] << 8) |
2160 } else if (cmd
->cmnd
[0] == WRITE_10
) {
2161 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
2162 (cmd
->cmnd
[3] << 16) |
2163 (cmd
->cmnd
[4] << 8) |
2165 cmnd_count
= (cmd
->cmnd
[7] << 8) |
2169 if (((cmnd_lba
+ cmnd_count
) < lba
) ||
2170 (count
&& ((lba
+ count
) < cmnd_lba
)))
2176 spin_unlock_irqrestore(&sdev
->list_lock
, flags
);
2179 * Yield the processor (requeue for later)
2182 return SCSI_MLQUEUE_DEVICE_BUSY
;
2184 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2186 return SCSI_MLQUEUE_HOST_BUSY
;
2189 * Allocate and initialize a Fib
2191 if (!(cmd_fibcontext
= aac_fib_alloc(aac
)))
2192 return SCSI_MLQUEUE_HOST_BUSY
;
2194 aac_fib_init(cmd_fibcontext
);
2196 synchronizecmd
= fib_data(cmd_fibcontext
);
2197 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2198 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
2199 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
2200 synchronizecmd
->count
=
2201 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
2204 * Now send the Fib to the adapter
2206 status
= aac_fib_send(ContainerCommand
,
2208 sizeof(struct aac_synchronize
),
2211 (fib_callback
)synchronize_callback
,
2215 * Check that the command queued to the controller
2217 if (status
== -EINPROGRESS
) {
2218 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2223 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
2224 aac_fib_complete(cmd_fibcontext
);
2225 aac_fib_free(cmd_fibcontext
);
2226 return SCSI_MLQUEUE_HOST_BUSY
;
2229 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
2231 struct scsi_cmnd
*scsicmd
= context
;
2233 if (!aac_valid_context(scsicmd
, fibptr
))
2236 BUG_ON(fibptr
== NULL
);
2238 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2240 aac_fib_complete(fibptr
);
2241 aac_fib_free(fibptr
);
2242 scsicmd
->scsi_done(scsicmd
);
2245 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
2248 struct fib
*cmd_fibcontext
;
2249 struct aac_power_management
*pmcmd
;
2250 struct scsi_device
*sdev
= scsicmd
->device
;
2251 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2253 if (!(aac
->supplement_adapter_info
.SupportedOptions2
&
2254 AAC_OPTION_POWER_MANAGEMENT
)) {
2255 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2257 scsicmd
->scsi_done(scsicmd
);
2262 return SCSI_MLQUEUE_HOST_BUSY
;
2265 * Allocate and initialize a Fib
2267 cmd_fibcontext
= aac_fib_alloc_tag(aac
, scsicmd
);
2269 aac_fib_init(cmd_fibcontext
);
2271 pmcmd
= fib_data(cmd_fibcontext
);
2272 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2273 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
2274 /* Eject bit ignored, not relevant */
2275 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
2276 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
2277 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
2278 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
2279 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
2282 * Now send the Fib to the adapter
2284 status
= aac_fib_send(ContainerCommand
,
2286 sizeof(struct aac_power_management
),
2289 (fib_callback
)aac_start_stop_callback
,
2293 * Check that the command queued to the controller
2295 if (status
== -EINPROGRESS
) {
2296 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2300 aac_fib_complete(cmd_fibcontext
);
2301 aac_fib_free(cmd_fibcontext
);
2302 return SCSI_MLQUEUE_HOST_BUSY
;
2306 * aac_scsi_cmd() - Process SCSI command
2307 * @scsicmd: SCSI command block
2309 * Emulate a SCSI command and queue the required request for the
2313 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
2316 struct Scsi_Host
*host
= scsicmd
->device
->host
;
2317 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
2318 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
2320 if (fsa_dev_ptr
== NULL
)
2323 * If the bus, id or lun is out of range, return fail
2324 * Test does not apply to ID 16, the pseudo id for the controller
2327 cid
= scmd_id(scsicmd
);
2328 if (cid
!= host
->this_id
) {
2329 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
2330 if((cid
>= dev
->maximum_num_containers
) ||
2331 (scsicmd
->device
->lun
!= 0)) {
2332 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2333 scsicmd
->scsi_done(scsicmd
);
2338 * If the target container doesn't exist, it may have
2339 * been newly created
2341 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2342 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2344 switch (scsicmd
->cmnd
[0]) {
2345 case SERVICE_ACTION_IN_16
:
2346 if (!(dev
->raw_io_interface
) ||
2347 !(dev
->raw_io_64
) ||
2348 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2352 case TEST_UNIT_READY
:
2355 return _aac_probe_container(scsicmd
,
2356 aac_probe_container_callback2
);
2361 } else { /* check for physical non-dasd devices */
2362 if (dev
->nondasd_support
|| expose_physicals
||
2366 return aac_send_srb_fib(scsicmd
);
2368 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2369 scsicmd
->scsi_done(scsicmd
);
2375 * else Command for the controller itself
2377 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2378 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2380 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2381 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2382 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2383 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2384 ASENCODE_INVALID_COMMAND
, 0, 0);
2385 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2386 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2387 SCSI_SENSE_BUFFERSIZE
));
2388 scsicmd
->scsi_done(scsicmd
);
2393 /* Handle commands here that don't really require going out to the adapter */
2394 switch (scsicmd
->cmnd
[0]) {
2397 struct inquiry_data inq_data
;
2399 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2400 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2402 if ((scsicmd
->cmnd
[1] & 0x1) && aac_wwn
) {
2403 char *arr
= (char *)&inq_data
;
2406 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2407 INQD_PDT_PROC
: INQD_PDT_DA
;
2408 if (scsicmd
->cmnd
[2] == 0) {
2409 /* supported vital product data pages */
2414 arr
[1] = scsicmd
->cmnd
[2];
2415 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2417 scsicmd
->result
= DID_OK
<< 16 |
2418 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2419 } else if (scsicmd
->cmnd
[2] == 0x80) {
2420 /* unit serial number page */
2421 arr
[3] = setinqserial(dev
, &arr
[4],
2423 arr
[1] = scsicmd
->cmnd
[2];
2424 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2427 return aac_get_container_serial(
2429 scsicmd
->result
= DID_OK
<< 16 |
2430 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2431 } else if (scsicmd
->cmnd
[2] == 0x83) {
2432 /* vpd page 0x83 - Device Identification Page */
2433 char *sno
= (char *)&inq_data
;
2434 sno
[3] = setinqserial(dev
, &sno
[4],
2437 return aac_get_container_serial(
2439 scsicmd
->result
= DID_OK
<< 16 |
2440 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2442 /* vpd page not implemented */
2443 scsicmd
->result
= DID_OK
<< 16 |
2444 COMMAND_COMPLETE
<< 8 |
2445 SAM_STAT_CHECK_CONDITION
;
2446 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2447 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2448 ASENCODE_NO_SENSE
, 7, 2);
2449 memcpy(scsicmd
->sense_buffer
,
2450 &dev
->fsa_dev
[cid
].sense_data
,
2452 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2453 SCSI_SENSE_BUFFERSIZE
));
2455 scsicmd
->scsi_done(scsicmd
);
2458 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2459 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 */
2460 inq_data
.inqd_len
= 31;
2461 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2462 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2464 * Set the Vendor, Product, and Revision Level
2465 * see: <vendor>.c i.e. aac.c
2467 if (cid
== host
->this_id
) {
2468 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2469 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2470 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2472 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2473 scsicmd
->scsi_done(scsicmd
);
2478 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2479 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2480 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2481 return aac_get_container_name(scsicmd
);
2483 case SERVICE_ACTION_IN_16
:
2484 if (!(dev
->raw_io_interface
) ||
2485 !(dev
->raw_io_64
) ||
2486 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2491 unsigned int alloc_len
;
2493 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2494 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2495 cp
[0] = (capacity
>> 56) & 0xff;
2496 cp
[1] = (capacity
>> 48) & 0xff;
2497 cp
[2] = (capacity
>> 40) & 0xff;
2498 cp
[3] = (capacity
>> 32) & 0xff;
2499 cp
[4] = (capacity
>> 24) & 0xff;
2500 cp
[5] = (capacity
>> 16) & 0xff;
2501 cp
[6] = (capacity
>> 8) & 0xff;
2502 cp
[7] = (capacity
>> 0) & 0xff;
2503 cp
[8] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2504 cp
[9] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2505 cp
[10] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2506 cp
[11] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2509 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
2510 + (scsicmd
->cmnd
[11] << 16)
2511 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
2513 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
2514 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
2515 if (alloc_len
< scsi_bufflen(scsicmd
))
2516 scsi_set_resid(scsicmd
,
2517 scsi_bufflen(scsicmd
) - alloc_len
);
2519 /* Do not cache partition table for arrays */
2520 scsicmd
->device
->removable
= 1;
2522 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2523 scsicmd
->scsi_done(scsicmd
);
2533 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
2534 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2535 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2539 cp
[0] = (capacity
>> 24) & 0xff;
2540 cp
[1] = (capacity
>> 16) & 0xff;
2541 cp
[2] = (capacity
>> 8) & 0xff;
2542 cp
[3] = (capacity
>> 0) & 0xff;
2543 cp
[4] = (fsa_dev_ptr
[cid
].block_size
>> 24) & 0xff;
2544 cp
[5] = (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2545 cp
[6] = (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2546 cp
[7] = (fsa_dev_ptr
[cid
].block_size
) & 0xff;
2547 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
2548 /* Do not cache partition table for arrays */
2549 scsicmd
->device
->removable
= 1;
2550 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2552 scsicmd
->scsi_done(scsicmd
);
2559 int mode_buf_length
= 4;
2563 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2564 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2568 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
2569 memset((char *)&mpd
, 0, sizeof(aac_modep_data
));
2571 /* Mode data length */
2572 mpd
.hd
.data_length
= sizeof(mpd
.hd
) - 1;
2573 /* Medium type - default */
2574 mpd
.hd
.med_type
= 0;
2575 /* Device-specific param,
2576 bit 8: 0/1 = write enabled/protected
2577 bit 4: 0/1 = FUA enabled */
2580 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2581 mpd
.hd
.dev_par
= 0x10;
2582 if (scsicmd
->cmnd
[1] & 0x8)
2583 mpd
.hd
.bd_length
= 0; /* Block descriptor length */
2585 mpd
.hd
.bd_length
= sizeof(mpd
.bd
);
2586 mpd
.hd
.data_length
+= mpd
.hd
.bd_length
;
2587 mpd
.bd
.block_length
[0] =
2588 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2589 mpd
.bd
.block_length
[1] =
2590 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2591 mpd
.bd
.block_length
[2] =
2592 fsa_dev_ptr
[cid
].block_size
& 0xff;
2594 mpd
.mpc_buf
[0] = scsicmd
->cmnd
[2];
2595 if (scsicmd
->cmnd
[2] == 0x1C) {
2597 mpd
.mpc_buf
[1] = 0xa;
2598 /* Mode data length */
2599 mpd
.hd
.data_length
= 23;
2601 /* Mode data length */
2602 mpd
.hd
.data_length
= 15;
2605 if (capacity
> 0xffffff) {
2606 mpd
.bd
.block_count
[0] = 0xff;
2607 mpd
.bd
.block_count
[1] = 0xff;
2608 mpd
.bd
.block_count
[2] = 0xff;
2610 mpd
.bd
.block_count
[0] = (capacity
>> 16) & 0xff;
2611 mpd
.bd
.block_count
[1] = (capacity
>> 8) & 0xff;
2612 mpd
.bd
.block_count
[2] = capacity
& 0xff;
2615 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2616 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2617 mpd
.hd
.data_length
+= 3;
2620 mpd
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
2621 ? 0 : 0x04; /* WCE */
2622 mode_buf_length
= sizeof(mpd
);
2625 if (mode_buf_length
> scsicmd
->cmnd
[4])
2626 mode_buf_length
= scsicmd
->cmnd
[4];
2628 mode_buf_length
= sizeof(mpd
);
2629 scsi_sg_copy_from_buffer(scsicmd
,
2632 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2633 scsicmd
->scsi_done(scsicmd
);
2640 int mode_buf_length
= 8;
2641 aac_modep10_data mpd10
;
2643 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2644 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2648 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
2649 memset((char *)&mpd10
, 0, sizeof(aac_modep10_data
));
2650 /* Mode data length (MSB) */
2651 mpd10
.hd
.data_length
[0] = 0;
2652 /* Mode data length (LSB) */
2653 mpd10
.hd
.data_length
[1] = sizeof(mpd10
.hd
) - 1;
2654 /* Medium type - default */
2655 mpd10
.hd
.med_type
= 0;
2656 /* Device-specific param,
2657 bit 8: 0/1 = write enabled/protected
2658 bit 4: 0/1 = FUA enabled */
2659 mpd10
.hd
.dev_par
= 0;
2661 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2662 mpd10
.hd
.dev_par
= 0x10;
2663 mpd10
.hd
.rsrvd
[0] = 0; /* reserved */
2664 mpd10
.hd
.rsrvd
[1] = 0; /* reserved */
2665 if (scsicmd
->cmnd
[1] & 0x8) {
2666 /* Block descriptor length (MSB) */
2667 mpd10
.hd
.bd_length
[0] = 0;
2668 /* Block descriptor length (LSB) */
2669 mpd10
.hd
.bd_length
[1] = 0;
2671 mpd10
.hd
.bd_length
[0] = 0;
2672 mpd10
.hd
.bd_length
[1] = sizeof(mpd10
.bd
);
2674 mpd10
.hd
.data_length
[1] += mpd10
.hd
.bd_length
[1];
2676 mpd10
.bd
.block_length
[0] =
2677 (fsa_dev_ptr
[cid
].block_size
>> 16) & 0xff;
2678 mpd10
.bd
.block_length
[1] =
2679 (fsa_dev_ptr
[cid
].block_size
>> 8) & 0xff;
2680 mpd10
.bd
.block_length
[2] =
2681 fsa_dev_ptr
[cid
].block_size
& 0xff;
2683 if (capacity
> 0xffffff) {
2684 mpd10
.bd
.block_count
[0] = 0xff;
2685 mpd10
.bd
.block_count
[1] = 0xff;
2686 mpd10
.bd
.block_count
[2] = 0xff;
2688 mpd10
.bd
.block_count
[0] =
2689 (capacity
>> 16) & 0xff;
2690 mpd10
.bd
.block_count
[1] =
2691 (capacity
>> 8) & 0xff;
2692 mpd10
.bd
.block_count
[2] =
2696 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2697 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2698 mpd10
.hd
.data_length
[1] += 3;
2699 mpd10
.mpc_buf
[0] = 8;
2700 mpd10
.mpc_buf
[1] = 1;
2701 mpd10
.mpc_buf
[2] = ((aac_cache
& 6) == 2)
2702 ? 0 : 0x04; /* WCE */
2703 mode_buf_length
= sizeof(mpd10
);
2704 if (mode_buf_length
> scsicmd
->cmnd
[8])
2705 mode_buf_length
= scsicmd
->cmnd
[8];
2707 scsi_sg_copy_from_buffer(scsicmd
,
2711 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2712 scsicmd
->scsi_done(scsicmd
);
2717 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
2718 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
, sizeof (struct sense_data
));
2719 memset(&dev
->fsa_dev
[cid
].sense_data
, 0, sizeof (struct sense_data
));
2720 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2721 scsicmd
->scsi_done(scsicmd
);
2724 case ALLOW_MEDIUM_REMOVAL
:
2725 dprintk((KERN_DEBUG
"LOCK command.\n"));
2726 if (scsicmd
->cmnd
[4])
2727 fsa_dev_ptr
[cid
].locked
= 1;
2729 fsa_dev_ptr
[cid
].locked
= 0;
2731 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2732 scsicmd
->scsi_done(scsicmd
);
2735 * These commands are all No-Ops
2737 case TEST_UNIT_READY
:
2738 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
2739 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2740 SAM_STAT_CHECK_CONDITION
;
2741 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2742 NOT_READY
, SENCODE_BECOMING_READY
,
2743 ASENCODE_BECOMING_READY
, 0, 0);
2744 memcpy(scsicmd
->sense_buffer
,
2745 &dev
->fsa_dev
[cid
].sense_data
,
2747 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2748 SCSI_SENSE_BUFFERSIZE
));
2749 scsicmd
->scsi_done(scsicmd
);
2756 case REASSIGN_BLOCKS
:
2758 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2759 scsicmd
->scsi_done(scsicmd
);
2763 return aac_start_stop(scsicmd
);
2766 switch (scsicmd
->cmnd
[0])
2775 * Hack to keep track of ordinal number of the device that
2776 * corresponds to a container. Needed to convert
2777 * containers to /dev/sd device names
2780 if (scsicmd
->request
->rq_disk
)
2781 strlcpy(fsa_dev_ptr
[cid
].devname
,
2782 scsicmd
->request
->rq_disk
->disk_name
,
2783 min(sizeof(fsa_dev_ptr
[cid
].devname
),
2784 sizeof(scsicmd
->request
->rq_disk
->disk_name
) + 1));
2786 return aac_read(scsicmd
);
2794 return aac_write(scsicmd
);
2796 case SYNCHRONIZE_CACHE
:
2797 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2798 scsicmd
->result
= DID_OK
<< 16 |
2799 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2800 scsicmd
->scsi_done(scsicmd
);
2803 /* Issue FIB to tell Firmware to flush it's cache */
2804 if ((aac_cache
& 6) != 2)
2805 return aac_synchronize(scsicmd
);
2809 * Unhandled commands
2811 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n", scsicmd
->cmnd
[0]));
2812 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2813 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2814 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2815 ASENCODE_INVALID_COMMAND
, 0, 0);
2816 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2818 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2819 SCSI_SENSE_BUFFERSIZE
));
2820 scsicmd
->scsi_done(scsicmd
);
2825 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
2827 struct aac_query_disk qd
;
2828 struct fsa_dev_info
*fsa_dev_ptr
;
2830 fsa_dev_ptr
= dev
->fsa_dev
;
2833 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
2837 else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1))
2839 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
2841 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
2843 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
2844 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
2846 else return -EINVAL
;
2848 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
2849 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
2850 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
2852 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
2857 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
2858 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
2860 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
2865 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2867 struct aac_delete_disk dd
;
2868 struct fsa_dev_info
*fsa_dev_ptr
;
2870 fsa_dev_ptr
= dev
->fsa_dev
;
2874 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2877 if (dd
.cnum
>= dev
->maximum_num_containers
)
2880 * Mark this container as being deleted.
2882 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
2884 * Mark the container as no longer valid
2886 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2890 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2892 struct aac_delete_disk dd
;
2893 struct fsa_dev_info
*fsa_dev_ptr
;
2895 fsa_dev_ptr
= dev
->fsa_dev
;
2899 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2902 if (dd
.cnum
>= dev
->maximum_num_containers
)
2905 * If the container is locked, it can not be deleted by the API.
2907 if (fsa_dev_ptr
[dd
.cnum
].locked
)
2911 * Mark the container as no longer being valid.
2913 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2914 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
2919 int aac_dev_ioctl(struct aac_dev
*dev
, int cmd
, void __user
*arg
)
2922 case FSACTL_QUERY_DISK
:
2923 return query_disk(dev
, arg
);
2924 case FSACTL_DELETE_DISK
:
2925 return delete_disk(dev
, arg
);
2926 case FSACTL_FORCE_DELETE_DISK
:
2927 return force_delete_disk(dev
, arg
);
2928 case FSACTL_GET_CONTAINERS
:
2929 return aac_get_containers(dev
);
2938 * @context: the context set in the fib - here it is scsi cmd
2939 * @fibptr: pointer to the fib
2941 * Handles the completion of a scsi command to a non dasd device
2945 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
2947 struct aac_dev
*dev
;
2948 struct aac_srb_reply
*srbreply
;
2949 struct scsi_cmnd
*scsicmd
;
2951 scsicmd
= (struct scsi_cmnd
*) context
;
2953 if (!aac_valid_context(scsicmd
, fibptr
))
2956 BUG_ON(fibptr
== NULL
);
2959 scsi_dma_unmap(scsicmd
);
2961 /* expose physical device if expose_physicald flag is on */
2962 if (scsicmd
->cmnd
[0] == INQUIRY
&& !(scsicmd
->cmnd
[1] & 0x01)
2963 && expose_physicals
> 0)
2964 aac_expose_phy_device(scsicmd
);
2966 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
2967 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
2969 if (fibptr
->flags
& FIB_CONTEXT_FLAG_FASTRESP
) {
2971 srbreply
->srb_status
= cpu_to_le32(SRB_STATUS_SUCCESS
);
2972 srbreply
->scsi_status
= cpu_to_le32(SAM_STAT_GOOD
);
2975 * Calculate resid for sg
2977 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
2978 - le32_to_cpu(srbreply
->data_xfer_length
));
2980 * First check the fib status
2983 if (le32_to_cpu(srbreply
->status
) != ST_OK
) {
2986 printk(KERN_WARNING
"aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply
->status
));
2987 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
2988 SCSI_SENSE_BUFFERSIZE
);
2989 scsicmd
->result
= DID_ERROR
<< 16
2990 | COMMAND_COMPLETE
<< 8
2991 | SAM_STAT_CHECK_CONDITION
;
2992 memcpy(scsicmd
->sense_buffer
,
2993 srbreply
->sense_data
, len
);
2997 * Next check the srb status
2999 switch ((le32_to_cpu(srbreply
->srb_status
))&0x3f) {
3000 case SRB_STATUS_ERROR_RECOVERY
:
3001 case SRB_STATUS_PENDING
:
3002 case SRB_STATUS_SUCCESS
:
3003 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3005 case SRB_STATUS_DATA_OVERRUN
:
3006 switch (scsicmd
->cmnd
[0]) {
3015 if (le32_to_cpu(srbreply
->data_xfer_length
)
3016 < scsicmd
->underflow
)
3017 printk(KERN_WARNING
"aacraid: SCSI CMD underflow\n");
3019 printk(KERN_WARNING
"aacraid: SCSI CMD Data Overrun\n");
3020 scsicmd
->result
= DID_ERROR
<< 16
3021 | COMMAND_COMPLETE
<< 8;
3024 scsicmd
->result
= DID_OK
<< 16
3025 | COMMAND_COMPLETE
<< 8;
3029 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
3033 case SRB_STATUS_ABORTED
:
3034 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
3036 case SRB_STATUS_ABORT_FAILED
:
3038 * Not sure about this one - but assuming the
3039 * hba was trying to abort for some reason
3041 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
3043 case SRB_STATUS_PARITY_ERROR
:
3044 scsicmd
->result
= DID_PARITY
<< 16
3045 | MSG_PARITY_ERROR
<< 8;
3047 case SRB_STATUS_NO_DEVICE
:
3048 case SRB_STATUS_INVALID_PATH_ID
:
3049 case SRB_STATUS_INVALID_TARGET_ID
:
3050 case SRB_STATUS_INVALID_LUN
:
3051 case SRB_STATUS_SELECTION_TIMEOUT
:
3052 scsicmd
->result
= DID_NO_CONNECT
<< 16
3053 | COMMAND_COMPLETE
<< 8;
3056 case SRB_STATUS_COMMAND_TIMEOUT
:
3057 case SRB_STATUS_TIMEOUT
:
3058 scsicmd
->result
= DID_TIME_OUT
<< 16
3059 | COMMAND_COMPLETE
<< 8;
3062 case SRB_STATUS_BUSY
:
3063 scsicmd
->result
= DID_BUS_BUSY
<< 16
3064 | COMMAND_COMPLETE
<< 8;
3067 case SRB_STATUS_BUS_RESET
:
3068 scsicmd
->result
= DID_RESET
<< 16
3069 | COMMAND_COMPLETE
<< 8;
3072 case SRB_STATUS_MESSAGE_REJECTED
:
3073 scsicmd
->result
= DID_ERROR
<< 16
3074 | MESSAGE_REJECT
<< 8;
3076 case SRB_STATUS_REQUEST_FLUSHED
:
3077 case SRB_STATUS_ERROR
:
3078 case SRB_STATUS_INVALID_REQUEST
:
3079 case SRB_STATUS_REQUEST_SENSE_FAILED
:
3080 case SRB_STATUS_NO_HBA
:
3081 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
3082 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
3083 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
3084 case SRB_STATUS_DELAYED_RETRY
:
3085 case SRB_STATUS_BAD_FUNCTION
:
3086 case SRB_STATUS_NOT_STARTED
:
3087 case SRB_STATUS_NOT_IN_USE
:
3088 case SRB_STATUS_FORCE_ABORT
:
3089 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
3091 #ifdef AAC_DETAILED_STATUS_INFO
3092 printk(KERN_INFO
"aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
3093 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
3094 aac_get_status_string(
3095 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
3097 le32_to_cpu(srbreply
->scsi_status
));
3099 if ((scsicmd
->cmnd
[0] == ATA_12
)
3100 || (scsicmd
->cmnd
[0] == ATA_16
)) {
3101 if (scsicmd
->cmnd
[2] & (0x01 << 5)) {
3102 scsicmd
->result
= DID_OK
<< 16
3103 | COMMAND_COMPLETE
<< 8;
3106 scsicmd
->result
= DID_ERROR
<< 16
3107 | COMMAND_COMPLETE
<< 8;
3111 scsicmd
->result
= DID_ERROR
<< 16
3112 | COMMAND_COMPLETE
<< 8;
3116 if (le32_to_cpu(srbreply
->scsi_status
)
3117 == SAM_STAT_CHECK_CONDITION
) {
3120 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
3121 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
3122 SCSI_SENSE_BUFFERSIZE
);
3123 #ifdef AAC_DETAILED_STATUS_INFO
3124 printk(KERN_WARNING
"aac_srb_callback: check condition, status = %d len=%d\n",
3125 le32_to_cpu(srbreply
->status
), len
);
3127 memcpy(scsicmd
->sense_buffer
,
3128 srbreply
->sense_data
, len
);
3132 * OR in the scsi status (already shifted up a bit)
3134 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
3136 aac_fib_complete(fibptr
);
3137 scsicmd
->scsi_done(scsicmd
);
3143 * @scsicmd: the scsi command block
3145 * This routine will form a FIB and fill in the aac_srb from the
3146 * scsicmd passed in.
3149 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
3151 struct fib
* cmd_fibcontext
;
3152 struct aac_dev
* dev
;
3155 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3156 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
3157 scsicmd
->device
->lun
> 7) {
3158 scsicmd
->result
= DID_NO_CONNECT
<< 16;
3159 scsicmd
->scsi_done(scsicmd
);
3164 * Allocate and initialize a Fib then setup a BlockWrite command
3166 cmd_fibcontext
= aac_fib_alloc_tag(dev
, scsicmd
);
3168 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
3171 * Check that the command queued to the controller
3173 if (status
== -EINPROGRESS
) {
3174 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
3178 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
3179 aac_fib_complete(cmd_fibcontext
);
3180 aac_fib_free(cmd_fibcontext
);
3185 static long aac_build_sg(struct scsi_cmnd
*scsicmd
, struct sgmap
*psg
)
3187 struct aac_dev
*dev
;
3188 unsigned long byte_count
= 0;
3191 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3192 // Get rid of old data
3194 psg
->sg
[0].addr
= 0;
3195 psg
->sg
[0].count
= 0;
3197 nseg
= scsi_dma_map(scsicmd
);
3201 struct scatterlist
*sg
;
3204 psg
->count
= cpu_to_le32(nseg
);
3206 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3207 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
3208 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
3209 byte_count
+= sg_dma_len(sg
);
3211 /* hba wants the size to be exact */
3212 if (byte_count
> scsi_bufflen(scsicmd
)) {
3213 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3214 (byte_count
- scsi_bufflen(scsicmd
));
3215 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3216 byte_count
= scsi_bufflen(scsicmd
);
3218 /* Check for command underflow */
3219 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3220 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3221 byte_count
, scsicmd
->underflow
);
3228 static long aac_build_sg64(struct scsi_cmnd
*scsicmd
, struct sgmap64
*psg
)
3230 struct aac_dev
*dev
;
3231 unsigned long byte_count
= 0;
3235 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
3236 // Get rid of old data
3238 psg
->sg
[0].addr
[0] = 0;
3239 psg
->sg
[0].addr
[1] = 0;
3240 psg
->sg
[0].count
= 0;
3242 nseg
= scsi_dma_map(scsicmd
);
3246 struct scatterlist
*sg
;
3249 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3250 int count
= sg_dma_len(sg
);
3251 addr
= sg_dma_address(sg
);
3252 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
3253 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
3254 psg
->sg
[i
].count
= cpu_to_le32(count
);
3255 byte_count
+= count
;
3257 psg
->count
= cpu_to_le32(nseg
);
3258 /* hba wants the size to be exact */
3259 if (byte_count
> scsi_bufflen(scsicmd
)) {
3260 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3261 (byte_count
- scsi_bufflen(scsicmd
));
3262 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3263 byte_count
= scsi_bufflen(scsicmd
);
3265 /* Check for command underflow */
3266 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3267 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3268 byte_count
, scsicmd
->underflow
);
3274 static long aac_build_sgraw(struct scsi_cmnd
*scsicmd
, struct sgmapraw
*psg
)
3276 unsigned long byte_count
= 0;
3279 // Get rid of old data
3281 psg
->sg
[0].next
= 0;
3282 psg
->sg
[0].prev
= 0;
3283 psg
->sg
[0].addr
[0] = 0;
3284 psg
->sg
[0].addr
[1] = 0;
3285 psg
->sg
[0].count
= 0;
3286 psg
->sg
[0].flags
= 0;
3288 nseg
= scsi_dma_map(scsicmd
);
3292 struct scatterlist
*sg
;
3295 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3296 int count
= sg_dma_len(sg
);
3297 u64 addr
= sg_dma_address(sg
);
3298 psg
->sg
[i
].next
= 0;
3299 psg
->sg
[i
].prev
= 0;
3300 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
3301 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
3302 psg
->sg
[i
].count
= cpu_to_le32(count
);
3303 psg
->sg
[i
].flags
= 0;
3304 byte_count
+= count
;
3306 psg
->count
= cpu_to_le32(nseg
);
3307 /* hba wants the size to be exact */
3308 if (byte_count
> scsi_bufflen(scsicmd
)) {
3309 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
3310 (byte_count
- scsi_bufflen(scsicmd
));
3311 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
3312 byte_count
= scsi_bufflen(scsicmd
);
3314 /* Check for command underflow */
3315 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
3316 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3317 byte_count
, scsicmd
->underflow
);
3323 static long aac_build_sgraw2(struct scsi_cmnd
*scsicmd
,
3324 struct aac_raw_io2
*rio2
, int sg_max
)
3326 unsigned long byte_count
= 0;
3329 nseg
= scsi_dma_map(scsicmd
);
3333 struct scatterlist
*sg
;
3334 int i
, conformable
= 0;
3335 u32 min_size
= PAGE_SIZE
, cur_size
;
3337 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
3338 int count
= sg_dma_len(sg
);
3339 u64 addr
= sg_dma_address(sg
);
3341 BUG_ON(i
>= sg_max
);
3342 rio2
->sge
[i
].addrHigh
= cpu_to_le32((u32
)(addr
>>32));
3343 rio2
->sge
[i
].addrLow
= cpu_to_le32((u32
)(addr
& 0xffffffff));
3344 cur_size
= cpu_to_le32(count
);
3345 rio2
->sge
[i
].length
= cur_size
;
3346 rio2
->sge
[i
].flags
= 0;
3349 rio2
->sgeFirstSize
= cur_size
;
3350 } else if (i
== 1) {
3351 rio2
->sgeNominalSize
= cur_size
;
3352 min_size
= cur_size
;
3353 } else if ((i
+1) < nseg
&& cur_size
!= rio2
->sgeNominalSize
) {
3355 if (cur_size
< min_size
)
3356 min_size
= cur_size
;
3358 byte_count
+= count
;
3361 /* hba wants the size to be exact */
3362 if (byte_count
> scsi_bufflen(scsicmd
)) {
3363 u32 temp
= le32_to_cpu(rio2
->sge
[i
-1].length
) -
3364 (byte_count
- scsi_bufflen(scsicmd
));
3365 rio2
->sge
[i
-1].length
= cpu_to_le32(temp
);
3366 byte_count
= scsi_bufflen(scsicmd
);
3369 rio2
->sgeCnt
= cpu_to_le32(nseg
);
3370 rio2
->flags
|= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212
);
3371 /* not conformable: evaluate required sg elements */
3373 int j
, nseg_new
= nseg
, err_found
;
3374 for (i
= min_size
/ PAGE_SIZE
; i
>= 1; --i
) {
3377 for (j
= 1; j
< nseg
- 1; ++j
) {
3378 if (rio2
->sge
[j
].length
% (i
*PAGE_SIZE
)) {
3382 nseg_new
+= (rio2
->sge
[j
].length
/ (i
*PAGE_SIZE
));
3387 if (i
> 0 && nseg_new
<= sg_max
)
3388 aac_convert_sgraw2(rio2
, i
, nseg
, nseg_new
);
3390 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3392 /* Check for command underflow */
3393 if (scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)) {
3394 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
3395 byte_count
, scsicmd
->underflow
);
3402 static int aac_convert_sgraw2(struct aac_raw_io2
*rio2
, int pages
, int nseg
, int nseg_new
)
3404 struct sge_ieee1212
*sge
;
3408 if (aac_convert_sgl
== 0)
3411 sge
= kmalloc(nseg_new
* sizeof(struct sge_ieee1212
), GFP_ATOMIC
);
3415 for (i
= 1, pos
= 1; i
< nseg
-1; ++i
) {
3416 for (j
= 0; j
< rio2
->sge
[i
].length
/ (pages
* PAGE_SIZE
); ++j
) {
3417 addr_low
= rio2
->sge
[i
].addrLow
+ j
* pages
* PAGE_SIZE
;
3418 sge
[pos
].addrLow
= addr_low
;
3419 sge
[pos
].addrHigh
= rio2
->sge
[i
].addrHigh
;
3420 if (addr_low
< rio2
->sge
[i
].addrLow
)
3421 sge
[pos
].addrHigh
++;
3422 sge
[pos
].length
= pages
* PAGE_SIZE
;
3427 sge
[pos
] = rio2
->sge
[nseg
-1];
3428 memcpy(&rio2
->sge
[1], &sge
[1], (nseg_new
-1)*sizeof(struct sge_ieee1212
));
3431 rio2
->sgeCnt
= cpu_to_le32(nseg_new
);
3432 rio2
->flags
|= cpu_to_le16(RIO2_SGL_CONFORMANT
);
3433 rio2
->sgeNominalSize
= pages
* PAGE_SIZE
;
3437 #ifdef AAC_DETAILED_STATUS_INFO
3439 struct aac_srb_status_info
{
3445 static struct aac_srb_status_info srb_status_info
[] = {
3446 { SRB_STATUS_PENDING
, "Pending Status"},
3447 { SRB_STATUS_SUCCESS
, "Success"},
3448 { SRB_STATUS_ABORTED
, "Aborted Command"},
3449 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
3450 { SRB_STATUS_ERROR
, "Error Event"},
3451 { SRB_STATUS_BUSY
, "Device Busy"},
3452 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
3453 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
3454 { SRB_STATUS_NO_DEVICE
, "No Device"},
3455 { SRB_STATUS_TIMEOUT
, "Timeout"},
3456 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
3457 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
3458 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
3459 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
3460 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
3461 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
3462 { SRB_STATUS_NO_HBA
, "No HBA"},
3463 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
3464 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
3465 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
3466 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
3467 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
3468 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
3469 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
3470 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
3471 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
3472 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
3473 { SRB_STATUS_NOT_STARTED
, "Not Started"},
3474 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
3475 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
3476 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
3477 { 0xff, "Unknown Error"}
3480 char *aac_get_status_string(u32 status
)
3484 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
3485 if (srb_status_info
[i
].status
== status
)
3486 return srb_status_info
[i
].str
;
3488 return "Bad Status Code";