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