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