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