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