2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/types.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/slab.h>
32 #include <linux/completion.h>
33 #include <linux/blkdev.h>
34 #include <asm/uaccess.h>
35 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
37 #include <scsi/scsi.h>
38 #include <scsi/scsi_cmnd.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_host.h>
44 /* values for inqd_pdt: Peripheral device type in plain English */
45 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
46 #define INQD_PDT_PROC 0x03 /* Processor device */
47 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
48 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
49 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
50 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
52 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
53 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
59 #define SENCODE_NO_SENSE 0x00
60 #define SENCODE_END_OF_DATA 0x00
61 #define SENCODE_BECOMING_READY 0x04
62 #define SENCODE_INIT_CMD_REQUIRED 0x04
63 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
64 #define SENCODE_INVALID_COMMAND 0x20
65 #define SENCODE_LBA_OUT_OF_RANGE 0x21
66 #define SENCODE_INVALID_CDB_FIELD 0x24
67 #define SENCODE_LUN_NOT_SUPPORTED 0x25
68 #define SENCODE_INVALID_PARAM_FIELD 0x26
69 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
70 #define SENCODE_PARAM_VALUE_INVALID 0x26
71 #define SENCODE_RESET_OCCURRED 0x29
72 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
73 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
74 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
75 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
76 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
77 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
78 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
79 #define SENCODE_OVERLAPPED_COMMAND 0x4E
82 * Additional sense codes
85 #define ASENCODE_NO_SENSE 0x00
86 #define ASENCODE_END_OF_DATA 0x05
87 #define ASENCODE_BECOMING_READY 0x01
88 #define ASENCODE_INIT_CMD_REQUIRED 0x02
89 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
90 #define ASENCODE_INVALID_COMMAND 0x00
91 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
92 #define ASENCODE_INVALID_CDB_FIELD 0x00
93 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
94 #define ASENCODE_INVALID_PARAM_FIELD 0x00
95 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
96 #define ASENCODE_PARAM_VALUE_INVALID 0x02
97 #define ASENCODE_RESET_OCCURRED 0x00
98 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
99 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
100 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
101 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
102 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
103 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
104 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
105 #define ASENCODE_OVERLAPPED_COMMAND 0x00
107 #define BYTE0(x) (unsigned char)(x)
108 #define BYTE1(x) (unsigned char)((x) >> 8)
109 #define BYTE2(x) (unsigned char)((x) >> 16)
110 #define BYTE3(x) (unsigned char)((x) >> 24)
112 /*------------------------------------------------------------------------------
113 * S T R U C T S / T Y P E D E F S
114 *----------------------------------------------------------------------------*/
115 /* SCSI inquiry data */
116 struct inquiry_data
{
117 u8 inqd_pdt
; /* Peripheral qualifier | Peripheral Device Type */
118 u8 inqd_dtq
; /* RMB | Device Type Qualifier */
119 u8 inqd_ver
; /* ISO version | ECMA version | ANSI-approved version */
120 u8 inqd_rdf
; /* AENC | TrmIOP | Response data format */
121 u8 inqd_len
; /* Additional length (n-4) */
122 u8 inqd_pad1
[2];/* Reserved - must be zero */
123 u8 inqd_pad2
; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
124 u8 inqd_vid
[8]; /* Vendor ID */
125 u8 inqd_pid
[16];/* Product ID */
126 u8 inqd_prl
[4]; /* Product Revision Level */
130 * M O D U L E G L O B A L S
133 static unsigned long aac_build_sg(struct scsi_cmnd
* scsicmd
, struct sgmap
* sgmap
);
134 static unsigned long aac_build_sg64(struct scsi_cmnd
* scsicmd
, struct sgmap64
* psg
);
135 static unsigned long aac_build_sgraw(struct scsi_cmnd
* scsicmd
, struct sgmapraw
* psg
);
136 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
);
137 #ifdef AAC_DETAILED_STATUS_INFO
138 static char *aac_get_status_string(u32 status
);
142 * Non dasd selection is handled entirely in aachba now
145 static int nondasd
= -1;
146 static int aac_cache
;
147 static int dacmode
= -1;
150 int startup_timeout
= 180;
151 int aif_timeout
= 120;
153 module_param(nondasd
, int, S_IRUGO
|S_IWUSR
);
154 MODULE_PARM_DESC(nondasd
, "Control scanning of hba for nondasd devices."
156 module_param_named(cache
, aac_cache
, int, S_IRUGO
|S_IWUSR
);
157 MODULE_PARM_DESC(cache
, "Disable Queue Flush commands:\n"
158 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
159 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
160 "\tbit 2 - Disable only if Battery not protecting Cache");
161 module_param(dacmode
, int, S_IRUGO
|S_IWUSR
);
162 MODULE_PARM_DESC(dacmode
, "Control whether dma addressing is using 64 bit DAC."
164 module_param_named(commit
, aac_commit
, int, S_IRUGO
|S_IWUSR
);
165 MODULE_PARM_DESC(commit
, "Control whether a COMMIT_CONFIG is issued to the"
166 " adapter for foreign arrays.\n"
167 "This is typically needed in systems that do not have a BIOS."
169 module_param_named(msi
, aac_msi
, int, S_IRUGO
|S_IWUSR
);
170 MODULE_PARM_DESC(msi
, "IRQ handling."
171 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
172 module_param(startup_timeout
, int, S_IRUGO
|S_IWUSR
);
173 MODULE_PARM_DESC(startup_timeout
, "The duration of time in seconds to wait for"
174 " adapter to have it's kernel up and\n"
175 "running. This is typically adjusted for large systems that do not"
177 module_param(aif_timeout
, int, S_IRUGO
|S_IWUSR
);
178 MODULE_PARM_DESC(aif_timeout
, "The duration of time in seconds to wait for"
179 " applications to pick up AIFs before\n"
180 "deregistering them. This is typically adjusted for heavily burdened"
184 module_param(numacb
, int, S_IRUGO
|S_IWUSR
);
185 MODULE_PARM_DESC(numacb
, "Request a limit to the number of adapter control"
186 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
187 " to use suggestion from Firmware.");
190 module_param(acbsize
, int, S_IRUGO
|S_IWUSR
);
191 MODULE_PARM_DESC(acbsize
, "Request a specific adapter control block (FIB)"
192 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
193 " suggestion from Firmware.");
195 int update_interval
= 30 * 60;
196 module_param(update_interval
, int, S_IRUGO
|S_IWUSR
);
197 MODULE_PARM_DESC(update_interval
, "Interval in seconds between time sync"
198 " updates issued to adapter.");
200 int check_interval
= 24 * 60 * 60;
201 module_param(check_interval
, int, S_IRUGO
|S_IWUSR
);
202 MODULE_PARM_DESC(check_interval
, "Interval in seconds between adapter health"
205 int aac_check_reset
= 1;
206 module_param_named(check_reset
, aac_check_reset
, int, S_IRUGO
|S_IWUSR
);
207 MODULE_PARM_DESC(check_reset
, "If adapter fails health check, reset the"
208 " adapter. a value of -1 forces the reset to adapters programmed to"
211 int expose_physicals
= -1;
212 module_param(expose_physicals
, int, S_IRUGO
|S_IWUSR
);
213 MODULE_PARM_DESC(expose_physicals
, "Expose physical components of the arrays."
214 " -1=protect 0=off, 1=on");
216 int aac_reset_devices
;
217 module_param_named(reset_devices
, aac_reset_devices
, int, S_IRUGO
|S_IWUSR
);
218 MODULE_PARM_DESC(reset_devices
, "Force an adapter reset at initialization.");
220 static inline int aac_valid_context(struct scsi_cmnd
*scsicmd
,
221 struct fib
*fibptr
) {
222 struct scsi_device
*device
;
224 if (unlikely(!scsicmd
|| !scsicmd
->scsi_done
)) {
225 dprintk((KERN_WARNING
"aac_valid_context: scsi command corrupt\n"));
226 aac_fib_complete(fibptr
);
227 aac_fib_free(fibptr
);
230 scsicmd
->SCp
.phase
= AAC_OWNER_MIDLEVEL
;
231 device
= scsicmd
->device
;
232 if (unlikely(!device
|| !scsi_device_online(device
))) {
233 dprintk((KERN_WARNING
"aac_valid_context: scsi device corrupt\n"));
234 aac_fib_complete(fibptr
);
235 aac_fib_free(fibptr
);
242 * aac_get_config_status - check the adapter configuration
243 * @common: adapter to query
245 * Query config status, and commit the configuration if needed.
247 int aac_get_config_status(struct aac_dev
*dev
, int commit_flag
)
252 if (!(fibptr
= aac_fib_alloc(dev
)))
255 aac_fib_init(fibptr
);
257 struct aac_get_config_status
*dinfo
;
258 dinfo
= (struct aac_get_config_status
*) fib_data(fibptr
);
260 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
261 dinfo
->type
= cpu_to_le32(CT_GET_CONFIG_STATUS
);
262 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_config_status_resp
*)NULL
)->data
));
265 status
= aac_fib_send(ContainerCommand
,
267 sizeof (struct aac_get_config_status
),
272 printk(KERN_WARNING
"aac_get_config_status: SendFIB failed.\n");
274 struct aac_get_config_status_resp
*reply
275 = (struct aac_get_config_status_resp
*) fib_data(fibptr
);
276 dprintk((KERN_WARNING
277 "aac_get_config_status: response=%d status=%d action=%d\n",
278 le32_to_cpu(reply
->response
),
279 le32_to_cpu(reply
->status
),
280 le32_to_cpu(reply
->data
.action
)));
281 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
282 (le32_to_cpu(reply
->status
) != CT_OK
) ||
283 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
284 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
288 aac_fib_complete(fibptr
);
289 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
291 if ((aac_commit
== 1) || commit_flag
) {
292 struct aac_commit_config
* dinfo
;
293 aac_fib_init(fibptr
);
294 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
296 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
297 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
299 status
= aac_fib_send(ContainerCommand
,
301 sizeof (struct aac_commit_config
),
305 aac_fib_complete(fibptr
);
306 } else if (aac_commit
== 0) {
308 "aac_get_config_status: Foreign device configurations are being ignored\n");
311 aac_fib_free(fibptr
);
316 * aac_get_containers - list containers
317 * @common: adapter to probe
319 * Make a list of all containers on this controller
321 int aac_get_containers(struct aac_dev
*dev
)
323 struct fsa_dev_info
*fsa_dev_ptr
;
327 struct aac_get_container_count
*dinfo
;
328 struct aac_get_container_count_resp
*dresp
;
329 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
331 if (!(fibptr
= aac_fib_alloc(dev
)))
334 aac_fib_init(fibptr
);
335 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
336 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
337 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
339 status
= aac_fib_send(ContainerCommand
,
341 sizeof (struct aac_get_container_count
),
346 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
347 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
348 aac_fib_complete(fibptr
);
350 aac_fib_free(fibptr
);
352 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
353 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
354 fsa_dev_ptr
= kzalloc(sizeof(*fsa_dev_ptr
) * maximum_num_containers
,
359 dev
->fsa_dev
= fsa_dev_ptr
;
360 dev
->maximum_num_containers
= maximum_num_containers
;
362 for (index
= 0; index
< dev
->maximum_num_containers
; ) {
363 fsa_dev_ptr
[index
].devname
[0] = '\0';
365 status
= aac_probe_container(dev
, index
);
368 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
373 * If there are no more containers, then stop asking.
375 if (++index
>= status
)
381 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
383 struct aac_get_name_resp
* get_name_reply
;
384 struct scsi_cmnd
* scsicmd
;
386 scsicmd
= (struct scsi_cmnd
*) context
;
388 if (!aac_valid_context(scsicmd
, fibptr
))
391 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
392 BUG_ON(fibptr
== NULL
);
394 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
395 /* Failure is irrelevant, using default value instead */
396 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
397 && (get_name_reply
->data
[0] != '\0')) {
398 char *sp
= get_name_reply
->data
;
399 sp
[sizeof(((struct aac_get_name_resp
*)NULL
)->data
)-1] = '\0';
403 struct inquiry_data inq
;
404 char d
[sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
)];
405 int count
= sizeof(d
);
408 *dp
++ = (*sp
) ? *sp
++ : ' ';
409 } while (--count
> 0);
411 scsi_sg_copy_to_buffer(scsicmd
, &inq
, sizeof(inq
));
412 memcpy(inq
.inqd_pid
, d
, sizeof(d
));
413 scsi_sg_copy_from_buffer(scsicmd
, &inq
, sizeof(inq
));
417 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
419 aac_fib_complete(fibptr
);
420 aac_fib_free(fibptr
);
421 scsicmd
->scsi_done(scsicmd
);
425 * aac_get_container_name - get container name, none blocking.
427 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
)
430 struct aac_get_name
*dinfo
;
431 struct fib
* cmd_fibcontext
;
432 struct aac_dev
* dev
;
434 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
436 if (!(cmd_fibcontext
= aac_fib_alloc(dev
)))
439 aac_fib_init(cmd_fibcontext
);
440 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
442 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
443 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
444 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
445 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_name_resp
*)NULL
)->data
));
447 status
= aac_fib_send(ContainerCommand
,
449 sizeof (struct aac_get_name
),
452 (fib_callback
)get_container_name_callback
,
456 * Check that the command queued to the controller
458 if (status
== -EINPROGRESS
) {
459 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
463 printk(KERN_WARNING
"aac_get_container_name: aac_fib_send failed with status: %d.\n", status
);
464 aac_fib_complete(cmd_fibcontext
);
465 aac_fib_free(cmd_fibcontext
);
469 static int aac_probe_container_callback2(struct scsi_cmnd
* scsicmd
)
471 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
473 if ((fsa_dev_ptr
[scmd_id(scsicmd
)].valid
& 1))
474 return aac_scsi_cmd(scsicmd
);
476 scsicmd
->result
= DID_NO_CONNECT
<< 16;
477 scsicmd
->scsi_done(scsicmd
);
481 static void _aac_probe_container2(void * context
, struct fib
* fibptr
)
483 struct fsa_dev_info
*fsa_dev_ptr
;
484 int (*callback
)(struct scsi_cmnd
*);
485 struct scsi_cmnd
* scsicmd
= (struct scsi_cmnd
*)context
;
488 if (!aac_valid_context(scsicmd
, fibptr
))
491 scsicmd
->SCp
.Status
= 0;
492 fsa_dev_ptr
= fibptr
->dev
->fsa_dev
;
494 struct aac_mount
* dresp
= (struct aac_mount
*) fib_data(fibptr
);
495 fsa_dev_ptr
+= scmd_id(scsicmd
);
497 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
498 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
499 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
500 fsa_dev_ptr
->valid
= 1;
501 /* sense_key holds the current state of the spin-up */
502 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
503 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
504 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
505 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
506 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
508 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
509 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
510 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
512 if ((fsa_dev_ptr
->valid
& 1) == 0)
513 fsa_dev_ptr
->valid
= 0;
514 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
516 aac_fib_complete(fibptr
);
517 aac_fib_free(fibptr
);
518 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
519 scsicmd
->SCp
.ptr
= NULL
;
520 (*callback
)(scsicmd
);
524 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
526 struct scsi_cmnd
* scsicmd
;
527 struct aac_mount
* dresp
;
528 struct aac_query_mount
*dinfo
;
531 dresp
= (struct aac_mount
*) fib_data(fibptr
);
532 dresp
->mnt
[0].capacityhigh
= 0;
533 if ((le32_to_cpu(dresp
->status
) != ST_OK
) ||
534 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
535 _aac_probe_container2(context
, fibptr
);
538 scsicmd
= (struct scsi_cmnd
*) context
;
540 if (!aac_valid_context(scsicmd
, fibptr
))
543 aac_fib_init(fibptr
);
545 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
547 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
548 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
549 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
551 status
= aac_fib_send(ContainerCommand
,
553 sizeof(struct aac_query_mount
),
556 _aac_probe_container2
,
559 * Check that the command queued to the controller
561 if (status
== -EINPROGRESS
)
562 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
563 else if (status
< 0) {
564 /* Inherit results from VM_NameServe, if any */
565 dresp
->status
= cpu_to_le32(ST_OK
);
566 _aac_probe_container2(context
, fibptr
);
570 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
573 int status
= -ENOMEM
;
575 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
576 struct aac_query_mount
*dinfo
;
578 aac_fib_init(fibptr
);
580 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
582 dinfo
->command
= cpu_to_le32(VM_NameServe
);
583 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
584 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
585 scsicmd
->SCp
.ptr
= (char *)callback
;
587 status
= aac_fib_send(ContainerCommand
,
589 sizeof(struct aac_query_mount
),
592 _aac_probe_container1
,
595 * Check that the command queued to the controller
597 if (status
== -EINPROGRESS
) {
598 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
602 scsicmd
->SCp
.ptr
= NULL
;
603 aac_fib_complete(fibptr
);
604 aac_fib_free(fibptr
);
608 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
610 fsa_dev_ptr
+= scmd_id(scsicmd
);
611 if ((fsa_dev_ptr
->valid
& 1) == 0) {
612 fsa_dev_ptr
->valid
= 0;
613 return (*callback
)(scsicmd
);
621 * aac_probe_container - query a logical volume
622 * @dev: device to query
623 * @cid: container identifier
625 * Queries the controller about the given volume. The volume information
626 * is updated in the struct fsa_dev_info structure rather than returned.
628 static int aac_probe_container_callback1(struct scsi_cmnd
* scsicmd
)
630 scsicmd
->device
= NULL
;
634 int aac_probe_container(struct aac_dev
*dev
, int cid
)
636 struct scsi_cmnd
*scsicmd
= kmalloc(sizeof(*scsicmd
), GFP_KERNEL
);
637 struct scsi_device
*scsidev
= kmalloc(sizeof(*scsidev
), GFP_KERNEL
);
640 if (!scsicmd
|| !scsidev
) {
645 scsicmd
->list
.next
= NULL
;
646 scsicmd
->scsi_done
= (void (*)(struct scsi_cmnd
*))aac_probe_container_callback1
;
648 scsicmd
->device
= scsidev
;
649 scsidev
->sdev_state
= 0;
651 scsidev
->host
= dev
->scsi_host_ptr
;
653 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
654 while (scsicmd
->device
== scsidev
)
657 status
= scsicmd
->SCp
.Status
;
662 /* Local Structure to set SCSI inquiry data strings */
664 char vid
[8]; /* Vendor ID */
665 char pid
[16]; /* Product ID */
666 char prl
[4]; /* Product Revision Level */
670 * InqStrCopy - string merge
671 * @a: string to copy from
672 * @b: string to copy to
674 * Copy a String from one location to another
678 static void inqstrcpy(char *a
, char *b
)
681 while (*a
!= (char)0)
685 static char *container_types
[] = {
709 char * get_container_type(unsigned tindex
)
711 if (tindex
>= ARRAY_SIZE(container_types
))
712 tindex
= ARRAY_SIZE(container_types
) - 1;
713 return container_types
[tindex
];
716 /* Function: setinqstr
718 * Arguments: [1] pointer to void [1] int
720 * Purpose: Sets SCSI inquiry data strings for vendor, product
721 * and revision level. Allows strings to be set in platform dependant
722 * files instead of in OS dependant driver source.
725 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
727 struct scsi_inq
*str
;
729 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
730 memset(str
, ' ', sizeof(*str
));
732 if (dev
->supplement_adapter_info
.AdapterTypeText
[0]) {
733 char * cp
= dev
->supplement_adapter_info
.AdapterTypeText
;
735 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
736 inqstrcpy("SMC", str
->vid
);
738 c
= sizeof(str
->vid
);
739 while (*cp
&& *cp
!= ' ' && --c
)
743 inqstrcpy (dev
->supplement_adapter_info
.AdapterTypeText
,
746 while (*cp
&& *cp
!= ' ')
751 /* last six chars reserved for vol type */
753 if (strlen(cp
) > sizeof(str
->pid
)) {
754 c
= cp
[sizeof(str
->pid
)];
755 cp
[sizeof(str
->pid
)] = '\0';
757 inqstrcpy (cp
, str
->pid
);
759 cp
[sizeof(str
->pid
)] = c
;
761 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
763 inqstrcpy (mp
->vname
, str
->vid
);
764 /* last six chars reserved for vol type */
765 inqstrcpy (mp
->model
, str
->pid
);
768 if (tindex
< ARRAY_SIZE(container_types
)){
769 char *findit
= str
->pid
;
771 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
772 /* RAID is superfluous in the context of a RAID device */
773 if (memcmp(findit
-4, "RAID", 4) == 0)
774 *(findit
-= 4) = ' ';
775 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
776 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
777 inqstrcpy (container_types
[tindex
], findit
+ 1);
779 inqstrcpy ("V1.0", str
->prl
);
782 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
784 struct aac_get_serial_resp
* get_serial_reply
;
785 struct scsi_cmnd
* scsicmd
;
787 BUG_ON(fibptr
== NULL
);
789 scsicmd
= (struct scsi_cmnd
*) context
;
790 if (!aac_valid_context(scsicmd
, fibptr
))
793 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
794 /* Failure is irrelevant, using default value instead */
795 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
799 sp
[1] = scsicmd
->cmnd
[2];
801 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
802 le32_to_cpu(get_serial_reply
->uid
));
803 scsi_sg_copy_from_buffer(scsicmd
, sp
, sizeof(sp
));
806 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
808 aac_fib_complete(fibptr
);
809 aac_fib_free(fibptr
);
810 scsicmd
->scsi_done(scsicmd
);
814 * aac_get_container_serial - get container serial, none blocking.
816 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
819 struct aac_get_serial
*dinfo
;
820 struct fib
* cmd_fibcontext
;
821 struct aac_dev
* dev
;
823 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
825 if (!(cmd_fibcontext
= aac_fib_alloc(dev
)))
828 aac_fib_init(cmd_fibcontext
);
829 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
831 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
832 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
833 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
835 status
= aac_fib_send(ContainerCommand
,
837 sizeof (struct aac_get_serial
),
840 (fib_callback
) get_container_serial_callback
,
844 * Check that the command queued to the controller
846 if (status
== -EINPROGRESS
) {
847 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
851 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
852 aac_fib_complete(cmd_fibcontext
);
853 aac_fib_free(cmd_fibcontext
);
857 /* Function: setinqserial
859 * Arguments: [1] pointer to void [1] int
861 * Purpose: Sets SCSI Unit Serial number.
862 * This is a fake. We should read a proper
863 * serial number from the container. <SuSE>But
864 * without docs it's quite hard to do it :-)
865 * So this will have to do in the meantime.</SuSE>
868 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
871 * This breaks array migration.
873 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
874 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
877 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
878 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
880 u8
*sense_buf
= (u8
*)sense_data
;
881 /* Sense data valid, err code 70h */
882 sense_buf
[0] = 0x70; /* No info field */
883 sense_buf
[1] = 0; /* Segment number, always zero */
885 sense_buf
[2] = sense_key
; /* Sense key */
887 sense_buf
[12] = sense_code
; /* Additional sense code */
888 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
890 if (sense_key
== ILLEGAL_REQUEST
) {
891 sense_buf
[7] = 10; /* Additional sense length */
893 sense_buf
[15] = bit_pointer
;
894 /* Illegal parameter is in the parameter block */
895 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
896 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
897 /* Illegal parameter is in the CDB block */
898 sense_buf
[16] = field_pointer
>> 8; /* MSB */
899 sense_buf
[17] = field_pointer
; /* LSB */
901 sense_buf
[7] = 6; /* Additional sense length */
904 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
906 if (lba
& 0xffffffff00000000LL
) {
907 int cid
= scmd_id(cmd
);
908 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
909 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
910 SAM_STAT_CHECK_CONDITION
;
911 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
912 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
913 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
914 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
915 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
916 SCSI_SENSE_BUFFERSIZE
));
923 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
928 static void io_callback(void *context
, struct fib
* fibptr
);
930 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
933 struct aac_raw_io
*readcmd
;
935 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
936 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
937 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
938 readcmd
->count
= cpu_to_le32(count
<<9);
939 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
940 readcmd
->flags
= cpu_to_le16(IO_TYPE_READ
);
941 readcmd
->bpTotal
= 0;
942 readcmd
->bpComplete
= 0;
944 aac_build_sgraw(cmd
, &readcmd
->sg
);
945 fibsize
= sizeof(struct aac_raw_io
) + ((le32_to_cpu(readcmd
->sg
.count
) - 1) * sizeof (struct sgentryraw
));
946 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
948 * Now send the Fib to the adapter
950 return aac_fib_send(ContainerRawIo
,
955 (fib_callback
) io_callback
,
959 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
962 struct aac_read64
*readcmd
;
964 readcmd
= (struct aac_read64
*) fib_data(fib
);
965 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
966 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
967 readcmd
->sector_count
= cpu_to_le16(count
);
968 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
972 aac_build_sg64(cmd
, &readcmd
->sg
);
973 fibsize
= sizeof(struct aac_read64
) +
974 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
975 sizeof (struct sgentry64
));
976 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
977 sizeof(struct aac_fibhdr
)));
979 * Now send the Fib to the adapter
981 return aac_fib_send(ContainerCommand64
,
986 (fib_callback
) io_callback
,
990 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
993 struct aac_read
*readcmd
;
995 readcmd
= (struct aac_read
*) fib_data(fib
);
996 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
997 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
998 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
999 readcmd
->count
= cpu_to_le32(count
* 512);
1001 aac_build_sg(cmd
, &readcmd
->sg
);
1002 fibsize
= sizeof(struct aac_read
) +
1003 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1004 sizeof (struct sgentry
));
1005 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1006 sizeof(struct aac_fibhdr
)));
1008 * Now send the Fib to the adapter
1010 return aac_fib_send(ContainerCommand
,
1015 (fib_callback
) io_callback
,
1019 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1022 struct aac_raw_io
*writecmd
;
1024 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1025 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1026 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1027 writecmd
->count
= cpu_to_le32(count
<<9);
1028 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1029 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1030 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1031 cpu_to_le16(IO_TYPE_WRITE
|IO_SUREWRITE
) :
1032 cpu_to_le16(IO_TYPE_WRITE
);
1033 writecmd
->bpTotal
= 0;
1034 writecmd
->bpComplete
= 0;
1036 aac_build_sgraw(cmd
, &writecmd
->sg
);
1037 fibsize
= sizeof(struct aac_raw_io
) + ((le32_to_cpu(writecmd
->sg
.count
) - 1) * sizeof (struct sgentryraw
));
1038 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1040 * Now send the Fib to the adapter
1042 return aac_fib_send(ContainerRawIo
,
1047 (fib_callback
) io_callback
,
1051 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1054 struct aac_write64
*writecmd
;
1056 writecmd
= (struct aac_write64
*) fib_data(fib
);
1057 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1058 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1059 writecmd
->sector_count
= cpu_to_le16(count
);
1060 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1062 writecmd
->flags
= 0;
1064 aac_build_sg64(cmd
, &writecmd
->sg
);
1065 fibsize
= sizeof(struct aac_write64
) +
1066 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1067 sizeof (struct sgentry64
));
1068 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1069 sizeof(struct aac_fibhdr
)));
1071 * Now send the Fib to the adapter
1073 return aac_fib_send(ContainerCommand64
,
1078 (fib_callback
) io_callback
,
1082 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1085 struct aac_write
*writecmd
;
1087 writecmd
= (struct aac_write
*) fib_data(fib
);
1088 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1089 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1090 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1091 writecmd
->count
= cpu_to_le32(count
* 512);
1092 writecmd
->sg
.count
= cpu_to_le32(1);
1093 /* ->stable is not used - it did mean which type of write */
1095 aac_build_sg(cmd
, &writecmd
->sg
);
1096 fibsize
= sizeof(struct aac_write
) +
1097 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1098 sizeof (struct sgentry
));
1099 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1100 sizeof(struct aac_fibhdr
)));
1102 * Now send the Fib to the adapter
1104 return aac_fib_send(ContainerCommand
,
1109 (fib_callback
) io_callback
,
1113 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1115 struct aac_srb
* srbcmd
;
1120 switch(cmd
->sc_data_direction
){
1124 case DMA_BIDIRECTIONAL
:
1125 flag
= SRB_DataIn
| SRB_DataOut
;
1127 case DMA_FROM_DEVICE
:
1131 default: /* shuts up some versions of gcc */
1132 flag
= SRB_NoDataXfer
;
1136 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1137 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1138 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1139 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1140 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1141 srbcmd
->flags
= cpu_to_le32(flag
);
1142 timeout
= cmd
->timeout_per_command
/HZ
;
1145 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1146 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1147 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1151 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1153 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1156 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1158 aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1159 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1161 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1162 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1164 * Build Scatter/Gather list
1166 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1167 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1168 sizeof (struct sgentry64
));
1169 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1170 sizeof(struct aac_fibhdr
)));
1173 * Now send the Fib to the adapter
1175 return aac_fib_send(ScsiPortCommand64
, fib
,
1176 fibsize
, FsaNormal
, 0, 1,
1177 (fib_callback
) aac_srb_callback
,
1181 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1184 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1186 aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1187 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1189 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1190 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1192 * Build Scatter/Gather list
1194 fibsize
= sizeof (struct aac_srb
) +
1195 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1196 sizeof (struct sgentry
));
1197 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1198 sizeof(struct aac_fibhdr
)));
1201 * Now send the Fib to the adapter
1203 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1204 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1207 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1209 if ((sizeof(dma_addr_t
) > 4) &&
1210 (num_physpages
> (0xFFFFFFFFULL
>> PAGE_SHIFT
)) &&
1211 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1213 return aac_scsi_32(fib
, cmd
);
1216 int aac_get_adapter_info(struct aac_dev
* dev
)
1221 struct aac_adapter_info
*info
;
1222 struct aac_bus_info
*command
;
1223 struct aac_bus_info_response
*bus_info
;
1225 if (!(fibptr
= aac_fib_alloc(dev
)))
1228 aac_fib_init(fibptr
);
1229 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
1230 memset(info
,0,sizeof(*info
));
1232 rcode
= aac_fib_send(RequestAdapterInfo
,
1236 -1, 1, /* First `interrupt' command uses special wait */
1241 aac_fib_complete(fibptr
);
1242 aac_fib_free(fibptr
);
1245 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
1247 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
1248 struct aac_supplement_adapter_info
* sinfo
;
1250 aac_fib_init(fibptr
);
1252 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
1254 memset(sinfo
,0,sizeof(*sinfo
));
1256 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
1265 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
1273 aac_fib_init(fibptr
);
1275 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
1277 memset(bus_info
, 0, sizeof(*bus_info
));
1279 command
= (struct aac_bus_info
*)bus_info
;
1281 command
->Command
= cpu_to_le32(VM_Ioctl
);
1282 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
1283 command
->MethodId
= cpu_to_le32(1);
1284 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
1286 rcode
= aac_fib_send(ContainerCommand
,
1293 /* reasoned default */
1294 dev
->maximum_num_physicals
= 16;
1295 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
1296 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
1297 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
1300 if (!dev
->in_reset
) {
1302 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
1303 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
1309 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
1310 (int)sizeof(dev
->supplement_adapter_info
.BuildDate
),
1311 dev
->supplement_adapter_info
.BuildDate
);
1312 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
1313 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
1315 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1316 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
1317 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
1318 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
1320 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1321 le32_to_cpu(dev
->adapter_info
.biosbuild
));
1323 if (aac_get_serial_number(
1324 shost_to_class(dev
->scsi_host_ptr
), buffer
))
1325 printk(KERN_INFO
"%s%d: serial %s",
1326 dev
->name
, dev
->id
, buffer
);
1327 if (dev
->supplement_adapter_info
.VpdInfo
.Tsid
[0]) {
1328 printk(KERN_INFO
"%s%d: TSID %.*s\n",
1330 (int)sizeof(dev
->supplement_adapter_info
.VpdInfo
.Tsid
),
1331 dev
->supplement_adapter_info
.VpdInfo
.Tsid
);
1333 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
1334 (dev
->supplement_adapter_info
.SupportedOptions2
&
1335 AAC_OPTION_IGNORE_RESET
))) {
1336 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
1337 dev
->name
, dev
->id
);
1341 dev
->cache_protected
= 0;
1342 dev
->jbod
= ((dev
->supplement_adapter_info
.FeatureBits
&
1343 AAC_FEATURE_JBOD
) != 0);
1344 dev
->nondasd_support
= 0;
1345 dev
->raid_scsi_mode
= 0;
1346 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
1347 dev
->nondasd_support
= 1;
1350 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1351 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1352 * force nondasd support on. If we decide to allow the non-dasd flag
1353 * additional changes changes will have to be made to support
1354 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1355 * changed to support the new dev->raid_scsi_mode flag instead of
1356 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1357 * function aac_detect will have to be modified where it sets up the
1358 * max number of channels based on the aac->nondasd_support flag only.
1360 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
1361 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
1362 dev
->nondasd_support
= 1;
1363 dev
->raid_scsi_mode
= 1;
1365 if (dev
->raid_scsi_mode
!= 0)
1366 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
1367 dev
->name
, dev
->id
);
1370 dev
->nondasd_support
= (nondasd
!=0);
1371 if (dev
->nondasd_support
&& !dev
->in_reset
)
1372 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
1374 dev
->dac_support
= 0;
1375 if( (sizeof(dma_addr_t
) > 4) && (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)){
1377 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
1378 dev
->name
, dev
->id
);
1379 dev
->dac_support
= 1;
1383 dev
->dac_support
= (dacmode
!=0);
1385 if(dev
->dac_support
!= 0) {
1386 if (!pci_set_dma_mask(dev
->pdev
, DMA_64BIT_MASK
) &&
1387 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_64BIT_MASK
)) {
1389 printk(KERN_INFO
"%s%d: 64 Bit DAC enabled\n",
1390 dev
->name
, dev
->id
);
1391 } else if (!pci_set_dma_mask(dev
->pdev
, DMA_32BIT_MASK
) &&
1392 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_32BIT_MASK
)) {
1393 printk(KERN_INFO
"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1394 dev
->name
, dev
->id
);
1395 dev
->dac_support
= 0;
1397 printk(KERN_WARNING
"%s%d: No suitable DMA available.\n",
1398 dev
->name
, dev
->id
);
1403 * Deal with configuring for the individualized limits of each packet
1406 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
1407 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
1411 if (dev
->raw_io_interface
) {
1412 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
1415 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
1416 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
1418 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
1419 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
1420 sizeof(struct aac_fibhdr
) -
1421 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
1422 sizeof(struct sgentry
);
1423 if (dev
->dac_support
) {
1424 dev
->a_ops
.adapter_read
= aac_read_block64
;
1425 dev
->a_ops
.adapter_write
= aac_write_block64
;
1427 * 38 scatter gather elements
1429 dev
->scsi_host_ptr
->sg_tablesize
=
1430 (dev
->max_fib_size
-
1431 sizeof(struct aac_fibhdr
) -
1432 sizeof(struct aac_write64
) +
1433 sizeof(struct sgentry64
)) /
1434 sizeof(struct sgentry64
);
1436 dev
->a_ops
.adapter_read
= aac_read_block
;
1437 dev
->a_ops
.adapter_write
= aac_write_block
;
1439 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
1440 if(!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
1442 * Worst case size that could cause sg overflow when
1443 * we break up SG elements that are larger than 64KB.
1444 * Would be nice if we could tell the SCSI layer what
1445 * the maximum SG element size can be. Worst case is
1446 * (sg_tablesize-1) 4KB elements with one 64KB
1448 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1450 dev
->scsi_host_ptr
->max_sectors
=
1451 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
1455 aac_fib_complete(fibptr
);
1456 aac_fib_free(fibptr
);
1462 static void io_callback(void *context
, struct fib
* fibptr
)
1464 struct aac_dev
*dev
;
1465 struct aac_read_reply
*readreply
;
1466 struct scsi_cmnd
*scsicmd
;
1469 scsicmd
= (struct scsi_cmnd
*) context
;
1471 if (!aac_valid_context(scsicmd
, fibptr
))
1475 cid
= scmd_id(scsicmd
);
1477 if (nblank(dprintk(x
))) {
1479 switch (scsicmd
->cmnd
[0]) {
1482 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1483 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1487 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1488 ((u64
)scsicmd
->cmnd
[3] << 48) |
1489 ((u64
)scsicmd
->cmnd
[4] << 40) |
1490 ((u64
)scsicmd
->cmnd
[5] << 32) |
1491 ((u64
)scsicmd
->cmnd
[6] << 24) |
1492 (scsicmd
->cmnd
[7] << 16) |
1493 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1497 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1498 (scsicmd
->cmnd
[3] << 16) |
1499 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1502 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1503 (scsicmd
->cmnd
[3] << 16) |
1504 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1508 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1509 smp_processor_id(), (unsigned long long)lba
, jiffies
);
1512 BUG_ON(fibptr
== NULL
);
1514 scsi_dma_unmap(scsicmd
);
1516 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
1517 switch (le32_to_cpu(readreply
->status
)) {
1519 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1521 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
1524 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1525 SAM_STAT_CHECK_CONDITION
;
1526 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
1527 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
1528 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1529 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1530 SCSI_SENSE_BUFFERSIZE
));
1533 #ifdef AAC_DETAILED_STATUS_INFO
1534 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
1535 le32_to_cpu(readreply
->status
));
1537 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1538 SAM_STAT_CHECK_CONDITION
;
1539 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1540 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1541 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1542 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1543 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1544 SCSI_SENSE_BUFFERSIZE
));
1547 aac_fib_complete(fibptr
);
1548 aac_fib_free(fibptr
);
1550 scsicmd
->scsi_done(scsicmd
);
1553 static int aac_read(struct scsi_cmnd
* scsicmd
)
1558 struct aac_dev
*dev
;
1559 struct fib
* cmd_fibcontext
;
1561 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1563 * Get block address and transfer length
1565 switch (scsicmd
->cmnd
[0]) {
1567 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
1569 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1570 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1571 count
= scsicmd
->cmnd
[4];
1577 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
1579 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1580 ((u64
)scsicmd
->cmnd
[3] << 48) |
1581 ((u64
)scsicmd
->cmnd
[4] << 40) |
1582 ((u64
)scsicmd
->cmnd
[5] << 32) |
1583 ((u64
)scsicmd
->cmnd
[6] << 24) |
1584 (scsicmd
->cmnd
[7] << 16) |
1585 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1586 count
= (scsicmd
->cmnd
[10] << 24) |
1587 (scsicmd
->cmnd
[11] << 16) |
1588 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
1591 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
1593 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1594 (scsicmd
->cmnd
[3] << 16) |
1595 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1596 count
= (scsicmd
->cmnd
[6] << 24) |
1597 (scsicmd
->cmnd
[7] << 16) |
1598 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1601 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
1603 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1604 (scsicmd
->cmnd
[3] << 16) |
1605 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1606 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1609 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1610 smp_processor_id(), (unsigned long long)lba
, jiffies
));
1611 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
1614 * Alocate and initialize a Fib
1616 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
1620 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
1623 * Check that the command queued to the controller
1625 if (status
== -EINPROGRESS
) {
1626 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1630 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
1632 * For some reason, the Fib didn't queue, return QUEUE_FULL
1634 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
1635 scsicmd
->scsi_done(scsicmd
);
1636 aac_fib_complete(cmd_fibcontext
);
1637 aac_fib_free(cmd_fibcontext
);
1641 static int aac_write(struct scsi_cmnd
* scsicmd
)
1647 struct aac_dev
*dev
;
1648 struct fib
* cmd_fibcontext
;
1650 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1652 * Get block address and transfer length
1654 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
1656 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1657 count
= scsicmd
->cmnd
[4];
1661 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
1662 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
1664 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1665 ((u64
)scsicmd
->cmnd
[3] << 48) |
1666 ((u64
)scsicmd
->cmnd
[4] << 40) |
1667 ((u64
)scsicmd
->cmnd
[5] << 32) |
1668 ((u64
)scsicmd
->cmnd
[6] << 24) |
1669 (scsicmd
->cmnd
[7] << 16) |
1670 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1671 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
1672 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
1673 fua
= scsicmd
->cmnd
[1] & 0x8;
1674 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
1675 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
1677 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
1678 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1679 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
1680 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1681 fua
= scsicmd
->cmnd
[1] & 0x8;
1683 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
1684 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1685 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1686 fua
= scsicmd
->cmnd
[1] & 0x8;
1688 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1689 smp_processor_id(), (unsigned long long)lba
, jiffies
));
1690 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
1693 * Allocate and initialize a Fib then setup a BlockWrite command
1695 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
1696 scsicmd
->result
= DID_ERROR
<< 16;
1697 scsicmd
->scsi_done(scsicmd
);
1701 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
1704 * Check that the command queued to the controller
1706 if (status
== -EINPROGRESS
) {
1707 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1711 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
1713 * For some reason, the Fib didn't queue, return QUEUE_FULL
1715 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
1716 scsicmd
->scsi_done(scsicmd
);
1718 aac_fib_complete(cmd_fibcontext
);
1719 aac_fib_free(cmd_fibcontext
);
1723 static void synchronize_callback(void *context
, struct fib
*fibptr
)
1725 struct aac_synchronize_reply
*synchronizereply
;
1726 struct scsi_cmnd
*cmd
;
1730 if (!aac_valid_context(cmd
, fibptr
))
1733 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
1734 smp_processor_id(), jiffies
));
1735 BUG_ON(fibptr
== NULL
);
1738 synchronizereply
= fib_data(fibptr
);
1739 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
1740 cmd
->result
= DID_OK
<< 16 |
1741 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1743 struct scsi_device
*sdev
= cmd
->device
;
1744 struct aac_dev
*dev
= fibptr
->dev
;
1745 u32 cid
= sdev_id(sdev
);
1747 "synchronize_callback: synchronize failed, status = %d\n",
1748 le32_to_cpu(synchronizereply
->status
));
1749 cmd
->result
= DID_OK
<< 16 |
1750 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
1751 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1752 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1753 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1754 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1755 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1756 SCSI_SENSE_BUFFERSIZE
));
1759 aac_fib_complete(fibptr
);
1760 aac_fib_free(fibptr
);
1761 cmd
->scsi_done(cmd
);
1764 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
1767 struct fib
*cmd_fibcontext
;
1768 struct aac_synchronize
*synchronizecmd
;
1769 struct scsi_cmnd
*cmd
;
1770 struct scsi_device
*sdev
= scsicmd
->device
;
1772 struct aac_dev
*aac
;
1773 u64 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) |
1774 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1775 u32 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1776 unsigned long flags
;
1779 * Wait for all outstanding queued commands to complete to this
1780 * specific target (block).
1782 spin_lock_irqsave(&sdev
->list_lock
, flags
);
1783 list_for_each_entry(cmd
, &sdev
->cmd_list
, list
)
1784 if (cmd
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
1788 if (cmd
->cmnd
[0] == WRITE_6
) {
1789 cmnd_lba
= ((cmd
->cmnd
[1] & 0x1F) << 16) |
1790 (cmd
->cmnd
[2] << 8) |
1792 cmnd_count
= cmd
->cmnd
[4];
1793 if (cmnd_count
== 0)
1795 } else if (cmd
->cmnd
[0] == WRITE_16
) {
1796 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 56) |
1797 ((u64
)cmd
->cmnd
[3] << 48) |
1798 ((u64
)cmd
->cmnd
[4] << 40) |
1799 ((u64
)cmd
->cmnd
[5] << 32) |
1800 ((u64
)cmd
->cmnd
[6] << 24) |
1801 (cmd
->cmnd
[7] << 16) |
1802 (cmd
->cmnd
[8] << 8) |
1804 cmnd_count
= (cmd
->cmnd
[10] << 24) |
1805 (cmd
->cmnd
[11] << 16) |
1806 (cmd
->cmnd
[12] << 8) |
1808 } else if (cmd
->cmnd
[0] == WRITE_12
) {
1809 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
1810 (cmd
->cmnd
[3] << 16) |
1811 (cmd
->cmnd
[4] << 8) |
1813 cmnd_count
= (cmd
->cmnd
[6] << 24) |
1814 (cmd
->cmnd
[7] << 16) |
1815 (cmd
->cmnd
[8] << 8) |
1817 } else if (cmd
->cmnd
[0] == WRITE_10
) {
1818 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
1819 (cmd
->cmnd
[3] << 16) |
1820 (cmd
->cmnd
[4] << 8) |
1822 cmnd_count
= (cmd
->cmnd
[7] << 8) |
1826 if (((cmnd_lba
+ cmnd_count
) < lba
) ||
1827 (count
&& ((lba
+ count
) < cmnd_lba
)))
1833 spin_unlock_irqrestore(&sdev
->list_lock
, flags
);
1836 * Yield the processor (requeue for later)
1839 return SCSI_MLQUEUE_DEVICE_BUSY
;
1841 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
1843 return SCSI_MLQUEUE_HOST_BUSY
;
1846 * Allocate and initialize a Fib
1848 if (!(cmd_fibcontext
= aac_fib_alloc(aac
)))
1849 return SCSI_MLQUEUE_HOST_BUSY
;
1851 aac_fib_init(cmd_fibcontext
);
1853 synchronizecmd
= fib_data(cmd_fibcontext
);
1854 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
1855 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
1856 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1857 synchronizecmd
->count
=
1858 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
1861 * Now send the Fib to the adapter
1863 status
= aac_fib_send(ContainerCommand
,
1865 sizeof(struct aac_synchronize
),
1868 (fib_callback
)synchronize_callback
,
1872 * Check that the command queued to the controller
1874 if (status
== -EINPROGRESS
) {
1875 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1880 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
1881 aac_fib_complete(cmd_fibcontext
);
1882 aac_fib_free(cmd_fibcontext
);
1883 return SCSI_MLQUEUE_HOST_BUSY
;
1886 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
1888 struct scsi_cmnd
*scsicmd
= context
;
1890 if (!aac_valid_context(scsicmd
, fibptr
))
1893 BUG_ON(fibptr
== NULL
);
1895 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1897 aac_fib_complete(fibptr
);
1898 aac_fib_free(fibptr
);
1899 scsicmd
->scsi_done(scsicmd
);
1902 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
1905 struct fib
*cmd_fibcontext
;
1906 struct aac_power_management
*pmcmd
;
1907 struct scsi_device
*sdev
= scsicmd
->device
;
1908 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
1910 if (!(aac
->supplement_adapter_info
.SupportedOptions2
&
1911 AAC_OPTION_POWER_MANAGEMENT
)) {
1912 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1914 scsicmd
->scsi_done(scsicmd
);
1919 return SCSI_MLQUEUE_HOST_BUSY
;
1922 * Allocate and initialize a Fib
1924 cmd_fibcontext
= aac_fib_alloc(aac
);
1925 if (!cmd_fibcontext
)
1926 return SCSI_MLQUEUE_HOST_BUSY
;
1928 aac_fib_init(cmd_fibcontext
);
1930 pmcmd
= fib_data(cmd_fibcontext
);
1931 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
1932 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
1933 /* Eject bit ignored, not relevant */
1934 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
1935 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
1936 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
1937 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
1938 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
1941 * Now send the Fib to the adapter
1943 status
= aac_fib_send(ContainerCommand
,
1945 sizeof(struct aac_power_management
),
1948 (fib_callback
)aac_start_stop_callback
,
1952 * Check that the command queued to the controller
1954 if (status
== -EINPROGRESS
) {
1955 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1959 aac_fib_complete(cmd_fibcontext
);
1960 aac_fib_free(cmd_fibcontext
);
1961 return SCSI_MLQUEUE_HOST_BUSY
;
1965 * aac_scsi_cmd() - Process SCSI command
1966 * @scsicmd: SCSI command block
1968 * Emulate a SCSI command and queue the required request for the
1972 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
1975 struct Scsi_Host
*host
= scsicmd
->device
->host
;
1976 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
1977 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
1979 if (fsa_dev_ptr
== NULL
)
1982 * If the bus, id or lun is out of range, return fail
1983 * Test does not apply to ID 16, the pseudo id for the controller
1986 cid
= scmd_id(scsicmd
);
1987 if (cid
!= host
->this_id
) {
1988 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
1989 if((cid
>= dev
->maximum_num_containers
) ||
1990 (scsicmd
->device
->lun
!= 0)) {
1991 scsicmd
->result
= DID_NO_CONNECT
<< 16;
1992 scsicmd
->scsi_done(scsicmd
);
1997 * If the target container doesn't exist, it may have
1998 * been newly created
2000 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2001 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2003 switch (scsicmd
->cmnd
[0]) {
2004 case SERVICE_ACTION_IN
:
2005 if (!(dev
->raw_io_interface
) ||
2006 !(dev
->raw_io_64
) ||
2007 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2011 case TEST_UNIT_READY
:
2014 return _aac_probe_container(scsicmd
,
2015 aac_probe_container_callback2
);
2020 } else { /* check for physical non-dasd devices */
2021 if (dev
->nondasd_support
|| expose_physicals
||
2025 return aac_send_srb_fib(scsicmd
);
2027 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2028 scsicmd
->scsi_done(scsicmd
);
2034 * else Command for the controller itself
2036 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2037 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2039 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2040 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2041 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2042 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2043 ASENCODE_INVALID_COMMAND
, 0, 0);
2044 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2045 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2046 SCSI_SENSE_BUFFERSIZE
));
2047 scsicmd
->scsi_done(scsicmd
);
2052 /* Handle commands here that don't really require going out to the adapter */
2053 switch (scsicmd
->cmnd
[0]) {
2056 struct inquiry_data inq_data
;
2058 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2059 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2061 if (scsicmd
->cmnd
[1] & 0x1) {
2062 char *arr
= (char *)&inq_data
;
2065 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2066 INQD_PDT_PROC
: INQD_PDT_DA
;
2067 if (scsicmd
->cmnd
[2] == 0) {
2068 /* supported vital product data pages */
2072 arr
[1] = scsicmd
->cmnd
[2];
2073 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2075 scsicmd
->result
= DID_OK
<< 16 |
2076 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2077 } else if (scsicmd
->cmnd
[2] == 0x80) {
2078 /* unit serial number page */
2079 arr
[3] = setinqserial(dev
, &arr
[4],
2081 arr
[1] = scsicmd
->cmnd
[2];
2082 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2084 return aac_get_container_serial(scsicmd
);
2086 /* vpd page not implemented */
2087 scsicmd
->result
= DID_OK
<< 16 |
2088 COMMAND_COMPLETE
<< 8 |
2089 SAM_STAT_CHECK_CONDITION
;
2090 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2091 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2092 ASENCODE_NO_SENSE
, 7, 2);
2093 memcpy(scsicmd
->sense_buffer
,
2094 &dev
->fsa_dev
[cid
].sense_data
,
2096 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2097 SCSI_SENSE_BUFFERSIZE
));
2099 scsicmd
->scsi_done(scsicmd
);
2102 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2103 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 */
2104 inq_data
.inqd_len
= 31;
2105 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2106 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2108 * Set the Vendor, Product, and Revision Level
2109 * see: <vendor>.c i.e. aac.c
2111 if (cid
== host
->this_id
) {
2112 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2113 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2114 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2116 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2117 scsicmd
->scsi_done(scsicmd
);
2122 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2123 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2124 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2125 return aac_get_container_name(scsicmd
);
2127 case SERVICE_ACTION_IN
:
2128 if (!(dev
->raw_io_interface
) ||
2129 !(dev
->raw_io_64
) ||
2130 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2135 unsigned int alloc_len
;
2137 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2138 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2139 cp
[0] = (capacity
>> 56) & 0xff;
2140 cp
[1] = (capacity
>> 48) & 0xff;
2141 cp
[2] = (capacity
>> 40) & 0xff;
2142 cp
[3] = (capacity
>> 32) & 0xff;
2143 cp
[4] = (capacity
>> 24) & 0xff;
2144 cp
[5] = (capacity
>> 16) & 0xff;
2145 cp
[6] = (capacity
>> 8) & 0xff;
2146 cp
[7] = (capacity
>> 0) & 0xff;
2153 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
2154 + (scsicmd
->cmnd
[11] << 16)
2155 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
2157 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
2158 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
2159 if (alloc_len
< scsi_bufflen(scsicmd
))
2160 scsi_set_resid(scsicmd
,
2161 scsi_bufflen(scsicmd
) - alloc_len
);
2163 /* Do not cache partition table for arrays */
2164 scsicmd
->device
->removable
= 1;
2166 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2167 scsicmd
->scsi_done(scsicmd
);
2177 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
2178 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2179 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2183 cp
[0] = (capacity
>> 24) & 0xff;
2184 cp
[1] = (capacity
>> 16) & 0xff;
2185 cp
[2] = (capacity
>> 8) & 0xff;
2186 cp
[3] = (capacity
>> 0) & 0xff;
2191 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
2192 /* Do not cache partition table for arrays */
2193 scsicmd
->device
->removable
= 1;
2194 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2196 scsicmd
->scsi_done(scsicmd
);
2204 int mode_buf_length
= 4;
2206 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
2207 mode_buf
[0] = 3; /* Mode data length */
2208 mode_buf
[1] = 0; /* Medium type - default */
2209 mode_buf
[2] = 0; /* Device-specific param,
2210 bit 8: 0/1 = write enabled/protected
2211 bit 4: 0/1 = FUA enabled */
2212 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2214 mode_buf
[3] = 0; /* Block descriptor length */
2215 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2216 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2220 mode_buf
[6] = ((aac_cache
& 6) == 2)
2221 ? 0 : 0x04; /* WCE */
2222 mode_buf_length
= 7;
2223 if (mode_buf_length
> scsicmd
->cmnd
[4])
2224 mode_buf_length
= scsicmd
->cmnd
[4];
2226 scsi_sg_copy_from_buffer(scsicmd
, mode_buf
, mode_buf_length
);
2227 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2228 scsicmd
->scsi_done(scsicmd
);
2235 int mode_buf_length
= 8;
2237 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
2238 mode_buf
[0] = 0; /* Mode data length (MSB) */
2239 mode_buf
[1] = 6; /* Mode data length (LSB) */
2240 mode_buf
[2] = 0; /* Medium type - default */
2241 mode_buf
[3] = 0; /* Device-specific param,
2242 bit 8: 0/1 = write enabled/protected
2243 bit 4: 0/1 = FUA enabled */
2244 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2246 mode_buf
[4] = 0; /* reserved */
2247 mode_buf
[5] = 0; /* reserved */
2248 mode_buf
[6] = 0; /* Block descriptor length (MSB) */
2249 mode_buf
[7] = 0; /* Block descriptor length (LSB) */
2250 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2251 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2255 mode_buf
[10] = ((aac_cache
& 6) == 2)
2256 ? 0 : 0x04; /* WCE */
2257 mode_buf_length
= 11;
2258 if (mode_buf_length
> scsicmd
->cmnd
[8])
2259 mode_buf_length
= scsicmd
->cmnd
[8];
2261 scsi_sg_copy_from_buffer(scsicmd
, mode_buf
, mode_buf_length
);
2263 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2264 scsicmd
->scsi_done(scsicmd
);
2269 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
2270 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
, sizeof (struct sense_data
));
2271 memset(&dev
->fsa_dev
[cid
].sense_data
, 0, sizeof (struct sense_data
));
2272 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2273 scsicmd
->scsi_done(scsicmd
);
2276 case ALLOW_MEDIUM_REMOVAL
:
2277 dprintk((KERN_DEBUG
"LOCK command.\n"));
2278 if (scsicmd
->cmnd
[4])
2279 fsa_dev_ptr
[cid
].locked
= 1;
2281 fsa_dev_ptr
[cid
].locked
= 0;
2283 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2284 scsicmd
->scsi_done(scsicmd
);
2287 * These commands are all No-Ops
2289 case TEST_UNIT_READY
:
2290 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
2291 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2292 SAM_STAT_CHECK_CONDITION
;
2293 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2294 NOT_READY
, SENCODE_BECOMING_READY
,
2295 ASENCODE_BECOMING_READY
, 0, 0);
2296 memcpy(scsicmd
->sense_buffer
,
2297 &dev
->fsa_dev
[cid
].sense_data
,
2299 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2300 SCSI_SENSE_BUFFERSIZE
));
2301 scsicmd
->scsi_done(scsicmd
);
2308 case REASSIGN_BLOCKS
:
2310 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2311 scsicmd
->scsi_done(scsicmd
);
2315 return aac_start_stop(scsicmd
);
2318 switch (scsicmd
->cmnd
[0])
2327 * Hack to keep track of ordinal number of the device that
2328 * corresponds to a container. Needed to convert
2329 * containers to /dev/sd device names
2332 if (scsicmd
->request
->rq_disk
)
2333 strlcpy(fsa_dev_ptr
[cid
].devname
,
2334 scsicmd
->request
->rq_disk
->disk_name
,
2335 min(sizeof(fsa_dev_ptr
[cid
].devname
),
2336 sizeof(scsicmd
->request
->rq_disk
->disk_name
) + 1));
2338 return aac_read(scsicmd
);
2346 return aac_write(scsicmd
);
2348 case SYNCHRONIZE_CACHE
:
2349 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2350 scsicmd
->result
= DID_OK
<< 16 |
2351 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2352 scsicmd
->scsi_done(scsicmd
);
2355 /* Issue FIB to tell Firmware to flush it's cache */
2356 if ((aac_cache
& 6) != 2)
2357 return aac_synchronize(scsicmd
);
2361 * Unhandled commands
2363 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n", scsicmd
->cmnd
[0]));
2364 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2365 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2366 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2367 ASENCODE_INVALID_COMMAND
, 0, 0);
2368 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2370 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2371 SCSI_SENSE_BUFFERSIZE
));
2372 scsicmd
->scsi_done(scsicmd
);
2377 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
2379 struct aac_query_disk qd
;
2380 struct fsa_dev_info
*fsa_dev_ptr
;
2382 fsa_dev_ptr
= dev
->fsa_dev
;
2385 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
2389 else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1))
2391 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
2393 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
2395 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
2396 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
2398 else return -EINVAL
;
2400 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
2401 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
2402 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
2404 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
2409 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
2410 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
2412 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
2417 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2419 struct aac_delete_disk dd
;
2420 struct fsa_dev_info
*fsa_dev_ptr
;
2422 fsa_dev_ptr
= dev
->fsa_dev
;
2426 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2429 if (dd
.cnum
>= dev
->maximum_num_containers
)
2432 * Mark this container as being deleted.
2434 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
2436 * Mark the container as no longer valid
2438 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2442 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2444 struct aac_delete_disk dd
;
2445 struct fsa_dev_info
*fsa_dev_ptr
;
2447 fsa_dev_ptr
= dev
->fsa_dev
;
2451 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2454 if (dd
.cnum
>= dev
->maximum_num_containers
)
2457 * If the container is locked, it can not be deleted by the API.
2459 if (fsa_dev_ptr
[dd
.cnum
].locked
)
2463 * Mark the container as no longer being valid.
2465 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2466 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
2471 int aac_dev_ioctl(struct aac_dev
*dev
, int cmd
, void __user
*arg
)
2474 case FSACTL_QUERY_DISK
:
2475 return query_disk(dev
, arg
);
2476 case FSACTL_DELETE_DISK
:
2477 return delete_disk(dev
, arg
);
2478 case FSACTL_FORCE_DELETE_DISK
:
2479 return force_delete_disk(dev
, arg
);
2480 case FSACTL_GET_CONTAINERS
:
2481 return aac_get_containers(dev
);
2490 * @context: the context set in the fib - here it is scsi cmd
2491 * @fibptr: pointer to the fib
2493 * Handles the completion of a scsi command to a non dasd device
2497 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
2499 struct aac_dev
*dev
;
2500 struct aac_srb_reply
*srbreply
;
2501 struct scsi_cmnd
*scsicmd
;
2503 scsicmd
= (struct scsi_cmnd
*) context
;
2505 if (!aac_valid_context(scsicmd
, fibptr
))
2508 BUG_ON(fibptr
== NULL
);
2512 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
2514 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
2516 * Calculate resid for sg
2519 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
2520 - le32_to_cpu(srbreply
->data_xfer_length
));
2522 scsi_dma_unmap(scsicmd
);
2525 * First check the fib status
2528 if (le32_to_cpu(srbreply
->status
) != ST_OK
){
2530 printk(KERN_WARNING
"aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply
->status
));
2531 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
2532 SCSI_SENSE_BUFFERSIZE
);
2533 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2534 memcpy(scsicmd
->sense_buffer
, srbreply
->sense_data
, len
);
2538 * Next check the srb status
2540 switch( (le32_to_cpu(srbreply
->srb_status
))&0x3f){
2541 case SRB_STATUS_ERROR_RECOVERY
:
2542 case SRB_STATUS_PENDING
:
2543 case SRB_STATUS_SUCCESS
:
2544 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
2546 case SRB_STATUS_DATA_OVERRUN
:
2547 switch(scsicmd
->cmnd
[0]){
2556 if (le32_to_cpu(srbreply
->data_xfer_length
) < scsicmd
->underflow
) {
2557 printk(KERN_WARNING
"aacraid: SCSI CMD underflow\n");
2559 printk(KERN_WARNING
"aacraid: SCSI CMD Data Overrun\n");
2561 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
2564 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
2568 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
2572 case SRB_STATUS_ABORTED
:
2573 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
2575 case SRB_STATUS_ABORT_FAILED
:
2576 // Not sure about this one - but assuming the hba was trying to abort for some reason
2577 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
2579 case SRB_STATUS_PARITY_ERROR
:
2580 scsicmd
->result
= DID_PARITY
<< 16 | MSG_PARITY_ERROR
<< 8;
2582 case SRB_STATUS_NO_DEVICE
:
2583 case SRB_STATUS_INVALID_PATH_ID
:
2584 case SRB_STATUS_INVALID_TARGET_ID
:
2585 case SRB_STATUS_INVALID_LUN
:
2586 case SRB_STATUS_SELECTION_TIMEOUT
:
2587 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
2590 case SRB_STATUS_COMMAND_TIMEOUT
:
2591 case SRB_STATUS_TIMEOUT
:
2592 scsicmd
->result
= DID_TIME_OUT
<< 16 | COMMAND_COMPLETE
<< 8;
2595 case SRB_STATUS_BUSY
:
2596 scsicmd
->result
= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
2599 case SRB_STATUS_BUS_RESET
:
2600 scsicmd
->result
= DID_RESET
<< 16 | COMMAND_COMPLETE
<< 8;
2603 case SRB_STATUS_MESSAGE_REJECTED
:
2604 scsicmd
->result
= DID_ERROR
<< 16 | MESSAGE_REJECT
<< 8;
2606 case SRB_STATUS_REQUEST_FLUSHED
:
2607 case SRB_STATUS_ERROR
:
2608 case SRB_STATUS_INVALID_REQUEST
:
2609 case SRB_STATUS_REQUEST_SENSE_FAILED
:
2610 case SRB_STATUS_NO_HBA
:
2611 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
2612 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
2613 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
2614 case SRB_STATUS_DELAYED_RETRY
:
2615 case SRB_STATUS_BAD_FUNCTION
:
2616 case SRB_STATUS_NOT_STARTED
:
2617 case SRB_STATUS_NOT_IN_USE
:
2618 case SRB_STATUS_FORCE_ABORT
:
2619 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
2621 #ifdef AAC_DETAILED_STATUS_INFO
2622 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2623 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
2624 aac_get_status_string(
2625 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
2627 le32_to_cpu(srbreply
->scsi_status
));
2629 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
2632 if (le32_to_cpu(srbreply
->scsi_status
) == SAM_STAT_CHECK_CONDITION
) {
2634 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
2635 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
2636 SCSI_SENSE_BUFFERSIZE
);
2637 #ifdef AAC_DETAILED_STATUS_INFO
2638 printk(KERN_WARNING
"aac_srb_callback: check condition, status = %d len=%d\n",
2639 le32_to_cpu(srbreply
->status
), len
);
2641 memcpy(scsicmd
->sense_buffer
, srbreply
->sense_data
, len
);
2644 * OR in the scsi status (already shifted up a bit)
2646 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
2648 aac_fib_complete(fibptr
);
2649 aac_fib_free(fibptr
);
2650 scsicmd
->scsi_done(scsicmd
);
2656 * @scsicmd: the scsi command block
2658 * This routine will form a FIB and fill in the aac_srb from the
2659 * scsicmd passed in.
2662 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
2664 struct fib
* cmd_fibcontext
;
2665 struct aac_dev
* dev
;
2668 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2669 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
2670 scsicmd
->device
->lun
> 7) {
2671 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2672 scsicmd
->scsi_done(scsicmd
);
2677 * Allocate and initialize a Fib then setup a BlockWrite command
2679 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
2682 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
2685 * Check that the command queued to the controller
2687 if (status
== -EINPROGRESS
) {
2688 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2692 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
2693 aac_fib_complete(cmd_fibcontext
);
2694 aac_fib_free(cmd_fibcontext
);
2699 static unsigned long aac_build_sg(struct scsi_cmnd
* scsicmd
, struct sgmap
* psg
)
2701 struct aac_dev
*dev
;
2702 unsigned long byte_count
= 0;
2705 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2706 // Get rid of old data
2708 psg
->sg
[0].addr
= 0;
2709 psg
->sg
[0].count
= 0;
2711 nseg
= scsi_dma_map(scsicmd
);
2714 struct scatterlist
*sg
;
2717 psg
->count
= cpu_to_le32(nseg
);
2719 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
2720 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
2721 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
2722 byte_count
+= sg_dma_len(sg
);
2724 /* hba wants the size to be exact */
2725 if (byte_count
> scsi_bufflen(scsicmd
)) {
2726 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
2727 (byte_count
- scsi_bufflen(scsicmd
));
2728 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
2729 byte_count
= scsi_bufflen(scsicmd
);
2731 /* Check for command underflow */
2732 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
2733 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
2734 byte_count
, scsicmd
->underflow
);
2741 static unsigned long aac_build_sg64(struct scsi_cmnd
* scsicmd
, struct sgmap64
* psg
)
2743 struct aac_dev
*dev
;
2744 unsigned long byte_count
= 0;
2748 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2749 // Get rid of old data
2751 psg
->sg
[0].addr
[0] = 0;
2752 psg
->sg
[0].addr
[1] = 0;
2753 psg
->sg
[0].count
= 0;
2755 nseg
= scsi_dma_map(scsicmd
);
2758 struct scatterlist
*sg
;
2761 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
2762 int count
= sg_dma_len(sg
);
2763 addr
= sg_dma_address(sg
);
2764 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
2765 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
2766 psg
->sg
[i
].count
= cpu_to_le32(count
);
2767 byte_count
+= count
;
2769 psg
->count
= cpu_to_le32(nseg
);
2770 /* hba wants the size to be exact */
2771 if (byte_count
> scsi_bufflen(scsicmd
)) {
2772 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
2773 (byte_count
- scsi_bufflen(scsicmd
));
2774 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
2775 byte_count
= scsi_bufflen(scsicmd
);
2777 /* Check for command underflow */
2778 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
2779 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
2780 byte_count
, scsicmd
->underflow
);
2786 static unsigned long aac_build_sgraw(struct scsi_cmnd
* scsicmd
, struct sgmapraw
* psg
)
2788 unsigned long byte_count
= 0;
2791 // Get rid of old data
2793 psg
->sg
[0].next
= 0;
2794 psg
->sg
[0].prev
= 0;
2795 psg
->sg
[0].addr
[0] = 0;
2796 psg
->sg
[0].addr
[1] = 0;
2797 psg
->sg
[0].count
= 0;
2798 psg
->sg
[0].flags
= 0;
2800 nseg
= scsi_dma_map(scsicmd
);
2803 struct scatterlist
*sg
;
2806 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
2807 int count
= sg_dma_len(sg
);
2808 u64 addr
= sg_dma_address(sg
);
2809 psg
->sg
[i
].next
= 0;
2810 psg
->sg
[i
].prev
= 0;
2811 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
2812 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
2813 psg
->sg
[i
].count
= cpu_to_le32(count
);
2814 psg
->sg
[i
].flags
= 0;
2815 byte_count
+= count
;
2817 psg
->count
= cpu_to_le32(nseg
);
2818 /* hba wants the size to be exact */
2819 if (byte_count
> scsi_bufflen(scsicmd
)) {
2820 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
2821 (byte_count
- scsi_bufflen(scsicmd
));
2822 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
2823 byte_count
= scsi_bufflen(scsicmd
);
2825 /* Check for command underflow */
2826 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
2827 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
2828 byte_count
, scsicmd
->underflow
);
2834 #ifdef AAC_DETAILED_STATUS_INFO
2836 struct aac_srb_status_info
{
2842 static struct aac_srb_status_info srb_status_info
[] = {
2843 { SRB_STATUS_PENDING
, "Pending Status"},
2844 { SRB_STATUS_SUCCESS
, "Success"},
2845 { SRB_STATUS_ABORTED
, "Aborted Command"},
2846 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
2847 { SRB_STATUS_ERROR
, "Error Event"},
2848 { SRB_STATUS_BUSY
, "Device Busy"},
2849 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
2850 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
2851 { SRB_STATUS_NO_DEVICE
, "No Device"},
2852 { SRB_STATUS_TIMEOUT
, "Timeout"},
2853 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
2854 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
2855 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
2856 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
2857 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
2858 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
2859 { SRB_STATUS_NO_HBA
, "No HBA"},
2860 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
2861 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
2862 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
2863 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
2864 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
2865 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
2866 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
2867 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
2868 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
2869 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
2870 { SRB_STATUS_NOT_STARTED
, "Not Started"},
2871 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
2872 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
2873 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
2874 { 0xff, "Unknown Error"}
2877 char *aac_get_status_string(u32 status
)
2881 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
2882 if (srb_status_info
[i
].status
== status
)
2883 return srb_status_info
[i
].str
;
2885 return "Bad Status Code";