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 */
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_cmnd.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_host.h>
45 /* values for inqd_pdt: Peripheral device type in plain English */
46 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
47 #define INQD_PDT_PROC 0x03 /* Processor device */
48 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
49 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
50 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
51 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
53 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
54 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
60 #define SENCODE_NO_SENSE 0x00
61 #define SENCODE_END_OF_DATA 0x00
62 #define SENCODE_BECOMING_READY 0x04
63 #define SENCODE_INIT_CMD_REQUIRED 0x04
64 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65 #define SENCODE_INVALID_COMMAND 0x20
66 #define SENCODE_LBA_OUT_OF_RANGE 0x21
67 #define SENCODE_INVALID_CDB_FIELD 0x24
68 #define SENCODE_LUN_NOT_SUPPORTED 0x25
69 #define SENCODE_INVALID_PARAM_FIELD 0x26
70 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
71 #define SENCODE_PARAM_VALUE_INVALID 0x26
72 #define SENCODE_RESET_OCCURRED 0x29
73 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
77 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
79 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80 #define SENCODE_OVERLAPPED_COMMAND 0x4E
83 * Additional sense codes
86 #define ASENCODE_NO_SENSE 0x00
87 #define ASENCODE_END_OF_DATA 0x05
88 #define ASENCODE_BECOMING_READY 0x01
89 #define ASENCODE_INIT_CMD_REQUIRED 0x02
90 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91 #define ASENCODE_INVALID_COMMAND 0x00
92 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
93 #define ASENCODE_INVALID_CDB_FIELD 0x00
94 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
95 #define ASENCODE_INVALID_PARAM_FIELD 0x00
96 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97 #define ASENCODE_PARAM_VALUE_INVALID 0x02
98 #define ASENCODE_RESET_OCCURRED 0x00
99 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106 #define ASENCODE_OVERLAPPED_COMMAND 0x00
108 #define BYTE0(x) (unsigned char)(x)
109 #define BYTE1(x) (unsigned char)((x) >> 8)
110 #define BYTE2(x) (unsigned char)((x) >> 16)
111 #define BYTE3(x) (unsigned char)((x) >> 24)
113 /*------------------------------------------------------------------------------
114 * S T R U C T S / T Y P E D E F S
115 *----------------------------------------------------------------------------*/
116 /* SCSI inquiry data */
117 struct inquiry_data
{
118 u8 inqd_pdt
; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq
; /* RMB | Device Type Qualifier */
120 u8 inqd_ver
; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf
; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len
; /* Additional length (n-4) */
123 u8 inqd_pad1
[2];/* Reserved - must be zero */
124 u8 inqd_pad2
; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
125 u8 inqd_vid
[8]; /* Vendor ID */
126 u8 inqd_pid
[16];/* Product ID */
127 u8 inqd_prl
[4]; /* Product Revision Level */
131 * M O D U L E G L O B A L S
134 static unsigned long aac_build_sg(struct scsi_cmnd
* scsicmd
, struct sgmap
* sgmap
);
135 static unsigned long aac_build_sg64(struct scsi_cmnd
* scsicmd
, struct sgmap64
* psg
);
136 static unsigned long aac_build_sgraw(struct scsi_cmnd
* scsicmd
, struct sgmapraw
* psg
);
137 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
);
138 #ifdef AAC_DETAILED_STATUS_INFO
139 static char *aac_get_status_string(u32 status
);
143 * Non dasd selection is handled entirely in aachba now
146 static int nondasd
= -1;
147 static int aac_cache
= 2; /* WCE=0 to avoid performance problems */
148 static int dacmode
= -1;
151 int startup_timeout
= 180;
152 int aif_timeout
= 120;
154 module_param(nondasd
, int, S_IRUGO
|S_IWUSR
);
155 MODULE_PARM_DESC(nondasd
, "Control scanning of hba for nondasd devices."
157 module_param_named(cache
, aac_cache
, int, S_IRUGO
|S_IWUSR
);
158 MODULE_PARM_DESC(cache
, "Disable Queue Flush commands:\n"
159 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
160 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
161 "\tbit 2 - Disable only if Battery is protecting Cache");
162 module_param(dacmode
, int, S_IRUGO
|S_IWUSR
);
163 MODULE_PARM_DESC(dacmode
, "Control whether dma addressing is using 64 bit DAC."
165 module_param_named(commit
, aac_commit
, int, S_IRUGO
|S_IWUSR
);
166 MODULE_PARM_DESC(commit
, "Control whether a COMMIT_CONFIG is issued to the"
167 " adapter for foreign arrays.\n"
168 "This is typically needed in systems that do not have a BIOS."
170 module_param_named(msi
, aac_msi
, int, S_IRUGO
|S_IWUSR
);
171 MODULE_PARM_DESC(msi
, "IRQ handling."
172 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
173 module_param(startup_timeout
, int, S_IRUGO
|S_IWUSR
);
174 MODULE_PARM_DESC(startup_timeout
, "The duration of time in seconds to wait for"
175 " adapter to have it's kernel up and\n"
176 "running. This is typically adjusted for large systems that do not"
178 module_param(aif_timeout
, int, S_IRUGO
|S_IWUSR
);
179 MODULE_PARM_DESC(aif_timeout
, "The duration of time in seconds to wait for"
180 " applications to pick up AIFs before\n"
181 "deregistering them. This is typically adjusted for heavily burdened"
185 module_param(numacb
, int, S_IRUGO
|S_IWUSR
);
186 MODULE_PARM_DESC(numacb
, "Request a limit to the number of adapter control"
187 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
188 " to use suggestion from Firmware.");
191 module_param(acbsize
, int, S_IRUGO
|S_IWUSR
);
192 MODULE_PARM_DESC(acbsize
, "Request a specific adapter control block (FIB)"
193 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
194 " suggestion from Firmware.");
196 int update_interval
= 30 * 60;
197 module_param(update_interval
, int, S_IRUGO
|S_IWUSR
);
198 MODULE_PARM_DESC(update_interval
, "Interval in seconds between time sync"
199 " updates issued to adapter.");
201 int check_interval
= 24 * 60 * 60;
202 module_param(check_interval
, int, S_IRUGO
|S_IWUSR
);
203 MODULE_PARM_DESC(check_interval
, "Interval in seconds between adapter health"
206 int aac_check_reset
= 1;
207 module_param_named(check_reset
, aac_check_reset
, int, S_IRUGO
|S_IWUSR
);
208 MODULE_PARM_DESC(check_reset
, "If adapter fails health check, reset the"
209 " adapter. a value of -1 forces the reset to adapters programmed to"
212 int expose_physicals
= -1;
213 module_param(expose_physicals
, int, S_IRUGO
|S_IWUSR
);
214 MODULE_PARM_DESC(expose_physicals
, "Expose physical components of the arrays."
215 " -1=protect 0=off, 1=on");
217 int aac_reset_devices
;
218 module_param_named(reset_devices
, aac_reset_devices
, int, S_IRUGO
|S_IWUSR
);
219 MODULE_PARM_DESC(reset_devices
, "Force an adapter reset at initialization.");
222 module_param_named(wwn
, aac_wwn
, int, S_IRUGO
|S_IWUSR
);
223 MODULE_PARM_DESC(wwn
, "Select a WWN type for the arrays:\n"
225 "\t1 - Array Meta Data Signature (default)\n"
226 "\t2 - Adapter Serial Number");
229 static inline int aac_valid_context(struct scsi_cmnd
*scsicmd
,
230 struct fib
*fibptr
) {
231 struct scsi_device
*device
;
233 if (unlikely(!scsicmd
|| !scsicmd
->scsi_done
)) {
234 dprintk((KERN_WARNING
"aac_valid_context: scsi command corrupt\n"));
235 aac_fib_complete(fibptr
);
236 aac_fib_free(fibptr
);
239 scsicmd
->SCp
.phase
= AAC_OWNER_MIDLEVEL
;
240 device
= scsicmd
->device
;
241 if (unlikely(!device
|| !scsi_device_online(device
))) {
242 dprintk((KERN_WARNING
"aac_valid_context: scsi device corrupt\n"));
243 aac_fib_complete(fibptr
);
244 aac_fib_free(fibptr
);
251 * aac_get_config_status - check the adapter configuration
252 * @common: adapter to query
254 * Query config status, and commit the configuration if needed.
256 int aac_get_config_status(struct aac_dev
*dev
, int commit_flag
)
261 if (!(fibptr
= aac_fib_alloc(dev
)))
264 aac_fib_init(fibptr
);
266 struct aac_get_config_status
*dinfo
;
267 dinfo
= (struct aac_get_config_status
*) fib_data(fibptr
);
269 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
270 dinfo
->type
= cpu_to_le32(CT_GET_CONFIG_STATUS
);
271 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_config_status_resp
*)NULL
)->data
));
274 status
= aac_fib_send(ContainerCommand
,
276 sizeof (struct aac_get_config_status
),
281 printk(KERN_WARNING
"aac_get_config_status: SendFIB failed.\n");
283 struct aac_get_config_status_resp
*reply
284 = (struct aac_get_config_status_resp
*) fib_data(fibptr
);
285 dprintk((KERN_WARNING
286 "aac_get_config_status: response=%d status=%d action=%d\n",
287 le32_to_cpu(reply
->response
),
288 le32_to_cpu(reply
->status
),
289 le32_to_cpu(reply
->data
.action
)));
290 if ((le32_to_cpu(reply
->response
) != ST_OK
) ||
291 (le32_to_cpu(reply
->status
) != CT_OK
) ||
292 (le32_to_cpu(reply
->data
.action
) > CFACT_PAUSE
)) {
293 printk(KERN_WARNING
"aac_get_config_status: Will not issue the Commit Configuration\n");
297 /* Do not set XferState to zero unless receives a response from F/W */
299 aac_fib_complete(fibptr
);
301 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
303 if ((aac_commit
== 1) || commit_flag
) {
304 struct aac_commit_config
* dinfo
;
305 aac_fib_init(fibptr
);
306 dinfo
= (struct aac_commit_config
*) fib_data(fibptr
);
308 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
309 dinfo
->type
= cpu_to_le32(CT_COMMIT_CONFIG
);
311 status
= aac_fib_send(ContainerCommand
,
313 sizeof (struct aac_commit_config
),
317 /* Do not set XferState to zero unless
318 * receives a response from F/W */
320 aac_fib_complete(fibptr
);
321 } else if (aac_commit
== 0) {
323 "aac_get_config_status: Foreign device configurations are being ignored\n");
326 /* FIB should be freed only after getting the response from the F/W */
327 if (status
!= -ERESTARTSYS
)
328 aac_fib_free(fibptr
);
332 static void aac_expose_phy_device(struct scsi_cmnd
*scsicmd
)
335 scsi_sg_copy_to_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
336 if ((inq_data
& 0x20) && (inq_data
& 0x1f) == TYPE_DISK
) {
338 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
343 * aac_get_containers - list containers
344 * @common: adapter to probe
346 * Make a list of all containers on this controller
348 int aac_get_containers(struct aac_dev
*dev
)
350 struct fsa_dev_info
*fsa_dev_ptr
;
354 struct aac_get_container_count
*dinfo
;
355 struct aac_get_container_count_resp
*dresp
;
356 int maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
358 if (!(fibptr
= aac_fib_alloc(dev
)))
361 aac_fib_init(fibptr
);
362 dinfo
= (struct aac_get_container_count
*) fib_data(fibptr
);
363 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
364 dinfo
->type
= cpu_to_le32(CT_GET_CONTAINER_COUNT
);
366 status
= aac_fib_send(ContainerCommand
,
368 sizeof (struct aac_get_container_count
),
373 dresp
= (struct aac_get_container_count_resp
*)fib_data(fibptr
);
374 maximum_num_containers
= le32_to_cpu(dresp
->ContainerSwitchEntries
);
375 aac_fib_complete(fibptr
);
377 /* FIB should be freed only after getting the response from the F/W */
378 if (status
!= -ERESTARTSYS
)
379 aac_fib_free(fibptr
);
381 if (maximum_num_containers
< MAXIMUM_NUM_CONTAINERS
)
382 maximum_num_containers
= MAXIMUM_NUM_CONTAINERS
;
383 fsa_dev_ptr
= kzalloc(sizeof(*fsa_dev_ptr
) * maximum_num_containers
,
388 dev
->fsa_dev
= fsa_dev_ptr
;
389 dev
->maximum_num_containers
= maximum_num_containers
;
391 for (index
= 0; index
< dev
->maximum_num_containers
; ) {
392 fsa_dev_ptr
[index
].devname
[0] = '\0';
394 status
= aac_probe_container(dev
, index
);
397 printk(KERN_WARNING
"aac_get_containers: SendFIB failed.\n");
402 * If there are no more containers, then stop asking.
404 if (++index
>= status
)
410 static void get_container_name_callback(void *context
, struct fib
* fibptr
)
412 struct aac_get_name_resp
* get_name_reply
;
413 struct scsi_cmnd
* scsicmd
;
415 scsicmd
= (struct scsi_cmnd
*) context
;
417 if (!aac_valid_context(scsicmd
, fibptr
))
420 dprintk((KERN_DEBUG
"get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies
));
421 BUG_ON(fibptr
== NULL
);
423 get_name_reply
= (struct aac_get_name_resp
*) fib_data(fibptr
);
424 /* Failure is irrelevant, using default value instead */
425 if ((le32_to_cpu(get_name_reply
->status
) == CT_OK
)
426 && (get_name_reply
->data
[0] != '\0')) {
427 char *sp
= get_name_reply
->data
;
428 sp
[sizeof(((struct aac_get_name_resp
*)NULL
)->data
)-1] = '\0';
432 struct inquiry_data inq
;
433 char d
[sizeof(((struct inquiry_data
*)NULL
)->inqd_pid
)];
434 int count
= sizeof(d
);
437 *dp
++ = (*sp
) ? *sp
++ : ' ';
438 } while (--count
> 0);
440 scsi_sg_copy_to_buffer(scsicmd
, &inq
, sizeof(inq
));
441 memcpy(inq
.inqd_pid
, d
, sizeof(d
));
442 scsi_sg_copy_from_buffer(scsicmd
, &inq
, sizeof(inq
));
446 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
448 aac_fib_complete(fibptr
);
449 aac_fib_free(fibptr
);
450 scsicmd
->scsi_done(scsicmd
);
454 * aac_get_container_name - get container name, none blocking.
456 static int aac_get_container_name(struct scsi_cmnd
* scsicmd
)
459 struct aac_get_name
*dinfo
;
460 struct fib
* cmd_fibcontext
;
461 struct aac_dev
* dev
;
463 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
465 if (!(cmd_fibcontext
= aac_fib_alloc(dev
)))
468 aac_fib_init(cmd_fibcontext
);
469 dinfo
= (struct aac_get_name
*) fib_data(cmd_fibcontext
);
471 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
472 dinfo
->type
= cpu_to_le32(CT_READ_NAME
);
473 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
474 dinfo
->count
= cpu_to_le32(sizeof(((struct aac_get_name_resp
*)NULL
)->data
));
476 status
= aac_fib_send(ContainerCommand
,
478 sizeof (struct aac_get_name
),
481 (fib_callback
)get_container_name_callback
,
485 * Check that the command queued to the controller
487 if (status
== -EINPROGRESS
) {
488 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
492 printk(KERN_WARNING
"aac_get_container_name: aac_fib_send failed with status: %d.\n", status
);
493 aac_fib_complete(cmd_fibcontext
);
494 aac_fib_free(cmd_fibcontext
);
498 static int aac_probe_container_callback2(struct scsi_cmnd
* scsicmd
)
500 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
502 if ((fsa_dev_ptr
[scmd_id(scsicmd
)].valid
& 1))
503 return aac_scsi_cmd(scsicmd
);
505 scsicmd
->result
= DID_NO_CONNECT
<< 16;
506 scsicmd
->scsi_done(scsicmd
);
510 static void _aac_probe_container2(void * context
, struct fib
* fibptr
)
512 struct fsa_dev_info
*fsa_dev_ptr
;
513 int (*callback
)(struct scsi_cmnd
*);
514 struct scsi_cmnd
* scsicmd
= (struct scsi_cmnd
*)context
;
517 if (!aac_valid_context(scsicmd
, fibptr
))
520 scsicmd
->SCp
.Status
= 0;
521 fsa_dev_ptr
= fibptr
->dev
->fsa_dev
;
523 struct aac_mount
* dresp
= (struct aac_mount
*) fib_data(fibptr
);
524 fsa_dev_ptr
+= scmd_id(scsicmd
);
526 if ((le32_to_cpu(dresp
->status
) == ST_OK
) &&
527 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
) &&
528 (le32_to_cpu(dresp
->mnt
[0].state
) != FSCS_HIDDEN
)) {
529 fsa_dev_ptr
->valid
= 1;
530 /* sense_key holds the current state of the spin-up */
531 if (dresp
->mnt
[0].state
& cpu_to_le32(FSCS_NOT_READY
))
532 fsa_dev_ptr
->sense_data
.sense_key
= NOT_READY
;
533 else if (fsa_dev_ptr
->sense_data
.sense_key
== NOT_READY
)
534 fsa_dev_ptr
->sense_data
.sense_key
= NO_SENSE
;
535 fsa_dev_ptr
->type
= le32_to_cpu(dresp
->mnt
[0].vol
);
537 = ((u64
)le32_to_cpu(dresp
->mnt
[0].capacity
)) +
538 (((u64
)le32_to_cpu(dresp
->mnt
[0].capacityhigh
)) << 32);
539 fsa_dev_ptr
->ro
= ((le32_to_cpu(dresp
->mnt
[0].state
) & FSCS_READONLY
) != 0);
541 if ((fsa_dev_ptr
->valid
& 1) == 0)
542 fsa_dev_ptr
->valid
= 0;
543 scsicmd
->SCp
.Status
= le32_to_cpu(dresp
->count
);
545 aac_fib_complete(fibptr
);
546 aac_fib_free(fibptr
);
547 callback
= (int (*)(struct scsi_cmnd
*))(scsicmd
->SCp
.ptr
);
548 scsicmd
->SCp
.ptr
= NULL
;
549 (*callback
)(scsicmd
);
553 static void _aac_probe_container1(void * context
, struct fib
* fibptr
)
555 struct scsi_cmnd
* scsicmd
;
556 struct aac_mount
* dresp
;
557 struct aac_query_mount
*dinfo
;
560 dresp
= (struct aac_mount
*) fib_data(fibptr
);
561 dresp
->mnt
[0].capacityhigh
= 0;
562 if ((le32_to_cpu(dresp
->status
) != ST_OK
) ||
563 (le32_to_cpu(dresp
->mnt
[0].vol
) != CT_NONE
)) {
564 _aac_probe_container2(context
, fibptr
);
567 scsicmd
= (struct scsi_cmnd
*) context
;
569 if (!aac_valid_context(scsicmd
, fibptr
))
572 aac_fib_init(fibptr
);
574 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
576 dinfo
->command
= cpu_to_le32(VM_NameServe64
);
577 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
578 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
580 status
= aac_fib_send(ContainerCommand
,
582 sizeof(struct aac_query_mount
),
585 _aac_probe_container2
,
588 * Check that the command queued to the controller
590 if (status
== -EINPROGRESS
)
591 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
592 else if (status
< 0) {
593 /* Inherit results from VM_NameServe, if any */
594 dresp
->status
= cpu_to_le32(ST_OK
);
595 _aac_probe_container2(context
, fibptr
);
599 static int _aac_probe_container(struct scsi_cmnd
* scsicmd
, int (*callback
)(struct scsi_cmnd
*))
602 int status
= -ENOMEM
;
604 if ((fibptr
= aac_fib_alloc((struct aac_dev
*)scsicmd
->device
->host
->hostdata
))) {
605 struct aac_query_mount
*dinfo
;
607 aac_fib_init(fibptr
);
609 dinfo
= (struct aac_query_mount
*)fib_data(fibptr
);
611 dinfo
->command
= cpu_to_le32(VM_NameServe
);
612 dinfo
->count
= cpu_to_le32(scmd_id(scsicmd
));
613 dinfo
->type
= cpu_to_le32(FT_FILESYS
);
614 scsicmd
->SCp
.ptr
= (char *)callback
;
616 status
= aac_fib_send(ContainerCommand
,
618 sizeof(struct aac_query_mount
),
621 _aac_probe_container1
,
624 * Check that the command queued to the controller
626 if (status
== -EINPROGRESS
) {
627 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
631 scsicmd
->SCp
.ptr
= NULL
;
632 aac_fib_complete(fibptr
);
633 aac_fib_free(fibptr
);
637 struct fsa_dev_info
*fsa_dev_ptr
= ((struct aac_dev
*)(scsicmd
->device
->host
->hostdata
))->fsa_dev
;
639 fsa_dev_ptr
+= scmd_id(scsicmd
);
640 if ((fsa_dev_ptr
->valid
& 1) == 0) {
641 fsa_dev_ptr
->valid
= 0;
642 return (*callback
)(scsicmd
);
650 * aac_probe_container - query a logical volume
651 * @dev: device to query
652 * @cid: container identifier
654 * Queries the controller about the given volume. The volume information
655 * is updated in the struct fsa_dev_info structure rather than returned.
657 static int aac_probe_container_callback1(struct scsi_cmnd
* scsicmd
)
659 scsicmd
->device
= NULL
;
663 int aac_probe_container(struct aac_dev
*dev
, int cid
)
665 struct scsi_cmnd
*scsicmd
= kmalloc(sizeof(*scsicmd
), GFP_KERNEL
);
666 struct scsi_device
*scsidev
= kmalloc(sizeof(*scsidev
), GFP_KERNEL
);
669 if (!scsicmd
|| !scsidev
) {
674 scsicmd
->list
.next
= NULL
;
675 scsicmd
->scsi_done
= (void (*)(struct scsi_cmnd
*))aac_probe_container_callback1
;
677 scsicmd
->device
= scsidev
;
678 scsidev
->sdev_state
= 0;
680 scsidev
->host
= dev
->scsi_host_ptr
;
682 if (_aac_probe_container(scsicmd
, aac_probe_container_callback1
) == 0)
683 while (scsicmd
->device
== scsidev
)
686 status
= scsicmd
->SCp
.Status
;
691 /* Local Structure to set SCSI inquiry data strings */
693 char vid
[8]; /* Vendor ID */
694 char pid
[16]; /* Product ID */
695 char prl
[4]; /* Product Revision Level */
699 * InqStrCopy - string merge
700 * @a: string to copy from
701 * @b: string to copy to
703 * Copy a String from one location to another
707 static void inqstrcpy(char *a
, char *b
)
710 while (*a
!= (char)0)
714 static char *container_types
[] = {
738 char * get_container_type(unsigned tindex
)
740 if (tindex
>= ARRAY_SIZE(container_types
))
741 tindex
= ARRAY_SIZE(container_types
) - 1;
742 return container_types
[tindex
];
745 /* Function: setinqstr
747 * Arguments: [1] pointer to void [1] int
749 * Purpose: Sets SCSI inquiry data strings for vendor, product
750 * and revision level. Allows strings to be set in platform dependent
751 * files instead of in OS dependent driver source.
754 static void setinqstr(struct aac_dev
*dev
, void *data
, int tindex
)
756 struct scsi_inq
*str
;
758 str
= (struct scsi_inq
*)(data
); /* cast data to scsi inq block */
759 memset(str
, ' ', sizeof(*str
));
761 if (dev
->supplement_adapter_info
.AdapterTypeText
[0]) {
762 char * cp
= dev
->supplement_adapter_info
.AdapterTypeText
;
764 if ((cp
[0] == 'A') && (cp
[1] == 'O') && (cp
[2] == 'C'))
765 inqstrcpy("SMC", str
->vid
);
767 c
= sizeof(str
->vid
);
768 while (*cp
&& *cp
!= ' ' && --c
)
772 inqstrcpy (dev
->supplement_adapter_info
.AdapterTypeText
,
775 while (*cp
&& *cp
!= ' ')
780 /* last six chars reserved for vol type */
782 if (strlen(cp
) > sizeof(str
->pid
)) {
783 c
= cp
[sizeof(str
->pid
)];
784 cp
[sizeof(str
->pid
)] = '\0';
786 inqstrcpy (cp
, str
->pid
);
788 cp
[sizeof(str
->pid
)] = c
;
790 struct aac_driver_ident
*mp
= aac_get_driver_ident(dev
->cardtype
);
792 inqstrcpy (mp
->vname
, str
->vid
);
793 /* last six chars reserved for vol type */
794 inqstrcpy (mp
->model
, str
->pid
);
797 if (tindex
< ARRAY_SIZE(container_types
)){
798 char *findit
= str
->pid
;
800 for ( ; *findit
!= ' '; findit
++); /* walk till we find a space */
801 /* RAID is superfluous in the context of a RAID device */
802 if (memcmp(findit
-4, "RAID", 4) == 0)
803 *(findit
-= 4) = ' ';
804 if (((findit
- str
->pid
) + strlen(container_types
[tindex
]))
805 < (sizeof(str
->pid
) + sizeof(str
->prl
)))
806 inqstrcpy (container_types
[tindex
], findit
+ 1);
808 inqstrcpy ("V1.0", str
->prl
);
811 static void get_container_serial_callback(void *context
, struct fib
* fibptr
)
813 struct aac_get_serial_resp
* get_serial_reply
;
814 struct scsi_cmnd
* scsicmd
;
816 BUG_ON(fibptr
== NULL
);
818 scsicmd
= (struct scsi_cmnd
*) context
;
819 if (!aac_valid_context(scsicmd
, fibptr
))
822 get_serial_reply
= (struct aac_get_serial_resp
*) fib_data(fibptr
);
823 /* Failure is irrelevant, using default value instead */
824 if (le32_to_cpu(get_serial_reply
->status
) == CT_OK
) {
828 sp
[1] = scsicmd
->cmnd
[2];
830 sp
[3] = snprintf(sp
+4, sizeof(sp
)-4, "%08X",
831 le32_to_cpu(get_serial_reply
->uid
));
832 scsi_sg_copy_from_buffer(scsicmd
, sp
, sizeof(sp
));
835 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
837 aac_fib_complete(fibptr
);
838 aac_fib_free(fibptr
);
839 scsicmd
->scsi_done(scsicmd
);
843 * aac_get_container_serial - get container serial, none blocking.
845 static int aac_get_container_serial(struct scsi_cmnd
* scsicmd
)
848 struct aac_get_serial
*dinfo
;
849 struct fib
* cmd_fibcontext
;
850 struct aac_dev
* dev
;
852 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
854 if (!(cmd_fibcontext
= aac_fib_alloc(dev
)))
857 aac_fib_init(cmd_fibcontext
);
858 dinfo
= (struct aac_get_serial
*) fib_data(cmd_fibcontext
);
860 dinfo
->command
= cpu_to_le32(VM_ContainerConfig
);
861 dinfo
->type
= cpu_to_le32(CT_CID_TO_32BITS_UID
);
862 dinfo
->cid
= cpu_to_le32(scmd_id(scsicmd
));
864 status
= aac_fib_send(ContainerCommand
,
866 sizeof (struct aac_get_serial
),
869 (fib_callback
) get_container_serial_callback
,
873 * Check that the command queued to the controller
875 if (status
== -EINPROGRESS
) {
876 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
880 printk(KERN_WARNING
"aac_get_container_serial: aac_fib_send failed with status: %d.\n", status
);
881 aac_fib_complete(cmd_fibcontext
);
882 aac_fib_free(cmd_fibcontext
);
886 /* Function: setinqserial
888 * Arguments: [1] pointer to void [1] int
890 * Purpose: Sets SCSI Unit Serial number.
891 * This is a fake. We should read a proper
892 * serial number from the container. <SuSE>But
893 * without docs it's quite hard to do it :-)
894 * So this will have to do in the meantime.</SuSE>
897 static int setinqserial(struct aac_dev
*dev
, void *data
, int cid
)
900 * This breaks array migration.
902 return snprintf((char *)(data
), sizeof(struct scsi_inq
) - 4, "%08X%02X",
903 le32_to_cpu(dev
->adapter_info
.serial
[0]), cid
);
906 static inline void set_sense(struct sense_data
*sense_data
, u8 sense_key
,
907 u8 sense_code
, u8 a_sense_code
, u8 bit_pointer
, u16 field_pointer
)
909 u8
*sense_buf
= (u8
*)sense_data
;
910 /* Sense data valid, err code 70h */
911 sense_buf
[0] = 0x70; /* No info field */
912 sense_buf
[1] = 0; /* Segment number, always zero */
914 sense_buf
[2] = sense_key
; /* Sense key */
916 sense_buf
[12] = sense_code
; /* Additional sense code */
917 sense_buf
[13] = a_sense_code
; /* Additional sense code qualifier */
919 if (sense_key
== ILLEGAL_REQUEST
) {
920 sense_buf
[7] = 10; /* Additional sense length */
922 sense_buf
[15] = bit_pointer
;
923 /* Illegal parameter is in the parameter block */
924 if (sense_code
== SENCODE_INVALID_CDB_FIELD
)
925 sense_buf
[15] |= 0xc0;/* Std sense key specific field */
926 /* Illegal parameter is in the CDB block */
927 sense_buf
[16] = field_pointer
>> 8; /* MSB */
928 sense_buf
[17] = field_pointer
; /* LSB */
930 sense_buf
[7] = 6; /* Additional sense length */
933 static int aac_bounds_32(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
935 if (lba
& 0xffffffff00000000LL
) {
936 int cid
= scmd_id(cmd
);
937 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
938 cmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
939 SAM_STAT_CHECK_CONDITION
;
940 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
941 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
942 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
943 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
944 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
945 SCSI_SENSE_BUFFERSIZE
));
952 static int aac_bounds_64(struct aac_dev
* dev
, struct scsi_cmnd
* cmd
, u64 lba
)
957 static void io_callback(void *context
, struct fib
* fibptr
);
959 static int aac_read_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
962 struct aac_raw_io
*readcmd
;
964 readcmd
= (struct aac_raw_io
*) fib_data(fib
);
965 readcmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
966 readcmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
967 readcmd
->count
= cpu_to_le32(count
<<9);
968 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
969 readcmd
->flags
= cpu_to_le16(IO_TYPE_READ
);
970 readcmd
->bpTotal
= 0;
971 readcmd
->bpComplete
= 0;
973 aac_build_sgraw(cmd
, &readcmd
->sg
);
974 fibsize
= sizeof(struct aac_raw_io
) + ((le32_to_cpu(readcmd
->sg
.count
) - 1) * sizeof (struct sgentryraw
));
975 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
977 * Now send the Fib to the adapter
979 return aac_fib_send(ContainerRawIo
,
984 (fib_callback
) io_callback
,
988 static int aac_read_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
991 struct aac_read64
*readcmd
;
993 readcmd
= (struct aac_read64
*) fib_data(fib
);
994 readcmd
->command
= cpu_to_le32(VM_CtHostRead64
);
995 readcmd
->cid
= cpu_to_le16(scmd_id(cmd
));
996 readcmd
->sector_count
= cpu_to_le16(count
);
997 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1001 aac_build_sg64(cmd
, &readcmd
->sg
);
1002 fibsize
= sizeof(struct aac_read64
) +
1003 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1004 sizeof (struct sgentry64
));
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(ContainerCommand64
,
1015 (fib_callback
) io_callback
,
1019 static int aac_read_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
)
1022 struct aac_read
*readcmd
;
1024 readcmd
= (struct aac_read
*) fib_data(fib
);
1025 readcmd
->command
= cpu_to_le32(VM_CtBlockRead
);
1026 readcmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1027 readcmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1028 readcmd
->count
= cpu_to_le32(count
* 512);
1030 aac_build_sg(cmd
, &readcmd
->sg
);
1031 fibsize
= sizeof(struct aac_read
) +
1032 ((le32_to_cpu(readcmd
->sg
.count
) - 1) *
1033 sizeof (struct sgentry
));
1034 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1035 sizeof(struct aac_fibhdr
)));
1037 * Now send the Fib to the adapter
1039 return aac_fib_send(ContainerCommand
,
1044 (fib_callback
) io_callback
,
1048 static int aac_write_raw_io(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1051 struct aac_raw_io
*writecmd
;
1053 writecmd
= (struct aac_raw_io
*) fib_data(fib
);
1054 writecmd
->block
[0] = cpu_to_le32((u32
)(lba
&0xffffffff));
1055 writecmd
->block
[1] = cpu_to_le32((u32
)((lba
&0xffffffff00000000LL
)>>32));
1056 writecmd
->count
= cpu_to_le32(count
<<9);
1057 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1058 writecmd
->flags
= (fua
&& ((aac_cache
& 5) != 1) &&
1059 (((aac_cache
& 5) != 5) || !fib
->dev
->cache_protected
)) ?
1060 cpu_to_le16(IO_TYPE_WRITE
|IO_SUREWRITE
) :
1061 cpu_to_le16(IO_TYPE_WRITE
);
1062 writecmd
->bpTotal
= 0;
1063 writecmd
->bpComplete
= 0;
1065 aac_build_sgraw(cmd
, &writecmd
->sg
);
1066 fibsize
= sizeof(struct aac_raw_io
) + ((le32_to_cpu(writecmd
->sg
.count
) - 1) * sizeof (struct sgentryraw
));
1067 BUG_ON(fibsize
> (fib
->dev
->max_fib_size
- sizeof(struct aac_fibhdr
)));
1069 * Now send the Fib to the adapter
1071 return aac_fib_send(ContainerRawIo
,
1076 (fib_callback
) io_callback
,
1080 static int aac_write_block64(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1083 struct aac_write64
*writecmd
;
1085 writecmd
= (struct aac_write64
*) fib_data(fib
);
1086 writecmd
->command
= cpu_to_le32(VM_CtHostWrite64
);
1087 writecmd
->cid
= cpu_to_le16(scmd_id(cmd
));
1088 writecmd
->sector_count
= cpu_to_le16(count
);
1089 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1091 writecmd
->flags
= 0;
1093 aac_build_sg64(cmd
, &writecmd
->sg
);
1094 fibsize
= sizeof(struct aac_write64
) +
1095 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1096 sizeof (struct sgentry64
));
1097 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1098 sizeof(struct aac_fibhdr
)));
1100 * Now send the Fib to the adapter
1102 return aac_fib_send(ContainerCommand64
,
1107 (fib_callback
) io_callback
,
1111 static int aac_write_block(struct fib
* fib
, struct scsi_cmnd
* cmd
, u64 lba
, u32 count
, int fua
)
1114 struct aac_write
*writecmd
;
1116 writecmd
= (struct aac_write
*) fib_data(fib
);
1117 writecmd
->command
= cpu_to_le32(VM_CtBlockWrite
);
1118 writecmd
->cid
= cpu_to_le32(scmd_id(cmd
));
1119 writecmd
->block
= cpu_to_le32((u32
)(lba
&0xffffffff));
1120 writecmd
->count
= cpu_to_le32(count
* 512);
1121 writecmd
->sg
.count
= cpu_to_le32(1);
1122 /* ->stable is not used - it did mean which type of write */
1124 aac_build_sg(cmd
, &writecmd
->sg
);
1125 fibsize
= sizeof(struct aac_write
) +
1126 ((le32_to_cpu(writecmd
->sg
.count
) - 1) *
1127 sizeof (struct sgentry
));
1128 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1129 sizeof(struct aac_fibhdr
)));
1131 * Now send the Fib to the adapter
1133 return aac_fib_send(ContainerCommand
,
1138 (fib_callback
) io_callback
,
1142 static struct aac_srb
* aac_scsi_common(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1144 struct aac_srb
* srbcmd
;
1149 switch(cmd
->sc_data_direction
){
1153 case DMA_BIDIRECTIONAL
:
1154 flag
= SRB_DataIn
| SRB_DataOut
;
1156 case DMA_FROM_DEVICE
:
1160 default: /* shuts up some versions of gcc */
1161 flag
= SRB_NoDataXfer
;
1165 srbcmd
= (struct aac_srb
*) fib_data(fib
);
1166 srbcmd
->function
= cpu_to_le32(SRBF_ExecuteScsi
);
1167 srbcmd
->channel
= cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd
)));
1168 srbcmd
->id
= cpu_to_le32(scmd_id(cmd
));
1169 srbcmd
->lun
= cpu_to_le32(cmd
->device
->lun
);
1170 srbcmd
->flags
= cpu_to_le32(flag
);
1171 timeout
= cmd
->request
->timeout
/HZ
;
1174 srbcmd
->timeout
= cpu_to_le32(timeout
); // timeout in seconds
1175 srbcmd
->retry_limit
= 0; /* Obsolete parameter */
1176 srbcmd
->cdb_size
= cpu_to_le32(cmd
->cmd_len
);
1180 static void aac_srb_callback(void *context
, struct fib
* fibptr
);
1182 static int aac_scsi_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1185 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1187 aac_build_sg64(cmd
, (struct sgmap64
*) &srbcmd
->sg
);
1188 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1190 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1191 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1193 * Build Scatter/Gather list
1195 fibsize
= sizeof (struct aac_srb
) - sizeof (struct sgentry
) +
1196 ((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) *
1197 sizeof (struct sgentry64
));
1198 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1199 sizeof(struct aac_fibhdr
)));
1202 * Now send the Fib to the adapter
1204 return aac_fib_send(ScsiPortCommand64
, fib
,
1205 fibsize
, FsaNormal
, 0, 1,
1206 (fib_callback
) aac_srb_callback
,
1210 static int aac_scsi_32(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1213 struct aac_srb
* srbcmd
= aac_scsi_common(fib
, cmd
);
1215 aac_build_sg(cmd
, (struct sgmap
*)&srbcmd
->sg
);
1216 srbcmd
->count
= cpu_to_le32(scsi_bufflen(cmd
));
1218 memset(srbcmd
->cdb
, 0, sizeof(srbcmd
->cdb
));
1219 memcpy(srbcmd
->cdb
, cmd
->cmnd
, cmd
->cmd_len
);
1221 * Build Scatter/Gather list
1223 fibsize
= sizeof (struct aac_srb
) +
1224 (((le32_to_cpu(srbcmd
->sg
.count
) & 0xff) - 1) *
1225 sizeof (struct sgentry
));
1226 BUG_ON (fibsize
> (fib
->dev
->max_fib_size
-
1227 sizeof(struct aac_fibhdr
)));
1230 * Now send the Fib to the adapter
1232 return aac_fib_send(ScsiPortCommand
, fib
, fibsize
, FsaNormal
, 0, 1,
1233 (fib_callback
) aac_srb_callback
, (void *) cmd
);
1236 static int aac_scsi_32_64(struct fib
* fib
, struct scsi_cmnd
* cmd
)
1238 if ((sizeof(dma_addr_t
) > 4) && fib
->dev
->needs_dac
&&
1239 (fib
->dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
))
1241 return aac_scsi_32(fib
, cmd
);
1244 int aac_get_adapter_info(struct aac_dev
* dev
)
1249 struct aac_adapter_info
*info
;
1250 struct aac_bus_info
*command
;
1251 struct aac_bus_info_response
*bus_info
;
1253 if (!(fibptr
= aac_fib_alloc(dev
)))
1256 aac_fib_init(fibptr
);
1257 info
= (struct aac_adapter_info
*) fib_data(fibptr
);
1258 memset(info
,0,sizeof(*info
));
1260 rcode
= aac_fib_send(RequestAdapterInfo
,
1264 -1, 1, /* First `interrupt' command uses special wait */
1269 /* FIB should be freed only after
1270 * getting the response from the F/W */
1271 if (rcode
!= -ERESTARTSYS
) {
1272 aac_fib_complete(fibptr
);
1273 aac_fib_free(fibptr
);
1277 memcpy(&dev
->adapter_info
, info
, sizeof(*info
));
1279 if (dev
->adapter_info
.options
& AAC_OPT_SUPPLEMENT_ADAPTER_INFO
) {
1280 struct aac_supplement_adapter_info
* sinfo
;
1282 aac_fib_init(fibptr
);
1284 sinfo
= (struct aac_supplement_adapter_info
*) fib_data(fibptr
);
1286 memset(sinfo
,0,sizeof(*sinfo
));
1288 rcode
= aac_fib_send(RequestSupplementAdapterInfo
,
1297 memcpy(&dev
->supplement_adapter_info
, sinfo
, sizeof(*sinfo
));
1298 if (rcode
== -ERESTARTSYS
) {
1299 fibptr
= aac_fib_alloc(dev
);
1311 aac_fib_init(fibptr
);
1313 bus_info
= (struct aac_bus_info_response
*) fib_data(fibptr
);
1315 memset(bus_info
, 0, sizeof(*bus_info
));
1317 command
= (struct aac_bus_info
*)bus_info
;
1319 command
->Command
= cpu_to_le32(VM_Ioctl
);
1320 command
->ObjType
= cpu_to_le32(FT_DRIVE
);
1321 command
->MethodId
= cpu_to_le32(1);
1322 command
->CtlCmd
= cpu_to_le32(GetBusInfo
);
1324 rcode
= aac_fib_send(ContainerCommand
,
1331 /* reasoned default */
1332 dev
->maximum_num_physicals
= 16;
1333 if (rcode
>= 0 && le32_to_cpu(bus_info
->Status
) == ST_OK
) {
1334 dev
->maximum_num_physicals
= le32_to_cpu(bus_info
->TargetsPerBus
);
1335 dev
->maximum_num_channels
= le32_to_cpu(bus_info
->BusCount
);
1338 if (!dev
->in_reset
) {
1340 tmp
= le32_to_cpu(dev
->adapter_info
.kernelrev
);
1341 printk(KERN_INFO
"%s%d: kernel %d.%d-%d[%d] %.*s\n",
1347 le32_to_cpu(dev
->adapter_info
.kernelbuild
),
1348 (int)sizeof(dev
->supplement_adapter_info
.BuildDate
),
1349 dev
->supplement_adapter_info
.BuildDate
);
1350 tmp
= le32_to_cpu(dev
->adapter_info
.monitorrev
);
1351 printk(KERN_INFO
"%s%d: monitor %d.%d-%d[%d]\n",
1353 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1354 le32_to_cpu(dev
->adapter_info
.monitorbuild
));
1355 tmp
= le32_to_cpu(dev
->adapter_info
.biosrev
);
1356 printk(KERN_INFO
"%s%d: bios %d.%d-%d[%d]\n",
1358 tmp
>>24,(tmp
>>16)&0xff,tmp
&0xff,
1359 le32_to_cpu(dev
->adapter_info
.biosbuild
));
1361 if (aac_get_serial_number(
1362 shost_to_class(dev
->scsi_host_ptr
), buffer
))
1363 printk(KERN_INFO
"%s%d: serial %s",
1364 dev
->name
, dev
->id
, buffer
);
1365 if (dev
->supplement_adapter_info
.VpdInfo
.Tsid
[0]) {
1366 printk(KERN_INFO
"%s%d: TSID %.*s\n",
1368 (int)sizeof(dev
->supplement_adapter_info
.VpdInfo
.Tsid
),
1369 dev
->supplement_adapter_info
.VpdInfo
.Tsid
);
1371 if (!aac_check_reset
|| ((aac_check_reset
== 1) &&
1372 (dev
->supplement_adapter_info
.SupportedOptions2
&
1373 AAC_OPTION_IGNORE_RESET
))) {
1374 printk(KERN_INFO
"%s%d: Reset Adapter Ignored\n",
1375 dev
->name
, dev
->id
);
1379 dev
->cache_protected
= 0;
1380 dev
->jbod
= ((dev
->supplement_adapter_info
.FeatureBits
&
1381 AAC_FEATURE_JBOD
) != 0);
1382 dev
->nondasd_support
= 0;
1383 dev
->raid_scsi_mode
= 0;
1384 if(dev
->adapter_info
.options
& AAC_OPT_NONDASD
)
1385 dev
->nondasd_support
= 1;
1388 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1389 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1390 * force nondasd support on. If we decide to allow the non-dasd flag
1391 * additional changes changes will have to be made to support
1392 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1393 * changed to support the new dev->raid_scsi_mode flag instead of
1394 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1395 * function aac_detect will have to be modified where it sets up the
1396 * max number of channels based on the aac->nondasd_support flag only.
1398 if ((dev
->adapter_info
.options
& AAC_OPT_SCSI_MANAGED
) &&
1399 (dev
->adapter_info
.options
& AAC_OPT_RAID_SCSI_MODE
)) {
1400 dev
->nondasd_support
= 1;
1401 dev
->raid_scsi_mode
= 1;
1403 if (dev
->raid_scsi_mode
!= 0)
1404 printk(KERN_INFO
"%s%d: ROMB RAID/SCSI mode enabled\n",
1405 dev
->name
, dev
->id
);
1408 dev
->nondasd_support
= (nondasd
!=0);
1409 if (dev
->nondasd_support
&& !dev
->in_reset
)
1410 printk(KERN_INFO
"%s%d: Non-DASD support enabled.\n",dev
->name
, dev
->id
);
1412 if (dma_get_required_mask(&dev
->pdev
->dev
) > DMA_BIT_MASK(32))
1414 dev
->dac_support
= 0;
1415 if ((sizeof(dma_addr_t
) > 4) && dev
->needs_dac
&&
1416 (dev
->adapter_info
.options
& AAC_OPT_SGMAP_HOST64
)) {
1418 printk(KERN_INFO
"%s%d: 64bit support enabled.\n",
1419 dev
->name
, dev
->id
);
1420 dev
->dac_support
= 1;
1424 dev
->dac_support
= (dacmode
!=0);
1427 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1428 if (dev
->dac_support
&& (aac_get_driver_ident(dev
->cardtype
)->quirks
1429 & AAC_QUIRK_SCSI_32
)) {
1430 dev
->nondasd_support
= 0;
1432 expose_physicals
= 0;
1435 if(dev
->dac_support
!= 0) {
1436 if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(64)) &&
1437 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(64))) {
1439 printk(KERN_INFO
"%s%d: 64 Bit DAC enabled\n",
1440 dev
->name
, dev
->id
);
1441 } else if (!pci_set_dma_mask(dev
->pdev
, DMA_BIT_MASK(32)) &&
1442 !pci_set_consistent_dma_mask(dev
->pdev
, DMA_BIT_MASK(32))) {
1443 printk(KERN_INFO
"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1444 dev
->name
, dev
->id
);
1445 dev
->dac_support
= 0;
1447 printk(KERN_WARNING
"%s%d: No suitable DMA available.\n",
1448 dev
->name
, dev
->id
);
1453 * Deal with configuring for the individualized limits of each packet
1456 dev
->a_ops
.adapter_scsi
= (dev
->dac_support
)
1457 ? ((aac_get_driver_ident(dev
->cardtype
)->quirks
& AAC_QUIRK_SCSI_32
)
1461 if (dev
->raw_io_interface
) {
1462 dev
->a_ops
.adapter_bounds
= (dev
->raw_io_64
)
1465 dev
->a_ops
.adapter_read
= aac_read_raw_io
;
1466 dev
->a_ops
.adapter_write
= aac_write_raw_io
;
1468 dev
->a_ops
.adapter_bounds
= aac_bounds_32
;
1469 dev
->scsi_host_ptr
->sg_tablesize
= (dev
->max_fib_size
-
1470 sizeof(struct aac_fibhdr
) -
1471 sizeof(struct aac_write
) + sizeof(struct sgentry
)) /
1472 sizeof(struct sgentry
);
1473 if (dev
->dac_support
) {
1474 dev
->a_ops
.adapter_read
= aac_read_block64
;
1475 dev
->a_ops
.adapter_write
= aac_write_block64
;
1477 * 38 scatter gather elements
1479 dev
->scsi_host_ptr
->sg_tablesize
=
1480 (dev
->max_fib_size
-
1481 sizeof(struct aac_fibhdr
) -
1482 sizeof(struct aac_write64
) +
1483 sizeof(struct sgentry64
)) /
1484 sizeof(struct sgentry64
);
1486 dev
->a_ops
.adapter_read
= aac_read_block
;
1487 dev
->a_ops
.adapter_write
= aac_write_block
;
1489 dev
->scsi_host_ptr
->max_sectors
= AAC_MAX_32BIT_SGBCOUNT
;
1490 if (dev
->adapter_info
.options
& AAC_OPT_NEW_COMM_TYPE1
)
1491 dev
->adapter_info
.options
|= AAC_OPT_NEW_COMM
;
1492 if (!(dev
->adapter_info
.options
& AAC_OPT_NEW_COMM
)) {
1494 * Worst case size that could cause sg overflow when
1495 * we break up SG elements that are larger than 64KB.
1496 * Would be nice if we could tell the SCSI layer what
1497 * the maximum SG element size can be. Worst case is
1498 * (sg_tablesize-1) 4KB elements with one 64KB
1500 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1502 dev
->scsi_host_ptr
->max_sectors
=
1503 (dev
->scsi_host_ptr
->sg_tablesize
* 8) + 112;
1506 /* FIB should be freed only after getting the response from the F/W */
1507 if (rcode
!= -ERESTARTSYS
) {
1508 aac_fib_complete(fibptr
);
1509 aac_fib_free(fibptr
);
1516 static void io_callback(void *context
, struct fib
* fibptr
)
1518 struct aac_dev
*dev
;
1519 struct aac_read_reply
*readreply
;
1520 struct scsi_cmnd
*scsicmd
;
1523 scsicmd
= (struct scsi_cmnd
*) context
;
1525 if (!aac_valid_context(scsicmd
, fibptr
))
1529 cid
= scmd_id(scsicmd
);
1531 if (nblank(dprintk(x
))) {
1533 switch (scsicmd
->cmnd
[0]) {
1536 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1537 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1541 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1542 ((u64
)scsicmd
->cmnd
[3] << 48) |
1543 ((u64
)scsicmd
->cmnd
[4] << 40) |
1544 ((u64
)scsicmd
->cmnd
[5] << 32) |
1545 ((u64
)scsicmd
->cmnd
[6] << 24) |
1546 (scsicmd
->cmnd
[7] << 16) |
1547 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1551 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1552 (scsicmd
->cmnd
[3] << 16) |
1553 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1556 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1557 (scsicmd
->cmnd
[3] << 16) |
1558 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1562 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1563 smp_processor_id(), (unsigned long long)lba
, jiffies
);
1566 BUG_ON(fibptr
== NULL
);
1568 scsi_dma_unmap(scsicmd
);
1570 readreply
= (struct aac_read_reply
*)fib_data(fibptr
);
1571 switch (le32_to_cpu(readreply
->status
)) {
1573 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1575 dev
->fsa_dev
[cid
].sense_data
.sense_key
= NO_SENSE
;
1578 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1579 SAM_STAT_CHECK_CONDITION
;
1580 set_sense(&dev
->fsa_dev
[cid
].sense_data
, NOT_READY
,
1581 SENCODE_BECOMING_READY
, ASENCODE_BECOMING_READY
, 0, 0);
1582 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1583 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1584 SCSI_SENSE_BUFFERSIZE
));
1587 #ifdef AAC_DETAILED_STATUS_INFO
1588 printk(KERN_WARNING
"io_callback: io failed, status = %d\n",
1589 le32_to_cpu(readreply
->status
));
1591 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1592 SAM_STAT_CHECK_CONDITION
;
1593 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1594 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1595 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1596 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1597 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1598 SCSI_SENSE_BUFFERSIZE
));
1601 aac_fib_complete(fibptr
);
1602 aac_fib_free(fibptr
);
1604 scsicmd
->scsi_done(scsicmd
);
1607 static int aac_read(struct scsi_cmnd
* scsicmd
)
1612 struct aac_dev
*dev
;
1613 struct fib
* cmd_fibcontext
;
1616 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1618 * Get block address and transfer length
1620 switch (scsicmd
->cmnd
[0]) {
1622 dprintk((KERN_DEBUG
"aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd
)));
1624 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) |
1625 (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1626 count
= scsicmd
->cmnd
[4];
1632 dprintk((KERN_DEBUG
"aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd
)));
1634 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1635 ((u64
)scsicmd
->cmnd
[3] << 48) |
1636 ((u64
)scsicmd
->cmnd
[4] << 40) |
1637 ((u64
)scsicmd
->cmnd
[5] << 32) |
1638 ((u64
)scsicmd
->cmnd
[6] << 24) |
1639 (scsicmd
->cmnd
[7] << 16) |
1640 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1641 count
= (scsicmd
->cmnd
[10] << 24) |
1642 (scsicmd
->cmnd
[11] << 16) |
1643 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
1646 dprintk((KERN_DEBUG
"aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd
)));
1648 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1649 (scsicmd
->cmnd
[3] << 16) |
1650 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1651 count
= (scsicmd
->cmnd
[6] << 24) |
1652 (scsicmd
->cmnd
[7] << 16) |
1653 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1656 dprintk((KERN_DEBUG
"aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd
)));
1658 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) |
1659 (scsicmd
->cmnd
[3] << 16) |
1660 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1661 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1665 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
1666 cid
= scmd_id(scsicmd
);
1667 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1668 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1669 SAM_STAT_CHECK_CONDITION
;
1670 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1671 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1672 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1673 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1674 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1675 SCSI_SENSE_BUFFERSIZE
));
1676 scsicmd
->scsi_done(scsicmd
);
1680 dprintk((KERN_DEBUG
"aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1681 smp_processor_id(), (unsigned long long)lba
, jiffies
));
1682 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
1685 * Alocate and initialize a Fib
1687 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
1688 printk(KERN_WARNING
"aac_read: fib allocation failed\n");
1692 status
= aac_adapter_read(cmd_fibcontext
, scsicmd
, lba
, count
);
1695 * Check that the command queued to the controller
1697 if (status
== -EINPROGRESS
) {
1698 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1702 printk(KERN_WARNING
"aac_read: aac_fib_send failed with status: %d.\n", status
);
1704 * For some reason, the Fib didn't queue, return QUEUE_FULL
1706 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
1707 scsicmd
->scsi_done(scsicmd
);
1708 aac_fib_complete(cmd_fibcontext
);
1709 aac_fib_free(cmd_fibcontext
);
1713 static int aac_write(struct scsi_cmnd
* scsicmd
)
1719 struct aac_dev
*dev
;
1720 struct fib
* cmd_fibcontext
;
1723 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
1725 * Get block address and transfer length
1727 if (scsicmd
->cmnd
[0] == WRITE_6
) /* 6 byte command */
1729 lba
= ((scsicmd
->cmnd
[1] & 0x1F) << 16) | (scsicmd
->cmnd
[2] << 8) | scsicmd
->cmnd
[3];
1730 count
= scsicmd
->cmnd
[4];
1734 } else if (scsicmd
->cmnd
[0] == WRITE_16
) { /* 16 byte command */
1735 dprintk((KERN_DEBUG
"aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd
)));
1737 lba
= ((u64
)scsicmd
->cmnd
[2] << 56) |
1738 ((u64
)scsicmd
->cmnd
[3] << 48) |
1739 ((u64
)scsicmd
->cmnd
[4] << 40) |
1740 ((u64
)scsicmd
->cmnd
[5] << 32) |
1741 ((u64
)scsicmd
->cmnd
[6] << 24) |
1742 (scsicmd
->cmnd
[7] << 16) |
1743 (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1744 count
= (scsicmd
->cmnd
[10] << 24) | (scsicmd
->cmnd
[11] << 16) |
1745 (scsicmd
->cmnd
[12] << 8) | scsicmd
->cmnd
[13];
1746 fua
= scsicmd
->cmnd
[1] & 0x8;
1747 } else if (scsicmd
->cmnd
[0] == WRITE_12
) { /* 12 byte command */
1748 dprintk((KERN_DEBUG
"aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd
)));
1750 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16)
1751 | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1752 count
= (scsicmd
->cmnd
[6] << 24) | (scsicmd
->cmnd
[7] << 16)
1753 | (scsicmd
->cmnd
[8] << 8) | scsicmd
->cmnd
[9];
1754 fua
= scsicmd
->cmnd
[1] & 0x8;
1756 dprintk((KERN_DEBUG
"aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd
)));
1757 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) | (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1758 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1759 fua
= scsicmd
->cmnd
[1] & 0x8;
1762 if ((lba
+ count
) > (dev
->fsa_dev
[scmd_id(scsicmd
)].size
)) {
1763 cid
= scmd_id(scsicmd
);
1764 dprintk((KERN_DEBUG
"aacraid: Illegal lba\n"));
1765 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
1766 SAM_STAT_CHECK_CONDITION
;
1767 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1768 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1769 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1770 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1771 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1772 SCSI_SENSE_BUFFERSIZE
));
1773 scsicmd
->scsi_done(scsicmd
);
1777 dprintk((KERN_DEBUG
"aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1778 smp_processor_id(), (unsigned long long)lba
, jiffies
));
1779 if (aac_adapter_bounds(dev
,scsicmd
,lba
))
1782 * Allocate and initialize a Fib then setup a BlockWrite command
1784 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
1785 /* FIB temporarily unavailable,not catastrophic failure */
1787 /* scsicmd->result = DID_ERROR << 16;
1788 * scsicmd->scsi_done(scsicmd);
1791 printk(KERN_WARNING
"aac_write: fib allocation failed\n");
1795 status
= aac_adapter_write(cmd_fibcontext
, scsicmd
, lba
, count
, fua
);
1798 * Check that the command queued to the controller
1800 if (status
== -EINPROGRESS
) {
1801 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1805 printk(KERN_WARNING
"aac_write: aac_fib_send failed with status: %d\n", status
);
1807 * For some reason, the Fib didn't queue, return QUEUE_FULL
1809 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_TASK_SET_FULL
;
1810 scsicmd
->scsi_done(scsicmd
);
1812 aac_fib_complete(cmd_fibcontext
);
1813 aac_fib_free(cmd_fibcontext
);
1817 static void synchronize_callback(void *context
, struct fib
*fibptr
)
1819 struct aac_synchronize_reply
*synchronizereply
;
1820 struct scsi_cmnd
*cmd
;
1824 if (!aac_valid_context(cmd
, fibptr
))
1827 dprintk((KERN_DEBUG
"synchronize_callback[cpu %d]: t = %ld.\n",
1828 smp_processor_id(), jiffies
));
1829 BUG_ON(fibptr
== NULL
);
1832 synchronizereply
= fib_data(fibptr
);
1833 if (le32_to_cpu(synchronizereply
->status
) == CT_OK
)
1834 cmd
->result
= DID_OK
<< 16 |
1835 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1837 struct scsi_device
*sdev
= cmd
->device
;
1838 struct aac_dev
*dev
= fibptr
->dev
;
1839 u32 cid
= sdev_id(sdev
);
1841 "synchronize_callback: synchronize failed, status = %d\n",
1842 le32_to_cpu(synchronizereply
->status
));
1843 cmd
->result
= DID_OK
<< 16 |
1844 COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
1845 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
1846 HARDWARE_ERROR
, SENCODE_INTERNAL_TARGET_FAILURE
,
1847 ASENCODE_INTERNAL_TARGET_FAILURE
, 0, 0);
1848 memcpy(cmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
1849 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
1850 SCSI_SENSE_BUFFERSIZE
));
1853 aac_fib_complete(fibptr
);
1854 aac_fib_free(fibptr
);
1855 cmd
->scsi_done(cmd
);
1858 static int aac_synchronize(struct scsi_cmnd
*scsicmd
)
1861 struct fib
*cmd_fibcontext
;
1862 struct aac_synchronize
*synchronizecmd
;
1863 struct scsi_cmnd
*cmd
;
1864 struct scsi_device
*sdev
= scsicmd
->device
;
1866 struct aac_dev
*aac
;
1867 u64 lba
= ((u64
)scsicmd
->cmnd
[2] << 24) | (scsicmd
->cmnd
[3] << 16) |
1868 (scsicmd
->cmnd
[4] << 8) | scsicmd
->cmnd
[5];
1869 u32 count
= (scsicmd
->cmnd
[7] << 8) | scsicmd
->cmnd
[8];
1870 unsigned long flags
;
1873 * Wait for all outstanding queued commands to complete to this
1874 * specific target (block).
1876 spin_lock_irqsave(&sdev
->list_lock
, flags
);
1877 list_for_each_entry(cmd
, &sdev
->cmd_list
, list
)
1878 if (cmd
->SCp
.phase
== AAC_OWNER_FIRMWARE
) {
1882 if (cmd
->cmnd
[0] == WRITE_6
) {
1883 cmnd_lba
= ((cmd
->cmnd
[1] & 0x1F) << 16) |
1884 (cmd
->cmnd
[2] << 8) |
1886 cmnd_count
= cmd
->cmnd
[4];
1887 if (cmnd_count
== 0)
1889 } else if (cmd
->cmnd
[0] == WRITE_16
) {
1890 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 56) |
1891 ((u64
)cmd
->cmnd
[3] << 48) |
1892 ((u64
)cmd
->cmnd
[4] << 40) |
1893 ((u64
)cmd
->cmnd
[5] << 32) |
1894 ((u64
)cmd
->cmnd
[6] << 24) |
1895 (cmd
->cmnd
[7] << 16) |
1896 (cmd
->cmnd
[8] << 8) |
1898 cmnd_count
= (cmd
->cmnd
[10] << 24) |
1899 (cmd
->cmnd
[11] << 16) |
1900 (cmd
->cmnd
[12] << 8) |
1902 } else if (cmd
->cmnd
[0] == WRITE_12
) {
1903 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
1904 (cmd
->cmnd
[3] << 16) |
1905 (cmd
->cmnd
[4] << 8) |
1907 cmnd_count
= (cmd
->cmnd
[6] << 24) |
1908 (cmd
->cmnd
[7] << 16) |
1909 (cmd
->cmnd
[8] << 8) |
1911 } else if (cmd
->cmnd
[0] == WRITE_10
) {
1912 cmnd_lba
= ((u64
)cmd
->cmnd
[2] << 24) |
1913 (cmd
->cmnd
[3] << 16) |
1914 (cmd
->cmnd
[4] << 8) |
1916 cmnd_count
= (cmd
->cmnd
[7] << 8) |
1920 if (((cmnd_lba
+ cmnd_count
) < lba
) ||
1921 (count
&& ((lba
+ count
) < cmnd_lba
)))
1927 spin_unlock_irqrestore(&sdev
->list_lock
, flags
);
1930 * Yield the processor (requeue for later)
1933 return SCSI_MLQUEUE_DEVICE_BUSY
;
1935 aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
1937 return SCSI_MLQUEUE_HOST_BUSY
;
1940 * Allocate and initialize a Fib
1942 if (!(cmd_fibcontext
= aac_fib_alloc(aac
)))
1943 return SCSI_MLQUEUE_HOST_BUSY
;
1945 aac_fib_init(cmd_fibcontext
);
1947 synchronizecmd
= fib_data(cmd_fibcontext
);
1948 synchronizecmd
->command
= cpu_to_le32(VM_ContainerConfig
);
1949 synchronizecmd
->type
= cpu_to_le32(CT_FLUSH_CACHE
);
1950 synchronizecmd
->cid
= cpu_to_le32(scmd_id(scsicmd
));
1951 synchronizecmd
->count
=
1952 cpu_to_le32(sizeof(((struct aac_synchronize_reply
*)NULL
)->data
));
1955 * Now send the Fib to the adapter
1957 status
= aac_fib_send(ContainerCommand
,
1959 sizeof(struct aac_synchronize
),
1962 (fib_callback
)synchronize_callback
,
1966 * Check that the command queued to the controller
1968 if (status
== -EINPROGRESS
) {
1969 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
1974 "aac_synchronize: aac_fib_send failed with status: %d.\n", status
);
1975 aac_fib_complete(cmd_fibcontext
);
1976 aac_fib_free(cmd_fibcontext
);
1977 return SCSI_MLQUEUE_HOST_BUSY
;
1980 static void aac_start_stop_callback(void *context
, struct fib
*fibptr
)
1982 struct scsi_cmnd
*scsicmd
= context
;
1984 if (!aac_valid_context(scsicmd
, fibptr
))
1987 BUG_ON(fibptr
== NULL
);
1989 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
1991 aac_fib_complete(fibptr
);
1992 aac_fib_free(fibptr
);
1993 scsicmd
->scsi_done(scsicmd
);
1996 static int aac_start_stop(struct scsi_cmnd
*scsicmd
)
1999 struct fib
*cmd_fibcontext
;
2000 struct aac_power_management
*pmcmd
;
2001 struct scsi_device
*sdev
= scsicmd
->device
;
2002 struct aac_dev
*aac
= (struct aac_dev
*)sdev
->host
->hostdata
;
2004 if (!(aac
->supplement_adapter_info
.SupportedOptions2
&
2005 AAC_OPTION_POWER_MANAGEMENT
)) {
2006 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2008 scsicmd
->scsi_done(scsicmd
);
2013 return SCSI_MLQUEUE_HOST_BUSY
;
2016 * Allocate and initialize a Fib
2018 cmd_fibcontext
= aac_fib_alloc(aac
);
2019 if (!cmd_fibcontext
)
2020 return SCSI_MLQUEUE_HOST_BUSY
;
2022 aac_fib_init(cmd_fibcontext
);
2024 pmcmd
= fib_data(cmd_fibcontext
);
2025 pmcmd
->command
= cpu_to_le32(VM_ContainerConfig
);
2026 pmcmd
->type
= cpu_to_le32(CT_POWER_MANAGEMENT
);
2027 /* Eject bit ignored, not relevant */
2028 pmcmd
->sub
= (scsicmd
->cmnd
[4] & 1) ?
2029 cpu_to_le32(CT_PM_START_UNIT
) : cpu_to_le32(CT_PM_STOP_UNIT
);
2030 pmcmd
->cid
= cpu_to_le32(sdev_id(sdev
));
2031 pmcmd
->parm
= (scsicmd
->cmnd
[1] & 1) ?
2032 cpu_to_le32(CT_PM_UNIT_IMMEDIATE
) : 0;
2035 * Now send the Fib to the adapter
2037 status
= aac_fib_send(ContainerCommand
,
2039 sizeof(struct aac_power_management
),
2042 (fib_callback
)aac_start_stop_callback
,
2046 * Check that the command queued to the controller
2048 if (status
== -EINPROGRESS
) {
2049 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2053 aac_fib_complete(cmd_fibcontext
);
2054 aac_fib_free(cmd_fibcontext
);
2055 return SCSI_MLQUEUE_HOST_BUSY
;
2059 * aac_scsi_cmd() - Process SCSI command
2060 * @scsicmd: SCSI command block
2062 * Emulate a SCSI command and queue the required request for the
2066 int aac_scsi_cmd(struct scsi_cmnd
* scsicmd
)
2069 struct Scsi_Host
*host
= scsicmd
->device
->host
;
2070 struct aac_dev
*dev
= (struct aac_dev
*)host
->hostdata
;
2071 struct fsa_dev_info
*fsa_dev_ptr
= dev
->fsa_dev
;
2073 if (fsa_dev_ptr
== NULL
)
2076 * If the bus, id or lun is out of range, return fail
2077 * Test does not apply to ID 16, the pseudo id for the controller
2080 cid
= scmd_id(scsicmd
);
2081 if (cid
!= host
->this_id
) {
2082 if (scmd_channel(scsicmd
) == CONTAINER_CHANNEL
) {
2083 if((cid
>= dev
->maximum_num_containers
) ||
2084 (scsicmd
->device
->lun
!= 0)) {
2085 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2086 scsicmd
->scsi_done(scsicmd
);
2091 * If the target container doesn't exist, it may have
2092 * been newly created
2094 if (((fsa_dev_ptr
[cid
].valid
& 1) == 0) ||
2095 (fsa_dev_ptr
[cid
].sense_data
.sense_key
==
2097 switch (scsicmd
->cmnd
[0]) {
2098 case SERVICE_ACTION_IN
:
2099 if (!(dev
->raw_io_interface
) ||
2100 !(dev
->raw_io_64
) ||
2101 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2105 case TEST_UNIT_READY
:
2108 return _aac_probe_container(scsicmd
,
2109 aac_probe_container_callback2
);
2114 } else { /* check for physical non-dasd devices */
2115 if (dev
->nondasd_support
|| expose_physicals
||
2119 return aac_send_srb_fib(scsicmd
);
2121 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2122 scsicmd
->scsi_done(scsicmd
);
2128 * else Command for the controller itself
2130 else if ((scsicmd
->cmnd
[0] != INQUIRY
) && /* only INQUIRY & TUR cmnd supported for controller */
2131 (scsicmd
->cmnd
[0] != TEST_UNIT_READY
))
2133 dprintk((KERN_WARNING
"Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd
->cmnd
[0]));
2134 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2135 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2136 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2137 ASENCODE_INVALID_COMMAND
, 0, 0);
2138 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2139 min_t(size_t, sizeof(dev
->fsa_dev
[cid
].sense_data
),
2140 SCSI_SENSE_BUFFERSIZE
));
2141 scsicmd
->scsi_done(scsicmd
);
2146 /* Handle commands here that don't really require going out to the adapter */
2147 switch (scsicmd
->cmnd
[0]) {
2150 struct inquiry_data inq_data
;
2152 dprintk((KERN_DEBUG
"INQUIRY command, ID: %d.\n", cid
));
2153 memset(&inq_data
, 0, sizeof (struct inquiry_data
));
2155 if ((scsicmd
->cmnd
[1] & 0x1) && aac_wwn
) {
2156 char *arr
= (char *)&inq_data
;
2159 arr
[0] = (scmd_id(scsicmd
) == host
->this_id
) ?
2160 INQD_PDT_PROC
: INQD_PDT_DA
;
2161 if (scsicmd
->cmnd
[2] == 0) {
2162 /* supported vital product data pages */
2166 arr
[1] = scsicmd
->cmnd
[2];
2167 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2169 scsicmd
->result
= DID_OK
<< 16 |
2170 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2171 } else if (scsicmd
->cmnd
[2] == 0x80) {
2172 /* unit serial number page */
2173 arr
[3] = setinqserial(dev
, &arr
[4],
2175 arr
[1] = scsicmd
->cmnd
[2];
2176 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2179 return aac_get_container_serial(
2181 /* SLES 10 SP1 special */
2182 scsicmd
->result
= DID_OK
<< 16 |
2183 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2185 /* vpd page not implemented */
2186 scsicmd
->result
= DID_OK
<< 16 |
2187 COMMAND_COMPLETE
<< 8 |
2188 SAM_STAT_CHECK_CONDITION
;
2189 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2190 ILLEGAL_REQUEST
, SENCODE_INVALID_CDB_FIELD
,
2191 ASENCODE_NO_SENSE
, 7, 2);
2192 memcpy(scsicmd
->sense_buffer
,
2193 &dev
->fsa_dev
[cid
].sense_data
,
2195 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2196 SCSI_SENSE_BUFFERSIZE
));
2198 scsicmd
->scsi_done(scsicmd
);
2201 inq_data
.inqd_ver
= 2; /* claim compliance to SCSI-2 */
2202 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 */
2203 inq_data
.inqd_len
= 31;
2204 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2205 inq_data
.inqd_pad2
= 0x32 ; /*WBus16|Sync|CmdQue */
2207 * Set the Vendor, Product, and Revision Level
2208 * see: <vendor>.c i.e. aac.c
2210 if (cid
== host
->this_id
) {
2211 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), ARRAY_SIZE(container_types
));
2212 inq_data
.inqd_pdt
= INQD_PDT_PROC
; /* Processor device */
2213 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
,
2215 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2216 scsicmd
->scsi_done(scsicmd
);
2221 setinqstr(dev
, (void *) (inq_data
.inqd_vid
), fsa_dev_ptr
[cid
].type
);
2222 inq_data
.inqd_pdt
= INQD_PDT_DA
; /* Direct/random access device */
2223 scsi_sg_copy_from_buffer(scsicmd
, &inq_data
, sizeof(inq_data
));
2224 return aac_get_container_name(scsicmd
);
2226 case SERVICE_ACTION_IN
:
2227 if (!(dev
->raw_io_interface
) ||
2228 !(dev
->raw_io_64
) ||
2229 ((scsicmd
->cmnd
[1] & 0x1f) != SAI_READ_CAPACITY_16
))
2234 unsigned int alloc_len
;
2236 dprintk((KERN_DEBUG
"READ CAPACITY_16 command.\n"));
2237 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2238 cp
[0] = (capacity
>> 56) & 0xff;
2239 cp
[1] = (capacity
>> 48) & 0xff;
2240 cp
[2] = (capacity
>> 40) & 0xff;
2241 cp
[3] = (capacity
>> 32) & 0xff;
2242 cp
[4] = (capacity
>> 24) & 0xff;
2243 cp
[5] = (capacity
>> 16) & 0xff;
2244 cp
[6] = (capacity
>> 8) & 0xff;
2245 cp
[7] = (capacity
>> 0) & 0xff;
2252 alloc_len
= ((scsicmd
->cmnd
[10] << 24)
2253 + (scsicmd
->cmnd
[11] << 16)
2254 + (scsicmd
->cmnd
[12] << 8) + scsicmd
->cmnd
[13]);
2256 alloc_len
= min_t(size_t, alloc_len
, sizeof(cp
));
2257 scsi_sg_copy_from_buffer(scsicmd
, cp
, alloc_len
);
2258 if (alloc_len
< scsi_bufflen(scsicmd
))
2259 scsi_set_resid(scsicmd
,
2260 scsi_bufflen(scsicmd
) - alloc_len
);
2262 /* Do not cache partition table for arrays */
2263 scsicmd
->device
->removable
= 1;
2265 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2266 scsicmd
->scsi_done(scsicmd
);
2276 dprintk((KERN_DEBUG
"READ CAPACITY command.\n"));
2277 if (fsa_dev_ptr
[cid
].size
<= 0x100000000ULL
)
2278 capacity
= fsa_dev_ptr
[cid
].size
- 1;
2282 cp
[0] = (capacity
>> 24) & 0xff;
2283 cp
[1] = (capacity
>> 16) & 0xff;
2284 cp
[2] = (capacity
>> 8) & 0xff;
2285 cp
[3] = (capacity
>> 0) & 0xff;
2290 scsi_sg_copy_from_buffer(scsicmd
, cp
, sizeof(cp
));
2291 /* Do not cache partition table for arrays */
2292 scsicmd
->device
->removable
= 1;
2293 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2295 scsicmd
->scsi_done(scsicmd
);
2303 int mode_buf_length
= 4;
2305 dprintk((KERN_DEBUG
"MODE SENSE command.\n"));
2306 mode_buf
[0] = 3; /* Mode data length */
2307 mode_buf
[1] = 0; /* Medium type - default */
2308 mode_buf
[2] = 0; /* Device-specific param,
2309 bit 8: 0/1 = write enabled/protected
2310 bit 4: 0/1 = FUA enabled */
2311 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2313 mode_buf
[3] = 0; /* Block descriptor length */
2314 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2315 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2319 mode_buf
[6] = ((aac_cache
& 6) == 2)
2320 ? 0 : 0x04; /* WCE */
2321 mode_buf_length
= 7;
2322 if (mode_buf_length
> scsicmd
->cmnd
[4])
2323 mode_buf_length
= scsicmd
->cmnd
[4];
2325 scsi_sg_copy_from_buffer(scsicmd
, mode_buf
, mode_buf_length
);
2326 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2327 scsicmd
->scsi_done(scsicmd
);
2334 int mode_buf_length
= 8;
2336 dprintk((KERN_DEBUG
"MODE SENSE 10 byte command.\n"));
2337 mode_buf
[0] = 0; /* Mode data length (MSB) */
2338 mode_buf
[1] = 6; /* Mode data length (LSB) */
2339 mode_buf
[2] = 0; /* Medium type - default */
2340 mode_buf
[3] = 0; /* Device-specific param,
2341 bit 8: 0/1 = write enabled/protected
2342 bit 4: 0/1 = FUA enabled */
2343 if (dev
->raw_io_interface
&& ((aac_cache
& 5) != 1))
2345 mode_buf
[4] = 0; /* reserved */
2346 mode_buf
[5] = 0; /* reserved */
2347 mode_buf
[6] = 0; /* Block descriptor length (MSB) */
2348 mode_buf
[7] = 0; /* Block descriptor length (LSB) */
2349 if (((scsicmd
->cmnd
[2] & 0x3f) == 8) ||
2350 ((scsicmd
->cmnd
[2] & 0x3f) == 0x3f)) {
2354 mode_buf
[10] = ((aac_cache
& 6) == 2)
2355 ? 0 : 0x04; /* WCE */
2356 mode_buf_length
= 11;
2357 if (mode_buf_length
> scsicmd
->cmnd
[8])
2358 mode_buf_length
= scsicmd
->cmnd
[8];
2360 scsi_sg_copy_from_buffer(scsicmd
, mode_buf
, mode_buf_length
);
2362 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2363 scsicmd
->scsi_done(scsicmd
);
2368 dprintk((KERN_DEBUG
"REQUEST SENSE command.\n"));
2369 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
, sizeof (struct sense_data
));
2370 memset(&dev
->fsa_dev
[cid
].sense_data
, 0, sizeof (struct sense_data
));
2371 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2372 scsicmd
->scsi_done(scsicmd
);
2375 case ALLOW_MEDIUM_REMOVAL
:
2376 dprintk((KERN_DEBUG
"LOCK command.\n"));
2377 if (scsicmd
->cmnd
[4])
2378 fsa_dev_ptr
[cid
].locked
= 1;
2380 fsa_dev_ptr
[cid
].locked
= 0;
2382 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2383 scsicmd
->scsi_done(scsicmd
);
2386 * These commands are all No-Ops
2388 case TEST_UNIT_READY
:
2389 if (fsa_dev_ptr
[cid
].sense_data
.sense_key
== NOT_READY
) {
2390 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 |
2391 SAM_STAT_CHECK_CONDITION
;
2392 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2393 NOT_READY
, SENCODE_BECOMING_READY
,
2394 ASENCODE_BECOMING_READY
, 0, 0);
2395 memcpy(scsicmd
->sense_buffer
,
2396 &dev
->fsa_dev
[cid
].sense_data
,
2398 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2399 SCSI_SENSE_BUFFERSIZE
));
2400 scsicmd
->scsi_done(scsicmd
);
2407 case REASSIGN_BLOCKS
:
2409 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2410 scsicmd
->scsi_done(scsicmd
);
2414 return aac_start_stop(scsicmd
);
2417 switch (scsicmd
->cmnd
[0])
2426 * Hack to keep track of ordinal number of the device that
2427 * corresponds to a container. Needed to convert
2428 * containers to /dev/sd device names
2431 if (scsicmd
->request
->rq_disk
)
2432 strlcpy(fsa_dev_ptr
[cid
].devname
,
2433 scsicmd
->request
->rq_disk
->disk_name
,
2434 min(sizeof(fsa_dev_ptr
[cid
].devname
),
2435 sizeof(scsicmd
->request
->rq_disk
->disk_name
) + 1));
2437 return aac_read(scsicmd
);
2445 return aac_write(scsicmd
);
2447 case SYNCHRONIZE_CACHE
:
2448 if (((aac_cache
& 6) == 6) && dev
->cache_protected
) {
2449 scsicmd
->result
= DID_OK
<< 16 |
2450 COMMAND_COMPLETE
<< 8 | SAM_STAT_GOOD
;
2451 scsicmd
->scsi_done(scsicmd
);
2454 /* Issue FIB to tell Firmware to flush it's cache */
2455 if ((aac_cache
& 6) != 2)
2456 return aac_synchronize(scsicmd
);
2460 * Unhandled commands
2462 dprintk((KERN_WARNING
"Unhandled SCSI Command: 0x%x.\n", scsicmd
->cmnd
[0]));
2463 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2464 set_sense(&dev
->fsa_dev
[cid
].sense_data
,
2465 ILLEGAL_REQUEST
, SENCODE_INVALID_COMMAND
,
2466 ASENCODE_INVALID_COMMAND
, 0, 0);
2467 memcpy(scsicmd
->sense_buffer
, &dev
->fsa_dev
[cid
].sense_data
,
2469 sizeof(dev
->fsa_dev
[cid
].sense_data
),
2470 SCSI_SENSE_BUFFERSIZE
));
2471 scsicmd
->scsi_done(scsicmd
);
2476 static int query_disk(struct aac_dev
*dev
, void __user
*arg
)
2478 struct aac_query_disk qd
;
2479 struct fsa_dev_info
*fsa_dev_ptr
;
2481 fsa_dev_ptr
= dev
->fsa_dev
;
2484 if (copy_from_user(&qd
, arg
, sizeof (struct aac_query_disk
)))
2488 else if ((qd
.bus
== -1) && (qd
.id
== -1) && (qd
.lun
== -1))
2490 if (qd
.cnum
< 0 || qd
.cnum
>= dev
->maximum_num_containers
)
2492 qd
.instance
= dev
->scsi_host_ptr
->host_no
;
2494 qd
.id
= CONTAINER_TO_ID(qd
.cnum
);
2495 qd
.lun
= CONTAINER_TO_LUN(qd
.cnum
);
2497 else return -EINVAL
;
2499 qd
.valid
= fsa_dev_ptr
[qd
.cnum
].valid
!= 0;
2500 qd
.locked
= fsa_dev_ptr
[qd
.cnum
].locked
;
2501 qd
.deleted
= fsa_dev_ptr
[qd
.cnum
].deleted
;
2503 if (fsa_dev_ptr
[qd
.cnum
].devname
[0] == '\0')
2508 strlcpy(qd
.name
, fsa_dev_ptr
[qd
.cnum
].devname
,
2509 min(sizeof(qd
.name
), sizeof(fsa_dev_ptr
[qd
.cnum
].devname
) + 1));
2511 if (copy_to_user(arg
, &qd
, sizeof (struct aac_query_disk
)))
2516 static int force_delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2518 struct aac_delete_disk dd
;
2519 struct fsa_dev_info
*fsa_dev_ptr
;
2521 fsa_dev_ptr
= dev
->fsa_dev
;
2525 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2528 if (dd
.cnum
>= dev
->maximum_num_containers
)
2531 * Mark this container as being deleted.
2533 fsa_dev_ptr
[dd
.cnum
].deleted
= 1;
2535 * Mark the container as no longer valid
2537 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2541 static int delete_disk(struct aac_dev
*dev
, void __user
*arg
)
2543 struct aac_delete_disk dd
;
2544 struct fsa_dev_info
*fsa_dev_ptr
;
2546 fsa_dev_ptr
= dev
->fsa_dev
;
2550 if (copy_from_user(&dd
, arg
, sizeof (struct aac_delete_disk
)))
2553 if (dd
.cnum
>= dev
->maximum_num_containers
)
2556 * If the container is locked, it can not be deleted by the API.
2558 if (fsa_dev_ptr
[dd
.cnum
].locked
)
2562 * Mark the container as no longer being valid.
2564 fsa_dev_ptr
[dd
.cnum
].valid
= 0;
2565 fsa_dev_ptr
[dd
.cnum
].devname
[0] = '\0';
2570 int aac_dev_ioctl(struct aac_dev
*dev
, int cmd
, void __user
*arg
)
2573 case FSACTL_QUERY_DISK
:
2574 return query_disk(dev
, arg
);
2575 case FSACTL_DELETE_DISK
:
2576 return delete_disk(dev
, arg
);
2577 case FSACTL_FORCE_DELETE_DISK
:
2578 return force_delete_disk(dev
, arg
);
2579 case FSACTL_GET_CONTAINERS
:
2580 return aac_get_containers(dev
);
2589 * @context: the context set in the fib - here it is scsi cmd
2590 * @fibptr: pointer to the fib
2592 * Handles the completion of a scsi command to a non dasd device
2596 static void aac_srb_callback(void *context
, struct fib
* fibptr
)
2598 struct aac_dev
*dev
;
2599 struct aac_srb_reply
*srbreply
;
2600 struct scsi_cmnd
*scsicmd
;
2602 scsicmd
= (struct scsi_cmnd
*) context
;
2604 if (!aac_valid_context(scsicmd
, fibptr
))
2607 BUG_ON(fibptr
== NULL
);
2611 srbreply
= (struct aac_srb_reply
*) fib_data(fibptr
);
2613 scsicmd
->sense_buffer
[0] = '\0'; /* Initialize sense valid flag to false */
2615 * Calculate resid for sg
2618 scsi_set_resid(scsicmd
, scsi_bufflen(scsicmd
)
2619 - le32_to_cpu(srbreply
->data_xfer_length
));
2621 scsi_dma_unmap(scsicmd
);
2623 /* expose physical device if expose_physicald flag is on */
2624 if (scsicmd
->cmnd
[0] == INQUIRY
&& !(scsicmd
->cmnd
[1] & 0x01)
2625 && expose_physicals
> 0)
2626 aac_expose_phy_device(scsicmd
);
2629 * First check the fib status
2632 if (le32_to_cpu(srbreply
->status
) != ST_OK
){
2634 printk(KERN_WARNING
"aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply
->status
));
2635 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
2636 SCSI_SENSE_BUFFERSIZE
);
2637 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8 | SAM_STAT_CHECK_CONDITION
;
2638 memcpy(scsicmd
->sense_buffer
, srbreply
->sense_data
, len
);
2642 * Next check the srb status
2644 switch( (le32_to_cpu(srbreply
->srb_status
))&0x3f){
2645 case SRB_STATUS_ERROR_RECOVERY
:
2646 case SRB_STATUS_PENDING
:
2647 case SRB_STATUS_SUCCESS
:
2648 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
2650 case SRB_STATUS_DATA_OVERRUN
:
2651 switch(scsicmd
->cmnd
[0]){
2660 if (le32_to_cpu(srbreply
->data_xfer_length
) < scsicmd
->underflow
) {
2661 printk(KERN_WARNING
"aacraid: SCSI CMD underflow\n");
2663 printk(KERN_WARNING
"aacraid: SCSI CMD Data Overrun\n");
2665 scsicmd
->result
= DID_ERROR
<< 16 | COMMAND_COMPLETE
<< 8;
2668 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
2672 scsicmd
->result
= DID_OK
<< 16 | COMMAND_COMPLETE
<< 8;
2676 case SRB_STATUS_ABORTED
:
2677 scsicmd
->result
= DID_ABORT
<< 16 | ABORT
<< 8;
2679 case SRB_STATUS_ABORT_FAILED
:
2680 // Not sure about this one - but assuming the hba was trying to abort for some reason
2681 scsicmd
->result
= DID_ERROR
<< 16 | ABORT
<< 8;
2683 case SRB_STATUS_PARITY_ERROR
:
2684 scsicmd
->result
= DID_PARITY
<< 16 | MSG_PARITY_ERROR
<< 8;
2686 case SRB_STATUS_NO_DEVICE
:
2687 case SRB_STATUS_INVALID_PATH_ID
:
2688 case SRB_STATUS_INVALID_TARGET_ID
:
2689 case SRB_STATUS_INVALID_LUN
:
2690 case SRB_STATUS_SELECTION_TIMEOUT
:
2691 scsicmd
->result
= DID_NO_CONNECT
<< 16 | COMMAND_COMPLETE
<< 8;
2694 case SRB_STATUS_COMMAND_TIMEOUT
:
2695 case SRB_STATUS_TIMEOUT
:
2696 scsicmd
->result
= DID_TIME_OUT
<< 16 | COMMAND_COMPLETE
<< 8;
2699 case SRB_STATUS_BUSY
:
2700 scsicmd
->result
= DID_BUS_BUSY
<< 16 | COMMAND_COMPLETE
<< 8;
2703 case SRB_STATUS_BUS_RESET
:
2704 scsicmd
->result
= DID_RESET
<< 16 | COMMAND_COMPLETE
<< 8;
2707 case SRB_STATUS_MESSAGE_REJECTED
:
2708 scsicmd
->result
= DID_ERROR
<< 16 | MESSAGE_REJECT
<< 8;
2710 case SRB_STATUS_REQUEST_FLUSHED
:
2711 case SRB_STATUS_ERROR
:
2712 case SRB_STATUS_INVALID_REQUEST
:
2713 case SRB_STATUS_REQUEST_SENSE_FAILED
:
2714 case SRB_STATUS_NO_HBA
:
2715 case SRB_STATUS_UNEXPECTED_BUS_FREE
:
2716 case SRB_STATUS_PHASE_SEQUENCE_FAILURE
:
2717 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH
:
2718 case SRB_STATUS_DELAYED_RETRY
:
2719 case SRB_STATUS_BAD_FUNCTION
:
2720 case SRB_STATUS_NOT_STARTED
:
2721 case SRB_STATUS_NOT_IN_USE
:
2722 case SRB_STATUS_FORCE_ABORT
:
2723 case SRB_STATUS_DOMAIN_VALIDATION_FAIL
:
2725 #ifdef AAC_DETAILED_STATUS_INFO
2726 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2727 le32_to_cpu(srbreply
->srb_status
) & 0x3F,
2728 aac_get_status_string(
2729 le32_to_cpu(srbreply
->srb_status
) & 0x3F),
2731 le32_to_cpu(srbreply
->scsi_status
));
2733 if ((scsicmd
->cmnd
[0] == ATA_12
)
2734 || (scsicmd
->cmnd
[0] == ATA_16
)) {
2735 if (scsicmd
->cmnd
[2] & (0x01 << 5)) {
2736 scsicmd
->result
= DID_OK
<< 16
2737 | COMMAND_COMPLETE
<< 8;
2740 scsicmd
->result
= DID_ERROR
<< 16
2741 | COMMAND_COMPLETE
<< 8;
2745 scsicmd
->result
= DID_ERROR
<< 16
2746 | COMMAND_COMPLETE
<< 8;
2750 if (le32_to_cpu(srbreply
->scsi_status
) == SAM_STAT_CHECK_CONDITION
) {
2752 scsicmd
->result
|= SAM_STAT_CHECK_CONDITION
;
2753 len
= min_t(u32
, le32_to_cpu(srbreply
->sense_data_size
),
2754 SCSI_SENSE_BUFFERSIZE
);
2755 #ifdef AAC_DETAILED_STATUS_INFO
2756 printk(KERN_WARNING
"aac_srb_callback: check condition, status = %d len=%d\n",
2757 le32_to_cpu(srbreply
->status
), len
);
2759 memcpy(scsicmd
->sense_buffer
, srbreply
->sense_data
, len
);
2762 * OR in the scsi status (already shifted up a bit)
2764 scsicmd
->result
|= le32_to_cpu(srbreply
->scsi_status
);
2766 aac_fib_complete(fibptr
);
2767 aac_fib_free(fibptr
);
2768 scsicmd
->scsi_done(scsicmd
);
2774 * @scsicmd: the scsi command block
2776 * This routine will form a FIB and fill in the aac_srb from the
2777 * scsicmd passed in.
2780 static int aac_send_srb_fib(struct scsi_cmnd
* scsicmd
)
2782 struct fib
* cmd_fibcontext
;
2783 struct aac_dev
* dev
;
2786 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2787 if (scmd_id(scsicmd
) >= dev
->maximum_num_physicals
||
2788 scsicmd
->device
->lun
> 7) {
2789 scsicmd
->result
= DID_NO_CONNECT
<< 16;
2790 scsicmd
->scsi_done(scsicmd
);
2795 * Allocate and initialize a Fib then setup a BlockWrite command
2797 if (!(cmd_fibcontext
= aac_fib_alloc(dev
))) {
2800 status
= aac_adapter_scsi(cmd_fibcontext
, scsicmd
);
2803 * Check that the command queued to the controller
2805 if (status
== -EINPROGRESS
) {
2806 scsicmd
->SCp
.phase
= AAC_OWNER_FIRMWARE
;
2810 printk(KERN_WARNING
"aac_srb: aac_fib_send failed with status: %d\n", status
);
2811 aac_fib_complete(cmd_fibcontext
);
2812 aac_fib_free(cmd_fibcontext
);
2817 static unsigned long aac_build_sg(struct scsi_cmnd
* scsicmd
, struct sgmap
* psg
)
2819 struct aac_dev
*dev
;
2820 unsigned long byte_count
= 0;
2823 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2824 // Get rid of old data
2826 psg
->sg
[0].addr
= 0;
2827 psg
->sg
[0].count
= 0;
2829 nseg
= scsi_dma_map(scsicmd
);
2832 struct scatterlist
*sg
;
2835 psg
->count
= cpu_to_le32(nseg
);
2837 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
2838 psg
->sg
[i
].addr
= cpu_to_le32(sg_dma_address(sg
));
2839 psg
->sg
[i
].count
= cpu_to_le32(sg_dma_len(sg
));
2840 byte_count
+= sg_dma_len(sg
);
2842 /* hba wants the size to be exact */
2843 if (byte_count
> scsi_bufflen(scsicmd
)) {
2844 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
2845 (byte_count
- scsi_bufflen(scsicmd
));
2846 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
2847 byte_count
= scsi_bufflen(scsicmd
);
2849 /* Check for command underflow */
2850 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
2851 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
2852 byte_count
, scsicmd
->underflow
);
2859 static unsigned long aac_build_sg64(struct scsi_cmnd
* scsicmd
, struct sgmap64
* psg
)
2861 struct aac_dev
*dev
;
2862 unsigned long byte_count
= 0;
2866 dev
= (struct aac_dev
*)scsicmd
->device
->host
->hostdata
;
2867 // Get rid of old data
2869 psg
->sg
[0].addr
[0] = 0;
2870 psg
->sg
[0].addr
[1] = 0;
2871 psg
->sg
[0].count
= 0;
2873 nseg
= scsi_dma_map(scsicmd
);
2876 struct scatterlist
*sg
;
2879 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
2880 int count
= sg_dma_len(sg
);
2881 addr
= sg_dma_address(sg
);
2882 psg
->sg
[i
].addr
[0] = cpu_to_le32(addr
& 0xffffffff);
2883 psg
->sg
[i
].addr
[1] = cpu_to_le32(addr
>>32);
2884 psg
->sg
[i
].count
= cpu_to_le32(count
);
2885 byte_count
+= count
;
2887 psg
->count
= cpu_to_le32(nseg
);
2888 /* hba wants the size to be exact */
2889 if (byte_count
> scsi_bufflen(scsicmd
)) {
2890 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
2891 (byte_count
- scsi_bufflen(scsicmd
));
2892 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
2893 byte_count
= scsi_bufflen(scsicmd
);
2895 /* Check for command underflow */
2896 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
2897 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
2898 byte_count
, scsicmd
->underflow
);
2904 static unsigned long aac_build_sgraw(struct scsi_cmnd
* scsicmd
, struct sgmapraw
* psg
)
2906 unsigned long byte_count
= 0;
2909 // Get rid of old data
2911 psg
->sg
[0].next
= 0;
2912 psg
->sg
[0].prev
= 0;
2913 psg
->sg
[0].addr
[0] = 0;
2914 psg
->sg
[0].addr
[1] = 0;
2915 psg
->sg
[0].count
= 0;
2916 psg
->sg
[0].flags
= 0;
2918 nseg
= scsi_dma_map(scsicmd
);
2921 struct scatterlist
*sg
;
2924 scsi_for_each_sg(scsicmd
, sg
, nseg
, i
) {
2925 int count
= sg_dma_len(sg
);
2926 u64 addr
= sg_dma_address(sg
);
2927 psg
->sg
[i
].next
= 0;
2928 psg
->sg
[i
].prev
= 0;
2929 psg
->sg
[i
].addr
[1] = cpu_to_le32((u32
)(addr
>>32));
2930 psg
->sg
[i
].addr
[0] = cpu_to_le32((u32
)(addr
& 0xffffffff));
2931 psg
->sg
[i
].count
= cpu_to_le32(count
);
2932 psg
->sg
[i
].flags
= 0;
2933 byte_count
+= count
;
2935 psg
->count
= cpu_to_le32(nseg
);
2936 /* hba wants the size to be exact */
2937 if (byte_count
> scsi_bufflen(scsicmd
)) {
2938 u32 temp
= le32_to_cpu(psg
->sg
[i
-1].count
) -
2939 (byte_count
- scsi_bufflen(scsicmd
));
2940 psg
->sg
[i
-1].count
= cpu_to_le32(temp
);
2941 byte_count
= scsi_bufflen(scsicmd
);
2943 /* Check for command underflow */
2944 if(scsicmd
->underflow
&& (byte_count
< scsicmd
->underflow
)){
2945 printk(KERN_WARNING
"aacraid: cmd len %08lX cmd underflow %08X\n",
2946 byte_count
, scsicmd
->underflow
);
2952 #ifdef AAC_DETAILED_STATUS_INFO
2954 struct aac_srb_status_info
{
2960 static struct aac_srb_status_info srb_status_info
[] = {
2961 { SRB_STATUS_PENDING
, "Pending Status"},
2962 { SRB_STATUS_SUCCESS
, "Success"},
2963 { SRB_STATUS_ABORTED
, "Aborted Command"},
2964 { SRB_STATUS_ABORT_FAILED
, "Abort Failed"},
2965 { SRB_STATUS_ERROR
, "Error Event"},
2966 { SRB_STATUS_BUSY
, "Device Busy"},
2967 { SRB_STATUS_INVALID_REQUEST
, "Invalid Request"},
2968 { SRB_STATUS_INVALID_PATH_ID
, "Invalid Path ID"},
2969 { SRB_STATUS_NO_DEVICE
, "No Device"},
2970 { SRB_STATUS_TIMEOUT
, "Timeout"},
2971 { SRB_STATUS_SELECTION_TIMEOUT
, "Selection Timeout"},
2972 { SRB_STATUS_COMMAND_TIMEOUT
, "Command Timeout"},
2973 { SRB_STATUS_MESSAGE_REJECTED
, "Message Rejected"},
2974 { SRB_STATUS_BUS_RESET
, "Bus Reset"},
2975 { SRB_STATUS_PARITY_ERROR
, "Parity Error"},
2976 { SRB_STATUS_REQUEST_SENSE_FAILED
,"Request Sense Failed"},
2977 { SRB_STATUS_NO_HBA
, "No HBA"},
2978 { SRB_STATUS_DATA_OVERRUN
, "Data Overrun/Data Underrun"},
2979 { SRB_STATUS_UNEXPECTED_BUS_FREE
,"Unexpected Bus Free"},
2980 { SRB_STATUS_PHASE_SEQUENCE_FAILURE
,"Phase Error"},
2981 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH
,"Bad Srb Block Length"},
2982 { SRB_STATUS_REQUEST_FLUSHED
, "Request Flushed"},
2983 { SRB_STATUS_DELAYED_RETRY
, "Delayed Retry"},
2984 { SRB_STATUS_INVALID_LUN
, "Invalid LUN"},
2985 { SRB_STATUS_INVALID_TARGET_ID
, "Invalid TARGET ID"},
2986 { SRB_STATUS_BAD_FUNCTION
, "Bad Function"},
2987 { SRB_STATUS_ERROR_RECOVERY
, "Error Recovery"},
2988 { SRB_STATUS_NOT_STARTED
, "Not Started"},
2989 { SRB_STATUS_NOT_IN_USE
, "Not In Use"},
2990 { SRB_STATUS_FORCE_ABORT
, "Force Abort"},
2991 { SRB_STATUS_DOMAIN_VALIDATION_FAIL
,"Domain Validation Failure"},
2992 { 0xff, "Unknown Error"}
2995 char *aac_get_status_string(u32 status
)
2999 for (i
= 0; i
< ARRAY_SIZE(srb_status_info
); i
++)
3000 if (srb_status_info
[i
].status
== status
)
3001 return srb_status_info
[i
].str
;
3003 return "Bad Status Code";