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