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 */
944 if (strlen(cp) > sizeof(str->pid)) {
945 c = cp[sizeof(str->pid)];
946 cp[sizeof(str->pid)] = '\0';
948 inqstrcpy (cp, str->pid);
952 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
954 inqstrcpy (mp->vname, str->vid);
955 /* last six chars reserved for vol type */
956 inqstrcpy (mp->model, str->pid);
959 if (tindex < ARRAY_SIZE(container_types)){
960 char *findit = str->pid;
962 for ( ; *findit != ' '; findit++); /* walk till we find a space */
963 /* RAID is superfluous in the context of a RAID device */
964 if (memcmp(findit-4, "RAID", 4) == 0)
965 *(findit -= 4) = ' ';
966 if (((findit - str->pid) + strlen(container_types[tindex]))
967 < (sizeof(str->pid) + sizeof(str->prl)))
968 inqstrcpy (container_types[tindex], findit + 1);
970 inqstrcpy ("V1.0", str->prl);
973 static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
974 struct aac_dev *dev, struct scsi_cmnd *scsicmd)
978 vpdpage83data->type3.codeset = 1;
979 vpdpage83data->type3.identifiertype = 3;
980 vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
983 for (container = 0; container < dev->maximum_num_containers;
986 if (scmd_id(scsicmd) == container) {
987 memcpy(vpdpage83data->type3.Identifier,
988 dev->fsa_dev[container].identifier,
995 static void get_container_serial_callback(void *context, struct fib * fibptr)
997 struct aac_get_serial_resp * get_serial_reply;
998 struct scsi_cmnd * scsicmd;
1000 BUG_ON(fibptr == NULL);
1002 scsicmd = (struct scsi_cmnd *) context;
1003 if (!aac_valid_context(scsicmd, fibptr))
1006 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
1007 /* Failure is irrelevant, using default value instead */
1008 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
1009 /*Check to see if it's for VPD 0x83 or 0x80 */
1010 if (scsicmd->cmnd[2] == 0x83) {
1011 /* vpd page 0x83 - Device Identification Page */
1012 struct aac_dev *dev;
1014 struct tvpd_page83 vpdpage83data;
1016 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1018 memset(((u8 *)&vpdpage83data), 0,
1019 sizeof(vpdpage83data));
1021 /* DIRECT_ACCESS_DEVIC */
1022 vpdpage83data.DeviceType = 0;
1023 /* DEVICE_CONNECTED */
1024 vpdpage83data.DeviceTypeQualifier = 0;
1025 /* VPD_DEVICE_IDENTIFIERS */
1026 vpdpage83data.PageCode = 0x83;
1027 vpdpage83data.reserved = 0;
1028 vpdpage83data.PageLength =
1029 sizeof(vpdpage83data.type1) +
1030 sizeof(vpdpage83data.type2);
1032 /* VPD 83 Type 3 is not supported for ARC */
1033 if (dev->sa_firmware)
1034 vpdpage83data.PageLength +=
1035 sizeof(vpdpage83data.type3);
1037 /* T10 Vendor Identifier Field Format */
1038 /* VpdcodesetAscii */
1039 vpdpage83data.type1.codeset = 2;
1040 /* VpdIdentifierTypeVendorId */
1041 vpdpage83data.type1.identifiertype = 1;
1042 vpdpage83data.type1.identifierlength =
1043 sizeof(vpdpage83data.type1) - 4;
1045 /* "ADAPTEC " for adaptec */
1046 memcpy(vpdpage83data.type1.venid,
1048 sizeof(vpdpage83data.type1.venid));
1049 memcpy(vpdpage83data.type1.productid,
1052 vpdpage83data.type1.productid));
1054 /* Convert to ascii based serial number.
1055 * The LSB is the the end.
1057 for (i = 0; i < 8; i++) {
1059 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
1061 vpdpage83data.type1.serialnumber[i] =
1064 vpdpage83data.type1.serialnumber[i] =
1069 /* VpdCodeSetBinary */
1070 vpdpage83data.type2.codeset = 1;
1071 /* VpdidentifiertypeEUI64 */
1072 vpdpage83data.type2.identifiertype = 2;
1073 vpdpage83data.type2.identifierlength =
1074 sizeof(vpdpage83data.type2) - 4;
1076 vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1077 vpdpage83data.type2.eu64id.venid[1] = 0;
1078 vpdpage83data.type2.eu64id.venid[2] = 0;
1080 vpdpage83data.type2.eu64id.Serial =
1081 get_serial_reply->uid;
1082 vpdpage83data.type2.eu64id.reserved = 0;
1085 * VpdIdentifierTypeFCPHName
1086 * VPD 0x83 Type 3 not supported for ARC
1088 if (dev->sa_firmware) {
1089 build_vpd83_type3(&vpdpage83data,
1093 /* Move the inquiry data to the response buffer. */
1094 scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1095 sizeof(vpdpage83data));
1097 /* It must be for VPD 0x80 */
1100 sp[0] = INQD_PDT_DA;
1101 sp[1] = scsicmd->cmnd[2];
1103 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1104 le32_to_cpu(get_serial_reply->uid));
1105 scsi_sg_copy_from_buffer(scsicmd, sp,
1110 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1112 aac_fib_complete(fibptr);
1113 scsicmd->scsi_done(scsicmd);
1117 * aac_get_container_serial - get container serial, none blocking.
1119 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1122 struct aac_get_serial *dinfo;
1123 struct fib * cmd_fibcontext;
1124 struct aac_dev * dev;
1126 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1128 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
1130 aac_fib_init(cmd_fibcontext);
1131 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1133 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1134 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1135 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1136 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1138 status = aac_fib_send(ContainerCommand,
1140 sizeof(struct aac_get_serial_resp),
1143 (fib_callback) get_container_serial_callback,
1147 * Check that the command queued to the controller
1149 if (status == -EINPROGRESS)
1152 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1153 aac_fib_complete(cmd_fibcontext);
1157 /* Function: setinqserial
1159 * Arguments: [1] pointer to void [1] int
1161 * Purpose: Sets SCSI Unit Serial number.
1162 * This is a fake. We should read a proper
1163 * serial number from the container. <SuSE>But
1164 * without docs it's quite hard to do it :-)
1165 * So this will have to do in the meantime.</SuSE>
1168 static int setinqserial(struct aac_dev *dev, void *data, int cid)
1171 * This breaks array migration.
1173 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1174 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1177 static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1178 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
1180 u8 *sense_buf = (u8 *)sense_data;
1181 /* Sense data valid, err code 70h */
1182 sense_buf[0] = 0x70; /* No info field */
1183 sense_buf[1] = 0; /* Segment number, always zero */
1185 sense_buf[2] = sense_key; /* Sense key */
1187 sense_buf[12] = sense_code; /* Additional sense code */
1188 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
1190 if (sense_key == ILLEGAL_REQUEST) {
1191 sense_buf[7] = 10; /* Additional sense length */
1193 sense_buf[15] = bit_pointer;
1194 /* Illegal parameter is in the parameter block */
1195 if (sense_code == SENCODE_INVALID_CDB_FIELD)
1196 sense_buf[15] |= 0xc0;/* Std sense key specific field */
1197 /* Illegal parameter is in the CDB block */
1198 sense_buf[16] = field_pointer >> 8; /* MSB */
1199 sense_buf[17] = field_pointer; /* LSB */
1201 sense_buf[7] = 6; /* Additional sense length */
1204 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1206 if (lba & 0xffffffff00000000LL) {
1207 int cid = scmd_id(cmd);
1208 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1209 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1210 SAM_STAT_CHECK_CONDITION;
1211 set_sense(&dev->fsa_dev[cid].sense_data,
1212 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1213 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1214 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1215 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1216 SCSI_SENSE_BUFFERSIZE));
1217 cmd->scsi_done(cmd);
1223 static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1228 static void io_callback(void *context, struct fib * fibptr);
1230 static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1232 struct aac_dev *dev = fib->dev;
1233 u16 fibsize, command;
1237 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1238 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1240 struct aac_raw_io2 *readcmd2;
1241 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1242 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1243 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1244 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1245 readcmd2->byteCount = cpu_to_le32(count *
1246 dev->fsa_dev[scmd_id(cmd)].block_size);
1247 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1248 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
1249 ret = aac_build_sgraw2(cmd, readcmd2,
1250 dev->scsi_host_ptr->sg_tablesize);
1253 command = ContainerRawIo2;
1254 fibsize = sizeof(struct aac_raw_io2) +
1255 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1257 struct aac_raw_io *readcmd;
1258 readcmd = (struct aac_raw_io *) fib_data(fib);
1259 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1260 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1261 readcmd->count = cpu_to_le32(count *
1262 dev->fsa_dev[scmd_id(cmd)].block_size);
1263 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1264 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1265 readcmd->bpTotal = 0;
1266 readcmd->bpComplete = 0;
1267 ret = aac_build_sgraw(cmd, &readcmd->sg);
1270 command = ContainerRawIo;
1271 fibsize = sizeof(struct aac_raw_io) +
1272 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1275 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1277 * Now send the Fib to the adapter
1279 return aac_fib_send(command,
1284 (fib_callback) io_callback,
1288 static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1291 struct aac_read64 *readcmd;
1295 readcmd = (struct aac_read64 *) fib_data(fib);
1296 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1297 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1298 readcmd->sector_count = cpu_to_le16(count);
1299 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1303 ret = aac_build_sg64(cmd, &readcmd->sg);
1306 fibsize = sizeof(struct aac_read64) +
1307 ((le32_to_cpu(readcmd->sg.count) - 1) *
1308 sizeof (struct sgentry64));
1309 BUG_ON (fibsize > (fib->dev->max_fib_size -
1310 sizeof(struct aac_fibhdr)));
1312 * Now send the Fib to the adapter
1314 return aac_fib_send(ContainerCommand64,
1319 (fib_callback) io_callback,
1323 static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1326 struct aac_read *readcmd;
1327 struct aac_dev *dev = fib->dev;
1331 readcmd = (struct aac_read *) fib_data(fib);
1332 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1333 readcmd->cid = cpu_to_le32(scmd_id(cmd));
1334 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1335 readcmd->count = cpu_to_le32(count *
1336 dev->fsa_dev[scmd_id(cmd)].block_size);
1338 ret = aac_build_sg(cmd, &readcmd->sg);
1341 fibsize = sizeof(struct aac_read) +
1342 ((le32_to_cpu(readcmd->sg.count) - 1) *
1343 sizeof (struct sgentry));
1344 BUG_ON (fibsize > (fib->dev->max_fib_size -
1345 sizeof(struct aac_fibhdr)));
1347 * Now send the Fib to the adapter
1349 return aac_fib_send(ContainerCommand,
1354 (fib_callback) io_callback,
1358 static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1360 struct aac_dev *dev = fib->dev;
1361 u16 fibsize, command;
1365 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1366 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1368 struct aac_raw_io2 *writecmd2;
1369 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1370 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1371 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1372 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1373 writecmd2->byteCount = cpu_to_le32(count *
1374 dev->fsa_dev[scmd_id(cmd)].block_size);
1375 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1376 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1377 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1378 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1379 cpu_to_le16(RIO2_IO_TYPE_WRITE);
1380 ret = aac_build_sgraw2(cmd, writecmd2,
1381 dev->scsi_host_ptr->sg_tablesize);
1384 command = ContainerRawIo2;
1385 fibsize = sizeof(struct aac_raw_io2) +
1386 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1388 struct aac_raw_io *writecmd;
1389 writecmd = (struct aac_raw_io *) fib_data(fib);
1390 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1391 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1392 writecmd->count = cpu_to_le32(count *
1393 dev->fsa_dev[scmd_id(cmd)].block_size);
1394 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1395 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1396 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1397 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1398 cpu_to_le16(RIO_TYPE_WRITE);
1399 writecmd->bpTotal = 0;
1400 writecmd->bpComplete = 0;
1401 ret = aac_build_sgraw(cmd, &writecmd->sg);
1404 command = ContainerRawIo;
1405 fibsize = sizeof(struct aac_raw_io) +
1406 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1409 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1411 * Now send the Fib to the adapter
1413 return aac_fib_send(command,
1418 (fib_callback) io_callback,
1422 static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1425 struct aac_write64 *writecmd;
1429 writecmd = (struct aac_write64 *) fib_data(fib);
1430 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1431 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1432 writecmd->sector_count = cpu_to_le16(count);
1433 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1435 writecmd->flags = 0;
1437 ret = aac_build_sg64(cmd, &writecmd->sg);
1440 fibsize = sizeof(struct aac_write64) +
1441 ((le32_to_cpu(writecmd->sg.count) - 1) *
1442 sizeof (struct sgentry64));
1443 BUG_ON (fibsize > (fib->dev->max_fib_size -
1444 sizeof(struct aac_fibhdr)));
1446 * Now send the Fib to the adapter
1448 return aac_fib_send(ContainerCommand64,
1453 (fib_callback) io_callback,
1457 static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1460 struct aac_write *writecmd;
1461 struct aac_dev *dev = fib->dev;
1465 writecmd = (struct aac_write *) fib_data(fib);
1466 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1467 writecmd->cid = cpu_to_le32(scmd_id(cmd));
1468 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1469 writecmd->count = cpu_to_le32(count *
1470 dev->fsa_dev[scmd_id(cmd)].block_size);
1471 writecmd->sg.count = cpu_to_le32(1);
1472 /* ->stable is not used - it did mean which type of write */
1474 ret = aac_build_sg(cmd, &writecmd->sg);
1477 fibsize = sizeof(struct aac_write) +
1478 ((le32_to_cpu(writecmd->sg.count) - 1) *
1479 sizeof (struct sgentry));
1480 BUG_ON (fibsize > (fib->dev->max_fib_size -
1481 sizeof(struct aac_fibhdr)));
1483 * Now send the Fib to the adapter
1485 return aac_fib_send(ContainerCommand,
1490 (fib_callback) io_callback,
1494 static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1496 struct aac_srb * srbcmd;
1501 switch(cmd->sc_data_direction){
1505 case DMA_BIDIRECTIONAL:
1506 flag = SRB_DataIn | SRB_DataOut;
1508 case DMA_FROM_DEVICE:
1512 default: /* shuts up some versions of gcc */
1513 flag = SRB_NoDataXfer;
1517 srbcmd = (struct aac_srb*) fib_data(fib);
1518 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1519 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1520 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1521 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1522 srbcmd->flags = cpu_to_le32(flag);
1523 timeout = cmd->request->timeout/HZ;
1526 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1527 srbcmd->retry_limit = 0; /* Obsolete parameter */
1528 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1532 static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
1533 struct scsi_cmnd *cmd)
1535 struct aac_hba_cmd_req *hbacmd;
1536 struct aac_dev *dev;
1540 dev = (struct aac_dev *)cmd->device->host->hostdata;
1542 hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
1543 memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
1544 /* iu_type is a parameter of aac_hba_send */
1545 switch (cmd->sc_data_direction) {
1549 case DMA_FROM_DEVICE:
1550 case DMA_BIDIRECTIONAL:
1557 hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
1559 bus = aac_logical_to_phys(scmd_channel(cmd));
1560 target = scmd_id(cmd);
1561 hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
1563 /* we fill in reply_qid later in aac_src_deliver_message */
1564 /* we fill in iu_type, request_id later in aac_hba_send */
1565 /* we fill in emb_data_desc_count later in aac_build_sghba */
1567 memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
1568 hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
1570 address = (u64)fib->hw_error_pa;
1571 hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
1572 hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
1573 hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
1578 static void aac_srb_callback(void *context, struct fib * fibptr);
1580 static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1583 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1586 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1589 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1591 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1592 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1594 * Build Scatter/Gather list
1596 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1597 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1598 sizeof (struct sgentry64));
1599 BUG_ON (fibsize > (fib->dev->max_fib_size -
1600 sizeof(struct aac_fibhdr)));
1603 * Now send the Fib to the adapter
1605 return aac_fib_send(ScsiPortCommand64, fib,
1606 fibsize, FsaNormal, 0, 1,
1607 (fib_callback) aac_srb_callback,
1611 static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1614 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1617 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1620 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1622 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1623 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1625 * Build Scatter/Gather list
1627 fibsize = sizeof (struct aac_srb) +
1628 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1629 sizeof (struct sgentry));
1630 BUG_ON (fibsize > (fib->dev->max_fib_size -
1631 sizeof(struct aac_fibhdr)));
1634 * Now send the Fib to the adapter
1636 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1637 (fib_callback) aac_srb_callback, (void *) cmd);
1640 static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1642 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1643 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1645 return aac_scsi_32(fib, cmd);
1648 static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
1650 struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
1651 struct aac_dev *dev;
1654 dev = (struct aac_dev *)cmd->device->host->hostdata;
1656 ret = aac_build_sghba(cmd, hbacmd,
1657 dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
1662 * Now send the HBA command to the adapter
1664 fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
1665 sizeof(struct aac_hba_sgl);
1667 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
1668 (fib_callback) aac_hba_callback,
1672 static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
1673 struct aac_srb_unit *srbu, void *xfer_buf, int xfer_len)
1679 struct aac_srb *srb;
1680 struct aac_srb_reply *srb_reply;
1681 struct sgmap64 *sg64;
1685 if (!dev->sa_firmware)
1689 fibptr = aac_fib_alloc(dev);
1693 aac_fib_init(fibptr);
1694 fibptr->hw_fib_va->header.XferState &=
1695 ~cpu_to_le32(FastResponseCapable);
1697 fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
1698 sizeof(struct sgentry64);
1700 /* allocate DMA buffer for response */
1701 addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
1703 if (dma_mapping_error(&dev->pdev->dev, addr)) {
1708 srb = fib_data(fibptr);
1709 memcpy(srb, &srbu->srb, sizeof(struct aac_srb));
1711 vbus = (u32)le16_to_cpu(
1712 dev->supplement_adapter_info.virt_device_bus);
1713 vid = (u32)le16_to_cpu(
1714 dev->supplement_adapter_info.virt_device_target);
1716 /* set the common request fields */
1717 srb->channel = cpu_to_le32(vbus);
1718 srb->id = cpu_to_le32(vid);
1720 srb->function = cpu_to_le32(SRBF_ExecuteScsi);
1722 srb->retry_limit = 0;
1723 srb->cdb_size = cpu_to_le32(16);
1724 srb->count = cpu_to_le32(xfer_len);
1726 sg64 = (struct sgmap64 *)&srb->sg;
1727 sg64->count = cpu_to_le32(1);
1728 sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
1729 sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
1730 sg64->sg[0].count = cpu_to_le32(xfer_len);
1733 * Copy the updated data for other dumping or other usage if needed
1735 memcpy(&srbu->srb, srb, sizeof(struct aac_srb));
1737 /* issue request to the controller */
1738 rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize, FsaNormal,
1741 if (rcode == -ERESTARTSYS)
1744 if (unlikely(rcode < 0))
1747 srb_reply = (struct aac_srb_reply *)fib_data(fibptr);
1748 memcpy(&srbu->srb_reply, srb_reply, sizeof(struct aac_srb_reply));
1751 dma_unmap_single(&dev->pdev->dev, addr, xfer_len, DMA_BIDIRECTIONAL);
1753 aac_fib_complete(fibptr);
1754 aac_fib_free(fibptr);
1758 static void aac_set_safw_target_qd(struct aac_dev *dev, int bus, int target)
1761 struct aac_ciss_identify_pd *identify_resp;
1763 if (dev->hba_map[bus][target].devtype != AAC_DEVTYPE_NATIVE_RAW)
1766 identify_resp = dev->hba_map[bus][target].safw_identify_resp;
1767 if (identify_resp == NULL) {
1768 dev->hba_map[bus][target].qd_limit = 32;
1772 if (identify_resp->current_queue_depth_limit <= 0 ||
1773 identify_resp->current_queue_depth_limit > 255)
1774 dev->hba_map[bus][target].qd_limit = 32;
1776 dev->hba_map[bus][target].qd_limit =
1777 identify_resp->current_queue_depth_limit;
1780 static int aac_issue_safw_bmic_identify(struct aac_dev *dev,
1781 struct aac_ciss_identify_pd **identify_resp, u32 bus, u32 target)
1783 int rcode = -ENOMEM;
1785 struct aac_srb_unit srbu;
1786 struct aac_srb *srbcmd;
1787 struct aac_ciss_identify_pd *identify_reply;
1789 datasize = sizeof(struct aac_ciss_identify_pd);
1790 identify_reply = kmalloc(datasize, GFP_KERNEL);
1791 if (!identify_reply)
1794 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1797 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1798 srbcmd->cdb[0] = 0x26;
1799 srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
1800 srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
1802 rcode = aac_send_safw_bmic_cmd(dev, &srbu, identify_reply, datasize);
1803 if (unlikely(rcode < 0))
1806 *identify_resp = identify_reply;
1811 kfree(identify_reply);
1815 static inline void aac_free_safw_ciss_luns(struct aac_dev *dev)
1817 kfree(dev->safw_phys_luns);
1818 dev->safw_phys_luns = NULL;
1822 * aac_get_safw_ciss_luns() Process topology change
1823 * @dev: aac_dev structure
1824 * @rescan: Indicates rescan
1826 * Execute a CISS REPORT PHYS LUNS and process the results into
1827 * the current hba_map.
1829 static int aac_get_safw_ciss_luns(struct aac_dev *dev, int rescan)
1831 int rcode = -ENOMEM;
1833 struct aac_srb *srbcmd;
1834 struct aac_srb_unit srbu;
1835 struct aac_ciss_phys_luns_resp *phys_luns;
1837 datasize = sizeof(struct aac_ciss_phys_luns_resp) +
1838 (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
1839 phys_luns = kmalloc(datasize, GFP_KERNEL);
1840 if (phys_luns == NULL)
1843 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1846 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1847 srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
1848 srbcmd->cdb[1] = 2; /* extended reporting */
1849 srbcmd->cdb[8] = (u8)(datasize >> 8);
1850 srbcmd->cdb[9] = (u8)(datasize);
1852 rcode = aac_send_safw_bmic_cmd(dev, &srbu, phys_luns, datasize);
1853 if (unlikely(rcode < 0))
1856 if (phys_luns->resp_flag != 2) {
1861 dev->safw_phys_luns = phys_luns;
1870 static inline u32 aac_get_safw_phys_lun_count(struct aac_dev *dev)
1872 return get_unaligned_be32(&dev->safw_phys_luns->list_length[0]);
1875 static inline u32 aac_get_safw_phys_bus(struct aac_dev *dev, int lun)
1877 return dev->safw_phys_luns->lun[lun].level2[1] & 0x3f;
1880 static inline u32 aac_get_safw_phys_target(struct aac_dev *dev, int lun)
1882 return dev->safw_phys_luns->lun[lun].level2[0];
1885 static inline u32 aac_get_safw_phys_expose_flag(struct aac_dev *dev, int lun)
1887 return dev->safw_phys_luns->lun[lun].bus >> 6;
1890 static inline u32 aac_get_safw_phys_attribs(struct aac_dev *dev, int lun)
1892 return dev->safw_phys_luns->lun[lun].node_ident[9];
1895 static inline u32 aac_get_safw_phys_nexus(struct aac_dev *dev, int lun)
1897 return *((u32 *)&dev->safw_phys_luns->lun[lun].node_ident[12]);
1900 static inline u32 aac_get_safw_phys_device_type(struct aac_dev *dev, int lun)
1902 return dev->safw_phys_luns->lun[lun].node_ident[8];
1905 static inline void aac_free_safw_identify_resp(struct aac_dev *dev,
1906 int bus, int target)
1908 kfree(dev->hba_map[bus][target].safw_identify_resp);
1909 dev->hba_map[bus][target].safw_identify_resp = NULL;
1912 static inline void aac_free_safw_all_identify_resp(struct aac_dev *dev,
1920 luns = aac_get_safw_phys_lun_count(dev);
1922 if (luns < lun_count)
1924 else if (lun_count < 0)
1927 for (i = 0; i < lun_count; i++) {
1928 bus = aac_get_safw_phys_bus(dev, i);
1929 target = aac_get_safw_phys_target(dev, i);
1931 aac_free_safw_identify_resp(dev, bus, target);
1935 static int aac_get_safw_attr_all_targets(struct aac_dev *dev, int rescan)
1942 struct aac_ciss_identify_pd *identify_resp = NULL;
1944 lun_count = aac_get_safw_phys_lun_count(dev);
1946 for (i = 0; i < lun_count; ++i) {
1948 bus = aac_get_safw_phys_bus(dev, i);
1949 target = aac_get_safw_phys_target(dev, i);
1951 rcode = aac_issue_safw_bmic_identify(dev,
1952 &identify_resp, bus, target);
1954 if (unlikely(rcode < 0))
1955 goto free_identify_resp;
1957 dev->hba_map[bus][target].safw_identify_resp = identify_resp;
1963 aac_free_safw_all_identify_resp(dev, i);
1968 * aac_set_safw_attr_all_targets- update current hba map with data from FW
1969 * @dev: aac_dev structure
1970 * @phys_luns: FW information from report phys luns
1971 * @rescan: Indicates scan type
1973 * Update our hba map with the information gathered from the FW
1975 static void aac_set_safw_attr_all_targets(struct aac_dev *dev, int rescan)
1977 /* ok and extended reporting */
1978 u32 lun_count, nexus;
1980 u8 expose_flag, attribs;
1983 lun_count = aac_get_safw_phys_lun_count(dev);
1985 for (i = 0; i < lun_count; ++i) {
1987 bus = aac_get_safw_phys_bus(dev, i);
1988 target = aac_get_safw_phys_target(dev, i);
1989 expose_flag = aac_get_safw_phys_expose_flag(dev, i);
1990 attribs = aac_get_safw_phys_attribs(dev, i);
1991 nexus = aac_get_safw_phys_nexus(dev, i);
1993 if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
1996 dev->hba_map[bus][target].expose = expose_flag;
1998 if (expose_flag != 0) {
1999 devtype = AAC_DEVTYPE_RAID_MEMBER;
2000 goto update_devtype;
2003 if (nexus != 0 && (attribs & 8)) {
2004 devtype = AAC_DEVTYPE_NATIVE_RAW;
2005 dev->hba_map[bus][target].rmw_nexus =
2008 devtype = AAC_DEVTYPE_ARC_RAW;
2010 aac_set_safw_target_qd(dev, bus, target);
2013 if (rescan == AAC_INIT)
2014 dev->hba_map[bus][target].devtype = devtype;
2016 dev->hba_map[bus][target].new_devtype = devtype;
2020 static int aac_setup_safw_targets(struct aac_dev *dev, int rescan)
2024 rcode = aac_get_safw_ciss_luns(dev, rescan);
2025 if (unlikely(rcode < 0))
2028 rcode = aac_get_safw_attr_all_targets(dev, rescan);
2029 if (unlikely(rcode < 0))
2030 goto free_ciss_luns;
2032 aac_set_safw_attr_all_targets(dev, rescan);
2034 aac_free_safw_all_identify_resp(dev, -1);
2036 aac_free_safw_ciss_luns(dev);
2041 int aac_setup_safw_adapter(struct aac_dev *dev, int rescan)
2043 return aac_setup_safw_targets(dev, rescan);
2046 int aac_get_adapter_info(struct aac_dev* dev)
2050 u32 tmp, bus, target;
2051 struct aac_adapter_info *info;
2052 struct aac_bus_info *command;
2053 struct aac_bus_info_response *bus_info;
2055 if (!(fibptr = aac_fib_alloc(dev)))
2058 aac_fib_init(fibptr);
2059 info = (struct aac_adapter_info *) fib_data(fibptr);
2060 memset(info,0,sizeof(*info));
2062 rcode = aac_fib_send(RequestAdapterInfo,
2066 -1, 1, /* First `interrupt' command uses special wait */
2071 /* FIB should be freed only after
2072 * getting the response from the F/W */
2073 if (rcode != -ERESTARTSYS) {
2074 aac_fib_complete(fibptr);
2075 aac_fib_free(fibptr);
2079 memcpy(&dev->adapter_info, info, sizeof(*info));
2081 dev->supplement_adapter_info.virt_device_bus = 0xffff;
2082 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
2083 struct aac_supplement_adapter_info * sinfo;
2085 aac_fib_init(fibptr);
2087 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
2089 memset(sinfo,0,sizeof(*sinfo));
2091 rcode = aac_fib_send(RequestSupplementAdapterInfo,
2100 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
2101 if (rcode == -ERESTARTSYS) {
2102 fibptr = aac_fib_alloc(dev);
2109 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
2110 for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
2111 for (target = 0; target < AAC_MAX_TARGETS; target++) {
2112 dev->hba_map[bus][target].devtype = 0;
2113 dev->hba_map[bus][target].qd_limit = 0;
2121 aac_fib_init(fibptr);
2123 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
2125 memset(bus_info, 0, sizeof(*bus_info));
2127 command = (struct aac_bus_info *)bus_info;
2129 command->Command = cpu_to_le32(VM_Ioctl);
2130 command->ObjType = cpu_to_le32(FT_DRIVE);
2131 command->MethodId = cpu_to_le32(1);
2132 command->CtlCmd = cpu_to_le32(GetBusInfo);
2134 rcode = aac_fib_send(ContainerCommand,
2141 /* reasoned default */
2142 dev->maximum_num_physicals = 16;
2143 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
2144 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
2145 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
2148 if (!dev->sync_mode && dev->sa_firmware &&
2149 dev->supplement_adapter_info.virt_device_bus != 0xffff)
2150 rcode = aac_setup_safw_adapter(dev, AAC_INIT);
2152 if (!dev->in_reset) {
2154 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
2155 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
2161 le32_to_cpu(dev->adapter_info.kernelbuild),
2162 (int)sizeof(dev->supplement_adapter_info.build_date),
2163 dev->supplement_adapter_info.build_date);
2164 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
2165 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
2167 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2168 le32_to_cpu(dev->adapter_info.monitorbuild));
2169 tmp = le32_to_cpu(dev->adapter_info.biosrev);
2170 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
2172 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2173 le32_to_cpu(dev->adapter_info.biosbuild));
2175 if (aac_get_serial_number(
2176 shost_to_class(dev->scsi_host_ptr), buffer))
2177 printk(KERN_INFO "%s%d: serial %s",
2178 dev->name, dev->id, buffer);
2179 if (dev->supplement_adapter_info.vpd_info.tsid[0]) {
2180 printk(KERN_INFO "%s%d: TSID %.*s\n",
2182 (int)sizeof(dev->supplement_adapter_info
2184 dev->supplement_adapter_info.vpd_info.tsid);
2186 if (!aac_check_reset || ((aac_check_reset == 1) &&
2187 (dev->supplement_adapter_info.supported_options2 &
2188 AAC_OPTION_IGNORE_RESET))) {
2189 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
2190 dev->name, dev->id);
2194 dev->cache_protected = 0;
2195 dev->jbod = ((dev->supplement_adapter_info.feature_bits &
2196 AAC_FEATURE_JBOD) != 0);
2197 dev->nondasd_support = 0;
2198 dev->raid_scsi_mode = 0;
2199 if(dev->adapter_info.options & AAC_OPT_NONDASD)
2200 dev->nondasd_support = 1;
2203 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2204 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2205 * force nondasd support on. If we decide to allow the non-dasd flag
2206 * additional changes changes will have to be made to support
2207 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2208 * changed to support the new dev->raid_scsi_mode flag instead of
2209 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2210 * function aac_detect will have to be modified where it sets up the
2211 * max number of channels based on the aac->nondasd_support flag only.
2213 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
2214 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
2215 dev->nondasd_support = 1;
2216 dev->raid_scsi_mode = 1;
2218 if (dev->raid_scsi_mode != 0)
2219 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
2220 dev->name, dev->id);
2223 dev->nondasd_support = (nondasd!=0);
2224 if (dev->nondasd_support && !dev->in_reset)
2225 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
2227 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
2229 dev->dac_support = 0;
2230 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
2231 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
2233 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
2234 dev->name, dev->id);
2235 dev->dac_support = 1;
2239 dev->dac_support = (dacmode!=0);
2242 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2243 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
2244 & AAC_QUIRK_SCSI_32)) {
2245 dev->nondasd_support = 0;
2247 expose_physicals = 0;
2250 if (dev->dac_support) {
2251 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
2253 dev_info(&dev->pdev->dev, "64 Bit DAC enabled\n");
2254 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
2255 dev_info(&dev->pdev->dev, "DMA mask set failed, 64 Bit DAC disabled\n");
2256 dev->dac_support = 0;
2258 dev_info(&dev->pdev->dev, "No suitable DMA available\n");
2263 * Deal with configuring for the individualized limits of each packet
2266 dev->a_ops.adapter_scsi = (dev->dac_support)
2267 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
2271 if (dev->raw_io_interface) {
2272 dev->a_ops.adapter_bounds = (dev->raw_io_64)
2275 dev->a_ops.adapter_read = aac_read_raw_io;
2276 dev->a_ops.adapter_write = aac_write_raw_io;
2278 dev->a_ops.adapter_bounds = aac_bounds_32;
2279 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
2280 sizeof(struct aac_fibhdr) -
2281 sizeof(struct aac_write) + sizeof(struct sgentry)) /
2282 sizeof(struct sgentry);
2283 if (dev->dac_support) {
2284 dev->a_ops.adapter_read = aac_read_block64;
2285 dev->a_ops.adapter_write = aac_write_block64;
2287 * 38 scatter gather elements
2289 dev->scsi_host_ptr->sg_tablesize =
2290 (dev->max_fib_size -
2291 sizeof(struct aac_fibhdr) -
2292 sizeof(struct aac_write64) +
2293 sizeof(struct sgentry64)) /
2294 sizeof(struct sgentry64);
2296 dev->a_ops.adapter_read = aac_read_block;
2297 dev->a_ops.adapter_write = aac_write_block;
2299 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
2300 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
2302 * Worst case size that could cause sg overflow when
2303 * we break up SG elements that are larger than 64KB.
2304 * Would be nice if we could tell the SCSI layer what
2305 * the maximum SG element size can be. Worst case is
2306 * (sg_tablesize-1) 4KB elements with one 64KB
2308 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2310 dev->scsi_host_ptr->max_sectors =
2311 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
2314 if (!dev->sync_mode && dev->sa_firmware &&
2315 dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
2316 dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
2317 HBA_MAX_SG_SEPARATE;
2319 /* FIB should be freed only after getting the response from the F/W */
2320 if (rcode != -ERESTARTSYS) {
2321 aac_fib_complete(fibptr);
2322 aac_fib_free(fibptr);
2329 static void io_callback(void *context, struct fib * fibptr)
2331 struct aac_dev *dev;
2332 struct aac_read_reply *readreply;
2333 struct scsi_cmnd *scsicmd;
2336 scsicmd = (struct scsi_cmnd *) context;
2338 if (!aac_valid_context(scsicmd, fibptr))
2342 cid = scmd_id(scsicmd);
2344 if (nblank(dprintk(x))) {
2346 switch (scsicmd->cmnd[0]) {
2349 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2350 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2354 lba = ((u64)scsicmd->cmnd[2] << 56) |
2355 ((u64)scsicmd->cmnd[3] << 48) |
2356 ((u64)scsicmd->cmnd[4] << 40) |
2357 ((u64)scsicmd->cmnd[5] << 32) |
2358 ((u64)scsicmd->cmnd[6] << 24) |
2359 (scsicmd->cmnd[7] << 16) |
2360 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2364 lba = ((u64)scsicmd->cmnd[2] << 24) |
2365 (scsicmd->cmnd[3] << 16) |
2366 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2369 lba = ((u64)scsicmd->cmnd[2] << 24) |
2370 (scsicmd->cmnd[3] << 16) |
2371 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2375 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2376 smp_processor_id(), (unsigned long long)lba, jiffies);
2379 BUG_ON(fibptr == NULL);
2381 scsi_dma_unmap(scsicmd);
2383 readreply = (struct aac_read_reply *)fib_data(fibptr);
2384 switch (le32_to_cpu(readreply->status)) {
2386 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2388 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
2391 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2392 SAM_STAT_CHECK_CONDITION;
2393 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
2394 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
2395 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2396 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2397 SCSI_SENSE_BUFFERSIZE));
2400 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2401 SAM_STAT_CHECK_CONDITION;
2402 set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
2403 SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
2404 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2405 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2406 SCSI_SENSE_BUFFERSIZE));
2409 #ifdef AAC_DETAILED_STATUS_INFO
2410 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
2411 le32_to_cpu(readreply->status));
2413 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2414 SAM_STAT_CHECK_CONDITION;
2415 set_sense(&dev->fsa_dev[cid].sense_data,
2416 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2417 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2418 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2419 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2420 SCSI_SENSE_BUFFERSIZE));
2423 aac_fib_complete(fibptr);
2425 scsicmd->scsi_done(scsicmd);
2428 static int aac_read(struct scsi_cmnd * scsicmd)
2433 struct aac_dev *dev;
2434 struct fib * cmd_fibcontext;
2437 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2439 * Get block address and transfer length
2441 switch (scsicmd->cmnd[0]) {
2443 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
2445 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2446 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2447 count = scsicmd->cmnd[4];
2453 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
2455 lba = ((u64)scsicmd->cmnd[2] << 56) |
2456 ((u64)scsicmd->cmnd[3] << 48) |
2457 ((u64)scsicmd->cmnd[4] << 40) |
2458 ((u64)scsicmd->cmnd[5] << 32) |
2459 ((u64)scsicmd->cmnd[6] << 24) |
2460 (scsicmd->cmnd[7] << 16) |
2461 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2462 count = (scsicmd->cmnd[10] << 24) |
2463 (scsicmd->cmnd[11] << 16) |
2464 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2467 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
2469 lba = ((u64)scsicmd->cmnd[2] << 24) |
2470 (scsicmd->cmnd[3] << 16) |
2471 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2472 count = (scsicmd->cmnd[6] << 24) |
2473 (scsicmd->cmnd[7] << 16) |
2474 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2477 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
2479 lba = ((u64)scsicmd->cmnd[2] << 24) |
2480 (scsicmd->cmnd[3] << 16) |
2481 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2482 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2486 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2487 cid = scmd_id(scsicmd);
2488 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2489 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2490 SAM_STAT_CHECK_CONDITION;
2491 set_sense(&dev->fsa_dev[cid].sense_data,
2492 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2493 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2494 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2495 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2496 SCSI_SENSE_BUFFERSIZE));
2497 scsicmd->scsi_done(scsicmd);
2501 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
2502 smp_processor_id(), (unsigned long long)lba, jiffies));
2503 if (aac_adapter_bounds(dev,scsicmd,lba))
2506 * Alocate and initialize a Fib
2508 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
2509 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2510 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
2513 * Check that the command queued to the controller
2515 if (status == -EINPROGRESS)
2518 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
2520 * For some reason, the Fib didn't queue, return QUEUE_FULL
2522 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
2523 scsicmd->scsi_done(scsicmd);
2524 aac_fib_complete(cmd_fibcontext);
2525 aac_fib_free(cmd_fibcontext);
2529 static int aac_write(struct scsi_cmnd * scsicmd)
2535 struct aac_dev *dev;
2536 struct fib * cmd_fibcontext;
2539 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2541 * Get block address and transfer length
2543 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
2545 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2546 count = scsicmd->cmnd[4];
2550 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
2551 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
2553 lba = ((u64)scsicmd->cmnd[2] << 56) |
2554 ((u64)scsicmd->cmnd[3] << 48) |
2555 ((u64)scsicmd->cmnd[4] << 40) |
2556 ((u64)scsicmd->cmnd[5] << 32) |
2557 ((u64)scsicmd->cmnd[6] << 24) |
2558 (scsicmd->cmnd[7] << 16) |
2559 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2560 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2561 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2562 fua = scsicmd->cmnd[1] & 0x8;
2563 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
2564 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
2566 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2567 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2568 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2569 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2570 fua = scsicmd->cmnd[1] & 0x8;
2572 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
2573 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2574 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2575 fua = scsicmd->cmnd[1] & 0x8;
2578 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2579 cid = scmd_id(scsicmd);
2580 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2581 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2582 SAM_STAT_CHECK_CONDITION;
2583 set_sense(&dev->fsa_dev[cid].sense_data,
2584 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2585 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2586 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2587 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2588 SCSI_SENSE_BUFFERSIZE));
2589 scsicmd->scsi_done(scsicmd);
2593 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
2594 smp_processor_id(), (unsigned long long)lba, jiffies));
2595 if (aac_adapter_bounds(dev,scsicmd,lba))
2598 * Allocate and initialize a Fib then setup a BlockWrite command
2600 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
2601 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2602 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
2605 * Check that the command queued to the controller
2607 if (status == -EINPROGRESS)
2610 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
2612 * For some reason, the Fib didn't queue, return QUEUE_FULL
2614 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
2615 scsicmd->scsi_done(scsicmd);
2617 aac_fib_complete(cmd_fibcontext);
2618 aac_fib_free(cmd_fibcontext);
2622 static void synchronize_callback(void *context, struct fib *fibptr)
2624 struct aac_synchronize_reply *synchronizereply;
2625 struct scsi_cmnd *cmd;
2629 if (!aac_valid_context(cmd, fibptr))
2632 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
2633 smp_processor_id(), jiffies));
2634 BUG_ON(fibptr == NULL);
2637 synchronizereply = fib_data(fibptr);
2638 if (le32_to_cpu(synchronizereply->status) == CT_OK)
2639 cmd->result = DID_OK << 16 |
2640 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2642 struct scsi_device *sdev = cmd->device;
2643 struct aac_dev *dev = fibptr->dev;
2644 u32 cid = sdev_id(sdev);
2646 "synchronize_callback: synchronize failed, status = %d\n",
2647 le32_to_cpu(synchronizereply->status));
2648 cmd->result = DID_OK << 16 |
2649 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2650 set_sense(&dev->fsa_dev[cid].sense_data,
2651 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2652 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2653 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2654 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2655 SCSI_SENSE_BUFFERSIZE));
2658 aac_fib_complete(fibptr);
2659 aac_fib_free(fibptr);
2660 cmd->scsi_done(cmd);
2663 static int aac_synchronize(struct scsi_cmnd *scsicmd)
2666 struct fib *cmd_fibcontext;
2667 struct aac_synchronize *synchronizecmd;
2668 struct scsi_cmnd *cmd;
2669 struct scsi_device *sdev = scsicmd->device;
2671 struct aac_dev *aac;
2672 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2673 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2674 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2675 unsigned long flags;
2678 * Wait for all outstanding queued commands to complete to this
2679 * specific target (block).
2681 spin_lock_irqsave(&sdev->list_lock, flags);
2682 list_for_each_entry(cmd, &sdev->cmd_list, list)
2683 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2687 if (cmd->cmnd[0] == WRITE_6) {
2688 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2689 (cmd->cmnd[2] << 8) |
2691 cmnd_count = cmd->cmnd[4];
2692 if (cmnd_count == 0)
2694 } else if (cmd->cmnd[0] == WRITE_16) {
2695 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2696 ((u64)cmd->cmnd[3] << 48) |
2697 ((u64)cmd->cmnd[4] << 40) |
2698 ((u64)cmd->cmnd[5] << 32) |
2699 ((u64)cmd->cmnd[6] << 24) |
2700 (cmd->cmnd[7] << 16) |
2701 (cmd->cmnd[8] << 8) |
2703 cmnd_count = (cmd->cmnd[10] << 24) |
2704 (cmd->cmnd[11] << 16) |
2705 (cmd->cmnd[12] << 8) |
2707 } else if (cmd->cmnd[0] == WRITE_12) {
2708 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2709 (cmd->cmnd[3] << 16) |
2710 (cmd->cmnd[4] << 8) |
2712 cmnd_count = (cmd->cmnd[6] << 24) |
2713 (cmd->cmnd[7] << 16) |
2714 (cmd->cmnd[8] << 8) |
2716 } else if (cmd->cmnd[0] == WRITE_10) {
2717 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2718 (cmd->cmnd[3] << 16) |
2719 (cmd->cmnd[4] << 8) |
2721 cmnd_count = (cmd->cmnd[7] << 8) |
2725 if (((cmnd_lba + cmnd_count) < lba) ||
2726 (count && ((lba + count) < cmnd_lba)))
2732 spin_unlock_irqrestore(&sdev->list_lock, flags);
2735 * Yield the processor (requeue for later)
2738 return SCSI_MLQUEUE_DEVICE_BUSY;
2740 aac = (struct aac_dev *)sdev->host->hostdata;
2742 return SCSI_MLQUEUE_HOST_BUSY;
2745 * Allocate and initialize a Fib
2747 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
2748 return SCSI_MLQUEUE_HOST_BUSY;
2750 aac_fib_init(cmd_fibcontext);
2752 synchronizecmd = fib_data(cmd_fibcontext);
2753 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2754 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
2755 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
2756 synchronizecmd->count =
2757 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2758 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2761 * Now send the Fib to the adapter
2763 status = aac_fib_send(ContainerCommand,
2765 sizeof(struct aac_synchronize),
2768 (fib_callback)synchronize_callback,
2772 * Check that the command queued to the controller
2774 if (status == -EINPROGRESS)
2778 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2779 aac_fib_complete(cmd_fibcontext);
2780 aac_fib_free(cmd_fibcontext);
2781 return SCSI_MLQUEUE_HOST_BUSY;
2784 static void aac_start_stop_callback(void *context, struct fib *fibptr)
2786 struct scsi_cmnd *scsicmd = context;
2788 if (!aac_valid_context(scsicmd, fibptr))
2791 BUG_ON(fibptr == NULL);
2793 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2795 aac_fib_complete(fibptr);
2796 aac_fib_free(fibptr);
2797 scsicmd->scsi_done(scsicmd);
2800 static int aac_start_stop(struct scsi_cmnd *scsicmd)
2803 struct fib *cmd_fibcontext;
2804 struct aac_power_management *pmcmd;
2805 struct scsi_device *sdev = scsicmd->device;
2806 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2808 if (!(aac->supplement_adapter_info.supported_options2 &
2809 AAC_OPTION_POWER_MANAGEMENT)) {
2810 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2812 scsicmd->scsi_done(scsicmd);
2817 return SCSI_MLQUEUE_HOST_BUSY;
2820 * Allocate and initialize a Fib
2822 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
2824 aac_fib_init(cmd_fibcontext);
2826 pmcmd = fib_data(cmd_fibcontext);
2827 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2828 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2829 /* Eject bit ignored, not relevant */
2830 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2831 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2832 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2833 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2834 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2835 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2838 * Now send the Fib to the adapter
2840 status = aac_fib_send(ContainerCommand,
2842 sizeof(struct aac_power_management),
2845 (fib_callback)aac_start_stop_callback,
2849 * Check that the command queued to the controller
2851 if (status == -EINPROGRESS)
2854 aac_fib_complete(cmd_fibcontext);
2855 aac_fib_free(cmd_fibcontext);
2856 return SCSI_MLQUEUE_HOST_BUSY;
2860 * aac_scsi_cmd() - Process SCSI command
2861 * @scsicmd: SCSI command block
2863 * Emulate a SCSI command and queue the required request for the
2867 int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2870 struct Scsi_Host *host = scsicmd->device->host;
2871 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2872 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
2874 if (fsa_dev_ptr == NULL)
2877 * If the bus, id or lun is out of range, return fail
2878 * Test does not apply to ID 16, the pseudo id for the controller
2881 cid = scmd_id(scsicmd);
2882 if (cid != host->this_id) {
2883 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2884 if((cid >= dev->maximum_num_containers) ||
2885 (scsicmd->device->lun != 0)) {
2886 scsicmd->result = DID_NO_CONNECT << 16;
2891 * If the target container doesn't exist, it may have
2892 * been newly created
2894 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2895 (fsa_dev_ptr[cid].sense_data.sense_key ==
2897 switch (scsicmd->cmnd[0]) {
2898 case SERVICE_ACTION_IN_16:
2899 if (!(dev->raw_io_interface) ||
2900 !(dev->raw_io_64) ||
2901 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2905 case TEST_UNIT_READY:
2908 return _aac_probe_container(scsicmd,
2909 aac_probe_container_callback2);
2914 } else { /* check for physical non-dasd devices */
2915 bus = aac_logical_to_phys(scmd_channel(scsicmd));
2916 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2917 (dev->hba_map[bus][cid].expose
2919 if (scsicmd->cmnd[0] == INQUIRY) {
2920 scsicmd->result = DID_NO_CONNECT << 16;
2925 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2926 dev->hba_map[bus][cid].devtype
2927 == AAC_DEVTYPE_NATIVE_RAW) {
2930 return aac_send_hba_fib(scsicmd);
2931 } else if (dev->nondasd_support || expose_physicals ||
2935 return aac_send_srb_fib(scsicmd);
2937 scsicmd->result = DID_NO_CONNECT << 16;
2943 * else Command for the controller itself
2945 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
2946 (scsicmd->cmnd[0] != TEST_UNIT_READY))
2948 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2949 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2950 set_sense(&dev->fsa_dev[cid].sense_data,
2951 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2952 ASENCODE_INVALID_COMMAND, 0, 0);
2953 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2954 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2955 SCSI_SENSE_BUFFERSIZE));
2959 switch (scsicmd->cmnd[0]) {
2966 return aac_read(scsicmd);
2974 return aac_write(scsicmd);
2976 case SYNCHRONIZE_CACHE:
2977 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2978 scsicmd->result = AAC_STAT_GOOD;
2981 /* Issue FIB to tell Firmware to flush it's cache */
2982 if ((aac_cache & 6) != 2)
2983 return aac_synchronize(scsicmd);
2986 struct inquiry_data inq_data;
2988 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
2989 memset(&inq_data, 0, sizeof (struct inquiry_data));
2991 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
2992 char *arr = (char *)&inq_data;
2995 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2996 INQD_PDT_PROC : INQD_PDT_DA;
2997 if (scsicmd->cmnd[2] == 0) {
2998 /* supported vital product data pages */
3003 arr[1] = scsicmd->cmnd[2];
3004 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
3006 scsicmd->result = AAC_STAT_GOOD;
3007 } else if (scsicmd->cmnd[2] == 0x80) {
3008 /* unit serial number page */
3009 arr[3] = setinqserial(dev, &arr[4],
3011 arr[1] = scsicmd->cmnd[2];
3012 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
3015 return aac_get_container_serial(
3017 scsicmd->result = AAC_STAT_GOOD;
3018 } else if (scsicmd->cmnd[2] == 0x83) {
3019 /* vpd page 0x83 - Device Identification Page */
3020 char *sno = (char *)&inq_data;
3021 sno[3] = setinqserial(dev, &sno[4],
3024 return aac_get_container_serial(
3026 scsicmd->result = AAC_STAT_GOOD;
3028 /* vpd page not implemented */
3029 scsicmd->result = DID_OK << 16 |
3030 COMMAND_COMPLETE << 8 |
3031 SAM_STAT_CHECK_CONDITION;
3032 set_sense(&dev->fsa_dev[cid].sense_data,
3033 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
3034 ASENCODE_NO_SENSE, 7, 2);
3035 memcpy(scsicmd->sense_buffer,
3036 &dev->fsa_dev[cid].sense_data,
3038 sizeof(dev->fsa_dev[cid].sense_data),
3039 SCSI_SENSE_BUFFERSIZE));
3043 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
3044 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 */
3045 inq_data.inqd_len = 31;
3046 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
3047 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
3049 * Set the Vendor, Product, and Revision Level
3050 * see: <vendor>.c i.e. aac.c
3052 if (cid == host->this_id) {
3053 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
3054 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
3055 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
3057 scsicmd->result = AAC_STAT_GOOD;
3062 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
3063 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
3064 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
3065 return aac_get_container_name(scsicmd);
3067 case SERVICE_ACTION_IN_16:
3068 if (!(dev->raw_io_interface) ||
3069 !(dev->raw_io_64) ||
3070 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
3075 unsigned int alloc_len;
3077 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
3078 capacity = fsa_dev_ptr[cid].size - 1;
3079 cp[0] = (capacity >> 56) & 0xff;
3080 cp[1] = (capacity >> 48) & 0xff;
3081 cp[2] = (capacity >> 40) & 0xff;
3082 cp[3] = (capacity >> 32) & 0xff;
3083 cp[4] = (capacity >> 24) & 0xff;
3084 cp[5] = (capacity >> 16) & 0xff;
3085 cp[6] = (capacity >> 8) & 0xff;
3086 cp[7] = (capacity >> 0) & 0xff;
3087 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3088 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3089 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3090 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
3093 alloc_len = ((scsicmd->cmnd[10] << 24)
3094 + (scsicmd->cmnd[11] << 16)
3095 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
3097 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
3098 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
3099 if (alloc_len < scsi_bufflen(scsicmd))
3100 scsi_set_resid(scsicmd,
3101 scsi_bufflen(scsicmd) - alloc_len);
3103 /* Do not cache partition table for arrays */
3104 scsicmd->device->removable = 1;
3106 scsicmd->result = AAC_STAT_GOOD;
3115 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
3116 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3117 capacity = fsa_dev_ptr[cid].size - 1;
3121 cp[0] = (capacity >> 24) & 0xff;
3122 cp[1] = (capacity >> 16) & 0xff;
3123 cp[2] = (capacity >> 8) & 0xff;
3124 cp[3] = (capacity >> 0) & 0xff;
3125 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3126 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3127 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3128 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
3129 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
3130 /* Do not cache partition table for arrays */
3131 scsicmd->device->removable = 1;
3132 scsicmd->result = AAC_STAT_GOOD;
3138 int mode_buf_length = 4;
3142 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3143 capacity = fsa_dev_ptr[cid].size - 1;
3147 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
3148 memset((char *)&mpd, 0, sizeof(aac_modep_data));
3150 /* Mode data length */
3151 mpd.hd.data_length = sizeof(mpd.hd) - 1;
3152 /* Medium type - default */
3153 mpd.hd.med_type = 0;
3154 /* Device-specific param,
3155 bit 8: 0/1 = write enabled/protected
3156 bit 4: 0/1 = FUA enabled */
3159 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
3160 mpd.hd.dev_par = 0x10;
3161 if (scsicmd->cmnd[1] & 0x8)
3162 mpd.hd.bd_length = 0; /* Block descriptor length */
3164 mpd.hd.bd_length = sizeof(mpd.bd);
3165 mpd.hd.data_length += mpd.hd.bd_length;
3166 mpd.bd.block_length[0] =
3167 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3168 mpd.bd.block_length[1] =
3169 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3170 mpd.bd.block_length[2] =
3171 fsa_dev_ptr[cid].block_size & 0xff;
3173 mpd.mpc_buf[0] = scsicmd->cmnd[2];
3174 if (scsicmd->cmnd[2] == 0x1C) {
3176 mpd.mpc_buf[1] = 0xa;
3177 /* Mode data length */
3178 mpd.hd.data_length = 23;
3180 /* Mode data length */
3181 mpd.hd.data_length = 15;
3184 if (capacity > 0xffffff) {
3185 mpd.bd.block_count[0] = 0xff;
3186 mpd.bd.block_count[1] = 0xff;
3187 mpd.bd.block_count[2] = 0xff;
3189 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
3190 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
3191 mpd.bd.block_count[2] = capacity & 0xff;
3194 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3195 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
3196 mpd.hd.data_length += 3;
3199 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
3200 ? 0 : 0x04; /* WCE */
3201 mode_buf_length = sizeof(mpd);
3204 if (mode_buf_length > scsicmd->cmnd[4])
3205 mode_buf_length = scsicmd->cmnd[4];
3207 mode_buf_length = sizeof(mpd);
3208 scsi_sg_copy_from_buffer(scsicmd,
3211 scsicmd->result = AAC_STAT_GOOD;
3217 int mode_buf_length = 8;
3218 aac_modep10_data mpd10;
3220 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3221 capacity = fsa_dev_ptr[cid].size - 1;
3225 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
3226 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
3227 /* Mode data length (MSB) */
3228 mpd10.hd.data_length[0] = 0;
3229 /* Mode data length (LSB) */
3230 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
3231 /* Medium type - default */
3232 mpd10.hd.med_type = 0;
3233 /* Device-specific param,
3234 bit 8: 0/1 = write enabled/protected
3235 bit 4: 0/1 = FUA enabled */
3236 mpd10.hd.dev_par = 0;
3238 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
3239 mpd10.hd.dev_par = 0x10;
3240 mpd10.hd.rsrvd[0] = 0; /* reserved */
3241 mpd10.hd.rsrvd[1] = 0; /* reserved */
3242 if (scsicmd->cmnd[1] & 0x8) {
3243 /* Block descriptor length (MSB) */
3244 mpd10.hd.bd_length[0] = 0;
3245 /* Block descriptor length (LSB) */
3246 mpd10.hd.bd_length[1] = 0;
3248 mpd10.hd.bd_length[0] = 0;
3249 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
3251 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
3253 mpd10.bd.block_length[0] =
3254 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3255 mpd10.bd.block_length[1] =
3256 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3257 mpd10.bd.block_length[2] =
3258 fsa_dev_ptr[cid].block_size & 0xff;
3260 if (capacity > 0xffffff) {
3261 mpd10.bd.block_count[0] = 0xff;
3262 mpd10.bd.block_count[1] = 0xff;
3263 mpd10.bd.block_count[2] = 0xff;
3265 mpd10.bd.block_count[0] =
3266 (capacity >> 16) & 0xff;
3267 mpd10.bd.block_count[1] =
3268 (capacity >> 8) & 0xff;
3269 mpd10.bd.block_count[2] =
3273 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3274 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
3275 mpd10.hd.data_length[1] += 3;
3276 mpd10.mpc_buf[0] = 8;
3277 mpd10.mpc_buf[1] = 1;
3278 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
3279 ? 0 : 0x04; /* WCE */
3280 mode_buf_length = sizeof(mpd10);
3281 if (mode_buf_length > scsicmd->cmnd[8])
3282 mode_buf_length = scsicmd->cmnd[8];
3284 scsi_sg_copy_from_buffer(scsicmd,
3288 scsicmd->result = AAC_STAT_GOOD;
3292 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
3293 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3294 sizeof(struct sense_data));
3295 memset(&dev->fsa_dev[cid].sense_data, 0,
3296 sizeof(struct sense_data));
3297 scsicmd->result = AAC_STAT_GOOD;
3300 case ALLOW_MEDIUM_REMOVAL:
3301 dprintk((KERN_DEBUG "LOCK command.\n"));
3302 if (scsicmd->cmnd[4])
3303 fsa_dev_ptr[cid].locked = 1;
3305 fsa_dev_ptr[cid].locked = 0;
3307 scsicmd->result = AAC_STAT_GOOD;
3310 * These commands are all No-Ops
3312 case TEST_UNIT_READY:
3313 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
3314 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3315 SAM_STAT_CHECK_CONDITION;
3316 set_sense(&dev->fsa_dev[cid].sense_data,
3317 NOT_READY, SENCODE_BECOMING_READY,
3318 ASENCODE_BECOMING_READY, 0, 0);
3319 memcpy(scsicmd->sense_buffer,
3320 &dev->fsa_dev[cid].sense_data,
3322 sizeof(dev->fsa_dev[cid].sense_data),
3323 SCSI_SENSE_BUFFERSIZE));
3329 case REASSIGN_BLOCKS:
3331 scsicmd->result = AAC_STAT_GOOD;
3335 return aac_start_stop(scsicmd);
3340 * Unhandled commands
3342 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
3344 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3345 SAM_STAT_CHECK_CONDITION;
3346 set_sense(&dev->fsa_dev[cid].sense_data,
3347 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
3348 ASENCODE_INVALID_COMMAND, 0, 0);
3349 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3351 sizeof(dev->fsa_dev[cid].sense_data),
3352 SCSI_SENSE_BUFFERSIZE));
3357 scsicmd->scsi_done(scsicmd);
3361 static int query_disk(struct aac_dev *dev, void __user *arg)
3363 struct aac_query_disk qd;
3364 struct fsa_dev_info *fsa_dev_ptr;
3366 fsa_dev_ptr = dev->fsa_dev;
3369 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
3371 if (qd.cnum == -1) {
3372 if (qd.id < 0 || qd.id >= dev->maximum_num_containers)
3375 } else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) {
3376 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
3378 qd.instance = dev->scsi_host_ptr->host_no;
3380 qd.id = CONTAINER_TO_ID(qd.cnum);
3381 qd.lun = CONTAINER_TO_LUN(qd.cnum);
3383 else return -EINVAL;
3385 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
3386 qd.locked = fsa_dev_ptr[qd.cnum].locked;
3387 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
3389 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
3394 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
3395 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
3397 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
3402 static int force_delete_disk(struct aac_dev *dev, void __user *arg)
3404 struct aac_delete_disk dd;
3405 struct fsa_dev_info *fsa_dev_ptr;
3407 fsa_dev_ptr = dev->fsa_dev;
3411 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3414 if (dd.cnum >= dev->maximum_num_containers)
3417 * Mark this container as being deleted.
3419 fsa_dev_ptr[dd.cnum].deleted = 1;
3421 * Mark the container as no longer valid
3423 fsa_dev_ptr[dd.cnum].valid = 0;
3427 static int delete_disk(struct aac_dev *dev, void __user *arg)
3429 struct aac_delete_disk dd;
3430 struct fsa_dev_info *fsa_dev_ptr;
3432 fsa_dev_ptr = dev->fsa_dev;
3436 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3439 if (dd.cnum >= dev->maximum_num_containers)
3442 * If the container is locked, it can not be deleted by the API.
3444 if (fsa_dev_ptr[dd.cnum].locked)
3448 * Mark the container as no longer being valid.
3450 fsa_dev_ptr[dd.cnum].valid = 0;
3451 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
3456 int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
3459 case FSACTL_QUERY_DISK:
3460 return query_disk(dev, arg);
3461 case FSACTL_DELETE_DISK:
3462 return delete_disk(dev, arg);
3463 case FSACTL_FORCE_DELETE_DISK:
3464 return force_delete_disk(dev, arg);
3465 case FSACTL_GET_CONTAINERS:
3466 return aac_get_containers(dev);
3475 * @context: the context set in the fib - here it is scsi cmd
3476 * @fibptr: pointer to the fib
3478 * Handles the completion of a scsi command to a non dasd device
3482 static void aac_srb_callback(void *context, struct fib * fibptr)
3484 struct aac_dev *dev;
3485 struct aac_srb_reply *srbreply;
3486 struct scsi_cmnd *scsicmd;
3488 scsicmd = (struct scsi_cmnd *) context;
3490 if (!aac_valid_context(scsicmd, fibptr))
3493 BUG_ON(fibptr == NULL);
3497 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
3499 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
3501 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3503 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
3504 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
3507 * Calculate resid for sg
3509 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
3510 - le32_to_cpu(srbreply->data_xfer_length));
3514 scsi_dma_unmap(scsicmd);
3516 /* expose physical device if expose_physicald flag is on */
3517 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
3518 && expose_physicals > 0)
3519 aac_expose_phy_device(scsicmd);
3522 * First check the fib status
3525 if (le32_to_cpu(srbreply->status) != ST_OK) {
3528 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3529 le32_to_cpu(srbreply->status));
3530 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3531 SCSI_SENSE_BUFFERSIZE);
3532 scsicmd->result = DID_ERROR << 16
3533 | COMMAND_COMPLETE << 8
3534 | SAM_STAT_CHECK_CONDITION;
3535 memcpy(scsicmd->sense_buffer,
3536 srbreply->sense_data, len);
3540 * Next check the srb status
3542 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3543 case SRB_STATUS_ERROR_RECOVERY:
3544 case SRB_STATUS_PENDING:
3545 case SRB_STATUS_SUCCESS:
3546 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3548 case SRB_STATUS_DATA_OVERRUN:
3549 switch (scsicmd->cmnd[0]) {
3558 if (le32_to_cpu(srbreply->data_xfer_length)
3559 < scsicmd->underflow)
3560 pr_warn("aacraid: SCSI CMD underflow\n");
3562 pr_warn("aacraid: SCSI CMD Data Overrun\n");
3563 scsicmd->result = DID_ERROR << 16
3564 | COMMAND_COMPLETE << 8;
3567 scsicmd->result = DID_OK << 16
3568 | COMMAND_COMPLETE << 8;
3571 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3575 case SRB_STATUS_ABORTED:
3576 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3578 case SRB_STATUS_ABORT_FAILED:
3580 * Not sure about this one - but assuming the
3581 * hba was trying to abort for some reason
3583 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3585 case SRB_STATUS_PARITY_ERROR:
3586 scsicmd->result = DID_PARITY << 16
3587 | MSG_PARITY_ERROR << 8;
3589 case SRB_STATUS_NO_DEVICE:
3590 case SRB_STATUS_INVALID_PATH_ID:
3591 case SRB_STATUS_INVALID_TARGET_ID:
3592 case SRB_STATUS_INVALID_LUN:
3593 case SRB_STATUS_SELECTION_TIMEOUT:
3594 scsicmd->result = DID_NO_CONNECT << 16
3595 | COMMAND_COMPLETE << 8;
3598 case SRB_STATUS_COMMAND_TIMEOUT:
3599 case SRB_STATUS_TIMEOUT:
3600 scsicmd->result = DID_TIME_OUT << 16
3601 | COMMAND_COMPLETE << 8;
3604 case SRB_STATUS_BUSY:
3605 scsicmd->result = DID_BUS_BUSY << 16
3606 | COMMAND_COMPLETE << 8;
3609 case SRB_STATUS_BUS_RESET:
3610 scsicmd->result = DID_RESET << 16
3611 | COMMAND_COMPLETE << 8;
3614 case SRB_STATUS_MESSAGE_REJECTED:
3615 scsicmd->result = DID_ERROR << 16
3616 | MESSAGE_REJECT << 8;
3618 case SRB_STATUS_REQUEST_FLUSHED:
3619 case SRB_STATUS_ERROR:
3620 case SRB_STATUS_INVALID_REQUEST:
3621 case SRB_STATUS_REQUEST_SENSE_FAILED:
3622 case SRB_STATUS_NO_HBA:
3623 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3624 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3625 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3626 case SRB_STATUS_DELAYED_RETRY:
3627 case SRB_STATUS_BAD_FUNCTION:
3628 case SRB_STATUS_NOT_STARTED:
3629 case SRB_STATUS_NOT_IN_USE:
3630 case SRB_STATUS_FORCE_ABORT:
3631 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3633 #ifdef AAC_DETAILED_STATUS_INFO
3634 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3635 le32_to_cpu(srbreply->srb_status) & 0x3F,
3636 aac_get_status_string(
3637 le32_to_cpu(srbreply->srb_status) & 0x3F),
3639 le32_to_cpu(srbreply->scsi_status));
3642 * When the CC bit is SET by the host in ATA pass thru CDB,
3643 * driver is supposed to return DID_OK
3645 * When the CC bit is RESET by the host, driver should
3648 if ((scsicmd->cmnd[0] == ATA_12)
3649 || (scsicmd->cmnd[0] == ATA_16)) {
3651 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3652 scsicmd->result = DID_OK << 16
3653 | COMMAND_COMPLETE << 8;
3656 scsicmd->result = DID_ERROR << 16
3657 | COMMAND_COMPLETE << 8;
3661 scsicmd->result = DID_ERROR << 16
3662 | COMMAND_COMPLETE << 8;
3666 if (le32_to_cpu(srbreply->scsi_status)
3667 == SAM_STAT_CHECK_CONDITION) {
3670 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3671 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3672 SCSI_SENSE_BUFFERSIZE);
3673 #ifdef AAC_DETAILED_STATUS_INFO
3674 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3675 le32_to_cpu(srbreply->status), len);
3677 memcpy(scsicmd->sense_buffer,
3678 srbreply->sense_data, len);
3682 * OR in the scsi status (already shifted up a bit)
3684 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3686 aac_fib_complete(fibptr);
3687 scsicmd->scsi_done(scsicmd);
3690 static void hba_resp_task_complete(struct aac_dev *dev,
3691 struct scsi_cmnd *scsicmd,
3692 struct aac_hba_resp *err) {
3694 scsicmd->result = err->status;
3695 /* set residual count */
3696 scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
3698 switch (err->status) {
3700 scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3702 case SAM_STAT_CHECK_CONDITION:
3706 len = min_t(u8, err->sense_response_data_len,
3707 SCSI_SENSE_BUFFERSIZE);
3709 memcpy(scsicmd->sense_buffer,
3710 err->sense_response_buf, len);
3711 scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3715 scsicmd->result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
3717 case SAM_STAT_TASK_ABORTED:
3718 scsicmd->result |= DID_ABORT << 16 | ABORT << 8;
3720 case SAM_STAT_RESERVATION_CONFLICT:
3721 case SAM_STAT_TASK_SET_FULL:
3723 scsicmd->result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3728 static void hba_resp_task_failure(struct aac_dev *dev,
3729 struct scsi_cmnd *scsicmd,
3730 struct aac_hba_resp *err)
3732 switch (err->status) {
3733 case HBA_RESP_STAT_HBAMODE_DISABLED:
3737 bus = aac_logical_to_phys(scmd_channel(scsicmd));
3738 cid = scmd_id(scsicmd);
3739 if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
3740 dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
3741 dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
3743 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3746 case HBA_RESP_STAT_IO_ERROR:
3747 case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
3748 scsicmd->result = DID_OK << 16 |
3749 COMMAND_COMPLETE << 8 | SAM_STAT_BUSY;
3751 case HBA_RESP_STAT_IO_ABORTED:
3752 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3754 case HBA_RESP_STAT_INVALID_DEVICE:
3755 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3757 case HBA_RESP_STAT_UNDERRUN:
3758 /* UNDERRUN is OK */
3759 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3761 case HBA_RESP_STAT_OVERRUN:
3763 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3771 * @context: the context set in the fib - here it is scsi cmd
3772 * @fibptr: pointer to the fib
3774 * Handles the completion of a native HBA scsi command
3777 void aac_hba_callback(void *context, struct fib *fibptr)
3779 struct aac_dev *dev;
3780 struct scsi_cmnd *scsicmd;
3782 struct aac_hba_resp *err =
3783 &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
3785 scsicmd = (struct scsi_cmnd *) context;
3787 if (!aac_valid_context(scsicmd, fibptr))
3790 WARN_ON(fibptr == NULL);
3793 if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
3794 scsi_dma_unmap(scsicmd);
3796 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3798 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3802 switch (err->service_response) {
3803 case HBA_RESP_SVCRES_TASK_COMPLETE:
3804 hba_resp_task_complete(dev, scsicmd, err);
3806 case HBA_RESP_SVCRES_FAILURE:
3807 hba_resp_task_failure(dev, scsicmd, err);
3809 case HBA_RESP_SVCRES_TMF_REJECTED:
3810 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
3812 case HBA_RESP_SVCRES_TMF_LUN_INVALID:
3813 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3815 case HBA_RESP_SVCRES_TMF_COMPLETE:
3816 case HBA_RESP_SVCRES_TMF_SUCCEEDED:
3817 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3820 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3825 aac_fib_complete(fibptr);
3827 if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
3828 scsicmd->SCp.sent_command = 1;
3830 scsicmd->scsi_done(scsicmd);
3836 * @scsicmd: the scsi command block
3838 * This routine will form a FIB and fill in the aac_srb from the
3839 * scsicmd passed in.
3842 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3844 struct fib* cmd_fibcontext;
3845 struct aac_dev* dev;
3848 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3849 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3850 scsicmd->device->lun > 7) {
3851 scsicmd->result = DID_NO_CONNECT << 16;
3852 scsicmd->scsi_done(scsicmd);
3857 * Allocate and initialize a Fib then setup a BlockWrite command
3859 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3860 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3861 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
3864 * Check that the command queued to the controller
3866 if (status == -EINPROGRESS)
3869 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3870 aac_fib_complete(cmd_fibcontext);
3871 aac_fib_free(cmd_fibcontext);
3879 * @scsicmd: the scsi command block
3881 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3882 * scsicmd passed in.
3884 static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
3886 struct fib *cmd_fibcontext;
3887 struct aac_dev *dev;
3890 dev = shost_priv(scsicmd->device->host);
3891 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3892 scsicmd->device->lun > AAC_MAX_LUN - 1) {
3893 scsicmd->result = DID_NO_CONNECT << 16;
3894 scsicmd->scsi_done(scsicmd);
3899 * Allocate and initialize a Fib then setup a BlockWrite command
3901 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3902 if (!cmd_fibcontext)
3905 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3906 status = aac_adapter_hba(cmd_fibcontext, scsicmd);
3909 * Check that the command queued to the controller
3911 if (status == -EINPROGRESS)
3914 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3916 aac_fib_complete(cmd_fibcontext);
3917 aac_fib_free(cmd_fibcontext);
3923 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
3925 struct aac_dev *dev;
3926 unsigned long byte_count = 0;
3928 struct scatterlist *sg;
3931 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3932 // Get rid of old data
3934 psg->sg[0].addr = 0;
3935 psg->sg[0].count = 0;
3937 nseg = scsi_dma_map(scsicmd);
3941 psg->count = cpu_to_le32(nseg);
3943 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3944 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3945 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3946 byte_count += sg_dma_len(sg);
3948 /* hba wants the size to be exact */
3949 if (byte_count > scsi_bufflen(scsicmd)) {
3950 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3951 (byte_count - scsi_bufflen(scsicmd));
3952 psg->sg[i-1].count = cpu_to_le32(temp);
3953 byte_count = scsi_bufflen(scsicmd);
3955 /* Check for command underflow */
3956 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3957 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3958 byte_count, scsicmd->underflow);
3965 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
3967 struct aac_dev *dev;
3968 unsigned long byte_count = 0;
3971 struct scatterlist *sg;
3974 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3975 // Get rid of old data
3977 psg->sg[0].addr[0] = 0;
3978 psg->sg[0].addr[1] = 0;
3979 psg->sg[0].count = 0;
3981 nseg = scsi_dma_map(scsicmd);
3985 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3986 int count = sg_dma_len(sg);
3987 addr = sg_dma_address(sg);
3988 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3989 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
3990 psg->sg[i].count = cpu_to_le32(count);
3991 byte_count += count;
3993 psg->count = cpu_to_le32(nseg);
3994 /* hba wants the size to be exact */
3995 if (byte_count > scsi_bufflen(scsicmd)) {
3996 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3997 (byte_count - scsi_bufflen(scsicmd));
3998 psg->sg[i-1].count = cpu_to_le32(temp);
3999 byte_count = scsi_bufflen(scsicmd);
4001 /* Check for command underflow */
4002 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4003 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
4004 byte_count, scsicmd->underflow);
4010 static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
4012 unsigned long byte_count = 0;
4014 struct scatterlist *sg;
4017 // Get rid of old data
4019 psg->sg[0].next = 0;
4020 psg->sg[0].prev = 0;
4021 psg->sg[0].addr[0] = 0;
4022 psg->sg[0].addr[1] = 0;
4023 psg->sg[0].count = 0;
4024 psg->sg[0].flags = 0;
4026 nseg = scsi_dma_map(scsicmd);
4030 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4031 int count = sg_dma_len(sg);
4032 u64 addr = sg_dma_address(sg);
4033 psg->sg[i].next = 0;
4034 psg->sg[i].prev = 0;
4035 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
4036 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
4037 psg->sg[i].count = cpu_to_le32(count);
4038 psg->sg[i].flags = 0;
4039 byte_count += count;
4041 psg->count = cpu_to_le32(nseg);
4042 /* hba wants the size to be exact */
4043 if (byte_count > scsi_bufflen(scsicmd)) {
4044 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
4045 (byte_count - scsi_bufflen(scsicmd));
4046 psg->sg[i-1].count = cpu_to_le32(temp);
4047 byte_count = scsi_bufflen(scsicmd);
4049 /* Check for command underflow */
4050 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4051 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
4052 byte_count, scsicmd->underflow);
4058 static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
4059 struct aac_raw_io2 *rio2, int sg_max)
4061 unsigned long byte_count = 0;
4063 struct scatterlist *sg;
4064 int i, conformable = 0;
4065 u32 min_size = PAGE_SIZE, cur_size;
4067 nseg = scsi_dma_map(scsicmd);
4071 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4072 int count = sg_dma_len(sg);
4073 u64 addr = sg_dma_address(sg);
4075 BUG_ON(i >= sg_max);
4076 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
4077 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
4078 cur_size = cpu_to_le32(count);
4079 rio2->sge[i].length = cur_size;
4080 rio2->sge[i].flags = 0;
4083 rio2->sgeFirstSize = cur_size;
4084 } else if (i == 1) {
4085 rio2->sgeNominalSize = cur_size;
4086 min_size = cur_size;
4087 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
4089 if (cur_size < min_size)
4090 min_size = cur_size;
4092 byte_count += count;
4095 /* hba wants the size to be exact */
4096 if (byte_count > scsi_bufflen(scsicmd)) {
4097 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
4098 (byte_count - scsi_bufflen(scsicmd));
4099 rio2->sge[i-1].length = cpu_to_le32(temp);
4100 byte_count = scsi_bufflen(scsicmd);
4103 rio2->sgeCnt = cpu_to_le32(nseg);
4104 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
4105 /* not conformable: evaluate required sg elements */
4107 int j, nseg_new = nseg, err_found;
4108 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
4111 for (j = 1; j < nseg - 1; ++j) {
4112 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
4116 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
4121 if (i > 0 && nseg_new <= sg_max) {
4122 int ret = aac_convert_sgraw2(rio2, i, nseg, nseg_new);
4128 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4130 /* Check for command underflow */
4131 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4132 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
4133 byte_count, scsicmd->underflow);
4139 static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
4141 struct sge_ieee1212 *sge;
4145 if (aac_convert_sgl == 0)
4148 sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
4152 for (i = 1, pos = 1; i < nseg-1; ++i) {
4153 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
4154 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
4155 sge[pos].addrLow = addr_low;
4156 sge[pos].addrHigh = rio2->sge[i].addrHigh;
4157 if (addr_low < rio2->sge[i].addrLow)
4158 sge[pos].addrHigh++;
4159 sge[pos].length = pages * PAGE_SIZE;
4164 sge[pos] = rio2->sge[nseg-1];
4165 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
4168 rio2->sgeCnt = cpu_to_le32(nseg_new);
4169 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4170 rio2->sgeNominalSize = pages * PAGE_SIZE;
4174 static long aac_build_sghba(struct scsi_cmnd *scsicmd,
4175 struct aac_hba_cmd_req *hbacmd,
4179 unsigned long byte_count = 0;
4181 struct scatterlist *sg;
4184 struct aac_hba_sgl *sge;
4186 nseg = scsi_dma_map(scsicmd);
4192 if (nseg > HBA_MAX_SG_EMBEDDED)
4193 sge = &hbacmd->sge[2];
4195 sge = &hbacmd->sge[0];
4197 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4198 int count = sg_dma_len(sg);
4199 u64 addr = sg_dma_address(sg);
4201 WARN_ON(i >= sg_max);
4202 sge->addr_hi = cpu_to_le32((u32)(addr>>32));
4203 sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
4204 cur_size = cpu_to_le32(count);
4205 sge->len = cur_size;
4207 byte_count += count;
4212 /* hba wants the size to be exact */
4213 if (byte_count > scsi_bufflen(scsicmd)) {
4216 temp = le32_to_cpu(sge->len) - byte_count
4217 - scsi_bufflen(scsicmd);
4218 sge->len = cpu_to_le32(temp);
4219 byte_count = scsi_bufflen(scsicmd);
4222 if (nseg <= HBA_MAX_SG_EMBEDDED) {
4223 hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
4224 sge->flags = cpu_to_le32(0x40000000);
4227 hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
4228 hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
4229 hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
4230 hbacmd->sge[0].addr_lo =
4231 cpu_to_le32((u32)(sg_address & 0xffffffff));
4234 /* Check for command underflow */
4235 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4236 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4237 byte_count, scsicmd->underflow);
4243 #ifdef AAC_DETAILED_STATUS_INFO
4245 struct aac_srb_status_info {
4251 static struct aac_srb_status_info srb_status_info[] = {
4252 { SRB_STATUS_PENDING, "Pending Status"},
4253 { SRB_STATUS_SUCCESS, "Success"},
4254 { SRB_STATUS_ABORTED, "Aborted Command"},
4255 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
4256 { SRB_STATUS_ERROR, "Error Event"},
4257 { SRB_STATUS_BUSY, "Device Busy"},
4258 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
4259 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
4260 { SRB_STATUS_NO_DEVICE, "No Device"},
4261 { SRB_STATUS_TIMEOUT, "Timeout"},
4262 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
4263 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
4264 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
4265 { SRB_STATUS_BUS_RESET, "Bus Reset"},
4266 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
4267 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
4268 { SRB_STATUS_NO_HBA, "No HBA"},
4269 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
4270 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
4271 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
4272 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
4273 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
4274 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
4275 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
4276 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
4277 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
4278 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
4279 { SRB_STATUS_NOT_STARTED, "Not Started"},
4280 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
4281 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
4282 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
4283 { 0xff, "Unknown Error"}
4286 char *aac_get_status_string(u32 status)
4290 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
4291 if (srb_status_info[i].status == status)
4292 return srb_status_info[i].str;
4294 return "Bad Status Code";