2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc.
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
8 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 * Abstract: Contains Interfaces to manage IOs.
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
37 #include <linux/spinlock.h>
38 #include <linux/slab.h>
39 #include <linux/completion.h>
40 #include <linux/blkdev.h>
41 #include <linux/uaccess.h>
42 #include <linux/highmem.h> /* For flush_kernel_dcache_page */
43 #include <linux/module.h>
45 #include <asm/unaligned.h>
47 #include <scsi/scsi.h>
48 #include <scsi/scsi_cmnd.h>
49 #include <scsi/scsi_device.h>
50 #include <scsi/scsi_host.h>
54 /* values for inqd_pdt: Peripheral device type in plain English */
55 #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
56 #define INQD_PDT_PROC 0x03 /* Processor device */
57 #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
58 #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
59 #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
60 #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
62 #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
63 #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
69 #define SENCODE_NO_SENSE 0x00
70 #define SENCODE_END_OF_DATA 0x00
71 #define SENCODE_BECOMING_READY 0x04
72 #define SENCODE_INIT_CMD_REQUIRED 0x04
73 #define SENCODE_UNRECOVERED_READ_ERROR 0x11
74 #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
75 #define SENCODE_INVALID_COMMAND 0x20
76 #define SENCODE_LBA_OUT_OF_RANGE 0x21
77 #define SENCODE_INVALID_CDB_FIELD 0x24
78 #define SENCODE_LUN_NOT_SUPPORTED 0x25
79 #define SENCODE_INVALID_PARAM_FIELD 0x26
80 #define SENCODE_PARAM_NOT_SUPPORTED 0x26
81 #define SENCODE_PARAM_VALUE_INVALID 0x26
82 #define SENCODE_RESET_OCCURRED 0x29
83 #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
84 #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
85 #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
86 #define SENCODE_DIAGNOSTIC_FAILURE 0x40
87 #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
88 #define SENCODE_INVALID_MESSAGE_ERROR 0x49
89 #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
90 #define SENCODE_OVERLAPPED_COMMAND 0x4E
93 * Additional sense codes
96 #define ASENCODE_NO_SENSE 0x00
97 #define ASENCODE_END_OF_DATA 0x05
98 #define ASENCODE_BECOMING_READY 0x01
99 #define ASENCODE_INIT_CMD_REQUIRED 0x02
100 #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
101 #define ASENCODE_INVALID_COMMAND 0x00
102 #define ASENCODE_LBA_OUT_OF_RANGE 0x00
103 #define ASENCODE_INVALID_CDB_FIELD 0x00
104 #define ASENCODE_LUN_NOT_SUPPORTED 0x00
105 #define ASENCODE_INVALID_PARAM_FIELD 0x00
106 #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
107 #define ASENCODE_PARAM_VALUE_INVALID 0x02
108 #define ASENCODE_RESET_OCCURRED 0x00
109 #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
110 #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
111 #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
112 #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
113 #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
114 #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
115 #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
116 #define ASENCODE_OVERLAPPED_COMMAND 0x00
118 #define AAC_STAT_GOOD (DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD)
120 #define BYTE0(x) (unsigned char)(x)
121 #define BYTE1(x) (unsigned char)((x) >> 8)
122 #define BYTE2(x) (unsigned char)((x) >> 16)
123 #define BYTE3(x) (unsigned char)((x) >> 24)
125 /* MODE_SENSE data format */
132 } __attribute__((packed)) hd;
138 } __attribute__((packed)) bd;
140 } __attribute__((packed)) aac_modep_data;
142 /* MODE_SENSE_10 data format */
150 } __attribute__((packed)) hd;
156 } __attribute__((packed)) bd;
158 } __attribute__((packed)) aac_modep10_data;
160 /*------------------------------------------------------------------------------
161 * S T R U C T S / T Y P E D E F S
162 *----------------------------------------------------------------------------*/
163 /* SCSI inquiry data */
164 struct inquiry_data {
165 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
166 u8 inqd_dtq; /* RMB | Device Type Qualifier */
167 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
168 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
169 u8 inqd_len; /* Additional length (n-4) */
170 u8 inqd_pad1[2];/* Reserved - must be zero */
171 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
172 u8 inqd_vid[8]; /* Vendor ID */
173 u8 inqd_pid[16];/* Product ID */
174 u8 inqd_prl[4]; /* Product Revision Level */
177 /* Added for VPD 0x83 */
178 struct tvpd_id_descriptor_type_1 {
179 u8 codeset:4; /* VPD_CODE_SET */
181 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
187 u8 serialnumber[8]; /* SN in ASCII */
191 struct tvpd_id_descriptor_type_2 {
192 u8 codeset:4; /* VPD_CODE_SET */
194 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
200 /* The serial number supposed to be 40 bits,
201 * bit we only support 32, so make the last byte zero. */
208 struct tvpd_id_descriptor_type_3 {
209 u8 codeset : 4; /* VPD_CODE_SET */
211 u8 identifiertype : 4; /* VPD_IDENTIFIER_TYPE */
220 u8 DeviceTypeQualifier:3;
224 struct tvpd_id_descriptor_type_1 type1;
225 struct tvpd_id_descriptor_type_2 type2;
226 struct tvpd_id_descriptor_type_3 type3;
230 * M O D U L E G L O B A L S
233 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
234 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
235 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
236 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
237 struct aac_raw_io2 *rio2, int sg_max);
238 static long aac_build_sghba(struct scsi_cmnd *scsicmd,
239 struct aac_hba_cmd_req *hbacmd,
240 int sg_max, u64 sg_address);
241 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
242 int pages, int nseg, int nseg_new);
243 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
244 static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
245 #ifdef AAC_DETAILED_STATUS_INFO
246 static char *aac_get_status_string(u32 status);
250 * Non dasd selection is handled entirely in aachba now
253 static int nondasd = -1;
254 static int aac_cache = 2; /* WCE=0 to avoid performance problems */
255 static int dacmode = -1;
258 int startup_timeout = 180;
259 int aif_timeout = 120;
260 int aac_sync_mode; /* Only Sync. transfer - disabled */
261 int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
263 module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
264 MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
266 module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
267 MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
269 module_param(nondasd, int, S_IRUGO|S_IWUSR);
270 MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
272 module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
273 MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
274 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
275 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
276 "\tbit 2 - Disable only if Battery is protecting Cache");
277 module_param(dacmode, int, S_IRUGO|S_IWUSR);
278 MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
280 module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
281 MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
282 " adapter for foreign arrays.\n"
283 "This is typically needed in systems that do not have a BIOS."
285 module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
286 MODULE_PARM_DESC(msi, "IRQ handling."
287 " 0=PIC(default), 1=MSI, 2=MSI-X)");
288 module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
289 MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
290 " adapter to have it's kernel up and\n"
291 "running. This is typically adjusted for large systems that do not"
293 module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
294 MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
295 " applications to pick up AIFs before\n"
296 "deregistering them. This is typically adjusted for heavily burdened"
300 module_param(aac_fib_dump, int, 0644);
301 MODULE_PARM_DESC(aac_fib_dump, "Dump controller fibs prior to IOP_RESET 0=off, 1=on");
304 module_param(numacb, int, S_IRUGO|S_IWUSR);
305 MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
306 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
307 " to use suggestion from Firmware.");
310 module_param(acbsize, int, S_IRUGO|S_IWUSR);
311 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
312 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
313 " suggestion from Firmware.");
315 int update_interval = 30 * 60;
316 module_param(update_interval, int, S_IRUGO|S_IWUSR);
317 MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
318 " updates issued to adapter.");
320 int check_interval = 60;
321 module_param(check_interval, int, S_IRUGO|S_IWUSR);
322 MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
325 int aac_check_reset = 1;
326 module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
327 MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
328 " adapter. a value of -1 forces the reset to adapters programmed to"
331 int expose_physicals = -1;
332 module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
333 MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
334 " -1=protect 0=off, 1=on");
336 int aac_reset_devices;
337 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
338 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
341 module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
342 MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
344 "\t1 - Array Meta Data Signature (default)\n"
345 "\t2 - Adapter Serial Number");
348 static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
349 struct fib *fibptr) {
350 struct scsi_device *device;
352 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
353 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
354 aac_fib_complete(fibptr);
357 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
358 device = scsicmd->device;
359 if (unlikely(!device)) {
360 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
361 aac_fib_complete(fibptr);
368 * aac_get_config_status - check the adapter configuration
369 * @common: adapter to query
371 * Query config status, and commit the configuration if needed.
373 int aac_get_config_status(struct aac_dev *dev, int commit_flag)
378 if (!(fibptr = aac_fib_alloc(dev)))
381 aac_fib_init(fibptr);
383 struct aac_get_config_status *dinfo;
384 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
386 dinfo->command = cpu_to_le32(VM_ContainerConfig);
387 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
388 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
391 status = aac_fib_send(ContainerCommand,
393 sizeof (struct aac_get_config_status),
398 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
400 struct aac_get_config_status_resp *reply
401 = (struct aac_get_config_status_resp *) fib_data(fibptr);
402 dprintk((KERN_WARNING
403 "aac_get_config_status: response=%d status=%d action=%d\n",
404 le32_to_cpu(reply->response),
405 le32_to_cpu(reply->status),
406 le32_to_cpu(reply->data.action)));
407 if ((le32_to_cpu(reply->response) != ST_OK) ||
408 (le32_to_cpu(reply->status) != CT_OK) ||
409 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
410 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
414 /* Do not set XferState to zero unless receives a response from F/W */
416 aac_fib_complete(fibptr);
418 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
420 if ((aac_commit == 1) || commit_flag) {
421 struct aac_commit_config * dinfo;
422 aac_fib_init(fibptr);
423 dinfo = (struct aac_commit_config *) fib_data(fibptr);
425 dinfo->command = cpu_to_le32(VM_ContainerConfig);
426 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
428 status = aac_fib_send(ContainerCommand,
430 sizeof (struct aac_commit_config),
434 /* Do not set XferState to zero unless
435 * receives a response from F/W */
437 aac_fib_complete(fibptr);
438 } else if (aac_commit == 0) {
440 "aac_get_config_status: Foreign device configurations are being ignored\n");
443 /* FIB should be freed only after getting the response from the F/W */
444 if (status != -ERESTARTSYS)
445 aac_fib_free(fibptr);
449 static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
452 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
453 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
455 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
460 * aac_get_containers - list containers
461 * @common: adapter to probe
463 * Make a list of all containers on this controller
465 int aac_get_containers(struct aac_dev *dev)
467 struct fsa_dev_info *fsa_dev_ptr;
471 struct aac_get_container_count *dinfo;
472 struct aac_get_container_count_resp *dresp;
473 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
475 if (!(fibptr = aac_fib_alloc(dev)))
478 aac_fib_init(fibptr);
479 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
480 dinfo->command = cpu_to_le32(VM_ContainerConfig);
481 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
483 status = aac_fib_send(ContainerCommand,
485 sizeof (struct aac_get_container_count),
490 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
491 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
492 if (fibptr->dev->supplement_adapter_info.supported_options2 &
493 AAC_OPTION_SUPPORTED_240_VOLUMES) {
494 maximum_num_containers =
495 le32_to_cpu(dresp->MaxSimpleVolumes);
497 aac_fib_complete(fibptr);
499 /* FIB should be freed only after getting the response from the F/W */
500 if (status != -ERESTARTSYS)
501 aac_fib_free(fibptr);
503 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
504 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
505 if (dev->fsa_dev == NULL ||
506 dev->maximum_num_containers != maximum_num_containers) {
508 fsa_dev_ptr = dev->fsa_dev;
510 dev->fsa_dev = kcalloc(maximum_num_containers,
511 sizeof(*fsa_dev_ptr), GFP_KERNEL);
520 dev->maximum_num_containers = maximum_num_containers;
522 for (index = 0; index < dev->maximum_num_containers; index++) {
523 dev->fsa_dev[index].devname[0] = '\0';
524 dev->fsa_dev[index].valid = 0;
526 status = aac_probe_container(dev, index);
529 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
536 static void get_container_name_callback(void *context, struct fib * fibptr)
538 struct aac_get_name_resp * get_name_reply;
539 struct scsi_cmnd * scsicmd;
541 scsicmd = (struct scsi_cmnd *) context;
543 if (!aac_valid_context(scsicmd, fibptr))
546 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
547 BUG_ON(fibptr == NULL);
549 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
550 /* Failure is irrelevant, using default value instead */
551 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
552 && (get_name_reply->data[0] != '\0')) {
553 char *sp = get_name_reply->data;
554 int data_size = FIELD_SIZEOF(struct aac_get_name_resp, data);
556 sp[data_size - 1] = '\0';
560 struct inquiry_data inq;
561 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
562 int count = sizeof(d);
565 *dp++ = (*sp) ? *sp++ : ' ';
566 } while (--count > 0);
568 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
569 memcpy(inq.inqd_pid, d, sizeof(d));
570 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
574 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
576 aac_fib_complete(fibptr);
577 scsicmd->scsi_done(scsicmd);
581 * aac_get_container_name - get container name, none blocking.
583 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
587 struct aac_get_name *dinfo;
588 struct fib * cmd_fibcontext;
589 struct aac_dev * dev;
591 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
593 data_size = FIELD_SIZEOF(struct aac_get_name_resp, data);
595 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
597 aac_fib_init(cmd_fibcontext);
598 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
599 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
601 dinfo->command = cpu_to_le32(VM_ContainerConfig);
602 dinfo->type = cpu_to_le32(CT_READ_NAME);
603 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
604 dinfo->count = cpu_to_le32(data_size - 1);
606 status = aac_fib_send(ContainerCommand,
608 sizeof(struct aac_get_name_resp),
611 (fib_callback)get_container_name_callback,
615 * Check that the command queued to the controller
617 if (status == -EINPROGRESS)
620 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
621 aac_fib_complete(cmd_fibcontext);
625 static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
627 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
629 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
630 return aac_scsi_cmd(scsicmd);
632 scsicmd->result = DID_NO_CONNECT << 16;
633 scsicmd->scsi_done(scsicmd);
637 static void _aac_probe_container2(void * context, struct fib * fibptr)
639 struct fsa_dev_info *fsa_dev_ptr;
640 int (*callback)(struct scsi_cmnd *);
641 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
645 if (!aac_valid_context(scsicmd, fibptr))
648 scsicmd->SCp.Status = 0;
649 fsa_dev_ptr = fibptr->dev->fsa_dev;
651 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
654 fsa_dev_ptr += scmd_id(scsicmd);
656 fibptr->dev->supplement_adapter_info.supported_options2;
658 if ((le32_to_cpu(dresp->status) == ST_OK) &&
659 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
660 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
661 if (!(sup_options2 & AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
662 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
663 fsa_dev_ptr->block_size = 0x200;
665 fsa_dev_ptr->block_size =
666 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
668 for (i = 0; i < 16; i++)
669 fsa_dev_ptr->identifier[i] =
670 dresp->mnt[0].fileinfo.bdevinfo
672 fsa_dev_ptr->valid = 1;
673 /* sense_key holds the current state of the spin-up */
674 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
675 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
676 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
677 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
678 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
680 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
681 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
682 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
684 if ((fsa_dev_ptr->valid & 1) == 0)
685 fsa_dev_ptr->valid = 0;
686 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
688 aac_fib_complete(fibptr);
689 aac_fib_free(fibptr);
690 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
691 scsicmd->SCp.ptr = NULL;
692 (*callback)(scsicmd);
696 static void _aac_probe_container1(void * context, struct fib * fibptr)
698 struct scsi_cmnd * scsicmd;
699 struct aac_mount * dresp;
700 struct aac_query_mount *dinfo;
703 dresp = (struct aac_mount *) fib_data(fibptr);
704 if (!aac_supports_2T(fibptr->dev)) {
705 dresp->mnt[0].capacityhigh = 0;
706 if ((le32_to_cpu(dresp->status) == ST_OK) &&
707 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
708 _aac_probe_container2(context, fibptr);
712 scsicmd = (struct scsi_cmnd *) context;
714 if (!aac_valid_context(scsicmd, fibptr))
717 aac_fib_init(fibptr);
719 dinfo = (struct aac_query_mount *)fib_data(fibptr);
721 if (fibptr->dev->supplement_adapter_info.supported_options2 &
722 AAC_OPTION_VARIABLE_BLOCK_SIZE)
723 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
725 dinfo->command = cpu_to_le32(VM_NameServe64);
727 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
728 dinfo->type = cpu_to_le32(FT_FILESYS);
729 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
731 status = aac_fib_send(ContainerCommand,
733 sizeof(struct aac_query_mount),
736 _aac_probe_container2,
739 * Check that the command queued to the controller
741 if (status < 0 && status != -EINPROGRESS) {
742 /* Inherit results from VM_NameServe, if any */
743 dresp->status = cpu_to_le32(ST_OK);
744 _aac_probe_container2(context, fibptr);
748 static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
751 int status = -ENOMEM;
753 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
754 struct aac_query_mount *dinfo;
756 aac_fib_init(fibptr);
758 dinfo = (struct aac_query_mount *)fib_data(fibptr);
760 if (fibptr->dev->supplement_adapter_info.supported_options2 &
761 AAC_OPTION_VARIABLE_BLOCK_SIZE)
762 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
764 dinfo->command = cpu_to_le32(VM_NameServe);
766 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
767 dinfo->type = cpu_to_le32(FT_FILESYS);
768 scsicmd->SCp.ptr = (char *)callback;
769 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
771 status = aac_fib_send(ContainerCommand,
773 sizeof(struct aac_query_mount),
776 _aac_probe_container1,
779 * Check that the command queued to the controller
781 if (status == -EINPROGRESS)
785 scsicmd->SCp.ptr = NULL;
786 aac_fib_complete(fibptr);
787 aac_fib_free(fibptr);
791 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
793 fsa_dev_ptr += scmd_id(scsicmd);
794 if ((fsa_dev_ptr->valid & 1) == 0) {
795 fsa_dev_ptr->valid = 0;
796 return (*callback)(scsicmd);
804 * aac_probe_container - query a logical volume
805 * @dev: device to query
806 * @cid: container identifier
808 * Queries the controller about the given volume. The volume information
809 * is updated in the struct fsa_dev_info structure rather than returned.
811 static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
813 scsicmd->device = NULL;
817 int aac_probe_container(struct aac_dev *dev, int cid)
819 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
820 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
823 if (!scsicmd || !scsidev) {
828 scsicmd->list.next = NULL;
829 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
831 scsicmd->device = scsidev;
832 scsidev->sdev_state = 0;
834 scsidev->host = dev->scsi_host_ptr;
836 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
837 while (scsicmd->device == scsidev)
840 status = scsicmd->SCp.Status;
845 /* Local Structure to set SCSI inquiry data strings */
847 char vid[8]; /* Vendor ID */
848 char pid[16]; /* Product ID */
849 char prl[4]; /* Product Revision Level */
853 * InqStrCopy - string merge
854 * @a: string to copy from
855 * @b: string to copy to
857 * Copy a String from one location to another
861 static void inqstrcpy(char *a, char *b)
864 while (*a != (char)0)
868 static char *container_types[] = {
892 char * get_container_type(unsigned tindex)
894 if (tindex >= ARRAY_SIZE(container_types))
895 tindex = ARRAY_SIZE(container_types) - 1;
896 return container_types[tindex];
899 /* Function: setinqstr
901 * Arguments: [1] pointer to void [1] int
903 * Purpose: Sets SCSI inquiry data strings for vendor, product
904 * and revision level. Allows strings to be set in platform dependent
905 * files instead of in OS dependent driver source.
908 static void setinqstr(struct aac_dev *dev, void *data, int tindex)
910 struct scsi_inq *str;
911 struct aac_supplement_adapter_info *sup_adap_info;
913 sup_adap_info = &dev->supplement_adapter_info;
914 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
915 memset(str, ' ', sizeof(*str));
917 if (sup_adap_info->adapter_type_text[0]) {
920 char *cname = kmemdup(sup_adap_info->adapter_type_text,
921 sizeof(sup_adap_info->adapter_type_text),
927 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
928 inqstrcpy("SMC", str->vid);
930 c = sizeof(str->vid);
931 while (*cp && *cp != ' ' && --c)
935 inqstrcpy(cname, str->vid);
937 while (*cp && *cp != ' ')
942 /* last six chars reserved for vol type */
943 if (strlen(cp) > sizeof(str->pid))
944 cp[sizeof(str->pid)] = '\0';
945 inqstrcpy (cp, str->pid);
949 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
951 inqstrcpy (mp->vname, str->vid);
952 /* last six chars reserved for vol type */
953 inqstrcpy (mp->model, str->pid);
956 if (tindex < ARRAY_SIZE(container_types)){
957 char *findit = str->pid;
959 for ( ; *findit != ' '; findit++); /* walk till we find a space */
960 /* RAID is superfluous in the context of a RAID device */
961 if (memcmp(findit-4, "RAID", 4) == 0)
962 *(findit -= 4) = ' ';
963 if (((findit - str->pid) + strlen(container_types[tindex]))
964 < (sizeof(str->pid) + sizeof(str->prl)))
965 inqstrcpy (container_types[tindex], findit + 1);
967 inqstrcpy ("V1.0", str->prl);
970 static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
971 struct aac_dev *dev, struct scsi_cmnd *scsicmd)
975 vpdpage83data->type3.codeset = 1;
976 vpdpage83data->type3.identifiertype = 3;
977 vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
980 for (container = 0; container < dev->maximum_num_containers;
983 if (scmd_id(scsicmd) == container) {
984 memcpy(vpdpage83data->type3.Identifier,
985 dev->fsa_dev[container].identifier,
992 static void get_container_serial_callback(void *context, struct fib * fibptr)
994 struct aac_get_serial_resp * get_serial_reply;
995 struct scsi_cmnd * scsicmd;
997 BUG_ON(fibptr == NULL);
999 scsicmd = (struct scsi_cmnd *) context;
1000 if (!aac_valid_context(scsicmd, fibptr))
1003 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
1004 /* Failure is irrelevant, using default value instead */
1005 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
1006 /*Check to see if it's for VPD 0x83 or 0x80 */
1007 if (scsicmd->cmnd[2] == 0x83) {
1008 /* vpd page 0x83 - Device Identification Page */
1009 struct aac_dev *dev;
1011 struct tvpd_page83 vpdpage83data;
1013 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1015 memset(((u8 *)&vpdpage83data), 0,
1016 sizeof(vpdpage83data));
1018 /* DIRECT_ACCESS_DEVIC */
1019 vpdpage83data.DeviceType = 0;
1020 /* DEVICE_CONNECTED */
1021 vpdpage83data.DeviceTypeQualifier = 0;
1022 /* VPD_DEVICE_IDENTIFIERS */
1023 vpdpage83data.PageCode = 0x83;
1024 vpdpage83data.reserved = 0;
1025 vpdpage83data.PageLength =
1026 sizeof(vpdpage83data.type1) +
1027 sizeof(vpdpage83data.type2);
1029 /* VPD 83 Type 3 is not supported for ARC */
1030 if (dev->sa_firmware)
1031 vpdpage83data.PageLength +=
1032 sizeof(vpdpage83data.type3);
1034 /* T10 Vendor Identifier Field Format */
1035 /* VpdcodesetAscii */
1036 vpdpage83data.type1.codeset = 2;
1037 /* VpdIdentifierTypeVendorId */
1038 vpdpage83data.type1.identifiertype = 1;
1039 vpdpage83data.type1.identifierlength =
1040 sizeof(vpdpage83data.type1) - 4;
1042 /* "ADAPTEC " for adaptec */
1043 memcpy(vpdpage83data.type1.venid,
1045 sizeof(vpdpage83data.type1.venid));
1046 memcpy(vpdpage83data.type1.productid,
1049 vpdpage83data.type1.productid));
1051 /* Convert to ascii based serial number.
1052 * The LSB is the the end.
1054 for (i = 0; i < 8; i++) {
1056 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
1058 vpdpage83data.type1.serialnumber[i] =
1061 vpdpage83data.type1.serialnumber[i] =
1066 /* VpdCodeSetBinary */
1067 vpdpage83data.type2.codeset = 1;
1068 /* VpdidentifiertypeEUI64 */
1069 vpdpage83data.type2.identifiertype = 2;
1070 vpdpage83data.type2.identifierlength =
1071 sizeof(vpdpage83data.type2) - 4;
1073 vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1074 vpdpage83data.type2.eu64id.venid[1] = 0;
1075 vpdpage83data.type2.eu64id.venid[2] = 0;
1077 vpdpage83data.type2.eu64id.Serial =
1078 get_serial_reply->uid;
1079 vpdpage83data.type2.eu64id.reserved = 0;
1082 * VpdIdentifierTypeFCPHName
1083 * VPD 0x83 Type 3 not supported for ARC
1085 if (dev->sa_firmware) {
1086 build_vpd83_type3(&vpdpage83data,
1090 /* Move the inquiry data to the response buffer. */
1091 scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1092 sizeof(vpdpage83data));
1094 /* It must be for VPD 0x80 */
1097 sp[0] = INQD_PDT_DA;
1098 sp[1] = scsicmd->cmnd[2];
1100 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1101 le32_to_cpu(get_serial_reply->uid));
1102 scsi_sg_copy_from_buffer(scsicmd, sp,
1107 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1109 aac_fib_complete(fibptr);
1110 scsicmd->scsi_done(scsicmd);
1114 * aac_get_container_serial - get container serial, none blocking.
1116 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1119 struct aac_get_serial *dinfo;
1120 struct fib * cmd_fibcontext;
1121 struct aac_dev * dev;
1123 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1125 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
1127 aac_fib_init(cmd_fibcontext);
1128 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1130 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1131 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1132 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1133 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1135 status = aac_fib_send(ContainerCommand,
1137 sizeof(struct aac_get_serial_resp),
1140 (fib_callback) get_container_serial_callback,
1144 * Check that the command queued to the controller
1146 if (status == -EINPROGRESS)
1149 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1150 aac_fib_complete(cmd_fibcontext);
1154 /* Function: setinqserial
1156 * Arguments: [1] pointer to void [1] int
1158 * Purpose: Sets SCSI Unit Serial number.
1159 * This is a fake. We should read a proper
1160 * serial number from the container. <SuSE>But
1161 * without docs it's quite hard to do it :-)
1162 * So this will have to do in the meantime.</SuSE>
1165 static int setinqserial(struct aac_dev *dev, void *data, int cid)
1168 * This breaks array migration.
1170 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1171 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1174 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1175 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
1177 u8 *sense_buf = (u8 *)sense_data;
1178 /* Sense data valid, err code 70h */
1179 sense_buf[0] = 0x70; /* No info field */
1180 sense_buf[1] = 0; /* Segment number, always zero */
1182 sense_buf[2] = sense_key; /* Sense key */
1184 sense_buf[12] = sense_code; /* Additional sense code */
1185 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
1187 if (sense_key == ILLEGAL_REQUEST) {
1188 sense_buf[7] = 10; /* Additional sense length */
1190 sense_buf[15] = bit_pointer;
1191 /* Illegal parameter is in the parameter block */
1192 if (sense_code == SENCODE_INVALID_CDB_FIELD)
1193 sense_buf[15] |= 0xc0;/* Std sense key specific field */
1194 /* Illegal parameter is in the CDB block */
1195 sense_buf[16] = field_pointer >> 8; /* MSB */
1196 sense_buf[17] = field_pointer; /* LSB */
1198 sense_buf[7] = 6; /* Additional sense length */
1201 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1203 if (lba & 0xffffffff00000000LL) {
1204 int cid = scmd_id(cmd);
1205 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1206 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1207 SAM_STAT_CHECK_CONDITION;
1208 set_sense(&dev->fsa_dev[cid].sense_data,
1209 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1210 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1211 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1212 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1213 SCSI_SENSE_BUFFERSIZE));
1214 cmd->scsi_done(cmd);
1220 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1225 static void io_callback(void *context, struct fib * fibptr);
1227 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1229 struct aac_dev *dev = fib->dev;
1230 u16 fibsize, command;
1234 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1235 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1237 struct aac_raw_io2 *readcmd2;
1238 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1239 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1240 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1241 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1242 readcmd2->byteCount = cpu_to_le32(count *
1243 dev->fsa_dev[scmd_id(cmd)].block_size);
1244 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1245 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
1246 ret = aac_build_sgraw2(cmd, readcmd2,
1247 dev->scsi_host_ptr->sg_tablesize);
1250 command = ContainerRawIo2;
1251 fibsize = sizeof(struct aac_raw_io2) +
1252 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1254 struct aac_raw_io *readcmd;
1255 readcmd = (struct aac_raw_io *) fib_data(fib);
1256 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1257 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1258 readcmd->count = cpu_to_le32(count *
1259 dev->fsa_dev[scmd_id(cmd)].block_size);
1260 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1261 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1262 readcmd->bpTotal = 0;
1263 readcmd->bpComplete = 0;
1264 ret = aac_build_sgraw(cmd, &readcmd->sg);
1267 command = ContainerRawIo;
1268 fibsize = sizeof(struct aac_raw_io) +
1269 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1272 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1274 * Now send the Fib to the adapter
1276 return aac_fib_send(command,
1281 (fib_callback) io_callback,
1285 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1288 struct aac_read64 *readcmd;
1292 readcmd = (struct aac_read64 *) fib_data(fib);
1293 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1294 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1295 readcmd->sector_count = cpu_to_le16(count);
1296 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1300 ret = aac_build_sg64(cmd, &readcmd->sg);
1303 fibsize = sizeof(struct aac_read64) +
1304 ((le32_to_cpu(readcmd->sg.count) - 1) *
1305 sizeof (struct sgentry64));
1306 BUG_ON (fibsize > (fib->dev->max_fib_size -
1307 sizeof(struct aac_fibhdr)));
1309 * Now send the Fib to the adapter
1311 return aac_fib_send(ContainerCommand64,
1316 (fib_callback) io_callback,
1320 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1323 struct aac_read *readcmd;
1324 struct aac_dev *dev = fib->dev;
1328 readcmd = (struct aac_read *) fib_data(fib);
1329 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1330 readcmd->cid = cpu_to_le32(scmd_id(cmd));
1331 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1332 readcmd->count = cpu_to_le32(count *
1333 dev->fsa_dev[scmd_id(cmd)].block_size);
1335 ret = aac_build_sg(cmd, &readcmd->sg);
1338 fibsize = sizeof(struct aac_read) +
1339 ((le32_to_cpu(readcmd->sg.count) - 1) *
1340 sizeof (struct sgentry));
1341 BUG_ON (fibsize > (fib->dev->max_fib_size -
1342 sizeof(struct aac_fibhdr)));
1344 * Now send the Fib to the adapter
1346 return aac_fib_send(ContainerCommand,
1351 (fib_callback) io_callback,
1355 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1357 struct aac_dev *dev = fib->dev;
1358 u16 fibsize, command;
1362 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1363 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1365 struct aac_raw_io2 *writecmd2;
1366 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1367 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1368 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1369 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1370 writecmd2->byteCount = cpu_to_le32(count *
1371 dev->fsa_dev[scmd_id(cmd)].block_size);
1372 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1373 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1374 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1375 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1376 cpu_to_le16(RIO2_IO_TYPE_WRITE);
1377 ret = aac_build_sgraw2(cmd, writecmd2,
1378 dev->scsi_host_ptr->sg_tablesize);
1381 command = ContainerRawIo2;
1382 fibsize = sizeof(struct aac_raw_io2) +
1383 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1385 struct aac_raw_io *writecmd;
1386 writecmd = (struct aac_raw_io *) fib_data(fib);
1387 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1388 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1389 writecmd->count = cpu_to_le32(count *
1390 dev->fsa_dev[scmd_id(cmd)].block_size);
1391 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1392 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1393 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1394 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1395 cpu_to_le16(RIO_TYPE_WRITE);
1396 writecmd->bpTotal = 0;
1397 writecmd->bpComplete = 0;
1398 ret = aac_build_sgraw(cmd, &writecmd->sg);
1401 command = ContainerRawIo;
1402 fibsize = sizeof(struct aac_raw_io) +
1403 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1406 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1408 * Now send the Fib to the adapter
1410 return aac_fib_send(command,
1415 (fib_callback) io_callback,
1419 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1422 struct aac_write64 *writecmd;
1426 writecmd = (struct aac_write64 *) fib_data(fib);
1427 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1428 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1429 writecmd->sector_count = cpu_to_le16(count);
1430 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1432 writecmd->flags = 0;
1434 ret = aac_build_sg64(cmd, &writecmd->sg);
1437 fibsize = sizeof(struct aac_write64) +
1438 ((le32_to_cpu(writecmd->sg.count) - 1) *
1439 sizeof (struct sgentry64));
1440 BUG_ON (fibsize > (fib->dev->max_fib_size -
1441 sizeof(struct aac_fibhdr)));
1443 * Now send the Fib to the adapter
1445 return aac_fib_send(ContainerCommand64,
1450 (fib_callback) io_callback,
1454 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1457 struct aac_write *writecmd;
1458 struct aac_dev *dev = fib->dev;
1462 writecmd = (struct aac_write *) fib_data(fib);
1463 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1464 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1465 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1466 writecmd->count = cpu_to_le32(count *
1467 dev->fsa_dev[scmd_id(cmd)].block_size);
1468 writecmd->sg.count = cpu_to_le32(1);
1469 /* ->stable is not used - it did mean which type of write */
1471 ret = aac_build_sg(cmd, &writecmd->sg);
1474 fibsize = sizeof(struct aac_write) +
1475 ((le32_to_cpu(writecmd->sg.count) - 1) *
1476 sizeof (struct sgentry));
1477 BUG_ON (fibsize > (fib->dev->max_fib_size -
1478 sizeof(struct aac_fibhdr)));
1480 * Now send the Fib to the adapter
1482 return aac_fib_send(ContainerCommand,
1487 (fib_callback) io_callback,
1491 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1493 struct aac_srb * srbcmd;
1498 switch(cmd->sc_data_direction){
1502 case DMA_BIDIRECTIONAL:
1503 flag = SRB_DataIn | SRB_DataOut;
1505 case DMA_FROM_DEVICE:
1509 default: /* shuts up some versions of gcc */
1510 flag = SRB_NoDataXfer;
1514 srbcmd = (struct aac_srb*) fib_data(fib);
1515 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1516 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1517 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1518 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1519 srbcmd->flags = cpu_to_le32(flag);
1520 timeout = cmd->request->timeout/HZ;
1523 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1524 srbcmd->retry_limit = 0; /* Obsolete parameter */
1525 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1529 static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
1530 struct scsi_cmnd *cmd)
1532 struct aac_hba_cmd_req *hbacmd;
1533 struct aac_dev *dev;
1537 dev = (struct aac_dev *)cmd->device->host->hostdata;
1539 hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
1540 memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
1541 /* iu_type is a parameter of aac_hba_send */
1542 switch (cmd->sc_data_direction) {
1546 case DMA_FROM_DEVICE:
1547 case DMA_BIDIRECTIONAL:
1554 hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
1556 bus = aac_logical_to_phys(scmd_channel(cmd));
1557 target = scmd_id(cmd);
1558 hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
1560 /* we fill in reply_qid later in aac_src_deliver_message */
1561 /* we fill in iu_type, request_id later in aac_hba_send */
1562 /* we fill in emb_data_desc_count later in aac_build_sghba */
1564 memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
1565 hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
1567 address = (u64)fib->hw_error_pa;
1568 hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
1569 hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
1570 hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
1575 static void aac_srb_callback(void *context, struct fib * fibptr);
1577 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1580 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1583 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1586 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1588 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1589 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1591 * Build Scatter/Gather list
1593 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1594 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1595 sizeof (struct sgentry64));
1596 BUG_ON (fibsize > (fib->dev->max_fib_size -
1597 sizeof(struct aac_fibhdr)));
1600 * Now send the Fib to the adapter
1602 return aac_fib_send(ScsiPortCommand64, fib,
1603 fibsize, FsaNormal, 0, 1,
1604 (fib_callback) aac_srb_callback,
1608 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1611 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1614 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1617 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1619 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1620 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1622 * Build Scatter/Gather list
1624 fibsize = sizeof (struct aac_srb) +
1625 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1626 sizeof (struct sgentry));
1627 BUG_ON (fibsize > (fib->dev->max_fib_size -
1628 sizeof(struct aac_fibhdr)));
1631 * Now send the Fib to the adapter
1633 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1634 (fib_callback) aac_srb_callback, (void *) cmd);
1637 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1639 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1640 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1642 return aac_scsi_32(fib, cmd);
1645 static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
1647 struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
1648 struct aac_dev *dev;
1651 dev = (struct aac_dev *)cmd->device->host->hostdata;
1653 ret = aac_build_sghba(cmd, hbacmd,
1654 dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
1659 * Now send the HBA command to the adapter
1661 fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
1662 sizeof(struct aac_hba_sgl);
1664 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
1665 (fib_callback) aac_hba_callback,
1669 static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
1670 struct aac_srb_unit *srbu, void *xfer_buf, int xfer_len)
1676 struct aac_srb *srb;
1677 struct aac_srb_reply *srb_reply;
1678 struct sgmap64 *sg64;
1682 if (!dev->sa_firmware)
1686 fibptr = aac_fib_alloc(dev);
1690 aac_fib_init(fibptr);
1691 fibptr->hw_fib_va->header.XferState &=
1692 ~cpu_to_le32(FastResponseCapable);
1694 fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
1695 sizeof(struct sgentry64);
1697 /* allocate DMA buffer for response */
1698 addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
1700 if (dma_mapping_error(&dev->pdev->dev, addr)) {
1705 srb = fib_data(fibptr);
1706 memcpy(srb, &srbu->srb, sizeof(struct aac_srb));
1708 vbus = (u32)le16_to_cpu(
1709 dev->supplement_adapter_info.virt_device_bus);
1710 vid = (u32)le16_to_cpu(
1711 dev->supplement_adapter_info.virt_device_target);
1713 /* set the common request fields */
1714 srb->channel = cpu_to_le32(vbus);
1715 srb->id = cpu_to_le32(vid);
1717 srb->function = cpu_to_le32(SRBF_ExecuteScsi);
1719 srb->retry_limit = 0;
1720 srb->cdb_size = cpu_to_le32(16);
1721 srb->count = cpu_to_le32(xfer_len);
1723 sg64 = (struct sgmap64 *)&srb->sg;
1724 sg64->count = cpu_to_le32(1);
1725 sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
1726 sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
1727 sg64->sg[0].count = cpu_to_le32(xfer_len);
1730 * Copy the updated data for other dumping or other usage if needed
1732 memcpy(&srbu->srb, srb, sizeof(struct aac_srb));
1734 /* issue request to the controller */
1735 rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize, FsaNormal,
1738 if (rcode == -ERESTARTSYS)
1741 if (unlikely(rcode < 0))
1744 srb_reply = (struct aac_srb_reply *)fib_data(fibptr);
1745 memcpy(&srbu->srb_reply, srb_reply, sizeof(struct aac_srb_reply));
1748 dma_unmap_single(&dev->pdev->dev, addr, xfer_len, DMA_BIDIRECTIONAL);
1750 aac_fib_complete(fibptr);
1751 aac_fib_free(fibptr);
1755 static void aac_set_safw_target_qd(struct aac_dev *dev, int bus, int target)
1758 struct aac_ciss_identify_pd *identify_resp;
1760 if (dev->hba_map[bus][target].devtype != AAC_DEVTYPE_NATIVE_RAW)
1763 identify_resp = dev->hba_map[bus][target].safw_identify_resp;
1764 if (identify_resp == NULL) {
1765 dev->hba_map[bus][target].qd_limit = 32;
1769 if (identify_resp->current_queue_depth_limit <= 0 ||
1770 identify_resp->current_queue_depth_limit > 255)
1771 dev->hba_map[bus][target].qd_limit = 32;
1773 dev->hba_map[bus][target].qd_limit =
1774 identify_resp->current_queue_depth_limit;
1777 static int aac_issue_safw_bmic_identify(struct aac_dev *dev,
1778 struct aac_ciss_identify_pd **identify_resp, u32 bus, u32 target)
1780 int rcode = -ENOMEM;
1782 struct aac_srb_unit srbu;
1783 struct aac_srb *srbcmd;
1784 struct aac_ciss_identify_pd *identify_reply;
1786 datasize = sizeof(struct aac_ciss_identify_pd);
1787 identify_reply = kmalloc(datasize, GFP_KERNEL);
1788 if (!identify_reply)
1791 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1794 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1795 srbcmd->cdb[0] = 0x26;
1796 srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
1797 srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
1799 rcode = aac_send_safw_bmic_cmd(dev, &srbu, identify_reply, datasize);
1800 if (unlikely(rcode < 0))
1803 *identify_resp = identify_reply;
1808 kfree(identify_reply);
1812 static inline void aac_free_safw_ciss_luns(struct aac_dev *dev)
1814 kfree(dev->safw_phys_luns);
1815 dev->safw_phys_luns = NULL;
1819 * aac_get_safw_ciss_luns() Process topology change
1820 * @dev: aac_dev structure
1822 * Execute a CISS REPORT PHYS LUNS and process the results into
1823 * the current hba_map.
1825 static int aac_get_safw_ciss_luns(struct aac_dev *dev)
1827 int rcode = -ENOMEM;
1829 struct aac_srb *srbcmd;
1830 struct aac_srb_unit srbu;
1831 struct aac_ciss_phys_luns_resp *phys_luns;
1833 datasize = sizeof(struct aac_ciss_phys_luns_resp) +
1834 (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
1835 phys_luns = kmalloc(datasize, GFP_KERNEL);
1836 if (phys_luns == NULL)
1839 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1842 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1843 srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
1844 srbcmd->cdb[1] = 2; /* extended reporting */
1845 srbcmd->cdb[8] = (u8)(datasize >> 8);
1846 srbcmd->cdb[9] = (u8)(datasize);
1848 rcode = aac_send_safw_bmic_cmd(dev, &srbu, phys_luns, datasize);
1849 if (unlikely(rcode < 0))
1852 if (phys_luns->resp_flag != 2) {
1857 dev->safw_phys_luns = phys_luns;
1866 static inline u32 aac_get_safw_phys_lun_count(struct aac_dev *dev)
1868 return get_unaligned_be32(&dev->safw_phys_luns->list_length[0])/24;
1871 static inline u32 aac_get_safw_phys_bus(struct aac_dev *dev, int lun)
1873 return dev->safw_phys_luns->lun[lun].level2[1] & 0x3f;
1876 static inline u32 aac_get_safw_phys_target(struct aac_dev *dev, int lun)
1878 return dev->safw_phys_luns->lun[lun].level2[0];
1881 static inline u32 aac_get_safw_phys_expose_flag(struct aac_dev *dev, int lun)
1883 return dev->safw_phys_luns->lun[lun].bus >> 6;
1886 static inline u32 aac_get_safw_phys_attribs(struct aac_dev *dev, int lun)
1888 return dev->safw_phys_luns->lun[lun].node_ident[9];
1891 static inline u32 aac_get_safw_phys_nexus(struct aac_dev *dev, int lun)
1893 return *((u32 *)&dev->safw_phys_luns->lun[lun].node_ident[12]);
1896 static inline u32 aac_get_safw_phys_device_type(struct aac_dev *dev, int lun)
1898 return dev->safw_phys_luns->lun[lun].node_ident[8];
1901 static inline void aac_free_safw_identify_resp(struct aac_dev *dev,
1902 int bus, int target)
1904 kfree(dev->hba_map[bus][target].safw_identify_resp);
1905 dev->hba_map[bus][target].safw_identify_resp = NULL;
1908 static inline void aac_free_safw_all_identify_resp(struct aac_dev *dev,
1916 luns = aac_get_safw_phys_lun_count(dev);
1918 if (luns < lun_count)
1920 else if (lun_count < 0)
1923 for (i = 0; i < lun_count; i++) {
1924 bus = aac_get_safw_phys_bus(dev, i);
1925 target = aac_get_safw_phys_target(dev, i);
1927 aac_free_safw_identify_resp(dev, bus, target);
1931 static int aac_get_safw_attr_all_targets(struct aac_dev *dev)
1938 struct aac_ciss_identify_pd *identify_resp = NULL;
1940 lun_count = aac_get_safw_phys_lun_count(dev);
1942 for (i = 0; i < lun_count; ++i) {
1944 bus = aac_get_safw_phys_bus(dev, i);
1945 target = aac_get_safw_phys_target(dev, i);
1947 rcode = aac_issue_safw_bmic_identify(dev,
1948 &identify_resp, bus, target);
1950 if (unlikely(rcode < 0))
1951 goto free_identify_resp;
1953 dev->hba_map[bus][target].safw_identify_resp = identify_resp;
1959 aac_free_safw_all_identify_resp(dev, i);
1964 * aac_set_safw_attr_all_targets- update current hba map with data from FW
1965 * @dev: aac_dev structure
1966 * @phys_luns: FW information from report phys luns
1967 * @rescan: Indicates scan type
1969 * Update our hba map with the information gathered from the FW
1971 static void aac_set_safw_attr_all_targets(struct aac_dev *dev)
1973 /* ok and extended reporting */
1974 u32 lun_count, nexus;
1976 u8 expose_flag, attribs;
1978 lun_count = aac_get_safw_phys_lun_count(dev);
1980 dev->scan_counter++;
1982 for (i = 0; i < lun_count; ++i) {
1984 bus = aac_get_safw_phys_bus(dev, i);
1985 target = aac_get_safw_phys_target(dev, i);
1986 expose_flag = aac_get_safw_phys_expose_flag(dev, i);
1987 attribs = aac_get_safw_phys_attribs(dev, i);
1988 nexus = aac_get_safw_phys_nexus(dev, i);
1990 if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
1993 if (expose_flag != 0) {
1994 dev->hba_map[bus][target].devtype =
1995 AAC_DEVTYPE_RAID_MEMBER;
1999 if (nexus != 0 && (attribs & 8)) {
2000 dev->hba_map[bus][target].devtype =
2001 AAC_DEVTYPE_NATIVE_RAW;
2002 dev->hba_map[bus][target].rmw_nexus =
2005 dev->hba_map[bus][target].devtype =
2006 AAC_DEVTYPE_ARC_RAW;
2008 dev->hba_map[bus][target].scan_counter = dev->scan_counter;
2010 aac_set_safw_target_qd(dev, bus, target);
2014 static int aac_setup_safw_targets(struct aac_dev *dev)
2018 rcode = aac_get_containers(dev);
2019 if (unlikely(rcode < 0))
2022 rcode = aac_get_safw_ciss_luns(dev);
2023 if (unlikely(rcode < 0))
2026 rcode = aac_get_safw_attr_all_targets(dev);
2027 if (unlikely(rcode < 0))
2028 goto free_ciss_luns;
2030 aac_set_safw_attr_all_targets(dev);
2032 aac_free_safw_all_identify_resp(dev, -1);
2034 aac_free_safw_ciss_luns(dev);
2039 int aac_setup_safw_adapter(struct aac_dev *dev)
2041 return aac_setup_safw_targets(dev);
2044 int aac_get_adapter_info(struct aac_dev* dev)
2048 u32 tmp, bus, target;
2049 struct aac_adapter_info *info;
2050 struct aac_bus_info *command;
2051 struct aac_bus_info_response *bus_info;
2053 if (!(fibptr = aac_fib_alloc(dev)))
2056 aac_fib_init(fibptr);
2057 info = (struct aac_adapter_info *) fib_data(fibptr);
2058 memset(info,0,sizeof(*info));
2060 rcode = aac_fib_send(RequestAdapterInfo,
2064 -1, 1, /* First `interrupt' command uses special wait */
2069 /* FIB should be freed only after
2070 * getting the response from the F/W */
2071 if (rcode != -ERESTARTSYS) {
2072 aac_fib_complete(fibptr);
2073 aac_fib_free(fibptr);
2077 memcpy(&dev->adapter_info, info, sizeof(*info));
2079 dev->supplement_adapter_info.virt_device_bus = 0xffff;
2080 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
2081 struct aac_supplement_adapter_info * sinfo;
2083 aac_fib_init(fibptr);
2085 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
2087 memset(sinfo,0,sizeof(*sinfo));
2089 rcode = aac_fib_send(RequestSupplementAdapterInfo,
2098 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
2099 if (rcode == -ERESTARTSYS) {
2100 fibptr = aac_fib_alloc(dev);
2107 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
2108 for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
2109 for (target = 0; target < AAC_MAX_TARGETS; target++) {
2110 dev->hba_map[bus][target].devtype = 0;
2111 dev->hba_map[bus][target].qd_limit = 0;
2119 aac_fib_init(fibptr);
2121 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
2123 memset(bus_info, 0, sizeof(*bus_info));
2125 command = (struct aac_bus_info *)bus_info;
2127 command->Command = cpu_to_le32(VM_Ioctl);
2128 command->ObjType = cpu_to_le32(FT_DRIVE);
2129 command->MethodId = cpu_to_le32(1);
2130 command->CtlCmd = cpu_to_le32(GetBusInfo);
2132 rcode = aac_fib_send(ContainerCommand,
2139 /* reasoned default */
2140 dev->maximum_num_physicals = 16;
2141 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
2142 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
2143 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
2146 if (!dev->in_reset) {
2148 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
2149 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
2155 le32_to_cpu(dev->adapter_info.kernelbuild),
2156 (int)sizeof(dev->supplement_adapter_info.build_date),
2157 dev->supplement_adapter_info.build_date);
2158 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
2159 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
2161 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2162 le32_to_cpu(dev->adapter_info.monitorbuild));
2163 tmp = le32_to_cpu(dev->adapter_info.biosrev);
2164 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
2166 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2167 le32_to_cpu(dev->adapter_info.biosbuild));
2169 if (aac_get_serial_number(
2170 shost_to_class(dev->scsi_host_ptr), buffer))
2171 printk(KERN_INFO "%s%d: serial %s",
2172 dev->name, dev->id, buffer);
2173 if (dev->supplement_adapter_info.vpd_info.tsid[0]) {
2174 printk(KERN_INFO "%s%d: TSID %.*s\n",
2176 (int)sizeof(dev->supplement_adapter_info
2178 dev->supplement_adapter_info.vpd_info.tsid);
2180 if (!aac_check_reset || ((aac_check_reset == 1) &&
2181 (dev->supplement_adapter_info.supported_options2 &
2182 AAC_OPTION_IGNORE_RESET))) {
2183 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
2184 dev->name, dev->id);
2188 dev->cache_protected = 0;
2189 dev->jbod = ((dev->supplement_adapter_info.feature_bits &
2190 AAC_FEATURE_JBOD) != 0);
2191 dev->nondasd_support = 0;
2192 dev->raid_scsi_mode = 0;
2193 if(dev->adapter_info.options & AAC_OPT_NONDASD)
2194 dev->nondasd_support = 1;
2197 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2198 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2199 * force nondasd support on. If we decide to allow the non-dasd flag
2200 * additional changes changes will have to be made to support
2201 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2202 * changed to support the new dev->raid_scsi_mode flag instead of
2203 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2204 * function aac_detect will have to be modified where it sets up the
2205 * max number of channels based on the aac->nondasd_support flag only.
2207 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
2208 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
2209 dev->nondasd_support = 1;
2210 dev->raid_scsi_mode = 1;
2212 if (dev->raid_scsi_mode != 0)
2213 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
2214 dev->name, dev->id);
2217 dev->nondasd_support = (nondasd!=0);
2218 if (dev->nondasd_support && !dev->in_reset)
2219 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
2221 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
2223 dev->dac_support = 0;
2224 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
2225 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
2227 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
2228 dev->name, dev->id);
2229 dev->dac_support = 1;
2233 dev->dac_support = (dacmode!=0);
2236 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2237 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
2238 & AAC_QUIRK_SCSI_32)) {
2239 dev->nondasd_support = 0;
2241 expose_physicals = 0;
2244 if (dev->dac_support) {
2245 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
2247 dev_info(&dev->pdev->dev, "64 Bit DAC enabled\n");
2248 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
2249 dev_info(&dev->pdev->dev, "DMA mask set failed, 64 Bit DAC disabled\n");
2250 dev->dac_support = 0;
2252 dev_info(&dev->pdev->dev, "No suitable DMA available\n");
2257 * Deal with configuring for the individualized limits of each packet
2260 dev->a_ops.adapter_scsi = (dev->dac_support)
2261 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
2265 if (dev->raw_io_interface) {
2266 dev->a_ops.adapter_bounds = (dev->raw_io_64)
2269 dev->a_ops.adapter_read = aac_read_raw_io;
2270 dev->a_ops.adapter_write = aac_write_raw_io;
2272 dev->a_ops.adapter_bounds = aac_bounds_32;
2273 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
2274 sizeof(struct aac_fibhdr) -
2275 sizeof(struct aac_write) + sizeof(struct sgentry)) /
2276 sizeof(struct sgentry);
2277 if (dev->dac_support) {
2278 dev->a_ops.adapter_read = aac_read_block64;
2279 dev->a_ops.adapter_write = aac_write_block64;
2281 * 38 scatter gather elements
2283 dev->scsi_host_ptr->sg_tablesize =
2284 (dev->max_fib_size -
2285 sizeof(struct aac_fibhdr) -
2286 sizeof(struct aac_write64) +
2287 sizeof(struct sgentry64)) /
2288 sizeof(struct sgentry64);
2290 dev->a_ops.adapter_read = aac_read_block;
2291 dev->a_ops.adapter_write = aac_write_block;
2293 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
2294 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
2296 * Worst case size that could cause sg overflow when
2297 * we break up SG elements that are larger than 64KB.
2298 * Would be nice if we could tell the SCSI layer what
2299 * the maximum SG element size can be. Worst case is
2300 * (sg_tablesize-1) 4KB elements with one 64KB
2302 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2304 dev->scsi_host_ptr->max_sectors =
2305 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
2308 if (!dev->sync_mode && dev->sa_firmware &&
2309 dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
2310 dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
2311 HBA_MAX_SG_SEPARATE;
2313 /* FIB should be freed only after getting the response from the F/W */
2314 if (rcode != -ERESTARTSYS) {
2315 aac_fib_complete(fibptr);
2316 aac_fib_free(fibptr);
2323 static void io_callback(void *context, struct fib * fibptr)
2325 struct aac_dev *dev;
2326 struct aac_read_reply *readreply;
2327 struct scsi_cmnd *scsicmd;
2330 scsicmd = (struct scsi_cmnd *) context;
2332 if (!aac_valid_context(scsicmd, fibptr))
2336 cid = scmd_id(scsicmd);
2338 if (nblank(dprintk(x))) {
2340 switch (scsicmd->cmnd[0]) {
2343 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2344 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2348 lba = ((u64)scsicmd->cmnd[2] << 56) |
2349 ((u64)scsicmd->cmnd[3] << 48) |
2350 ((u64)scsicmd->cmnd[4] << 40) |
2351 ((u64)scsicmd->cmnd[5] << 32) |
2352 ((u64)scsicmd->cmnd[6] << 24) |
2353 (scsicmd->cmnd[7] << 16) |
2354 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2358 lba = ((u64)scsicmd->cmnd[2] << 24) |
2359 (scsicmd->cmnd[3] << 16) |
2360 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2363 lba = ((u64)scsicmd->cmnd[2] << 24) |
2364 (scsicmd->cmnd[3] << 16) |
2365 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2369 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2370 smp_processor_id(), (unsigned long long)lba, jiffies);
2373 BUG_ON(fibptr == NULL);
2375 scsi_dma_unmap(scsicmd);
2377 readreply = (struct aac_read_reply *)fib_data(fibptr);
2378 switch (le32_to_cpu(readreply->status)) {
2380 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2382 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
2385 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2386 SAM_STAT_CHECK_CONDITION;
2387 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
2388 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 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 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2395 SAM_STAT_CHECK_CONDITION;
2396 set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
2397 SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
2398 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2399 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2400 SCSI_SENSE_BUFFERSIZE));
2403 #ifdef AAC_DETAILED_STATUS_INFO
2404 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
2405 le32_to_cpu(readreply->status));
2407 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2408 SAM_STAT_CHECK_CONDITION;
2409 set_sense(&dev->fsa_dev[cid].sense_data,
2410 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2411 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2412 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2413 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2414 SCSI_SENSE_BUFFERSIZE));
2417 aac_fib_complete(fibptr);
2419 scsicmd->scsi_done(scsicmd);
2422 static int aac_read(struct scsi_cmnd * scsicmd)
2427 struct aac_dev *dev;
2428 struct fib * cmd_fibcontext;
2431 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2433 * Get block address and transfer length
2435 switch (scsicmd->cmnd[0]) {
2437 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
2439 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2440 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2441 count = scsicmd->cmnd[4];
2447 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
2449 lba = ((u64)scsicmd->cmnd[2] << 56) |
2450 ((u64)scsicmd->cmnd[3] << 48) |
2451 ((u64)scsicmd->cmnd[4] << 40) |
2452 ((u64)scsicmd->cmnd[5] << 32) |
2453 ((u64)scsicmd->cmnd[6] << 24) |
2454 (scsicmd->cmnd[7] << 16) |
2455 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2456 count = (scsicmd->cmnd[10] << 24) |
2457 (scsicmd->cmnd[11] << 16) |
2458 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2461 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
2463 lba = ((u64)scsicmd->cmnd[2] << 24) |
2464 (scsicmd->cmnd[3] << 16) |
2465 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2466 count = (scsicmd->cmnd[6] << 24) |
2467 (scsicmd->cmnd[7] << 16) |
2468 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2471 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
2473 lba = ((u64)scsicmd->cmnd[2] << 24) |
2474 (scsicmd->cmnd[3] << 16) |
2475 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2476 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2480 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2481 cid = scmd_id(scsicmd);
2482 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2483 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2484 SAM_STAT_CHECK_CONDITION;
2485 set_sense(&dev->fsa_dev[cid].sense_data,
2486 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2487 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2488 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2489 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2490 SCSI_SENSE_BUFFERSIZE));
2491 scsicmd->scsi_done(scsicmd);
2495 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
2496 smp_processor_id(), (unsigned long long)lba, jiffies));
2497 if (aac_adapter_bounds(dev,scsicmd,lba))
2500 * Alocate and initialize a Fib
2502 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
2503 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2504 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
2507 * Check that the command queued to the controller
2509 if (status == -EINPROGRESS)
2512 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
2514 * For some reason, the Fib didn't queue, return QUEUE_FULL
2516 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
2517 scsicmd->scsi_done(scsicmd);
2518 aac_fib_complete(cmd_fibcontext);
2519 aac_fib_free(cmd_fibcontext);
2523 static int aac_write(struct scsi_cmnd * scsicmd)
2529 struct aac_dev *dev;
2530 struct fib * cmd_fibcontext;
2533 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2535 * Get block address and transfer length
2537 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
2539 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2540 count = scsicmd->cmnd[4];
2544 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
2545 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
2547 lba = ((u64)scsicmd->cmnd[2] << 56) |
2548 ((u64)scsicmd->cmnd[3] << 48) |
2549 ((u64)scsicmd->cmnd[4] << 40) |
2550 ((u64)scsicmd->cmnd[5] << 32) |
2551 ((u64)scsicmd->cmnd[6] << 24) |
2552 (scsicmd->cmnd[7] << 16) |
2553 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2554 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2555 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2556 fua = scsicmd->cmnd[1] & 0x8;
2557 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
2558 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
2560 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2561 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2562 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2563 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2564 fua = scsicmd->cmnd[1] & 0x8;
2566 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
2567 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2568 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2569 fua = scsicmd->cmnd[1] & 0x8;
2572 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2573 cid = scmd_id(scsicmd);
2574 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2575 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2576 SAM_STAT_CHECK_CONDITION;
2577 set_sense(&dev->fsa_dev[cid].sense_data,
2578 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2579 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2580 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2581 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2582 SCSI_SENSE_BUFFERSIZE));
2583 scsicmd->scsi_done(scsicmd);
2587 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2588 smp_processor_id(), (unsigned long long)lba, jiffies));
2589 if (aac_adapter_bounds(dev,scsicmd,lba))
2592 * Allocate and initialize a Fib then setup a BlockWrite command
2594 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
2595 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2596 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
2599 * Check that the command queued to the controller
2601 if (status == -EINPROGRESS)
2604 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
2606 * For some reason, the Fib didn't queue, return QUEUE_FULL
2608 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
2609 scsicmd->scsi_done(scsicmd);
2611 aac_fib_complete(cmd_fibcontext);
2612 aac_fib_free(cmd_fibcontext);
2616 static void synchronize_callback(void *context, struct fib *fibptr)
2618 struct aac_synchronize_reply *synchronizereply;
2619 struct scsi_cmnd *cmd;
2623 if (!aac_valid_context(cmd, fibptr))
2626 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
2627 smp_processor_id(), jiffies));
2628 BUG_ON(fibptr == NULL);
2631 synchronizereply = fib_data(fibptr);
2632 if (le32_to_cpu(synchronizereply->status) == CT_OK)
2633 cmd->result = DID_OK << 16 |
2634 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2636 struct scsi_device *sdev = cmd->device;
2637 struct aac_dev *dev = fibptr->dev;
2638 u32 cid = sdev_id(sdev);
2640 "synchronize_callback: synchronize failed, status = %d\n",
2641 le32_to_cpu(synchronizereply->status));
2642 cmd->result = DID_OK << 16 |
2643 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2644 set_sense(&dev->fsa_dev[cid].sense_data,
2645 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2646 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2647 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2648 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2649 SCSI_SENSE_BUFFERSIZE));
2652 aac_fib_complete(fibptr);
2653 aac_fib_free(fibptr);
2654 cmd->scsi_done(cmd);
2657 static int aac_synchronize(struct scsi_cmnd *scsicmd)
2660 struct fib *cmd_fibcontext;
2661 struct aac_synchronize *synchronizecmd;
2662 struct scsi_cmnd *cmd;
2663 struct scsi_device *sdev = scsicmd->device;
2665 struct aac_dev *aac;
2666 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2667 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2668 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2669 unsigned long flags;
2672 * Wait for all outstanding queued commands to complete to this
2673 * specific target (block).
2675 spin_lock_irqsave(&sdev->list_lock, flags);
2676 list_for_each_entry(cmd, &sdev->cmd_list, list)
2677 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2681 if (cmd->cmnd[0] == WRITE_6) {
2682 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2683 (cmd->cmnd[2] << 8) |
2685 cmnd_count = cmd->cmnd[4];
2686 if (cmnd_count == 0)
2688 } else if (cmd->cmnd[0] == WRITE_16) {
2689 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2690 ((u64)cmd->cmnd[3] << 48) |
2691 ((u64)cmd->cmnd[4] << 40) |
2692 ((u64)cmd->cmnd[5] << 32) |
2693 ((u64)cmd->cmnd[6] << 24) |
2694 (cmd->cmnd[7] << 16) |
2695 (cmd->cmnd[8] << 8) |
2697 cmnd_count = (cmd->cmnd[10] << 24) |
2698 (cmd->cmnd[11] << 16) |
2699 (cmd->cmnd[12] << 8) |
2701 } else if (cmd->cmnd[0] == WRITE_12) {
2702 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2703 (cmd->cmnd[3] << 16) |
2704 (cmd->cmnd[4] << 8) |
2706 cmnd_count = (cmd->cmnd[6] << 24) |
2707 (cmd->cmnd[7] << 16) |
2708 (cmd->cmnd[8] << 8) |
2710 } else if (cmd->cmnd[0] == WRITE_10) {
2711 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2712 (cmd->cmnd[3] << 16) |
2713 (cmd->cmnd[4] << 8) |
2715 cmnd_count = (cmd->cmnd[7] << 8) |
2719 if (((cmnd_lba + cmnd_count) < lba) ||
2720 (count && ((lba + count) < cmnd_lba)))
2726 spin_unlock_irqrestore(&sdev->list_lock, flags);
2729 * Yield the processor (requeue for later)
2732 return SCSI_MLQUEUE_DEVICE_BUSY;
2734 aac = (struct aac_dev *)sdev->host->hostdata;
2736 return SCSI_MLQUEUE_HOST_BUSY;
2739 * Allocate and initialize a Fib
2741 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
2742 return SCSI_MLQUEUE_HOST_BUSY;
2744 aac_fib_init(cmd_fibcontext);
2746 synchronizecmd = fib_data(cmd_fibcontext);
2747 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2748 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
2749 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
2750 synchronizecmd->count =
2751 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2752 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2755 * Now send the Fib to the adapter
2757 status = aac_fib_send(ContainerCommand,
2759 sizeof(struct aac_synchronize),
2762 (fib_callback)synchronize_callback,
2766 * Check that the command queued to the controller
2768 if (status == -EINPROGRESS)
2772 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2773 aac_fib_complete(cmd_fibcontext);
2774 aac_fib_free(cmd_fibcontext);
2775 return SCSI_MLQUEUE_HOST_BUSY;
2778 static void aac_start_stop_callback(void *context, struct fib *fibptr)
2780 struct scsi_cmnd *scsicmd = context;
2782 if (!aac_valid_context(scsicmd, fibptr))
2785 BUG_ON(fibptr == NULL);
2787 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2789 aac_fib_complete(fibptr);
2790 aac_fib_free(fibptr);
2791 scsicmd->scsi_done(scsicmd);
2794 static int aac_start_stop(struct scsi_cmnd *scsicmd)
2797 struct fib *cmd_fibcontext;
2798 struct aac_power_management *pmcmd;
2799 struct scsi_device *sdev = scsicmd->device;
2800 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2802 if (!(aac->supplement_adapter_info.supported_options2 &
2803 AAC_OPTION_POWER_MANAGEMENT)) {
2804 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2806 scsicmd->scsi_done(scsicmd);
2811 return SCSI_MLQUEUE_HOST_BUSY;
2814 * Allocate and initialize a Fib
2816 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
2818 aac_fib_init(cmd_fibcontext);
2820 pmcmd = fib_data(cmd_fibcontext);
2821 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2822 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2823 /* Eject bit ignored, not relevant */
2824 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2825 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2826 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2827 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2828 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2829 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2832 * Now send the Fib to the adapter
2834 status = aac_fib_send(ContainerCommand,
2836 sizeof(struct aac_power_management),
2839 (fib_callback)aac_start_stop_callback,
2843 * Check that the command queued to the controller
2845 if (status == -EINPROGRESS)
2848 aac_fib_complete(cmd_fibcontext);
2849 aac_fib_free(cmd_fibcontext);
2850 return SCSI_MLQUEUE_HOST_BUSY;
2854 * aac_scsi_cmd() - Process SCSI command
2855 * @scsicmd: SCSI command block
2857 * Emulate a SCSI command and queue the required request for the
2861 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2864 struct Scsi_Host *host = scsicmd->device->host;
2865 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2866 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
2868 if (fsa_dev_ptr == NULL)
2871 * If the bus, id or lun is out of range, return fail
2872 * Test does not apply to ID 16, the pseudo id for the controller
2875 cid = scmd_id(scsicmd);
2876 if (cid != host->this_id) {
2877 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2878 if((cid >= dev->maximum_num_containers) ||
2879 (scsicmd->device->lun != 0)) {
2880 scsicmd->result = DID_NO_CONNECT << 16;
2885 * If the target container doesn't exist, it may have
2886 * been newly created
2888 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2889 (fsa_dev_ptr[cid].sense_data.sense_key ==
2891 switch (scsicmd->cmnd[0]) {
2892 case SERVICE_ACTION_IN_16:
2893 if (!(dev->raw_io_interface) ||
2894 !(dev->raw_io_64) ||
2895 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2899 case TEST_UNIT_READY:
2902 return _aac_probe_container(scsicmd,
2903 aac_probe_container_callback2);
2908 } else { /* check for physical non-dasd devices */
2909 bus = aac_logical_to_phys(scmd_channel(scsicmd));
2911 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2912 dev->hba_map[bus][cid].devtype
2913 == AAC_DEVTYPE_NATIVE_RAW) {
2916 return aac_send_hba_fib(scsicmd);
2917 } else if (dev->nondasd_support || expose_physicals ||
2921 return aac_send_srb_fib(scsicmd);
2923 scsicmd->result = DID_NO_CONNECT << 16;
2929 * else Command for the controller itself
2931 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
2932 (scsicmd->cmnd[0] != TEST_UNIT_READY))
2934 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2935 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2936 set_sense(&dev->fsa_dev[cid].sense_data,
2937 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2938 ASENCODE_INVALID_COMMAND, 0, 0);
2939 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2940 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2941 SCSI_SENSE_BUFFERSIZE));
2945 switch (scsicmd->cmnd[0]) {
2952 return aac_read(scsicmd);
2960 return aac_write(scsicmd);
2962 case SYNCHRONIZE_CACHE:
2963 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2964 scsicmd->result = AAC_STAT_GOOD;
2967 /* Issue FIB to tell Firmware to flush it's cache */
2968 if ((aac_cache & 6) != 2)
2969 return aac_synchronize(scsicmd);
2972 struct inquiry_data inq_data;
2974 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
2975 memset(&inq_data, 0, sizeof (struct inquiry_data));
2977 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
2978 char *arr = (char *)&inq_data;
2981 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2982 INQD_PDT_PROC : INQD_PDT_DA;
2983 if (scsicmd->cmnd[2] == 0) {
2984 /* supported vital product data pages */
2989 arr[1] = scsicmd->cmnd[2];
2990 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2992 scsicmd->result = AAC_STAT_GOOD;
2993 } else if (scsicmd->cmnd[2] == 0x80) {
2994 /* unit serial number page */
2995 arr[3] = setinqserial(dev, &arr[4],
2997 arr[1] = scsicmd->cmnd[2];
2998 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
3001 return aac_get_container_serial(
3003 scsicmd->result = AAC_STAT_GOOD;
3004 } else if (scsicmd->cmnd[2] == 0x83) {
3005 /* vpd page 0x83 - Device Identification Page */
3006 char *sno = (char *)&inq_data;
3007 sno[3] = setinqserial(dev, &sno[4],
3010 return aac_get_container_serial(
3012 scsicmd->result = AAC_STAT_GOOD;
3014 /* vpd page not implemented */
3015 scsicmd->result = DID_OK << 16 |
3016 COMMAND_COMPLETE << 8 |
3017 SAM_STAT_CHECK_CONDITION;
3018 set_sense(&dev->fsa_dev[cid].sense_data,
3019 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
3020 ASENCODE_NO_SENSE, 7, 2);
3021 memcpy(scsicmd->sense_buffer,
3022 &dev->fsa_dev[cid].sense_data,
3024 sizeof(dev->fsa_dev[cid].sense_data),
3025 SCSI_SENSE_BUFFERSIZE));
3029 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
3030 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 */
3031 inq_data.inqd_len = 31;
3032 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
3033 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
3035 * Set the Vendor, Product, and Revision Level
3036 * see: <vendor>.c i.e. aac.c
3038 if (cid == host->this_id) {
3039 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
3040 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
3041 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
3043 scsicmd->result = AAC_STAT_GOOD;
3048 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
3049 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
3050 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
3051 return aac_get_container_name(scsicmd);
3053 case SERVICE_ACTION_IN_16:
3054 if (!(dev->raw_io_interface) ||
3055 !(dev->raw_io_64) ||
3056 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
3061 unsigned int alloc_len;
3063 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
3064 capacity = fsa_dev_ptr[cid].size - 1;
3065 cp[0] = (capacity >> 56) & 0xff;
3066 cp[1] = (capacity >> 48) & 0xff;
3067 cp[2] = (capacity >> 40) & 0xff;
3068 cp[3] = (capacity >> 32) & 0xff;
3069 cp[4] = (capacity >> 24) & 0xff;
3070 cp[5] = (capacity >> 16) & 0xff;
3071 cp[6] = (capacity >> 8) & 0xff;
3072 cp[7] = (capacity >> 0) & 0xff;
3073 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3074 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3075 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3076 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
3079 alloc_len = ((scsicmd->cmnd[10] << 24)
3080 + (scsicmd->cmnd[11] << 16)
3081 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
3083 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
3084 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
3085 if (alloc_len < scsi_bufflen(scsicmd))
3086 scsi_set_resid(scsicmd,
3087 scsi_bufflen(scsicmd) - alloc_len);
3089 /* Do not cache partition table for arrays */
3090 scsicmd->device->removable = 1;
3092 scsicmd->result = AAC_STAT_GOOD;
3101 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
3102 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3103 capacity = fsa_dev_ptr[cid].size - 1;
3107 cp[0] = (capacity >> 24) & 0xff;
3108 cp[1] = (capacity >> 16) & 0xff;
3109 cp[2] = (capacity >> 8) & 0xff;
3110 cp[3] = (capacity >> 0) & 0xff;
3111 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3112 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3113 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3114 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
3115 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
3116 /* Do not cache partition table for arrays */
3117 scsicmd->device->removable = 1;
3118 scsicmd->result = AAC_STAT_GOOD;
3124 int mode_buf_length = 4;
3128 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3129 capacity = fsa_dev_ptr[cid].size - 1;
3133 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
3134 memset((char *)&mpd, 0, sizeof(aac_modep_data));
3136 /* Mode data length */
3137 mpd.hd.data_length = sizeof(mpd.hd) - 1;
3138 /* Medium type - default */
3139 mpd.hd.med_type = 0;
3140 /* Device-specific param,
3141 bit 8: 0/1 = write enabled/protected
3142 bit 4: 0/1 = FUA enabled */
3145 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
3146 mpd.hd.dev_par = 0x10;
3147 if (scsicmd->cmnd[1] & 0x8)
3148 mpd.hd.bd_length = 0; /* Block descriptor length */
3150 mpd.hd.bd_length = sizeof(mpd.bd);
3151 mpd.hd.data_length += mpd.hd.bd_length;
3152 mpd.bd.block_length[0] =
3153 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3154 mpd.bd.block_length[1] =
3155 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3156 mpd.bd.block_length[2] =
3157 fsa_dev_ptr[cid].block_size & 0xff;
3159 mpd.mpc_buf[0] = scsicmd->cmnd[2];
3160 if (scsicmd->cmnd[2] == 0x1C) {
3162 mpd.mpc_buf[1] = 0xa;
3163 /* Mode data length */
3164 mpd.hd.data_length = 23;
3166 /* Mode data length */
3167 mpd.hd.data_length = 15;
3170 if (capacity > 0xffffff) {
3171 mpd.bd.block_count[0] = 0xff;
3172 mpd.bd.block_count[1] = 0xff;
3173 mpd.bd.block_count[2] = 0xff;
3175 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
3176 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
3177 mpd.bd.block_count[2] = capacity & 0xff;
3180 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3181 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
3182 mpd.hd.data_length += 3;
3185 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
3186 ? 0 : 0x04; /* WCE */
3187 mode_buf_length = sizeof(mpd);
3190 if (mode_buf_length > scsicmd->cmnd[4])
3191 mode_buf_length = scsicmd->cmnd[4];
3193 mode_buf_length = sizeof(mpd);
3194 scsi_sg_copy_from_buffer(scsicmd,
3197 scsicmd->result = AAC_STAT_GOOD;
3203 int mode_buf_length = 8;
3204 aac_modep10_data mpd10;
3206 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3207 capacity = fsa_dev_ptr[cid].size - 1;
3211 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
3212 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
3213 /* Mode data length (MSB) */
3214 mpd10.hd.data_length[0] = 0;
3215 /* Mode data length (LSB) */
3216 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
3217 /* Medium type - default */
3218 mpd10.hd.med_type = 0;
3219 /* Device-specific param,
3220 bit 8: 0/1 = write enabled/protected
3221 bit 4: 0/1 = FUA enabled */
3222 mpd10.hd.dev_par = 0;
3224 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
3225 mpd10.hd.dev_par = 0x10;
3226 mpd10.hd.rsrvd[0] = 0; /* reserved */
3227 mpd10.hd.rsrvd[1] = 0; /* reserved */
3228 if (scsicmd->cmnd[1] & 0x8) {
3229 /* Block descriptor length (MSB) */
3230 mpd10.hd.bd_length[0] = 0;
3231 /* Block descriptor length (LSB) */
3232 mpd10.hd.bd_length[1] = 0;
3234 mpd10.hd.bd_length[0] = 0;
3235 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
3237 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
3239 mpd10.bd.block_length[0] =
3240 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3241 mpd10.bd.block_length[1] =
3242 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3243 mpd10.bd.block_length[2] =
3244 fsa_dev_ptr[cid].block_size & 0xff;
3246 if (capacity > 0xffffff) {
3247 mpd10.bd.block_count[0] = 0xff;
3248 mpd10.bd.block_count[1] = 0xff;
3249 mpd10.bd.block_count[2] = 0xff;
3251 mpd10.bd.block_count[0] =
3252 (capacity >> 16) & 0xff;
3253 mpd10.bd.block_count[1] =
3254 (capacity >> 8) & 0xff;
3255 mpd10.bd.block_count[2] =
3259 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3260 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
3261 mpd10.hd.data_length[1] += 3;
3262 mpd10.mpc_buf[0] = 8;
3263 mpd10.mpc_buf[1] = 1;
3264 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
3265 ? 0 : 0x04; /* WCE */
3266 mode_buf_length = sizeof(mpd10);
3267 if (mode_buf_length > scsicmd->cmnd[8])
3268 mode_buf_length = scsicmd->cmnd[8];
3270 scsi_sg_copy_from_buffer(scsicmd,
3274 scsicmd->result = AAC_STAT_GOOD;
3278 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
3279 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3280 sizeof(struct sense_data));
3281 memset(&dev->fsa_dev[cid].sense_data, 0,
3282 sizeof(struct sense_data));
3283 scsicmd->result = AAC_STAT_GOOD;
3286 case ALLOW_MEDIUM_REMOVAL:
3287 dprintk((KERN_DEBUG "LOCK command.\n"));
3288 if (scsicmd->cmnd[4])
3289 fsa_dev_ptr[cid].locked = 1;
3291 fsa_dev_ptr[cid].locked = 0;
3293 scsicmd->result = AAC_STAT_GOOD;
3296 * These commands are all No-Ops
3298 case TEST_UNIT_READY:
3299 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
3300 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3301 SAM_STAT_CHECK_CONDITION;
3302 set_sense(&dev->fsa_dev[cid].sense_data,
3303 NOT_READY, SENCODE_BECOMING_READY,
3304 ASENCODE_BECOMING_READY, 0, 0);
3305 memcpy(scsicmd->sense_buffer,
3306 &dev->fsa_dev[cid].sense_data,
3308 sizeof(dev->fsa_dev[cid].sense_data),
3309 SCSI_SENSE_BUFFERSIZE));
3315 case REASSIGN_BLOCKS:
3317 scsicmd->result = AAC_STAT_GOOD;
3321 return aac_start_stop(scsicmd);
3326 * Unhandled commands
3328 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
3330 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3331 SAM_STAT_CHECK_CONDITION;
3332 set_sense(&dev->fsa_dev[cid].sense_data,
3333 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
3334 ASENCODE_INVALID_COMMAND, 0, 0);
3335 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3337 sizeof(dev->fsa_dev[cid].sense_data),
3338 SCSI_SENSE_BUFFERSIZE));
3343 scsicmd->scsi_done(scsicmd);
3347 static int query_disk(struct aac_dev *dev, void __user *arg)
3349 struct aac_query_disk qd;
3350 struct fsa_dev_info *fsa_dev_ptr;
3352 fsa_dev_ptr = dev->fsa_dev;
3355 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
3357 if (qd.cnum == -1) {
3358 if (qd.id < 0 || qd.id >= dev->maximum_num_containers)
3361 } else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) {
3362 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
3364 qd.instance = dev->scsi_host_ptr->host_no;
3366 qd.id = CONTAINER_TO_ID(qd.cnum);
3367 qd.lun = CONTAINER_TO_LUN(qd.cnum);
3369 else return -EINVAL;
3371 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
3372 qd.locked = fsa_dev_ptr[qd.cnum].locked;
3373 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
3375 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
3380 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
3381 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
3383 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
3388 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
3390 struct aac_delete_disk dd;
3391 struct fsa_dev_info *fsa_dev_ptr;
3393 fsa_dev_ptr = dev->fsa_dev;
3397 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3400 if (dd.cnum >= dev->maximum_num_containers)
3403 * Mark this container as being deleted.
3405 fsa_dev_ptr[dd.cnum].deleted = 1;
3407 * Mark the container as no longer valid
3409 fsa_dev_ptr[dd.cnum].valid = 0;
3413 static int delete_disk(struct aac_dev *dev, void __user *arg)
3415 struct aac_delete_disk dd;
3416 struct fsa_dev_info *fsa_dev_ptr;
3418 fsa_dev_ptr = dev->fsa_dev;
3422 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3425 if (dd.cnum >= dev->maximum_num_containers)
3428 * If the container is locked, it can not be deleted by the API.
3430 if (fsa_dev_ptr[dd.cnum].locked)
3434 * Mark the container as no longer being valid.
3436 fsa_dev_ptr[dd.cnum].valid = 0;
3437 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
3442 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
3445 case FSACTL_QUERY_DISK:
3446 return query_disk(dev, arg);
3447 case FSACTL_DELETE_DISK:
3448 return delete_disk(dev, arg);
3449 case FSACTL_FORCE_DELETE_DISK:
3450 return force_delete_disk(dev, arg);
3451 case FSACTL_GET_CONTAINERS:
3452 return aac_get_containers(dev);
3461 * @context: the context set in the fib - here it is scsi cmd
3462 * @fibptr: pointer to the fib
3464 * Handles the completion of a scsi command to a non dasd device
3468 static void aac_srb_callback(void *context, struct fib * fibptr)
3470 struct aac_dev *dev;
3471 struct aac_srb_reply *srbreply;
3472 struct scsi_cmnd *scsicmd;
3474 scsicmd = (struct scsi_cmnd *) context;
3476 if (!aac_valid_context(scsicmd, fibptr))
3479 BUG_ON(fibptr == NULL);
3483 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
3485 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
3487 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3489 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
3490 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
3493 * Calculate resid for sg
3495 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
3496 - le32_to_cpu(srbreply->data_xfer_length));
3500 scsi_dma_unmap(scsicmd);
3502 /* expose physical device if expose_physicald flag is on */
3503 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
3504 && expose_physicals > 0)
3505 aac_expose_phy_device(scsicmd);
3508 * First check the fib status
3511 if (le32_to_cpu(srbreply->status) != ST_OK) {
3514 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3515 le32_to_cpu(srbreply->status));
3516 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3517 SCSI_SENSE_BUFFERSIZE);
3518 scsicmd->result = DID_ERROR << 16
3519 | COMMAND_COMPLETE << 8
3520 | SAM_STAT_CHECK_CONDITION;
3521 memcpy(scsicmd->sense_buffer,
3522 srbreply->sense_data, len);
3526 * Next check the srb status
3528 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3529 case SRB_STATUS_ERROR_RECOVERY:
3530 case SRB_STATUS_PENDING:
3531 case SRB_STATUS_SUCCESS:
3532 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3534 case SRB_STATUS_DATA_OVERRUN:
3535 switch (scsicmd->cmnd[0]) {
3544 if (le32_to_cpu(srbreply->data_xfer_length)
3545 < scsicmd->underflow)
3546 pr_warn("aacraid: SCSI CMD underflow\n");
3548 pr_warn("aacraid: SCSI CMD Data Overrun\n");
3549 scsicmd->result = DID_ERROR << 16
3550 | COMMAND_COMPLETE << 8;
3553 scsicmd->result = DID_OK << 16
3554 | COMMAND_COMPLETE << 8;
3557 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3561 case SRB_STATUS_ABORTED:
3562 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3564 case SRB_STATUS_ABORT_FAILED:
3566 * Not sure about this one - but assuming the
3567 * hba was trying to abort for some reason
3569 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3571 case SRB_STATUS_PARITY_ERROR:
3572 scsicmd->result = DID_PARITY << 16
3573 | MSG_PARITY_ERROR << 8;
3575 case SRB_STATUS_NO_DEVICE:
3576 case SRB_STATUS_INVALID_PATH_ID:
3577 case SRB_STATUS_INVALID_TARGET_ID:
3578 case SRB_STATUS_INVALID_LUN:
3579 case SRB_STATUS_SELECTION_TIMEOUT:
3580 scsicmd->result = DID_NO_CONNECT << 16
3581 | COMMAND_COMPLETE << 8;
3584 case SRB_STATUS_COMMAND_TIMEOUT:
3585 case SRB_STATUS_TIMEOUT:
3586 scsicmd->result = DID_TIME_OUT << 16
3587 | COMMAND_COMPLETE << 8;
3590 case SRB_STATUS_BUSY:
3591 scsicmd->result = DID_BUS_BUSY << 16
3592 | COMMAND_COMPLETE << 8;
3595 case SRB_STATUS_BUS_RESET:
3596 scsicmd->result = DID_RESET << 16
3597 | COMMAND_COMPLETE << 8;
3600 case SRB_STATUS_MESSAGE_REJECTED:
3601 scsicmd->result = DID_ERROR << 16
3602 | MESSAGE_REJECT << 8;
3604 case SRB_STATUS_REQUEST_FLUSHED:
3605 case SRB_STATUS_ERROR:
3606 case SRB_STATUS_INVALID_REQUEST:
3607 case SRB_STATUS_REQUEST_SENSE_FAILED:
3608 case SRB_STATUS_NO_HBA:
3609 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3610 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3611 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3612 case SRB_STATUS_DELAYED_RETRY:
3613 case SRB_STATUS_BAD_FUNCTION:
3614 case SRB_STATUS_NOT_STARTED:
3615 case SRB_STATUS_NOT_IN_USE:
3616 case SRB_STATUS_FORCE_ABORT:
3617 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3619 #ifdef AAC_DETAILED_STATUS_INFO
3620 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3621 le32_to_cpu(srbreply->srb_status) & 0x3F,
3622 aac_get_status_string(
3623 le32_to_cpu(srbreply->srb_status) & 0x3F),
3625 le32_to_cpu(srbreply->scsi_status));
3628 * When the CC bit is SET by the host in ATA pass thru CDB,
3629 * driver is supposed to return DID_OK
3631 * When the CC bit is RESET by the host, driver should
3634 if ((scsicmd->cmnd[0] == ATA_12)
3635 || (scsicmd->cmnd[0] == ATA_16)) {
3637 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3638 scsicmd->result = DID_OK << 16
3639 | COMMAND_COMPLETE << 8;
3642 scsicmd->result = DID_ERROR << 16
3643 | COMMAND_COMPLETE << 8;
3647 scsicmd->result = DID_ERROR << 16
3648 | COMMAND_COMPLETE << 8;
3652 if (le32_to_cpu(srbreply->scsi_status)
3653 == SAM_STAT_CHECK_CONDITION) {
3656 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3657 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3658 SCSI_SENSE_BUFFERSIZE);
3659 #ifdef AAC_DETAILED_STATUS_INFO
3660 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3661 le32_to_cpu(srbreply->status), len);
3663 memcpy(scsicmd->sense_buffer,
3664 srbreply->sense_data, len);
3668 * OR in the scsi status (already shifted up a bit)
3670 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3672 aac_fib_complete(fibptr);
3673 scsicmd->scsi_done(scsicmd);
3676 static void hba_resp_task_complete(struct aac_dev *dev,
3677 struct scsi_cmnd *scsicmd,
3678 struct aac_hba_resp *err) {
3680 scsicmd->result = err->status;
3681 /* set residual count */
3682 scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
3684 switch (err->status) {
3686 scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3688 case SAM_STAT_CHECK_CONDITION:
3692 len = min_t(u8, err->sense_response_data_len,
3693 SCSI_SENSE_BUFFERSIZE);
3695 memcpy(scsicmd->sense_buffer,
3696 err->sense_response_buf, len);
3697 scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3701 scsicmd->result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
3703 case SAM_STAT_TASK_ABORTED:
3704 scsicmd->result |= DID_ABORT << 16 | ABORT << 8;
3706 case SAM_STAT_RESERVATION_CONFLICT:
3707 case SAM_STAT_TASK_SET_FULL:
3709 scsicmd->result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3714 static void hba_resp_task_failure(struct aac_dev *dev,
3715 struct scsi_cmnd *scsicmd,
3716 struct aac_hba_resp *err)
3718 switch (err->status) {
3719 case HBA_RESP_STAT_HBAMODE_DISABLED:
3723 bus = aac_logical_to_phys(scmd_channel(scsicmd));
3724 cid = scmd_id(scsicmd);
3725 if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
3726 dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
3727 dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
3729 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3732 case HBA_RESP_STAT_IO_ERROR:
3733 case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
3734 scsicmd->result = DID_OK << 16 |
3735 COMMAND_COMPLETE << 8 | SAM_STAT_BUSY;
3737 case HBA_RESP_STAT_IO_ABORTED:
3738 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3740 case HBA_RESP_STAT_INVALID_DEVICE:
3741 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3743 case HBA_RESP_STAT_UNDERRUN:
3744 /* UNDERRUN is OK */
3745 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3747 case HBA_RESP_STAT_OVERRUN:
3749 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3757 * @context: the context set in the fib - here it is scsi cmd
3758 * @fibptr: pointer to the fib
3760 * Handles the completion of a native HBA scsi command
3763 void aac_hba_callback(void *context, struct fib *fibptr)
3765 struct aac_dev *dev;
3766 struct scsi_cmnd *scsicmd;
3768 struct aac_hba_resp *err =
3769 &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
3771 scsicmd = (struct scsi_cmnd *) context;
3773 if (!aac_valid_context(scsicmd, fibptr))
3776 WARN_ON(fibptr == NULL);
3779 if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
3780 scsi_dma_unmap(scsicmd);
3782 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3784 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3788 switch (err->service_response) {
3789 case HBA_RESP_SVCRES_TASK_COMPLETE:
3790 hba_resp_task_complete(dev, scsicmd, err);
3792 case HBA_RESP_SVCRES_FAILURE:
3793 hba_resp_task_failure(dev, scsicmd, err);
3795 case HBA_RESP_SVCRES_TMF_REJECTED:
3796 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
3798 case HBA_RESP_SVCRES_TMF_LUN_INVALID:
3799 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3801 case HBA_RESP_SVCRES_TMF_COMPLETE:
3802 case HBA_RESP_SVCRES_TMF_SUCCEEDED:
3803 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3806 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3811 aac_fib_complete(fibptr);
3813 if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
3814 scsicmd->SCp.sent_command = 1;
3816 scsicmd->scsi_done(scsicmd);
3822 * @scsicmd: the scsi command block
3824 * This routine will form a FIB and fill in the aac_srb from the
3825 * scsicmd passed in.
3828 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3830 struct fib* cmd_fibcontext;
3831 struct aac_dev* dev;
3834 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3835 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3836 scsicmd->device->lun > 7) {
3837 scsicmd->result = DID_NO_CONNECT << 16;
3838 scsicmd->scsi_done(scsicmd);
3843 * Allocate and initialize a Fib then setup a BlockWrite command
3845 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3846 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3847 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
3850 * Check that the command queued to the controller
3852 if (status == -EINPROGRESS)
3855 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3856 aac_fib_complete(cmd_fibcontext);
3857 aac_fib_free(cmd_fibcontext);
3865 * @scsicmd: the scsi command block
3867 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3868 * scsicmd passed in.
3870 static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
3872 struct fib *cmd_fibcontext;
3873 struct aac_dev *dev;
3876 dev = shost_priv(scsicmd->device->host);
3877 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3878 scsicmd->device->lun > AAC_MAX_LUN - 1) {
3879 scsicmd->result = DID_NO_CONNECT << 16;
3880 scsicmd->scsi_done(scsicmd);
3885 * Allocate and initialize a Fib then setup a BlockWrite command
3887 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3888 if (!cmd_fibcontext)
3891 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3892 status = aac_adapter_hba(cmd_fibcontext, scsicmd);
3895 * Check that the command queued to the controller
3897 if (status == -EINPROGRESS)
3900 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3902 aac_fib_complete(cmd_fibcontext);
3903 aac_fib_free(cmd_fibcontext);
3909 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
3911 struct aac_dev *dev;
3912 unsigned long byte_count = 0;
3914 struct scatterlist *sg;
3917 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3918 // Get rid of old data
3920 psg->sg[0].addr = 0;
3921 psg->sg[0].count = 0;
3923 nseg = scsi_dma_map(scsicmd);
3927 psg->count = cpu_to_le32(nseg);
3929 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3930 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3931 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3932 byte_count += sg_dma_len(sg);
3934 /* hba wants the size to be exact */
3935 if (byte_count > scsi_bufflen(scsicmd)) {
3936 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3937 (byte_count - scsi_bufflen(scsicmd));
3938 psg->sg[i-1].count = cpu_to_le32(temp);
3939 byte_count = scsi_bufflen(scsicmd);
3941 /* Check for command underflow */
3942 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3943 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3944 byte_count, scsicmd->underflow);
3951 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
3953 struct aac_dev *dev;
3954 unsigned long byte_count = 0;
3957 struct scatterlist *sg;
3960 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3961 // Get rid of old data
3963 psg->sg[0].addr[0] = 0;
3964 psg->sg[0].addr[1] = 0;
3965 psg->sg[0].count = 0;
3967 nseg = scsi_dma_map(scsicmd);
3971 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3972 int count = sg_dma_len(sg);
3973 addr = sg_dma_address(sg);
3974 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3975 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
3976 psg->sg[i].count = cpu_to_le32(count);
3977 byte_count += count;
3979 psg->count = cpu_to_le32(nseg);
3980 /* hba wants the size to be exact */
3981 if (byte_count > scsi_bufflen(scsicmd)) {
3982 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3983 (byte_count - scsi_bufflen(scsicmd));
3984 psg->sg[i-1].count = cpu_to_le32(temp);
3985 byte_count = scsi_bufflen(scsicmd);
3987 /* Check for command underflow */
3988 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3989 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3990 byte_count, scsicmd->underflow);
3996 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
3998 unsigned long byte_count = 0;
4000 struct scatterlist *sg;
4003 // Get rid of old data
4005 psg->sg[0].next = 0;
4006 psg->sg[0].prev = 0;
4007 psg->sg[0].addr[0] = 0;
4008 psg->sg[0].addr[1] = 0;
4009 psg->sg[0].count = 0;
4010 psg->sg[0].flags = 0;
4012 nseg = scsi_dma_map(scsicmd);
4016 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4017 int count = sg_dma_len(sg);
4018 u64 addr = sg_dma_address(sg);
4019 psg->sg[i].next = 0;
4020 psg->sg[i].prev = 0;
4021 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
4022 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
4023 psg->sg[i].count = cpu_to_le32(count);
4024 psg->sg[i].flags = 0;
4025 byte_count += count;
4027 psg->count = cpu_to_le32(nseg);
4028 /* hba wants the size to be exact */
4029 if (byte_count > scsi_bufflen(scsicmd)) {
4030 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
4031 (byte_count - scsi_bufflen(scsicmd));
4032 psg->sg[i-1].count = cpu_to_le32(temp);
4033 byte_count = scsi_bufflen(scsicmd);
4035 /* Check for command underflow */
4036 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4037 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
4038 byte_count, scsicmd->underflow);
4044 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
4045 struct aac_raw_io2 *rio2, int sg_max)
4047 unsigned long byte_count = 0;
4049 struct scatterlist *sg;
4050 int i, conformable = 0;
4051 u32 min_size = PAGE_SIZE, cur_size;
4053 nseg = scsi_dma_map(scsicmd);
4057 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4058 int count = sg_dma_len(sg);
4059 u64 addr = sg_dma_address(sg);
4061 BUG_ON(i >= sg_max);
4062 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
4063 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
4064 cur_size = cpu_to_le32(count);
4065 rio2->sge[i].length = cur_size;
4066 rio2->sge[i].flags = 0;
4069 rio2->sgeFirstSize = cur_size;
4070 } else if (i == 1) {
4071 rio2->sgeNominalSize = cur_size;
4072 min_size = cur_size;
4073 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
4075 if (cur_size < min_size)
4076 min_size = cur_size;
4078 byte_count += count;
4081 /* hba wants the size to be exact */
4082 if (byte_count > scsi_bufflen(scsicmd)) {
4083 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
4084 (byte_count - scsi_bufflen(scsicmd));
4085 rio2->sge[i-1].length = cpu_to_le32(temp);
4086 byte_count = scsi_bufflen(scsicmd);
4089 rio2->sgeCnt = cpu_to_le32(nseg);
4090 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
4091 /* not conformable: evaluate required sg elements */
4093 int j, nseg_new = nseg, err_found;
4094 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
4097 for (j = 1; j < nseg - 1; ++j) {
4098 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
4102 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
4107 if (i > 0 && nseg_new <= sg_max) {
4108 int ret = aac_convert_sgraw2(rio2, i, nseg, nseg_new);
4114 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4116 /* Check for command underflow */
4117 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4118 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
4119 byte_count, scsicmd->underflow);
4125 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
4127 struct sge_ieee1212 *sge;
4131 if (aac_convert_sgl == 0)
4134 sge = kmalloc_array(nseg_new, sizeof(struct sge_ieee1212), GFP_ATOMIC);
4138 for (i = 1, pos = 1; i < nseg-1; ++i) {
4139 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
4140 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
4141 sge[pos].addrLow = addr_low;
4142 sge[pos].addrHigh = rio2->sge[i].addrHigh;
4143 if (addr_low < rio2->sge[i].addrLow)
4144 sge[pos].addrHigh++;
4145 sge[pos].length = pages * PAGE_SIZE;
4150 sge[pos] = rio2->sge[nseg-1];
4151 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
4154 rio2->sgeCnt = cpu_to_le32(nseg_new);
4155 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4156 rio2->sgeNominalSize = pages * PAGE_SIZE;
4160 static long aac_build_sghba(struct scsi_cmnd *scsicmd,
4161 struct aac_hba_cmd_req *hbacmd,
4165 unsigned long byte_count = 0;
4167 struct scatterlist *sg;
4170 struct aac_hba_sgl *sge;
4172 nseg = scsi_dma_map(scsicmd);
4178 if (nseg > HBA_MAX_SG_EMBEDDED)
4179 sge = &hbacmd->sge[2];
4181 sge = &hbacmd->sge[0];
4183 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4184 int count = sg_dma_len(sg);
4185 u64 addr = sg_dma_address(sg);
4187 WARN_ON(i >= sg_max);
4188 sge->addr_hi = cpu_to_le32((u32)(addr>>32));
4189 sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
4190 cur_size = cpu_to_le32(count);
4191 sge->len = cur_size;
4193 byte_count += count;
4198 /* hba wants the size to be exact */
4199 if (byte_count > scsi_bufflen(scsicmd)) {
4202 temp = le32_to_cpu(sge->len) - byte_count
4203 - scsi_bufflen(scsicmd);
4204 sge->len = cpu_to_le32(temp);
4205 byte_count = scsi_bufflen(scsicmd);
4208 if (nseg <= HBA_MAX_SG_EMBEDDED) {
4209 hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
4210 sge->flags = cpu_to_le32(0x40000000);
4213 hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
4214 hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
4215 hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
4216 hbacmd->sge[0].addr_lo =
4217 cpu_to_le32((u32)(sg_address & 0xffffffff));
4220 /* Check for command underflow */
4221 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4222 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4223 byte_count, scsicmd->underflow);
4229 #ifdef AAC_DETAILED_STATUS_INFO
4231 struct aac_srb_status_info {
4237 static struct aac_srb_status_info srb_status_info[] = {
4238 { SRB_STATUS_PENDING, "Pending Status"},
4239 { SRB_STATUS_SUCCESS, "Success"},
4240 { SRB_STATUS_ABORTED, "Aborted Command"},
4241 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
4242 { SRB_STATUS_ERROR, "Error Event"},
4243 { SRB_STATUS_BUSY, "Device Busy"},
4244 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
4245 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
4246 { SRB_STATUS_NO_DEVICE, "No Device"},
4247 { SRB_STATUS_TIMEOUT, "Timeout"},
4248 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
4249 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
4250 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
4251 { SRB_STATUS_BUS_RESET, "Bus Reset"},
4252 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
4253 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
4254 { SRB_STATUS_NO_HBA, "No HBA"},
4255 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
4256 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
4257 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
4258 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
4259 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
4260 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
4261 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
4262 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
4263 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
4264 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
4265 { SRB_STATUS_NOT_STARTED, "Not Started"},
4266 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
4267 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
4268 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
4269 { 0xff, "Unknown Error"}
4272 char *aac_get_status_string(u32 status)
4276 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
4277 if (srb_status_info[i].status == status)
4278 return srb_status_info[i].str;
4280 return "Bad Status Code";