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