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