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