2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 #include <linux/slab.h>
33 #include <linux/completion.h>
34 #include <linux/blkdev.h>
35 #include <asm/uaccess.h>
36 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
37 #include <linux/module.h>
39 #include <scsi/scsi.h>
40 #include <scsi/scsi_cmnd.h>
41 #include <scsi/scsi_device.h>
42 #include <scsi/scsi_host.h>
46 /* values for inqd_pdt: Peripheral device type in plain English */
47 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
48 #define INQD_PDT_PROC 0x03 /* Processor device */
49 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
50 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
51 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
52 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
54 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
55 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
61 #define SENCODE_NO_SENSE 0x00
62 #define SENCODE_END_OF_DATA 0x00
63 #define SENCODE_BECOMING_READY 0x04
64 #define SENCODE_INIT_CMD_REQUIRED 0x04
65 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
66 #define SENCODE_INVALID_COMMAND 0x20
67 #define SENCODE_LBA_OUT_OF_RANGE 0x21
68 #define SENCODE_INVALID_CDB_FIELD 0x24
69 #define SENCODE_LUN_NOT_SUPPORTED 0x25
70 #define SENCODE_INVALID_PARAM_FIELD 0x26
71 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
72 #define SENCODE_PARAM_VALUE_INVALID 0x26
73 #define SENCODE_RESET_OCCURRED 0x29
74 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
75 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
76 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
77 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
78 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
79 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
80 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
81 #define SENCODE_OVERLAPPED_COMMAND 0x4E
84 * Additional sense codes
87 #define ASENCODE_NO_SENSE 0x00
88 #define ASENCODE_END_OF_DATA 0x05
89 #define ASENCODE_BECOMING_READY 0x01
90 #define ASENCODE_INIT_CMD_REQUIRED 0x02
91 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
92 #define ASENCODE_INVALID_COMMAND 0x00
93 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
94 #define ASENCODE_INVALID_CDB_FIELD 0x00
95 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
96 #define ASENCODE_INVALID_PARAM_FIELD 0x00
97 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
98 #define ASENCODE_PARAM_VALUE_INVALID 0x02
99 #define ASENCODE_RESET_OCCURRED 0x00
100 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
101 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
102 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
103 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
104 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
105 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
106 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
107 #define ASENCODE_OVERLAPPED_COMMAND 0x00
109 #define BYTE0(x) (unsigned char)(x)
110 #define BYTE1(x) (unsigned char)((x) >> 8)
111 #define BYTE2(x) (unsigned char)((x) >> 16)
112 #define BYTE3(x) (unsigned char)((x) >> 24)
114 /*------------------------------------------------------------------------------
115 * S T R U C T S / T Y P E D E F S
116 *----------------------------------------------------------------------------*/
117 /* SCSI inquiry data */
118 struct inquiry_data {
119 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
120 u8 inqd_dtq; /* RMB | Device Type Qualifier */
121 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
122 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
123 u8 inqd_len; /* Additional length (n-4) */
124 u8 inqd_pad1[2];/* Reserved - must be zero */
125 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
126 u8 inqd_vid[8]; /* Vendor ID */
127 u8 inqd_pid[16];/* Product ID */
128 u8 inqd_prl[4]; /* Product Revision Level */
132 * M O D U L E G L O B A L S
135 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
136 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
137 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
138 static unsigned long aac_build_sgraw2(struct scsi_cmnd *scsicmd, struct aac_raw_io2 *rio2, int sg_max);
139 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new);
140 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
141 #ifdef AAC_DETAILED_STATUS_INFO
142 static char *aac_get_status_string(u32 status);
146 * Non dasd selection is handled entirely in aachba now
149 static int nondasd = -1;
150 static int aac_cache = 2; /* WCE=0 to avoid performance problems */
151 static int dacmode = -1;
154 int startup_timeout = 180;
155 int aif_timeout = 120;
156 int aac_sync_mode; /* Only Sync. transfer - disabled */
157 int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
159 module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
160 MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
162 module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
163 MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
165 module_param(nondasd, int, S_IRUGO|S_IWUSR);
166 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
168 module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
169 MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
170 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
171 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
172 "\tbit 2 - Disable only if Battery is protecting Cache");
173 module_param(dacmode, int, S_IRUGO|S_IWUSR);
174 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
176 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
177 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
178 " adapter for foreign arrays.\n"
179 "This is typically needed in systems that do not have a BIOS."
181 module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
182 MODULE_PARM_DESC(msi, "IRQ handling."
183 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
184 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
185 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
186 " adapter to have it's kernel up and\n"
187 "running. This is typically adjusted for large systems that do not"
189 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
190 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
191 " applications to pick up AIFs before\n"
192 "deregistering them. This is typically adjusted for heavily burdened"
196 module_param(numacb, int, S_IRUGO|S_IWUSR);
197 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
198 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
199 " to use suggestion from Firmware.");
202 module_param(acbsize, int, S_IRUGO|S_IWUSR);
203 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
204 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
205 " suggestion from Firmware.");
207 int update_interval = 30 * 60;
208 module_param(update_interval, int, S_IRUGO|S_IWUSR);
209 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
210 " updates issued to adapter.");
212 int check_interval = 24 * 60 * 60;
213 module_param(check_interval, int, S_IRUGO|S_IWUSR);
214 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
217 int aac_check_reset = 1;
218 module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
219 MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
220 " adapter. a value of -1 forces the reset to adapters programmed to"
223 int expose_physicals = -1;
224 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
225 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
226 " -1=protect 0=off, 1=on");
228 int aac_reset_devices;
229 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
230 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
233 module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
234 MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
236 "\t1 - Array Meta Data Signature (default)\n"
237 "\t2 - Adapter Serial Number");
240 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
241 struct fib *fibptr) {
242 struct scsi_device *device;
244 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
245 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
246 aac_fib_complete(fibptr);
247 aac_fib_free(fibptr);
250 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
251 device = scsicmd->device;
252 if (unlikely(!device || !scsi_device_online(device))) {
253 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
254 aac_fib_complete(fibptr);
255 aac_fib_free(fibptr);
262 * aac_get_config_status - check the adapter configuration
263 * @common: adapter to query
265 * Query config status, and commit the configuration if needed.
267 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
272 if (!(fibptr = aac_fib_alloc(dev)))
275 aac_fib_init(fibptr);
277 struct aac_get_config_status *dinfo;
278 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
280 dinfo->command = cpu_to_le32(VM_ContainerConfig);
281 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
282 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
285 status = aac_fib_send(ContainerCommand,
287 sizeof (struct aac_get_config_status),
292 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
294 struct aac_get_config_status_resp *reply
295 = (struct aac_get_config_status_resp *) fib_data(fibptr);
296 dprintk((KERN_WARNING
297 "aac_get_config_status: response=%d status=%d action=%d\n",
298 le32_to_cpu(reply->response),
299 le32_to_cpu(reply->status),
300 le32_to_cpu(reply->data.action)));
301 if ((le32_to_cpu(reply->response) != ST_OK) ||
302 (le32_to_cpu(reply->status) != CT_OK) ||
303 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
304 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
308 /* Do not set XferState to zero unless receives a response from F/W */
310 aac_fib_complete(fibptr);
312 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
314 if ((aac_commit == 1) || commit_flag) {
315 struct aac_commit_config * dinfo;
316 aac_fib_init(fibptr);
317 dinfo = (struct aac_commit_config *) fib_data(fibptr);
319 dinfo->command = cpu_to_le32(VM_ContainerConfig);
320 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
322 status = aac_fib_send(ContainerCommand,
324 sizeof (struct aac_commit_config),
328 /* Do not set XferState to zero unless
329 * receives a response from F/W */
331 aac_fib_complete(fibptr);
332 } else if (aac_commit == 0) {
334 "aac_get_config_status: Foreign device configurations are being ignored\n");
337 /* FIB should be freed only after getting the response from the F/W */
338 if (status != -ERESTARTSYS)
339 aac_fib_free(fibptr);
343 static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
346 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
347 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
349 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
354 * aac_get_containers - list containers
355 * @common: adapter to probe
357 * Make a list of all containers on this controller
359 int aac_get_containers(struct aac_dev *dev)
361 struct fsa_dev_info *fsa_dev_ptr;
365 struct aac_get_container_count *dinfo;
366 struct aac_get_container_count_resp *dresp;
367 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
369 if (!(fibptr = aac_fib_alloc(dev)))
372 aac_fib_init(fibptr);
373 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
374 dinfo->command = cpu_to_le32(VM_ContainerConfig);
375 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
377 status = aac_fib_send(ContainerCommand,
379 sizeof (struct aac_get_container_count),
384 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
385 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
386 aac_fib_complete(fibptr);
388 /* FIB should be freed only after getting the response from the F/W */
389 if (status != -ERESTARTSYS)
390 aac_fib_free(fibptr);
392 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
393 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
394 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
399 dev->fsa_dev = fsa_dev_ptr;
400 dev->maximum_num_containers = maximum_num_containers;
402 for (index = 0; index < dev->maximum_num_containers; ) {
403 fsa_dev_ptr[index].devname[0] = '\0';
405 status = aac_probe_container(dev, index);
408 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
413 * If there are no more containers, then stop asking.
415 if (++index >= status)
421 static void get_container_name_callback(void *context, struct fib * fibptr)
423 struct aac_get_name_resp * get_name_reply;
424 struct scsi_cmnd * scsicmd;
426 scsicmd = (struct scsi_cmnd *) context;
428 if (!aac_valid_context(scsicmd, fibptr))
431 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
432 BUG_ON(fibptr == NULL);
434 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
435 /* Failure is irrelevant, using default value instead */
436 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
437 && (get_name_reply->data[0] != '\0')) {
438 char *sp = get_name_reply->data;
439 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
443 struct inquiry_data inq;
444 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
445 int count = sizeof(d);
448 *dp++ = (*sp) ? *sp++ : ' ';
449 } while (--count > 0);
451 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
452 memcpy(inq.inqd_pid, d, sizeof(d));
453 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
457 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
459 aac_fib_complete(fibptr);
460 aac_fib_free(fibptr);
461 scsicmd->scsi_done(scsicmd);
465 * aac_get_container_name - get container name, none blocking.
467 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
470 struct aac_get_name *dinfo;
471 struct fib * cmd_fibcontext;
472 struct aac_dev * dev;
474 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
476 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
479 aac_fib_init(cmd_fibcontext);
480 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
482 dinfo->command = cpu_to_le32(VM_ContainerConfig);
483 dinfo->type = cpu_to_le32(CT_READ_NAME);
484 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
485 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
487 status = aac_fib_send(ContainerCommand,
489 sizeof (struct aac_get_name),
492 (fib_callback)get_container_name_callback,
496 * Check that the command queued to the controller
498 if (status == -EINPROGRESS) {
499 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
503 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
504 aac_fib_complete(cmd_fibcontext);
505 aac_fib_free(cmd_fibcontext);
509 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
511 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
513 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
514 return aac_scsi_cmd(scsicmd);
516 scsicmd->result = DID_NO_CONNECT << 16;
517 scsicmd->scsi_done(scsicmd);
521 static void _aac_probe_container2(void * context, struct fib * fibptr)
523 struct fsa_dev_info *fsa_dev_ptr;
524 int (*callback)(struct scsi_cmnd *);
525 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
528 if (!aac_valid_context(scsicmd, fibptr))
531 scsicmd->SCp.Status = 0;
532 fsa_dev_ptr = fibptr->dev->fsa_dev;
534 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
535 fsa_dev_ptr += scmd_id(scsicmd);
537 if ((le32_to_cpu(dresp->status) == ST_OK) &&
538 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
539 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
540 fsa_dev_ptr->valid = 1;
541 /* sense_key holds the current state of the spin-up */
542 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
543 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
544 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
545 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
546 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
548 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
549 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
550 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
552 if ((fsa_dev_ptr->valid & 1) == 0)
553 fsa_dev_ptr->valid = 0;
554 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
556 aac_fib_complete(fibptr);
557 aac_fib_free(fibptr);
558 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
559 scsicmd->SCp.ptr = NULL;
560 (*callback)(scsicmd);
564 static void _aac_probe_container1(void * context, struct fib * fibptr)
566 struct scsi_cmnd * scsicmd;
567 struct aac_mount * dresp;
568 struct aac_query_mount *dinfo;
571 dresp = (struct aac_mount *) fib_data(fibptr);
572 dresp->mnt[0].capacityhigh = 0;
573 if ((le32_to_cpu(dresp->status) != ST_OK) ||
574 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
575 _aac_probe_container2(context, fibptr);
578 scsicmd = (struct scsi_cmnd *) context;
580 if (!aac_valid_context(scsicmd, fibptr))
583 aac_fib_init(fibptr);
585 dinfo = (struct aac_query_mount *)fib_data(fibptr);
587 dinfo->command = cpu_to_le32(VM_NameServe64);
588 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
589 dinfo->type = cpu_to_le32(FT_FILESYS);
591 status = aac_fib_send(ContainerCommand,
593 sizeof(struct aac_query_mount),
596 _aac_probe_container2,
599 * Check that the command queued to the controller
601 if (status == -EINPROGRESS)
602 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
603 else if (status < 0) {
604 /* Inherit results from VM_NameServe, if any */
605 dresp->status = cpu_to_le32(ST_OK);
606 _aac_probe_container2(context, fibptr);
610 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
613 int status = -ENOMEM;
615 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
616 struct aac_query_mount *dinfo;
618 aac_fib_init(fibptr);
620 dinfo = (struct aac_query_mount *)fib_data(fibptr);
622 dinfo->command = cpu_to_le32(VM_NameServe);
623 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
624 dinfo->type = cpu_to_le32(FT_FILESYS);
625 scsicmd->SCp.ptr = (char *)callback;
627 status = aac_fib_send(ContainerCommand,
629 sizeof(struct aac_query_mount),
632 _aac_probe_container1,
635 * Check that the command queued to the controller
637 if (status == -EINPROGRESS) {
638 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
642 scsicmd->SCp.ptr = NULL;
643 aac_fib_complete(fibptr);
644 aac_fib_free(fibptr);
648 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
650 fsa_dev_ptr += scmd_id(scsicmd);
651 if ((fsa_dev_ptr->valid & 1) == 0) {
652 fsa_dev_ptr->valid = 0;
653 return (*callback)(scsicmd);
661 * aac_probe_container - query a logical volume
662 * @dev: device to query
663 * @cid: container identifier
665 * Queries the controller about the given volume. The volume information
666 * is updated in the struct fsa_dev_info structure rather than returned.
668 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
670 scsicmd->device = NULL;
674 int aac_probe_container(struct aac_dev *dev, int cid)
676 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
677 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
680 if (!scsicmd || !scsidev) {
685 scsicmd->list.next = NULL;
686 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
688 scsicmd->device = scsidev;
689 scsidev->sdev_state = 0;
691 scsidev->host = dev->scsi_host_ptr;
693 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
694 while (scsicmd->device == scsidev)
697 status = scsicmd->SCp.Status;
702 /* Local Structure to set SCSI inquiry data strings */
704 char vid[8]; /* Vendor ID */
705 char pid[16]; /* Product ID */
706 char prl[4]; /* Product Revision Level */
710 * InqStrCopy - string merge
711 * @a: string to copy from
712 * @b: string to copy to
714 * Copy a String from one location to another
718 static void inqstrcpy(char *a, char *b)
721 while (*a != (char)0)
725 static char *container_types[] = {
749 char * get_container_type(unsigned tindex)
751 if (tindex >= ARRAY_SIZE(container_types))
752 tindex = ARRAY_SIZE(container_types) - 1;
753 return container_types[tindex];
756 /* Function: setinqstr
758 * Arguments: [1] pointer to void [1] int
760 * Purpose: Sets SCSI inquiry data strings for vendor, product
761 * and revision level. Allows strings to be set in platform dependent
762 * files instead of in OS dependent driver source.
765 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
767 struct scsi_inq *str;
769 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
770 memset(str, ' ', sizeof(*str));
772 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
773 char * cp = dev->supplement_adapter_info.AdapterTypeText;
775 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
776 inqstrcpy("SMC", str->vid);
778 c = sizeof(str->vid);
779 while (*cp && *cp != ' ' && --c)
783 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
786 while (*cp && *cp != ' ')
791 /* last six chars reserved for vol type */
793 if (strlen(cp) > sizeof(str->pid)) {
794 c = cp[sizeof(str->pid)];
795 cp[sizeof(str->pid)] = '\0';
797 inqstrcpy (cp, str->pid);
799 cp[sizeof(str->pid)] = c;
801 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
803 inqstrcpy (mp->vname, str->vid);
804 /* last six chars reserved for vol type */
805 inqstrcpy (mp->model, str->pid);
808 if (tindex < ARRAY_SIZE(container_types)){
809 char *findit = str->pid;
811 for ( ; *findit != ' '; findit++); /* walk till we find a space */
812 /* RAID is superfluous in the context of a RAID device */
813 if (memcmp(findit-4, "RAID", 4) == 0)
814 *(findit -= 4) = ' ';
815 if (((findit - str->pid) + strlen(container_types[tindex]))
816 < (sizeof(str->pid) + sizeof(str->prl)))
817 inqstrcpy (container_types[tindex], findit + 1);
819 inqstrcpy ("V1.0", str->prl);
822 static void get_container_serial_callback(void *context, struct fib * fibptr)
824 struct aac_get_serial_resp * get_serial_reply;
825 struct scsi_cmnd * scsicmd;
827 BUG_ON(fibptr == NULL);
829 scsicmd = (struct scsi_cmnd *) context;
830 if (!aac_valid_context(scsicmd, fibptr))
833 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
834 /* Failure is irrelevant, using default value instead */
835 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
839 sp[1] = scsicmd->cmnd[2];
841 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
842 le32_to_cpu(get_serial_reply->uid));
843 scsi_sg_copy_from_buffer(scsicmd, sp, sizeof(sp));
846 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
848 aac_fib_complete(fibptr);
849 aac_fib_free(fibptr);
850 scsicmd->scsi_done(scsicmd);
854 * aac_get_container_serial - get container serial, none blocking.
856 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
859 struct aac_get_serial *dinfo;
860 struct fib * cmd_fibcontext;
861 struct aac_dev * dev;
863 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
865 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
868 aac_fib_init(cmd_fibcontext);
869 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
871 dinfo->command = cpu_to_le32(VM_ContainerConfig);
872 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
873 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
875 status = aac_fib_send(ContainerCommand,
877 sizeof (struct aac_get_serial),
880 (fib_callback) get_container_serial_callback,
884 * Check that the command queued to the controller
886 if (status == -EINPROGRESS) {
887 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
891 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
892 aac_fib_complete(cmd_fibcontext);
893 aac_fib_free(cmd_fibcontext);
897 /* Function: setinqserial
899 * Arguments: [1] pointer to void [1] int
901 * Purpose: Sets SCSI Unit Serial number.
902 * This is a fake. We should read a proper
903 * serial number from the container. <SuSE>But
904 * without docs it's quite hard to do it :-)
905 * So this will have to do in the meantime.</SuSE>
908 static int setinqserial(struct aac_dev *dev, void *data, int cid)
911 * This breaks array migration.
913 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
914 le32_to_cpu(dev->adapter_info.serial[0]), cid);
917 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
918 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
920 u8 *sense_buf = (u8 *)sense_data;
921 /* Sense data valid, err code 70h */
922 sense_buf[0] = 0x70; /* No info field */
923 sense_buf[1] = 0; /* Segment number, always zero */
925 sense_buf[2] = sense_key; /* Sense key */
927 sense_buf[12] = sense_code; /* Additional sense code */
928 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
930 if (sense_key == ILLEGAL_REQUEST) {
931 sense_buf[7] = 10; /* Additional sense length */
933 sense_buf[15] = bit_pointer;
934 /* Illegal parameter is in the parameter block */
935 if (sense_code == SENCODE_INVALID_CDB_FIELD)
936 sense_buf[15] |= 0xc0;/* Std sense key specific field */
937 /* Illegal parameter is in the CDB block */
938 sense_buf[16] = field_pointer >> 8; /* MSB */
939 sense_buf[17] = field_pointer; /* LSB */
941 sense_buf[7] = 6; /* Additional sense length */
944 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
946 if (lba & 0xffffffff00000000LL) {
947 int cid = scmd_id(cmd);
948 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
949 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
950 SAM_STAT_CHECK_CONDITION;
951 set_sense(&dev->fsa_dev[cid].sense_data,
952 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
953 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
954 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
955 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
956 SCSI_SENSE_BUFFERSIZE));
963 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
968 static void io_callback(void *context, struct fib * fibptr);
970 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
972 struct aac_dev *dev = fib->dev;
973 u16 fibsize, command;
976 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
977 struct aac_raw_io2 *readcmd2;
978 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
979 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
980 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
981 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
982 readcmd2->byteCount = cpu_to_le32(count<<9);
983 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
984 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
985 aac_build_sgraw2(cmd, readcmd2, dev->scsi_host_ptr->sg_tablesize);
986 command = ContainerRawIo2;
987 fibsize = sizeof(struct aac_raw_io2) +
988 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
990 struct aac_raw_io *readcmd;
991 readcmd = (struct aac_raw_io *) fib_data(fib);
992 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
993 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
994 readcmd->count = cpu_to_le32(count<<9);
995 readcmd->cid = cpu_to_le16(scmd_id(cmd));
996 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
997 readcmd->bpTotal = 0;
998 readcmd->bpComplete = 0;
999 aac_build_sgraw(cmd, &readcmd->sg);
1000 command = ContainerRawIo;
1001 fibsize = sizeof(struct aac_raw_io) +
1002 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1005 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1007 * Now send the Fib to the adapter
1009 return aac_fib_send(command,
1014 (fib_callback) io_callback,
1018 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1021 struct aac_read64 *readcmd;
1023 readcmd = (struct aac_read64 *) fib_data(fib);
1024 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1025 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1026 readcmd->sector_count = cpu_to_le16(count);
1027 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1031 aac_build_sg64(cmd, &readcmd->sg);
1032 fibsize = sizeof(struct aac_read64) +
1033 ((le32_to_cpu(readcmd->sg.count) - 1) *
1034 sizeof (struct sgentry64));
1035 BUG_ON (fibsize > (fib->dev->max_fib_size -
1036 sizeof(struct aac_fibhdr)));
1038 * Now send the Fib to the adapter
1040 return aac_fib_send(ContainerCommand64,
1045 (fib_callback) io_callback,
1049 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1052 struct aac_read *readcmd;
1054 readcmd = (struct aac_read *) fib_data(fib);
1055 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1056 readcmd->cid = cpu_to_le32(scmd_id(cmd));
1057 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1058 readcmd->count = cpu_to_le32(count * 512);
1060 aac_build_sg(cmd, &readcmd->sg);
1061 fibsize = sizeof(struct aac_read) +
1062 ((le32_to_cpu(readcmd->sg.count) - 1) *
1063 sizeof (struct sgentry));
1064 BUG_ON (fibsize > (fib->dev->max_fib_size -
1065 sizeof(struct aac_fibhdr)));
1067 * Now send the Fib to the adapter
1069 return aac_fib_send(ContainerCommand,
1074 (fib_callback) io_callback,
1078 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1080 struct aac_dev *dev = fib->dev;
1081 u16 fibsize, command;
1084 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1085 struct aac_raw_io2 *writecmd2;
1086 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1087 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1088 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1089 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1090 writecmd2->byteCount = cpu_to_le32(count<<9);
1091 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1092 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1093 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1094 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1095 cpu_to_le16(RIO2_IO_TYPE_WRITE);
1096 aac_build_sgraw2(cmd, writecmd2, dev->scsi_host_ptr->sg_tablesize);
1097 command = ContainerRawIo2;
1098 fibsize = sizeof(struct aac_raw_io2) +
1099 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1101 struct aac_raw_io *writecmd;
1102 writecmd = (struct aac_raw_io *) fib_data(fib);
1103 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1104 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1105 writecmd->count = cpu_to_le32(count<<9);
1106 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1107 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1108 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1109 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1110 cpu_to_le16(RIO_TYPE_WRITE);
1111 writecmd->bpTotal = 0;
1112 writecmd->bpComplete = 0;
1113 aac_build_sgraw(cmd, &writecmd->sg);
1114 command = ContainerRawIo;
1115 fibsize = sizeof(struct aac_raw_io) +
1116 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1119 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1121 * Now send the Fib to the adapter
1123 return aac_fib_send(command,
1128 (fib_callback) io_callback,
1132 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1135 struct aac_write64 *writecmd;
1137 writecmd = (struct aac_write64 *) fib_data(fib);
1138 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1139 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1140 writecmd->sector_count = cpu_to_le16(count);
1141 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1143 writecmd->flags = 0;
1145 aac_build_sg64(cmd, &writecmd->sg);
1146 fibsize = sizeof(struct aac_write64) +
1147 ((le32_to_cpu(writecmd->sg.count) - 1) *
1148 sizeof (struct sgentry64));
1149 BUG_ON (fibsize > (fib->dev->max_fib_size -
1150 sizeof(struct aac_fibhdr)));
1152 * Now send the Fib to the adapter
1154 return aac_fib_send(ContainerCommand64,
1159 (fib_callback) io_callback,
1163 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1166 struct aac_write *writecmd;
1168 writecmd = (struct aac_write *) fib_data(fib);
1169 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1170 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1171 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1172 writecmd->count = cpu_to_le32(count * 512);
1173 writecmd->sg.count = cpu_to_le32(1);
1174 /* ->stable is not used - it did mean which type of write */
1176 aac_build_sg(cmd, &writecmd->sg);
1177 fibsize = sizeof(struct aac_write) +
1178 ((le32_to_cpu(writecmd->sg.count) - 1) *
1179 sizeof (struct sgentry));
1180 BUG_ON (fibsize > (fib->dev->max_fib_size -
1181 sizeof(struct aac_fibhdr)));
1183 * Now send the Fib to the adapter
1185 return aac_fib_send(ContainerCommand,
1190 (fib_callback) io_callback,
1194 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1196 struct aac_srb * srbcmd;
1201 switch(cmd->sc_data_direction){
1205 case DMA_BIDIRECTIONAL:
1206 flag = SRB_DataIn | SRB_DataOut;
1208 case DMA_FROM_DEVICE:
1212 default: /* shuts up some versions of gcc */
1213 flag = SRB_NoDataXfer;
1217 srbcmd = (struct aac_srb*) fib_data(fib);
1218 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1219 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1220 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1221 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1222 srbcmd->flags = cpu_to_le32(flag);
1223 timeout = cmd->request->timeout/HZ;
1226 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1227 srbcmd->retry_limit = 0; /* Obsolete parameter */
1228 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1232 static void aac_srb_callback(void *context, struct fib * fibptr);
1234 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1237 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1239 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
1240 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1242 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1243 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1245 * Build Scatter/Gather list
1247 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1248 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1249 sizeof (struct sgentry64));
1250 BUG_ON (fibsize > (fib->dev->max_fib_size -
1251 sizeof(struct aac_fibhdr)));
1254 * Now send the Fib to the adapter
1256 return aac_fib_send(ScsiPortCommand64, fib,
1257 fibsize, FsaNormal, 0, 1,
1258 (fib_callback) aac_srb_callback,
1262 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1265 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1267 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
1268 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1270 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1271 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1273 * Build Scatter/Gather list
1275 fibsize = sizeof (struct aac_srb) +
1276 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1277 sizeof (struct sgentry));
1278 BUG_ON (fibsize > (fib->dev->max_fib_size -
1279 sizeof(struct aac_fibhdr)));
1282 * Now send the Fib to the adapter
1284 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1285 (fib_callback) aac_srb_callback, (void *) cmd);
1288 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1290 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1291 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1293 return aac_scsi_32(fib, cmd);
1296 int aac_get_adapter_info(struct aac_dev* dev)
1301 struct aac_adapter_info *info;
1302 struct aac_bus_info *command;
1303 struct aac_bus_info_response *bus_info;
1305 if (!(fibptr = aac_fib_alloc(dev)))
1308 aac_fib_init(fibptr);
1309 info = (struct aac_adapter_info *) fib_data(fibptr);
1310 memset(info,0,sizeof(*info));
1312 rcode = aac_fib_send(RequestAdapterInfo,
1316 -1, 1, /* First `interrupt' command uses special wait */
1321 /* FIB should be freed only after
1322 * getting the response from the F/W */
1323 if (rcode != -ERESTARTSYS) {
1324 aac_fib_complete(fibptr);
1325 aac_fib_free(fibptr);
1329 memcpy(&dev->adapter_info, info, sizeof(*info));
1331 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1332 struct aac_supplement_adapter_info * sinfo;
1334 aac_fib_init(fibptr);
1336 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1338 memset(sinfo,0,sizeof(*sinfo));
1340 rcode = aac_fib_send(RequestSupplementAdapterInfo,
1349 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
1350 if (rcode == -ERESTARTSYS) {
1351 fibptr = aac_fib_alloc(dev);
1363 aac_fib_init(fibptr);
1365 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1367 memset(bus_info, 0, sizeof(*bus_info));
1369 command = (struct aac_bus_info *)bus_info;
1371 command->Command = cpu_to_le32(VM_Ioctl);
1372 command->ObjType = cpu_to_le32(FT_DRIVE);
1373 command->MethodId = cpu_to_le32(1);
1374 command->CtlCmd = cpu_to_le32(GetBusInfo);
1376 rcode = aac_fib_send(ContainerCommand,
1383 /* reasoned default */
1384 dev->maximum_num_physicals = 16;
1385 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1386 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1387 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1390 if (!dev->in_reset) {
1392 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1393 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
1399 le32_to_cpu(dev->adapter_info.kernelbuild),
1400 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1401 dev->supplement_adapter_info.BuildDate);
1402 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1403 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
1405 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1406 le32_to_cpu(dev->adapter_info.monitorbuild));
1407 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1408 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
1410 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1411 le32_to_cpu(dev->adapter_info.biosbuild));
1413 if (aac_get_serial_number(
1414 shost_to_class(dev->scsi_host_ptr), buffer))
1415 printk(KERN_INFO "%s%d: serial %s",
1416 dev->name, dev->id, buffer);
1417 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1418 printk(KERN_INFO "%s%d: TSID %.*s\n",
1420 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1421 dev->supplement_adapter_info.VpdInfo.Tsid);
1423 if (!aac_check_reset || ((aac_check_reset == 1) &&
1424 (dev->supplement_adapter_info.SupportedOptions2 &
1425 AAC_OPTION_IGNORE_RESET))) {
1426 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1427 dev->name, dev->id);
1431 dev->cache_protected = 0;
1432 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1433 AAC_FEATURE_JBOD) != 0);
1434 dev->nondasd_support = 0;
1435 dev->raid_scsi_mode = 0;
1436 if(dev->adapter_info.options & AAC_OPT_NONDASD)
1437 dev->nondasd_support = 1;
1440 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1441 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1442 * force nondasd support on. If we decide to allow the non-dasd flag
1443 * additional changes changes will have to be made to support
1444 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1445 * changed to support the new dev->raid_scsi_mode flag instead of
1446 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1447 * function aac_detect will have to be modified where it sets up the
1448 * max number of channels based on the aac->nondasd_support flag only.
1450 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1451 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1452 dev->nondasd_support = 1;
1453 dev->raid_scsi_mode = 1;
1455 if (dev->raid_scsi_mode != 0)
1456 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1457 dev->name, dev->id);
1460 dev->nondasd_support = (nondasd!=0);
1461 if (dev->nondasd_support && !dev->in_reset)
1462 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1464 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
1466 dev->dac_support = 0;
1467 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
1468 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
1470 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
1471 dev->name, dev->id);
1472 dev->dac_support = 1;
1476 dev->dac_support = (dacmode!=0);
1479 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1480 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
1481 & AAC_QUIRK_SCSI_32)) {
1482 dev->nondasd_support = 0;
1484 expose_physicals = 0;
1487 if(dev->dac_support != 0) {
1488 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64)) &&
1489 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
1491 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1492 dev->name, dev->id);
1493 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32)) &&
1494 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
1495 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1496 dev->name, dev->id);
1497 dev->dac_support = 0;
1499 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1500 dev->name, dev->id);
1505 * Deal with configuring for the individualized limits of each packet
1508 dev->a_ops.adapter_scsi = (dev->dac_support)
1509 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1513 if (dev->raw_io_interface) {
1514 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1517 dev->a_ops.adapter_read = aac_read_raw_io;
1518 dev->a_ops.adapter_write = aac_write_raw_io;
1520 dev->a_ops.adapter_bounds = aac_bounds_32;
1521 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
1522 sizeof(struct aac_fibhdr) -
1523 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1524 sizeof(struct sgentry);
1525 if (dev->dac_support) {
1526 dev->a_ops.adapter_read = aac_read_block64;
1527 dev->a_ops.adapter_write = aac_write_block64;
1529 * 38 scatter gather elements
1531 dev->scsi_host_ptr->sg_tablesize =
1532 (dev->max_fib_size -
1533 sizeof(struct aac_fibhdr) -
1534 sizeof(struct aac_write64) +
1535 sizeof(struct sgentry64)) /
1536 sizeof(struct sgentry64);
1538 dev->a_ops.adapter_read = aac_read_block;
1539 dev->a_ops.adapter_write = aac_write_block;
1541 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1542 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1544 * Worst case size that could cause sg overflow when
1545 * we break up SG elements that are larger than 64KB.
1546 * Would be nice if we could tell the SCSI layer what
1547 * the maximum SG element size can be. Worst case is
1548 * (sg_tablesize-1) 4KB elements with one 64KB
1550 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1552 dev->scsi_host_ptr->max_sectors =
1553 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1556 /* FIB should be freed only after getting the response from the F/W */
1557 if (rcode != -ERESTARTSYS) {
1558 aac_fib_complete(fibptr);
1559 aac_fib_free(fibptr);
1566 static void io_callback(void *context, struct fib * fibptr)
1568 struct aac_dev *dev;
1569 struct aac_read_reply *readreply;
1570 struct scsi_cmnd *scsicmd;
1573 scsicmd = (struct scsi_cmnd *) context;
1575 if (!aac_valid_context(scsicmd, fibptr))
1579 cid = scmd_id(scsicmd);
1581 if (nblank(dprintk(x))) {
1583 switch (scsicmd->cmnd[0]) {
1586 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1587 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1591 lba = ((u64)scsicmd->cmnd[2] << 56) |
1592 ((u64)scsicmd->cmnd[3] << 48) |
1593 ((u64)scsicmd->cmnd[4] << 40) |
1594 ((u64)scsicmd->cmnd[5] << 32) |
1595 ((u64)scsicmd->cmnd[6] << 24) |
1596 (scsicmd->cmnd[7] << 16) |
1597 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1601 lba = ((u64)scsicmd->cmnd[2] << 24) |
1602 (scsicmd->cmnd[3] << 16) |
1603 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1606 lba = ((u64)scsicmd->cmnd[2] << 24) |
1607 (scsicmd->cmnd[3] << 16) |
1608 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1612 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1613 smp_processor_id(), (unsigned long long)lba, jiffies);
1616 BUG_ON(fibptr == NULL);
1618 scsi_dma_unmap(scsicmd);
1620 readreply = (struct aac_read_reply *)fib_data(fibptr);
1621 switch (le32_to_cpu(readreply->status)) {
1623 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1625 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
1628 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1629 SAM_STAT_CHECK_CONDITION;
1630 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
1631 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
1632 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1633 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1634 SCSI_SENSE_BUFFERSIZE));
1637 #ifdef AAC_DETAILED_STATUS_INFO
1638 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1639 le32_to_cpu(readreply->status));
1641 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1642 SAM_STAT_CHECK_CONDITION;
1643 set_sense(&dev->fsa_dev[cid].sense_data,
1644 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1645 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1646 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1647 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1648 SCSI_SENSE_BUFFERSIZE));
1651 aac_fib_complete(fibptr);
1652 aac_fib_free(fibptr);
1654 scsicmd->scsi_done(scsicmd);
1657 static int aac_read(struct scsi_cmnd * scsicmd)
1662 struct aac_dev *dev;
1663 struct fib * cmd_fibcontext;
1666 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1668 * Get block address and transfer length
1670 switch (scsicmd->cmnd[0]) {
1672 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
1674 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1675 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1676 count = scsicmd->cmnd[4];
1682 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
1684 lba = ((u64)scsicmd->cmnd[2] << 56) |
1685 ((u64)scsicmd->cmnd[3] << 48) |
1686 ((u64)scsicmd->cmnd[4] << 40) |
1687 ((u64)scsicmd->cmnd[5] << 32) |
1688 ((u64)scsicmd->cmnd[6] << 24) |
1689 (scsicmd->cmnd[7] << 16) |
1690 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1691 count = (scsicmd->cmnd[10] << 24) |
1692 (scsicmd->cmnd[11] << 16) |
1693 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1696 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
1698 lba = ((u64)scsicmd->cmnd[2] << 24) |
1699 (scsicmd->cmnd[3] << 16) |
1700 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1701 count = (scsicmd->cmnd[6] << 24) |
1702 (scsicmd->cmnd[7] << 16) |
1703 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1706 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
1708 lba = ((u64)scsicmd->cmnd[2] << 24) |
1709 (scsicmd->cmnd[3] << 16) |
1710 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1711 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1715 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1716 cid = scmd_id(scsicmd);
1717 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1718 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1719 SAM_STAT_CHECK_CONDITION;
1720 set_sense(&dev->fsa_dev[cid].sense_data,
1721 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1722 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1723 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1724 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1725 SCSI_SENSE_BUFFERSIZE));
1726 scsicmd->scsi_done(scsicmd);
1730 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1731 smp_processor_id(), (unsigned long long)lba, jiffies));
1732 if (aac_adapter_bounds(dev,scsicmd,lba))
1735 * Alocate and initialize a Fib
1737 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1738 printk(KERN_WARNING "aac_read: fib allocation failed\n");
1742 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1745 * Check that the command queued to the controller
1747 if (status == -EINPROGRESS) {
1748 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1752 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1754 * For some reason, the Fib didn't queue, return QUEUE_FULL
1756 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1757 scsicmd->scsi_done(scsicmd);
1758 aac_fib_complete(cmd_fibcontext);
1759 aac_fib_free(cmd_fibcontext);
1763 static int aac_write(struct scsi_cmnd * scsicmd)
1769 struct aac_dev *dev;
1770 struct fib * cmd_fibcontext;
1773 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1775 * Get block address and transfer length
1777 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1779 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1780 count = scsicmd->cmnd[4];
1784 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
1785 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
1787 lba = ((u64)scsicmd->cmnd[2] << 56) |
1788 ((u64)scsicmd->cmnd[3] << 48) |
1789 ((u64)scsicmd->cmnd[4] << 40) |
1790 ((u64)scsicmd->cmnd[5] << 32) |
1791 ((u64)scsicmd->cmnd[6] << 24) |
1792 (scsicmd->cmnd[7] << 16) |
1793 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1794 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1795 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1796 fua = scsicmd->cmnd[1] & 0x8;
1797 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
1798 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
1800 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1801 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1802 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1803 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1804 fua = scsicmd->cmnd[1] & 0x8;
1806 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
1807 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1808 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1809 fua = scsicmd->cmnd[1] & 0x8;
1812 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1813 cid = scmd_id(scsicmd);
1814 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1815 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1816 SAM_STAT_CHECK_CONDITION;
1817 set_sense(&dev->fsa_dev[cid].sense_data,
1818 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1819 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1820 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1821 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1822 SCSI_SENSE_BUFFERSIZE));
1823 scsicmd->scsi_done(scsicmd);
1827 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1828 smp_processor_id(), (unsigned long long)lba, jiffies));
1829 if (aac_adapter_bounds(dev,scsicmd,lba))
1832 * Allocate and initialize a Fib then setup a BlockWrite command
1834 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
1835 /* FIB temporarily unavailable,not catastrophic failure */
1837 /* scsicmd->result = DID_ERROR << 16;
1838 * scsicmd->scsi_done(scsicmd);
1841 printk(KERN_WARNING "aac_write: fib allocation failed\n");
1845 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
1848 * Check that the command queued to the controller
1850 if (status == -EINPROGRESS) {
1851 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1855 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
1857 * For some reason, the Fib didn't queue, return QUEUE_FULL
1859 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
1860 scsicmd->scsi_done(scsicmd);
1862 aac_fib_complete(cmd_fibcontext);
1863 aac_fib_free(cmd_fibcontext);
1867 static void synchronize_callback(void *context, struct fib *fibptr)
1869 struct aac_synchronize_reply *synchronizereply;
1870 struct scsi_cmnd *cmd;
1874 if (!aac_valid_context(cmd, fibptr))
1877 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1878 smp_processor_id(), jiffies));
1879 BUG_ON(fibptr == NULL);
1882 synchronizereply = fib_data(fibptr);
1883 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1884 cmd->result = DID_OK << 16 |
1885 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1887 struct scsi_device *sdev = cmd->device;
1888 struct aac_dev *dev = fibptr->dev;
1889 u32 cid = sdev_id(sdev);
1891 "synchronize_callback: synchronize failed, status = %d\n",
1892 le32_to_cpu(synchronizereply->status));
1893 cmd->result = DID_OK << 16 |
1894 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1895 set_sense(&dev->fsa_dev[cid].sense_data,
1896 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1897 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1898 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1899 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1900 SCSI_SENSE_BUFFERSIZE));
1903 aac_fib_complete(fibptr);
1904 aac_fib_free(fibptr);
1905 cmd->scsi_done(cmd);
1908 static int aac_synchronize(struct scsi_cmnd *scsicmd)
1911 struct fib *cmd_fibcontext;
1912 struct aac_synchronize *synchronizecmd;
1913 struct scsi_cmnd *cmd;
1914 struct scsi_device *sdev = scsicmd->device;
1916 struct aac_dev *aac;
1917 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1918 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1919 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
1920 unsigned long flags;
1923 * Wait for all outstanding queued commands to complete to this
1924 * specific target (block).
1926 spin_lock_irqsave(&sdev->list_lock, flags);
1927 list_for_each_entry(cmd, &sdev->cmd_list, list)
1928 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1932 if (cmd->cmnd[0] == WRITE_6) {
1933 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1934 (cmd->cmnd[2] << 8) |
1936 cmnd_count = cmd->cmnd[4];
1937 if (cmnd_count == 0)
1939 } else if (cmd->cmnd[0] == WRITE_16) {
1940 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1941 ((u64)cmd->cmnd[3] << 48) |
1942 ((u64)cmd->cmnd[4] << 40) |
1943 ((u64)cmd->cmnd[5] << 32) |
1944 ((u64)cmd->cmnd[6] << 24) |
1945 (cmd->cmnd[7] << 16) |
1946 (cmd->cmnd[8] << 8) |
1948 cmnd_count = (cmd->cmnd[10] << 24) |
1949 (cmd->cmnd[11] << 16) |
1950 (cmd->cmnd[12] << 8) |
1952 } else if (cmd->cmnd[0] == WRITE_12) {
1953 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1954 (cmd->cmnd[3] << 16) |
1955 (cmd->cmnd[4] << 8) |
1957 cmnd_count = (cmd->cmnd[6] << 24) |
1958 (cmd->cmnd[7] << 16) |
1959 (cmd->cmnd[8] << 8) |
1961 } else if (cmd->cmnd[0] == WRITE_10) {
1962 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1963 (cmd->cmnd[3] << 16) |
1964 (cmd->cmnd[4] << 8) |
1966 cmnd_count = (cmd->cmnd[7] << 8) |
1970 if (((cmnd_lba + cmnd_count) < lba) ||
1971 (count && ((lba + count) < cmnd_lba)))
1977 spin_unlock_irqrestore(&sdev->list_lock, flags);
1980 * Yield the processor (requeue for later)
1983 return SCSI_MLQUEUE_DEVICE_BUSY;
1985 aac = (struct aac_dev *)sdev->host->hostdata;
1987 return SCSI_MLQUEUE_HOST_BUSY;
1990 * Allocate and initialize a Fib
1992 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
1993 return SCSI_MLQUEUE_HOST_BUSY;
1995 aac_fib_init(cmd_fibcontext);
1997 synchronizecmd = fib_data(cmd_fibcontext);
1998 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1999 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
2000 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
2001 synchronizecmd->count =
2002 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2005 * Now send the Fib to the adapter
2007 status = aac_fib_send(ContainerCommand,
2009 sizeof(struct aac_synchronize),
2012 (fib_callback)synchronize_callback,
2016 * Check that the command queued to the controller
2018 if (status == -EINPROGRESS) {
2019 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2024 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2025 aac_fib_complete(cmd_fibcontext);
2026 aac_fib_free(cmd_fibcontext);
2027 return SCSI_MLQUEUE_HOST_BUSY;
2030 static void aac_start_stop_callback(void *context, struct fib *fibptr)
2032 struct scsi_cmnd *scsicmd = context;
2034 if (!aac_valid_context(scsicmd, fibptr))
2037 BUG_ON(fibptr == NULL);
2039 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2041 aac_fib_complete(fibptr);
2042 aac_fib_free(fibptr);
2043 scsicmd->scsi_done(scsicmd);
2046 static int aac_start_stop(struct scsi_cmnd *scsicmd)
2049 struct fib *cmd_fibcontext;
2050 struct aac_power_management *pmcmd;
2051 struct scsi_device *sdev = scsicmd->device;
2052 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2054 if (!(aac->supplement_adapter_info.SupportedOptions2 &
2055 AAC_OPTION_POWER_MANAGEMENT)) {
2056 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2058 scsicmd->scsi_done(scsicmd);
2063 return SCSI_MLQUEUE_HOST_BUSY;
2066 * Allocate and initialize a Fib
2068 cmd_fibcontext = aac_fib_alloc(aac);
2069 if (!cmd_fibcontext)
2070 return SCSI_MLQUEUE_HOST_BUSY;
2072 aac_fib_init(cmd_fibcontext);
2074 pmcmd = fib_data(cmd_fibcontext);
2075 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2076 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2077 /* Eject bit ignored, not relevant */
2078 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2079 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2080 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2081 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2082 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2085 * Now send the Fib to the adapter
2087 status = aac_fib_send(ContainerCommand,
2089 sizeof(struct aac_power_management),
2092 (fib_callback)aac_start_stop_callback,
2096 * Check that the command queued to the controller
2098 if (status == -EINPROGRESS) {
2099 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2103 aac_fib_complete(cmd_fibcontext);
2104 aac_fib_free(cmd_fibcontext);
2105 return SCSI_MLQUEUE_HOST_BUSY;
2109 * aac_scsi_cmd() - Process SCSI command
2110 * @scsicmd: SCSI command block
2112 * Emulate a SCSI command and queue the required request for the
2116 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2119 struct Scsi_Host *host = scsicmd->device->host;
2120 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2121 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
2123 if (fsa_dev_ptr == NULL)
2126 * If the bus, id or lun is out of range, return fail
2127 * Test does not apply to ID 16, the pseudo id for the controller
2130 cid = scmd_id(scsicmd);
2131 if (cid != host->this_id) {
2132 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2133 if((cid >= dev->maximum_num_containers) ||
2134 (scsicmd->device->lun != 0)) {
2135 scsicmd->result = DID_NO_CONNECT << 16;
2136 scsicmd->scsi_done(scsicmd);
2141 * If the target container doesn't exist, it may have
2142 * been newly created
2144 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2145 (fsa_dev_ptr[cid].sense_data.sense_key ==
2147 switch (scsicmd->cmnd[0]) {
2148 case SERVICE_ACTION_IN:
2149 if (!(dev->raw_io_interface) ||
2150 !(dev->raw_io_64) ||
2151 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2155 case TEST_UNIT_READY:
2158 return _aac_probe_container(scsicmd,
2159 aac_probe_container_callback2);
2164 } else { /* check for physical non-dasd devices */
2165 if (dev->nondasd_support || expose_physicals ||
2169 return aac_send_srb_fib(scsicmd);
2171 scsicmd->result = DID_NO_CONNECT << 16;
2172 scsicmd->scsi_done(scsicmd);
2178 * else Command for the controller itself
2180 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
2181 (scsicmd->cmnd[0] != TEST_UNIT_READY))
2183 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2184 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2185 set_sense(&dev->fsa_dev[cid].sense_data,
2186 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2187 ASENCODE_INVALID_COMMAND, 0, 0);
2188 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2189 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2190 SCSI_SENSE_BUFFERSIZE));
2191 scsicmd->scsi_done(scsicmd);
2196 /* Handle commands here that don't really require going out to the adapter */
2197 switch (scsicmd->cmnd[0]) {
2200 struct inquiry_data inq_data;
2202 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
2203 memset(&inq_data, 0, sizeof (struct inquiry_data));
2205 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
2206 char *arr = (char *)&inq_data;
2209 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2210 INQD_PDT_PROC : INQD_PDT_DA;
2211 if (scsicmd->cmnd[2] == 0) {
2212 /* supported vital product data pages */
2216 arr[1] = scsicmd->cmnd[2];
2217 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2219 scsicmd->result = DID_OK << 16 |
2220 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2221 } else if (scsicmd->cmnd[2] == 0x80) {
2222 /* unit serial number page */
2223 arr[3] = setinqserial(dev, &arr[4],
2225 arr[1] = scsicmd->cmnd[2];
2226 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2229 return aac_get_container_serial(
2231 /* SLES 10 SP1 special */
2232 scsicmd->result = DID_OK << 16 |
2233 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2235 /* vpd page not implemented */
2236 scsicmd->result = DID_OK << 16 |
2237 COMMAND_COMPLETE << 8 |
2238 SAM_STAT_CHECK_CONDITION;
2239 set_sense(&dev->fsa_dev[cid].sense_data,
2240 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2241 ASENCODE_NO_SENSE, 7, 2);
2242 memcpy(scsicmd->sense_buffer,
2243 &dev->fsa_dev[cid].sense_data,
2245 sizeof(dev->fsa_dev[cid].sense_data),
2246 SCSI_SENSE_BUFFERSIZE));
2248 scsicmd->scsi_done(scsicmd);
2251 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
2252 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 */
2253 inq_data.inqd_len = 31;
2254 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2255 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
2257 * Set the Vendor, Product, and Revision Level
2258 * see: <vendor>.c i.e. aac.c
2260 if (cid == host->this_id) {
2261 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
2262 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2263 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2265 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2266 scsicmd->scsi_done(scsicmd);
2271 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2272 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2273 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
2274 return aac_get_container_name(scsicmd);
2276 case SERVICE_ACTION_IN:
2277 if (!(dev->raw_io_interface) ||
2278 !(dev->raw_io_64) ||
2279 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2284 unsigned int alloc_len;
2286 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2287 capacity = fsa_dev_ptr[cid].size - 1;
2288 cp[0] = (capacity >> 56) & 0xff;
2289 cp[1] = (capacity >> 48) & 0xff;
2290 cp[2] = (capacity >> 40) & 0xff;
2291 cp[3] = (capacity >> 32) & 0xff;
2292 cp[4] = (capacity >> 24) & 0xff;
2293 cp[5] = (capacity >> 16) & 0xff;
2294 cp[6] = (capacity >> 8) & 0xff;
2295 cp[7] = (capacity >> 0) & 0xff;
2302 alloc_len = ((scsicmd->cmnd[10] << 24)
2303 + (scsicmd->cmnd[11] << 16)
2304 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2306 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
2307 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
2308 if (alloc_len < scsi_bufflen(scsicmd))
2309 scsi_set_resid(scsicmd,
2310 scsi_bufflen(scsicmd) - alloc_len);
2312 /* Do not cache partition table for arrays */
2313 scsicmd->device->removable = 1;
2315 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2316 scsicmd->scsi_done(scsicmd);
2326 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
2327 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2328 capacity = fsa_dev_ptr[cid].size - 1;
2332 cp[0] = (capacity >> 24) & 0xff;
2333 cp[1] = (capacity >> 16) & 0xff;
2334 cp[2] = (capacity >> 8) & 0xff;
2335 cp[3] = (capacity >> 0) & 0xff;
2340 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
2341 /* Do not cache partition table for arrays */
2342 scsicmd->device->removable = 1;
2343 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2345 scsicmd->scsi_done(scsicmd);
2353 int mode_buf_length = 4;
2355 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
2356 mode_buf[0] = 3; /* Mode data length */
2357 mode_buf[1] = 0; /* Medium type - default */
2358 mode_buf[2] = 0; /* Device-specific param,
2359 bit 8: 0/1 = write enabled/protected
2360 bit 4: 0/1 = FUA enabled */
2361 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2363 mode_buf[3] = 0; /* Block descriptor length */
2364 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2365 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2369 mode_buf[6] = ((aac_cache & 6) == 2)
2370 ? 0 : 0x04; /* WCE */
2371 mode_buf_length = 7;
2372 if (mode_buf_length > scsicmd->cmnd[4])
2373 mode_buf_length = scsicmd->cmnd[4];
2375 scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
2376 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2377 scsicmd->scsi_done(scsicmd);
2384 int mode_buf_length = 8;
2386 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
2387 mode_buf[0] = 0; /* Mode data length (MSB) */
2388 mode_buf[1] = 6; /* Mode data length (LSB) */
2389 mode_buf[2] = 0; /* Medium type - default */
2390 mode_buf[3] = 0; /* Device-specific param,
2391 bit 8: 0/1 = write enabled/protected
2392 bit 4: 0/1 = FUA enabled */
2393 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
2395 mode_buf[4] = 0; /* reserved */
2396 mode_buf[5] = 0; /* reserved */
2397 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2398 mode_buf[7] = 0; /* Block descriptor length (LSB) */
2399 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2400 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2404 mode_buf[10] = ((aac_cache & 6) == 2)
2405 ? 0 : 0x04; /* WCE */
2406 mode_buf_length = 11;
2407 if (mode_buf_length > scsicmd->cmnd[8])
2408 mode_buf_length = scsicmd->cmnd[8];
2410 scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
2412 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2413 scsicmd->scsi_done(scsicmd);
2418 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2419 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2420 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2421 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2422 scsicmd->scsi_done(scsicmd);
2425 case ALLOW_MEDIUM_REMOVAL:
2426 dprintk((KERN_DEBUG "LOCK command.\n"));
2427 if (scsicmd->cmnd[4])
2428 fsa_dev_ptr[cid].locked = 1;
2430 fsa_dev_ptr[cid].locked = 0;
2432 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2433 scsicmd->scsi_done(scsicmd);
2436 * These commands are all No-Ops
2438 case TEST_UNIT_READY:
2439 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
2440 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2441 SAM_STAT_CHECK_CONDITION;
2442 set_sense(&dev->fsa_dev[cid].sense_data,
2443 NOT_READY, SENCODE_BECOMING_READY,
2444 ASENCODE_BECOMING_READY, 0, 0);
2445 memcpy(scsicmd->sense_buffer,
2446 &dev->fsa_dev[cid].sense_data,
2448 sizeof(dev->fsa_dev[cid].sense_data),
2449 SCSI_SENSE_BUFFERSIZE));
2450 scsicmd->scsi_done(scsicmd);
2457 case REASSIGN_BLOCKS:
2459 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2460 scsicmd->scsi_done(scsicmd);
2464 return aac_start_stop(scsicmd);
2467 switch (scsicmd->cmnd[0])
2476 * Hack to keep track of ordinal number of the device that
2477 * corresponds to a container. Needed to convert
2478 * containers to /dev/sd device names
2481 if (scsicmd->request->rq_disk)
2482 strlcpy(fsa_dev_ptr[cid].devname,
2483 scsicmd->request->rq_disk->disk_name,
2484 min(sizeof(fsa_dev_ptr[cid].devname),
2485 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
2487 return aac_read(scsicmd);
2495 return aac_write(scsicmd);
2497 case SYNCHRONIZE_CACHE:
2498 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2499 scsicmd->result = DID_OK << 16 |
2500 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2501 scsicmd->scsi_done(scsicmd);
2504 /* Issue FIB to tell Firmware to flush it's cache */
2505 if ((aac_cache & 6) != 2)
2506 return aac_synchronize(scsicmd);
2510 * Unhandled commands
2512 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
2513 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2514 set_sense(&dev->fsa_dev[cid].sense_data,
2515 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2516 ASENCODE_INVALID_COMMAND, 0, 0);
2517 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2519 sizeof(dev->fsa_dev[cid].sense_data),
2520 SCSI_SENSE_BUFFERSIZE));
2521 scsicmd->scsi_done(scsicmd);
2526 static int query_disk(struct aac_dev *dev, void __user *arg)
2528 struct aac_query_disk qd;
2529 struct fsa_dev_info *fsa_dev_ptr;
2531 fsa_dev_ptr = dev->fsa_dev;
2534 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2538 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2540 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2542 qd.instance = dev->scsi_host_ptr->host_no;
2544 qd.id = CONTAINER_TO_ID(qd.cnum);
2545 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2547 else return -EINVAL;
2549 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
2550 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2551 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2553 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2558 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2559 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2561 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2566 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2568 struct aac_delete_disk dd;
2569 struct fsa_dev_info *fsa_dev_ptr;
2571 fsa_dev_ptr = dev->fsa_dev;
2575 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2578 if (dd.cnum >= dev->maximum_num_containers)
2581 * Mark this container as being deleted.
2583 fsa_dev_ptr[dd.cnum].deleted = 1;
2585 * Mark the container as no longer valid
2587 fsa_dev_ptr[dd.cnum].valid = 0;
2591 static int delete_disk(struct aac_dev *dev, void __user *arg)
2593 struct aac_delete_disk dd;
2594 struct fsa_dev_info *fsa_dev_ptr;
2596 fsa_dev_ptr = dev->fsa_dev;
2600 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2603 if (dd.cnum >= dev->maximum_num_containers)
2606 * If the container is locked, it can not be deleted by the API.
2608 if (fsa_dev_ptr[dd.cnum].locked)
2612 * Mark the container as no longer being valid.
2614 fsa_dev_ptr[dd.cnum].valid = 0;
2615 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2620 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2623 case FSACTL_QUERY_DISK:
2624 return query_disk(dev, arg);
2625 case FSACTL_DELETE_DISK:
2626 return delete_disk(dev, arg);
2627 case FSACTL_FORCE_DELETE_DISK:
2628 return force_delete_disk(dev, arg);
2629 case FSACTL_GET_CONTAINERS:
2630 return aac_get_containers(dev);
2639 * @context: the context set in the fib - here it is scsi cmd
2640 * @fibptr: pointer to the fib
2642 * Handles the completion of a scsi command to a non dasd device
2646 static void aac_srb_callback(void *context, struct fib * fibptr)
2648 struct aac_dev *dev;
2649 struct aac_srb_reply *srbreply;
2650 struct scsi_cmnd *scsicmd;
2652 scsicmd = (struct scsi_cmnd *) context;
2654 if (!aac_valid_context(scsicmd, fibptr))
2657 BUG_ON(fibptr == NULL);
2661 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2663 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2665 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
2667 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
2668 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
2671 * Calculate resid for sg
2673 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2674 - le32_to_cpu(srbreply->data_xfer_length));
2677 scsi_dma_unmap(scsicmd);
2679 /* expose physical device if expose_physicald flag is on */
2680 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
2681 && expose_physicals > 0)
2682 aac_expose_phy_device(scsicmd);
2685 * First check the fib status
2688 if (le32_to_cpu(srbreply->status) != ST_OK){
2690 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2691 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2692 SCSI_SENSE_BUFFERSIZE);
2693 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2694 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2698 * Next check the srb status
2700 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2701 case SRB_STATUS_ERROR_RECOVERY:
2702 case SRB_STATUS_PENDING:
2703 case SRB_STATUS_SUCCESS:
2704 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2706 case SRB_STATUS_DATA_OVERRUN:
2707 switch(scsicmd->cmnd[0]){
2716 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
2717 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2719 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2721 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2724 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2728 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2732 case SRB_STATUS_ABORTED:
2733 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2735 case SRB_STATUS_ABORT_FAILED:
2736 // Not sure about this one - but assuming the hba was trying to abort for some reason
2737 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2739 case SRB_STATUS_PARITY_ERROR:
2740 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2742 case SRB_STATUS_NO_DEVICE:
2743 case SRB_STATUS_INVALID_PATH_ID:
2744 case SRB_STATUS_INVALID_TARGET_ID:
2745 case SRB_STATUS_INVALID_LUN:
2746 case SRB_STATUS_SELECTION_TIMEOUT:
2747 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2750 case SRB_STATUS_COMMAND_TIMEOUT:
2751 case SRB_STATUS_TIMEOUT:
2752 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2755 case SRB_STATUS_BUSY:
2756 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
2759 case SRB_STATUS_BUS_RESET:
2760 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2763 case SRB_STATUS_MESSAGE_REJECTED:
2764 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2766 case SRB_STATUS_REQUEST_FLUSHED:
2767 case SRB_STATUS_ERROR:
2768 case SRB_STATUS_INVALID_REQUEST:
2769 case SRB_STATUS_REQUEST_SENSE_FAILED:
2770 case SRB_STATUS_NO_HBA:
2771 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2772 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2773 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2774 case SRB_STATUS_DELAYED_RETRY:
2775 case SRB_STATUS_BAD_FUNCTION:
2776 case SRB_STATUS_NOT_STARTED:
2777 case SRB_STATUS_NOT_IN_USE:
2778 case SRB_STATUS_FORCE_ABORT:
2779 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2781 #ifdef AAC_DETAILED_STATUS_INFO
2782 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2783 le32_to_cpu(srbreply->srb_status) & 0x3F,
2784 aac_get_status_string(
2785 le32_to_cpu(srbreply->srb_status) & 0x3F),
2787 le32_to_cpu(srbreply->scsi_status));
2789 if ((scsicmd->cmnd[0] == ATA_12)
2790 || (scsicmd->cmnd[0] == ATA_16)) {
2791 if (scsicmd->cmnd[2] & (0x01 << 5)) {
2792 scsicmd->result = DID_OK << 16
2793 | COMMAND_COMPLETE << 8;
2796 scsicmd->result = DID_ERROR << 16
2797 | COMMAND_COMPLETE << 8;
2801 scsicmd->result = DID_ERROR << 16
2802 | COMMAND_COMPLETE << 8;
2806 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
2808 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2809 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2810 SCSI_SENSE_BUFFERSIZE);
2811 #ifdef AAC_DETAILED_STATUS_INFO
2812 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2813 le32_to_cpu(srbreply->status), len);
2815 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2818 * OR in the scsi status (already shifted up a bit)
2820 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2822 aac_fib_complete(fibptr);
2823 aac_fib_free(fibptr);
2824 scsicmd->scsi_done(scsicmd);
2830 * @scsicmd: the scsi command block
2832 * This routine will form a FIB and fill in the aac_srb from the
2833 * scsicmd passed in.
2836 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2838 struct fib* cmd_fibcontext;
2839 struct aac_dev* dev;
2842 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2843 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2844 scsicmd->device->lun > 7) {
2845 scsicmd->result = DID_NO_CONNECT << 16;
2846 scsicmd->scsi_done(scsicmd);
2851 * Allocate and initialize a Fib then setup a BlockWrite command
2853 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2856 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2859 * Check that the command queued to the controller
2861 if (status == -EINPROGRESS) {
2862 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2866 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2867 aac_fib_complete(cmd_fibcontext);
2868 aac_fib_free(cmd_fibcontext);
2873 static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2875 struct aac_dev *dev;
2876 unsigned long byte_count = 0;
2879 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2880 // Get rid of old data
2882 psg->sg[0].addr = 0;
2883 psg->sg[0].count = 0;
2885 nseg = scsi_dma_map(scsicmd);
2888 struct scatterlist *sg;
2891 psg->count = cpu_to_le32(nseg);
2893 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2894 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2895 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2896 byte_count += sg_dma_len(sg);
2898 /* hba wants the size to be exact */
2899 if (byte_count > scsi_bufflen(scsicmd)) {
2900 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2901 (byte_count - scsi_bufflen(scsicmd));
2902 psg->sg[i-1].count = cpu_to_le32(temp);
2903 byte_count = scsi_bufflen(scsicmd);
2905 /* Check for command underflow */
2906 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2907 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2908 byte_count, scsicmd->underflow);
2915 static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2917 struct aac_dev *dev;
2918 unsigned long byte_count = 0;
2922 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2923 // Get rid of old data
2925 psg->sg[0].addr[0] = 0;
2926 psg->sg[0].addr[1] = 0;
2927 psg->sg[0].count = 0;
2929 nseg = scsi_dma_map(scsicmd);
2932 struct scatterlist *sg;
2935 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2936 int count = sg_dma_len(sg);
2937 addr = sg_dma_address(sg);
2938 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2939 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2940 psg->sg[i].count = cpu_to_le32(count);
2941 byte_count += count;
2943 psg->count = cpu_to_le32(nseg);
2944 /* hba wants the size to be exact */
2945 if (byte_count > scsi_bufflen(scsicmd)) {
2946 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2947 (byte_count - scsi_bufflen(scsicmd));
2948 psg->sg[i-1].count = cpu_to_le32(temp);
2949 byte_count = scsi_bufflen(scsicmd);
2951 /* Check for command underflow */
2952 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2953 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2954 byte_count, scsicmd->underflow);
2960 static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2962 unsigned long byte_count = 0;
2965 // Get rid of old data
2967 psg->sg[0].next = 0;
2968 psg->sg[0].prev = 0;
2969 psg->sg[0].addr[0] = 0;
2970 psg->sg[0].addr[1] = 0;
2971 psg->sg[0].count = 0;
2972 psg->sg[0].flags = 0;
2974 nseg = scsi_dma_map(scsicmd);
2977 struct scatterlist *sg;
2980 scsi_for_each_sg(scsicmd, sg, nseg, i) {
2981 int count = sg_dma_len(sg);
2982 u64 addr = sg_dma_address(sg);
2983 psg->sg[i].next = 0;
2984 psg->sg[i].prev = 0;
2985 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2986 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2987 psg->sg[i].count = cpu_to_le32(count);
2988 psg->sg[i].flags = 0;
2989 byte_count += count;
2991 psg->count = cpu_to_le32(nseg);
2992 /* hba wants the size to be exact */
2993 if (byte_count > scsi_bufflen(scsicmd)) {
2994 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2995 (byte_count - scsi_bufflen(scsicmd));
2996 psg->sg[i-1].count = cpu_to_le32(temp);
2997 byte_count = scsi_bufflen(scsicmd);
2999 /* Check for command underflow */
3000 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3001 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3002 byte_count, scsicmd->underflow);
3008 static unsigned long aac_build_sgraw2(struct scsi_cmnd *scsicmd, struct aac_raw_io2 *rio2, int sg_max)
3010 unsigned long byte_count = 0;
3013 nseg = scsi_dma_map(scsicmd);
3016 struct scatterlist *sg;
3017 int i, conformable = 0;
3018 u32 min_size = PAGE_SIZE, cur_size;
3020 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3021 int count = sg_dma_len(sg);
3022 u64 addr = sg_dma_address(sg);
3024 BUG_ON(i >= sg_max);
3025 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3026 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3027 cur_size = cpu_to_le32(count);
3028 rio2->sge[i].length = cur_size;
3029 rio2->sge[i].flags = 0;
3032 rio2->sgeFirstSize = cur_size;
3033 } else if (i == 1) {
3034 rio2->sgeNominalSize = cur_size;
3035 min_size = cur_size;
3036 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3038 if (cur_size < min_size)
3039 min_size = cur_size;
3041 byte_count += count;
3044 /* hba wants the size to be exact */
3045 if (byte_count > scsi_bufflen(scsicmd)) {
3046 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3047 (byte_count - scsi_bufflen(scsicmd));
3048 rio2->sge[i-1].length = cpu_to_le32(temp);
3049 byte_count = scsi_bufflen(scsicmd);
3052 rio2->sgeCnt = cpu_to_le32(nseg);
3053 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3054 /* not conformable: evaluate required sg elements */
3056 int j, nseg_new = nseg, err_found;
3057 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3060 for (j = 1; j < nseg - 1; ++j) {
3061 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3065 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3070 if (i > 0 && nseg_new <= sg_max)
3071 aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3073 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3075 /* Check for command underflow */
3076 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3077 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3078 byte_count, scsicmd->underflow);
3085 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3087 struct sge_ieee1212 *sge;
3091 if (aac_convert_sgl == 0)
3094 sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
3098 for (i = 1, pos = 1; i < nseg-1; ++i) {
3099 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
3100 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
3101 sge[pos].addrLow = addr_low;
3102 sge[pos].addrHigh = rio2->sge[i].addrHigh;
3103 if (addr_low < rio2->sge[i].addrLow)
3104 sge[pos].addrHigh++;
3105 sge[pos].length = pages * PAGE_SIZE;
3110 sge[pos] = rio2->sge[nseg-1];
3111 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
3114 rio2->sgeCnt = cpu_to_le32(nseg_new);
3115 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3116 rio2->sgeNominalSize = pages * PAGE_SIZE;
3120 #ifdef AAC_DETAILED_STATUS_INFO
3122 struct aac_srb_status_info {
3128 static struct aac_srb_status_info srb_status_info[] = {
3129 { SRB_STATUS_PENDING, "Pending Status"},
3130 { SRB_STATUS_SUCCESS, "Success"},
3131 { SRB_STATUS_ABORTED, "Aborted Command"},
3132 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
3133 { SRB_STATUS_ERROR, "Error Event"},
3134 { SRB_STATUS_BUSY, "Device Busy"},
3135 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
3136 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
3137 { SRB_STATUS_NO_DEVICE, "No Device"},
3138 { SRB_STATUS_TIMEOUT, "Timeout"},
3139 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
3140 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
3141 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
3142 { SRB_STATUS_BUS_RESET, "Bus Reset"},
3143 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
3144 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
3145 { SRB_STATUS_NO_HBA, "No HBA"},
3146 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
3147 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
3148 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
3149 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
3150 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
3151 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
3152 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
3153 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
3154 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
3155 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
3156 { SRB_STATUS_NOT_STARTED, "Not Started"},
3157 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
3158 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
3159 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
3160 { 0xff, "Unknown Error"}
3163 char *aac_get_status_string(u32 status)
3167 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
3168 if (srb_status_info[i].status == status)
3169 return srb_status_info[i].str;
3171 return "Bad Status Code";