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