1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Adaptec AAC series RAID controller driver
4 * (c) Copyright 2001 Red Hat Inc.
6 * based on the old aacraid driver that is..
7 * Adaptec aacraid device driver for Linux.
9 * Copyright (c) 2000-2010 Adaptec, Inc.
10 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
16 * Abstract: Contains Interfaces to manage IOs.
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/types.h>
22 #include <linux/pci.h>
23 #include <linux/spinlock.h>
24 #include <linux/slab.h>
25 #include <linux/completion.h>
26 #include <linux/blkdev.h>
27 #include <linux/uaccess.h>
28 #include <linux/module.h>
30 #include <asm/unaligned.h>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_cmnd.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
39 /* values for inqd_pdt: Peripheral device type in plain English */
40 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
41 #define INQD_PDT_PROC 0x03 /* Processor device */
42 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
43 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
44 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
45 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
47 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
48 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
54 #define SENCODE_NO_SENSE 0x00
55 #define SENCODE_END_OF_DATA 0x00
56 #define SENCODE_BECOMING_READY 0x04
57 #define SENCODE_INIT_CMD_REQUIRED 0x04
58 #define SENCODE_UNRECOVERED_READ_ERROR 0x11
59 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
60 #define SENCODE_INVALID_COMMAND 0x20
61 #define SENCODE_LBA_OUT_OF_RANGE 0x21
62 #define SENCODE_INVALID_CDB_FIELD 0x24
63 #define SENCODE_LUN_NOT_SUPPORTED 0x25
64 #define SENCODE_INVALID_PARAM_FIELD 0x26
65 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
66 #define SENCODE_PARAM_VALUE_INVALID 0x26
67 #define SENCODE_RESET_OCCURRED 0x29
68 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
69 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
70 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
71 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
72 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
73 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
74 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
75 #define SENCODE_OVERLAPPED_COMMAND 0x4E
78 * Additional sense codes
81 #define ASENCODE_NO_SENSE 0x00
82 #define ASENCODE_END_OF_DATA 0x05
83 #define ASENCODE_BECOMING_READY 0x01
84 #define ASENCODE_INIT_CMD_REQUIRED 0x02
85 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
86 #define ASENCODE_INVALID_COMMAND 0x00
87 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
88 #define ASENCODE_INVALID_CDB_FIELD 0x00
89 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
90 #define ASENCODE_INVALID_PARAM_FIELD 0x00
91 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
92 #define ASENCODE_PARAM_VALUE_INVALID 0x02
93 #define ASENCODE_RESET_OCCURRED 0x00
94 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
95 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
96 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
97 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
98 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
99 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
100 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
101 #define ASENCODE_OVERLAPPED_COMMAND 0x00
103 #define BYTE0(x) (unsigned char)(x)
104 #define BYTE1(x) (unsigned char)((x) >> 8)
105 #define BYTE2(x) (unsigned char)((x) >> 16)
106 #define BYTE3(x) (unsigned char)((x) >> 24)
108 /* MODE_SENSE data format */
115 } __attribute__((packed)) hd;
121 } __attribute__((packed)) bd;
123 } __attribute__((packed)) aac_modep_data;
125 /* MODE_SENSE_10 data format */
133 } __attribute__((packed)) hd;
139 } __attribute__((packed)) bd;
141 } __attribute__((packed)) aac_modep10_data;
143 /*------------------------------------------------------------------------------
144 * S T R U C T S / T Y P E D E F S
145 *----------------------------------------------------------------------------*/
146 /* SCSI inquiry data */
147 struct inquiry_data {
148 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
149 u8 inqd_dtq; /* RMB | Device Type Qualifier */
150 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
151 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
152 u8 inqd_len; /* Additional length (n-4) */
153 u8 inqd_pad1[2];/* Reserved - must be zero */
154 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
155 u8 inqd_vid[8]; /* Vendor ID */
156 u8 inqd_pid[16];/* Product ID */
157 u8 inqd_prl[4]; /* Product Revision Level */
160 /* Added for VPD 0x83 */
161 struct tvpd_id_descriptor_type_1 {
162 u8 codeset:4; /* VPD_CODE_SET */
164 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
170 u8 serialnumber[8]; /* SN in ASCII */
174 struct tvpd_id_descriptor_type_2 {
175 u8 codeset:4; /* VPD_CODE_SET */
177 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
183 /* The serial number supposed to be 40 bits,
184 * bit we only support 32, so make the last byte zero. */
191 struct tvpd_id_descriptor_type_3 {
192 u8 codeset : 4; /* VPD_CODE_SET */
194 u8 identifiertype : 4; /* VPD_IDENTIFIER_TYPE */
203 u8 DeviceTypeQualifier:3;
207 struct tvpd_id_descriptor_type_1 type1;
208 struct tvpd_id_descriptor_type_2 type2;
209 struct tvpd_id_descriptor_type_3 type3;
213 * M O D U L E G L O B A L S
216 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
217 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
218 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
219 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
220 struct aac_raw_io2 *rio2, int sg_max);
221 static long aac_build_sghba(struct scsi_cmnd *scsicmd,
222 struct aac_hba_cmd_req *hbacmd,
223 int sg_max, u64 sg_address);
224 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
225 int pages, int nseg, int nseg_new);
226 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
227 static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
228 #ifdef AAC_DETAILED_STATUS_INFO
229 static char *aac_get_status_string(u32 status);
233 * Non dasd selection is handled entirely in aachba now
236 static int nondasd = -1;
237 static int aac_cache = 2; /* WCE=0 to avoid performance problems */
238 static int dacmode = -1;
241 int startup_timeout = 180;
242 int aif_timeout = 120;
243 int aac_sync_mode; /* Only Sync. transfer - disabled */
244 static int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
246 module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
247 MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
249 module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
250 MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
252 module_param(nondasd, int, S_IRUGO|S_IWUSR);
253 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
255 module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
256 MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
257 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
258 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
259 "\tbit 2 - Disable only if Battery is protecting Cache");
260 module_param(dacmode, int, S_IRUGO|S_IWUSR);
261 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
263 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
264 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
265 " adapter for foreign arrays.\n"
266 "This is typically needed in systems that do not have a BIOS."
268 module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
269 MODULE_PARM_DESC(msi, "IRQ handling."
270 " 0=PIC(default), 1=MSI, 2=MSI-X)");
271 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
272 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
273 " adapter to have it's kernel up and\n"
274 "running. This is typically adjusted for large systems that do not"
276 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
277 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
278 " applications to pick up AIFs before\n"
279 "deregistering them. This is typically adjusted for heavily burdened"
283 module_param(aac_fib_dump, int, 0644);
284 MODULE_PARM_DESC(aac_fib_dump, "Dump controller fibs prior to IOP_RESET 0=off, 1=on");
287 module_param(numacb, int, S_IRUGO|S_IWUSR);
288 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
289 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
290 " to use suggestion from Firmware.");
292 static int acbsize = -1;
293 module_param(acbsize, int, S_IRUGO|S_IWUSR);
294 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
295 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
296 " suggestion from Firmware.");
298 int update_interval = 30 * 60;
299 module_param(update_interval, int, S_IRUGO|S_IWUSR);
300 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
301 " updates issued to adapter.");
303 int check_interval = 60;
304 module_param(check_interval, int, S_IRUGO|S_IWUSR);
305 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
308 int aac_check_reset = 1;
309 module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
310 MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
311 " adapter. a value of -1 forces the reset to adapters programmed to"
314 int expose_physicals = -1;
315 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
316 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
317 " -1=protect 0=off, 1=on");
319 int aac_reset_devices;
320 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
321 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
323 static int aac_wwn = 1;
324 module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
325 MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
327 "\t1 - Array Meta Data Signature (default)\n"
328 "\t2 - Adapter Serial Number");
331 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
332 struct fib *fibptr) {
333 struct scsi_device *device;
335 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
336 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
337 aac_fib_complete(fibptr);
340 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
341 device = scsicmd->device;
342 if (unlikely(!device)) {
343 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
344 aac_fib_complete(fibptr);
351 * aac_get_config_status - check the adapter configuration
352 * @dev: aac driver data
353 * @commit_flag: force sending CT_COMMIT_CONFIG
355 * Query config status, and commit the configuration if needed.
357 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
362 if (!(fibptr = aac_fib_alloc(dev)))
365 aac_fib_init(fibptr);
367 struct aac_get_config_status *dinfo;
368 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
370 dinfo->command = cpu_to_le32(VM_ContainerConfig);
371 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
372 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
375 status = aac_fib_send(ContainerCommand,
377 sizeof (struct aac_get_config_status),
382 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
384 struct aac_get_config_status_resp *reply
385 = (struct aac_get_config_status_resp *) fib_data(fibptr);
386 dprintk((KERN_WARNING
387 "aac_get_config_status: response=%d status=%d action=%d\n",
388 le32_to_cpu(reply->response),
389 le32_to_cpu(reply->status),
390 le32_to_cpu(reply->data.action)));
391 if ((le32_to_cpu(reply->response) != ST_OK) ||
392 (le32_to_cpu(reply->status) != CT_OK) ||
393 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
394 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
398 /* Do not set XferState to zero unless receives a response from F/W */
400 aac_fib_complete(fibptr);
402 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
404 if ((aac_commit == 1) || commit_flag) {
405 struct aac_commit_config * dinfo;
406 aac_fib_init(fibptr);
407 dinfo = (struct aac_commit_config *) fib_data(fibptr);
409 dinfo->command = cpu_to_le32(VM_ContainerConfig);
410 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
412 status = aac_fib_send(ContainerCommand,
414 sizeof (struct aac_commit_config),
418 /* Do not set XferState to zero unless
419 * receives a response from F/W */
421 aac_fib_complete(fibptr);
422 } else if (aac_commit == 0) {
424 "aac_get_config_status: Foreign device configurations are being ignored\n");
427 /* FIB should be freed only after getting the response from the F/W */
428 if (status != -ERESTARTSYS)
429 aac_fib_free(fibptr);
433 static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
436 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
437 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
439 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
444 * aac_get_containers - list containers
445 * @dev: aac driver data
447 * Make a list of all containers on this controller
449 int aac_get_containers(struct aac_dev *dev)
451 struct fsa_dev_info *fsa_dev_ptr;
455 struct aac_get_container_count *dinfo;
456 struct aac_get_container_count_resp *dresp;
457 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
459 if (!(fibptr = aac_fib_alloc(dev)))
462 aac_fib_init(fibptr);
463 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
464 dinfo->command = cpu_to_le32(VM_ContainerConfig);
465 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
467 status = aac_fib_send(ContainerCommand,
469 sizeof (struct aac_get_container_count),
474 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
475 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
476 if (fibptr->dev->supplement_adapter_info.supported_options2 &
477 AAC_OPTION_SUPPORTED_240_VOLUMES) {
478 maximum_num_containers =
479 le32_to_cpu(dresp->MaxSimpleVolumes);
481 aac_fib_complete(fibptr);
483 /* FIB should be freed only after getting the response from the F/W */
484 if (status != -ERESTARTSYS)
485 aac_fib_free(fibptr);
487 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
488 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
489 if (dev->fsa_dev == NULL ||
490 dev->maximum_num_containers != maximum_num_containers) {
492 fsa_dev_ptr = dev->fsa_dev;
494 dev->fsa_dev = kcalloc(maximum_num_containers,
495 sizeof(*fsa_dev_ptr), GFP_KERNEL);
504 dev->maximum_num_containers = maximum_num_containers;
506 for (index = 0; index < dev->maximum_num_containers; index++) {
507 dev->fsa_dev[index].devname[0] = '\0';
508 dev->fsa_dev[index].valid = 0;
510 status = aac_probe_container(dev, index);
513 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
520 static void get_container_name_callback(void *context, struct fib * fibptr)
522 struct aac_get_name_resp * get_name_reply;
523 struct scsi_cmnd * scsicmd;
525 scsicmd = (struct scsi_cmnd *) context;
527 if (!aac_valid_context(scsicmd, fibptr))
530 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
531 BUG_ON(fibptr == NULL);
533 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
534 /* Failure is irrelevant, using default value instead */
535 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
536 && (get_name_reply->data[0] != '\0')) {
537 char *sp = get_name_reply->data;
538 int data_size = sizeof_field(struct aac_get_name_resp, data);
540 sp[data_size - 1] = '\0';
544 struct inquiry_data inq;
545 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
546 int count = sizeof(d);
549 *dp++ = (*sp) ? *sp++ : ' ';
550 } while (--count > 0);
552 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
553 memcpy(inq.inqd_pid, d, sizeof(d));
554 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
558 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
560 aac_fib_complete(fibptr);
561 scsicmd->scsi_done(scsicmd);
565 * aac_get_container_name - get container name, none blocking.
567 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
571 struct aac_get_name *dinfo;
572 struct fib * cmd_fibcontext;
573 struct aac_dev * dev;
575 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
577 data_size = sizeof_field(struct aac_get_name_resp, data);
579 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
581 aac_fib_init(cmd_fibcontext);
582 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
583 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
585 dinfo->command = cpu_to_le32(VM_ContainerConfig);
586 dinfo->type = cpu_to_le32(CT_READ_NAME);
587 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
588 dinfo->count = cpu_to_le32(data_size - 1);
590 status = aac_fib_send(ContainerCommand,
592 sizeof(struct aac_get_name_resp),
595 (fib_callback)get_container_name_callback,
599 * Check that the command queued to the controller
601 if (status == -EINPROGRESS)
604 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
605 aac_fib_complete(cmd_fibcontext);
609 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
611 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
613 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
614 return aac_scsi_cmd(scsicmd);
616 scsicmd->result = DID_NO_CONNECT << 16;
617 scsicmd->scsi_done(scsicmd);
621 static void _aac_probe_container2(void * context, struct fib * fibptr)
623 struct fsa_dev_info *fsa_dev_ptr;
624 int (*callback)(struct scsi_cmnd *);
625 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
629 if (!aac_valid_context(scsicmd, fibptr))
632 scsicmd->SCp.Status = 0;
633 fsa_dev_ptr = fibptr->dev->fsa_dev;
635 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
638 fsa_dev_ptr += scmd_id(scsicmd);
640 fibptr->dev->supplement_adapter_info.supported_options2;
642 if ((le32_to_cpu(dresp->status) == ST_OK) &&
643 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
644 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
645 if (!(sup_options2 & AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
646 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
647 fsa_dev_ptr->block_size = 0x200;
649 fsa_dev_ptr->block_size =
650 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
652 for (i = 0; i < 16; i++)
653 fsa_dev_ptr->identifier[i] =
654 dresp->mnt[0].fileinfo.bdevinfo
656 fsa_dev_ptr->valid = 1;
657 /* sense_key holds the current state of the spin-up */
658 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
659 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
660 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
661 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
662 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
664 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
665 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
666 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
668 if ((fsa_dev_ptr->valid & 1) == 0)
669 fsa_dev_ptr->valid = 0;
670 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
672 aac_fib_complete(fibptr);
673 aac_fib_free(fibptr);
674 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
675 scsicmd->SCp.ptr = NULL;
676 (*callback)(scsicmd);
680 static void _aac_probe_container1(void * context, struct fib * fibptr)
682 struct scsi_cmnd * scsicmd;
683 struct aac_mount * dresp;
684 struct aac_query_mount *dinfo;
687 dresp = (struct aac_mount *) fib_data(fibptr);
688 if (!aac_supports_2T(fibptr->dev)) {
689 dresp->mnt[0].capacityhigh = 0;
690 if ((le32_to_cpu(dresp->status) == ST_OK) &&
691 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
692 _aac_probe_container2(context, fibptr);
696 scsicmd = (struct scsi_cmnd *) context;
698 if (!aac_valid_context(scsicmd, fibptr))
701 aac_fib_init(fibptr);
703 dinfo = (struct aac_query_mount *)fib_data(fibptr);
705 if (fibptr->dev->supplement_adapter_info.supported_options2 &
706 AAC_OPTION_VARIABLE_BLOCK_SIZE)
707 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
709 dinfo->command = cpu_to_le32(VM_NameServe64);
711 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
712 dinfo->type = cpu_to_le32(FT_FILESYS);
713 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
715 status = aac_fib_send(ContainerCommand,
717 sizeof(struct aac_query_mount),
720 _aac_probe_container2,
723 * Check that the command queued to the controller
725 if (status < 0 && status != -EINPROGRESS) {
726 /* Inherit results from VM_NameServe, if any */
727 dresp->status = cpu_to_le32(ST_OK);
728 _aac_probe_container2(context, fibptr);
732 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
735 int status = -ENOMEM;
737 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
738 struct aac_query_mount *dinfo;
740 aac_fib_init(fibptr);
742 dinfo = (struct aac_query_mount *)fib_data(fibptr);
744 if (fibptr->dev->supplement_adapter_info.supported_options2 &
745 AAC_OPTION_VARIABLE_BLOCK_SIZE)
746 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
748 dinfo->command = cpu_to_le32(VM_NameServe);
750 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
751 dinfo->type = cpu_to_le32(FT_FILESYS);
752 scsicmd->SCp.ptr = (char *)callback;
753 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
755 status = aac_fib_send(ContainerCommand,
757 sizeof(struct aac_query_mount),
760 _aac_probe_container1,
763 * Check that the command queued to the controller
765 if (status == -EINPROGRESS)
769 scsicmd->SCp.ptr = NULL;
770 aac_fib_complete(fibptr);
771 aac_fib_free(fibptr);
775 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
777 fsa_dev_ptr += scmd_id(scsicmd);
778 if ((fsa_dev_ptr->valid & 1) == 0) {
779 fsa_dev_ptr->valid = 0;
780 return (*callback)(scsicmd);
788 * aac_probe_container_callback1 - query a logical volume
789 * @scsicmd: the scsi command block
791 * Queries the controller about the given volume. The volume information
792 * is updated in the struct fsa_dev_info structure rather than returned.
794 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
796 scsicmd->device = NULL;
800 static void aac_probe_container_scsi_done(struct scsi_cmnd *scsi_cmnd)
802 aac_probe_container_callback1(scsi_cmnd);
805 int aac_probe_container(struct aac_dev *dev, int cid)
807 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
808 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
811 if (!scsicmd || !scsidev) {
816 scsicmd->scsi_done = aac_probe_container_scsi_done;
818 scsicmd->device = scsidev;
819 scsidev->sdev_state = 0;
821 scsidev->host = dev->scsi_host_ptr;
823 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
824 while (scsicmd->device == scsidev)
827 status = scsicmd->SCp.Status;
832 /* Local Structure to set SCSI inquiry data strings */
834 char vid[8]; /* Vendor ID */
835 char pid[16]; /* Product ID */
836 char prl[4]; /* Product Revision Level */
840 * inqstrcpy - string merge
841 * @a: string to copy from
842 * @b: string to copy to
844 * Copy a String from one location to another
848 static void inqstrcpy(char *a, char *b)
851 while (*a != (char)0)
855 static char *container_types[] = {
879 char * get_container_type(unsigned tindex)
881 if (tindex >= ARRAY_SIZE(container_types))
882 tindex = ARRAY_SIZE(container_types) - 1;
883 return container_types[tindex];
886 /* Function: setinqstr
888 * Arguments: [1] pointer to void [1] int
890 * Purpose: Sets SCSI inquiry data strings for vendor, product
891 * and revision level. Allows strings to be set in platform dependent
892 * files instead of in OS dependent driver source.
895 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
897 struct scsi_inq *str;
898 struct aac_supplement_adapter_info *sup_adap_info;
900 sup_adap_info = &dev->supplement_adapter_info;
901 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
902 memset(str, ' ', sizeof(*str));
904 if (sup_adap_info->adapter_type_text[0]) {
907 char *cname = kmemdup(sup_adap_info->adapter_type_text,
908 sizeof(sup_adap_info->adapter_type_text),
914 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
915 inqstrcpy("SMC", str->vid);
917 c = sizeof(str->vid);
918 while (*cp && *cp != ' ' && --c)
922 inqstrcpy(cname, str->vid);
924 while (*cp && *cp != ' ')
929 /* last six chars reserved for vol type */
930 if (strlen(cp) > sizeof(str->pid))
931 cp[sizeof(str->pid)] = '\0';
932 inqstrcpy (cp, str->pid);
936 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
938 inqstrcpy (mp->vname, str->vid);
939 /* last six chars reserved for vol type */
940 inqstrcpy (mp->model, str->pid);
943 if (tindex < ARRAY_SIZE(container_types)){
944 char *findit = str->pid;
946 for ( ; *findit != ' '; findit++); /* walk till we find a space */
947 /* RAID is superfluous in the context of a RAID device */
948 if (memcmp(findit-4, "RAID", 4) == 0)
949 *(findit -= 4) = ' ';
950 if (((findit - str->pid) + strlen(container_types[tindex]))
951 < (sizeof(str->pid) + sizeof(str->prl)))
952 inqstrcpy (container_types[tindex], findit + 1);
954 inqstrcpy ("V1.0", str->prl);
957 static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
958 struct aac_dev *dev, struct scsi_cmnd *scsicmd)
962 vpdpage83data->type3.codeset = 1;
963 vpdpage83data->type3.identifiertype = 3;
964 vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
967 for (container = 0; container < dev->maximum_num_containers;
970 if (scmd_id(scsicmd) == container) {
971 memcpy(vpdpage83data->type3.Identifier,
972 dev->fsa_dev[container].identifier,
979 static void get_container_serial_callback(void *context, struct fib * fibptr)
981 struct aac_get_serial_resp * get_serial_reply;
982 struct scsi_cmnd * scsicmd;
984 BUG_ON(fibptr == NULL);
986 scsicmd = (struct scsi_cmnd *) context;
987 if (!aac_valid_context(scsicmd, fibptr))
990 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
991 /* Failure is irrelevant, using default value instead */
992 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
993 /*Check to see if it's for VPD 0x83 or 0x80 */
994 if (scsicmd->cmnd[2] == 0x83) {
995 /* vpd page 0x83 - Device Identification Page */
998 struct tvpd_page83 vpdpage83data;
1000 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1002 memset(((u8 *)&vpdpage83data), 0,
1003 sizeof(vpdpage83data));
1005 /* DIRECT_ACCESS_DEVIC */
1006 vpdpage83data.DeviceType = 0;
1007 /* DEVICE_CONNECTED */
1008 vpdpage83data.DeviceTypeQualifier = 0;
1009 /* VPD_DEVICE_IDENTIFIERS */
1010 vpdpage83data.PageCode = 0x83;
1011 vpdpage83data.reserved = 0;
1012 vpdpage83data.PageLength =
1013 sizeof(vpdpage83data.type1) +
1014 sizeof(vpdpage83data.type2);
1016 /* VPD 83 Type 3 is not supported for ARC */
1017 if (dev->sa_firmware)
1018 vpdpage83data.PageLength +=
1019 sizeof(vpdpage83data.type3);
1021 /* T10 Vendor Identifier Field Format */
1022 /* VpdcodesetAscii */
1023 vpdpage83data.type1.codeset = 2;
1024 /* VpdIdentifierTypeVendorId */
1025 vpdpage83data.type1.identifiertype = 1;
1026 vpdpage83data.type1.identifierlength =
1027 sizeof(vpdpage83data.type1) - 4;
1029 /* "ADAPTEC " for adaptec */
1030 memcpy(vpdpage83data.type1.venid,
1032 sizeof(vpdpage83data.type1.venid));
1033 memcpy(vpdpage83data.type1.productid,
1036 vpdpage83data.type1.productid));
1038 /* Convert to ascii based serial number.
1039 * The LSB is the the end.
1041 for (i = 0; i < 8; i++) {
1043 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
1045 vpdpage83data.type1.serialnumber[i] =
1048 vpdpage83data.type1.serialnumber[i] =
1053 /* VpdCodeSetBinary */
1054 vpdpage83data.type2.codeset = 1;
1055 /* VpdidentifiertypeEUI64 */
1056 vpdpage83data.type2.identifiertype = 2;
1057 vpdpage83data.type2.identifierlength =
1058 sizeof(vpdpage83data.type2) - 4;
1060 vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1061 vpdpage83data.type2.eu64id.venid[1] = 0;
1062 vpdpage83data.type2.eu64id.venid[2] = 0;
1064 vpdpage83data.type2.eu64id.Serial =
1065 get_serial_reply->uid;
1066 vpdpage83data.type2.eu64id.reserved = 0;
1069 * VpdIdentifierTypeFCPHName
1070 * VPD 0x83 Type 3 not supported for ARC
1072 if (dev->sa_firmware) {
1073 build_vpd83_type3(&vpdpage83data,
1077 /* Move the inquiry data to the response buffer. */
1078 scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1079 sizeof(vpdpage83data));
1081 /* It must be for VPD 0x80 */
1084 sp[0] = INQD_PDT_DA;
1085 sp[1] = scsicmd->cmnd[2];
1087 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1088 le32_to_cpu(get_serial_reply->uid));
1089 scsi_sg_copy_from_buffer(scsicmd, sp,
1094 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
1096 aac_fib_complete(fibptr);
1097 scsicmd->scsi_done(scsicmd);
1101 * aac_get_container_serial - get container serial, none blocking.
1103 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1106 struct aac_get_serial *dinfo;
1107 struct fib * cmd_fibcontext;
1108 struct aac_dev * dev;
1110 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1112 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
1114 aac_fib_init(cmd_fibcontext);
1115 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1117 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1118 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1119 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1120 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1122 status = aac_fib_send(ContainerCommand,
1124 sizeof(struct aac_get_serial_resp),
1127 (fib_callback) get_container_serial_callback,
1131 * Check that the command queued to the controller
1133 if (status == -EINPROGRESS)
1136 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1137 aac_fib_complete(cmd_fibcontext);
1141 /* Function: setinqserial
1143 * Arguments: [1] pointer to void [1] int
1145 * Purpose: Sets SCSI Unit Serial number.
1146 * This is a fake. We should read a proper
1147 * serial number from the container. <SuSE>But
1148 * without docs it's quite hard to do it :-)
1149 * So this will have to do in the meantime.</SuSE>
1152 static int setinqserial(struct aac_dev *dev, void *data, int cid)
1155 * This breaks array migration.
1157 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1158 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1161 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1162 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
1164 u8 *sense_buf = (u8 *)sense_data;
1165 /* Sense data valid, err code 70h */
1166 sense_buf[0] = 0x70; /* No info field */
1167 sense_buf[1] = 0; /* Segment number, always zero */
1169 sense_buf[2] = sense_key; /* Sense key */
1171 sense_buf[12] = sense_code; /* Additional sense code */
1172 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
1174 if (sense_key == ILLEGAL_REQUEST) {
1175 sense_buf[7] = 10; /* Additional sense length */
1177 sense_buf[15] = bit_pointer;
1178 /* Illegal parameter is in the parameter block */
1179 if (sense_code == SENCODE_INVALID_CDB_FIELD)
1180 sense_buf[15] |= 0xc0;/* Std sense key specific field */
1181 /* Illegal parameter is in the CDB block */
1182 sense_buf[16] = field_pointer >> 8; /* MSB */
1183 sense_buf[17] = field_pointer; /* LSB */
1185 sense_buf[7] = 6; /* Additional sense length */
1188 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1190 if (lba & 0xffffffff00000000LL) {
1191 int cid = scmd_id(cmd);
1192 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1193 cmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
1194 set_sense(&dev->fsa_dev[cid].sense_data,
1195 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1196 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1197 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1198 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1199 SCSI_SENSE_BUFFERSIZE));
1200 cmd->scsi_done(cmd);
1206 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1211 static void io_callback(void *context, struct fib * fibptr);
1213 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1215 struct aac_dev *dev = fib->dev;
1216 u16 fibsize, command;
1220 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1221 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1223 struct aac_raw_io2 *readcmd2;
1224 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1225 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1226 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1227 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1228 readcmd2->byteCount = cpu_to_le32(count *
1229 dev->fsa_dev[scmd_id(cmd)].block_size);
1230 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1231 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
1232 ret = aac_build_sgraw2(cmd, readcmd2,
1233 dev->scsi_host_ptr->sg_tablesize);
1236 command = ContainerRawIo2;
1237 fibsize = struct_size(readcmd2, sge,
1238 le32_to_cpu(readcmd2->sgeCnt));
1240 struct aac_raw_io *readcmd;
1241 readcmd = (struct aac_raw_io *) fib_data(fib);
1242 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1243 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1244 readcmd->count = cpu_to_le32(count *
1245 dev->fsa_dev[scmd_id(cmd)].block_size);
1246 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1247 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1248 readcmd->bpTotal = 0;
1249 readcmd->bpComplete = 0;
1250 ret = aac_build_sgraw(cmd, &readcmd->sg);
1253 command = ContainerRawIo;
1254 fibsize = sizeof(struct aac_raw_io) +
1255 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1258 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1260 * Now send the Fib to the adapter
1262 return aac_fib_send(command,
1267 (fib_callback) io_callback,
1271 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1274 struct aac_read64 *readcmd;
1278 readcmd = (struct aac_read64 *) fib_data(fib);
1279 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1280 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1281 readcmd->sector_count = cpu_to_le16(count);
1282 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1286 ret = aac_build_sg64(cmd, &readcmd->sg);
1289 fibsize = sizeof(struct aac_read64) +
1290 ((le32_to_cpu(readcmd->sg.count) - 1) *
1291 sizeof (struct sgentry64));
1292 BUG_ON (fibsize > (fib->dev->max_fib_size -
1293 sizeof(struct aac_fibhdr)));
1295 * Now send the Fib to the adapter
1297 return aac_fib_send(ContainerCommand64,
1302 (fib_callback) io_callback,
1306 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1309 struct aac_read *readcmd;
1310 struct aac_dev *dev = fib->dev;
1314 readcmd = (struct aac_read *) fib_data(fib);
1315 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1316 readcmd->cid = cpu_to_le32(scmd_id(cmd));
1317 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1318 readcmd->count = cpu_to_le32(count *
1319 dev->fsa_dev[scmd_id(cmd)].block_size);
1321 ret = aac_build_sg(cmd, &readcmd->sg);
1324 fibsize = sizeof(struct aac_read) +
1325 ((le32_to_cpu(readcmd->sg.count) - 1) *
1326 sizeof (struct sgentry));
1327 BUG_ON (fibsize > (fib->dev->max_fib_size -
1328 sizeof(struct aac_fibhdr)));
1330 * Now send the Fib to the adapter
1332 return aac_fib_send(ContainerCommand,
1337 (fib_callback) io_callback,
1341 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1343 struct aac_dev *dev = fib->dev;
1344 u16 fibsize, command;
1348 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1349 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1351 struct aac_raw_io2 *writecmd2;
1352 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1353 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1354 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1355 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1356 writecmd2->byteCount = cpu_to_le32(count *
1357 dev->fsa_dev[scmd_id(cmd)].block_size);
1358 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1359 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1360 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1361 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1362 cpu_to_le16(RIO2_IO_TYPE_WRITE);
1363 ret = aac_build_sgraw2(cmd, writecmd2,
1364 dev->scsi_host_ptr->sg_tablesize);
1367 command = ContainerRawIo2;
1368 fibsize = struct_size(writecmd2, sge,
1369 le32_to_cpu(writecmd2->sgeCnt));
1371 struct aac_raw_io *writecmd;
1372 writecmd = (struct aac_raw_io *) fib_data(fib);
1373 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1374 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1375 writecmd->count = cpu_to_le32(count *
1376 dev->fsa_dev[scmd_id(cmd)].block_size);
1377 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1378 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1379 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1380 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1381 cpu_to_le16(RIO_TYPE_WRITE);
1382 writecmd->bpTotal = 0;
1383 writecmd->bpComplete = 0;
1384 ret = aac_build_sgraw(cmd, &writecmd->sg);
1387 command = ContainerRawIo;
1388 fibsize = sizeof(struct aac_raw_io) +
1389 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1392 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1394 * Now send the Fib to the adapter
1396 return aac_fib_send(command,
1401 (fib_callback) io_callback,
1405 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1408 struct aac_write64 *writecmd;
1412 writecmd = (struct aac_write64 *) fib_data(fib);
1413 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1414 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1415 writecmd->sector_count = cpu_to_le16(count);
1416 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1418 writecmd->flags = 0;
1420 ret = aac_build_sg64(cmd, &writecmd->sg);
1423 fibsize = sizeof(struct aac_write64) +
1424 ((le32_to_cpu(writecmd->sg.count) - 1) *
1425 sizeof (struct sgentry64));
1426 BUG_ON (fibsize > (fib->dev->max_fib_size -
1427 sizeof(struct aac_fibhdr)));
1429 * Now send the Fib to the adapter
1431 return aac_fib_send(ContainerCommand64,
1436 (fib_callback) io_callback,
1440 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1443 struct aac_write *writecmd;
1444 struct aac_dev *dev = fib->dev;
1448 writecmd = (struct aac_write *) fib_data(fib);
1449 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1450 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1451 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1452 writecmd->count = cpu_to_le32(count *
1453 dev->fsa_dev[scmd_id(cmd)].block_size);
1454 writecmd->sg.count = cpu_to_le32(1);
1455 /* ->stable is not used - it did mean which type of write */
1457 ret = aac_build_sg(cmd, &writecmd->sg);
1460 fibsize = sizeof(struct aac_write) +
1461 ((le32_to_cpu(writecmd->sg.count) - 1) *
1462 sizeof (struct sgentry));
1463 BUG_ON (fibsize > (fib->dev->max_fib_size -
1464 sizeof(struct aac_fibhdr)));
1466 * Now send the Fib to the adapter
1468 return aac_fib_send(ContainerCommand,
1473 (fib_callback) io_callback,
1477 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1479 struct aac_srb * srbcmd;
1482 struct aac_dev *dev = fib->dev;
1485 switch(cmd->sc_data_direction){
1489 case DMA_BIDIRECTIONAL:
1490 flag = SRB_DataIn | SRB_DataOut;
1492 case DMA_FROM_DEVICE:
1496 default: /* shuts up some versions of gcc */
1497 flag = SRB_NoDataXfer;
1501 srbcmd = (struct aac_srb*) fib_data(fib);
1502 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1503 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1504 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1505 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1506 srbcmd->flags = cpu_to_le32(flag);
1507 timeout = scsi_cmd_to_rq(cmd)->timeout / HZ;
1509 timeout = (dev->sa_firmware ? AAC_SA_TIMEOUT : AAC_ARC_TIMEOUT);
1510 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1511 srbcmd->retry_limit = 0; /* Obsolete parameter */
1512 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1516 static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
1517 struct scsi_cmnd *cmd)
1519 struct aac_hba_cmd_req *hbacmd;
1520 struct aac_dev *dev;
1524 dev = (struct aac_dev *)cmd->device->host->hostdata;
1526 hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
1527 memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
1528 /* iu_type is a parameter of aac_hba_send */
1529 switch (cmd->sc_data_direction) {
1533 case DMA_FROM_DEVICE:
1534 case DMA_BIDIRECTIONAL:
1541 hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
1543 bus = aac_logical_to_phys(scmd_channel(cmd));
1544 target = scmd_id(cmd);
1545 hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
1547 /* we fill in reply_qid later in aac_src_deliver_message */
1548 /* we fill in iu_type, request_id later in aac_hba_send */
1549 /* we fill in emb_data_desc_count later in aac_build_sghba */
1551 memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
1552 hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
1554 address = (u64)fib->hw_error_pa;
1555 hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
1556 hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
1557 hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
1562 static void aac_srb_callback(void *context, struct fib * fibptr);
1564 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1567 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1570 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1573 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1575 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1576 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1578 * Build Scatter/Gather list
1580 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1581 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1582 sizeof (struct sgentry64));
1583 BUG_ON (fibsize > (fib->dev->max_fib_size -
1584 sizeof(struct aac_fibhdr)));
1587 * Now send the Fib to the adapter
1589 return aac_fib_send(ScsiPortCommand64, fib,
1590 fibsize, FsaNormal, 0, 1,
1591 (fib_callback) aac_srb_callback,
1595 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1598 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1601 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1604 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1606 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1607 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1609 * Build Scatter/Gather list
1611 fibsize = sizeof (struct aac_srb) +
1612 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1613 sizeof (struct sgentry));
1614 BUG_ON (fibsize > (fib->dev->max_fib_size -
1615 sizeof(struct aac_fibhdr)));
1618 * Now send the Fib to the adapter
1620 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1621 (fib_callback) aac_srb_callback, (void *) cmd);
1624 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1626 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1627 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1629 return aac_scsi_32(fib, cmd);
1632 static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
1634 struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
1635 struct aac_dev *dev;
1638 dev = (struct aac_dev *)cmd->device->host->hostdata;
1640 ret = aac_build_sghba(cmd, hbacmd,
1641 dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
1646 * Now send the HBA command to the adapter
1648 fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
1649 sizeof(struct aac_hba_sgl);
1651 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
1652 (fib_callback) aac_hba_callback,
1656 static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
1657 struct aac_srb_unit *srbu, void *xfer_buf, int xfer_len)
1663 struct aac_srb *srb;
1664 struct aac_srb_reply *srb_reply;
1665 struct sgmap64 *sg64;
1669 if (!dev->sa_firmware)
1673 fibptr = aac_fib_alloc(dev);
1677 aac_fib_init(fibptr);
1678 fibptr->hw_fib_va->header.XferState &=
1679 ~cpu_to_le32(FastResponseCapable);
1681 fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
1682 sizeof(struct sgentry64);
1684 /* allocate DMA buffer for response */
1685 addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
1687 if (dma_mapping_error(&dev->pdev->dev, addr)) {
1692 srb = fib_data(fibptr);
1693 memcpy(srb, &srbu->srb, sizeof(struct aac_srb));
1695 vbus = (u32)le16_to_cpu(
1696 dev->supplement_adapter_info.virt_device_bus);
1697 vid = (u32)le16_to_cpu(
1698 dev->supplement_adapter_info.virt_device_target);
1700 /* set the common request fields */
1701 srb->channel = cpu_to_le32(vbus);
1702 srb->id = cpu_to_le32(vid);
1704 srb->function = cpu_to_le32(SRBF_ExecuteScsi);
1706 srb->retry_limit = 0;
1707 srb->cdb_size = cpu_to_le32(16);
1708 srb->count = cpu_to_le32(xfer_len);
1710 sg64 = (struct sgmap64 *)&srb->sg;
1711 sg64->count = cpu_to_le32(1);
1712 sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
1713 sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
1714 sg64->sg[0].count = cpu_to_le32(xfer_len);
1717 * Copy the updated data for other dumping or other usage if needed
1719 memcpy(&srbu->srb, srb, sizeof(struct aac_srb));
1721 /* issue request to the controller */
1722 rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize, FsaNormal,
1725 if (rcode == -ERESTARTSYS)
1728 if (unlikely(rcode < 0))
1731 srb_reply = (struct aac_srb_reply *)fib_data(fibptr);
1732 memcpy(&srbu->srb_reply, srb_reply, sizeof(struct aac_srb_reply));
1735 dma_unmap_single(&dev->pdev->dev, addr, xfer_len, DMA_BIDIRECTIONAL);
1737 aac_fib_complete(fibptr);
1738 aac_fib_free(fibptr);
1742 static void aac_set_safw_target_qd(struct aac_dev *dev, int bus, int target)
1745 struct aac_ciss_identify_pd *identify_resp;
1747 if (dev->hba_map[bus][target].devtype != AAC_DEVTYPE_NATIVE_RAW)
1750 identify_resp = dev->hba_map[bus][target].safw_identify_resp;
1751 if (identify_resp == NULL) {
1752 dev->hba_map[bus][target].qd_limit = 32;
1756 if (identify_resp->current_queue_depth_limit <= 0 ||
1757 identify_resp->current_queue_depth_limit > 255)
1758 dev->hba_map[bus][target].qd_limit = 32;
1760 dev->hba_map[bus][target].qd_limit =
1761 identify_resp->current_queue_depth_limit;
1764 static int aac_issue_safw_bmic_identify(struct aac_dev *dev,
1765 struct aac_ciss_identify_pd **identify_resp, u32 bus, u32 target)
1767 int rcode = -ENOMEM;
1769 struct aac_srb_unit srbu;
1770 struct aac_srb *srbcmd;
1771 struct aac_ciss_identify_pd *identify_reply;
1773 datasize = sizeof(struct aac_ciss_identify_pd);
1774 identify_reply = kmalloc(datasize, GFP_KERNEL);
1775 if (!identify_reply)
1778 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1781 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1782 srbcmd->cdb[0] = 0x26;
1783 srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
1784 srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
1786 rcode = aac_send_safw_bmic_cmd(dev, &srbu, identify_reply, datasize);
1787 if (unlikely(rcode < 0))
1790 *identify_resp = identify_reply;
1795 kfree(identify_reply);
1799 static inline void aac_free_safw_ciss_luns(struct aac_dev *dev)
1801 kfree(dev->safw_phys_luns);
1802 dev->safw_phys_luns = NULL;
1806 * aac_get_safw_ciss_luns() - Process topology change
1807 * @dev: aac_dev structure
1809 * Execute a CISS REPORT PHYS LUNS and process the results into
1810 * the current hba_map.
1812 static int aac_get_safw_ciss_luns(struct aac_dev *dev)
1814 int rcode = -ENOMEM;
1816 struct aac_srb *srbcmd;
1817 struct aac_srb_unit srbu;
1818 struct aac_ciss_phys_luns_resp *phys_luns;
1820 datasize = sizeof(struct aac_ciss_phys_luns_resp) +
1821 (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
1822 phys_luns = kmalloc(datasize, GFP_KERNEL);
1823 if (phys_luns == NULL)
1826 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1829 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1830 srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
1831 srbcmd->cdb[1] = 2; /* extended reporting */
1832 srbcmd->cdb[8] = (u8)(datasize >> 8);
1833 srbcmd->cdb[9] = (u8)(datasize);
1835 rcode = aac_send_safw_bmic_cmd(dev, &srbu, phys_luns, datasize);
1836 if (unlikely(rcode < 0))
1839 if (phys_luns->resp_flag != 2) {
1844 dev->safw_phys_luns = phys_luns;
1853 static inline u32 aac_get_safw_phys_lun_count(struct aac_dev *dev)
1855 return get_unaligned_be32(&dev->safw_phys_luns->list_length[0])/24;
1858 static inline u32 aac_get_safw_phys_bus(struct aac_dev *dev, int lun)
1860 return dev->safw_phys_luns->lun[lun].level2[1] & 0x3f;
1863 static inline u32 aac_get_safw_phys_target(struct aac_dev *dev, int lun)
1865 return dev->safw_phys_luns->lun[lun].level2[0];
1868 static inline u32 aac_get_safw_phys_expose_flag(struct aac_dev *dev, int lun)
1870 return dev->safw_phys_luns->lun[lun].bus >> 6;
1873 static inline u32 aac_get_safw_phys_attribs(struct aac_dev *dev, int lun)
1875 return dev->safw_phys_luns->lun[lun].node_ident[9];
1878 static inline u32 aac_get_safw_phys_nexus(struct aac_dev *dev, int lun)
1880 return *((u32 *)&dev->safw_phys_luns->lun[lun].node_ident[12]);
1883 static inline void aac_free_safw_identify_resp(struct aac_dev *dev,
1884 int bus, int target)
1886 kfree(dev->hba_map[bus][target].safw_identify_resp);
1887 dev->hba_map[bus][target].safw_identify_resp = NULL;
1890 static inline void aac_free_safw_all_identify_resp(struct aac_dev *dev,
1898 luns = aac_get_safw_phys_lun_count(dev);
1900 if (luns < lun_count)
1902 else if (lun_count < 0)
1905 for (i = 0; i < lun_count; i++) {
1906 bus = aac_get_safw_phys_bus(dev, i);
1907 target = aac_get_safw_phys_target(dev, i);
1909 aac_free_safw_identify_resp(dev, bus, target);
1913 static int aac_get_safw_attr_all_targets(struct aac_dev *dev)
1920 struct aac_ciss_identify_pd *identify_resp = NULL;
1922 lun_count = aac_get_safw_phys_lun_count(dev);
1924 for (i = 0; i < lun_count; ++i) {
1926 bus = aac_get_safw_phys_bus(dev, i);
1927 target = aac_get_safw_phys_target(dev, i);
1929 rcode = aac_issue_safw_bmic_identify(dev,
1930 &identify_resp, bus, target);
1932 if (unlikely(rcode < 0))
1933 goto free_identify_resp;
1935 dev->hba_map[bus][target].safw_identify_resp = identify_resp;
1941 aac_free_safw_all_identify_resp(dev, i);
1946 * aac_set_safw_attr_all_targets- update current hba map with data from FW
1947 * @dev: aac_dev structure
1949 * Update our hba map with the information gathered from the FW
1951 static void aac_set_safw_attr_all_targets(struct aac_dev *dev)
1953 /* ok and extended reporting */
1954 u32 lun_count, nexus;
1956 u8 expose_flag, attribs;
1958 lun_count = aac_get_safw_phys_lun_count(dev);
1960 dev->scan_counter++;
1962 for (i = 0; i < lun_count; ++i) {
1964 bus = aac_get_safw_phys_bus(dev, i);
1965 target = aac_get_safw_phys_target(dev, i);
1966 expose_flag = aac_get_safw_phys_expose_flag(dev, i);
1967 attribs = aac_get_safw_phys_attribs(dev, i);
1968 nexus = aac_get_safw_phys_nexus(dev, i);
1970 if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
1973 if (expose_flag != 0) {
1974 dev->hba_map[bus][target].devtype =
1975 AAC_DEVTYPE_RAID_MEMBER;
1979 if (nexus != 0 && (attribs & 8)) {
1980 dev->hba_map[bus][target].devtype =
1981 AAC_DEVTYPE_NATIVE_RAW;
1982 dev->hba_map[bus][target].rmw_nexus =
1985 dev->hba_map[bus][target].devtype =
1986 AAC_DEVTYPE_ARC_RAW;
1988 dev->hba_map[bus][target].scan_counter = dev->scan_counter;
1990 aac_set_safw_target_qd(dev, bus, target);
1994 static int aac_setup_safw_targets(struct aac_dev *dev)
1998 rcode = aac_get_containers(dev);
1999 if (unlikely(rcode < 0))
2002 rcode = aac_get_safw_ciss_luns(dev);
2003 if (unlikely(rcode < 0))
2006 rcode = aac_get_safw_attr_all_targets(dev);
2007 if (unlikely(rcode < 0))
2008 goto free_ciss_luns;
2010 aac_set_safw_attr_all_targets(dev);
2012 aac_free_safw_all_identify_resp(dev, -1);
2014 aac_free_safw_ciss_luns(dev);
2019 int aac_setup_safw_adapter(struct aac_dev *dev)
2021 return aac_setup_safw_targets(dev);
2024 int aac_get_adapter_info(struct aac_dev* dev)
2028 u32 tmp, bus, target;
2029 struct aac_adapter_info *info;
2030 struct aac_bus_info *command;
2031 struct aac_bus_info_response *bus_info;
2033 if (!(fibptr = aac_fib_alloc(dev)))
2036 aac_fib_init(fibptr);
2037 info = (struct aac_adapter_info *) fib_data(fibptr);
2038 memset(info,0,sizeof(*info));
2040 rcode = aac_fib_send(RequestAdapterInfo,
2044 -1, 1, /* First `interrupt' command uses special wait */
2049 /* FIB should be freed only after
2050 * getting the response from the F/W */
2051 if (rcode != -ERESTARTSYS) {
2052 aac_fib_complete(fibptr);
2053 aac_fib_free(fibptr);
2057 memcpy(&dev->adapter_info, info, sizeof(*info));
2059 dev->supplement_adapter_info.virt_device_bus = 0xffff;
2060 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
2061 struct aac_supplement_adapter_info * sinfo;
2063 aac_fib_init(fibptr);
2065 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
2067 memset(sinfo,0,sizeof(*sinfo));
2069 rcode = aac_fib_send(RequestSupplementAdapterInfo,
2078 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
2079 if (rcode == -ERESTARTSYS) {
2080 fibptr = aac_fib_alloc(dev);
2087 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
2088 for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
2089 for (target = 0; target < AAC_MAX_TARGETS; target++) {
2090 dev->hba_map[bus][target].devtype = 0;
2091 dev->hba_map[bus][target].qd_limit = 0;
2099 aac_fib_init(fibptr);
2101 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
2103 memset(bus_info, 0, sizeof(*bus_info));
2105 command = (struct aac_bus_info *)bus_info;
2107 command->Command = cpu_to_le32(VM_Ioctl);
2108 command->ObjType = cpu_to_le32(FT_DRIVE);
2109 command->MethodId = cpu_to_le32(1);
2110 command->CtlCmd = cpu_to_le32(GetBusInfo);
2112 rcode = aac_fib_send(ContainerCommand,
2119 /* reasoned default */
2120 dev->maximum_num_physicals = 16;
2121 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
2122 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
2123 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
2126 if (!dev->in_reset) {
2128 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
2129 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
2135 le32_to_cpu(dev->adapter_info.kernelbuild),
2136 (int)sizeof(dev->supplement_adapter_info.build_date),
2137 dev->supplement_adapter_info.build_date);
2138 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
2139 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
2141 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2142 le32_to_cpu(dev->adapter_info.monitorbuild));
2143 tmp = le32_to_cpu(dev->adapter_info.biosrev);
2144 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
2146 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2147 le32_to_cpu(dev->adapter_info.biosbuild));
2149 if (aac_get_serial_number(
2150 shost_to_class(dev->scsi_host_ptr), buffer))
2151 printk(KERN_INFO "%s%d: serial %s",
2152 dev->name, dev->id, buffer);
2153 if (dev->supplement_adapter_info.vpd_info.tsid[0]) {
2154 printk(KERN_INFO "%s%d: TSID %.*s\n",
2156 (int)sizeof(dev->supplement_adapter_info
2158 dev->supplement_adapter_info.vpd_info.tsid);
2160 if (!aac_check_reset || ((aac_check_reset == 1) &&
2161 (dev->supplement_adapter_info.supported_options2 &
2162 AAC_OPTION_IGNORE_RESET))) {
2163 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
2164 dev->name, dev->id);
2168 dev->cache_protected = 0;
2169 dev->jbod = ((dev->supplement_adapter_info.feature_bits &
2170 AAC_FEATURE_JBOD) != 0);
2171 dev->nondasd_support = 0;
2172 dev->raid_scsi_mode = 0;
2173 if(dev->adapter_info.options & AAC_OPT_NONDASD)
2174 dev->nondasd_support = 1;
2177 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2178 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2179 * force nondasd support on. If we decide to allow the non-dasd flag
2180 * additional changes changes will have to be made to support
2181 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2182 * changed to support the new dev->raid_scsi_mode flag instead of
2183 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2184 * function aac_detect will have to be modified where it sets up the
2185 * max number of channels based on the aac->nondasd_support flag only.
2187 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
2188 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
2189 dev->nondasd_support = 1;
2190 dev->raid_scsi_mode = 1;
2192 if (dev->raid_scsi_mode != 0)
2193 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
2194 dev->name, dev->id);
2197 dev->nondasd_support = (nondasd!=0);
2198 if (dev->nondasd_support && !dev->in_reset)
2199 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
2201 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
2203 dev->dac_support = 0;
2204 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
2205 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
2207 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
2208 dev->name, dev->id);
2209 dev->dac_support = 1;
2213 dev->dac_support = (dacmode!=0);
2216 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2217 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
2218 & AAC_QUIRK_SCSI_32)) {
2219 dev->nondasd_support = 0;
2221 expose_physicals = 0;
2224 if (dev->dac_support) {
2225 if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(64))) {
2227 dev_info(&dev->pdev->dev, "64 Bit DAC enabled\n");
2228 } else if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(32))) {
2229 dev_info(&dev->pdev->dev, "DMA mask set failed, 64 Bit DAC disabled\n");
2230 dev->dac_support = 0;
2232 dev_info(&dev->pdev->dev, "No suitable DMA available\n");
2237 * Deal with configuring for the individualized limits of each packet
2240 dev->a_ops.adapter_scsi = (dev->dac_support)
2241 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
2245 if (dev->raw_io_interface) {
2246 dev->a_ops.adapter_bounds = (dev->raw_io_64)
2249 dev->a_ops.adapter_read = aac_read_raw_io;
2250 dev->a_ops.adapter_write = aac_write_raw_io;
2252 dev->a_ops.adapter_bounds = aac_bounds_32;
2253 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
2254 sizeof(struct aac_fibhdr) -
2255 sizeof(struct aac_write) + sizeof(struct sgentry)) /
2256 sizeof(struct sgentry);
2257 if (dev->dac_support) {
2258 dev->a_ops.adapter_read = aac_read_block64;
2259 dev->a_ops.adapter_write = aac_write_block64;
2261 * 38 scatter gather elements
2263 dev->scsi_host_ptr->sg_tablesize =
2264 (dev->max_fib_size -
2265 sizeof(struct aac_fibhdr) -
2266 sizeof(struct aac_write64) +
2267 sizeof(struct sgentry64)) /
2268 sizeof(struct sgentry64);
2270 dev->a_ops.adapter_read = aac_read_block;
2271 dev->a_ops.adapter_write = aac_write_block;
2273 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
2274 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
2276 * Worst case size that could cause sg overflow when
2277 * we break up SG elements that are larger than 64KB.
2278 * Would be nice if we could tell the SCSI layer what
2279 * the maximum SG element size can be. Worst case is
2280 * (sg_tablesize-1) 4KB elements with one 64KB
2282 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2284 dev->scsi_host_ptr->max_sectors =
2285 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
2288 if (!dev->sync_mode && dev->sa_firmware &&
2289 dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
2290 dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
2291 HBA_MAX_SG_SEPARATE;
2293 /* FIB should be freed only after getting the response from the F/W */
2294 if (rcode != -ERESTARTSYS) {
2295 aac_fib_complete(fibptr);
2296 aac_fib_free(fibptr);
2303 static void io_callback(void *context, struct fib * fibptr)
2305 struct aac_dev *dev;
2306 struct aac_read_reply *readreply;
2307 struct scsi_cmnd *scsicmd;
2310 scsicmd = (struct scsi_cmnd *) context;
2312 if (!aac_valid_context(scsicmd, fibptr))
2316 cid = scmd_id(scsicmd);
2318 if (nblank(dprintk(x))) {
2320 switch (scsicmd->cmnd[0]) {
2323 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2324 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2328 lba = ((u64)scsicmd->cmnd[2] << 56) |
2329 ((u64)scsicmd->cmnd[3] << 48) |
2330 ((u64)scsicmd->cmnd[4] << 40) |
2331 ((u64)scsicmd->cmnd[5] << 32) |
2332 ((u64)scsicmd->cmnd[6] << 24) |
2333 (scsicmd->cmnd[7] << 16) |
2334 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2338 lba = ((u64)scsicmd->cmnd[2] << 24) |
2339 (scsicmd->cmnd[3] << 16) |
2340 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2343 lba = ((u64)scsicmd->cmnd[2] << 24) |
2344 (scsicmd->cmnd[3] << 16) |
2345 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2349 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2350 smp_processor_id(), (unsigned long long)lba, jiffies);
2353 BUG_ON(fibptr == NULL);
2355 scsi_dma_unmap(scsicmd);
2357 readreply = (struct aac_read_reply *)fib_data(fibptr);
2358 switch (le32_to_cpu(readreply->status)) {
2360 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2361 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
2364 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2365 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
2366 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
2367 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2368 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2369 SCSI_SENSE_BUFFERSIZE));
2372 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2373 set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
2374 SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
2375 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2376 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2377 SCSI_SENSE_BUFFERSIZE));
2380 #ifdef AAC_DETAILED_STATUS_INFO
2381 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
2382 le32_to_cpu(readreply->status));
2384 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2385 set_sense(&dev->fsa_dev[cid].sense_data,
2386 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2387 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2388 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2389 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2390 SCSI_SENSE_BUFFERSIZE));
2393 aac_fib_complete(fibptr);
2395 scsicmd->scsi_done(scsicmd);
2398 static int aac_read(struct scsi_cmnd * scsicmd)
2403 struct aac_dev *dev;
2404 struct fib * cmd_fibcontext;
2407 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2409 * Get block address and transfer length
2411 switch (scsicmd->cmnd[0]) {
2413 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
2415 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2416 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2417 count = scsicmd->cmnd[4];
2423 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
2425 lba = ((u64)scsicmd->cmnd[2] << 56) |
2426 ((u64)scsicmd->cmnd[3] << 48) |
2427 ((u64)scsicmd->cmnd[4] << 40) |
2428 ((u64)scsicmd->cmnd[5] << 32) |
2429 ((u64)scsicmd->cmnd[6] << 24) |
2430 (scsicmd->cmnd[7] << 16) |
2431 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2432 count = (scsicmd->cmnd[10] << 24) |
2433 (scsicmd->cmnd[11] << 16) |
2434 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2437 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
2439 lba = ((u64)scsicmd->cmnd[2] << 24) |
2440 (scsicmd->cmnd[3] << 16) |
2441 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2442 count = (scsicmd->cmnd[6] << 24) |
2443 (scsicmd->cmnd[7] << 16) |
2444 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2447 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
2449 lba = ((u64)scsicmd->cmnd[2] << 24) |
2450 (scsicmd->cmnd[3] << 16) |
2451 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2452 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2456 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2457 cid = scmd_id(scsicmd);
2458 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2459 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2460 set_sense(&dev->fsa_dev[cid].sense_data,
2461 ILLEGAL_REQUEST, SENCODE_LBA_OUT_OF_RANGE,
2462 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2463 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2464 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2465 SCSI_SENSE_BUFFERSIZE));
2466 scsicmd->scsi_done(scsicmd);
2470 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
2471 smp_processor_id(), (unsigned long long)lba, jiffies));
2472 if (aac_adapter_bounds(dev,scsicmd,lba))
2475 * Alocate and initialize a Fib
2477 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
2478 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2479 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
2482 * Check that the command queued to the controller
2484 if (status == -EINPROGRESS)
2487 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
2489 * For some reason, the Fib didn't queue, return QUEUE_FULL
2491 scsicmd->result = DID_OK << 16 | SAM_STAT_TASK_SET_FULL;
2492 scsicmd->scsi_done(scsicmd);
2493 aac_fib_complete(cmd_fibcontext);
2494 aac_fib_free(cmd_fibcontext);
2498 static int aac_write(struct scsi_cmnd * scsicmd)
2504 struct aac_dev *dev;
2505 struct fib * cmd_fibcontext;
2508 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2510 * Get block address and transfer length
2512 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
2514 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2515 count = scsicmd->cmnd[4];
2519 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
2520 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
2522 lba = ((u64)scsicmd->cmnd[2] << 56) |
2523 ((u64)scsicmd->cmnd[3] << 48) |
2524 ((u64)scsicmd->cmnd[4] << 40) |
2525 ((u64)scsicmd->cmnd[5] << 32) |
2526 ((u64)scsicmd->cmnd[6] << 24) |
2527 (scsicmd->cmnd[7] << 16) |
2528 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2529 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2530 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2531 fua = scsicmd->cmnd[1] & 0x8;
2532 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
2533 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
2535 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2536 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2537 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2538 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2539 fua = scsicmd->cmnd[1] & 0x8;
2541 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
2542 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2543 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2544 fua = scsicmd->cmnd[1] & 0x8;
2547 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2548 cid = scmd_id(scsicmd);
2549 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2550 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2551 set_sense(&dev->fsa_dev[cid].sense_data,
2552 ILLEGAL_REQUEST, SENCODE_LBA_OUT_OF_RANGE,
2553 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2554 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2555 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2556 SCSI_SENSE_BUFFERSIZE));
2557 scsicmd->scsi_done(scsicmd);
2561 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2562 smp_processor_id(), (unsigned long long)lba, jiffies));
2563 if (aac_adapter_bounds(dev,scsicmd,lba))
2566 * Allocate and initialize a Fib then setup a BlockWrite command
2568 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
2569 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2570 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
2573 * Check that the command queued to the controller
2575 if (status == -EINPROGRESS)
2578 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
2580 * For some reason, the Fib didn't queue, return QUEUE_FULL
2582 scsicmd->result = DID_OK << 16 | SAM_STAT_TASK_SET_FULL;
2583 scsicmd->scsi_done(scsicmd);
2585 aac_fib_complete(cmd_fibcontext);
2586 aac_fib_free(cmd_fibcontext);
2590 static void synchronize_callback(void *context, struct fib *fibptr)
2592 struct aac_synchronize_reply *synchronizereply;
2593 struct scsi_cmnd *cmd = context;
2595 if (!aac_valid_context(cmd, fibptr))
2598 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
2599 smp_processor_id(), jiffies));
2600 BUG_ON(fibptr == NULL);
2603 synchronizereply = fib_data(fibptr);
2604 if (le32_to_cpu(synchronizereply->status) == CT_OK)
2605 cmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2607 struct scsi_device *sdev = cmd->device;
2608 struct aac_dev *dev = fibptr->dev;
2609 u32 cid = sdev_id(sdev);
2611 "synchronize_callback: synchronize failed, status = %d\n",
2612 le32_to_cpu(synchronizereply->status));
2613 cmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2614 set_sense(&dev->fsa_dev[cid].sense_data,
2615 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2616 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2617 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2618 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2619 SCSI_SENSE_BUFFERSIZE));
2622 aac_fib_complete(fibptr);
2623 aac_fib_free(fibptr);
2624 cmd->scsi_done(cmd);
2627 static int aac_synchronize(struct scsi_cmnd *scsicmd)
2630 struct fib *cmd_fibcontext;
2631 struct aac_synchronize *synchronizecmd;
2632 struct scsi_device *sdev = scsicmd->device;
2633 struct aac_dev *aac;
2635 aac = (struct aac_dev *)sdev->host->hostdata;
2637 return SCSI_MLQUEUE_HOST_BUSY;
2640 * Allocate and initialize a Fib
2642 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
2644 aac_fib_init(cmd_fibcontext);
2646 synchronizecmd = fib_data(cmd_fibcontext);
2647 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2648 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
2649 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
2650 synchronizecmd->count =
2651 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2652 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2655 * Now send the Fib to the adapter
2657 status = aac_fib_send(ContainerCommand,
2659 sizeof(struct aac_synchronize),
2662 (fib_callback)synchronize_callback,
2666 * Check that the command queued to the controller
2668 if (status == -EINPROGRESS)
2672 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2673 aac_fib_complete(cmd_fibcontext);
2674 aac_fib_free(cmd_fibcontext);
2675 return SCSI_MLQUEUE_HOST_BUSY;
2678 static void aac_start_stop_callback(void *context, struct fib *fibptr)
2680 struct scsi_cmnd *scsicmd = context;
2682 if (!aac_valid_context(scsicmd, fibptr))
2685 BUG_ON(fibptr == NULL);
2687 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2689 aac_fib_complete(fibptr);
2690 aac_fib_free(fibptr);
2691 scsicmd->scsi_done(scsicmd);
2694 static int aac_start_stop(struct scsi_cmnd *scsicmd)
2697 struct fib *cmd_fibcontext;
2698 struct aac_power_management *pmcmd;
2699 struct scsi_device *sdev = scsicmd->device;
2700 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2702 if (!(aac->supplement_adapter_info.supported_options2 &
2703 AAC_OPTION_POWER_MANAGEMENT)) {
2704 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2705 scsicmd->scsi_done(scsicmd);
2710 return SCSI_MLQUEUE_HOST_BUSY;
2713 * Allocate and initialize a Fib
2715 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
2717 aac_fib_init(cmd_fibcontext);
2719 pmcmd = fib_data(cmd_fibcontext);
2720 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2721 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2722 /* Eject bit ignored, not relevant */
2723 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2724 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2725 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2726 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2727 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2728 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2731 * Now send the Fib to the adapter
2733 status = aac_fib_send(ContainerCommand,
2735 sizeof(struct aac_power_management),
2738 (fib_callback)aac_start_stop_callback,
2742 * Check that the command queued to the controller
2744 if (status == -EINPROGRESS)
2747 aac_fib_complete(cmd_fibcontext);
2748 aac_fib_free(cmd_fibcontext);
2749 return SCSI_MLQUEUE_HOST_BUSY;
2753 * aac_scsi_cmd() - Process SCSI command
2754 * @scsicmd: SCSI command block
2756 * Emulate a SCSI command and queue the required request for the
2760 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2763 struct Scsi_Host *host = scsicmd->device->host;
2764 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2765 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
2767 if (fsa_dev_ptr == NULL)
2770 * If the bus, id or lun is out of range, return fail
2771 * Test does not apply to ID 16, the pseudo id for the controller
2774 cid = scmd_id(scsicmd);
2775 if (cid != host->this_id) {
2776 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2777 if((cid >= dev->maximum_num_containers) ||
2778 (scsicmd->device->lun != 0)) {
2779 scsicmd->result = DID_NO_CONNECT << 16;
2784 * If the target container doesn't exist, it may have
2785 * been newly created
2787 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2788 (fsa_dev_ptr[cid].sense_data.sense_key ==
2790 switch (scsicmd->cmnd[0]) {
2791 case SERVICE_ACTION_IN_16:
2792 if (!(dev->raw_io_interface) ||
2793 !(dev->raw_io_64) ||
2794 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2799 case TEST_UNIT_READY:
2802 return _aac_probe_container(scsicmd,
2803 aac_probe_container_callback2);
2808 } else { /* check for physical non-dasd devices */
2809 bus = aac_logical_to_phys(scmd_channel(scsicmd));
2811 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2812 dev->hba_map[bus][cid].devtype
2813 == AAC_DEVTYPE_NATIVE_RAW) {
2816 return aac_send_hba_fib(scsicmd);
2817 } else if (dev->nondasd_support || expose_physicals ||
2821 return aac_send_srb_fib(scsicmd);
2823 scsicmd->result = DID_NO_CONNECT << 16;
2829 * else Command for the controller itself
2831 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
2832 (scsicmd->cmnd[0] != TEST_UNIT_READY))
2834 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2835 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2836 set_sense(&dev->fsa_dev[cid].sense_data,
2837 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2838 ASENCODE_INVALID_COMMAND, 0, 0);
2839 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2840 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2841 SCSI_SENSE_BUFFERSIZE));
2845 switch (scsicmd->cmnd[0]) {
2852 return aac_read(scsicmd);
2860 return aac_write(scsicmd);
2862 case SYNCHRONIZE_CACHE:
2863 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2864 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2867 /* Issue FIB to tell Firmware to flush it's cache */
2868 if ((aac_cache & 6) != 2)
2869 return aac_synchronize(scsicmd);
2873 struct inquiry_data inq_data;
2875 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
2876 memset(&inq_data, 0, sizeof (struct inquiry_data));
2878 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
2879 char *arr = (char *)&inq_data;
2882 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2883 INQD_PDT_PROC : INQD_PDT_DA;
2884 if (scsicmd->cmnd[2] == 0) {
2885 /* supported vital product data pages */
2890 arr[1] = scsicmd->cmnd[2];
2891 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2893 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2894 } else if (scsicmd->cmnd[2] == 0x80) {
2895 /* unit serial number page */
2896 arr[3] = setinqserial(dev, &arr[4],
2898 arr[1] = scsicmd->cmnd[2];
2899 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2902 return aac_get_container_serial(
2904 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2905 } else if (scsicmd->cmnd[2] == 0x83) {
2906 /* vpd page 0x83 - Device Identification Page */
2907 char *sno = (char *)&inq_data;
2908 sno[3] = setinqserial(dev, &sno[4],
2911 return aac_get_container_serial(
2913 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2915 /* vpd page not implemented */
2916 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2917 set_sense(&dev->fsa_dev[cid].sense_data,
2918 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2919 ASENCODE_NO_SENSE, 7, 2);
2920 memcpy(scsicmd->sense_buffer,
2921 &dev->fsa_dev[cid].sense_data,
2923 sizeof(dev->fsa_dev[cid].sense_data),
2924 SCSI_SENSE_BUFFERSIZE));
2928 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
2929 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 */
2930 inq_data.inqd_len = 31;
2931 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2932 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
2934 * Set the Vendor, Product, and Revision Level
2935 * see: <vendor>.c i.e. aac.c
2937 if (cid == host->this_id) {
2938 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
2939 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2940 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2942 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2947 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2948 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2949 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
2950 return aac_get_container_name(scsicmd);
2952 case SERVICE_ACTION_IN_16:
2953 if (!(dev->raw_io_interface) ||
2954 !(dev->raw_io_64) ||
2955 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2960 unsigned int alloc_len;
2962 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2963 capacity = fsa_dev_ptr[cid].size - 1;
2964 cp[0] = (capacity >> 56) & 0xff;
2965 cp[1] = (capacity >> 48) & 0xff;
2966 cp[2] = (capacity >> 40) & 0xff;
2967 cp[3] = (capacity >> 32) & 0xff;
2968 cp[4] = (capacity >> 24) & 0xff;
2969 cp[5] = (capacity >> 16) & 0xff;
2970 cp[6] = (capacity >> 8) & 0xff;
2971 cp[7] = (capacity >> 0) & 0xff;
2972 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2973 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2974 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2975 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
2978 alloc_len = ((scsicmd->cmnd[10] << 24)
2979 + (scsicmd->cmnd[11] << 16)
2980 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2982 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
2983 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
2984 if (alloc_len < scsi_bufflen(scsicmd))
2985 scsi_set_resid(scsicmd,
2986 scsi_bufflen(scsicmd) - alloc_len);
2988 /* Do not cache partition table for arrays */
2989 scsicmd->device->removable = 1;
2991 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3000 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
3001 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3002 capacity = fsa_dev_ptr[cid].size - 1;
3006 cp[0] = (capacity >> 24) & 0xff;
3007 cp[1] = (capacity >> 16) & 0xff;
3008 cp[2] = (capacity >> 8) & 0xff;
3009 cp[3] = (capacity >> 0) & 0xff;
3010 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3011 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3012 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3013 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
3014 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
3015 /* Do not cache partition table for arrays */
3016 scsicmd->device->removable = 1;
3017 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3023 int mode_buf_length = 4;
3027 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3028 capacity = fsa_dev_ptr[cid].size - 1;
3032 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
3033 memset((char *)&mpd, 0, sizeof(aac_modep_data));
3035 /* Mode data length */
3036 mpd.hd.data_length = sizeof(mpd.hd) - 1;
3037 /* Medium type - default */
3038 mpd.hd.med_type = 0;
3039 /* Device-specific param,
3040 bit 8: 0/1 = write enabled/protected
3041 bit 4: 0/1 = FUA enabled */
3044 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
3045 mpd.hd.dev_par = 0x10;
3046 if (scsicmd->cmnd[1] & 0x8)
3047 mpd.hd.bd_length = 0; /* Block descriptor length */
3049 mpd.hd.bd_length = sizeof(mpd.bd);
3050 mpd.hd.data_length += mpd.hd.bd_length;
3051 mpd.bd.block_length[0] =
3052 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3053 mpd.bd.block_length[1] =
3054 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3055 mpd.bd.block_length[2] =
3056 fsa_dev_ptr[cid].block_size & 0xff;
3058 mpd.mpc_buf[0] = scsicmd->cmnd[2];
3059 if (scsicmd->cmnd[2] == 0x1C) {
3061 mpd.mpc_buf[1] = 0xa;
3062 /* Mode data length */
3063 mpd.hd.data_length = 23;
3065 /* Mode data length */
3066 mpd.hd.data_length = 15;
3069 if (capacity > 0xffffff) {
3070 mpd.bd.block_count[0] = 0xff;
3071 mpd.bd.block_count[1] = 0xff;
3072 mpd.bd.block_count[2] = 0xff;
3074 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
3075 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
3076 mpd.bd.block_count[2] = capacity & 0xff;
3079 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3080 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
3081 mpd.hd.data_length += 3;
3084 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
3085 ? 0 : 0x04; /* WCE */
3086 mode_buf_length = sizeof(mpd);
3089 if (mode_buf_length > scsicmd->cmnd[4])
3090 mode_buf_length = scsicmd->cmnd[4];
3092 mode_buf_length = sizeof(mpd);
3093 scsi_sg_copy_from_buffer(scsicmd,
3096 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3102 int mode_buf_length = 8;
3103 aac_modep10_data mpd10;
3105 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3106 capacity = fsa_dev_ptr[cid].size - 1;
3110 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
3111 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
3112 /* Mode data length (MSB) */
3113 mpd10.hd.data_length[0] = 0;
3114 /* Mode data length (LSB) */
3115 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
3116 /* Medium type - default */
3117 mpd10.hd.med_type = 0;
3118 /* Device-specific param,
3119 bit 8: 0/1 = write enabled/protected
3120 bit 4: 0/1 = FUA enabled */
3121 mpd10.hd.dev_par = 0;
3123 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
3124 mpd10.hd.dev_par = 0x10;
3125 mpd10.hd.rsrvd[0] = 0; /* reserved */
3126 mpd10.hd.rsrvd[1] = 0; /* reserved */
3127 if (scsicmd->cmnd[1] & 0x8) {
3128 /* Block descriptor length (MSB) */
3129 mpd10.hd.bd_length[0] = 0;
3130 /* Block descriptor length (LSB) */
3131 mpd10.hd.bd_length[1] = 0;
3133 mpd10.hd.bd_length[0] = 0;
3134 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
3136 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
3138 mpd10.bd.block_length[0] =
3139 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3140 mpd10.bd.block_length[1] =
3141 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3142 mpd10.bd.block_length[2] =
3143 fsa_dev_ptr[cid].block_size & 0xff;
3145 if (capacity > 0xffffff) {
3146 mpd10.bd.block_count[0] = 0xff;
3147 mpd10.bd.block_count[1] = 0xff;
3148 mpd10.bd.block_count[2] = 0xff;
3150 mpd10.bd.block_count[0] =
3151 (capacity >> 16) & 0xff;
3152 mpd10.bd.block_count[1] =
3153 (capacity >> 8) & 0xff;
3154 mpd10.bd.block_count[2] =
3158 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3159 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
3160 mpd10.hd.data_length[1] += 3;
3161 mpd10.mpc_buf[0] = 8;
3162 mpd10.mpc_buf[1] = 1;
3163 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
3164 ? 0 : 0x04; /* WCE */
3165 mode_buf_length = sizeof(mpd10);
3166 if (mode_buf_length > scsicmd->cmnd[8])
3167 mode_buf_length = scsicmd->cmnd[8];
3169 scsi_sg_copy_from_buffer(scsicmd,
3173 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3177 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
3178 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3179 sizeof(struct sense_data));
3180 memset(&dev->fsa_dev[cid].sense_data, 0,
3181 sizeof(struct sense_data));
3182 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3185 case ALLOW_MEDIUM_REMOVAL:
3186 dprintk((KERN_DEBUG "LOCK command.\n"));
3187 if (scsicmd->cmnd[4])
3188 fsa_dev_ptr[cid].locked = 1;
3190 fsa_dev_ptr[cid].locked = 0;
3192 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3195 * These commands are all No-Ops
3197 case TEST_UNIT_READY:
3198 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
3199 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
3200 set_sense(&dev->fsa_dev[cid].sense_data,
3201 NOT_READY, SENCODE_BECOMING_READY,
3202 ASENCODE_BECOMING_READY, 0, 0);
3203 memcpy(scsicmd->sense_buffer,
3204 &dev->fsa_dev[cid].sense_data,
3206 sizeof(dev->fsa_dev[cid].sense_data),
3207 SCSI_SENSE_BUFFERSIZE));
3214 case REASSIGN_BLOCKS:
3216 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3220 return aac_start_stop(scsicmd);
3224 * Unhandled commands
3226 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
3228 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
3229 set_sense(&dev->fsa_dev[cid].sense_data,
3230 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
3231 ASENCODE_INVALID_COMMAND, 0, 0);
3232 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3234 sizeof(dev->fsa_dev[cid].sense_data),
3235 SCSI_SENSE_BUFFERSIZE));
3240 scsicmd->scsi_done(scsicmd);
3244 static int query_disk(struct aac_dev *dev, void __user *arg)
3246 struct aac_query_disk qd;
3247 struct fsa_dev_info *fsa_dev_ptr;
3249 fsa_dev_ptr = dev->fsa_dev;
3252 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
3254 if (qd.cnum == -1) {
3255 if (qd.id < 0 || qd.id >= dev->maximum_num_containers)
3258 } else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) {
3259 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
3261 qd.instance = dev->scsi_host_ptr->host_no;
3263 qd.id = CONTAINER_TO_ID(qd.cnum);
3264 qd.lun = CONTAINER_TO_LUN(qd.cnum);
3266 else return -EINVAL;
3268 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
3269 qd.locked = fsa_dev_ptr[qd.cnum].locked;
3270 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
3272 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
3277 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
3278 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
3280 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
3285 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
3287 struct aac_delete_disk dd;
3288 struct fsa_dev_info *fsa_dev_ptr;
3290 fsa_dev_ptr = dev->fsa_dev;
3294 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3297 if (dd.cnum >= dev->maximum_num_containers)
3300 * Mark this container as being deleted.
3302 fsa_dev_ptr[dd.cnum].deleted = 1;
3304 * Mark the container as no longer valid
3306 fsa_dev_ptr[dd.cnum].valid = 0;
3310 static int delete_disk(struct aac_dev *dev, void __user *arg)
3312 struct aac_delete_disk dd;
3313 struct fsa_dev_info *fsa_dev_ptr;
3315 fsa_dev_ptr = dev->fsa_dev;
3319 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3322 if (dd.cnum >= dev->maximum_num_containers)
3325 * If the container is locked, it can not be deleted by the API.
3327 if (fsa_dev_ptr[dd.cnum].locked)
3331 * Mark the container as no longer being valid.
3333 fsa_dev_ptr[dd.cnum].valid = 0;
3334 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
3339 int aac_dev_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg)
3342 case FSACTL_QUERY_DISK:
3343 return query_disk(dev, arg);
3344 case FSACTL_DELETE_DISK:
3345 return delete_disk(dev, arg);
3346 case FSACTL_FORCE_DELETE_DISK:
3347 return force_delete_disk(dev, arg);
3348 case FSACTL_GET_CONTAINERS:
3349 return aac_get_containers(dev);
3357 * @context: the context set in the fib - here it is scsi cmd
3358 * @fibptr: pointer to the fib
3360 * Handles the completion of a scsi command to a non dasd device
3362 static void aac_srb_callback(void *context, struct fib * fibptr)
3364 struct aac_srb_reply *srbreply;
3365 struct scsi_cmnd *scsicmd;
3367 scsicmd = (struct scsi_cmnd *) context;
3369 if (!aac_valid_context(scsicmd, fibptr))
3372 BUG_ON(fibptr == NULL);
3374 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
3376 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
3378 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3380 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
3381 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
3384 * Calculate resid for sg
3386 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
3387 - le32_to_cpu(srbreply->data_xfer_length));
3391 scsi_dma_unmap(scsicmd);
3393 /* expose physical device if expose_physicald flag is on */
3394 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
3395 && expose_physicals > 0)
3396 aac_expose_phy_device(scsicmd);
3399 * First check the fib status
3402 if (le32_to_cpu(srbreply->status) != ST_OK) {
3405 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3406 le32_to_cpu(srbreply->status));
3407 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3408 SCSI_SENSE_BUFFERSIZE);
3409 scsicmd->result = DID_ERROR << 16 | SAM_STAT_CHECK_CONDITION;
3410 memcpy(scsicmd->sense_buffer,
3411 srbreply->sense_data, len);
3415 * Next check the srb status
3417 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3418 case SRB_STATUS_ERROR_RECOVERY:
3419 case SRB_STATUS_PENDING:
3420 case SRB_STATUS_SUCCESS:
3421 scsicmd->result = DID_OK << 16;
3423 case SRB_STATUS_DATA_OVERRUN:
3424 switch (scsicmd->cmnd[0]) {
3433 if (le32_to_cpu(srbreply->data_xfer_length)
3434 < scsicmd->underflow)
3435 pr_warn("aacraid: SCSI CMD underflow\n");
3437 pr_warn("aacraid: SCSI CMD Data Overrun\n");
3438 scsicmd->result = DID_ERROR << 16;
3441 scsicmd->result = DID_OK << 16;
3444 scsicmd->result = DID_OK << 16;
3448 case SRB_STATUS_ABORTED:
3449 scsicmd->result = DID_ABORT << 16;
3451 case SRB_STATUS_ABORT_FAILED:
3453 * Not sure about this one - but assuming the
3454 * hba was trying to abort for some reason
3456 scsicmd->result = DID_ERROR << 16;
3458 case SRB_STATUS_PARITY_ERROR:
3459 scsicmd->result = DID_PARITY << 16;
3461 case SRB_STATUS_NO_DEVICE:
3462 case SRB_STATUS_INVALID_PATH_ID:
3463 case SRB_STATUS_INVALID_TARGET_ID:
3464 case SRB_STATUS_INVALID_LUN:
3465 case SRB_STATUS_SELECTION_TIMEOUT:
3466 scsicmd->result = DID_NO_CONNECT << 16;
3469 case SRB_STATUS_COMMAND_TIMEOUT:
3470 case SRB_STATUS_TIMEOUT:
3471 scsicmd->result = DID_TIME_OUT << 16;
3474 case SRB_STATUS_BUSY:
3475 scsicmd->result = DID_BUS_BUSY << 16;
3478 case SRB_STATUS_BUS_RESET:
3479 scsicmd->result = DID_RESET << 16;
3482 case SRB_STATUS_MESSAGE_REJECTED:
3483 scsicmd->result = DID_ERROR << 16;
3485 case SRB_STATUS_REQUEST_FLUSHED:
3486 case SRB_STATUS_ERROR:
3487 case SRB_STATUS_INVALID_REQUEST:
3488 case SRB_STATUS_REQUEST_SENSE_FAILED:
3489 case SRB_STATUS_NO_HBA:
3490 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3491 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3492 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3493 case SRB_STATUS_DELAYED_RETRY:
3494 case SRB_STATUS_BAD_FUNCTION:
3495 case SRB_STATUS_NOT_STARTED:
3496 case SRB_STATUS_NOT_IN_USE:
3497 case SRB_STATUS_FORCE_ABORT:
3498 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3500 #ifdef AAC_DETAILED_STATUS_INFO
3501 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3502 le32_to_cpu(srbreply->srb_status) & 0x3F,
3503 aac_get_status_string(
3504 le32_to_cpu(srbreply->srb_status) & 0x3F),
3506 le32_to_cpu(srbreply->scsi_status));
3509 * When the CC bit is SET by the host in ATA pass thru CDB,
3510 * driver is supposed to return DID_OK
3512 * When the CC bit is RESET by the host, driver should
3515 if ((scsicmd->cmnd[0] == ATA_12)
3516 || (scsicmd->cmnd[0] == ATA_16)) {
3518 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3519 scsicmd->result = DID_OK << 16;
3521 scsicmd->result = DID_ERROR << 16;
3524 scsicmd->result = DID_ERROR << 16;
3528 if (le32_to_cpu(srbreply->scsi_status)
3529 == SAM_STAT_CHECK_CONDITION) {
3532 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3533 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3534 SCSI_SENSE_BUFFERSIZE);
3535 #ifdef AAC_DETAILED_STATUS_INFO
3536 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3537 le32_to_cpu(srbreply->status), len);
3539 memcpy(scsicmd->sense_buffer,
3540 srbreply->sense_data, len);
3544 * OR in the scsi status (already shifted up a bit)
3546 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3548 aac_fib_complete(fibptr);
3549 scsicmd->scsi_done(scsicmd);
3552 static void hba_resp_task_complete(struct aac_dev *dev,
3553 struct scsi_cmnd *scsicmd,
3554 struct aac_hba_resp *err) {
3556 scsicmd->result = err->status;
3557 /* set residual count */
3558 scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
3560 switch (err->status) {
3562 scsicmd->result |= DID_OK << 16;
3564 case SAM_STAT_CHECK_CONDITION:
3568 len = min_t(u8, err->sense_response_data_len,
3569 SCSI_SENSE_BUFFERSIZE);
3571 memcpy(scsicmd->sense_buffer,
3572 err->sense_response_buf, len);
3573 scsicmd->result |= DID_OK << 16;
3577 scsicmd->result |= DID_BUS_BUSY << 16;
3579 case SAM_STAT_TASK_ABORTED:
3580 scsicmd->result |= DID_ABORT << 16;
3582 case SAM_STAT_RESERVATION_CONFLICT:
3583 case SAM_STAT_TASK_SET_FULL:
3585 scsicmd->result |= DID_ERROR << 16;
3590 static void hba_resp_task_failure(struct aac_dev *dev,
3591 struct scsi_cmnd *scsicmd,
3592 struct aac_hba_resp *err)
3594 switch (err->status) {
3595 case HBA_RESP_STAT_HBAMODE_DISABLED:
3599 bus = aac_logical_to_phys(scmd_channel(scsicmd));
3600 cid = scmd_id(scsicmd);
3601 if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
3602 dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
3603 dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
3605 scsicmd->result = DID_NO_CONNECT << 16;
3608 case HBA_RESP_STAT_IO_ERROR:
3609 case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
3610 scsicmd->result = DID_OK << 16 | SAM_STAT_BUSY;
3612 case HBA_RESP_STAT_IO_ABORTED:
3613 scsicmd->result = DID_ABORT << 16;
3615 case HBA_RESP_STAT_INVALID_DEVICE:
3616 scsicmd->result = DID_NO_CONNECT << 16;
3618 case HBA_RESP_STAT_UNDERRUN:
3619 /* UNDERRUN is OK */
3620 scsicmd->result = DID_OK << 16;
3622 case HBA_RESP_STAT_OVERRUN:
3624 scsicmd->result = DID_ERROR << 16;
3631 * @context: the context set in the fib - here it is scsi cmd
3632 * @fibptr: pointer to the fib
3634 * Handles the completion of a native HBA scsi command
3636 void aac_hba_callback(void *context, struct fib *fibptr)
3638 struct aac_dev *dev;
3639 struct scsi_cmnd *scsicmd;
3641 struct aac_hba_resp *err =
3642 &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
3644 scsicmd = (struct scsi_cmnd *) context;
3646 if (!aac_valid_context(scsicmd, fibptr))
3649 WARN_ON(fibptr == NULL);
3652 if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
3653 scsi_dma_unmap(scsicmd);
3655 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3657 scsicmd->result = DID_OK << 16;
3661 switch (err->service_response) {
3662 case HBA_RESP_SVCRES_TASK_COMPLETE:
3663 hba_resp_task_complete(dev, scsicmd, err);
3665 case HBA_RESP_SVCRES_FAILURE:
3666 hba_resp_task_failure(dev, scsicmd, err);
3668 case HBA_RESP_SVCRES_TMF_REJECTED:
3669 scsicmd->result = DID_ERROR << 16;
3671 case HBA_RESP_SVCRES_TMF_LUN_INVALID:
3672 scsicmd->result = DID_NO_CONNECT << 16;
3674 case HBA_RESP_SVCRES_TMF_COMPLETE:
3675 case HBA_RESP_SVCRES_TMF_SUCCEEDED:
3676 scsicmd->result = DID_OK << 16;
3679 scsicmd->result = DID_ERROR << 16;
3684 aac_fib_complete(fibptr);
3686 if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
3687 scsicmd->SCp.sent_command = 1;
3689 scsicmd->scsi_done(scsicmd);
3694 * @scsicmd: the scsi command block
3696 * This routine will form a FIB and fill in the aac_srb from the
3697 * scsicmd passed in.
3699 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3701 struct fib* cmd_fibcontext;
3702 struct aac_dev* dev;
3705 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3706 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3707 scsicmd->device->lun > 7) {
3708 scsicmd->result = DID_NO_CONNECT << 16;
3709 scsicmd->scsi_done(scsicmd);
3714 * Allocate and initialize a Fib then setup a BlockWrite command
3716 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3717 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3718 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
3721 * Check that the command queued to the controller
3723 if (status == -EINPROGRESS)
3726 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3727 aac_fib_complete(cmd_fibcontext);
3728 aac_fib_free(cmd_fibcontext);
3735 * @scsicmd: the scsi command block
3737 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3738 * scsicmd passed in.
3740 static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
3742 struct fib *cmd_fibcontext;
3743 struct aac_dev *dev;
3746 dev = shost_priv(scsicmd->device->host);
3747 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3748 scsicmd->device->lun > AAC_MAX_LUN - 1) {
3749 scsicmd->result = DID_NO_CONNECT << 16;
3750 scsicmd->scsi_done(scsicmd);
3755 * Allocate and initialize a Fib then setup a BlockWrite command
3757 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3758 if (!cmd_fibcontext)
3761 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3762 status = aac_adapter_hba(cmd_fibcontext, scsicmd);
3765 * Check that the command queued to the controller
3767 if (status == -EINPROGRESS)
3770 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3772 aac_fib_complete(cmd_fibcontext);
3773 aac_fib_free(cmd_fibcontext);
3779 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
3781 unsigned long byte_count = 0;
3783 struct scatterlist *sg;
3786 // Get rid of old data
3788 psg->sg[0].addr = 0;
3789 psg->sg[0].count = 0;
3791 nseg = scsi_dma_map(scsicmd);
3795 psg->count = cpu_to_le32(nseg);
3797 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3798 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3799 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3800 byte_count += sg_dma_len(sg);
3802 /* hba wants the size to be exact */
3803 if (byte_count > scsi_bufflen(scsicmd)) {
3804 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3805 (byte_count - scsi_bufflen(scsicmd));
3806 psg->sg[i-1].count = cpu_to_le32(temp);
3807 byte_count = scsi_bufflen(scsicmd);
3809 /* Check for command underflow */
3810 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3811 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3812 byte_count, scsicmd->underflow);
3819 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
3821 unsigned long byte_count = 0;
3824 struct scatterlist *sg;
3827 // Get rid of old data
3829 psg->sg[0].addr[0] = 0;
3830 psg->sg[0].addr[1] = 0;
3831 psg->sg[0].count = 0;
3833 nseg = scsi_dma_map(scsicmd);
3837 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3838 int count = sg_dma_len(sg);
3839 addr = sg_dma_address(sg);
3840 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3841 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
3842 psg->sg[i].count = cpu_to_le32(count);
3843 byte_count += count;
3845 psg->count = cpu_to_le32(nseg);
3846 /* hba wants the size to be exact */
3847 if (byte_count > scsi_bufflen(scsicmd)) {
3848 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3849 (byte_count - scsi_bufflen(scsicmd));
3850 psg->sg[i-1].count = cpu_to_le32(temp);
3851 byte_count = scsi_bufflen(scsicmd);
3853 /* Check for command underflow */
3854 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3855 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3856 byte_count, scsicmd->underflow);
3862 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
3864 unsigned long byte_count = 0;
3866 struct scatterlist *sg;
3869 // Get rid of old data
3871 psg->sg[0].next = 0;
3872 psg->sg[0].prev = 0;
3873 psg->sg[0].addr[0] = 0;
3874 psg->sg[0].addr[1] = 0;
3875 psg->sg[0].count = 0;
3876 psg->sg[0].flags = 0;
3878 nseg = scsi_dma_map(scsicmd);
3882 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3883 int count = sg_dma_len(sg);
3884 u64 addr = sg_dma_address(sg);
3885 psg->sg[i].next = 0;
3886 psg->sg[i].prev = 0;
3887 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
3888 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
3889 psg->sg[i].count = cpu_to_le32(count);
3890 psg->sg[i].flags = 0;
3891 byte_count += count;
3893 psg->count = cpu_to_le32(nseg);
3894 /* hba wants the size to be exact */
3895 if (byte_count > scsi_bufflen(scsicmd)) {
3896 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3897 (byte_count - scsi_bufflen(scsicmd));
3898 psg->sg[i-1].count = cpu_to_le32(temp);
3899 byte_count = scsi_bufflen(scsicmd);
3901 /* Check for command underflow */
3902 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3903 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3904 byte_count, scsicmd->underflow);
3910 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
3911 struct aac_raw_io2 *rio2, int sg_max)
3913 unsigned long byte_count = 0;
3915 struct scatterlist *sg;
3916 int i, conformable = 0;
3917 u32 min_size = PAGE_SIZE, cur_size;
3919 nseg = scsi_dma_map(scsicmd);
3923 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3924 int count = sg_dma_len(sg);
3925 u64 addr = sg_dma_address(sg);
3927 BUG_ON(i >= sg_max);
3928 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3929 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3930 cur_size = cpu_to_le32(count);
3931 rio2->sge[i].length = cur_size;
3932 rio2->sge[i].flags = 0;
3935 rio2->sgeFirstSize = cur_size;
3936 } else if (i == 1) {
3937 rio2->sgeNominalSize = cur_size;
3938 min_size = cur_size;
3939 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3941 if (cur_size < min_size)
3942 min_size = cur_size;
3944 byte_count += count;
3947 /* hba wants the size to be exact */
3948 if (byte_count > scsi_bufflen(scsicmd)) {
3949 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3950 (byte_count - scsi_bufflen(scsicmd));
3951 rio2->sge[i-1].length = cpu_to_le32(temp);
3952 byte_count = scsi_bufflen(scsicmd);
3955 rio2->sgeCnt = cpu_to_le32(nseg);
3956 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3957 /* not conformable: evaluate required sg elements */
3959 int j, nseg_new = nseg, err_found;
3960 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3963 for (j = 1; j < nseg - 1; ++j) {
3964 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3968 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3973 if (i > 0 && nseg_new <= sg_max) {
3974 int ret = aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3980 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3982 /* Check for command underflow */
3983 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3984 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3985 byte_count, scsicmd->underflow);
3991 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3993 struct sge_ieee1212 *sge;
3997 if (aac_convert_sgl == 0)
4000 sge = kmalloc_array(nseg_new, sizeof(*sge), GFP_ATOMIC);
4004 for (i = 1, pos = 1; i < nseg-1; ++i) {
4005 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
4006 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
4007 sge[pos].addrLow = addr_low;
4008 sge[pos].addrHigh = rio2->sge[i].addrHigh;
4009 if (addr_low < rio2->sge[i].addrLow)
4010 sge[pos].addrHigh++;
4011 sge[pos].length = pages * PAGE_SIZE;
4016 sge[pos] = rio2->sge[nseg-1];
4017 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
4020 rio2->sgeCnt = cpu_to_le32(nseg_new);
4021 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4022 rio2->sgeNominalSize = pages * PAGE_SIZE;
4026 static long aac_build_sghba(struct scsi_cmnd *scsicmd,
4027 struct aac_hba_cmd_req *hbacmd,
4031 unsigned long byte_count = 0;
4033 struct scatterlist *sg;
4036 struct aac_hba_sgl *sge;
4038 nseg = scsi_dma_map(scsicmd);
4044 if (nseg > HBA_MAX_SG_EMBEDDED)
4045 sge = &hbacmd->sge[2];
4047 sge = &hbacmd->sge[0];
4049 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4050 int count = sg_dma_len(sg);
4051 u64 addr = sg_dma_address(sg);
4053 WARN_ON(i >= sg_max);
4054 sge->addr_hi = cpu_to_le32((u32)(addr>>32));
4055 sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
4056 cur_size = cpu_to_le32(count);
4057 sge->len = cur_size;
4059 byte_count += count;
4064 /* hba wants the size to be exact */
4065 if (byte_count > scsi_bufflen(scsicmd)) {
4068 temp = le32_to_cpu(sge->len) - byte_count
4069 - scsi_bufflen(scsicmd);
4070 sge->len = cpu_to_le32(temp);
4071 byte_count = scsi_bufflen(scsicmd);
4074 if (nseg <= HBA_MAX_SG_EMBEDDED) {
4075 hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
4076 sge->flags = cpu_to_le32(0x40000000);
4079 hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
4080 hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
4081 hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
4082 hbacmd->sge[0].addr_lo =
4083 cpu_to_le32((u32)(sg_address & 0xffffffff));
4086 /* Check for command underflow */
4087 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4088 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4089 byte_count, scsicmd->underflow);
4095 #ifdef AAC_DETAILED_STATUS_INFO
4097 struct aac_srb_status_info {
4103 static struct aac_srb_status_info srb_status_info[] = {
4104 { SRB_STATUS_PENDING, "Pending Status"},
4105 { SRB_STATUS_SUCCESS, "Success"},
4106 { SRB_STATUS_ABORTED, "Aborted Command"},
4107 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
4108 { SRB_STATUS_ERROR, "Error Event"},
4109 { SRB_STATUS_BUSY, "Device Busy"},
4110 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
4111 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
4112 { SRB_STATUS_NO_DEVICE, "No Device"},
4113 { SRB_STATUS_TIMEOUT, "Timeout"},
4114 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
4115 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
4116 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
4117 { SRB_STATUS_BUS_RESET, "Bus Reset"},
4118 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
4119 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
4120 { SRB_STATUS_NO_HBA, "No HBA"},
4121 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
4122 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
4123 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
4124 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
4125 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
4126 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
4127 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
4128 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
4129 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
4130 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
4131 { SRB_STATUS_NOT_STARTED, "Not Started"},
4132 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
4133 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
4134 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
4135 { 0xff, "Unknown Error"}
4138 char *aac_get_status_string(u32 status)
4142 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
4143 if (srb_status_info[i].status == status)
4144 return srb_status_info[i].str;
4146 return "Bad Status Code";