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