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.
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/highmem.h> /* For flush_kernel_dcache_page */
29 #include <linux/module.h>
31 #include <asm/unaligned.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_cmnd.h>
35 #include <scsi/scsi_device.h>
36 #include <scsi/scsi_host.h>
40 /* values for inqd_pdt: Peripheral device type in plain English */
41 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
42 #define INQD_PDT_PROC 0x03 /* Processor device */
43 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
44 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
45 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
46 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
48 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
49 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
55 #define SENCODE_NO_SENSE 0x00
56 #define SENCODE_END_OF_DATA 0x00
57 #define SENCODE_BECOMING_READY 0x04
58 #define SENCODE_INIT_CMD_REQUIRED 0x04
59 #define SENCODE_UNRECOVERED_READ_ERROR 0x11
60 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
61 #define SENCODE_INVALID_COMMAND 0x20
62 #define SENCODE_LBA_OUT_OF_RANGE 0x21
63 #define SENCODE_INVALID_CDB_FIELD 0x24
64 #define SENCODE_LUN_NOT_SUPPORTED 0x25
65 #define SENCODE_INVALID_PARAM_FIELD 0x26
66 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
67 #define SENCODE_PARAM_VALUE_INVALID 0x26
68 #define SENCODE_RESET_OCCURRED 0x29
69 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
70 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
71 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
72 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
73 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
74 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
75 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
76 #define SENCODE_OVERLAPPED_COMMAND 0x4E
79 * Additional sense codes
82 #define ASENCODE_NO_SENSE 0x00
83 #define ASENCODE_END_OF_DATA 0x05
84 #define ASENCODE_BECOMING_READY 0x01
85 #define ASENCODE_INIT_CMD_REQUIRED 0x02
86 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
87 #define ASENCODE_INVALID_COMMAND 0x00
88 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
89 #define ASENCODE_INVALID_CDB_FIELD 0x00
90 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
91 #define ASENCODE_INVALID_PARAM_FIELD 0x00
92 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
93 #define ASENCODE_PARAM_VALUE_INVALID 0x02
94 #define ASENCODE_RESET_OCCURRED 0x00
95 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
96 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
97 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
98 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
99 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
100 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
101 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
102 #define ASENCODE_OVERLAPPED_COMMAND 0x00
104 #define BYTE0(x) (unsigned char)(x)
105 #define BYTE1(x) (unsigned char)((x) >> 8)
106 #define BYTE2(x) (unsigned char)((x) >> 16)
107 #define BYTE3(x) (unsigned char)((x) >> 24)
109 /* MODE_SENSE data format */
116 } __attribute__((packed)) hd;
122 } __attribute__((packed)) bd;
124 } __attribute__((packed)) aac_modep_data;
126 /* MODE_SENSE_10 data format */
134 } __attribute__((packed)) hd;
140 } __attribute__((packed)) bd;
142 } __attribute__((packed)) aac_modep10_data;
144 /*------------------------------------------------------------------------------
145 * S T R U C T S / T Y P E D E F S
146 *----------------------------------------------------------------------------*/
147 /* SCSI inquiry data */
148 struct inquiry_data {
149 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
150 u8 inqd_dtq; /* RMB | Device Type Qualifier */
151 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
152 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
153 u8 inqd_len; /* Additional length (n-4) */
154 u8 inqd_pad1[2];/* Reserved - must be zero */
155 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
156 u8 inqd_vid[8]; /* Vendor ID */
157 u8 inqd_pid[16];/* Product ID */
158 u8 inqd_prl[4]; /* Product Revision Level */
161 /* Added for VPD 0x83 */
162 struct tvpd_id_descriptor_type_1 {
163 u8 codeset:4; /* VPD_CODE_SET */
165 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
171 u8 serialnumber[8]; /* SN in ASCII */
175 struct tvpd_id_descriptor_type_2 {
176 u8 codeset:4; /* VPD_CODE_SET */
178 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
184 /* The serial number supposed to be 40 bits,
185 * bit we only support 32, so make the last byte zero. */
192 struct tvpd_id_descriptor_type_3 {
193 u8 codeset : 4; /* VPD_CODE_SET */
195 u8 identifiertype : 4; /* VPD_IDENTIFIER_TYPE */
204 u8 DeviceTypeQualifier:3;
208 struct tvpd_id_descriptor_type_1 type1;
209 struct tvpd_id_descriptor_type_2 type2;
210 struct tvpd_id_descriptor_type_3 type3;
214 * M O D U L E G L O B A L S
217 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
218 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
219 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
220 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
221 struct aac_raw_io2 *rio2, int sg_max);
222 static long aac_build_sghba(struct scsi_cmnd *scsicmd,
223 struct aac_hba_cmd_req *hbacmd,
224 int sg_max, u64 sg_address);
225 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
226 int pages, int nseg, int nseg_new);
227 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
228 static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
229 #ifdef AAC_DETAILED_STATUS_INFO
230 static char *aac_get_status_string(u32 status);
234 * Non dasd selection is handled entirely in aachba now
237 static int nondasd = -1;
238 static int aac_cache = 2; /* WCE=0 to avoid performance problems */
239 static int dacmode = -1;
242 int startup_timeout = 180;
243 int aif_timeout = 120;
244 int aac_sync_mode; /* Only Sync. transfer - disabled */
245 static int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
247 module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
248 MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
250 module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
251 MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
253 module_param(nondasd, int, S_IRUGO|S_IWUSR);
254 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
256 module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
257 MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
258 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
259 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
260 "\tbit 2 - Disable only if Battery is protecting Cache");
261 module_param(dacmode, int, S_IRUGO|S_IWUSR);
262 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
264 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
265 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
266 " adapter for foreign arrays.\n"
267 "This is typically needed in systems that do not have a BIOS."
269 module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
270 MODULE_PARM_DESC(msi, "IRQ handling."
271 " 0=PIC(default), 1=MSI, 2=MSI-X)");
272 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
273 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
274 " adapter to have it's kernel up and\n"
275 "running. This is typically adjusted for large systems that do not"
277 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
278 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
279 " applications to pick up AIFs before\n"
280 "deregistering them. This is typically adjusted for heavily burdened"
284 module_param(aac_fib_dump, int, 0644);
285 MODULE_PARM_DESC(aac_fib_dump, "Dump controller fibs prior to IOP_RESET 0=off, 1=on");
288 module_param(numacb, int, S_IRUGO|S_IWUSR);
289 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
290 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
291 " to use suggestion from Firmware.");
293 static int acbsize = -1;
294 module_param(acbsize, int, S_IRUGO|S_IWUSR);
295 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
296 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
297 " suggestion from Firmware.");
299 int update_interval = 30 * 60;
300 module_param(update_interval, int, S_IRUGO|S_IWUSR);
301 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
302 " updates issued to adapter.");
304 int check_interval = 60;
305 module_param(check_interval, int, S_IRUGO|S_IWUSR);
306 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
309 int aac_check_reset = 1;
310 module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
311 MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
312 " adapter. a value of -1 forces the reset to adapters programmed to"
315 int expose_physicals = -1;
316 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
317 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
318 " -1=protect 0=off, 1=on");
320 int aac_reset_devices;
321 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
322 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
324 static int aac_wwn = 1;
325 module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
326 MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
328 "\t1 - Array Meta Data Signature (default)\n"
329 "\t2 - Adapter Serial Number");
332 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
333 struct fib *fibptr) {
334 struct scsi_device *device;
336 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
337 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
338 aac_fib_complete(fibptr);
341 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
342 device = scsicmd->device;
343 if (unlikely(!device)) {
344 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
345 aac_fib_complete(fibptr);
352 * aac_get_config_status - check the adapter configuration
353 * @dev: aac driver data
354 * @commit_flag: force sending CT_COMMIT_CONFIG
356 * Query config status, and commit the configuration if needed.
358 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
363 if (!(fibptr = aac_fib_alloc(dev)))
366 aac_fib_init(fibptr);
368 struct aac_get_config_status *dinfo;
369 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
371 dinfo->command = cpu_to_le32(VM_ContainerConfig);
372 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
373 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
376 status = aac_fib_send(ContainerCommand,
378 sizeof (struct aac_get_config_status),
383 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
385 struct aac_get_config_status_resp *reply
386 = (struct aac_get_config_status_resp *) fib_data(fibptr);
387 dprintk((KERN_WARNING
388 "aac_get_config_status: response=%d status=%d action=%d\n",
389 le32_to_cpu(reply->response),
390 le32_to_cpu(reply->status),
391 le32_to_cpu(reply->data.action)));
392 if ((le32_to_cpu(reply->response) != ST_OK) ||
393 (le32_to_cpu(reply->status) != CT_OK) ||
394 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
395 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
399 /* Do not set XferState to zero unless receives a response from F/W */
401 aac_fib_complete(fibptr);
403 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
405 if ((aac_commit == 1) || commit_flag) {
406 struct aac_commit_config * dinfo;
407 aac_fib_init(fibptr);
408 dinfo = (struct aac_commit_config *) fib_data(fibptr);
410 dinfo->command = cpu_to_le32(VM_ContainerConfig);
411 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
413 status = aac_fib_send(ContainerCommand,
415 sizeof (struct aac_commit_config),
419 /* Do not set XferState to zero unless
420 * receives a response from F/W */
422 aac_fib_complete(fibptr);
423 } else if (aac_commit == 0) {
425 "aac_get_config_status: Foreign device configurations are being ignored\n");
428 /* FIB should be freed only after getting the response from the F/W */
429 if (status != -ERESTARTSYS)
430 aac_fib_free(fibptr);
434 static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
437 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
438 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
440 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
445 * aac_get_containers - list containers
446 * @dev: aac driver data
448 * Make a list of all containers on this controller
450 int aac_get_containers(struct aac_dev *dev)
452 struct fsa_dev_info *fsa_dev_ptr;
456 struct aac_get_container_count *dinfo;
457 struct aac_get_container_count_resp *dresp;
458 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
460 if (!(fibptr = aac_fib_alloc(dev)))
463 aac_fib_init(fibptr);
464 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
465 dinfo->command = cpu_to_le32(VM_ContainerConfig);
466 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
468 status = aac_fib_send(ContainerCommand,
470 sizeof (struct aac_get_container_count),
475 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
476 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
477 if (fibptr->dev->supplement_adapter_info.supported_options2 &
478 AAC_OPTION_SUPPORTED_240_VOLUMES) {
479 maximum_num_containers =
480 le32_to_cpu(dresp->MaxSimpleVolumes);
482 aac_fib_complete(fibptr);
484 /* FIB should be freed only after getting the response from the F/W */
485 if (status != -ERESTARTSYS)
486 aac_fib_free(fibptr);
488 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
489 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
490 if (dev->fsa_dev == NULL ||
491 dev->maximum_num_containers != maximum_num_containers) {
493 fsa_dev_ptr = dev->fsa_dev;
495 dev->fsa_dev = kcalloc(maximum_num_containers,
496 sizeof(*fsa_dev_ptr), GFP_KERNEL);
505 dev->maximum_num_containers = maximum_num_containers;
507 for (index = 0; index < dev->maximum_num_containers; index++) {
508 dev->fsa_dev[index].devname[0] = '\0';
509 dev->fsa_dev[index].valid = 0;
511 status = aac_probe_container(dev, index);
514 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
521 static void get_container_name_callback(void *context, struct fib * fibptr)
523 struct aac_get_name_resp * get_name_reply;
524 struct scsi_cmnd * scsicmd;
526 scsicmd = (struct scsi_cmnd *) context;
528 if (!aac_valid_context(scsicmd, fibptr))
531 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
532 BUG_ON(fibptr == NULL);
534 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
535 /* Failure is irrelevant, using default value instead */
536 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
537 && (get_name_reply->data[0] != '\0')) {
538 char *sp = get_name_reply->data;
539 int data_size = sizeof_field(struct aac_get_name_resp, data);
541 sp[data_size - 1] = '\0';
545 struct inquiry_data inq;
546 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
547 int count = sizeof(d);
550 *dp++ = (*sp) ? *sp++ : ' ';
551 } while (--count > 0);
553 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
554 memcpy(inq.inqd_pid, d, sizeof(d));
555 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
559 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
561 aac_fib_complete(fibptr);
562 scsicmd->scsi_done(scsicmd);
566 * aac_get_container_name - get container name, none blocking.
568 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
572 struct aac_get_name *dinfo;
573 struct fib * cmd_fibcontext;
574 struct aac_dev * dev;
576 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
578 data_size = sizeof_field(struct aac_get_name_resp, data);
580 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
582 aac_fib_init(cmd_fibcontext);
583 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
584 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
586 dinfo->command = cpu_to_le32(VM_ContainerConfig);
587 dinfo->type = cpu_to_le32(CT_READ_NAME);
588 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
589 dinfo->count = cpu_to_le32(data_size - 1);
591 status = aac_fib_send(ContainerCommand,
593 sizeof(struct aac_get_name_resp),
596 (fib_callback)get_container_name_callback,
600 * Check that the command queued to the controller
602 if (status == -EINPROGRESS)
605 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
606 aac_fib_complete(cmd_fibcontext);
610 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
612 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
614 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
615 return aac_scsi_cmd(scsicmd);
617 scsicmd->result = DID_NO_CONNECT << 16;
618 scsicmd->scsi_done(scsicmd);
622 static void _aac_probe_container2(void * context, struct fib * fibptr)
624 struct fsa_dev_info *fsa_dev_ptr;
625 int (*callback)(struct scsi_cmnd *);
626 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
630 if (!aac_valid_context(scsicmd, fibptr))
633 scsicmd->SCp.Status = 0;
634 fsa_dev_ptr = fibptr->dev->fsa_dev;
636 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
639 fsa_dev_ptr += scmd_id(scsicmd);
641 fibptr->dev->supplement_adapter_info.supported_options2;
643 if ((le32_to_cpu(dresp->status) == ST_OK) &&
644 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
645 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
646 if (!(sup_options2 & AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
647 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
648 fsa_dev_ptr->block_size = 0x200;
650 fsa_dev_ptr->block_size =
651 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
653 for (i = 0; i < 16; i++)
654 fsa_dev_ptr->identifier[i] =
655 dresp->mnt[0].fileinfo.bdevinfo
657 fsa_dev_ptr->valid = 1;
658 /* sense_key holds the current state of the spin-up */
659 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
660 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
661 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
662 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
663 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
665 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
666 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
667 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
669 if ((fsa_dev_ptr->valid & 1) == 0)
670 fsa_dev_ptr->valid = 0;
671 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
673 aac_fib_complete(fibptr);
674 aac_fib_free(fibptr);
675 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
676 scsicmd->SCp.ptr = NULL;
677 (*callback)(scsicmd);
681 static void _aac_probe_container1(void * context, struct fib * fibptr)
683 struct scsi_cmnd * scsicmd;
684 struct aac_mount * dresp;
685 struct aac_query_mount *dinfo;
688 dresp = (struct aac_mount *) fib_data(fibptr);
689 if (!aac_supports_2T(fibptr->dev)) {
690 dresp->mnt[0].capacityhigh = 0;
691 if ((le32_to_cpu(dresp->status) == ST_OK) &&
692 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
693 _aac_probe_container2(context, fibptr);
697 scsicmd = (struct scsi_cmnd *) context;
699 if (!aac_valid_context(scsicmd, fibptr))
702 aac_fib_init(fibptr);
704 dinfo = (struct aac_query_mount *)fib_data(fibptr);
706 if (fibptr->dev->supplement_adapter_info.supported_options2 &
707 AAC_OPTION_VARIABLE_BLOCK_SIZE)
708 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
710 dinfo->command = cpu_to_le32(VM_NameServe64);
712 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
713 dinfo->type = cpu_to_le32(FT_FILESYS);
714 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
716 status = aac_fib_send(ContainerCommand,
718 sizeof(struct aac_query_mount),
721 _aac_probe_container2,
724 * Check that the command queued to the controller
726 if (status < 0 && status != -EINPROGRESS) {
727 /* Inherit results from VM_NameServe, if any */
728 dresp->status = cpu_to_le32(ST_OK);
729 _aac_probe_container2(context, fibptr);
733 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
736 int status = -ENOMEM;
738 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
739 struct aac_query_mount *dinfo;
741 aac_fib_init(fibptr);
743 dinfo = (struct aac_query_mount *)fib_data(fibptr);
745 if (fibptr->dev->supplement_adapter_info.supported_options2 &
746 AAC_OPTION_VARIABLE_BLOCK_SIZE)
747 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
749 dinfo->command = cpu_to_le32(VM_NameServe);
751 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
752 dinfo->type = cpu_to_le32(FT_FILESYS);
753 scsicmd->SCp.ptr = (char *)callback;
754 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
756 status = aac_fib_send(ContainerCommand,
758 sizeof(struct aac_query_mount),
761 _aac_probe_container1,
764 * Check that the command queued to the controller
766 if (status == -EINPROGRESS)
770 scsicmd->SCp.ptr = NULL;
771 aac_fib_complete(fibptr);
772 aac_fib_free(fibptr);
776 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
778 fsa_dev_ptr += scmd_id(scsicmd);
779 if ((fsa_dev_ptr->valid & 1) == 0) {
780 fsa_dev_ptr->valid = 0;
781 return (*callback)(scsicmd);
789 * aac_probe_container_callback1 - query a logical volume
790 * @scsicmd: the scsi command block
792 * Queries the controller about the given volume. The volume information
793 * is updated in the struct fsa_dev_info structure rather than returned.
795 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
797 scsicmd->device = NULL;
801 static void aac_probe_container_scsi_done(struct scsi_cmnd *scsi_cmnd)
803 aac_probe_container_callback1(scsi_cmnd);
806 int aac_probe_container(struct aac_dev *dev, int cid)
808 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
809 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
812 if (!scsicmd || !scsidev) {
817 scsicmd->scsi_done = aac_probe_container_scsi_done;
819 scsicmd->device = scsidev;
820 scsidev->sdev_state = 0;
822 scsidev->host = dev->scsi_host_ptr;
824 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
825 while (scsicmd->device == scsidev)
828 status = scsicmd->SCp.Status;
833 /* Local Structure to set SCSI inquiry data strings */
835 char vid[8]; /* Vendor ID */
836 char pid[16]; /* Product ID */
837 char prl[4]; /* Product Revision Level */
841 * inqstrcpy - string merge
842 * @a: string to copy from
843 * @b: string to copy to
845 * Copy a String from one location to another
849 static void inqstrcpy(char *a, char *b)
852 while (*a != (char)0)
856 static char *container_types[] = {
880 char * get_container_type(unsigned tindex)
882 if (tindex >= ARRAY_SIZE(container_types))
883 tindex = ARRAY_SIZE(container_types) - 1;
884 return container_types[tindex];
887 /* Function: setinqstr
889 * Arguments: [1] pointer to void [1] int
891 * Purpose: Sets SCSI inquiry data strings for vendor, product
892 * and revision level. Allows strings to be set in platform dependent
893 * files instead of in OS dependent driver source.
896 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
898 struct scsi_inq *str;
899 struct aac_supplement_adapter_info *sup_adap_info;
901 sup_adap_info = &dev->supplement_adapter_info;
902 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
903 memset(str, ' ', sizeof(*str));
905 if (sup_adap_info->adapter_type_text[0]) {
908 char *cname = kmemdup(sup_adap_info->adapter_type_text,
909 sizeof(sup_adap_info->adapter_type_text),
915 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
916 inqstrcpy("SMC", str->vid);
918 c = sizeof(str->vid);
919 while (*cp && *cp != ' ' && --c)
923 inqstrcpy(cname, str->vid);
925 while (*cp && *cp != ' ')
930 /* last six chars reserved for vol type */
931 if (strlen(cp) > sizeof(str->pid))
932 cp[sizeof(str->pid)] = '\0';
933 inqstrcpy (cp, str->pid);
937 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
939 inqstrcpy (mp->vname, str->vid);
940 /* last six chars reserved for vol type */
941 inqstrcpy (mp->model, str->pid);
944 if (tindex < ARRAY_SIZE(container_types)){
945 char *findit = str->pid;
947 for ( ; *findit != ' '; findit++); /* walk till we find a space */
948 /* RAID is superfluous in the context of a RAID device */
949 if (memcmp(findit-4, "RAID", 4) == 0)
950 *(findit -= 4) = ' ';
951 if (((findit - str->pid) + strlen(container_types[tindex]))
952 < (sizeof(str->pid) + sizeof(str->prl)))
953 inqstrcpy (container_types[tindex], findit + 1);
955 inqstrcpy ("V1.0", str->prl);
958 static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
959 struct aac_dev *dev, struct scsi_cmnd *scsicmd)
963 vpdpage83data->type3.codeset = 1;
964 vpdpage83data->type3.identifiertype = 3;
965 vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
968 for (container = 0; container < dev->maximum_num_containers;
971 if (scmd_id(scsicmd) == container) {
972 memcpy(vpdpage83data->type3.Identifier,
973 dev->fsa_dev[container].identifier,
980 static void get_container_serial_callback(void *context, struct fib * fibptr)
982 struct aac_get_serial_resp * get_serial_reply;
983 struct scsi_cmnd * scsicmd;
985 BUG_ON(fibptr == NULL);
987 scsicmd = (struct scsi_cmnd *) context;
988 if (!aac_valid_context(scsicmd, fibptr))
991 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
992 /* Failure is irrelevant, using default value instead */
993 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
994 /*Check to see if it's for VPD 0x83 or 0x80 */
995 if (scsicmd->cmnd[2] == 0x83) {
996 /* vpd page 0x83 - Device Identification Page */
999 struct tvpd_page83 vpdpage83data;
1001 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1003 memset(((u8 *)&vpdpage83data), 0,
1004 sizeof(vpdpage83data));
1006 /* DIRECT_ACCESS_DEVIC */
1007 vpdpage83data.DeviceType = 0;
1008 /* DEVICE_CONNECTED */
1009 vpdpage83data.DeviceTypeQualifier = 0;
1010 /* VPD_DEVICE_IDENTIFIERS */
1011 vpdpage83data.PageCode = 0x83;
1012 vpdpage83data.reserved = 0;
1013 vpdpage83data.PageLength =
1014 sizeof(vpdpage83data.type1) +
1015 sizeof(vpdpage83data.type2);
1017 /* VPD 83 Type 3 is not supported for ARC */
1018 if (dev->sa_firmware)
1019 vpdpage83data.PageLength +=
1020 sizeof(vpdpage83data.type3);
1022 /* T10 Vendor Identifier Field Format */
1023 /* VpdcodesetAscii */
1024 vpdpage83data.type1.codeset = 2;
1025 /* VpdIdentifierTypeVendorId */
1026 vpdpage83data.type1.identifiertype = 1;
1027 vpdpage83data.type1.identifierlength =
1028 sizeof(vpdpage83data.type1) - 4;
1030 /* "ADAPTEC " for adaptec */
1031 memcpy(vpdpage83data.type1.venid,
1033 sizeof(vpdpage83data.type1.venid));
1034 memcpy(vpdpage83data.type1.productid,
1037 vpdpage83data.type1.productid));
1039 /* Convert to ascii based serial number.
1040 * The LSB is the the end.
1042 for (i = 0; i < 8; i++) {
1044 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
1046 vpdpage83data.type1.serialnumber[i] =
1049 vpdpage83data.type1.serialnumber[i] =
1054 /* VpdCodeSetBinary */
1055 vpdpage83data.type2.codeset = 1;
1056 /* VpdidentifiertypeEUI64 */
1057 vpdpage83data.type2.identifiertype = 2;
1058 vpdpage83data.type2.identifierlength =
1059 sizeof(vpdpage83data.type2) - 4;
1061 vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1062 vpdpage83data.type2.eu64id.venid[1] = 0;
1063 vpdpage83data.type2.eu64id.venid[2] = 0;
1065 vpdpage83data.type2.eu64id.Serial =
1066 get_serial_reply->uid;
1067 vpdpage83data.type2.eu64id.reserved = 0;
1070 * VpdIdentifierTypeFCPHName
1071 * VPD 0x83 Type 3 not supported for ARC
1073 if (dev->sa_firmware) {
1074 build_vpd83_type3(&vpdpage83data,
1078 /* Move the inquiry data to the response buffer. */
1079 scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1080 sizeof(vpdpage83data));
1082 /* It must be for VPD 0x80 */
1085 sp[0] = INQD_PDT_DA;
1086 sp[1] = scsicmd->cmnd[2];
1088 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1089 le32_to_cpu(get_serial_reply->uid));
1090 scsi_sg_copy_from_buffer(scsicmd, sp,
1095 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
1097 aac_fib_complete(fibptr);
1098 scsicmd->scsi_done(scsicmd);
1102 * aac_get_container_serial - get container serial, none blocking.
1104 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1107 struct aac_get_serial *dinfo;
1108 struct fib * cmd_fibcontext;
1109 struct aac_dev * dev;
1111 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1113 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
1115 aac_fib_init(cmd_fibcontext);
1116 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1118 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1119 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1120 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1121 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1123 status = aac_fib_send(ContainerCommand,
1125 sizeof(struct aac_get_serial_resp),
1128 (fib_callback) get_container_serial_callback,
1132 * Check that the command queued to the controller
1134 if (status == -EINPROGRESS)
1137 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1138 aac_fib_complete(cmd_fibcontext);
1142 /* Function: setinqserial
1144 * Arguments: [1] pointer to void [1] int
1146 * Purpose: Sets SCSI Unit Serial number.
1147 * This is a fake. We should read a proper
1148 * serial number from the container. <SuSE>But
1149 * without docs it's quite hard to do it :-)
1150 * So this will have to do in the meantime.</SuSE>
1153 static int setinqserial(struct aac_dev *dev, void *data, int cid)
1156 * This breaks array migration.
1158 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1159 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1162 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1163 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
1165 u8 *sense_buf = (u8 *)sense_data;
1166 /* Sense data valid, err code 70h */
1167 sense_buf[0] = 0x70; /* No info field */
1168 sense_buf[1] = 0; /* Segment number, always zero */
1170 sense_buf[2] = sense_key; /* Sense key */
1172 sense_buf[12] = sense_code; /* Additional sense code */
1173 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
1175 if (sense_key == ILLEGAL_REQUEST) {
1176 sense_buf[7] = 10; /* Additional sense length */
1178 sense_buf[15] = bit_pointer;
1179 /* Illegal parameter is in the parameter block */
1180 if (sense_code == SENCODE_INVALID_CDB_FIELD)
1181 sense_buf[15] |= 0xc0;/* Std sense key specific field */
1182 /* Illegal parameter is in the CDB block */
1183 sense_buf[16] = field_pointer >> 8; /* MSB */
1184 sense_buf[17] = field_pointer; /* LSB */
1186 sense_buf[7] = 6; /* Additional sense length */
1189 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1191 if (lba & 0xffffffff00000000LL) {
1192 int cid = scmd_id(cmd);
1193 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1194 cmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
1195 set_sense(&dev->fsa_dev[cid].sense_data,
1196 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1197 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1198 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1199 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1200 SCSI_SENSE_BUFFERSIZE));
1201 cmd->scsi_done(cmd);
1207 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1212 static void io_callback(void *context, struct fib * fibptr);
1214 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1216 struct aac_dev *dev = fib->dev;
1217 u16 fibsize, command;
1221 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1222 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1224 struct aac_raw_io2 *readcmd2;
1225 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1226 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1227 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1228 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1229 readcmd2->byteCount = cpu_to_le32(count *
1230 dev->fsa_dev[scmd_id(cmd)].block_size);
1231 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1232 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
1233 ret = aac_build_sgraw2(cmd, readcmd2,
1234 dev->scsi_host_ptr->sg_tablesize);
1237 command = ContainerRawIo2;
1238 fibsize = struct_size(readcmd2, sge,
1239 le32_to_cpu(readcmd2->sgeCnt));
1241 struct aac_raw_io *readcmd;
1242 readcmd = (struct aac_raw_io *) fib_data(fib);
1243 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1244 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1245 readcmd->count = cpu_to_le32(count *
1246 dev->fsa_dev[scmd_id(cmd)].block_size);
1247 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1248 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1249 readcmd->bpTotal = 0;
1250 readcmd->bpComplete = 0;
1251 ret = aac_build_sgraw(cmd, &readcmd->sg);
1254 command = ContainerRawIo;
1255 fibsize = sizeof(struct aac_raw_io) +
1256 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1259 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1261 * Now send the Fib to the adapter
1263 return aac_fib_send(command,
1268 (fib_callback) io_callback,
1272 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1275 struct aac_read64 *readcmd;
1279 readcmd = (struct aac_read64 *) fib_data(fib);
1280 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1281 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1282 readcmd->sector_count = cpu_to_le16(count);
1283 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1287 ret = aac_build_sg64(cmd, &readcmd->sg);
1290 fibsize = sizeof(struct aac_read64) +
1291 ((le32_to_cpu(readcmd->sg.count) - 1) *
1292 sizeof (struct sgentry64));
1293 BUG_ON (fibsize > (fib->dev->max_fib_size -
1294 sizeof(struct aac_fibhdr)));
1296 * Now send the Fib to the adapter
1298 return aac_fib_send(ContainerCommand64,
1303 (fib_callback) io_callback,
1307 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1310 struct aac_read *readcmd;
1311 struct aac_dev *dev = fib->dev;
1315 readcmd = (struct aac_read *) fib_data(fib);
1316 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1317 readcmd->cid = cpu_to_le32(scmd_id(cmd));
1318 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1319 readcmd->count = cpu_to_le32(count *
1320 dev->fsa_dev[scmd_id(cmd)].block_size);
1322 ret = aac_build_sg(cmd, &readcmd->sg);
1325 fibsize = sizeof(struct aac_read) +
1326 ((le32_to_cpu(readcmd->sg.count) - 1) *
1327 sizeof (struct sgentry));
1328 BUG_ON (fibsize > (fib->dev->max_fib_size -
1329 sizeof(struct aac_fibhdr)));
1331 * Now send the Fib to the adapter
1333 return aac_fib_send(ContainerCommand,
1338 (fib_callback) io_callback,
1342 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1344 struct aac_dev *dev = fib->dev;
1345 u16 fibsize, command;
1349 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1350 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1352 struct aac_raw_io2 *writecmd2;
1353 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1354 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1355 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1356 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1357 writecmd2->byteCount = cpu_to_le32(count *
1358 dev->fsa_dev[scmd_id(cmd)].block_size);
1359 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1360 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1361 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1362 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1363 cpu_to_le16(RIO2_IO_TYPE_WRITE);
1364 ret = aac_build_sgraw2(cmd, writecmd2,
1365 dev->scsi_host_ptr->sg_tablesize);
1368 command = ContainerRawIo2;
1369 fibsize = struct_size(writecmd2, sge,
1370 le32_to_cpu(writecmd2->sgeCnt));
1372 struct aac_raw_io *writecmd;
1373 writecmd = (struct aac_raw_io *) fib_data(fib);
1374 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1375 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1376 writecmd->count = cpu_to_le32(count *
1377 dev->fsa_dev[scmd_id(cmd)].block_size);
1378 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1379 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1380 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1381 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1382 cpu_to_le16(RIO_TYPE_WRITE);
1383 writecmd->bpTotal = 0;
1384 writecmd->bpComplete = 0;
1385 ret = aac_build_sgraw(cmd, &writecmd->sg);
1388 command = ContainerRawIo;
1389 fibsize = sizeof(struct aac_raw_io) +
1390 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1393 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1395 * Now send the Fib to the adapter
1397 return aac_fib_send(command,
1402 (fib_callback) io_callback,
1406 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1409 struct aac_write64 *writecmd;
1413 writecmd = (struct aac_write64 *) fib_data(fib);
1414 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1415 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1416 writecmd->sector_count = cpu_to_le16(count);
1417 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1419 writecmd->flags = 0;
1421 ret = aac_build_sg64(cmd, &writecmd->sg);
1424 fibsize = sizeof(struct aac_write64) +
1425 ((le32_to_cpu(writecmd->sg.count) - 1) *
1426 sizeof (struct sgentry64));
1427 BUG_ON (fibsize > (fib->dev->max_fib_size -
1428 sizeof(struct aac_fibhdr)));
1430 * Now send the Fib to the adapter
1432 return aac_fib_send(ContainerCommand64,
1437 (fib_callback) io_callback,
1441 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1444 struct aac_write *writecmd;
1445 struct aac_dev *dev = fib->dev;
1449 writecmd = (struct aac_write *) fib_data(fib);
1450 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1451 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1452 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1453 writecmd->count = cpu_to_le32(count *
1454 dev->fsa_dev[scmd_id(cmd)].block_size);
1455 writecmd->sg.count = cpu_to_le32(1);
1456 /* ->stable is not used - it did mean which type of write */
1458 ret = aac_build_sg(cmd, &writecmd->sg);
1461 fibsize = sizeof(struct aac_write) +
1462 ((le32_to_cpu(writecmd->sg.count) - 1) *
1463 sizeof (struct sgentry));
1464 BUG_ON (fibsize > (fib->dev->max_fib_size -
1465 sizeof(struct aac_fibhdr)));
1467 * Now send the Fib to the adapter
1469 return aac_fib_send(ContainerCommand,
1474 (fib_callback) io_callback,
1478 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1480 struct aac_srb * srbcmd;
1483 struct aac_dev *dev = fib->dev;
1486 switch(cmd->sc_data_direction){
1490 case DMA_BIDIRECTIONAL:
1491 flag = SRB_DataIn | SRB_DataOut;
1493 case DMA_FROM_DEVICE:
1497 default: /* shuts up some versions of gcc */
1498 flag = SRB_NoDataXfer;
1502 srbcmd = (struct aac_srb*) fib_data(fib);
1503 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1504 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1505 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1506 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1507 srbcmd->flags = cpu_to_le32(flag);
1508 timeout = cmd->request->timeout/HZ;
1510 timeout = (dev->sa_firmware ? AAC_SA_TIMEOUT : AAC_ARC_TIMEOUT);
1511 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1512 srbcmd->retry_limit = 0; /* Obsolete parameter */
1513 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1517 static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
1518 struct scsi_cmnd *cmd)
1520 struct aac_hba_cmd_req *hbacmd;
1521 struct aac_dev *dev;
1525 dev = (struct aac_dev *)cmd->device->host->hostdata;
1527 hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
1528 memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
1529 /* iu_type is a parameter of aac_hba_send */
1530 switch (cmd->sc_data_direction) {
1534 case DMA_FROM_DEVICE:
1535 case DMA_BIDIRECTIONAL:
1542 hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
1544 bus = aac_logical_to_phys(scmd_channel(cmd));
1545 target = scmd_id(cmd);
1546 hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
1548 /* we fill in reply_qid later in aac_src_deliver_message */
1549 /* we fill in iu_type, request_id later in aac_hba_send */
1550 /* we fill in emb_data_desc_count later in aac_build_sghba */
1552 memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
1553 hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
1555 address = (u64)fib->hw_error_pa;
1556 hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
1557 hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
1558 hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
1563 static void aac_srb_callback(void *context, struct fib * fibptr);
1565 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1568 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1571 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1574 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1576 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1577 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1579 * Build Scatter/Gather list
1581 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1582 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1583 sizeof (struct sgentry64));
1584 BUG_ON (fibsize > (fib->dev->max_fib_size -
1585 sizeof(struct aac_fibhdr)));
1588 * Now send the Fib to the adapter
1590 return aac_fib_send(ScsiPortCommand64, fib,
1591 fibsize, FsaNormal, 0, 1,
1592 (fib_callback) aac_srb_callback,
1596 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1599 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1602 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1605 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1607 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1608 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1610 * Build Scatter/Gather list
1612 fibsize = sizeof (struct aac_srb) +
1613 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1614 sizeof (struct sgentry));
1615 BUG_ON (fibsize > (fib->dev->max_fib_size -
1616 sizeof(struct aac_fibhdr)));
1619 * Now send the Fib to the adapter
1621 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1622 (fib_callback) aac_srb_callback, (void *) cmd);
1625 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1627 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1628 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1630 return aac_scsi_32(fib, cmd);
1633 static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
1635 struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
1636 struct aac_dev *dev;
1639 dev = (struct aac_dev *)cmd->device->host->hostdata;
1641 ret = aac_build_sghba(cmd, hbacmd,
1642 dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
1647 * Now send the HBA command to the adapter
1649 fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
1650 sizeof(struct aac_hba_sgl);
1652 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
1653 (fib_callback) aac_hba_callback,
1657 static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
1658 struct aac_srb_unit *srbu, void *xfer_buf, int xfer_len)
1664 struct aac_srb *srb;
1665 struct aac_srb_reply *srb_reply;
1666 struct sgmap64 *sg64;
1670 if (!dev->sa_firmware)
1674 fibptr = aac_fib_alloc(dev);
1678 aac_fib_init(fibptr);
1679 fibptr->hw_fib_va->header.XferState &=
1680 ~cpu_to_le32(FastResponseCapable);
1682 fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
1683 sizeof(struct sgentry64);
1685 /* allocate DMA buffer for response */
1686 addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
1688 if (dma_mapping_error(&dev->pdev->dev, addr)) {
1693 srb = fib_data(fibptr);
1694 memcpy(srb, &srbu->srb, sizeof(struct aac_srb));
1696 vbus = (u32)le16_to_cpu(
1697 dev->supplement_adapter_info.virt_device_bus);
1698 vid = (u32)le16_to_cpu(
1699 dev->supplement_adapter_info.virt_device_target);
1701 /* set the common request fields */
1702 srb->channel = cpu_to_le32(vbus);
1703 srb->id = cpu_to_le32(vid);
1705 srb->function = cpu_to_le32(SRBF_ExecuteScsi);
1707 srb->retry_limit = 0;
1708 srb->cdb_size = cpu_to_le32(16);
1709 srb->count = cpu_to_le32(xfer_len);
1711 sg64 = (struct sgmap64 *)&srb->sg;
1712 sg64->count = cpu_to_le32(1);
1713 sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
1714 sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
1715 sg64->sg[0].count = cpu_to_le32(xfer_len);
1718 * Copy the updated data for other dumping or other usage if needed
1720 memcpy(&srbu->srb, srb, sizeof(struct aac_srb));
1722 /* issue request to the controller */
1723 rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize, FsaNormal,
1726 if (rcode == -ERESTARTSYS)
1729 if (unlikely(rcode < 0))
1732 srb_reply = (struct aac_srb_reply *)fib_data(fibptr);
1733 memcpy(&srbu->srb_reply, srb_reply, sizeof(struct aac_srb_reply));
1736 dma_unmap_single(&dev->pdev->dev, addr, xfer_len, DMA_BIDIRECTIONAL);
1738 aac_fib_complete(fibptr);
1739 aac_fib_free(fibptr);
1743 static void aac_set_safw_target_qd(struct aac_dev *dev, int bus, int target)
1746 struct aac_ciss_identify_pd *identify_resp;
1748 if (dev->hba_map[bus][target].devtype != AAC_DEVTYPE_NATIVE_RAW)
1751 identify_resp = dev->hba_map[bus][target].safw_identify_resp;
1752 if (identify_resp == NULL) {
1753 dev->hba_map[bus][target].qd_limit = 32;
1757 if (identify_resp->current_queue_depth_limit <= 0 ||
1758 identify_resp->current_queue_depth_limit > 255)
1759 dev->hba_map[bus][target].qd_limit = 32;
1761 dev->hba_map[bus][target].qd_limit =
1762 identify_resp->current_queue_depth_limit;
1765 static int aac_issue_safw_bmic_identify(struct aac_dev *dev,
1766 struct aac_ciss_identify_pd **identify_resp, u32 bus, u32 target)
1768 int rcode = -ENOMEM;
1770 struct aac_srb_unit srbu;
1771 struct aac_srb *srbcmd;
1772 struct aac_ciss_identify_pd *identify_reply;
1774 datasize = sizeof(struct aac_ciss_identify_pd);
1775 identify_reply = kmalloc(datasize, GFP_KERNEL);
1776 if (!identify_reply)
1779 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1782 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1783 srbcmd->cdb[0] = 0x26;
1784 srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
1785 srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
1787 rcode = aac_send_safw_bmic_cmd(dev, &srbu, identify_reply, datasize);
1788 if (unlikely(rcode < 0))
1791 *identify_resp = identify_reply;
1796 kfree(identify_reply);
1800 static inline void aac_free_safw_ciss_luns(struct aac_dev *dev)
1802 kfree(dev->safw_phys_luns);
1803 dev->safw_phys_luns = NULL;
1807 * aac_get_safw_ciss_luns() - Process topology change
1808 * @dev: aac_dev structure
1810 * Execute a CISS REPORT PHYS LUNS and process the results into
1811 * the current hba_map.
1813 static int aac_get_safw_ciss_luns(struct aac_dev *dev)
1815 int rcode = -ENOMEM;
1817 struct aac_srb *srbcmd;
1818 struct aac_srb_unit srbu;
1819 struct aac_ciss_phys_luns_resp *phys_luns;
1821 datasize = sizeof(struct aac_ciss_phys_luns_resp) +
1822 (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
1823 phys_luns = kmalloc(datasize, GFP_KERNEL);
1824 if (phys_luns == NULL)
1827 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1830 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1831 srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
1832 srbcmd->cdb[1] = 2; /* extended reporting */
1833 srbcmd->cdb[8] = (u8)(datasize >> 8);
1834 srbcmd->cdb[9] = (u8)(datasize);
1836 rcode = aac_send_safw_bmic_cmd(dev, &srbu, phys_luns, datasize);
1837 if (unlikely(rcode < 0))
1840 if (phys_luns->resp_flag != 2) {
1845 dev->safw_phys_luns = phys_luns;
1854 static inline u32 aac_get_safw_phys_lun_count(struct aac_dev *dev)
1856 return get_unaligned_be32(&dev->safw_phys_luns->list_length[0])/24;
1859 static inline u32 aac_get_safw_phys_bus(struct aac_dev *dev, int lun)
1861 return dev->safw_phys_luns->lun[lun].level2[1] & 0x3f;
1864 static inline u32 aac_get_safw_phys_target(struct aac_dev *dev, int lun)
1866 return dev->safw_phys_luns->lun[lun].level2[0];
1869 static inline u32 aac_get_safw_phys_expose_flag(struct aac_dev *dev, int lun)
1871 return dev->safw_phys_luns->lun[lun].bus >> 6;
1874 static inline u32 aac_get_safw_phys_attribs(struct aac_dev *dev, int lun)
1876 return dev->safw_phys_luns->lun[lun].node_ident[9];
1879 static inline u32 aac_get_safw_phys_nexus(struct aac_dev *dev, int lun)
1881 return *((u32 *)&dev->safw_phys_luns->lun[lun].node_ident[12]);
1884 static inline void aac_free_safw_identify_resp(struct aac_dev *dev,
1885 int bus, int target)
1887 kfree(dev->hba_map[bus][target].safw_identify_resp);
1888 dev->hba_map[bus][target].safw_identify_resp = NULL;
1891 static inline void aac_free_safw_all_identify_resp(struct aac_dev *dev,
1899 luns = aac_get_safw_phys_lun_count(dev);
1901 if (luns < lun_count)
1903 else if (lun_count < 0)
1906 for (i = 0; i < lun_count; i++) {
1907 bus = aac_get_safw_phys_bus(dev, i);
1908 target = aac_get_safw_phys_target(dev, i);
1910 aac_free_safw_identify_resp(dev, bus, target);
1914 static int aac_get_safw_attr_all_targets(struct aac_dev *dev)
1921 struct aac_ciss_identify_pd *identify_resp = NULL;
1923 lun_count = aac_get_safw_phys_lun_count(dev);
1925 for (i = 0; i < lun_count; ++i) {
1927 bus = aac_get_safw_phys_bus(dev, i);
1928 target = aac_get_safw_phys_target(dev, i);
1930 rcode = aac_issue_safw_bmic_identify(dev,
1931 &identify_resp, bus, target);
1933 if (unlikely(rcode < 0))
1934 goto free_identify_resp;
1936 dev->hba_map[bus][target].safw_identify_resp = identify_resp;
1942 aac_free_safw_all_identify_resp(dev, i);
1947 * aac_set_safw_attr_all_targets- update current hba map with data from FW
1948 * @dev: aac_dev structure
1950 * Update our hba map with the information gathered from the FW
1952 static void aac_set_safw_attr_all_targets(struct aac_dev *dev)
1954 /* ok and extended reporting */
1955 u32 lun_count, nexus;
1957 u8 expose_flag, attribs;
1959 lun_count = aac_get_safw_phys_lun_count(dev);
1961 dev->scan_counter++;
1963 for (i = 0; i < lun_count; ++i) {
1965 bus = aac_get_safw_phys_bus(dev, i);
1966 target = aac_get_safw_phys_target(dev, i);
1967 expose_flag = aac_get_safw_phys_expose_flag(dev, i);
1968 attribs = aac_get_safw_phys_attribs(dev, i);
1969 nexus = aac_get_safw_phys_nexus(dev, i);
1971 if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
1974 if (expose_flag != 0) {
1975 dev->hba_map[bus][target].devtype =
1976 AAC_DEVTYPE_RAID_MEMBER;
1980 if (nexus != 0 && (attribs & 8)) {
1981 dev->hba_map[bus][target].devtype =
1982 AAC_DEVTYPE_NATIVE_RAW;
1983 dev->hba_map[bus][target].rmw_nexus =
1986 dev->hba_map[bus][target].devtype =
1987 AAC_DEVTYPE_ARC_RAW;
1989 dev->hba_map[bus][target].scan_counter = dev->scan_counter;
1991 aac_set_safw_target_qd(dev, bus, target);
1995 static int aac_setup_safw_targets(struct aac_dev *dev)
1999 rcode = aac_get_containers(dev);
2000 if (unlikely(rcode < 0))
2003 rcode = aac_get_safw_ciss_luns(dev);
2004 if (unlikely(rcode < 0))
2007 rcode = aac_get_safw_attr_all_targets(dev);
2008 if (unlikely(rcode < 0))
2009 goto free_ciss_luns;
2011 aac_set_safw_attr_all_targets(dev);
2013 aac_free_safw_all_identify_resp(dev, -1);
2015 aac_free_safw_ciss_luns(dev);
2020 int aac_setup_safw_adapter(struct aac_dev *dev)
2022 return aac_setup_safw_targets(dev);
2025 int aac_get_adapter_info(struct aac_dev* dev)
2029 u32 tmp, bus, target;
2030 struct aac_adapter_info *info;
2031 struct aac_bus_info *command;
2032 struct aac_bus_info_response *bus_info;
2034 if (!(fibptr = aac_fib_alloc(dev)))
2037 aac_fib_init(fibptr);
2038 info = (struct aac_adapter_info *) fib_data(fibptr);
2039 memset(info,0,sizeof(*info));
2041 rcode = aac_fib_send(RequestAdapterInfo,
2045 -1, 1, /* First `interrupt' command uses special wait */
2050 /* FIB should be freed only after
2051 * getting the response from the F/W */
2052 if (rcode != -ERESTARTSYS) {
2053 aac_fib_complete(fibptr);
2054 aac_fib_free(fibptr);
2058 memcpy(&dev->adapter_info, info, sizeof(*info));
2060 dev->supplement_adapter_info.virt_device_bus = 0xffff;
2061 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
2062 struct aac_supplement_adapter_info * sinfo;
2064 aac_fib_init(fibptr);
2066 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
2068 memset(sinfo,0,sizeof(*sinfo));
2070 rcode = aac_fib_send(RequestSupplementAdapterInfo,
2079 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
2080 if (rcode == -ERESTARTSYS) {
2081 fibptr = aac_fib_alloc(dev);
2088 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
2089 for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
2090 for (target = 0; target < AAC_MAX_TARGETS; target++) {
2091 dev->hba_map[bus][target].devtype = 0;
2092 dev->hba_map[bus][target].qd_limit = 0;
2100 aac_fib_init(fibptr);
2102 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
2104 memset(bus_info, 0, sizeof(*bus_info));
2106 command = (struct aac_bus_info *)bus_info;
2108 command->Command = cpu_to_le32(VM_Ioctl);
2109 command->ObjType = cpu_to_le32(FT_DRIVE);
2110 command->MethodId = cpu_to_le32(1);
2111 command->CtlCmd = cpu_to_le32(GetBusInfo);
2113 rcode = aac_fib_send(ContainerCommand,
2120 /* reasoned default */
2121 dev->maximum_num_physicals = 16;
2122 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
2123 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
2124 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
2127 if (!dev->in_reset) {
2129 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
2130 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
2136 le32_to_cpu(dev->adapter_info.kernelbuild),
2137 (int)sizeof(dev->supplement_adapter_info.build_date),
2138 dev->supplement_adapter_info.build_date);
2139 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
2140 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
2142 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2143 le32_to_cpu(dev->adapter_info.monitorbuild));
2144 tmp = le32_to_cpu(dev->adapter_info.biosrev);
2145 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
2147 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2148 le32_to_cpu(dev->adapter_info.biosbuild));
2150 if (aac_get_serial_number(
2151 shost_to_class(dev->scsi_host_ptr), buffer))
2152 printk(KERN_INFO "%s%d: serial %s",
2153 dev->name, dev->id, buffer);
2154 if (dev->supplement_adapter_info.vpd_info.tsid[0]) {
2155 printk(KERN_INFO "%s%d: TSID %.*s\n",
2157 (int)sizeof(dev->supplement_adapter_info
2159 dev->supplement_adapter_info.vpd_info.tsid);
2161 if (!aac_check_reset || ((aac_check_reset == 1) &&
2162 (dev->supplement_adapter_info.supported_options2 &
2163 AAC_OPTION_IGNORE_RESET))) {
2164 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
2165 dev->name, dev->id);
2169 dev->cache_protected = 0;
2170 dev->jbod = ((dev->supplement_adapter_info.feature_bits &
2171 AAC_FEATURE_JBOD) != 0);
2172 dev->nondasd_support = 0;
2173 dev->raid_scsi_mode = 0;
2174 if(dev->adapter_info.options & AAC_OPT_NONDASD)
2175 dev->nondasd_support = 1;
2178 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2179 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2180 * force nondasd support on. If we decide to allow the non-dasd flag
2181 * additional changes changes will have to be made to support
2182 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2183 * changed to support the new dev->raid_scsi_mode flag instead of
2184 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2185 * function aac_detect will have to be modified where it sets up the
2186 * max number of channels based on the aac->nondasd_support flag only.
2188 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
2189 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
2190 dev->nondasd_support = 1;
2191 dev->raid_scsi_mode = 1;
2193 if (dev->raid_scsi_mode != 0)
2194 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
2195 dev->name, dev->id);
2198 dev->nondasd_support = (nondasd!=0);
2199 if (dev->nondasd_support && !dev->in_reset)
2200 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
2202 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
2204 dev->dac_support = 0;
2205 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
2206 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
2208 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
2209 dev->name, dev->id);
2210 dev->dac_support = 1;
2214 dev->dac_support = (dacmode!=0);
2217 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2218 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
2219 & AAC_QUIRK_SCSI_32)) {
2220 dev->nondasd_support = 0;
2222 expose_physicals = 0;
2225 if (dev->dac_support) {
2226 if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(64))) {
2228 dev_info(&dev->pdev->dev, "64 Bit DAC enabled\n");
2229 } else if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(32))) {
2230 dev_info(&dev->pdev->dev, "DMA mask set failed, 64 Bit DAC disabled\n");
2231 dev->dac_support = 0;
2233 dev_info(&dev->pdev->dev, "No suitable DMA available\n");
2238 * Deal with configuring for the individualized limits of each packet
2241 dev->a_ops.adapter_scsi = (dev->dac_support)
2242 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
2246 if (dev->raw_io_interface) {
2247 dev->a_ops.adapter_bounds = (dev->raw_io_64)
2250 dev->a_ops.adapter_read = aac_read_raw_io;
2251 dev->a_ops.adapter_write = aac_write_raw_io;
2253 dev->a_ops.adapter_bounds = aac_bounds_32;
2254 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
2255 sizeof(struct aac_fibhdr) -
2256 sizeof(struct aac_write) + sizeof(struct sgentry)) /
2257 sizeof(struct sgentry);
2258 if (dev->dac_support) {
2259 dev->a_ops.adapter_read = aac_read_block64;
2260 dev->a_ops.adapter_write = aac_write_block64;
2262 * 38 scatter gather elements
2264 dev->scsi_host_ptr->sg_tablesize =
2265 (dev->max_fib_size -
2266 sizeof(struct aac_fibhdr) -
2267 sizeof(struct aac_write64) +
2268 sizeof(struct sgentry64)) /
2269 sizeof(struct sgentry64);
2271 dev->a_ops.adapter_read = aac_read_block;
2272 dev->a_ops.adapter_write = aac_write_block;
2274 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
2275 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
2277 * Worst case size that could cause sg overflow when
2278 * we break up SG elements that are larger than 64KB.
2279 * Would be nice if we could tell the SCSI layer what
2280 * the maximum SG element size can be. Worst case is
2281 * (sg_tablesize-1) 4KB elements with one 64KB
2283 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2285 dev->scsi_host_ptr->max_sectors =
2286 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
2289 if (!dev->sync_mode && dev->sa_firmware &&
2290 dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
2291 dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
2292 HBA_MAX_SG_SEPARATE;
2294 /* FIB should be freed only after getting the response from the F/W */
2295 if (rcode != -ERESTARTSYS) {
2296 aac_fib_complete(fibptr);
2297 aac_fib_free(fibptr);
2304 static void io_callback(void *context, struct fib * fibptr)
2306 struct aac_dev *dev;
2307 struct aac_read_reply *readreply;
2308 struct scsi_cmnd *scsicmd;
2311 scsicmd = (struct scsi_cmnd *) context;
2313 if (!aac_valid_context(scsicmd, fibptr))
2317 cid = scmd_id(scsicmd);
2319 if (nblank(dprintk(x))) {
2321 switch (scsicmd->cmnd[0]) {
2324 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2325 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2329 lba = ((u64)scsicmd->cmnd[2] << 56) |
2330 ((u64)scsicmd->cmnd[3] << 48) |
2331 ((u64)scsicmd->cmnd[4] << 40) |
2332 ((u64)scsicmd->cmnd[5] << 32) |
2333 ((u64)scsicmd->cmnd[6] << 24) |
2334 (scsicmd->cmnd[7] << 16) |
2335 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2339 lba = ((u64)scsicmd->cmnd[2] << 24) |
2340 (scsicmd->cmnd[3] << 16) |
2341 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2344 lba = ((u64)scsicmd->cmnd[2] << 24) |
2345 (scsicmd->cmnd[3] << 16) |
2346 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2350 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2351 smp_processor_id(), (unsigned long long)lba, jiffies);
2354 BUG_ON(fibptr == NULL);
2356 scsi_dma_unmap(scsicmd);
2358 readreply = (struct aac_read_reply *)fib_data(fibptr);
2359 switch (le32_to_cpu(readreply->status)) {
2361 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2362 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
2365 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2366 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
2367 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
2368 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2369 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2370 SCSI_SENSE_BUFFERSIZE));
2373 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2374 set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
2375 SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
2376 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2377 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2378 SCSI_SENSE_BUFFERSIZE));
2381 #ifdef AAC_DETAILED_STATUS_INFO
2382 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
2383 le32_to_cpu(readreply->status));
2385 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2386 set_sense(&dev->fsa_dev[cid].sense_data,
2387 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2388 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2389 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2390 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2391 SCSI_SENSE_BUFFERSIZE));
2394 aac_fib_complete(fibptr);
2396 scsicmd->scsi_done(scsicmd);
2399 static int aac_read(struct scsi_cmnd * scsicmd)
2404 struct aac_dev *dev;
2405 struct fib * cmd_fibcontext;
2408 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2410 * Get block address and transfer length
2412 switch (scsicmd->cmnd[0]) {
2414 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
2416 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2417 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2418 count = scsicmd->cmnd[4];
2424 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
2426 lba = ((u64)scsicmd->cmnd[2] << 56) |
2427 ((u64)scsicmd->cmnd[3] << 48) |
2428 ((u64)scsicmd->cmnd[4] << 40) |
2429 ((u64)scsicmd->cmnd[5] << 32) |
2430 ((u64)scsicmd->cmnd[6] << 24) |
2431 (scsicmd->cmnd[7] << 16) |
2432 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2433 count = (scsicmd->cmnd[10] << 24) |
2434 (scsicmd->cmnd[11] << 16) |
2435 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2438 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
2440 lba = ((u64)scsicmd->cmnd[2] << 24) |
2441 (scsicmd->cmnd[3] << 16) |
2442 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2443 count = (scsicmd->cmnd[6] << 24) |
2444 (scsicmd->cmnd[7] << 16) |
2445 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2448 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
2450 lba = ((u64)scsicmd->cmnd[2] << 24) |
2451 (scsicmd->cmnd[3] << 16) |
2452 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2453 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2457 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2458 cid = scmd_id(scsicmd);
2459 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2460 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2461 set_sense(&dev->fsa_dev[cid].sense_data,
2462 ILLEGAL_REQUEST, SENCODE_LBA_OUT_OF_RANGE,
2463 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2464 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2465 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2466 SCSI_SENSE_BUFFERSIZE));
2467 scsicmd->scsi_done(scsicmd);
2471 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
2472 smp_processor_id(), (unsigned long long)lba, jiffies));
2473 if (aac_adapter_bounds(dev,scsicmd,lba))
2476 * Alocate and initialize a Fib
2478 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
2479 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2480 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
2483 * Check that the command queued to the controller
2485 if (status == -EINPROGRESS)
2488 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
2490 * For some reason, the Fib didn't queue, return QUEUE_FULL
2492 scsicmd->result = DID_OK << 16 | SAM_STAT_TASK_SET_FULL;
2493 scsicmd->scsi_done(scsicmd);
2494 aac_fib_complete(cmd_fibcontext);
2495 aac_fib_free(cmd_fibcontext);
2499 static int aac_write(struct scsi_cmnd * scsicmd)
2505 struct aac_dev *dev;
2506 struct fib * cmd_fibcontext;
2509 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2511 * Get block address and transfer length
2513 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
2515 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2516 count = scsicmd->cmnd[4];
2520 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
2521 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
2523 lba = ((u64)scsicmd->cmnd[2] << 56) |
2524 ((u64)scsicmd->cmnd[3] << 48) |
2525 ((u64)scsicmd->cmnd[4] << 40) |
2526 ((u64)scsicmd->cmnd[5] << 32) |
2527 ((u64)scsicmd->cmnd[6] << 24) |
2528 (scsicmd->cmnd[7] << 16) |
2529 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2530 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2531 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2532 fua = scsicmd->cmnd[1] & 0x8;
2533 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
2534 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
2536 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2537 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2538 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2539 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2540 fua = scsicmd->cmnd[1] & 0x8;
2542 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
2543 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2544 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2545 fua = scsicmd->cmnd[1] & 0x8;
2548 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2549 cid = scmd_id(scsicmd);
2550 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2551 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2552 set_sense(&dev->fsa_dev[cid].sense_data,
2553 ILLEGAL_REQUEST, SENCODE_LBA_OUT_OF_RANGE,
2554 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2555 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2556 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2557 SCSI_SENSE_BUFFERSIZE));
2558 scsicmd->scsi_done(scsicmd);
2562 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2563 smp_processor_id(), (unsigned long long)lba, jiffies));
2564 if (aac_adapter_bounds(dev,scsicmd,lba))
2567 * Allocate and initialize a Fib then setup a BlockWrite command
2569 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
2570 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2571 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
2574 * Check that the command queued to the controller
2576 if (status == -EINPROGRESS)
2579 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
2581 * For some reason, the Fib didn't queue, return QUEUE_FULL
2583 scsicmd->result = DID_OK << 16 | SAM_STAT_TASK_SET_FULL;
2584 scsicmd->scsi_done(scsicmd);
2586 aac_fib_complete(cmd_fibcontext);
2587 aac_fib_free(cmd_fibcontext);
2591 static void synchronize_callback(void *context, struct fib *fibptr)
2593 struct aac_synchronize_reply *synchronizereply;
2594 struct scsi_cmnd *cmd = context;
2596 if (!aac_valid_context(cmd, fibptr))
2599 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
2600 smp_processor_id(), jiffies));
2601 BUG_ON(fibptr == NULL);
2604 synchronizereply = fib_data(fibptr);
2605 if (le32_to_cpu(synchronizereply->status) == CT_OK)
2606 cmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2608 struct scsi_device *sdev = cmd->device;
2609 struct aac_dev *dev = fibptr->dev;
2610 u32 cid = sdev_id(sdev);
2612 "synchronize_callback: synchronize failed, status = %d\n",
2613 le32_to_cpu(synchronizereply->status));
2614 cmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2615 set_sense(&dev->fsa_dev[cid].sense_data,
2616 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2617 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2618 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2619 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2620 SCSI_SENSE_BUFFERSIZE));
2623 aac_fib_complete(fibptr);
2624 aac_fib_free(fibptr);
2625 cmd->scsi_done(cmd);
2628 static int aac_synchronize(struct scsi_cmnd *scsicmd)
2631 struct fib *cmd_fibcontext;
2632 struct aac_synchronize *synchronizecmd;
2633 struct scsi_device *sdev = scsicmd->device;
2634 struct aac_dev *aac;
2636 aac = (struct aac_dev *)sdev->host->hostdata;
2638 return SCSI_MLQUEUE_HOST_BUSY;
2641 * Allocate and initialize a Fib
2643 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
2645 aac_fib_init(cmd_fibcontext);
2647 synchronizecmd = fib_data(cmd_fibcontext);
2648 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2649 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
2650 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
2651 synchronizecmd->count =
2652 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2653 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2656 * Now send the Fib to the adapter
2658 status = aac_fib_send(ContainerCommand,
2660 sizeof(struct aac_synchronize),
2663 (fib_callback)synchronize_callback,
2667 * Check that the command queued to the controller
2669 if (status == -EINPROGRESS)
2673 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2674 aac_fib_complete(cmd_fibcontext);
2675 aac_fib_free(cmd_fibcontext);
2676 return SCSI_MLQUEUE_HOST_BUSY;
2679 static void aac_start_stop_callback(void *context, struct fib *fibptr)
2681 struct scsi_cmnd *scsicmd = context;
2683 if (!aac_valid_context(scsicmd, fibptr))
2686 BUG_ON(fibptr == NULL);
2688 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2690 aac_fib_complete(fibptr);
2691 aac_fib_free(fibptr);
2692 scsicmd->scsi_done(scsicmd);
2695 static int aac_start_stop(struct scsi_cmnd *scsicmd)
2698 struct fib *cmd_fibcontext;
2699 struct aac_power_management *pmcmd;
2700 struct scsi_device *sdev = scsicmd->device;
2701 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2703 if (!(aac->supplement_adapter_info.supported_options2 &
2704 AAC_OPTION_POWER_MANAGEMENT)) {
2705 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2706 scsicmd->scsi_done(scsicmd);
2711 return SCSI_MLQUEUE_HOST_BUSY;
2714 * Allocate and initialize a Fib
2716 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
2718 aac_fib_init(cmd_fibcontext);
2720 pmcmd = fib_data(cmd_fibcontext);
2721 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2722 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2723 /* Eject bit ignored, not relevant */
2724 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2725 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2726 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2727 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2728 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2729 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2732 * Now send the Fib to the adapter
2734 status = aac_fib_send(ContainerCommand,
2736 sizeof(struct aac_power_management),
2739 (fib_callback)aac_start_stop_callback,
2743 * Check that the command queued to the controller
2745 if (status == -EINPROGRESS)
2748 aac_fib_complete(cmd_fibcontext);
2749 aac_fib_free(cmd_fibcontext);
2750 return SCSI_MLQUEUE_HOST_BUSY;
2754 * aac_scsi_cmd() - Process SCSI command
2755 * @scsicmd: SCSI command block
2757 * Emulate a SCSI command and queue the required request for the
2761 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2764 struct Scsi_Host *host = scsicmd->device->host;
2765 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2766 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
2768 if (fsa_dev_ptr == NULL)
2771 * If the bus, id or lun is out of range, return fail
2772 * Test does not apply to ID 16, the pseudo id for the controller
2775 cid = scmd_id(scsicmd);
2776 if (cid != host->this_id) {
2777 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2778 if((cid >= dev->maximum_num_containers) ||
2779 (scsicmd->device->lun != 0)) {
2780 scsicmd->result = DID_NO_CONNECT << 16;
2785 * If the target container doesn't exist, it may have
2786 * been newly created
2788 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2789 (fsa_dev_ptr[cid].sense_data.sense_key ==
2791 switch (scsicmd->cmnd[0]) {
2792 case SERVICE_ACTION_IN_16:
2793 if (!(dev->raw_io_interface) ||
2794 !(dev->raw_io_64) ||
2795 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2800 case TEST_UNIT_READY:
2803 return _aac_probe_container(scsicmd,
2804 aac_probe_container_callback2);
2809 } else { /* check for physical non-dasd devices */
2810 bus = aac_logical_to_phys(scmd_channel(scsicmd));
2812 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2813 dev->hba_map[bus][cid].devtype
2814 == AAC_DEVTYPE_NATIVE_RAW) {
2817 return aac_send_hba_fib(scsicmd);
2818 } else if (dev->nondasd_support || expose_physicals ||
2822 return aac_send_srb_fib(scsicmd);
2824 scsicmd->result = DID_NO_CONNECT << 16;
2830 * else Command for the controller itself
2832 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
2833 (scsicmd->cmnd[0] != TEST_UNIT_READY))
2835 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2836 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2837 set_sense(&dev->fsa_dev[cid].sense_data,
2838 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2839 ASENCODE_INVALID_COMMAND, 0, 0);
2840 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2841 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2842 SCSI_SENSE_BUFFERSIZE));
2846 switch (scsicmd->cmnd[0]) {
2853 return aac_read(scsicmd);
2861 return aac_write(scsicmd);
2863 case SYNCHRONIZE_CACHE:
2864 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2865 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2868 /* Issue FIB to tell Firmware to flush it's cache */
2869 if ((aac_cache & 6) != 2)
2870 return aac_synchronize(scsicmd);
2874 struct inquiry_data inq_data;
2876 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
2877 memset(&inq_data, 0, sizeof (struct inquiry_data));
2879 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
2880 char *arr = (char *)&inq_data;
2883 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2884 INQD_PDT_PROC : INQD_PDT_DA;
2885 if (scsicmd->cmnd[2] == 0) {
2886 /* supported vital product data pages */
2891 arr[1] = scsicmd->cmnd[2];
2892 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2894 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2895 } else if (scsicmd->cmnd[2] == 0x80) {
2896 /* unit serial number page */
2897 arr[3] = setinqserial(dev, &arr[4],
2899 arr[1] = scsicmd->cmnd[2];
2900 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2903 return aac_get_container_serial(
2905 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2906 } else if (scsicmd->cmnd[2] == 0x83) {
2907 /* vpd page 0x83 - Device Identification Page */
2908 char *sno = (char *)&inq_data;
2909 sno[3] = setinqserial(dev, &sno[4],
2912 return aac_get_container_serial(
2914 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2916 /* vpd page not implemented */
2917 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
2918 set_sense(&dev->fsa_dev[cid].sense_data,
2919 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2920 ASENCODE_NO_SENSE, 7, 2);
2921 memcpy(scsicmd->sense_buffer,
2922 &dev->fsa_dev[cid].sense_data,
2924 sizeof(dev->fsa_dev[cid].sense_data),
2925 SCSI_SENSE_BUFFERSIZE));
2929 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
2930 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 */
2931 inq_data.inqd_len = 31;
2932 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
2933 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
2935 * Set the Vendor, Product, and Revision Level
2936 * see: <vendor>.c i.e. aac.c
2938 if (cid == host->this_id) {
2939 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
2940 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2941 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2943 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
2948 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
2949 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2950 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
2951 return aac_get_container_name(scsicmd);
2953 case SERVICE_ACTION_IN_16:
2954 if (!(dev->raw_io_interface) ||
2955 !(dev->raw_io_64) ||
2956 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2961 unsigned int alloc_len;
2963 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2964 capacity = fsa_dev_ptr[cid].size - 1;
2965 cp[0] = (capacity >> 56) & 0xff;
2966 cp[1] = (capacity >> 48) & 0xff;
2967 cp[2] = (capacity >> 40) & 0xff;
2968 cp[3] = (capacity >> 32) & 0xff;
2969 cp[4] = (capacity >> 24) & 0xff;
2970 cp[5] = (capacity >> 16) & 0xff;
2971 cp[6] = (capacity >> 8) & 0xff;
2972 cp[7] = (capacity >> 0) & 0xff;
2973 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2974 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2975 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2976 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
2979 alloc_len = ((scsicmd->cmnd[10] << 24)
2980 + (scsicmd->cmnd[11] << 16)
2981 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2983 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
2984 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
2985 if (alloc_len < scsi_bufflen(scsicmd))
2986 scsi_set_resid(scsicmd,
2987 scsi_bufflen(scsicmd) - alloc_len);
2989 /* Do not cache partition table for arrays */
2990 scsicmd->device->removable = 1;
2992 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3001 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
3002 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3003 capacity = fsa_dev_ptr[cid].size - 1;
3007 cp[0] = (capacity >> 24) & 0xff;
3008 cp[1] = (capacity >> 16) & 0xff;
3009 cp[2] = (capacity >> 8) & 0xff;
3010 cp[3] = (capacity >> 0) & 0xff;
3011 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3012 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3013 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3014 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
3015 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
3016 /* Do not cache partition table for arrays */
3017 scsicmd->device->removable = 1;
3018 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3024 int mode_buf_length = 4;
3028 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3029 capacity = fsa_dev_ptr[cid].size - 1;
3033 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
3034 memset((char *)&mpd, 0, sizeof(aac_modep_data));
3036 /* Mode data length */
3037 mpd.hd.data_length = sizeof(mpd.hd) - 1;
3038 /* Medium type - default */
3039 mpd.hd.med_type = 0;
3040 /* Device-specific param,
3041 bit 8: 0/1 = write enabled/protected
3042 bit 4: 0/1 = FUA enabled */
3045 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
3046 mpd.hd.dev_par = 0x10;
3047 if (scsicmd->cmnd[1] & 0x8)
3048 mpd.hd.bd_length = 0; /* Block descriptor length */
3050 mpd.hd.bd_length = sizeof(mpd.bd);
3051 mpd.hd.data_length += mpd.hd.bd_length;
3052 mpd.bd.block_length[0] =
3053 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3054 mpd.bd.block_length[1] =
3055 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3056 mpd.bd.block_length[2] =
3057 fsa_dev_ptr[cid].block_size & 0xff;
3059 mpd.mpc_buf[0] = scsicmd->cmnd[2];
3060 if (scsicmd->cmnd[2] == 0x1C) {
3062 mpd.mpc_buf[1] = 0xa;
3063 /* Mode data length */
3064 mpd.hd.data_length = 23;
3066 /* Mode data length */
3067 mpd.hd.data_length = 15;
3070 if (capacity > 0xffffff) {
3071 mpd.bd.block_count[0] = 0xff;
3072 mpd.bd.block_count[1] = 0xff;
3073 mpd.bd.block_count[2] = 0xff;
3075 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
3076 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
3077 mpd.bd.block_count[2] = capacity & 0xff;
3080 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3081 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
3082 mpd.hd.data_length += 3;
3085 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
3086 ? 0 : 0x04; /* WCE */
3087 mode_buf_length = sizeof(mpd);
3090 if (mode_buf_length > scsicmd->cmnd[4])
3091 mode_buf_length = scsicmd->cmnd[4];
3093 mode_buf_length = sizeof(mpd);
3094 scsi_sg_copy_from_buffer(scsicmd,
3097 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3103 int mode_buf_length = 8;
3104 aac_modep10_data mpd10;
3106 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3107 capacity = fsa_dev_ptr[cid].size - 1;
3111 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
3112 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
3113 /* Mode data length (MSB) */
3114 mpd10.hd.data_length[0] = 0;
3115 /* Mode data length (LSB) */
3116 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
3117 /* Medium type - default */
3118 mpd10.hd.med_type = 0;
3119 /* Device-specific param,
3120 bit 8: 0/1 = write enabled/protected
3121 bit 4: 0/1 = FUA enabled */
3122 mpd10.hd.dev_par = 0;
3124 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
3125 mpd10.hd.dev_par = 0x10;
3126 mpd10.hd.rsrvd[0] = 0; /* reserved */
3127 mpd10.hd.rsrvd[1] = 0; /* reserved */
3128 if (scsicmd->cmnd[1] & 0x8) {
3129 /* Block descriptor length (MSB) */
3130 mpd10.hd.bd_length[0] = 0;
3131 /* Block descriptor length (LSB) */
3132 mpd10.hd.bd_length[1] = 0;
3134 mpd10.hd.bd_length[0] = 0;
3135 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
3137 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
3139 mpd10.bd.block_length[0] =
3140 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3141 mpd10.bd.block_length[1] =
3142 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3143 mpd10.bd.block_length[2] =
3144 fsa_dev_ptr[cid].block_size & 0xff;
3146 if (capacity > 0xffffff) {
3147 mpd10.bd.block_count[0] = 0xff;
3148 mpd10.bd.block_count[1] = 0xff;
3149 mpd10.bd.block_count[2] = 0xff;
3151 mpd10.bd.block_count[0] =
3152 (capacity >> 16) & 0xff;
3153 mpd10.bd.block_count[1] =
3154 (capacity >> 8) & 0xff;
3155 mpd10.bd.block_count[2] =
3159 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3160 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
3161 mpd10.hd.data_length[1] += 3;
3162 mpd10.mpc_buf[0] = 8;
3163 mpd10.mpc_buf[1] = 1;
3164 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
3165 ? 0 : 0x04; /* WCE */
3166 mode_buf_length = sizeof(mpd10);
3167 if (mode_buf_length > scsicmd->cmnd[8])
3168 mode_buf_length = scsicmd->cmnd[8];
3170 scsi_sg_copy_from_buffer(scsicmd,
3174 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3178 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
3179 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3180 sizeof(struct sense_data));
3181 memset(&dev->fsa_dev[cid].sense_data, 0,
3182 sizeof(struct sense_data));
3183 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3186 case ALLOW_MEDIUM_REMOVAL:
3187 dprintk((KERN_DEBUG "LOCK command.\n"));
3188 if (scsicmd->cmnd[4])
3189 fsa_dev_ptr[cid].locked = 1;
3191 fsa_dev_ptr[cid].locked = 0;
3193 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3196 * These commands are all No-Ops
3198 case TEST_UNIT_READY:
3199 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
3200 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
3201 set_sense(&dev->fsa_dev[cid].sense_data,
3202 NOT_READY, SENCODE_BECOMING_READY,
3203 ASENCODE_BECOMING_READY, 0, 0);
3204 memcpy(scsicmd->sense_buffer,
3205 &dev->fsa_dev[cid].sense_data,
3207 sizeof(dev->fsa_dev[cid].sense_data),
3208 SCSI_SENSE_BUFFERSIZE));
3215 case REASSIGN_BLOCKS:
3217 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
3221 return aac_start_stop(scsicmd);
3225 * Unhandled commands
3227 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
3229 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
3230 set_sense(&dev->fsa_dev[cid].sense_data,
3231 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
3232 ASENCODE_INVALID_COMMAND, 0, 0);
3233 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3235 sizeof(dev->fsa_dev[cid].sense_data),
3236 SCSI_SENSE_BUFFERSIZE));
3241 scsicmd->scsi_done(scsicmd);
3245 static int query_disk(struct aac_dev *dev, void __user *arg)
3247 struct aac_query_disk qd;
3248 struct fsa_dev_info *fsa_dev_ptr;
3250 fsa_dev_ptr = dev->fsa_dev;
3253 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
3255 if (qd.cnum == -1) {
3256 if (qd.id < 0 || qd.id >= dev->maximum_num_containers)
3259 } else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) {
3260 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
3262 qd.instance = dev->scsi_host_ptr->host_no;
3264 qd.id = CONTAINER_TO_ID(qd.cnum);
3265 qd.lun = CONTAINER_TO_LUN(qd.cnum);
3267 else return -EINVAL;
3269 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
3270 qd.locked = fsa_dev_ptr[qd.cnum].locked;
3271 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
3273 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
3278 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
3279 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
3281 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
3286 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
3288 struct aac_delete_disk dd;
3289 struct fsa_dev_info *fsa_dev_ptr;
3291 fsa_dev_ptr = dev->fsa_dev;
3295 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3298 if (dd.cnum >= dev->maximum_num_containers)
3301 * Mark this container as being deleted.
3303 fsa_dev_ptr[dd.cnum].deleted = 1;
3305 * Mark the container as no longer valid
3307 fsa_dev_ptr[dd.cnum].valid = 0;
3311 static int delete_disk(struct aac_dev *dev, void __user *arg)
3313 struct aac_delete_disk dd;
3314 struct fsa_dev_info *fsa_dev_ptr;
3316 fsa_dev_ptr = dev->fsa_dev;
3320 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3323 if (dd.cnum >= dev->maximum_num_containers)
3326 * If the container is locked, it can not be deleted by the API.
3328 if (fsa_dev_ptr[dd.cnum].locked)
3332 * Mark the container as no longer being valid.
3334 fsa_dev_ptr[dd.cnum].valid = 0;
3335 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
3340 int aac_dev_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg)
3343 case FSACTL_QUERY_DISK:
3344 return query_disk(dev, arg);
3345 case FSACTL_DELETE_DISK:
3346 return delete_disk(dev, arg);
3347 case FSACTL_FORCE_DELETE_DISK:
3348 return force_delete_disk(dev, arg);
3349 case FSACTL_GET_CONTAINERS:
3350 return aac_get_containers(dev);
3358 * @context: the context set in the fib - here it is scsi cmd
3359 * @fibptr: pointer to the fib
3361 * Handles the completion of a scsi command to a non dasd device
3363 static void aac_srb_callback(void *context, struct fib * fibptr)
3365 struct aac_srb_reply *srbreply;
3366 struct scsi_cmnd *scsicmd;
3368 scsicmd = (struct scsi_cmnd *) context;
3370 if (!aac_valid_context(scsicmd, fibptr))
3373 BUG_ON(fibptr == NULL);
3375 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
3377 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
3379 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3381 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
3382 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
3385 * Calculate resid for sg
3387 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
3388 - le32_to_cpu(srbreply->data_xfer_length));
3392 scsi_dma_unmap(scsicmd);
3394 /* expose physical device if expose_physicald flag is on */
3395 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
3396 && expose_physicals > 0)
3397 aac_expose_phy_device(scsicmd);
3400 * First check the fib status
3403 if (le32_to_cpu(srbreply->status) != ST_OK) {
3406 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3407 le32_to_cpu(srbreply->status));
3408 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3409 SCSI_SENSE_BUFFERSIZE);
3410 scsicmd->result = DID_ERROR << 16 | SAM_STAT_CHECK_CONDITION;
3411 memcpy(scsicmd->sense_buffer,
3412 srbreply->sense_data, len);
3416 * Next check the srb status
3418 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3419 case SRB_STATUS_ERROR_RECOVERY:
3420 case SRB_STATUS_PENDING:
3421 case SRB_STATUS_SUCCESS:
3422 scsicmd->result = DID_OK << 16;
3424 case SRB_STATUS_DATA_OVERRUN:
3425 switch (scsicmd->cmnd[0]) {
3434 if (le32_to_cpu(srbreply->data_xfer_length)
3435 < scsicmd->underflow)
3436 pr_warn("aacraid: SCSI CMD underflow\n");
3438 pr_warn("aacraid: SCSI CMD Data Overrun\n");
3439 scsicmd->result = DID_ERROR << 16;
3442 scsicmd->result = DID_OK << 16;
3445 scsicmd->result = DID_OK << 16;
3449 case SRB_STATUS_ABORTED:
3450 scsicmd->result = DID_ABORT << 16;
3452 case SRB_STATUS_ABORT_FAILED:
3454 * Not sure about this one - but assuming the
3455 * hba was trying to abort for some reason
3457 scsicmd->result = DID_ERROR << 16;
3459 case SRB_STATUS_PARITY_ERROR:
3460 scsicmd->result = DID_PARITY << 16;
3462 case SRB_STATUS_NO_DEVICE:
3463 case SRB_STATUS_INVALID_PATH_ID:
3464 case SRB_STATUS_INVALID_TARGET_ID:
3465 case SRB_STATUS_INVALID_LUN:
3466 case SRB_STATUS_SELECTION_TIMEOUT:
3467 scsicmd->result = DID_NO_CONNECT << 16;
3470 case SRB_STATUS_COMMAND_TIMEOUT:
3471 case SRB_STATUS_TIMEOUT:
3472 scsicmd->result = DID_TIME_OUT << 16;
3475 case SRB_STATUS_BUSY:
3476 scsicmd->result = DID_BUS_BUSY << 16;
3479 case SRB_STATUS_BUS_RESET:
3480 scsicmd->result = DID_RESET << 16;
3483 case SRB_STATUS_MESSAGE_REJECTED:
3484 scsicmd->result = DID_ERROR << 16;
3486 case SRB_STATUS_REQUEST_FLUSHED:
3487 case SRB_STATUS_ERROR:
3488 case SRB_STATUS_INVALID_REQUEST:
3489 case SRB_STATUS_REQUEST_SENSE_FAILED:
3490 case SRB_STATUS_NO_HBA:
3491 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3492 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3493 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3494 case SRB_STATUS_DELAYED_RETRY:
3495 case SRB_STATUS_BAD_FUNCTION:
3496 case SRB_STATUS_NOT_STARTED:
3497 case SRB_STATUS_NOT_IN_USE:
3498 case SRB_STATUS_FORCE_ABORT:
3499 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3501 #ifdef AAC_DETAILED_STATUS_INFO
3502 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3503 le32_to_cpu(srbreply->srb_status) & 0x3F,
3504 aac_get_status_string(
3505 le32_to_cpu(srbreply->srb_status) & 0x3F),
3507 le32_to_cpu(srbreply->scsi_status));
3510 * When the CC bit is SET by the host in ATA pass thru CDB,
3511 * driver is supposed to return DID_OK
3513 * When the CC bit is RESET by the host, driver should
3516 if ((scsicmd->cmnd[0] == ATA_12)
3517 || (scsicmd->cmnd[0] == ATA_16)) {
3519 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3520 scsicmd->result = DID_OK << 16;
3522 scsicmd->result = DID_ERROR << 16;
3525 scsicmd->result = DID_ERROR << 16;
3529 if (le32_to_cpu(srbreply->scsi_status)
3530 == SAM_STAT_CHECK_CONDITION) {
3533 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3534 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3535 SCSI_SENSE_BUFFERSIZE);
3536 #ifdef AAC_DETAILED_STATUS_INFO
3537 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3538 le32_to_cpu(srbreply->status), len);
3540 memcpy(scsicmd->sense_buffer,
3541 srbreply->sense_data, len);
3545 * OR in the scsi status (already shifted up a bit)
3547 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3549 aac_fib_complete(fibptr);
3550 scsicmd->scsi_done(scsicmd);
3553 static void hba_resp_task_complete(struct aac_dev *dev,
3554 struct scsi_cmnd *scsicmd,
3555 struct aac_hba_resp *err) {
3557 scsicmd->result = err->status;
3558 /* set residual count */
3559 scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
3561 switch (err->status) {
3563 scsicmd->result |= DID_OK << 16;
3565 case SAM_STAT_CHECK_CONDITION:
3569 len = min_t(u8, err->sense_response_data_len,
3570 SCSI_SENSE_BUFFERSIZE);
3572 memcpy(scsicmd->sense_buffer,
3573 err->sense_response_buf, len);
3574 scsicmd->result |= DID_OK << 16;
3578 scsicmd->result |= DID_BUS_BUSY << 16;
3580 case SAM_STAT_TASK_ABORTED:
3581 scsicmd->result |= DID_ABORT << 16;
3583 case SAM_STAT_RESERVATION_CONFLICT:
3584 case SAM_STAT_TASK_SET_FULL:
3586 scsicmd->result |= DID_ERROR << 16;
3591 static void hba_resp_task_failure(struct aac_dev *dev,
3592 struct scsi_cmnd *scsicmd,
3593 struct aac_hba_resp *err)
3595 switch (err->status) {
3596 case HBA_RESP_STAT_HBAMODE_DISABLED:
3600 bus = aac_logical_to_phys(scmd_channel(scsicmd));
3601 cid = scmd_id(scsicmd);
3602 if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
3603 dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
3604 dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
3606 scsicmd->result = DID_NO_CONNECT << 16;
3609 case HBA_RESP_STAT_IO_ERROR:
3610 case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
3611 scsicmd->result = DID_OK << 16 | SAM_STAT_BUSY;
3613 case HBA_RESP_STAT_IO_ABORTED:
3614 scsicmd->result = DID_ABORT << 16;
3616 case HBA_RESP_STAT_INVALID_DEVICE:
3617 scsicmd->result = DID_NO_CONNECT << 16;
3619 case HBA_RESP_STAT_UNDERRUN:
3620 /* UNDERRUN is OK */
3621 scsicmd->result = DID_OK << 16;
3623 case HBA_RESP_STAT_OVERRUN:
3625 scsicmd->result = DID_ERROR << 16;
3632 * @context: the context set in the fib - here it is scsi cmd
3633 * @fibptr: pointer to the fib
3635 * Handles the completion of a native HBA scsi command
3637 void aac_hba_callback(void *context, struct fib *fibptr)
3639 struct aac_dev *dev;
3640 struct scsi_cmnd *scsicmd;
3642 struct aac_hba_resp *err =
3643 &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
3645 scsicmd = (struct scsi_cmnd *) context;
3647 if (!aac_valid_context(scsicmd, fibptr))
3650 WARN_ON(fibptr == NULL);
3653 if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
3654 scsi_dma_unmap(scsicmd);
3656 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3658 scsicmd->result = DID_OK << 16;
3662 switch (err->service_response) {
3663 case HBA_RESP_SVCRES_TASK_COMPLETE:
3664 hba_resp_task_complete(dev, scsicmd, err);
3666 case HBA_RESP_SVCRES_FAILURE:
3667 hba_resp_task_failure(dev, scsicmd, err);
3669 case HBA_RESP_SVCRES_TMF_REJECTED:
3670 scsicmd->result = DID_ERROR << 16;
3672 case HBA_RESP_SVCRES_TMF_LUN_INVALID:
3673 scsicmd->result = DID_NO_CONNECT << 16;
3675 case HBA_RESP_SVCRES_TMF_COMPLETE:
3676 case HBA_RESP_SVCRES_TMF_SUCCEEDED:
3677 scsicmd->result = DID_OK << 16;
3680 scsicmd->result = DID_ERROR << 16;
3685 aac_fib_complete(fibptr);
3687 if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
3688 scsicmd->SCp.sent_command = 1;
3690 scsicmd->scsi_done(scsicmd);
3695 * @scsicmd: the scsi command block
3697 * This routine will form a FIB and fill in the aac_srb from the
3698 * scsicmd passed in.
3700 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3702 struct fib* cmd_fibcontext;
3703 struct aac_dev* dev;
3706 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3707 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3708 scsicmd->device->lun > 7) {
3709 scsicmd->result = DID_NO_CONNECT << 16;
3710 scsicmd->scsi_done(scsicmd);
3715 * Allocate and initialize a Fib then setup a BlockWrite command
3717 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3718 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3719 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
3722 * Check that the command queued to the controller
3724 if (status == -EINPROGRESS)
3727 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3728 aac_fib_complete(cmd_fibcontext);
3729 aac_fib_free(cmd_fibcontext);
3736 * @scsicmd: the scsi command block
3738 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3739 * scsicmd passed in.
3741 static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
3743 struct fib *cmd_fibcontext;
3744 struct aac_dev *dev;
3747 dev = shost_priv(scsicmd->device->host);
3748 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3749 scsicmd->device->lun > AAC_MAX_LUN - 1) {
3750 scsicmd->result = DID_NO_CONNECT << 16;
3751 scsicmd->scsi_done(scsicmd);
3756 * Allocate and initialize a Fib then setup a BlockWrite command
3758 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3759 if (!cmd_fibcontext)
3762 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3763 status = aac_adapter_hba(cmd_fibcontext, scsicmd);
3766 * Check that the command queued to the controller
3768 if (status == -EINPROGRESS)
3771 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3773 aac_fib_complete(cmd_fibcontext);
3774 aac_fib_free(cmd_fibcontext);
3780 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
3782 unsigned long byte_count = 0;
3784 struct scatterlist *sg;
3787 // Get rid of old data
3789 psg->sg[0].addr = 0;
3790 psg->sg[0].count = 0;
3792 nseg = scsi_dma_map(scsicmd);
3796 psg->count = cpu_to_le32(nseg);
3798 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3799 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3800 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3801 byte_count += sg_dma_len(sg);
3803 /* hba wants the size to be exact */
3804 if (byte_count > scsi_bufflen(scsicmd)) {
3805 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3806 (byte_count - scsi_bufflen(scsicmd));
3807 psg->sg[i-1].count = cpu_to_le32(temp);
3808 byte_count = scsi_bufflen(scsicmd);
3810 /* Check for command underflow */
3811 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3812 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3813 byte_count, scsicmd->underflow);
3820 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
3822 unsigned long byte_count = 0;
3825 struct scatterlist *sg;
3828 // Get rid of old data
3830 psg->sg[0].addr[0] = 0;
3831 psg->sg[0].addr[1] = 0;
3832 psg->sg[0].count = 0;
3834 nseg = scsi_dma_map(scsicmd);
3838 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3839 int count = sg_dma_len(sg);
3840 addr = sg_dma_address(sg);
3841 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3842 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
3843 psg->sg[i].count = cpu_to_le32(count);
3844 byte_count += count;
3846 psg->count = cpu_to_le32(nseg);
3847 /* hba wants the size to be exact */
3848 if (byte_count > scsi_bufflen(scsicmd)) {
3849 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3850 (byte_count - scsi_bufflen(scsicmd));
3851 psg->sg[i-1].count = cpu_to_le32(temp);
3852 byte_count = scsi_bufflen(scsicmd);
3854 /* Check for command underflow */
3855 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3856 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3857 byte_count, scsicmd->underflow);
3863 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
3865 unsigned long byte_count = 0;
3867 struct scatterlist *sg;
3870 // Get rid of old data
3872 psg->sg[0].next = 0;
3873 psg->sg[0].prev = 0;
3874 psg->sg[0].addr[0] = 0;
3875 psg->sg[0].addr[1] = 0;
3876 psg->sg[0].count = 0;
3877 psg->sg[0].flags = 0;
3879 nseg = scsi_dma_map(scsicmd);
3883 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3884 int count = sg_dma_len(sg);
3885 u64 addr = sg_dma_address(sg);
3886 psg->sg[i].next = 0;
3887 psg->sg[i].prev = 0;
3888 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
3889 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
3890 psg->sg[i].count = cpu_to_le32(count);
3891 psg->sg[i].flags = 0;
3892 byte_count += count;
3894 psg->count = cpu_to_le32(nseg);
3895 /* hba wants the size to be exact */
3896 if (byte_count > scsi_bufflen(scsicmd)) {
3897 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3898 (byte_count - scsi_bufflen(scsicmd));
3899 psg->sg[i-1].count = cpu_to_le32(temp);
3900 byte_count = scsi_bufflen(scsicmd);
3902 /* Check for command underflow */
3903 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3904 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3905 byte_count, scsicmd->underflow);
3911 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
3912 struct aac_raw_io2 *rio2, int sg_max)
3914 unsigned long byte_count = 0;
3916 struct scatterlist *sg;
3917 int i, conformable = 0;
3918 u32 min_size = PAGE_SIZE, cur_size;
3920 nseg = scsi_dma_map(scsicmd);
3924 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3925 int count = sg_dma_len(sg);
3926 u64 addr = sg_dma_address(sg);
3928 BUG_ON(i >= sg_max);
3929 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3930 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3931 cur_size = cpu_to_le32(count);
3932 rio2->sge[i].length = cur_size;
3933 rio2->sge[i].flags = 0;
3936 rio2->sgeFirstSize = cur_size;
3937 } else if (i == 1) {
3938 rio2->sgeNominalSize = cur_size;
3939 min_size = cur_size;
3940 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3942 if (cur_size < min_size)
3943 min_size = cur_size;
3945 byte_count += count;
3948 /* hba wants the size to be exact */
3949 if (byte_count > scsi_bufflen(scsicmd)) {
3950 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3951 (byte_count - scsi_bufflen(scsicmd));
3952 rio2->sge[i-1].length = cpu_to_le32(temp);
3953 byte_count = scsi_bufflen(scsicmd);
3956 rio2->sgeCnt = cpu_to_le32(nseg);
3957 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3958 /* not conformable: evaluate required sg elements */
3960 int j, nseg_new = nseg, err_found;
3961 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3964 for (j = 1; j < nseg - 1; ++j) {
3965 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3969 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3974 if (i > 0 && nseg_new <= sg_max) {
3975 int ret = aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3981 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3983 /* Check for command underflow */
3984 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3985 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3986 byte_count, scsicmd->underflow);
3992 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3994 struct sge_ieee1212 *sge;
3998 if (aac_convert_sgl == 0)
4001 sge = kmalloc_array(nseg_new, sizeof(*sge), GFP_ATOMIC);
4005 for (i = 1, pos = 1; i < nseg-1; ++i) {
4006 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
4007 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
4008 sge[pos].addrLow = addr_low;
4009 sge[pos].addrHigh = rio2->sge[i].addrHigh;
4010 if (addr_low < rio2->sge[i].addrLow)
4011 sge[pos].addrHigh++;
4012 sge[pos].length = pages * PAGE_SIZE;
4017 sge[pos] = rio2->sge[nseg-1];
4018 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
4021 rio2->sgeCnt = cpu_to_le32(nseg_new);
4022 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4023 rio2->sgeNominalSize = pages * PAGE_SIZE;
4027 static long aac_build_sghba(struct scsi_cmnd *scsicmd,
4028 struct aac_hba_cmd_req *hbacmd,
4032 unsigned long byte_count = 0;
4034 struct scatterlist *sg;
4037 struct aac_hba_sgl *sge;
4039 nseg = scsi_dma_map(scsicmd);
4045 if (nseg > HBA_MAX_SG_EMBEDDED)
4046 sge = &hbacmd->sge[2];
4048 sge = &hbacmd->sge[0];
4050 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4051 int count = sg_dma_len(sg);
4052 u64 addr = sg_dma_address(sg);
4054 WARN_ON(i >= sg_max);
4055 sge->addr_hi = cpu_to_le32((u32)(addr>>32));
4056 sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
4057 cur_size = cpu_to_le32(count);
4058 sge->len = cur_size;
4060 byte_count += count;
4065 /* hba wants the size to be exact */
4066 if (byte_count > scsi_bufflen(scsicmd)) {
4069 temp = le32_to_cpu(sge->len) - byte_count
4070 - scsi_bufflen(scsicmd);
4071 sge->len = cpu_to_le32(temp);
4072 byte_count = scsi_bufflen(scsicmd);
4075 if (nseg <= HBA_MAX_SG_EMBEDDED) {
4076 hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
4077 sge->flags = cpu_to_le32(0x40000000);
4080 hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
4081 hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
4082 hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
4083 hbacmd->sge[0].addr_lo =
4084 cpu_to_le32((u32)(sg_address & 0xffffffff));
4087 /* Check for command underflow */
4088 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4089 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4090 byte_count, scsicmd->underflow);
4096 #ifdef AAC_DETAILED_STATUS_INFO
4098 struct aac_srb_status_info {
4104 static struct aac_srb_status_info srb_status_info[] = {
4105 { SRB_STATUS_PENDING, "Pending Status"},
4106 { SRB_STATUS_SUCCESS, "Success"},
4107 { SRB_STATUS_ABORTED, "Aborted Command"},
4108 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
4109 { SRB_STATUS_ERROR, "Error Event"},
4110 { SRB_STATUS_BUSY, "Device Busy"},
4111 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
4112 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
4113 { SRB_STATUS_NO_DEVICE, "No Device"},
4114 { SRB_STATUS_TIMEOUT, "Timeout"},
4115 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
4116 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
4117 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
4118 { SRB_STATUS_BUS_RESET, "Bus Reset"},
4119 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
4120 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
4121 { SRB_STATUS_NO_HBA, "No HBA"},
4122 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
4123 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
4124 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
4125 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
4126 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
4127 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
4128 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
4129 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
4130 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
4131 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
4132 { SRB_STATUS_NOT_STARTED, "Not Started"},
4133 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
4134 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
4135 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
4136 { 0xff, "Unknown Error"}
4139 char *aac_get_status_string(u32 status)
4143 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
4144 if (srb_status_info[i].status == status)
4145 return srb_status_info[i].str;
4147 return "Bad Status Code";