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