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