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