Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Adaptec AAC series RAID controller driver |
Alan Cox | fa195af | 2008-10-27 15:16:36 +0000 | [diff] [blame] | 3 | * (c) Copyright 2001 Red Hat Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * based on the old aacraid driver that is.. |
| 6 | * Adaptec aacraid device driver for Linux. |
| 7 | * |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 8 | * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; see the file COPYING. If not, write to |
| 22 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/pci.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/completion.h> |
| 33 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/uaccess.h> |
Salyzyn, Mark | 3a0086a | 2008-01-11 11:46:44 -0800 | [diff] [blame] | 35 | #include <linux/highmem.h> /* For flush_kernel_dcache_page */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <scsi/scsi.h> |
| 38 | #include <scsi/scsi_cmnd.h> |
| 39 | #include <scsi/scsi_device.h> |
| 40 | #include <scsi/scsi_host.h> |
| 41 | |
| 42 | #include "aacraid.h" |
| 43 | |
| 44 | /* values for inqd_pdt: Peripheral device type in plain English */ |
| 45 | #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */ |
| 46 | #define INQD_PDT_PROC 0x03 /* Processor device */ |
| 47 | #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */ |
| 48 | #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */ |
| 49 | #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */ |
| 50 | #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */ |
| 51 | |
| 52 | #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */ |
| 53 | #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */ |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | /* |
| 56 | * Sense codes |
| 57 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 58 | |
| 59 | #define SENCODE_NO_SENSE 0x00 |
| 60 | #define SENCODE_END_OF_DATA 0x00 |
| 61 | #define SENCODE_BECOMING_READY 0x04 |
| 62 | #define SENCODE_INIT_CMD_REQUIRED 0x04 |
| 63 | #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A |
| 64 | #define SENCODE_INVALID_COMMAND 0x20 |
| 65 | #define SENCODE_LBA_OUT_OF_RANGE 0x21 |
| 66 | #define SENCODE_INVALID_CDB_FIELD 0x24 |
| 67 | #define SENCODE_LUN_NOT_SUPPORTED 0x25 |
| 68 | #define SENCODE_INVALID_PARAM_FIELD 0x26 |
| 69 | #define SENCODE_PARAM_NOT_SUPPORTED 0x26 |
| 70 | #define SENCODE_PARAM_VALUE_INVALID 0x26 |
| 71 | #define SENCODE_RESET_OCCURRED 0x29 |
| 72 | #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E |
| 73 | #define SENCODE_INQUIRY_DATA_CHANGED 0x3F |
| 74 | #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39 |
| 75 | #define SENCODE_DIAGNOSTIC_FAILURE 0x40 |
| 76 | #define SENCODE_INTERNAL_TARGET_FAILURE 0x44 |
| 77 | #define SENCODE_INVALID_MESSAGE_ERROR 0x49 |
| 78 | #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c |
| 79 | #define SENCODE_OVERLAPPED_COMMAND 0x4E |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * Additional sense codes |
| 83 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 84 | |
| 85 | #define ASENCODE_NO_SENSE 0x00 |
| 86 | #define ASENCODE_END_OF_DATA 0x05 |
| 87 | #define ASENCODE_BECOMING_READY 0x01 |
| 88 | #define ASENCODE_INIT_CMD_REQUIRED 0x02 |
| 89 | #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00 |
| 90 | #define ASENCODE_INVALID_COMMAND 0x00 |
| 91 | #define ASENCODE_LBA_OUT_OF_RANGE 0x00 |
| 92 | #define ASENCODE_INVALID_CDB_FIELD 0x00 |
| 93 | #define ASENCODE_LUN_NOT_SUPPORTED 0x00 |
| 94 | #define ASENCODE_INVALID_PARAM_FIELD 0x00 |
| 95 | #define ASENCODE_PARAM_NOT_SUPPORTED 0x01 |
| 96 | #define ASENCODE_PARAM_VALUE_INVALID 0x02 |
| 97 | #define ASENCODE_RESET_OCCURRED 0x00 |
| 98 | #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00 |
| 99 | #define ASENCODE_INQUIRY_DATA_CHANGED 0x03 |
| 100 | #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00 |
| 101 | #define ASENCODE_DIAGNOSTIC_FAILURE 0x80 |
| 102 | #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00 |
| 103 | #define ASENCODE_INVALID_MESSAGE_ERROR 0x00 |
| 104 | #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00 |
| 105 | #define ASENCODE_OVERLAPPED_COMMAND 0x00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | #define BYTE0(x) (unsigned char)(x) |
| 108 | #define BYTE1(x) (unsigned char)((x) >> 8) |
| 109 | #define BYTE2(x) (unsigned char)((x) >> 16) |
| 110 | #define BYTE3(x) (unsigned char)((x) >> 24) |
| 111 | |
| 112 | /*------------------------------------------------------------------------------ |
| 113 | * S T R U C T S / T Y P E D E F S |
| 114 | *----------------------------------------------------------------------------*/ |
| 115 | /* SCSI inquiry data */ |
| 116 | struct inquiry_data { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 117 | u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */ |
| 118 | u8 inqd_dtq; /* RMB | Device Type Qualifier */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */ |
| 120 | u8 inqd_rdf; /* AENC | TrmIOP | Response data format */ |
| 121 | u8 inqd_len; /* Additional length (n-4) */ |
| 122 | u8 inqd_pad1[2];/* Reserved - must be zero */ |
| 123 | u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */ |
| 124 | u8 inqd_vid[8]; /* Vendor ID */ |
| 125 | u8 inqd_pid[16];/* Product ID */ |
| 126 | u8 inqd_prl[4]; /* Product Revision Level */ |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * M O D U L E G L O B A L S |
| 131 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap); |
| 134 | static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg); |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 135 | static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | static int aac_send_srb_fib(struct scsi_cmnd* scsicmd); |
| 137 | #ifdef AAC_DETAILED_STATUS_INFO |
| 138 | static char *aac_get_status_string(u32 status); |
| 139 | #endif |
| 140 | |
| 141 | /* |
| 142 | * Non dasd selection is handled entirely in aachba now |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 143 | */ |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static int nondasd = -1; |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 146 | static int aac_cache = 2; /* WCE=0 to avoid performance problems */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | static int dacmode = -1; |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 148 | int aac_msi; |
Salyzyn, Mark | 1208bab | 2007-05-22 09:32:29 -0400 | [diff] [blame] | 149 | int aac_commit = -1; |
Mark Haverkamp | 404d9a9 | 2006-05-10 09:12:48 -0700 | [diff] [blame] | 150 | int startup_timeout = 180; |
| 151 | int aif_timeout = 120; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Mark Haverkamp | 9a72f97 | 2006-03-27 09:44:37 -0800 | [diff] [blame] | 153 | module_param(nondasd, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 154 | MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices." |
| 155 | " 0=off, 1=on"); |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 156 | module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 157 | MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n" |
| 158 | "\tbit 0 - Disable FUA in WRITE SCSI commands\n" |
| 159 | "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n" |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 160 | "\tbit 2 - Disable only if Battery is protecting Cache"); |
Mark Haverkamp | 9a72f97 | 2006-03-27 09:44:37 -0800 | [diff] [blame] | 161 | module_param(dacmode, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 162 | MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC." |
| 163 | " 0=off, 1=on"); |
Salyzyn, Mark | 1208bab | 2007-05-22 09:32:29 -0400 | [diff] [blame] | 164 | module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 165 | MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the" |
| 166 | " adapter for foreign arrays.\n" |
| 167 | "This is typically needed in systems that do not have a BIOS." |
| 168 | " 0=off, 1=on"); |
| 169 | module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR); |
| 170 | MODULE_PARM_DESC(msi, "IRQ handling." |
| 171 | " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)"); |
Mark Haverkamp | 404d9a9 | 2006-05-10 09:12:48 -0700 | [diff] [blame] | 172 | module_param(startup_timeout, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 173 | MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for" |
| 174 | " adapter to have it's kernel up and\n" |
| 175 | "running. This is typically adjusted for large systems that do not" |
| 176 | " have a BIOS."); |
Mark Haverkamp | 404d9a9 | 2006-05-10 09:12:48 -0700 | [diff] [blame] | 177 | module_param(aif_timeout, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 178 | MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for" |
| 179 | " applications to pick up AIFs before\n" |
| 180 | "deregistering them. This is typically adjusted for heavily burdened" |
| 181 | " systems."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 183 | int numacb = -1; |
| 184 | module_param(numacb, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 185 | MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control" |
| 186 | " blocks (FIB) allocated. Valid values are 512 and down. Default is" |
| 187 | " to use suggestion from Firmware."); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 188 | |
| 189 | int acbsize = -1; |
| 190 | module_param(acbsize, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 191 | MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)" |
| 192 | " size. Valid values are 512, 2048, 4096 and 8192. Default is to use" |
| 193 | " suggestion from Firmware."); |
Mark Haverkamp | 653ba58 | 2006-09-19 08:59:43 -0700 | [diff] [blame] | 194 | |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 195 | int update_interval = 30 * 60; |
| 196 | module_param(update_interval, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 197 | MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync" |
| 198 | " updates issued to adapter."); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 199 | |
| 200 | int check_interval = 24 * 60 * 60; |
| 201 | module_param(check_interval, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 202 | MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health" |
| 203 | " checks."); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 204 | |
Andrew Morton | 87f3bda | 2007-08-10 14:50:30 -0700 | [diff] [blame] | 205 | int aac_check_reset = 1; |
| 206 | module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR); |
Paul Bolle | 95e7a8e | 2008-04-16 14:43:00 +0200 | [diff] [blame] | 207 | MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the" |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 208 | " adapter. a value of -1 forces the reset to adapters programmed to" |
| 209 | " ignore it."); |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 210 | |
Mark Haverkamp | e37ee4b | 2007-01-26 09:23:32 -0800 | [diff] [blame] | 211 | int expose_physicals = -1; |
Mark Haverkamp | 653ba58 | 2006-09-19 08:59:43 -0700 | [diff] [blame] | 212 | module_param(expose_physicals, int, S_IRUGO|S_IWUSR); |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 213 | MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays." |
| 214 | " -1=protect 0=off, 1=on"); |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 215 | |
Salyzyn, Mark | 8ef2224 | 2008-02-08 05:48:22 -0800 | [diff] [blame] | 216 | int aac_reset_devices; |
Salyzyn, Mark | 1208bab | 2007-05-22 09:32:29 -0400 | [diff] [blame] | 217 | module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR); |
| 218 | MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization."); |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 219 | |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 220 | int aac_wwn = 1; |
| 221 | module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR); |
| 222 | MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n" |
| 223 | "\t0 - Disable\n" |
| 224 | "\t1 - Array Meta Data Signature (default)\n" |
| 225 | "\t2 - Adapter Serial Number"); |
| 226 | |
| 227 | |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 228 | static inline int aac_valid_context(struct scsi_cmnd *scsicmd, |
| 229 | struct fib *fibptr) { |
| 230 | struct scsi_device *device; |
| 231 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 232 | if (unlikely(!scsicmd || !scsicmd->scsi_done)) { |
Salyzyn, Mark | c835e37 | 2007-07-26 14:20:02 -0400 | [diff] [blame] | 233 | dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n")); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 234 | aac_fib_complete(fibptr); |
| 235 | aac_fib_free(fibptr); |
| 236 | return 0; |
| 237 | } |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 238 | scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL; |
| 239 | device = scsicmd->device; |
| 240 | if (unlikely(!device || !scsi_device_online(device))) { |
| 241 | dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n")); |
| 242 | aac_fib_complete(fibptr); |
| 243 | aac_fib_free(fibptr); |
| 244 | return 0; |
| 245 | } |
| 246 | return 1; |
| 247 | } |
| 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | /** |
| 250 | * aac_get_config_status - check the adapter configuration |
| 251 | * @common: adapter to query |
| 252 | * |
| 253 | * Query config status, and commit the configuration if needed. |
| 254 | */ |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 255 | int aac_get_config_status(struct aac_dev *dev, int commit_flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
| 257 | int status = 0; |
| 258 | struct fib * fibptr; |
| 259 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 260 | if (!(fibptr = aac_fib_alloc(dev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return -ENOMEM; |
| 262 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 263 | aac_fib_init(fibptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
| 265 | struct aac_get_config_status *dinfo; |
| 266 | dinfo = (struct aac_get_config_status *) fib_data(fibptr); |
| 267 | |
| 268 | dinfo->command = cpu_to_le32(VM_ContainerConfig); |
| 269 | dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS); |
| 270 | dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data)); |
| 271 | } |
| 272 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 273 | status = aac_fib_send(ContainerCommand, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | fibptr, |
| 275 | sizeof (struct aac_get_config_status), |
| 276 | FsaNormal, |
| 277 | 1, 1, |
| 278 | NULL, NULL); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 279 | if (status < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n"); |
| 281 | } else { |
| 282 | struct aac_get_config_status_resp *reply |
| 283 | = (struct aac_get_config_status_resp *) fib_data(fibptr); |
| 284 | dprintk((KERN_WARNING |
| 285 | "aac_get_config_status: response=%d status=%d action=%d\n", |
| 286 | le32_to_cpu(reply->response), |
| 287 | le32_to_cpu(reply->status), |
| 288 | le32_to_cpu(reply->data.action))); |
| 289 | if ((le32_to_cpu(reply->response) != ST_OK) || |
| 290 | (le32_to_cpu(reply->status) != CT_OK) || |
| 291 | (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) { |
| 292 | printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n"); |
| 293 | status = -EINVAL; |
| 294 | } |
| 295 | } |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 296 | /* Do not set XferState to zero unless receives a response from F/W */ |
| 297 | if (status >= 0) |
| 298 | aac_fib_complete(fibptr); |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | /* Send a CT_COMMIT_CONFIG to enable discovery of devices */ |
| 301 | if (status >= 0) { |
Salyzyn, Mark | 1208bab | 2007-05-22 09:32:29 -0400 | [diff] [blame] | 302 | if ((aac_commit == 1) || commit_flag) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | struct aac_commit_config * dinfo; |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 304 | aac_fib_init(fibptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | dinfo = (struct aac_commit_config *) fib_data(fibptr); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | dinfo->command = cpu_to_le32(VM_ContainerConfig); |
| 308 | dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 309 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 310 | status = aac_fib_send(ContainerCommand, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | fibptr, |
| 312 | sizeof (struct aac_commit_config), |
| 313 | FsaNormal, |
| 314 | 1, 1, |
| 315 | NULL, NULL); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 316 | /* Do not set XferState to zero unless |
| 317 | * receives a response from F/W */ |
| 318 | if (status >= 0) |
| 319 | aac_fib_complete(fibptr); |
Salyzyn, Mark | 1208bab | 2007-05-22 09:32:29 -0400 | [diff] [blame] | 320 | } else if (aac_commit == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | printk(KERN_WARNING |
| 322 | "aac_get_config_status: Foreign device configurations are being ignored\n"); |
| 323 | } |
| 324 | } |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 325 | /* FIB should be freed only after getting the response from the F/W */ |
| 326 | if (status != -ERESTARTSYS) |
| 327 | aac_fib_free(fibptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return status; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * aac_get_containers - list containers |
| 333 | * @common: adapter to probe |
| 334 | * |
| 335 | * Make a list of all containers on this controller |
| 336 | */ |
| 337 | int aac_get_containers(struct aac_dev *dev) |
| 338 | { |
| 339 | struct fsa_dev_info *fsa_dev_ptr; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 340 | u32 index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | int status = 0; |
| 342 | struct fib * fibptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | struct aac_get_container_count *dinfo; |
| 344 | struct aac_get_container_count_resp *dresp; |
| 345 | int maximum_num_containers = MAXIMUM_NUM_CONTAINERS; |
| 346 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 347 | if (!(fibptr = aac_fib_alloc(dev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | return -ENOMEM; |
| 349 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 350 | aac_fib_init(fibptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | dinfo = (struct aac_get_container_count *) fib_data(fibptr); |
| 352 | dinfo->command = cpu_to_le32(VM_ContainerConfig); |
| 353 | dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT); |
| 354 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 355 | status = aac_fib_send(ContainerCommand, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | fibptr, |
| 357 | sizeof (struct aac_get_container_count), |
| 358 | FsaNormal, |
| 359 | 1, 1, |
| 360 | NULL, NULL); |
| 361 | if (status >= 0) { |
| 362 | dresp = (struct aac_get_container_count_resp *)fib_data(fibptr); |
| 363 | maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries); |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 364 | aac_fib_complete(fibptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 366 | /* FIB should be freed only after getting the response from the F/W */ |
| 367 | if (status != -ERESTARTSYS) |
| 368 | aac_fib_free(fibptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS) |
| 371 | maximum_num_containers = MAXIMUM_NUM_CONTAINERS; |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 372 | fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers, |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 373 | GFP_KERNEL); |
| 374 | if (!fsa_dev_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | dev->fsa_dev = fsa_dev_ptr; |
| 378 | dev->maximum_num_containers = maximum_num_containers; |
| 379 | |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 380 | for (index = 0; index < dev->maximum_num_containers; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | fsa_dev_ptr[index].devname[0] = '\0'; |
| 382 | |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 383 | status = aac_probe_container(dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 385 | if (status < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n"); |
| 387 | break; |
| 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | /* |
| 391 | * If there are no more containers, then stop asking. |
| 392 | */ |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 393 | if (++index >= status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | return status; |
| 397 | } |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | static void get_container_name_callback(void *context, struct fib * fibptr) |
| 400 | { |
| 401 | struct aac_get_name_resp * get_name_reply; |
| 402 | struct scsi_cmnd * scsicmd; |
| 403 | |
| 404 | scsicmd = (struct scsi_cmnd *) context; |
| 405 | |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 406 | if (!aac_valid_context(scsicmd, fibptr)) |
| 407 | return; |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies)); |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 410 | BUG_ON(fibptr == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr); |
| 413 | /* Failure is irrelevant, using default value instead */ |
| 414 | if ((le32_to_cpu(get_name_reply->status) == CT_OK) |
| 415 | && (get_name_reply->data[0] != '\0')) { |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 416 | char *sp = get_name_reply->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0'; |
| 418 | while (*sp == ' ') |
| 419 | ++sp; |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 420 | if (*sp) { |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 421 | struct inquiry_data inq; |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 422 | char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)]; |
| 423 | int count = sizeof(d); |
| 424 | char *dp = d; |
| 425 | do { |
| 426 | *dp++ = (*sp) ? *sp++ : ' '; |
| 427 | } while (--count > 0); |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 428 | |
| 429 | scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq)); |
| 430 | memcpy(inq.inqd_pid, d, sizeof(d)); |
| 431 | scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq)); |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 436 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 437 | aac_fib_complete(fibptr); |
| 438 | aac_fib_free(fibptr); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 439 | scsicmd->scsi_done(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /** |
| 443 | * aac_get_container_name - get container name, none blocking. |
| 444 | */ |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 445 | static int aac_get_container_name(struct scsi_cmnd * scsicmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | int status; |
| 448 | struct aac_get_name *dinfo; |
| 449 | struct fib * cmd_fibcontext; |
| 450 | struct aac_dev * dev; |
| 451 | |
| 452 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; |
| 453 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 454 | if (!(cmd_fibcontext = aac_fib_alloc(dev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | return -ENOMEM; |
| 456 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 457 | aac_fib_init(cmd_fibcontext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext); |
| 459 | |
| 460 | dinfo->command = cpu_to_le32(VM_ContainerConfig); |
| 461 | dinfo->type = cpu_to_le32(CT_READ_NAME); |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 462 | dinfo->cid = cpu_to_le32(scmd_id(scsicmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data)); |
| 464 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 465 | status = aac_fib_send(ContainerCommand, |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 466 | cmd_fibcontext, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | sizeof (struct aac_get_name), |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 468 | FsaNormal, |
| 469 | 0, 1, |
| 470 | (fib_callback)get_container_name_callback, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | (void *) scsicmd); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /* |
| 474 | * Check that the command queued to the controller |
| 475 | */ |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 476 | if (status == -EINPROGRESS) { |
| 477 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return 0; |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 479 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 480 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 481 | printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status); |
| 482 | aac_fib_complete(cmd_fibcontext); |
| 483 | aac_fib_free(cmd_fibcontext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | return -1; |
| 485 | } |
| 486 | |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 487 | static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd) |
| 488 | { |
| 489 | struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev; |
| 490 | |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 491 | if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1)) |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 492 | return aac_scsi_cmd(scsicmd); |
| 493 | |
| 494 | scsicmd->result = DID_NO_CONNECT << 16; |
| 495 | scsicmd->scsi_done(scsicmd); |
| 496 | return 0; |
| 497 | } |
| 498 | |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 499 | static void _aac_probe_container2(void * context, struct fib * fibptr) |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 500 | { |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 501 | struct fsa_dev_info *fsa_dev_ptr; |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 502 | int (*callback)(struct scsi_cmnd *); |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 503 | struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context; |
| 504 | |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 505 | |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 506 | if (!aac_valid_context(scsicmd, fibptr)) |
| 507 | return; |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 508 | |
| 509 | scsicmd->SCp.Status = 0; |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 510 | fsa_dev_ptr = fibptr->dev->fsa_dev; |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 511 | if (fsa_dev_ptr) { |
| 512 | struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr); |
| 513 | fsa_dev_ptr += scmd_id(scsicmd); |
| 514 | |
| 515 | if ((le32_to_cpu(dresp->status) == ST_OK) && |
| 516 | (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && |
| 517 | (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { |
| 518 | fsa_dev_ptr->valid = 1; |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 519 | /* sense_key holds the current state of the spin-up */ |
| 520 | if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY)) |
| 521 | fsa_dev_ptr->sense_data.sense_key = NOT_READY; |
| 522 | else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY) |
| 523 | fsa_dev_ptr->sense_data.sense_key = NO_SENSE; |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 524 | fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol); |
| 525 | fsa_dev_ptr->size |
| 526 | = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) + |
| 527 | (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32); |
| 528 | fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0); |
| 529 | } |
| 530 | if ((fsa_dev_ptr->valid & 1) == 0) |
| 531 | fsa_dev_ptr->valid = 0; |
| 532 | scsicmd->SCp.Status = le32_to_cpu(dresp->count); |
| 533 | } |
| 534 | aac_fib_complete(fibptr); |
| 535 | aac_fib_free(fibptr); |
| 536 | callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr); |
| 537 | scsicmd->SCp.ptr = NULL; |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 538 | (*callback)(scsicmd); |
| 539 | return; |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 542 | static void _aac_probe_container1(void * context, struct fib * fibptr) |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 543 | { |
| 544 | struct scsi_cmnd * scsicmd; |
| 545 | struct aac_mount * dresp; |
| 546 | struct aac_query_mount *dinfo; |
| 547 | int status; |
| 548 | |
| 549 | dresp = (struct aac_mount *) fib_data(fibptr); |
| 550 | dresp->mnt[0].capacityhigh = 0; |
| 551 | if ((le32_to_cpu(dresp->status) != ST_OK) || |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 552 | (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) { |
| 553 | _aac_probe_container2(context, fibptr); |
| 554 | return; |
| 555 | } |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 556 | scsicmd = (struct scsi_cmnd *) context; |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 557 | |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 558 | if (!aac_valid_context(scsicmd, fibptr)) |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 559 | return; |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 560 | |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 561 | aac_fib_init(fibptr); |
| 562 | |
| 563 | dinfo = (struct aac_query_mount *)fib_data(fibptr); |
| 564 | |
| 565 | dinfo->command = cpu_to_le32(VM_NameServe64); |
| 566 | dinfo->count = cpu_to_le32(scmd_id(scsicmd)); |
| 567 | dinfo->type = cpu_to_le32(FT_FILESYS); |
| 568 | |
| 569 | status = aac_fib_send(ContainerCommand, |
| 570 | fibptr, |
| 571 | sizeof(struct aac_query_mount), |
| 572 | FsaNormal, |
| 573 | 0, 1, |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 574 | _aac_probe_container2, |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 575 | (void *) scsicmd); |
| 576 | /* |
| 577 | * Check that the command queued to the controller |
| 578 | */ |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 579 | if (status == -EINPROGRESS) |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 580 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 581 | else if (status < 0) { |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 582 | /* Inherit results from VM_NameServe, if any */ |
| 583 | dresp->status = cpu_to_le32(ST_OK); |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 584 | _aac_probe_container2(context, fibptr); |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 585 | } |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *)) |
| 589 | { |
| 590 | struct fib * fibptr; |
| 591 | int status = -ENOMEM; |
| 592 | |
| 593 | if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) { |
| 594 | struct aac_query_mount *dinfo; |
| 595 | |
| 596 | aac_fib_init(fibptr); |
| 597 | |
| 598 | dinfo = (struct aac_query_mount *)fib_data(fibptr); |
| 599 | |
| 600 | dinfo->command = cpu_to_le32(VM_NameServe); |
| 601 | dinfo->count = cpu_to_le32(scmd_id(scsicmd)); |
| 602 | dinfo->type = cpu_to_le32(FT_FILESYS); |
| 603 | scsicmd->SCp.ptr = (char *)callback; |
| 604 | |
| 605 | status = aac_fib_send(ContainerCommand, |
| 606 | fibptr, |
| 607 | sizeof(struct aac_query_mount), |
| 608 | FsaNormal, |
| 609 | 0, 1, |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 610 | _aac_probe_container1, |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 611 | (void *) scsicmd); |
| 612 | /* |
| 613 | * Check that the command queued to the controller |
| 614 | */ |
| 615 | if (status == -EINPROGRESS) { |
| 616 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
| 617 | return 0; |
| 618 | } |
| 619 | if (status < 0) { |
| 620 | scsicmd->SCp.ptr = NULL; |
| 621 | aac_fib_complete(fibptr); |
| 622 | aac_fib_free(fibptr); |
| 623 | } |
| 624 | } |
| 625 | if (status < 0) { |
| 626 | struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev; |
| 627 | if (fsa_dev_ptr) { |
| 628 | fsa_dev_ptr += scmd_id(scsicmd); |
| 629 | if ((fsa_dev_ptr->valid & 1) == 0) { |
| 630 | fsa_dev_ptr->valid = 0; |
| 631 | return (*callback)(scsicmd); |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | return status; |
| 636 | } |
| 637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | /** |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 639 | * aac_probe_container - query a logical volume |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | * @dev: device to query |
| 641 | * @cid: container identifier |
| 642 | * |
| 643 | * Queries the controller about the given volume. The volume information |
| 644 | * is updated in the struct fsa_dev_info structure rather than returned. |
| 645 | */ |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 646 | static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd) |
| 647 | { |
| 648 | scsicmd->device = NULL; |
| 649 | return 0; |
| 650 | } |
| 651 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 652 | int aac_probe_container(struct aac_dev *dev, int cid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 654 | struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL); |
| 655 | struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 658 | if (!scsicmd || !scsidev) { |
| 659 | kfree(scsicmd); |
| 660 | kfree(scsidev); |
Mark Haverkamp | 90ee346 | 2006-08-03 08:03:07 -0700 | [diff] [blame] | 661 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | } |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 663 | scsicmd->list.next = NULL; |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 664 | scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 666 | scsicmd->device = scsidev; |
| 667 | scsidev->sdev_state = 0; |
| 668 | scsidev->id = cid; |
| 669 | scsidev->host = dev->scsi_host_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 671 | if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0) |
| 672 | while (scsicmd->device == scsidev) |
| 673 | schedule(); |
Salyzyn, Mark | 802ae2f | 2007-03-21 13:49:47 -0400 | [diff] [blame] | 674 | kfree(scsidev); |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 675 | status = scsicmd->SCp.Status; |
| 676 | kfree(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | return status; |
| 678 | } |
| 679 | |
| 680 | /* Local Structure to set SCSI inquiry data strings */ |
| 681 | struct scsi_inq { |
| 682 | char vid[8]; /* Vendor ID */ |
| 683 | char pid[16]; /* Product ID */ |
| 684 | char prl[4]; /* Product Revision Level */ |
| 685 | }; |
| 686 | |
| 687 | /** |
| 688 | * InqStrCopy - string merge |
| 689 | * @a: string to copy from |
| 690 | * @b: string to copy to |
| 691 | * |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 692 | * Copy a String from one location to another |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | * without copying \0 |
| 694 | */ |
| 695 | |
| 696 | static void inqstrcpy(char *a, char *b) |
| 697 | { |
| 698 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 699 | while (*a != (char)0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | *b++ = *a++; |
| 701 | } |
| 702 | |
| 703 | static char *container_types[] = { |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 704 | "None", |
| 705 | "Volume", |
| 706 | "Mirror", |
| 707 | "Stripe", |
| 708 | "RAID5", |
| 709 | "SSRW", |
| 710 | "SSRO", |
| 711 | "Morph", |
| 712 | "Legacy", |
| 713 | "RAID4", |
| 714 | "RAID10", |
| 715 | "RAID00", |
| 716 | "V-MIRRORS", |
| 717 | "PSEUDO R4", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | "RAID50", |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 719 | "RAID5D", |
| 720 | "RAID5D0", |
| 721 | "RAID1E", |
| 722 | "RAID6", |
| 723 | "RAID60", |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 724 | "Unknown" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | }; |
| 726 | |
Salyzyn, Mark | 17eaace | 2008-01-08 12:23:49 -0800 | [diff] [blame] | 727 | char * get_container_type(unsigned tindex) |
| 728 | { |
| 729 | if (tindex >= ARRAY_SIZE(container_types)) |
| 730 | tindex = ARRAY_SIZE(container_types) - 1; |
| 731 | return container_types[tindex]; |
| 732 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | /* Function: setinqstr |
| 735 | * |
| 736 | * Arguments: [1] pointer to void [1] int |
| 737 | * |
| 738 | * Purpose: Sets SCSI inquiry data strings for vendor, product |
| 739 | * and revision level. Allows strings to be set in platform dependant |
| 740 | * files instead of in OS dependant driver source. |
| 741 | */ |
| 742 | |
Mark Haverkamp | 794d060 | 2005-10-24 10:51:53 -0700 | [diff] [blame] | 743 | static void setinqstr(struct aac_dev *dev, void *data, int tindex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | { |
| 745 | struct scsi_inq *str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | str = (struct scsi_inq *)(data); /* cast data to scsi inq block */ |
Mark Haverkamp | 794d060 | 2005-10-24 10:51:53 -0700 | [diff] [blame] | 748 | memset(str, ' ', sizeof(*str)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Mark Haverkamp | 794d060 | 2005-10-24 10:51:53 -0700 | [diff] [blame] | 750 | if (dev->supplement_adapter_info.AdapterTypeText[0]) { |
| 751 | char * cp = dev->supplement_adapter_info.AdapterTypeText; |
Salyzyn, Mark | 3bc8070 | 2008-01-11 13:46:24 -0800 | [diff] [blame] | 752 | int c; |
| 753 | if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C')) |
| 754 | inqstrcpy("SMC", str->vid); |
| 755 | else { |
| 756 | c = sizeof(str->vid); |
| 757 | while (*cp && *cp != ' ' && --c) |
| 758 | ++cp; |
| 759 | c = *cp; |
| 760 | *cp = '\0'; |
| 761 | inqstrcpy (dev->supplement_adapter_info.AdapterTypeText, |
| 762 | str->vid); |
| 763 | *cp = c; |
| 764 | while (*cp && *cp != ' ') |
| 765 | ++cp; |
| 766 | } |
Mark Haverkamp | 794d060 | 2005-10-24 10:51:53 -0700 | [diff] [blame] | 767 | while (*cp == ' ') |
| 768 | ++cp; |
| 769 | /* last six chars reserved for vol type */ |
| 770 | c = 0; |
| 771 | if (strlen(cp) > sizeof(str->pid)) { |
| 772 | c = cp[sizeof(str->pid)]; |
| 773 | cp[sizeof(str->pid)] = '\0'; |
| 774 | } |
| 775 | inqstrcpy (cp, str->pid); |
| 776 | if (c) |
| 777 | cp[sizeof(str->pid)] = c; |
| 778 | } else { |
| 779 | struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype); |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 780 | |
| 781 | inqstrcpy (mp->vname, str->vid); |
Mark Haverkamp | 794d060 | 2005-10-24 10:51:53 -0700 | [diff] [blame] | 782 | /* last six chars reserved for vol type */ |
| 783 | inqstrcpy (mp->model, str->pid); |
| 784 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 786 | if (tindex < ARRAY_SIZE(container_types)){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | char *findit = str->pid; |
| 788 | |
| 789 | for ( ; *findit != ' '; findit++); /* walk till we find a space */ |
| 790 | /* RAID is superfluous in the context of a RAID device */ |
| 791 | if (memcmp(findit-4, "RAID", 4) == 0) |
| 792 | *(findit -= 4) = ' '; |
Mark Haverkamp | 794d060 | 2005-10-24 10:51:53 -0700 | [diff] [blame] | 793 | if (((findit - str->pid) + strlen(container_types[tindex])) |
| 794 | < (sizeof(str->pid) + sizeof(str->prl))) |
| 795 | inqstrcpy (container_types[tindex], findit + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | } |
| 797 | inqstrcpy ("V1.0", str->prl); |
| 798 | } |
| 799 | |
Salyzyn, Mark | 88e2f98 | 2007-07-17 14:01:28 -0400 | [diff] [blame] | 800 | static void get_container_serial_callback(void *context, struct fib * fibptr) |
| 801 | { |
| 802 | struct aac_get_serial_resp * get_serial_reply; |
| 803 | struct scsi_cmnd * scsicmd; |
| 804 | |
| 805 | BUG_ON(fibptr == NULL); |
| 806 | |
| 807 | scsicmd = (struct scsi_cmnd *) context; |
| 808 | if (!aac_valid_context(scsicmd, fibptr)) |
| 809 | return; |
| 810 | |
| 811 | get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr); |
| 812 | /* Failure is irrelevant, using default value instead */ |
| 813 | if (le32_to_cpu(get_serial_reply->status) == CT_OK) { |
| 814 | char sp[13]; |
| 815 | /* EVPD bit set */ |
| 816 | sp[0] = INQD_PDT_DA; |
| 817 | sp[1] = scsicmd->cmnd[2]; |
| 818 | sp[2] = 0; |
| 819 | sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X", |
| 820 | le32_to_cpu(get_serial_reply->uid)); |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 821 | scsi_sg_copy_from_buffer(scsicmd, sp, sizeof(sp)); |
Salyzyn, Mark | 88e2f98 | 2007-07-17 14:01:28 -0400 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 825 | |
| 826 | aac_fib_complete(fibptr); |
| 827 | aac_fib_free(fibptr); |
| 828 | scsicmd->scsi_done(scsicmd); |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * aac_get_container_serial - get container serial, none blocking. |
| 833 | */ |
| 834 | static int aac_get_container_serial(struct scsi_cmnd * scsicmd) |
| 835 | { |
| 836 | int status; |
| 837 | struct aac_get_serial *dinfo; |
| 838 | struct fib * cmd_fibcontext; |
| 839 | struct aac_dev * dev; |
| 840 | |
| 841 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; |
| 842 | |
| 843 | if (!(cmd_fibcontext = aac_fib_alloc(dev))) |
| 844 | return -ENOMEM; |
| 845 | |
| 846 | aac_fib_init(cmd_fibcontext); |
| 847 | dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext); |
| 848 | |
| 849 | dinfo->command = cpu_to_le32(VM_ContainerConfig); |
| 850 | dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID); |
| 851 | dinfo->cid = cpu_to_le32(scmd_id(scsicmd)); |
| 852 | |
| 853 | status = aac_fib_send(ContainerCommand, |
| 854 | cmd_fibcontext, |
| 855 | sizeof (struct aac_get_serial), |
| 856 | FsaNormal, |
| 857 | 0, 1, |
| 858 | (fib_callback) get_container_serial_callback, |
| 859 | (void *) scsicmd); |
| 860 | |
| 861 | /* |
| 862 | * Check that the command queued to the controller |
| 863 | */ |
| 864 | if (status == -EINPROGRESS) { |
| 865 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status); |
| 870 | aac_fib_complete(cmd_fibcontext); |
| 871 | aac_fib_free(cmd_fibcontext); |
| 872 | return -1; |
| 873 | } |
| 874 | |
| 875 | /* Function: setinqserial |
| 876 | * |
| 877 | * Arguments: [1] pointer to void [1] int |
| 878 | * |
| 879 | * Purpose: Sets SCSI Unit Serial number. |
| 880 | * This is a fake. We should read a proper |
| 881 | * serial number from the container. <SuSE>But |
| 882 | * without docs it's quite hard to do it :-) |
| 883 | * So this will have to do in the meantime.</SuSE> |
| 884 | */ |
| 885 | |
| 886 | static int setinqserial(struct aac_dev *dev, void *data, int cid) |
| 887 | { |
| 888 | /* |
| 889 | * This breaks array migration. |
| 890 | */ |
| 891 | return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X", |
| 892 | le32_to_cpu(dev->adapter_info.serial[0]), cid); |
| 893 | } |
| 894 | |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 895 | static inline void set_sense(struct sense_data *sense_data, u8 sense_key, |
| 896 | u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | { |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 898 | u8 *sense_buf = (u8 *)sense_data; |
| 899 | /* Sense data valid, err code 70h */ |
| 900 | sense_buf[0] = 0x70; /* No info field */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | sense_buf[1] = 0; /* Segment number, always zero */ |
| 902 | |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 903 | sense_buf[2] = sense_key; /* Sense key */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | sense_buf[12] = sense_code; /* Additional sense code */ |
| 906 | sense_buf[13] = a_sense_code; /* Additional sense code qualifier */ |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | if (sense_key == ILLEGAL_REQUEST) { |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 909 | sense_buf[7] = 10; /* Additional sense length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 911 | sense_buf[15] = bit_pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | /* Illegal parameter is in the parameter block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | if (sense_code == SENCODE_INVALID_CDB_FIELD) |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 914 | sense_buf[15] |= 0xc0;/* Std sense key specific field */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | /* Illegal parameter is in the CDB block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | sense_buf[16] = field_pointer >> 8; /* MSB */ |
| 917 | sense_buf[17] = field_pointer; /* LSB */ |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 918 | } else |
| 919 | sense_buf[7] = 6; /* Additional sense length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 922 | static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba) |
| 923 | { |
| 924 | if (lba & 0xffffffff00000000LL) { |
| 925 | int cid = scmd_id(cmd); |
| 926 | dprintk((KERN_DEBUG "aacraid: Illegal lba\n")); |
| 927 | cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | |
| 928 | SAM_STAT_CHECK_CONDITION; |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 929 | set_sense(&dev->fsa_dev[cid].sense_data, |
| 930 | HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE, |
| 931 | ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 932 | memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, |
Salyzyn, Mark | 3ace426 | 2008-01-14 07:25:33 -0800 | [diff] [blame] | 933 | min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), |
| 934 | SCSI_SENSE_BUFFERSIZE)); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 935 | cmd->scsi_done(cmd); |
| 936 | return 1; |
| 937 | } |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba) |
| 942 | { |
| 943 | return 0; |
| 944 | } |
| 945 | |
| 946 | static void io_callback(void *context, struct fib * fibptr); |
| 947 | |
| 948 | static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) |
| 949 | { |
| 950 | u16 fibsize; |
| 951 | struct aac_raw_io *readcmd; |
| 952 | aac_fib_init(fib); |
| 953 | readcmd = (struct aac_raw_io *) fib_data(fib); |
| 954 | readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff)); |
| 955 | readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); |
| 956 | readcmd->count = cpu_to_le32(count<<9); |
| 957 | readcmd->cid = cpu_to_le16(scmd_id(cmd)); |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 958 | readcmd->flags = cpu_to_le16(IO_TYPE_READ); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 959 | readcmd->bpTotal = 0; |
| 960 | readcmd->bpComplete = 0; |
| 961 | |
| 962 | aac_build_sgraw(cmd, &readcmd->sg); |
| 963 | fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw)); |
| 964 | BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); |
| 965 | /* |
| 966 | * Now send the Fib to the adapter |
| 967 | */ |
| 968 | return aac_fib_send(ContainerRawIo, |
| 969 | fib, |
| 970 | fibsize, |
| 971 | FsaNormal, |
| 972 | 0, 1, |
| 973 | (fib_callback) io_callback, |
| 974 | (void *) cmd); |
| 975 | } |
| 976 | |
| 977 | static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) |
| 978 | { |
| 979 | u16 fibsize; |
| 980 | struct aac_read64 *readcmd; |
| 981 | aac_fib_init(fib); |
| 982 | readcmd = (struct aac_read64 *) fib_data(fib); |
| 983 | readcmd->command = cpu_to_le32(VM_CtHostRead64); |
| 984 | readcmd->cid = cpu_to_le16(scmd_id(cmd)); |
| 985 | readcmd->sector_count = cpu_to_le16(count); |
| 986 | readcmd->block = cpu_to_le32((u32)(lba&0xffffffff)); |
| 987 | readcmd->pad = 0; |
| 988 | readcmd->flags = 0; |
| 989 | |
| 990 | aac_build_sg64(cmd, &readcmd->sg); |
| 991 | fibsize = sizeof(struct aac_read64) + |
| 992 | ((le32_to_cpu(readcmd->sg.count) - 1) * |
| 993 | sizeof (struct sgentry64)); |
| 994 | BUG_ON (fibsize > (fib->dev->max_fib_size - |
| 995 | sizeof(struct aac_fibhdr))); |
| 996 | /* |
| 997 | * Now send the Fib to the adapter |
| 998 | */ |
| 999 | return aac_fib_send(ContainerCommand64, |
| 1000 | fib, |
| 1001 | fibsize, |
| 1002 | FsaNormal, |
| 1003 | 0, 1, |
| 1004 | (fib_callback) io_callback, |
| 1005 | (void *) cmd); |
| 1006 | } |
| 1007 | |
| 1008 | static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) |
| 1009 | { |
| 1010 | u16 fibsize; |
| 1011 | struct aac_read *readcmd; |
| 1012 | aac_fib_init(fib); |
| 1013 | readcmd = (struct aac_read *) fib_data(fib); |
| 1014 | readcmd->command = cpu_to_le32(VM_CtBlockRead); |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1015 | readcmd->cid = cpu_to_le32(scmd_id(cmd)); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1016 | readcmd->block = cpu_to_le32((u32)(lba&0xffffffff)); |
| 1017 | readcmd->count = cpu_to_le32(count * 512); |
| 1018 | |
| 1019 | aac_build_sg(cmd, &readcmd->sg); |
| 1020 | fibsize = sizeof(struct aac_read) + |
| 1021 | ((le32_to_cpu(readcmd->sg.count) - 1) * |
| 1022 | sizeof (struct sgentry)); |
| 1023 | BUG_ON (fibsize > (fib->dev->max_fib_size - |
| 1024 | sizeof(struct aac_fibhdr))); |
| 1025 | /* |
| 1026 | * Now send the Fib to the adapter |
| 1027 | */ |
| 1028 | return aac_fib_send(ContainerCommand, |
| 1029 | fib, |
| 1030 | fibsize, |
| 1031 | FsaNormal, |
| 1032 | 0, 1, |
| 1033 | (fib_callback) io_callback, |
| 1034 | (void *) cmd); |
| 1035 | } |
| 1036 | |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1037 | static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua) |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1038 | { |
| 1039 | u16 fibsize; |
| 1040 | struct aac_raw_io *writecmd; |
| 1041 | aac_fib_init(fib); |
| 1042 | writecmd = (struct aac_raw_io *) fib_data(fib); |
| 1043 | writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff)); |
| 1044 | writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); |
| 1045 | writecmd->count = cpu_to_le32(count<<9); |
| 1046 | writecmd->cid = cpu_to_le16(scmd_id(cmd)); |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 1047 | writecmd->flags = (fua && ((aac_cache & 5) != 1) && |
| 1048 | (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ? |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1049 | cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) : |
| 1050 | cpu_to_le16(IO_TYPE_WRITE); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1051 | writecmd->bpTotal = 0; |
| 1052 | writecmd->bpComplete = 0; |
| 1053 | |
| 1054 | aac_build_sgraw(cmd, &writecmd->sg); |
| 1055 | fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw)); |
| 1056 | BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); |
| 1057 | /* |
| 1058 | * Now send the Fib to the adapter |
| 1059 | */ |
| 1060 | return aac_fib_send(ContainerRawIo, |
| 1061 | fib, |
| 1062 | fibsize, |
| 1063 | FsaNormal, |
| 1064 | 0, 1, |
| 1065 | (fib_callback) io_callback, |
| 1066 | (void *) cmd); |
| 1067 | } |
| 1068 | |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1069 | static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua) |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1070 | { |
| 1071 | u16 fibsize; |
| 1072 | struct aac_write64 *writecmd; |
| 1073 | aac_fib_init(fib); |
| 1074 | writecmd = (struct aac_write64 *) fib_data(fib); |
| 1075 | writecmd->command = cpu_to_le32(VM_CtHostWrite64); |
| 1076 | writecmd->cid = cpu_to_le16(scmd_id(cmd)); |
| 1077 | writecmd->sector_count = cpu_to_le16(count); |
| 1078 | writecmd->block = cpu_to_le32((u32)(lba&0xffffffff)); |
| 1079 | writecmd->pad = 0; |
| 1080 | writecmd->flags = 0; |
| 1081 | |
| 1082 | aac_build_sg64(cmd, &writecmd->sg); |
| 1083 | fibsize = sizeof(struct aac_write64) + |
| 1084 | ((le32_to_cpu(writecmd->sg.count) - 1) * |
| 1085 | sizeof (struct sgentry64)); |
| 1086 | BUG_ON (fibsize > (fib->dev->max_fib_size - |
| 1087 | sizeof(struct aac_fibhdr))); |
| 1088 | /* |
| 1089 | * Now send the Fib to the adapter |
| 1090 | */ |
| 1091 | return aac_fib_send(ContainerCommand64, |
| 1092 | fib, |
| 1093 | fibsize, |
| 1094 | FsaNormal, |
| 1095 | 0, 1, |
| 1096 | (fib_callback) io_callback, |
| 1097 | (void *) cmd); |
| 1098 | } |
| 1099 | |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1100 | static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua) |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1101 | { |
| 1102 | u16 fibsize; |
| 1103 | struct aac_write *writecmd; |
| 1104 | aac_fib_init(fib); |
| 1105 | writecmd = (struct aac_write *) fib_data(fib); |
| 1106 | writecmd->command = cpu_to_le32(VM_CtBlockWrite); |
Christoph Hellwig | f3307f7 | 2007-11-08 17:27:47 +0000 | [diff] [blame] | 1107 | writecmd->cid = cpu_to_le32(scmd_id(cmd)); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1108 | writecmd->block = cpu_to_le32((u32)(lba&0xffffffff)); |
| 1109 | writecmd->count = cpu_to_le32(count * 512); |
| 1110 | writecmd->sg.count = cpu_to_le32(1); |
| 1111 | /* ->stable is not used - it did mean which type of write */ |
| 1112 | |
| 1113 | aac_build_sg(cmd, &writecmd->sg); |
| 1114 | fibsize = sizeof(struct aac_write) + |
| 1115 | ((le32_to_cpu(writecmd->sg.count) - 1) * |
| 1116 | sizeof (struct sgentry)); |
| 1117 | BUG_ON (fibsize > (fib->dev->max_fib_size - |
| 1118 | sizeof(struct aac_fibhdr))); |
| 1119 | /* |
| 1120 | * Now send the Fib to the adapter |
| 1121 | */ |
| 1122 | return aac_fib_send(ContainerCommand, |
| 1123 | fib, |
| 1124 | fibsize, |
| 1125 | FsaNormal, |
| 1126 | 0, 1, |
| 1127 | (fib_callback) io_callback, |
| 1128 | (void *) cmd); |
| 1129 | } |
| 1130 | |
| 1131 | static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd) |
| 1132 | { |
| 1133 | struct aac_srb * srbcmd; |
| 1134 | u32 flag; |
| 1135 | u32 timeout; |
| 1136 | |
| 1137 | aac_fib_init(fib); |
| 1138 | switch(cmd->sc_data_direction){ |
| 1139 | case DMA_TO_DEVICE: |
| 1140 | flag = SRB_DataOut; |
| 1141 | break; |
| 1142 | case DMA_BIDIRECTIONAL: |
| 1143 | flag = SRB_DataIn | SRB_DataOut; |
| 1144 | break; |
| 1145 | case DMA_FROM_DEVICE: |
| 1146 | flag = SRB_DataIn; |
| 1147 | break; |
| 1148 | case DMA_NONE: |
| 1149 | default: /* shuts up some versions of gcc */ |
| 1150 | flag = SRB_NoDataXfer; |
| 1151 | break; |
| 1152 | } |
| 1153 | |
| 1154 | srbcmd = (struct aac_srb*) fib_data(fib); |
| 1155 | srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); |
| 1156 | srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd))); |
| 1157 | srbcmd->id = cpu_to_le32(scmd_id(cmd)); |
| 1158 | srbcmd->lun = cpu_to_le32(cmd->device->lun); |
| 1159 | srbcmd->flags = cpu_to_le32(flag); |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 1160 | timeout = cmd->request->timeout/HZ; |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1161 | if (timeout == 0) |
| 1162 | timeout = 1; |
| 1163 | srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds |
| 1164 | srbcmd->retry_limit = 0; /* Obsolete parameter */ |
| 1165 | srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len); |
| 1166 | return srbcmd; |
| 1167 | } |
| 1168 | |
| 1169 | static void aac_srb_callback(void *context, struct fib * fibptr); |
| 1170 | |
| 1171 | static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd) |
| 1172 | { |
| 1173 | u16 fibsize; |
| 1174 | struct aac_srb * srbcmd = aac_scsi_common(fib, cmd); |
| 1175 | |
| 1176 | aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg); |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 1177 | srbcmd->count = cpu_to_le32(scsi_bufflen(cmd)); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1178 | |
| 1179 | memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); |
| 1180 | memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len); |
| 1181 | /* |
| 1182 | * Build Scatter/Gather list |
| 1183 | */ |
| 1184 | fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) + |
| 1185 | ((le32_to_cpu(srbcmd->sg.count) & 0xff) * |
| 1186 | sizeof (struct sgentry64)); |
| 1187 | BUG_ON (fibsize > (fib->dev->max_fib_size - |
| 1188 | sizeof(struct aac_fibhdr))); |
| 1189 | |
| 1190 | /* |
| 1191 | * Now send the Fib to the adapter |
| 1192 | */ |
| 1193 | return aac_fib_send(ScsiPortCommand64, fib, |
| 1194 | fibsize, FsaNormal, 0, 1, |
| 1195 | (fib_callback) aac_srb_callback, |
| 1196 | (void *) cmd); |
| 1197 | } |
| 1198 | |
| 1199 | static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd) |
| 1200 | { |
| 1201 | u16 fibsize; |
| 1202 | struct aac_srb * srbcmd = aac_scsi_common(fib, cmd); |
| 1203 | |
| 1204 | aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg); |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 1205 | srbcmd->count = cpu_to_le32(scsi_bufflen(cmd)); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1206 | |
| 1207 | memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); |
| 1208 | memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len); |
| 1209 | /* |
| 1210 | * Build Scatter/Gather list |
| 1211 | */ |
| 1212 | fibsize = sizeof (struct aac_srb) + |
| 1213 | (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) * |
| 1214 | sizeof (struct sgentry)); |
| 1215 | BUG_ON (fibsize > (fib->dev->max_fib_size - |
| 1216 | sizeof(struct aac_fibhdr))); |
| 1217 | |
| 1218 | /* |
| 1219 | * Now send the Fib to the adapter |
| 1220 | */ |
| 1221 | return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1, |
| 1222 | (fib_callback) aac_srb_callback, (void *) cmd); |
| 1223 | } |
| 1224 | |
Salyzyn, Mark | 94cf6ba | 2007-12-13 16:14:18 -0800 | [diff] [blame] | 1225 | static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd) |
| 1226 | { |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 1227 | if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac && |
| 1228 | (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) |
Salyzyn, Mark | 94cf6ba | 2007-12-13 16:14:18 -0800 | [diff] [blame] | 1229 | return FAILED; |
| 1230 | return aac_scsi_32(fib, cmd); |
| 1231 | } |
| 1232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | int aac_get_adapter_info(struct aac_dev* dev) |
| 1234 | { |
| 1235 | struct fib* fibptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | int rcode; |
| 1237 | u32 tmp; |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 1238 | struct aac_adapter_info *info; |
| 1239 | struct aac_bus_info *command; |
| 1240 | struct aac_bus_info_response *bus_info; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1241 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1242 | if (!(fibptr = aac_fib_alloc(dev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | return -ENOMEM; |
| 1244 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1245 | aac_fib_init(fibptr); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1246 | info = (struct aac_adapter_info *) fib_data(fibptr); |
| 1247 | memset(info,0,sizeof(*info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1249 | rcode = aac_fib_send(RequestAdapterInfo, |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1250 | fibptr, |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1251 | sizeof(*info), |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1252 | FsaNormal, |
Mark Haverkamp | 9203344 | 2005-09-20 12:56:50 -0700 | [diff] [blame] | 1253 | -1, 1, /* First `interrupt' command uses special wait */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1254 | NULL, |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1255 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1257 | if (rcode < 0) { |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1258 | /* FIB should be freed only after |
| 1259 | * getting the response from the F/W */ |
| 1260 | if (rcode != -ERESTARTSYS) { |
| 1261 | aac_fib_complete(fibptr); |
| 1262 | aac_fib_free(fibptr); |
| 1263 | } |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1264 | return rcode; |
| 1265 | } |
| 1266 | memcpy(&dev->adapter_info, info, sizeof(*info)); |
| 1267 | |
| 1268 | if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) { |
Salyzyn, Mark | 06a43d1 | 2008-01-08 12:32:00 -0800 | [diff] [blame] | 1269 | struct aac_supplement_adapter_info * sinfo; |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1270 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1271 | aac_fib_init(fibptr); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1272 | |
Salyzyn, Mark | 06a43d1 | 2008-01-08 12:32:00 -0800 | [diff] [blame] | 1273 | sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1274 | |
Salyzyn, Mark | 06a43d1 | 2008-01-08 12:32:00 -0800 | [diff] [blame] | 1275 | memset(sinfo,0,sizeof(*sinfo)); |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1276 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1277 | rcode = aac_fib_send(RequestSupplementAdapterInfo, |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1278 | fibptr, |
Salyzyn, Mark | 06a43d1 | 2008-01-08 12:32:00 -0800 | [diff] [blame] | 1279 | sizeof(*sinfo), |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1280 | FsaNormal, |
| 1281 | 1, 1, |
| 1282 | NULL, |
| 1283 | NULL); |
| 1284 | |
| 1285 | if (rcode >= 0) |
Salyzyn, Mark | 06a43d1 | 2008-01-08 12:32:00 -0800 | [diff] [blame] | 1286 | memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo)); |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1287 | if (rcode == -ERESTARTSYS) { |
| 1288 | fibptr = aac_fib_alloc(dev); |
| 1289 | if (!fibptr) |
| 1290 | return -ENOMEM; |
| 1291 | } |
| 1292 | |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 1295 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1296 | /* |
| 1297 | * GetBusInfo |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 1298 | */ |
| 1299 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1300 | aac_fib_init(fibptr); |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 1301 | |
| 1302 | bus_info = (struct aac_bus_info_response *) fib_data(fibptr); |
| 1303 | |
| 1304 | memset(bus_info, 0, sizeof(*bus_info)); |
| 1305 | |
| 1306 | command = (struct aac_bus_info *)bus_info; |
| 1307 | |
| 1308 | command->Command = cpu_to_le32(VM_Ioctl); |
| 1309 | command->ObjType = cpu_to_le32(FT_DRIVE); |
| 1310 | command->MethodId = cpu_to_le32(1); |
| 1311 | command->CtlCmd = cpu_to_le32(GetBusInfo); |
| 1312 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1313 | rcode = aac_fib_send(ContainerCommand, |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 1314 | fibptr, |
| 1315 | sizeof (*bus_info), |
| 1316 | FsaNormal, |
| 1317 | 1, 1, |
| 1318 | NULL, NULL); |
| 1319 | |
Salyzyn, Mark | 94cf6ba | 2007-12-13 16:14:18 -0800 | [diff] [blame] | 1320 | /* reasoned default */ |
| 1321 | dev->maximum_num_physicals = 16; |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 1322 | if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) { |
| 1323 | dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus); |
| 1324 | dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount); |
| 1325 | } |
| 1326 | |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1327 | if (!dev->in_reset) { |
Salyzyn, Mark | 24f02e1 | 2007-06-19 16:29:24 -0400 | [diff] [blame] | 1328 | char buffer[16]; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1329 | tmp = le32_to_cpu(dev->adapter_info.kernelrev); |
| 1330 | printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n", |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1331 | dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | dev->id, |
| 1333 | tmp>>24, |
| 1334 | (tmp>>16)&0xff, |
| 1335 | tmp&0xff, |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1336 | le32_to_cpu(dev->adapter_info.kernelbuild), |
| 1337 | (int)sizeof(dev->supplement_adapter_info.BuildDate), |
| 1338 | dev->supplement_adapter_info.BuildDate); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1339 | tmp = le32_to_cpu(dev->adapter_info.monitorrev); |
| 1340 | printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | dev->name, dev->id, |
| 1342 | tmp>>24,(tmp>>16)&0xff,tmp&0xff, |
| 1343 | le32_to_cpu(dev->adapter_info.monitorbuild)); |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1344 | tmp = le32_to_cpu(dev->adapter_info.biosrev); |
| 1345 | printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | dev->name, dev->id, |
| 1347 | tmp>>24,(tmp>>16)&0xff,tmp&0xff, |
| 1348 | le32_to_cpu(dev->adapter_info.biosbuild)); |
Salyzyn, Mark | 24f02e1 | 2007-06-19 16:29:24 -0400 | [diff] [blame] | 1349 | buffer[0] = '\0'; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 1350 | if (aac_get_serial_number( |
Salyzyn, Mark | 24f02e1 | 2007-06-19 16:29:24 -0400 | [diff] [blame] | 1351 | shost_to_class(dev->scsi_host_ptr), buffer)) |
| 1352 | printk(KERN_INFO "%s%d: serial %s", |
| 1353 | dev->name, dev->id, buffer); |
Salyzyn, Mark | a45c863 | 2007-03-28 13:44:54 -0400 | [diff] [blame] | 1354 | if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) { |
| 1355 | printk(KERN_INFO "%s%d: TSID %.*s\n", |
| 1356 | dev->name, dev->id, |
| 1357 | (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid), |
| 1358 | dev->supplement_adapter_info.VpdInfo.Tsid); |
| 1359 | } |
Salyzyn, Mark | 2f7ecc5 | 2008-02-08 08:36:23 -0800 | [diff] [blame] | 1360 | if (!aac_check_reset || ((aac_check_reset == 1) && |
Salyzyn, Mark | a3940da | 2008-01-08 12:48:25 -0800 | [diff] [blame] | 1361 | (dev->supplement_adapter_info.SupportedOptions2 & |
| 1362 | AAC_OPTION_IGNORE_RESET))) { |
Salyzyn, Mark | 29c9768 | 2007-06-12 09:33:54 -0400 | [diff] [blame] | 1363 | printk(KERN_INFO "%s%d: Reset Adapter Ignored\n", |
| 1364 | dev->name, dev->id); |
| 1365 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 1368 | dev->cache_protected = 0; |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 1369 | dev->jbod = ((dev->supplement_adapter_info.FeatureBits & |
| 1370 | AAC_FEATURE_JBOD) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | dev->nondasd_support = 0; |
| 1372 | dev->raid_scsi_mode = 0; |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 1373 | if(dev->adapter_info.options & AAC_OPT_NONDASD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | dev->nondasd_support = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
| 1376 | /* |
| 1377 | * If the firmware supports ROMB RAID/SCSI mode and we are currently |
| 1378 | * in RAID/SCSI mode, set the flag. For now if in this mode we will |
| 1379 | * force nondasd support on. If we decide to allow the non-dasd flag |
| 1380 | * additional changes changes will have to be made to support |
| 1381 | * RAID/SCSI. the function aac_scsi_cmd in this module will have to be |
| 1382 | * changed to support the new dev->raid_scsi_mode flag instead of |
| 1383 | * leaching off of the dev->nondasd_support flag. Also in linit.c the |
| 1384 | * function aac_detect will have to be modified where it sets up the |
| 1385 | * max number of channels based on the aac->nondasd_support flag only. |
| 1386 | */ |
| 1387 | if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) && |
| 1388 | (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) { |
| 1389 | dev->nondasd_support = 1; |
| 1390 | dev->raid_scsi_mode = 1; |
| 1391 | } |
| 1392 | if (dev->raid_scsi_mode != 0) |
| 1393 | printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n", |
| 1394 | dev->name, dev->id); |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1395 | |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 1396 | if (nondasd != -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | dev->nondasd_support = (nondasd!=0); |
Salyzyn, Mark | 2f7ecc5 | 2008-02-08 08:36:23 -0800 | [diff] [blame] | 1398 | if (dev->nondasd_support && !dev->in_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 1401 | if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32)) |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 1402 | dev->needs_dac = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | dev->dac_support = 0; |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 1404 | if ((sizeof(dma_addr_t) > 4) && dev->needs_dac && |
| 1405 | (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) { |
Salyzyn, Mark | 2f7ecc5 | 2008-02-08 08:36:23 -0800 | [diff] [blame] | 1406 | if (!dev->in_reset) |
| 1407 | printk(KERN_INFO "%s%d: 64bit support enabled.\n", |
| 1408 | dev->name, dev->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | dev->dac_support = 1; |
| 1410 | } |
| 1411 | |
| 1412 | if(dacmode != -1) { |
| 1413 | dev->dac_support = (dacmode!=0); |
| 1414 | } |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 1415 | |
| 1416 | /* avoid problems with AAC_QUIRK_SCSI_32 controllers */ |
| 1417 | if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks |
| 1418 | & AAC_QUIRK_SCSI_32)) { |
| 1419 | dev->nondasd_support = 0; |
| 1420 | dev->jbod = 0; |
| 1421 | expose_physicals = 0; |
| 1422 | } |
| 1423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | if(dev->dac_support != 0) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 1425 | if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64)) && |
| 1426 | !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(64))) { |
Salyzyn, Mark | 2f7ecc5 | 2008-02-08 08:36:23 -0800 | [diff] [blame] | 1427 | if (!dev->in_reset) |
| 1428 | printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n", |
| 1429 | dev->name, dev->id); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1430 | } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32)) && |
| 1431 | !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n", |
| 1433 | dev->name, dev->id); |
| 1434 | dev->dac_support = 0; |
| 1435 | } else { |
| 1436 | printk(KERN_WARNING"%s%d: No suitable DMA available.\n", |
| 1437 | dev->name, dev->id); |
| 1438 | rcode = -ENOMEM; |
| 1439 | } |
| 1440 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1441 | /* |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1442 | * Deal with configuring for the individualized limits of each packet |
| 1443 | * interface. |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1444 | */ |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1445 | dev->a_ops.adapter_scsi = (dev->dac_support) |
Salyzyn, Mark | 94cf6ba | 2007-12-13 16:14:18 -0800 | [diff] [blame] | 1446 | ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32) |
| 1447 | ? aac_scsi_32_64 |
| 1448 | : aac_scsi_64) |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1449 | : aac_scsi_32; |
| 1450 | if (dev->raw_io_interface) { |
| 1451 | dev->a_ops.adapter_bounds = (dev->raw_io_64) |
| 1452 | ? aac_bounds_64 |
| 1453 | : aac_bounds_32; |
| 1454 | dev->a_ops.adapter_read = aac_read_raw_io; |
| 1455 | dev->a_ops.adapter_write = aac_write_raw_io; |
| 1456 | } else { |
| 1457 | dev->a_ops.adapter_bounds = aac_bounds_32; |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 1458 | dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1459 | sizeof(struct aac_fibhdr) - |
Mark Haverkamp | 63a70ee | 2005-09-20 12:57:04 -0700 | [diff] [blame] | 1460 | sizeof(struct aac_write) + sizeof(struct sgentry)) / |
| 1461 | sizeof(struct sgentry); |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 1462 | if (dev->dac_support) { |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1463 | dev->a_ops.adapter_read = aac_read_block64; |
| 1464 | dev->a_ops.adapter_write = aac_write_block64; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1465 | /* |
| 1466 | * 38 scatter gather elements |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 1467 | */ |
| 1468 | dev->scsi_host_ptr->sg_tablesize = |
| 1469 | (dev->max_fib_size - |
| 1470 | sizeof(struct aac_fibhdr) - |
| 1471 | sizeof(struct aac_write64) + |
Mark Haverkamp | 63a70ee | 2005-09-20 12:57:04 -0700 | [diff] [blame] | 1472 | sizeof(struct sgentry64)) / |
| 1473 | sizeof(struct sgentry64); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1474 | } else { |
| 1475 | dev->a_ops.adapter_read = aac_read_block; |
| 1476 | dev->a_ops.adapter_write = aac_write_block; |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 1477 | } |
| 1478 | dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT; |
| 1479 | if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) { |
| 1480 | /* |
| 1481 | * Worst case size that could cause sg overflow when |
| 1482 | * we break up SG elements that are larger than 64KB. |
| 1483 | * Would be nice if we could tell the SCSI layer what |
| 1484 | * the maximum SG element size can be. Worst case is |
| 1485 | * (sg_tablesize-1) 4KB elements with one 64KB |
| 1486 | * element. |
| 1487 | * 32bit -> 468 or 238KB 64bit -> 424 or 212KB |
| 1488 | */ |
| 1489 | dev->scsi_host_ptr->max_sectors = |
| 1490 | (dev->scsi_host_ptr->sg_tablesize * 8) + 112; |
| 1491 | } |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1492 | } |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1493 | /* FIB should be freed only after getting the response from the F/W */ |
| 1494 | if (rcode != -ERESTARTSYS) { |
| 1495 | aac_fib_complete(fibptr); |
| 1496 | aac_fib_free(fibptr); |
| 1497 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | |
| 1499 | return rcode; |
| 1500 | } |
| 1501 | |
| 1502 | |
Mark Haverkamp | e53cb35 | 2005-08-03 15:39:09 -0700 | [diff] [blame] | 1503 | static void io_callback(void *context, struct fib * fibptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | { |
| 1505 | struct aac_dev *dev; |
| 1506 | struct aac_read_reply *readreply; |
| 1507 | struct scsi_cmnd *scsicmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | u32 cid; |
| 1509 | |
| 1510 | scsicmd = (struct scsi_cmnd *) context; |
| 1511 | |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 1512 | if (!aac_valid_context(scsicmd, fibptr)) |
| 1513 | return; |
| 1514 | |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 1515 | dev = fibptr->dev; |
Mark Haverkamp | e571877 | 2006-03-27 09:43:25 -0800 | [diff] [blame] | 1516 | cid = scmd_id(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1518 | if (nblank(dprintk(x))) { |
| 1519 | u64 lba; |
| 1520 | switch (scsicmd->cmnd[0]) { |
| 1521 | case WRITE_6: |
| 1522 | case READ_6: |
| 1523 | lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | |
| 1524 | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; |
| 1525 | break; |
| 1526 | case WRITE_16: |
| 1527 | case READ_16: |
| 1528 | lba = ((u64)scsicmd->cmnd[2] << 56) | |
| 1529 | ((u64)scsicmd->cmnd[3] << 48) | |
| 1530 | ((u64)scsicmd->cmnd[4] << 40) | |
| 1531 | ((u64)scsicmd->cmnd[5] << 32) | |
| 1532 | ((u64)scsicmd->cmnd[6] << 24) | |
| 1533 | (scsicmd->cmnd[7] << 16) | |
| 1534 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; |
| 1535 | break; |
| 1536 | case WRITE_12: |
| 1537 | case READ_12: |
| 1538 | lba = ((u64)scsicmd->cmnd[2] << 24) | |
| 1539 | (scsicmd->cmnd[3] << 16) | |
| 1540 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; |
| 1541 | break; |
| 1542 | default: |
| 1543 | lba = ((u64)scsicmd->cmnd[2] << 24) | |
| 1544 | (scsicmd->cmnd[3] << 16) | |
| 1545 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; |
| 1546 | break; |
| 1547 | } |
| 1548 | printk(KERN_DEBUG |
| 1549 | "io_callback[cpu %d]: lba = %llu, t = %ld.\n", |
| 1550 | smp_processor_id(), (unsigned long long)lba, jiffies); |
| 1551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 1553 | BUG_ON(fibptr == NULL); |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 1554 | |
| 1555 | scsi_dma_unmap(scsicmd); |
| 1556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | readreply = (struct aac_read_reply *)fib_data(fibptr); |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 1558 | switch (le32_to_cpu(readreply->status)) { |
| 1559 | case ST_OK: |
| 1560 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | |
| 1561 | SAM_STAT_GOOD; |
| 1562 | dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE; |
| 1563 | break; |
| 1564 | case ST_NOT_READY: |
| 1565 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | |
| 1566 | SAM_STAT_CHECK_CONDITION; |
| 1567 | set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY, |
| 1568 | SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0); |
| 1569 | memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, |
| 1570 | min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), |
| 1571 | SCSI_SENSE_BUFFERSIZE)); |
| 1572 | break; |
| 1573 | default: |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1574 | #ifdef AAC_DETAILED_STATUS_INFO |
Mark Haverkamp | e53cb35 | 2005-08-03 15:39:09 -0700 | [diff] [blame] | 1575 | printk(KERN_WARNING "io_callback: io failed, status = %d\n", |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1576 | le32_to_cpu(readreply->status)); |
| 1577 | #endif |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 1578 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | |
| 1579 | SAM_STAT_CHECK_CONDITION; |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 1580 | set_sense(&dev->fsa_dev[cid].sense_data, |
| 1581 | HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE, |
| 1582 | ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, |
Salyzyn, Mark | 3ace426 | 2008-01-14 07:25:33 -0800 | [diff] [blame] | 1584 | min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), |
| 1585 | SCSI_SENSE_BUFFERSIZE)); |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 1586 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | } |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1588 | aac_fib_complete(fibptr); |
| 1589 | aac_fib_free(fibptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 1591 | scsicmd->scsi_done(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1594 | static int aac_read(struct scsi_cmnd * scsicmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | { |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1596 | u64 lba; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | u32 count; |
| 1598 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | struct aac_dev *dev; |
| 1600 | struct fib * cmd_fibcontext; |
| 1601 | |
| 1602 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; |
| 1603 | /* |
| 1604 | * Get block address and transfer length |
| 1605 | */ |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1606 | switch (scsicmd->cmnd[0]) { |
| 1607 | case READ_6: |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1608 | dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1610 | lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1611 | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | count = scsicmd->cmnd[4]; |
| 1613 | |
| 1614 | if (count == 0) |
| 1615 | count = 256; |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1616 | break; |
| 1617 | case READ_16: |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1618 | dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd))); |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1619 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1620 | lba = ((u64)scsicmd->cmnd[2] << 56) | |
| 1621 | ((u64)scsicmd->cmnd[3] << 48) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1622 | ((u64)scsicmd->cmnd[4] << 40) | |
| 1623 | ((u64)scsicmd->cmnd[5] << 32) | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1624 | ((u64)scsicmd->cmnd[6] << 24) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1625 | (scsicmd->cmnd[7] << 16) | |
| 1626 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1627 | count = (scsicmd->cmnd[10] << 24) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1628 | (scsicmd->cmnd[11] << 16) | |
| 1629 | (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13]; |
| 1630 | break; |
| 1631 | case READ_12: |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1632 | dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd))); |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1633 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1634 | lba = ((u64)scsicmd->cmnd[2] << 24) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1635 | (scsicmd->cmnd[3] << 16) | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1636 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; |
| 1637 | count = (scsicmd->cmnd[6] << 24) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1638 | (scsicmd->cmnd[7] << 16) | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1639 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1640 | break; |
| 1641 | default: |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1642 | dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1644 | lba = ((u64)scsicmd->cmnd[2] << 24) | |
| 1645 | (scsicmd->cmnd[3] << 16) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1646 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1648 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | } |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1650 | dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n", |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1651 | smp_processor_id(), (unsigned long long)lba, jiffies)); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1652 | if (aac_adapter_bounds(dev,scsicmd,lba)) |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1653 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | /* |
| 1655 | * Alocate and initialize a Fib |
| 1656 | */ |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1657 | if (!(cmd_fibcontext = aac_fib_alloc(dev))) { |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1658 | printk(KERN_WARNING "aac_read: fib allocation failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | return -1; |
| 1660 | } |
| 1661 | |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1662 | status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
| 1664 | /* |
| 1665 | * Check that the command queued to the controller |
| 1666 | */ |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 1667 | if (status == -EINPROGRESS) { |
| 1668 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | return 0; |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 1670 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1671 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1672 | printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | /* |
| 1674 | * For some reason, the Fib didn't queue, return QUEUE_FULL |
| 1675 | */ |
| 1676 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL; |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 1677 | scsicmd->scsi_done(scsicmd); |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1678 | aac_fib_complete(cmd_fibcontext); |
| 1679 | aac_fib_free(cmd_fibcontext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | return 0; |
| 1681 | } |
| 1682 | |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1683 | static int aac_write(struct scsi_cmnd * scsicmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | { |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1685 | u64 lba; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | u32 count; |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1687 | int fua; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | struct aac_dev *dev; |
| 1690 | struct fib * cmd_fibcontext; |
| 1691 | |
| 1692 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; |
| 1693 | /* |
| 1694 | * Get block address and transfer length |
| 1695 | */ |
| 1696 | if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */ |
| 1697 | { |
| 1698 | lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; |
| 1699 | count = scsicmd->cmnd[4]; |
| 1700 | if (count == 0) |
| 1701 | count = 256; |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1702 | fua = 0; |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1703 | } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */ |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1704 | dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd))); |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1705 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1706 | lba = ((u64)scsicmd->cmnd[2] << 56) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1707 | ((u64)scsicmd->cmnd[3] << 48) | |
| 1708 | ((u64)scsicmd->cmnd[4] << 40) | |
| 1709 | ((u64)scsicmd->cmnd[5] << 32) | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 1710 | ((u64)scsicmd->cmnd[6] << 24) | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1711 | (scsicmd->cmnd[7] << 16) | |
| 1712 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; |
| 1713 | count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) | |
| 1714 | (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13]; |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1715 | fua = scsicmd->cmnd[1] & 0x8; |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1716 | } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */ |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1717 | dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd))); |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1718 | |
| 1719 | lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
| 1720 | | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; |
| 1721 | count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16) |
| 1722 | | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1723 | fua = scsicmd->cmnd[1] & 0x8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | } else { |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1725 | dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd))); |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1726 | lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1728 | fua = scsicmd->cmnd[1] & 0x8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | } |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1730 | dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | smp_processor_id(), (unsigned long long)lba, jiffies)); |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 1732 | if (aac_adapter_bounds(dev,scsicmd,lba)) |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 1733 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | /* |
| 1735 | * Allocate and initialize a Fib then setup a BlockWrite command |
| 1736 | */ |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1737 | if (!(cmd_fibcontext = aac_fib_alloc(dev))) { |
Penchala Narasimha Reddy Chilakala, ERS-HCLTech | cacb6dc | 2009-12-21 18:39:27 +0530 | [diff] [blame] | 1738 | /* FIB temporarily unavailable,not catastrophic failure */ |
| 1739 | |
| 1740 | /* scsicmd->result = DID_ERROR << 16; |
| 1741 | * scsicmd->scsi_done(scsicmd); |
| 1742 | * return 0; |
| 1743 | */ |
| 1744 | printk(KERN_WARNING "aac_write: fib allocation failed\n"); |
| 1745 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 1748 | status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
| 1750 | /* |
| 1751 | * Check that the command queued to the controller |
| 1752 | */ |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 1753 | if (status == -EINPROGRESS) { |
| 1754 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | return 0; |
| 1756 | } |
| 1757 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1758 | printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | /* |
| 1760 | * For some reason, the Fib didn't queue, return QUEUE_FULL |
| 1761 | */ |
| 1762 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL; |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 1763 | scsicmd->scsi_done(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1765 | aac_fib_complete(cmd_fibcontext); |
| 1766 | aac_fib_free(cmd_fibcontext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | return 0; |
| 1768 | } |
| 1769 | |
| 1770 | static void synchronize_callback(void *context, struct fib *fibptr) |
| 1771 | { |
| 1772 | struct aac_synchronize_reply *synchronizereply; |
| 1773 | struct scsi_cmnd *cmd; |
| 1774 | |
| 1775 | cmd = context; |
| 1776 | |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 1777 | if (!aac_valid_context(cmd, fibptr)) |
| 1778 | return; |
| 1779 | |
Salyzyn, Mark | b90f90d | 2007-07-27 09:48:49 -0400 | [diff] [blame] | 1780 | dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | smp_processor_id(), jiffies)); |
| 1782 | BUG_ON(fibptr == NULL); |
| 1783 | |
| 1784 | |
| 1785 | synchronizereply = fib_data(fibptr); |
| 1786 | if (le32_to_cpu(synchronizereply->status) == CT_OK) |
Salyzyn, Mark | b90f90d | 2007-07-27 09:48:49 -0400 | [diff] [blame] | 1787 | cmd->result = DID_OK << 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 1789 | else { |
| 1790 | struct scsi_device *sdev = cmd->device; |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 1791 | struct aac_dev *dev = fibptr->dev; |
Mark Haverkamp | e571877 | 2006-03-27 09:43:25 -0800 | [diff] [blame] | 1792 | u32 cid = sdev_id(sdev); |
Salyzyn, Mark | b90f90d | 2007-07-27 09:48:49 -0400 | [diff] [blame] | 1793 | printk(KERN_WARNING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | "synchronize_callback: synchronize failed, status = %d\n", |
| 1795 | le32_to_cpu(synchronizereply->status)); |
Salyzyn, Mark | b90f90d | 2007-07-27 09:48:49 -0400 | [diff] [blame] | 1796 | cmd->result = DID_OK << 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 1798 | set_sense(&dev->fsa_dev[cid].sense_data, |
| 1799 | HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE, |
| 1800 | ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, |
FUJITA Tomonori | b80ca4f | 2008-01-13 15:46:13 +0900 | [diff] [blame] | 1802 | min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), |
| 1803 | SCSI_SENSE_BUFFERSIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1806 | aac_fib_complete(fibptr); |
| 1807 | aac_fib_free(fibptr); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 1808 | cmd->scsi_done(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1811 | static int aac_synchronize(struct scsi_cmnd *scsicmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | { |
| 1813 | int status; |
| 1814 | struct fib *cmd_fibcontext; |
| 1815 | struct aac_synchronize *synchronizecmd; |
| 1816 | struct scsi_cmnd *cmd; |
| 1817 | struct scsi_device *sdev = scsicmd->device; |
| 1818 | int active = 0; |
Mark Haverkamp | 90ee346 | 2006-08-03 08:03:07 -0700 | [diff] [blame] | 1819 | struct aac_dev *aac; |
Salyzyn, Mark | b90f90d | 2007-07-27 09:48:49 -0400 | [diff] [blame] | 1820 | u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | |
| 1821 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; |
| 1822 | u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | unsigned long flags; |
| 1824 | |
| 1825 | /* |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 1826 | * Wait for all outstanding queued commands to complete to this |
| 1827 | * specific target (block). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | */ |
| 1829 | spin_lock_irqsave(&sdev->list_lock, flags); |
| 1830 | list_for_each_entry(cmd, &sdev->cmd_list, list) |
Salyzyn, Mark | b90f90d | 2007-07-27 09:48:49 -0400 | [diff] [blame] | 1831 | if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) { |
| 1832 | u64 cmnd_lba; |
| 1833 | u32 cmnd_count; |
| 1834 | |
| 1835 | if (cmd->cmnd[0] == WRITE_6) { |
| 1836 | cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) | |
| 1837 | (cmd->cmnd[2] << 8) | |
| 1838 | cmd->cmnd[3]; |
| 1839 | cmnd_count = cmd->cmnd[4]; |
| 1840 | if (cmnd_count == 0) |
| 1841 | cmnd_count = 256; |
| 1842 | } else if (cmd->cmnd[0] == WRITE_16) { |
| 1843 | cmnd_lba = ((u64)cmd->cmnd[2] << 56) | |
| 1844 | ((u64)cmd->cmnd[3] << 48) | |
| 1845 | ((u64)cmd->cmnd[4] << 40) | |
| 1846 | ((u64)cmd->cmnd[5] << 32) | |
| 1847 | ((u64)cmd->cmnd[6] << 24) | |
| 1848 | (cmd->cmnd[7] << 16) | |
| 1849 | (cmd->cmnd[8] << 8) | |
| 1850 | cmd->cmnd[9]; |
| 1851 | cmnd_count = (cmd->cmnd[10] << 24) | |
| 1852 | (cmd->cmnd[11] << 16) | |
| 1853 | (cmd->cmnd[12] << 8) | |
| 1854 | cmd->cmnd[13]; |
| 1855 | } else if (cmd->cmnd[0] == WRITE_12) { |
| 1856 | cmnd_lba = ((u64)cmd->cmnd[2] << 24) | |
| 1857 | (cmd->cmnd[3] << 16) | |
| 1858 | (cmd->cmnd[4] << 8) | |
| 1859 | cmd->cmnd[5]; |
| 1860 | cmnd_count = (cmd->cmnd[6] << 24) | |
| 1861 | (cmd->cmnd[7] << 16) | |
| 1862 | (cmd->cmnd[8] << 8) | |
| 1863 | cmd->cmnd[9]; |
| 1864 | } else if (cmd->cmnd[0] == WRITE_10) { |
| 1865 | cmnd_lba = ((u64)cmd->cmnd[2] << 24) | |
| 1866 | (cmd->cmnd[3] << 16) | |
| 1867 | (cmd->cmnd[4] << 8) | |
| 1868 | cmd->cmnd[5]; |
| 1869 | cmnd_count = (cmd->cmnd[7] << 8) | |
| 1870 | cmd->cmnd[8]; |
| 1871 | } else |
| 1872 | continue; |
| 1873 | if (((cmnd_lba + cmnd_count) < lba) || |
| 1874 | (count && ((lba + count) < cmnd_lba))) |
| 1875 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | ++active; |
| 1877 | break; |
| 1878 | } |
| 1879 | |
| 1880 | spin_unlock_irqrestore(&sdev->list_lock, flags); |
| 1881 | |
| 1882 | /* |
| 1883 | * Yield the processor (requeue for later) |
| 1884 | */ |
| 1885 | if (active) |
| 1886 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 1887 | |
Salyzyn, Mark | f858317 | 2007-10-30 15:50:49 -0400 | [diff] [blame] | 1888 | aac = (struct aac_dev *)sdev->host->hostdata; |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 1889 | if (aac->in_reset) |
| 1890 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | /* |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 1893 | * Allocate and initialize a Fib |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | */ |
Mark Haverkamp | 90ee346 | 2006-08-03 08:03:07 -0700 | [diff] [blame] | 1895 | if (!(cmd_fibcontext = aac_fib_alloc(aac))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1897 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1898 | aac_fib_init(cmd_fibcontext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
| 1900 | synchronizecmd = fib_data(cmd_fibcontext); |
| 1901 | synchronizecmd->command = cpu_to_le32(VM_ContainerConfig); |
| 1902 | synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE); |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 1903 | synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd)); |
Salyzyn, Mark | b90f90d | 2007-07-27 09:48:49 -0400 | [diff] [blame] | 1904 | synchronizecmd->count = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data)); |
| 1906 | |
| 1907 | /* |
| 1908 | * Now send the Fib to the adapter |
| 1909 | */ |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1910 | status = aac_fib_send(ContainerCommand, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | cmd_fibcontext, |
| 1912 | sizeof(struct aac_synchronize), |
| 1913 | FsaNormal, |
| 1914 | 0, 1, |
| 1915 | (fib_callback)synchronize_callback, |
| 1916 | (void *)scsicmd); |
| 1917 | |
| 1918 | /* |
| 1919 | * Check that the command queued to the controller |
| 1920 | */ |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 1921 | if (status == -EINPROGRESS) { |
| 1922 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | return 0; |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 1924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | |
Salyzyn, Mark | b90f90d | 2007-07-27 09:48:49 -0400 | [diff] [blame] | 1926 | printk(KERN_WARNING |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 1927 | "aac_synchronize: aac_fib_send failed with status: %d.\n", status); |
| 1928 | aac_fib_complete(cmd_fibcontext); |
| 1929 | aac_fib_free(cmd_fibcontext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1931 | } |
| 1932 | |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 1933 | static void aac_start_stop_callback(void *context, struct fib *fibptr) |
| 1934 | { |
| 1935 | struct scsi_cmnd *scsicmd = context; |
| 1936 | |
| 1937 | if (!aac_valid_context(scsicmd, fibptr)) |
| 1938 | return; |
| 1939 | |
| 1940 | BUG_ON(fibptr == NULL); |
| 1941 | |
| 1942 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 1943 | |
| 1944 | aac_fib_complete(fibptr); |
| 1945 | aac_fib_free(fibptr); |
| 1946 | scsicmd->scsi_done(scsicmd); |
| 1947 | } |
| 1948 | |
| 1949 | static int aac_start_stop(struct scsi_cmnd *scsicmd) |
| 1950 | { |
| 1951 | int status; |
| 1952 | struct fib *cmd_fibcontext; |
| 1953 | struct aac_power_management *pmcmd; |
| 1954 | struct scsi_device *sdev = scsicmd->device; |
| 1955 | struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata; |
| 1956 | |
| 1957 | if (!(aac->supplement_adapter_info.SupportedOptions2 & |
| 1958 | AAC_OPTION_POWER_MANAGEMENT)) { |
| 1959 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | |
| 1960 | SAM_STAT_GOOD; |
| 1961 | scsicmd->scsi_done(scsicmd); |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
| 1965 | if (aac->in_reset) |
| 1966 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1967 | |
| 1968 | /* |
| 1969 | * Allocate and initialize a Fib |
| 1970 | */ |
| 1971 | cmd_fibcontext = aac_fib_alloc(aac); |
| 1972 | if (!cmd_fibcontext) |
| 1973 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1974 | |
| 1975 | aac_fib_init(cmd_fibcontext); |
| 1976 | |
| 1977 | pmcmd = fib_data(cmd_fibcontext); |
| 1978 | pmcmd->command = cpu_to_le32(VM_ContainerConfig); |
| 1979 | pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT); |
| 1980 | /* Eject bit ignored, not relevant */ |
| 1981 | pmcmd->sub = (scsicmd->cmnd[4] & 1) ? |
| 1982 | cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT); |
| 1983 | pmcmd->cid = cpu_to_le32(sdev_id(sdev)); |
| 1984 | pmcmd->parm = (scsicmd->cmnd[1] & 1) ? |
| 1985 | cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0; |
| 1986 | |
| 1987 | /* |
| 1988 | * Now send the Fib to the adapter |
| 1989 | */ |
| 1990 | status = aac_fib_send(ContainerCommand, |
| 1991 | cmd_fibcontext, |
| 1992 | sizeof(struct aac_power_management), |
| 1993 | FsaNormal, |
| 1994 | 0, 1, |
| 1995 | (fib_callback)aac_start_stop_callback, |
| 1996 | (void *)scsicmd); |
| 1997 | |
| 1998 | /* |
| 1999 | * Check that the command queued to the controller |
| 2000 | */ |
| 2001 | if (status == -EINPROGRESS) { |
| 2002 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
| 2003 | return 0; |
| 2004 | } |
| 2005 | |
| 2006 | aac_fib_complete(cmd_fibcontext); |
| 2007 | aac_fib_free(cmd_fibcontext); |
| 2008 | return SCSI_MLQUEUE_HOST_BUSY; |
| 2009 | } |
| 2010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | /** |
| 2012 | * aac_scsi_cmd() - Process SCSI command |
| 2013 | * @scsicmd: SCSI command block |
| 2014 | * |
| 2015 | * Emulate a SCSI command and queue the required request for the |
| 2016 | * aacraid firmware. |
| 2017 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | int aac_scsi_cmd(struct scsi_cmnd * scsicmd) |
| 2020 | { |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 2021 | u32 cid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | struct Scsi_Host *host = scsicmd->device->host; |
| 2023 | struct aac_dev *dev = (struct aac_dev *)host->hostdata; |
| 2024 | struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2025 | |
Mark Haverkamp | 90ee346 | 2006-08-03 08:03:07 -0700 | [diff] [blame] | 2026 | if (fsa_dev_ptr == NULL) |
| 2027 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | /* |
| 2029 | * If the bus, id or lun is out of range, return fail |
| 2030 | * Test does not apply to ID 16, the pseudo id for the controller |
| 2031 | * itself. |
| 2032 | */ |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 2033 | cid = scmd_id(scsicmd); |
| 2034 | if (cid != host->this_id) { |
| 2035 | if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) { |
| 2036 | if((cid >= dev->maximum_num_containers) || |
Mark Haverkamp | e571877 | 2006-03-27 09:43:25 -0800 | [diff] [blame] | 2037 | (scsicmd->device->lun != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | scsicmd->result = DID_NO_CONNECT << 16; |
| 2039 | scsicmd->scsi_done(scsicmd); |
| 2040 | return 0; |
| 2041 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | |
| 2043 | /* |
| 2044 | * If the target container doesn't exist, it may have |
| 2045 | * been newly created |
| 2046 | */ |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 2047 | if (((fsa_dev_ptr[cid].valid & 1) == 0) || |
| 2048 | (fsa_dev_ptr[cid].sense_data.sense_key == |
| 2049 | NOT_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | switch (scsicmd->cmnd[0]) { |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2051 | case SERVICE_ACTION_IN: |
| 2052 | if (!(dev->raw_io_interface) || |
| 2053 | !(dev->raw_io_64) || |
| 2054 | ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) |
| 2055 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | case INQUIRY: |
| 2057 | case READ_CAPACITY: |
| 2058 | case TEST_UNIT_READY: |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 2059 | if (dev->in_reset) |
| 2060 | return -1; |
Mark Haverkamp | fe76df4 | 2007-03-15 12:55:07 -0700 | [diff] [blame] | 2061 | return _aac_probe_container(scsicmd, |
| 2062 | aac_probe_container_callback2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | default: |
| 2064 | break; |
| 2065 | } |
| 2066 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | } else { /* check for physical non-dasd devices */ |
Salyzyn, Mark | cb1042f | 2008-01-17 09:25:07 -0800 | [diff] [blame] | 2068 | if (dev->nondasd_support || expose_physicals || |
| 2069 | dev->jbod) { |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 2070 | if (dev->in_reset) |
| 2071 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | return aac_send_srb_fib(scsicmd); |
| 2073 | } else { |
| 2074 | scsicmd->result = DID_NO_CONNECT << 16; |
| 2075 | scsicmd->scsi_done(scsicmd); |
| 2076 | return 0; |
| 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | /* |
| 2081 | * else Command for the controller itself |
| 2082 | */ |
| 2083 | else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2084 | (scsicmd->cmnd[0] != TEST_UNIT_READY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | { |
| 2086 | dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0])); |
| 2087 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 2088 | set_sense(&dev->fsa_dev[cid].sense_data, |
| 2089 | ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND, |
| 2090 | ASENCODE_INVALID_COMMAND, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, |
Salyzyn, Mark | 3ace426 | 2008-01-14 07:25:33 -0800 | [diff] [blame] | 2092 | min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), |
| 2093 | SCSI_SENSE_BUFFERSIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | scsicmd->scsi_done(scsicmd); |
| 2095 | return 0; |
| 2096 | } |
| 2097 | |
| 2098 | |
| 2099 | /* Handle commands here that don't really require going out to the adapter */ |
| 2100 | switch (scsicmd->cmnd[0]) { |
| 2101 | case INQUIRY: |
| 2102 | { |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2103 | struct inquiry_data inq_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 2105 | dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid)); |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2106 | memset(&inq_data, 0, sizeof (struct inquiry_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 2108 | if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) { |
Salyzyn, Mark | 88e2f98 | 2007-07-17 14:01:28 -0400 | [diff] [blame] | 2109 | char *arr = (char *)&inq_data; |
| 2110 | |
| 2111 | /* EVPD bit set */ |
| 2112 | arr[0] = (scmd_id(scsicmd) == host->this_id) ? |
| 2113 | INQD_PDT_PROC : INQD_PDT_DA; |
| 2114 | if (scsicmd->cmnd[2] == 0) { |
| 2115 | /* supported vital product data pages */ |
| 2116 | arr[3] = 2; |
| 2117 | arr[4] = 0x0; |
| 2118 | arr[5] = 0x80; |
| 2119 | arr[1] = scsicmd->cmnd[2]; |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 2120 | scsi_sg_copy_from_buffer(scsicmd, &inq_data, |
| 2121 | sizeof(inq_data)); |
Salyzyn, Mark | 88e2f98 | 2007-07-17 14:01:28 -0400 | [diff] [blame] | 2122 | scsicmd->result = DID_OK << 16 | |
| 2123 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2124 | } else if (scsicmd->cmnd[2] == 0x80) { |
| 2125 | /* unit serial number page */ |
| 2126 | arr[3] = setinqserial(dev, &arr[4], |
| 2127 | scmd_id(scsicmd)); |
| 2128 | arr[1] = scsicmd->cmnd[2]; |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 2129 | scsi_sg_copy_from_buffer(scsicmd, &inq_data, |
| 2130 | sizeof(inq_data)); |
Leubner, Achim | d8e96507 | 2009-04-01 07:16:08 -0700 | [diff] [blame] | 2131 | if (aac_wwn != 2) |
| 2132 | return aac_get_container_serial( |
| 2133 | scsicmd); |
| 2134 | /* SLES 10 SP1 special */ |
| 2135 | scsicmd->result = DID_OK << 16 | |
| 2136 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
Salyzyn, Mark | 88e2f98 | 2007-07-17 14:01:28 -0400 | [diff] [blame] | 2137 | } else { |
| 2138 | /* vpd page not implemented */ |
| 2139 | scsicmd->result = DID_OK << 16 | |
| 2140 | COMMAND_COMPLETE << 8 | |
| 2141 | SAM_STAT_CHECK_CONDITION; |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 2142 | set_sense(&dev->fsa_dev[cid].sense_data, |
| 2143 | ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD, |
| 2144 | ASENCODE_NO_SENSE, 7, 2); |
Salyzyn, Mark | 88e2f98 | 2007-07-17 14:01:28 -0400 | [diff] [blame] | 2145 | memcpy(scsicmd->sense_buffer, |
| 2146 | &dev->fsa_dev[cid].sense_data, |
Salyzyn, Mark | 3ace426 | 2008-01-14 07:25:33 -0800 | [diff] [blame] | 2147 | min_t(size_t, |
| 2148 | sizeof(dev->fsa_dev[cid].sense_data), |
| 2149 | SCSI_SENSE_BUFFERSIZE)); |
Salyzyn, Mark | 88e2f98 | 2007-07-17 14:01:28 -0400 | [diff] [blame] | 2150 | } |
| 2151 | scsicmd->scsi_done(scsicmd); |
| 2152 | return 0; |
| 2153 | } |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2154 | inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */ |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2155 | 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 */ |
| 2156 | inq_data.inqd_len = 31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */ |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2158 | inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | /* |
| 2160 | * Set the Vendor, Product, and Revision Level |
| 2161 | * see: <vendor>.c i.e. aac.c |
| 2162 | */ |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 2163 | if (cid == host->this_id) { |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 2164 | setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types)); |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2165 | inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */ |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 2166 | scsi_sg_copy_from_buffer(scsicmd, &inq_data, |
| 2167 | sizeof(inq_data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2169 | scsicmd->scsi_done(scsicmd); |
| 2170 | return 0; |
| 2171 | } |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 2172 | if (dev->in_reset) |
| 2173 | return -1; |
Mark Haverkamp | 794d060 | 2005-10-24 10:51:53 -0700 | [diff] [blame] | 2174 | setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type); |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2175 | inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */ |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 2176 | scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data)); |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 2177 | return aac_get_container_name(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | } |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2179 | case SERVICE_ACTION_IN: |
| 2180 | if (!(dev->raw_io_interface) || |
| 2181 | !(dev->raw_io_64) || |
| 2182 | ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) |
| 2183 | break; |
| 2184 | { |
| 2185 | u64 capacity; |
Mark Haverkamp | 07ce5eb | 2005-11-08 14:26:33 -0800 | [diff] [blame] | 2186 | char cp[13]; |
FUJITA Tomonori | b271f1c | 2008-02-24 15:25:23 -0800 | [diff] [blame] | 2187 | unsigned int alloc_len; |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2188 | |
| 2189 | dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n")); |
| 2190 | capacity = fsa_dev_ptr[cid].size - 1; |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2191 | cp[0] = (capacity >> 56) & 0xff; |
| 2192 | cp[1] = (capacity >> 48) & 0xff; |
| 2193 | cp[2] = (capacity >> 40) & 0xff; |
| 2194 | cp[3] = (capacity >> 32) & 0xff; |
| 2195 | cp[4] = (capacity >> 24) & 0xff; |
| 2196 | cp[5] = (capacity >> 16) & 0xff; |
| 2197 | cp[6] = (capacity >> 8) & 0xff; |
| 2198 | cp[7] = (capacity >> 0) & 0xff; |
| 2199 | cp[8] = 0; |
| 2200 | cp[9] = 0; |
| 2201 | cp[10] = 2; |
| 2202 | cp[11] = 0; |
Mark Haverkamp | 07ce5eb | 2005-11-08 14:26:33 -0800 | [diff] [blame] | 2203 | cp[12] = 0; |
Mark Haverkamp | 07ce5eb | 2005-11-08 14:26:33 -0800 | [diff] [blame] | 2204 | |
FUJITA Tomonori | b271f1c | 2008-02-24 15:25:23 -0800 | [diff] [blame] | 2205 | alloc_len = ((scsicmd->cmnd[10] << 24) |
| 2206 | + (scsicmd->cmnd[11] << 16) |
| 2207 | + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]); |
| 2208 | |
| 2209 | alloc_len = min_t(size_t, alloc_len, sizeof(cp)); |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 2210 | scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len); |
FUJITA Tomonori | b271f1c | 2008-02-24 15:25:23 -0800 | [diff] [blame] | 2211 | if (alloc_len < scsi_bufflen(scsicmd)) |
| 2212 | scsi_set_resid(scsicmd, |
| 2213 | scsi_bufflen(scsicmd) - alloc_len); |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2214 | |
| 2215 | /* Do not cache partition table for arrays */ |
| 2216 | scsicmd->device->removable = 1; |
| 2217 | |
| 2218 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2219 | scsicmd->scsi_done(scsicmd); |
| 2220 | |
| 2221 | return 0; |
| 2222 | } |
| 2223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | case READ_CAPACITY: |
| 2225 | { |
| 2226 | u32 capacity; |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2227 | char cp[8]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | |
| 2229 | dprintk((KERN_DEBUG "READ CAPACITY command.\n")); |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2230 | if (fsa_dev_ptr[cid].size <= 0x100000000ULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | capacity = fsa_dev_ptr[cid].size - 1; |
| 2232 | else |
| 2233 | capacity = (u32)-1; |
Mark Haverkamp | 3b2946c | 2005-08-15 10:50:24 -0700 | [diff] [blame] | 2234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | cp[0] = (capacity >> 24) & 0xff; |
| 2236 | cp[1] = (capacity >> 16) & 0xff; |
| 2237 | cp[2] = (capacity >> 8) & 0xff; |
| 2238 | cp[3] = (capacity >> 0) & 0xff; |
| 2239 | cp[4] = 0; |
| 2240 | cp[5] = 0; |
| 2241 | cp[6] = 2; |
| 2242 | cp[7] = 0; |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 2243 | scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp)); |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2244 | /* Do not cache partition table for arrays */ |
| 2245 | scsicmd->device->removable = 1; |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 2246 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | |
| 2247 | SAM_STAT_GOOD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | scsicmd->scsi_done(scsicmd); |
| 2249 | |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
| 2253 | case MODE_SENSE: |
| 2254 | { |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2255 | char mode_buf[7]; |
| 2256 | int mode_buf_length = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | |
| 2258 | dprintk((KERN_DEBUG "MODE SENSE command.\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | mode_buf[0] = 3; /* Mode data length */ |
| 2260 | mode_buf[1] = 0; /* Medium type - default */ |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2261 | mode_buf[2] = 0; /* Device-specific param, |
| 2262 | bit 8: 0/1 = write enabled/protected |
| 2263 | bit 4: 0/1 = FUA enabled */ |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 2264 | if (dev->raw_io_interface && ((aac_cache & 5) != 1)) |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2265 | mode_buf[2] = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | mode_buf[3] = 0; /* Block descriptor length */ |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2267 | if (((scsicmd->cmnd[2] & 0x3f) == 8) || |
| 2268 | ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) { |
| 2269 | mode_buf[0] = 6; |
| 2270 | mode_buf[4] = 8; |
| 2271 | mode_buf[5] = 1; |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 2272 | mode_buf[6] = ((aac_cache & 6) == 2) |
| 2273 | ? 0 : 0x04; /* WCE */ |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2274 | mode_buf_length = 7; |
| 2275 | if (mode_buf_length > scsicmd->cmnd[4]) |
| 2276 | mode_buf_length = scsicmd->cmnd[4]; |
| 2277 | } |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 2278 | scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2280 | scsicmd->scsi_done(scsicmd); |
| 2281 | |
| 2282 | return 0; |
| 2283 | } |
| 2284 | case MODE_SENSE_10: |
| 2285 | { |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2286 | char mode_buf[11]; |
| 2287 | int mode_buf_length = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | |
| 2289 | dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | mode_buf[0] = 0; /* Mode data length (MSB) */ |
| 2291 | mode_buf[1] = 6; /* Mode data length (LSB) */ |
| 2292 | mode_buf[2] = 0; /* Medium type - default */ |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2293 | mode_buf[3] = 0; /* Device-specific param, |
| 2294 | bit 8: 0/1 = write enabled/protected |
| 2295 | bit 4: 0/1 = FUA enabled */ |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 2296 | if (dev->raw_io_interface && ((aac_cache & 5) != 1)) |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2297 | mode_buf[3] = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | mode_buf[4] = 0; /* reserved */ |
| 2299 | mode_buf[5] = 0; /* reserved */ |
| 2300 | mode_buf[6] = 0; /* Block descriptor length (MSB) */ |
| 2301 | mode_buf[7] = 0; /* Block descriptor length (LSB) */ |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2302 | if (((scsicmd->cmnd[2] & 0x3f) == 8) || |
| 2303 | ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) { |
| 2304 | mode_buf[1] = 9; |
| 2305 | mode_buf[8] = 8; |
| 2306 | mode_buf[9] = 1; |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 2307 | mode_buf[10] = ((aac_cache & 6) == 2) |
| 2308 | ? 0 : 0x04; /* WCE */ |
Salyzyn, Mark | 9d399cc | 2007-05-18 14:51:34 -0400 | [diff] [blame] | 2309 | mode_buf_length = 11; |
| 2310 | if (mode_buf_length > scsicmd->cmnd[8]) |
| 2311 | mode_buf_length = scsicmd->cmnd[8]; |
| 2312 | } |
FUJITA Tomonori | d434502 | 2008-03-09 13:44:34 +0900 | [diff] [blame] | 2313 | scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | |
| 2315 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2316 | scsicmd->scsi_done(scsicmd); |
| 2317 | |
| 2318 | return 0; |
| 2319 | } |
| 2320 | case REQUEST_SENSE: |
| 2321 | dprintk((KERN_DEBUG "REQUEST SENSE command.\n")); |
| 2322 | memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data)); |
| 2323 | memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data)); |
| 2324 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2325 | scsicmd->scsi_done(scsicmd); |
| 2326 | return 0; |
| 2327 | |
| 2328 | case ALLOW_MEDIUM_REMOVAL: |
| 2329 | dprintk((KERN_DEBUG "LOCK command.\n")); |
| 2330 | if (scsicmd->cmnd[4]) |
| 2331 | fsa_dev_ptr[cid].locked = 1; |
| 2332 | else |
| 2333 | fsa_dev_ptr[cid].locked = 0; |
| 2334 | |
| 2335 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2336 | scsicmd->scsi_done(scsicmd); |
| 2337 | return 0; |
| 2338 | /* |
| 2339 | * These commands are all No-Ops |
| 2340 | */ |
| 2341 | case TEST_UNIT_READY: |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 2342 | if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) { |
| 2343 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | |
| 2344 | SAM_STAT_CHECK_CONDITION; |
| 2345 | set_sense(&dev->fsa_dev[cid].sense_data, |
| 2346 | NOT_READY, SENCODE_BECOMING_READY, |
| 2347 | ASENCODE_BECOMING_READY, 0, 0); |
| 2348 | memcpy(scsicmd->sense_buffer, |
| 2349 | &dev->fsa_dev[cid].sense_data, |
| 2350 | min_t(size_t, |
| 2351 | sizeof(dev->fsa_dev[cid].sense_data), |
| 2352 | SCSI_SENSE_BUFFERSIZE)); |
| 2353 | scsicmd->scsi_done(scsicmd); |
| 2354 | return 0; |
| 2355 | } |
| 2356 | /* FALLTHRU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | case RESERVE: |
| 2358 | case RELEASE: |
| 2359 | case REZERO_UNIT: |
| 2360 | case REASSIGN_BLOCKS: |
| 2361 | case SEEK_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2363 | scsicmd->scsi_done(scsicmd); |
| 2364 | return 0; |
Mark Salyzyn | 655d722 | 2008-04-30 16:03:42 -0400 | [diff] [blame] | 2365 | |
| 2366 | case START_STOP: |
| 2367 | return aac_start_stop(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2370 | switch (scsicmd->cmnd[0]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | { |
| 2372 | case READ_6: |
| 2373 | case READ_10: |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2374 | case READ_12: |
| 2375 | case READ_16: |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 2376 | if (dev->in_reset) |
| 2377 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | /* |
| 2379 | * Hack to keep track of ordinal number of the device that |
| 2380 | * corresponds to a container. Needed to convert |
| 2381 | * containers to /dev/sd device names |
| 2382 | */ |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2383 | |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2384 | if (scsicmd->request->rq_disk) |
| 2385 | strlcpy(fsa_dev_ptr[cid].devname, |
| 2386 | scsicmd->request->rq_disk->disk_name, |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2387 | min(sizeof(fsa_dev_ptr[cid].devname), |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2388 | sizeof(scsicmd->request->rq_disk->disk_name) + 1)); |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 2389 | |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 2390 | return aac_read(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | |
| 2392 | case WRITE_6: |
| 2393 | case WRITE_10: |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2394 | case WRITE_12: |
| 2395 | case WRITE_16: |
Mark Haverkamp | 8c867b2 | 2006-08-03 08:03:30 -0700 | [diff] [blame] | 2396 | if (dev->in_reset) |
| 2397 | return -1; |
Mark Haverkamp | 9e7c349 | 2007-03-15 10:26:55 -0700 | [diff] [blame] | 2398 | return aac_write(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | |
| 2400 | case SYNCHRONIZE_CACHE: |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 2401 | if (((aac_cache & 6) == 6) && dev->cache_protected) { |
| 2402 | scsicmd->result = DID_OK << 16 | |
| 2403 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; |
| 2404 | scsicmd->scsi_done(scsicmd); |
| 2405 | return 0; |
| 2406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | /* Issue FIB to tell Firmware to flush it's cache */ |
Salyzyn, Mark | 95e852e | 2008-01-08 12:01:07 -0800 | [diff] [blame] | 2408 | if ((aac_cache & 6) != 2) |
| 2409 | return aac_synchronize(scsicmd); |
| 2410 | /* FALLTHRU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | default: |
| 2412 | /* |
| 2413 | * Unhandled commands |
| 2414 | */ |
Mark Haverkamp | 7c00ffa | 2005-05-16 18:28:42 -0700 | [diff] [blame] | 2415 | dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; |
Salyzyn, Mark | 8e31e60 | 2008-02-06 13:54:12 -0800 | [diff] [blame] | 2417 | set_sense(&dev->fsa_dev[cid].sense_data, |
| 2418 | ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND, |
| 2419 | ASENCODE_INVALID_COMMAND, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, |
Salyzyn, Mark | 3ace426 | 2008-01-14 07:25:33 -0800 | [diff] [blame] | 2421 | min_t(size_t, |
| 2422 | sizeof(dev->fsa_dev[cid].sense_data), |
| 2423 | SCSI_SENSE_BUFFERSIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | scsicmd->scsi_done(scsicmd); |
| 2425 | return 0; |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | static int query_disk(struct aac_dev *dev, void __user *arg) |
| 2430 | { |
| 2431 | struct aac_query_disk qd; |
| 2432 | struct fsa_dev_info *fsa_dev_ptr; |
| 2433 | |
| 2434 | fsa_dev_ptr = dev->fsa_dev; |
Mark Haverkamp | 90ee346 | 2006-08-03 08:03:07 -0700 | [diff] [blame] | 2435 | if (!fsa_dev_ptr) |
Mark Haverkamp | 6510135 | 2006-09-19 08:59:23 -0700 | [diff] [blame] | 2436 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk))) |
| 2438 | return -EFAULT; |
| 2439 | if (qd.cnum == -1) |
Mark Haverkamp | e571877 | 2006-03-27 09:43:25 -0800 | [diff] [blame] | 2440 | qd.cnum = qd.id; |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2441 | else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | { |
| 2443 | if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers) |
| 2444 | return -EINVAL; |
| 2445 | qd.instance = dev->scsi_host_ptr->host_no; |
| 2446 | qd.bus = 0; |
| 2447 | qd.id = CONTAINER_TO_ID(qd.cnum); |
| 2448 | qd.lun = CONTAINER_TO_LUN(qd.cnum); |
| 2449 | } |
| 2450 | else return -EINVAL; |
| 2451 | |
Salyzyn, Mark | fd622b1 | 2007-07-17 10:59:19 -0400 | [diff] [blame] | 2452 | qd.valid = fsa_dev_ptr[qd.cnum].valid != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | qd.locked = fsa_dev_ptr[qd.cnum].locked; |
| 2454 | qd.deleted = fsa_dev_ptr[qd.cnum].deleted; |
| 2455 | |
| 2456 | if (fsa_dev_ptr[qd.cnum].devname[0] == '\0') |
| 2457 | qd.unmapped = 1; |
| 2458 | else |
| 2459 | qd.unmapped = 0; |
| 2460 | |
| 2461 | strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname, |
| 2462 | min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1)); |
| 2463 | |
| 2464 | if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk))) |
| 2465 | return -EFAULT; |
| 2466 | return 0; |
| 2467 | } |
| 2468 | |
| 2469 | static int force_delete_disk(struct aac_dev *dev, void __user *arg) |
| 2470 | { |
| 2471 | struct aac_delete_disk dd; |
| 2472 | struct fsa_dev_info *fsa_dev_ptr; |
| 2473 | |
| 2474 | fsa_dev_ptr = dev->fsa_dev; |
Mark Haverkamp | 6510135 | 2006-09-19 08:59:23 -0700 | [diff] [blame] | 2475 | if (!fsa_dev_ptr) |
| 2476 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | |
| 2478 | if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk))) |
| 2479 | return -EFAULT; |
| 2480 | |
| 2481 | if (dd.cnum >= dev->maximum_num_containers) |
| 2482 | return -EINVAL; |
| 2483 | /* |
| 2484 | * Mark this container as being deleted. |
| 2485 | */ |
| 2486 | fsa_dev_ptr[dd.cnum].deleted = 1; |
| 2487 | /* |
| 2488 | * Mark the container as no longer valid |
| 2489 | */ |
| 2490 | fsa_dev_ptr[dd.cnum].valid = 0; |
| 2491 | return 0; |
| 2492 | } |
| 2493 | |
| 2494 | static int delete_disk(struct aac_dev *dev, void __user *arg) |
| 2495 | { |
| 2496 | struct aac_delete_disk dd; |
| 2497 | struct fsa_dev_info *fsa_dev_ptr; |
| 2498 | |
| 2499 | fsa_dev_ptr = dev->fsa_dev; |
Mark Haverkamp | 90ee346 | 2006-08-03 08:03:07 -0700 | [diff] [blame] | 2500 | if (!fsa_dev_ptr) |
Mark Haverkamp | 6510135 | 2006-09-19 08:59:23 -0700 | [diff] [blame] | 2501 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | |
| 2503 | if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk))) |
| 2504 | return -EFAULT; |
| 2505 | |
| 2506 | if (dd.cnum >= dev->maximum_num_containers) |
| 2507 | return -EINVAL; |
| 2508 | /* |
| 2509 | * If the container is locked, it can not be deleted by the API. |
| 2510 | */ |
| 2511 | if (fsa_dev_ptr[dd.cnum].locked) |
| 2512 | return -EBUSY; |
| 2513 | else { |
| 2514 | /* |
| 2515 | * Mark the container as no longer being valid. |
| 2516 | */ |
| 2517 | fsa_dev_ptr[dd.cnum].valid = 0; |
| 2518 | fsa_dev_ptr[dd.cnum].devname[0] = '\0'; |
| 2519 | return 0; |
| 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg) |
| 2524 | { |
| 2525 | switch (cmd) { |
| 2526 | case FSACTL_QUERY_DISK: |
| 2527 | return query_disk(dev, arg); |
| 2528 | case FSACTL_DELETE_DISK: |
| 2529 | return delete_disk(dev, arg); |
| 2530 | case FSACTL_FORCE_DELETE_DISK: |
| 2531 | return force_delete_disk(dev, arg); |
| 2532 | case FSACTL_GET_CONTAINERS: |
| 2533 | return aac_get_containers(dev); |
| 2534 | default: |
| 2535 | return -ENOTTY; |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | /** |
| 2540 | * |
| 2541 | * aac_srb_callback |
| 2542 | * @context: the context set in the fib - here it is scsi cmd |
| 2543 | * @fibptr: pointer to the fib |
| 2544 | * |
| 2545 | * Handles the completion of a scsi command to a non dasd device |
| 2546 | * |
| 2547 | */ |
| 2548 | |
| 2549 | static void aac_srb_callback(void *context, struct fib * fibptr) |
| 2550 | { |
| 2551 | struct aac_dev *dev; |
| 2552 | struct aac_srb_reply *srbreply; |
| 2553 | struct scsi_cmnd *scsicmd; |
| 2554 | |
| 2555 | scsicmd = (struct scsi_cmnd *) context; |
Mark Haverkamp | 03d4433 | 2007-03-15 10:27:45 -0700 | [diff] [blame] | 2556 | |
| 2557 | if (!aac_valid_context(scsicmd, fibptr)) |
| 2558 | return; |
| 2559 | |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 2560 | BUG_ON(fibptr == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | |
Salyzyn, Mark | 1a65504 | 2007-06-11 16:17:55 -0400 | [diff] [blame] | 2562 | dev = fibptr->dev; |
| 2563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | srbreply = (struct aac_srb_reply *) fib_data(fibptr); |
| 2565 | |
| 2566 | scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */ |
| 2567 | /* |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2568 | * Calculate resid for sg |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2571 | scsi_set_resid(scsicmd, scsi_bufflen(scsicmd) |
| 2572 | - le32_to_cpu(srbreply->data_xfer_length)); |
| 2573 | |
| 2574 | scsi_dma_unmap(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | |
| 2576 | /* |
| 2577 | * First check the fib status |
| 2578 | */ |
| 2579 | |
| 2580 | if (le32_to_cpu(srbreply->status) != ST_OK){ |
| 2581 | int len; |
| 2582 | printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status)); |
Salyzyn, Mark | 3ace426 | 2008-01-14 07:25:33 -0800 | [diff] [blame] | 2583 | len = min_t(u32, le32_to_cpu(srbreply->sense_data_size), |
| 2584 | SCSI_SENSE_BUFFERSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; |
| 2586 | memcpy(scsicmd->sense_buffer, srbreply->sense_data, len); |
| 2587 | } |
| 2588 | |
| 2589 | /* |
| 2590 | * Next check the srb status |
| 2591 | */ |
| 2592 | switch( (le32_to_cpu(srbreply->srb_status))&0x3f){ |
| 2593 | case SRB_STATUS_ERROR_RECOVERY: |
| 2594 | case SRB_STATUS_PENDING: |
| 2595 | case SRB_STATUS_SUCCESS: |
Mark Haverkamp | bb08f92 | 2006-02-01 09:30:44 -0800 | [diff] [blame] | 2596 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | break; |
| 2598 | case SRB_STATUS_DATA_OVERRUN: |
| 2599 | switch(scsicmd->cmnd[0]){ |
| 2600 | case READ_6: |
| 2601 | case WRITE_6: |
| 2602 | case READ_10: |
| 2603 | case WRITE_10: |
| 2604 | case READ_12: |
| 2605 | case WRITE_12: |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2606 | case READ_16: |
| 2607 | case WRITE_16: |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2608 | if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | printk(KERN_WARNING"aacraid: SCSI CMD underflow\n"); |
| 2610 | } else { |
| 2611 | printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n"); |
| 2612 | } |
| 2613 | scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8; |
| 2614 | break; |
| 2615 | case INQUIRY: { |
Mark Haverkamp | bb08f92 | 2006-02-01 09:30:44 -0800 | [diff] [blame] | 2616 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | break; |
| 2618 | } |
| 2619 | default: |
| 2620 | scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; |
| 2621 | break; |
| 2622 | } |
| 2623 | break; |
| 2624 | case SRB_STATUS_ABORTED: |
| 2625 | scsicmd->result = DID_ABORT << 16 | ABORT << 8; |
| 2626 | break; |
| 2627 | case SRB_STATUS_ABORT_FAILED: |
| 2628 | // Not sure about this one - but assuming the hba was trying to abort for some reason |
| 2629 | scsicmd->result = DID_ERROR << 16 | ABORT << 8; |
| 2630 | break; |
| 2631 | case SRB_STATUS_PARITY_ERROR: |
| 2632 | scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8; |
| 2633 | break; |
| 2634 | case SRB_STATUS_NO_DEVICE: |
| 2635 | case SRB_STATUS_INVALID_PATH_ID: |
| 2636 | case SRB_STATUS_INVALID_TARGET_ID: |
| 2637 | case SRB_STATUS_INVALID_LUN: |
| 2638 | case SRB_STATUS_SELECTION_TIMEOUT: |
| 2639 | scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8; |
| 2640 | break; |
| 2641 | |
| 2642 | case SRB_STATUS_COMMAND_TIMEOUT: |
| 2643 | case SRB_STATUS_TIMEOUT: |
| 2644 | scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8; |
| 2645 | break; |
| 2646 | |
| 2647 | case SRB_STATUS_BUSY: |
Salyzyn, Mark | 760af10 | 2007-06-19 11:41:21 -0400 | [diff] [blame] | 2648 | scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | break; |
| 2650 | |
| 2651 | case SRB_STATUS_BUS_RESET: |
| 2652 | scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8; |
| 2653 | break; |
| 2654 | |
| 2655 | case SRB_STATUS_MESSAGE_REJECTED: |
| 2656 | scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8; |
| 2657 | break; |
| 2658 | case SRB_STATUS_REQUEST_FLUSHED: |
| 2659 | case SRB_STATUS_ERROR: |
| 2660 | case SRB_STATUS_INVALID_REQUEST: |
| 2661 | case SRB_STATUS_REQUEST_SENSE_FAILED: |
| 2662 | case SRB_STATUS_NO_HBA: |
| 2663 | case SRB_STATUS_UNEXPECTED_BUS_FREE: |
| 2664 | case SRB_STATUS_PHASE_SEQUENCE_FAILURE: |
| 2665 | case SRB_STATUS_BAD_SRB_BLOCK_LENGTH: |
| 2666 | case SRB_STATUS_DELAYED_RETRY: |
| 2667 | case SRB_STATUS_BAD_FUNCTION: |
| 2668 | case SRB_STATUS_NOT_STARTED: |
| 2669 | case SRB_STATUS_NOT_IN_USE: |
| 2670 | case SRB_STATUS_FORCE_ABORT: |
| 2671 | case SRB_STATUS_DOMAIN_VALIDATION_FAIL: |
| 2672 | default: |
| 2673 | #ifdef AAC_DETAILED_STATUS_INFO |
| 2674 | printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n", |
| 2675 | le32_to_cpu(srbreply->srb_status) & 0x3F, |
| 2676 | aac_get_status_string( |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2677 | le32_to_cpu(srbreply->srb_status) & 0x3F), |
| 2678 | scsicmd->cmnd[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | le32_to_cpu(srbreply->scsi_status)); |
| 2680 | #endif |
| 2681 | scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8; |
| 2682 | break; |
| 2683 | } |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2684 | if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | int len; |
| 2686 | scsicmd->result |= SAM_STAT_CHECK_CONDITION; |
Salyzyn, Mark | 3ace426 | 2008-01-14 07:25:33 -0800 | [diff] [blame] | 2687 | len = min_t(u32, le32_to_cpu(srbreply->sense_data_size), |
| 2688 | SCSI_SENSE_BUFFERSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | #ifdef AAC_DETAILED_STATUS_INFO |
Mark Haverkamp | 7a8cf29 | 2005-09-22 09:15:24 -0700 | [diff] [blame] | 2690 | printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n", |
| 2691 | le32_to_cpu(srbreply->status), len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | #endif |
| 2693 | memcpy(scsicmd->sense_buffer, srbreply->sense_data, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | } |
| 2695 | /* |
| 2696 | * OR in the scsi status (already shifted up a bit) |
| 2697 | */ |
| 2698 | scsicmd->result |= le32_to_cpu(srbreply->scsi_status); |
| 2699 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 2700 | aac_fib_complete(fibptr); |
| 2701 | aac_fib_free(fibptr); |
Mark Haverkamp | 8e0c5eb | 2005-10-24 10:52:22 -0700 | [diff] [blame] | 2702 | scsicmd->scsi_done(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | /** |
| 2706 | * |
| 2707 | * aac_send_scb_fib |
| 2708 | * @scsicmd: the scsi command block |
| 2709 | * |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2710 | * This routine will form a FIB and fill in the aac_srb from the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | * scsicmd passed in. |
| 2712 | */ |
| 2713 | |
| 2714 | static int aac_send_srb_fib(struct scsi_cmnd* scsicmd) |
| 2715 | { |
| 2716 | struct fib* cmd_fibcontext; |
| 2717 | struct aac_dev* dev; |
| 2718 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 2720 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; |
Mark Haverkamp | e571877 | 2006-03-27 09:43:25 -0800 | [diff] [blame] | 2721 | if (scmd_id(scsicmd) >= dev->maximum_num_physicals || |
Mark Haverkamp | 8497173 | 2005-06-20 11:55:24 -0700 | [diff] [blame] | 2722 | scsicmd->device->lun > 7) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | scsicmd->result = DID_NO_CONNECT << 16; |
| 2724 | scsicmd->scsi_done(scsicmd); |
| 2725 | return 0; |
| 2726 | } |
| 2727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | /* |
| 2729 | * Allocate and initialize a Fib then setup a BlockWrite command |
| 2730 | */ |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 2731 | if (!(cmd_fibcontext = aac_fib_alloc(dev))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | return -1; |
| 2733 | } |
Mark Haverkamp | e8f32de | 2007-01-23 15:00:30 -0800 | [diff] [blame] | 2734 | status = aac_adapter_scsi(cmd_fibcontext, scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | /* |
| 2737 | * Check that the command queued to the controller |
| 2738 | */ |
Mark Haverkamp | 77d644d | 2006-03-27 09:43:40 -0800 | [diff] [blame] | 2739 | if (status == -EINPROGRESS) { |
| 2740 | scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | return 0; |
| 2742 | } |
| 2743 | |
Mark Haverkamp | bfb35aa8 | 2006-02-01 09:30:55 -0800 | [diff] [blame] | 2744 | printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status); |
| 2745 | aac_fib_complete(cmd_fibcontext); |
| 2746 | aac_fib_free(cmd_fibcontext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | |
| 2748 | return -1; |
| 2749 | } |
| 2750 | |
| 2751 | static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg) |
| 2752 | { |
| 2753 | struct aac_dev *dev; |
| 2754 | unsigned long byte_count = 0; |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2755 | int nseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | |
| 2757 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; |
| 2758 | // Get rid of old data |
| 2759 | psg->count = 0; |
| 2760 | psg->sg[0].addr = 0; |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2761 | psg->sg[0].count = 0; |
| 2762 | |
| 2763 | nseg = scsi_dma_map(scsicmd); |
| 2764 | BUG_ON(nseg < 0); |
| 2765 | if (nseg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | struct scatterlist *sg; |
| 2767 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2769 | psg->count = cpu_to_le32(nseg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2771 | scsi_for_each_sg(scsicmd, sg, nseg, i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg)); |
| 2773 | psg->sg[i].count = cpu_to_le32(sg_dma_len(sg)); |
| 2774 | byte_count += sg_dma_len(sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | } |
| 2776 | /* hba wants the size to be exact */ |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2777 | if (byte_count > scsi_bufflen(scsicmd)) { |
| 2778 | u32 temp = le32_to_cpu(psg->sg[i-1].count) - |
| 2779 | (byte_count - scsi_bufflen(scsicmd)); |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 2780 | psg->sg[i-1].count = cpu_to_le32(temp); |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2781 | byte_count = scsi_bufflen(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | } |
| 2783 | /* Check for command underflow */ |
| 2784 | if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ |
| 2785 | printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n", |
| 2786 | byte_count, scsicmd->underflow); |
| 2787 | } |
| 2788 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | return byte_count; |
| 2790 | } |
| 2791 | |
| 2792 | |
| 2793 | static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg) |
| 2794 | { |
| 2795 | struct aac_dev *dev; |
| 2796 | unsigned long byte_count = 0; |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 2797 | u64 addr; |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2798 | int nseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | |
| 2800 | dev = (struct aac_dev *)scsicmd->device->host->hostdata; |
| 2801 | // Get rid of old data |
| 2802 | psg->count = 0; |
| 2803 | psg->sg[0].addr[0] = 0; |
| 2804 | psg->sg[0].addr[1] = 0; |
| 2805 | psg->sg[0].count = 0; |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2806 | |
| 2807 | nseg = scsi_dma_map(scsicmd); |
| 2808 | BUG_ON(nseg < 0); |
| 2809 | if (nseg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | struct scatterlist *sg; |
| 2811 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2813 | scsi_for_each_sg(scsicmd, sg, nseg, i) { |
Mark Haverkamp | 1241f35 | 2006-03-27 09:44:23 -0800 | [diff] [blame] | 2814 | int count = sg_dma_len(sg); |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 2815 | addr = sg_dma_address(sg); |
| 2816 | psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff); |
| 2817 | psg->sg[i].addr[1] = cpu_to_le32(addr>>32); |
Mark Haverkamp | 1241f35 | 2006-03-27 09:44:23 -0800 | [diff] [blame] | 2818 | psg->sg[i].count = cpu_to_le32(count); |
| 2819 | byte_count += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | } |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2821 | psg->count = cpu_to_le32(nseg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | /* hba wants the size to be exact */ |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2823 | if (byte_count > scsi_bufflen(scsicmd)) { |
| 2824 | u32 temp = le32_to_cpu(psg->sg[i-1].count) - |
| 2825 | (byte_count - scsi_bufflen(scsicmd)); |
Mark Haverkamp | 56b5871 | 2005-04-27 06:05:51 -0700 | [diff] [blame] | 2826 | psg->sg[i-1].count = cpu_to_le32(temp); |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2827 | byte_count = scsi_bufflen(scsicmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | } |
| 2829 | /* Check for command underflow */ |
| 2830 | if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ |
| 2831 | printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n", |
| 2832 | byte_count, scsicmd->underflow); |
| 2833 | } |
| 2834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | return byte_count; |
| 2836 | } |
| 2837 | |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2838 | static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg) |
| 2839 | { |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2840 | unsigned long byte_count = 0; |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2841 | int nseg; |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2842 | |
| 2843 | // Get rid of old data |
| 2844 | psg->count = 0; |
| 2845 | psg->sg[0].next = 0; |
| 2846 | psg->sg[0].prev = 0; |
| 2847 | psg->sg[0].addr[0] = 0; |
| 2848 | psg->sg[0].addr[1] = 0; |
| 2849 | psg->sg[0].count = 0; |
| 2850 | psg->sg[0].flags = 0; |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2851 | |
| 2852 | nseg = scsi_dma_map(scsicmd); |
| 2853 | BUG_ON(nseg < 0); |
| 2854 | if (nseg) { |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2855 | struct scatterlist *sg; |
| 2856 | int i; |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2857 | |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2858 | scsi_for_each_sg(scsicmd, sg, nseg, i) { |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2859 | int count = sg_dma_len(sg); |
| 2860 | u64 addr = sg_dma_address(sg); |
| 2861 | psg->sg[i].next = 0; |
| 2862 | psg->sg[i].prev = 0; |
| 2863 | psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32)); |
| 2864 | psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff)); |
| 2865 | psg->sg[i].count = cpu_to_le32(count); |
| 2866 | psg->sg[i].flags = 0; |
| 2867 | byte_count += count; |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2868 | } |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2869 | psg->count = cpu_to_le32(nseg); |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2870 | /* hba wants the size to be exact */ |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2871 | if (byte_count > scsi_bufflen(scsicmd)) { |
| 2872 | u32 temp = le32_to_cpu(psg->sg[i-1].count) - |
| 2873 | (byte_count - scsi_bufflen(scsicmd)); |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2874 | psg->sg[i-1].count = cpu_to_le32(temp); |
FUJITA Tomonori | 727eead | 2007-05-26 02:00:42 +0900 | [diff] [blame] | 2875 | byte_count = scsi_bufflen(scsicmd); |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2876 | } |
| 2877 | /* Check for command underflow */ |
| 2878 | if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ |
| 2879 | printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n", |
| 2880 | byte_count, scsicmd->underflow); |
| 2881 | } |
| 2882 | } |
Mark Haverkamp | 0e68c00 | 2005-08-03 15:39:49 -0700 | [diff] [blame] | 2883 | return byte_count; |
| 2884 | } |
| 2885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | #ifdef AAC_DETAILED_STATUS_INFO |
| 2887 | |
| 2888 | struct aac_srb_status_info { |
| 2889 | u32 status; |
| 2890 | char *str; |
| 2891 | }; |
| 2892 | |
| 2893 | |
| 2894 | static struct aac_srb_status_info srb_status_info[] = { |
| 2895 | { SRB_STATUS_PENDING, "Pending Status"}, |
| 2896 | { SRB_STATUS_SUCCESS, "Success"}, |
| 2897 | { SRB_STATUS_ABORTED, "Aborted Command"}, |
| 2898 | { SRB_STATUS_ABORT_FAILED, "Abort Failed"}, |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 2899 | { SRB_STATUS_ERROR, "Error Event"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | { SRB_STATUS_BUSY, "Device Busy"}, |
| 2901 | { SRB_STATUS_INVALID_REQUEST, "Invalid Request"}, |
| 2902 | { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"}, |
| 2903 | { SRB_STATUS_NO_DEVICE, "No Device"}, |
| 2904 | { SRB_STATUS_TIMEOUT, "Timeout"}, |
| 2905 | { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"}, |
| 2906 | { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"}, |
| 2907 | { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"}, |
| 2908 | { SRB_STATUS_BUS_RESET, "Bus Reset"}, |
| 2909 | { SRB_STATUS_PARITY_ERROR, "Parity Error"}, |
| 2910 | { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"}, |
| 2911 | { SRB_STATUS_NO_HBA, "No HBA"}, |
| 2912 | { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"}, |
| 2913 | { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"}, |
| 2914 | { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"}, |
| 2915 | { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"}, |
| 2916 | { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"}, |
| 2917 | { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"}, |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 2918 | { SRB_STATUS_INVALID_LUN, "Invalid LUN"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"}, |
| 2920 | { SRB_STATUS_BAD_FUNCTION, "Bad Function"}, |
| 2921 | { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"}, |
| 2922 | { SRB_STATUS_NOT_STARTED, "Not Started"}, |
| 2923 | { SRB_STATUS_NOT_IN_USE, "Not In Use"}, |
Salyzyn, Mark | 8ce3eca | 2008-01-16 07:39:06 -0800 | [diff] [blame] | 2924 | { SRB_STATUS_FORCE_ABORT, "Force Abort"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"}, |
| 2926 | { 0xff, "Unknown Error"} |
| 2927 | }; |
| 2928 | |
| 2929 | char *aac_get_status_string(u32 status) |
| 2930 | { |
| 2931 | int i; |
| 2932 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 2933 | for (i = 0; i < ARRAY_SIZE(srb_status_info); i++) |
| 2934 | if (srb_status_info[i].status == status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | return srb_status_info[i].str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | |
| 2937 | return "Bad Status Code"; |
| 2938 | } |
| 2939 | |
| 2940 | #endif |