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