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