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