blob: bfd0e64964accc6e8317c50338725d4fc8db6ad5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
4 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mark Haverkamp03d44332007-03-15 10:27:45 -07008 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/pci.h>
30#include <linux/spinlock.h>
31#include <linux/slab.h>
32#include <linux/completion.h>
33#include <linux/blkdev.h>
34#include <asm/semaphore.h>
35#include <asm/uaccess.h>
Salyzyn, Mark3a0086a2008-01-11 11:46:44 -080036#include <linux/highmem.h> /* For flush_kernel_dcache_page */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <scsi/scsi.h>
39#include <scsi/scsi_cmnd.h>
40#include <scsi/scsi_device.h>
41#include <scsi/scsi_host.h>
42
43#include "aacraid.h"
44
45/* values for inqd_pdt: Peripheral device type in plain English */
46#define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
47#define INQD_PDT_PROC 0x03 /* Processor device */
48#define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
49#define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
50#define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
51#define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
52
53#define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
54#define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*
57 * Sense codes
58 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080059
60#define SENCODE_NO_SENSE 0x00
61#define SENCODE_END_OF_DATA 0x00
62#define SENCODE_BECOMING_READY 0x04
63#define SENCODE_INIT_CMD_REQUIRED 0x04
64#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65#define SENCODE_INVALID_COMMAND 0x20
66#define SENCODE_LBA_OUT_OF_RANGE 0x21
67#define SENCODE_INVALID_CDB_FIELD 0x24
68#define SENCODE_LUN_NOT_SUPPORTED 0x25
69#define SENCODE_INVALID_PARAM_FIELD 0x26
70#define SENCODE_PARAM_NOT_SUPPORTED 0x26
71#define SENCODE_PARAM_VALUE_INVALID 0x26
72#define SENCODE_RESET_OCCURRED 0x29
73#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76#define SENCODE_DIAGNOSTIC_FAILURE 0x40
77#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78#define SENCODE_INVALID_MESSAGE_ERROR 0x49
79#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80#define SENCODE_OVERLAPPED_COMMAND 0x4E
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
83 * Additional sense codes
84 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080085
86#define ASENCODE_NO_SENSE 0x00
87#define ASENCODE_END_OF_DATA 0x05
88#define ASENCODE_BECOMING_READY 0x01
89#define ASENCODE_INIT_CMD_REQUIRED 0x02
90#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91#define ASENCODE_INVALID_COMMAND 0x00
92#define ASENCODE_LBA_OUT_OF_RANGE 0x00
93#define ASENCODE_INVALID_CDB_FIELD 0x00
94#define ASENCODE_LUN_NOT_SUPPORTED 0x00
95#define ASENCODE_INVALID_PARAM_FIELD 0x00
96#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97#define ASENCODE_PARAM_VALUE_INVALID 0x02
98#define ASENCODE_RESET_OCCURRED 0x00
99#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106#define ASENCODE_OVERLAPPED_COMMAND 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108#define BYTE0(x) (unsigned char)(x)
109#define BYTE1(x) (unsigned char)((x) >> 8)
110#define BYTE2(x) (unsigned char)((x) >> 16)
111#define BYTE3(x) (unsigned char)((x) >> 24)
112
113/*------------------------------------------------------------------------------
114 * S T R U C T S / T Y P E D E F S
115 *----------------------------------------------------------------------------*/
116/* SCSI inquiry data */
117struct inquiry_data {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq; /* RMB | Device Type Qualifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len; /* Additional length (n-4) */
123 u8 inqd_pad1[2];/* Reserved - must be zero */
124 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
125 u8 inqd_vid[8]; /* Vendor ID */
126 u8 inqd_pid[16];/* Product ID */
127 u8 inqd_prl[4]; /* Product Revision Level */
128};
129
130/*
131 * M O D U L E G L O B A L S
132 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -0700136static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
138#ifdef AAC_DETAILED_STATUS_INFO
139static char *aac_get_status_string(u32 status);
140#endif
141
142/*
143 * Non dasd selection is handled entirely in aachba now
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800144 */
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static int nondasd = -1;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -0800147static int aac_cache = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static int dacmode = -1;
149
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400150int aac_commit = -1;
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700151int startup_timeout = 180;
152int aif_timeout = 120;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800154module_param(nondasd, int, S_IRUGO|S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
Salyzyn, Mark95e852e2008-01-08 12:01:07 -0800156module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
157MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n\tbit 0 - Disable FUA in WRITE SCSI commands\n\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n\tbit 2 - Disable only if Battery not protecting Cache");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800158module_param(dacmode, int, S_IRUGO|S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400160module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700162module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
163MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for adapter to have it's kernel up and\nrunning. This is typically adjusted for large systems that do not have a BIOS.");
164module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
165MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for applications to pick up AIFs before\nderegistering them. This is typically adjusted for heavily burdened systems.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700167int numacb = -1;
168module_param(numacb, int, S_IRUGO|S_IWUSR);
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800169MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid values are 512 and down. Default is to use suggestion from Firmware.");
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700170
171int acbsize = -1;
172module_param(acbsize, int, S_IRUGO|S_IWUSR);
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800173MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware.");
Mark Haverkamp653ba582006-09-19 08:59:43 -0700174
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400175int update_interval = 30 * 60;
176module_param(update_interval, int, S_IRUGO|S_IWUSR);
177MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync updates issued to adapter.");
178
179int check_interval = 24 * 60 * 60;
180module_param(check_interval, int, S_IRUGO|S_IWUSR);
181MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health checks.");
182
Andrew Morton87f3bda2007-08-10 14:50:30 -0700183int aac_check_reset = 1;
184module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
Salyzyn, Markf8583172007-10-30 15:50:49 -0400185MODULE_PARM_DESC(aac_check_reset, "If adapter fails health check, reset the adapter. a value of -1 forces the reset to adapters programmed to ignore it.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400186
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800187int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700188module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800189MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700190
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400191int aac_reset_devices = 0;
192module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
193MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700194
195static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
196 struct fib *fibptr) {
197 struct scsi_device *device;
198
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800199 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
Salyzyn, Markc835e372007-07-26 14:20:02 -0400200 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800201 aac_fib_complete(fibptr);
202 aac_fib_free(fibptr);
203 return 0;
204 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700205 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
206 device = scsicmd->device;
207 if (unlikely(!device || !scsi_device_online(device))) {
208 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
209 aac_fib_complete(fibptr);
210 aac_fib_free(fibptr);
211 return 0;
212 }
213 return 1;
214}
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216/**
217 * aac_get_config_status - check the adapter configuration
218 * @common: adapter to query
219 *
220 * Query config status, and commit the configuration if needed.
221 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700222int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224 int status = 0;
225 struct fib * fibptr;
226
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800227 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return -ENOMEM;
229
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800230 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 {
232 struct aac_get_config_status *dinfo;
233 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
234
235 dinfo->command = cpu_to_le32(VM_ContainerConfig);
236 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
237 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
238 }
239
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800240 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 fibptr,
242 sizeof (struct aac_get_config_status),
243 FsaNormal,
244 1, 1,
245 NULL, NULL);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800246 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
248 } else {
249 struct aac_get_config_status_resp *reply
250 = (struct aac_get_config_status_resp *) fib_data(fibptr);
251 dprintk((KERN_WARNING
252 "aac_get_config_status: response=%d status=%d action=%d\n",
253 le32_to_cpu(reply->response),
254 le32_to_cpu(reply->status),
255 le32_to_cpu(reply->data.action)));
256 if ((le32_to_cpu(reply->response) != ST_OK) ||
257 (le32_to_cpu(reply->status) != CT_OK) ||
258 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
259 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
260 status = -EINVAL;
261 }
262 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800263 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
265 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400266 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800268 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 dinfo = (struct aac_commit_config *) fib_data(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 dinfo->command = cpu_to_le32(VM_ContainerConfig);
272 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800273
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800274 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 fibptr,
276 sizeof (struct aac_commit_config),
277 FsaNormal,
278 1, 1,
279 NULL, NULL);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800280 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400281 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 printk(KERN_WARNING
283 "aac_get_config_status: Foreign device configurations are being ignored\n");
284 }
285 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800286 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 return status;
288}
289
290/**
291 * aac_get_containers - list containers
292 * @common: adapter to probe
293 *
294 * Make a list of all containers on this controller
295 */
296int aac_get_containers(struct aac_dev *dev)
297{
298 struct fsa_dev_info *fsa_dev_ptr;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800299 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 int status = 0;
301 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 struct aac_get_container_count *dinfo;
303 struct aac_get_container_count_resp *dresp;
304 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
305
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800306 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 return -ENOMEM;
308
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800309 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
311 dinfo->command = cpu_to_le32(VM_ContainerConfig);
312 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
313
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800314 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 fibptr,
316 sizeof (struct aac_get_container_count),
317 FsaNormal,
318 1, 1,
319 NULL, NULL);
320 if (status >= 0) {
321 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
322 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800323 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700325 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
328 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400329 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700330 GFP_KERNEL);
331 if (!fsa_dev_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 dev->fsa_dev = fsa_dev_ptr;
335 dev->maximum_num_containers = maximum_num_containers;
336
Mark Haverkampfe76df42007-03-15 12:55:07 -0700337 for (index = 0; index < dev->maximum_num_containers; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 fsa_dev_ptr[index].devname[0] = '\0';
339
Mark Haverkampfe76df42007-03-15 12:55:07 -0700340 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Mark Haverkampfe76df42007-03-15 12:55:07 -0700342 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
344 break;
345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 /*
348 * If there are no more containers, then stop asking.
349 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700350 if (++index >= status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return status;
354}
355
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700356static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
357{
358 void *buf;
James Bottomleycab537d2007-05-16 10:06:39 -0400359 int transfer_len;
FUJITA Tomonori727eead2007-05-26 02:00:42 +0900360 struct scatterlist *sg = scsi_sglist(scsicmd);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700361
Jens Axboe45711f12007-10-22 21:19:53 +0200362 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
FUJITA Tomonori727eead2007-05-26 02:00:42 +0900363 transfer_len = min(sg->length, len + offset);
364
Salyzyn, Mark20235f32007-03-21 13:22:56 -0400365 transfer_len -= offset;
James Bottomleycab537d2007-05-16 10:06:39 -0400366 if (buf && transfer_len > 0)
Salyzyn, Mark20235f32007-03-21 13:22:56 -0400367 memcpy(buf + offset, data, transfer_len);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700368
Salyzyn, Mark3a0086a2008-01-11 11:46:44 -0800369 flush_kernel_dcache_page(kmap_atomic_to_page(buf - sg->offset));
FUJITA Tomonori727eead2007-05-26 02:00:42 +0900370 kunmap_atomic(buf - sg->offset, KM_IRQ0);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700371
372}
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374static void get_container_name_callback(void *context, struct fib * fibptr)
375{
376 struct aac_get_name_resp * get_name_reply;
377 struct scsi_cmnd * scsicmd;
378
379 scsicmd = (struct scsi_cmnd *) context;
380
Mark Haverkamp03d44332007-03-15 10:27:45 -0700381 if (!aac_valid_context(scsicmd, fibptr))
382 return;
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700385 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
388 /* Failure is irrelevant, using default value instead */
389 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
390 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700391 char *sp = get_name_reply->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
393 while (*sp == ' ')
394 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700395 if (*sp) {
396 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
397 int count = sizeof(d);
398 char *dp = d;
399 do {
400 *dp++ = (*sp) ? *sp++ : ' ';
401 } while (--count > 0);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800402 aac_internal_transfer(scsicmd, d,
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700403 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
408
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800409 aac_fib_complete(fibptr);
410 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700411 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414/**
415 * aac_get_container_name - get container name, none blocking.
416 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700417static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
419 int status;
420 struct aac_get_name *dinfo;
421 struct fib * cmd_fibcontext;
422 struct aac_dev * dev;
423
424 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
425
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800426 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return -ENOMEM;
428
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800429 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
431
432 dinfo->command = cpu_to_le32(VM_ContainerConfig);
433 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700434 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
436
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800437 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800438 cmd_fibcontext,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 sizeof (struct aac_get_name),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800440 FsaNormal,
441 0, 1,
442 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 /*
446 * Check that the command queued to the controller
447 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800448 if (status == -EINPROGRESS) {
449 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800451 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800452
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800453 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
454 aac_fib_complete(cmd_fibcontext);
455 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 return -1;
457}
458
Mark Haverkampfe76df42007-03-15 12:55:07 -0700459static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
460{
461 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
462
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400463 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700464 return aac_scsi_cmd(scsicmd);
465
466 scsicmd->result = DID_NO_CONNECT << 16;
467 scsicmd->scsi_done(scsicmd);
468 return 0;
469}
470
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400471static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700472{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700473 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700474 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700475 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
476
Mark Haverkamp03d44332007-03-15 10:27:45 -0700477
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400478 if (!aac_valid_context(scsicmd, fibptr))
479 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700480
481 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400482 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700483 if (fsa_dev_ptr) {
484 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
485 fsa_dev_ptr += scmd_id(scsicmd);
486
487 if ((le32_to_cpu(dresp->status) == ST_OK) &&
488 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
489 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
490 fsa_dev_ptr->valid = 1;
491 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
492 fsa_dev_ptr->size
493 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
494 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
495 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
496 }
497 if ((fsa_dev_ptr->valid & 1) == 0)
498 fsa_dev_ptr->valid = 0;
499 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
500 }
501 aac_fib_complete(fibptr);
502 aac_fib_free(fibptr);
503 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
504 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400505 (*callback)(scsicmd);
506 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700507}
508
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400509static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700510{
511 struct scsi_cmnd * scsicmd;
512 struct aac_mount * dresp;
513 struct aac_query_mount *dinfo;
514 int status;
515
516 dresp = (struct aac_mount *) fib_data(fibptr);
517 dresp->mnt[0].capacityhigh = 0;
518 if ((le32_to_cpu(dresp->status) != ST_OK) ||
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400519 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
520 _aac_probe_container2(context, fibptr);
521 return;
522 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700523 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700524
Mark Haverkamp03d44332007-03-15 10:27:45 -0700525 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400526 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700527
Mark Haverkampfe76df42007-03-15 12:55:07 -0700528 aac_fib_init(fibptr);
529
530 dinfo = (struct aac_query_mount *)fib_data(fibptr);
531
532 dinfo->command = cpu_to_le32(VM_NameServe64);
533 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
534 dinfo->type = cpu_to_le32(FT_FILESYS);
535
536 status = aac_fib_send(ContainerCommand,
537 fibptr,
538 sizeof(struct aac_query_mount),
539 FsaNormal,
540 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400541 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700542 (void *) scsicmd);
543 /*
544 * Check that the command queued to the controller
545 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400546 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700547 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400548 else if (status < 0) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700549 /* Inherit results from VM_NameServe, if any */
550 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400551 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700552 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700553}
554
555static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
556{
557 struct fib * fibptr;
558 int status = -ENOMEM;
559
560 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
561 struct aac_query_mount *dinfo;
562
563 aac_fib_init(fibptr);
564
565 dinfo = (struct aac_query_mount *)fib_data(fibptr);
566
567 dinfo->command = cpu_to_le32(VM_NameServe);
568 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
569 dinfo->type = cpu_to_le32(FT_FILESYS);
570 scsicmd->SCp.ptr = (char *)callback;
571
572 status = aac_fib_send(ContainerCommand,
573 fibptr,
574 sizeof(struct aac_query_mount),
575 FsaNormal,
576 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400577 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700578 (void *) scsicmd);
579 /*
580 * Check that the command queued to the controller
581 */
582 if (status == -EINPROGRESS) {
583 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
584 return 0;
585 }
586 if (status < 0) {
587 scsicmd->SCp.ptr = NULL;
588 aac_fib_complete(fibptr);
589 aac_fib_free(fibptr);
590 }
591 }
592 if (status < 0) {
593 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
594 if (fsa_dev_ptr) {
595 fsa_dev_ptr += scmd_id(scsicmd);
596 if ((fsa_dev_ptr->valid & 1) == 0) {
597 fsa_dev_ptr->valid = 0;
598 return (*callback)(scsicmd);
599 }
600 }
601 }
602 return status;
603}
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800606 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 * @dev: device to query
608 * @cid: container identifier
609 *
610 * Queries the controller about the given volume. The volume information
611 * is updated in the struct fsa_dev_info structure rather than returned.
612 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700613static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
614{
615 scsicmd->device = NULL;
616 return 0;
617}
618
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800619int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700621 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
622 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Mark Haverkampfe76df42007-03-15 12:55:07 -0700625 if (!scsicmd || !scsidev) {
626 kfree(scsicmd);
627 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700628 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700630 scsicmd->list.next = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400631 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Mark Haverkampfe76df42007-03-15 12:55:07 -0700633 scsicmd->device = scsidev;
634 scsidev->sdev_state = 0;
635 scsidev->id = cid;
636 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Mark Haverkampfe76df42007-03-15 12:55:07 -0700638 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
639 while (scsicmd->device == scsidev)
640 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400641 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700642 status = scsicmd->SCp.Status;
643 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return status;
645}
646
647/* Local Structure to set SCSI inquiry data strings */
648struct scsi_inq {
649 char vid[8]; /* Vendor ID */
650 char pid[16]; /* Product ID */
651 char prl[4]; /* Product Revision Level */
652};
653
654/**
655 * InqStrCopy - string merge
656 * @a: string to copy from
657 * @b: string to copy to
658 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800659 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 * without copying \0
661 */
662
663static void inqstrcpy(char *a, char *b)
664{
665
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800666 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 *b++ = *a++;
668}
669
670static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800671 "None",
672 "Volume",
673 "Mirror",
674 "Stripe",
675 "RAID5",
676 "SSRW",
677 "SSRO",
678 "Morph",
679 "Legacy",
680 "RAID4",
681 "RAID10",
682 "RAID00",
683 "V-MIRRORS",
684 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700686 "RAID5D",
687 "RAID5D0",
688 "RAID1E",
689 "RAID6",
690 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800691 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692};
693
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800694char * get_container_type(unsigned tindex)
695{
696 if (tindex >= ARRAY_SIZE(container_types))
697 tindex = ARRAY_SIZE(container_types) - 1;
698 return container_types[tindex];
699}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701/* Function: setinqstr
702 *
703 * Arguments: [1] pointer to void [1] int
704 *
705 * Purpose: Sets SCSI inquiry data strings for vendor, product
706 * and revision level. Allows strings to be set in platform dependant
707 * files instead of in OS dependant driver source.
708 */
709
Mark Haverkamp794d0602005-10-24 10:51:53 -0700710static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
712 struct scsi_inq *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700715 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Mark Haverkamp794d0602005-10-24 10:51:53 -0700717 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
718 char * cp = dev->supplement_adapter_info.AdapterTypeText;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800719 int c;
720 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
721 inqstrcpy("SMC", str->vid);
722 else {
723 c = sizeof(str->vid);
724 while (*cp && *cp != ' ' && --c)
725 ++cp;
726 c = *cp;
727 *cp = '\0';
728 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
729 str->vid);
730 *cp = c;
731 while (*cp && *cp != ' ')
732 ++cp;
733 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700734 while (*cp == ' ')
735 ++cp;
736 /* last six chars reserved for vol type */
737 c = 0;
738 if (strlen(cp) > sizeof(str->pid)) {
739 c = cp[sizeof(str->pid)];
740 cp[sizeof(str->pid)] = '\0';
741 }
742 inqstrcpy (cp, str->pid);
743 if (c)
744 cp[sizeof(str->pid)] = c;
745 } else {
746 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700747
748 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700749 /* last six chars reserved for vol type */
750 inqstrcpy (mp->model, str->pid);
751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Tobias Klauser6391a112006-06-08 22:23:48 -0700753 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 char *findit = str->pid;
755
756 for ( ; *findit != ' '; findit++); /* walk till we find a space */
757 /* RAID is superfluous in the context of a RAID device */
758 if (memcmp(findit-4, "RAID", 4) == 0)
759 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700760 if (((findit - str->pid) + strlen(container_types[tindex]))
761 < (sizeof(str->pid) + sizeof(str->prl)))
762 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
764 inqstrcpy ("V1.0", str->prl);
765}
766
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400767static void get_container_serial_callback(void *context, struct fib * fibptr)
768{
769 struct aac_get_serial_resp * get_serial_reply;
770 struct scsi_cmnd * scsicmd;
771
772 BUG_ON(fibptr == NULL);
773
774 scsicmd = (struct scsi_cmnd *) context;
775 if (!aac_valid_context(scsicmd, fibptr))
776 return;
777
778 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
779 /* Failure is irrelevant, using default value instead */
780 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
781 char sp[13];
782 /* EVPD bit set */
783 sp[0] = INQD_PDT_DA;
784 sp[1] = scsicmd->cmnd[2];
785 sp[2] = 0;
786 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
787 le32_to_cpu(get_serial_reply->uid));
788 aac_internal_transfer(scsicmd, sp, 0, sizeof(sp));
789 }
790
791 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
792
793 aac_fib_complete(fibptr);
794 aac_fib_free(fibptr);
795 scsicmd->scsi_done(scsicmd);
796}
797
798/**
799 * aac_get_container_serial - get container serial, none blocking.
800 */
801static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
802{
803 int status;
804 struct aac_get_serial *dinfo;
805 struct fib * cmd_fibcontext;
806 struct aac_dev * dev;
807
808 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
809
810 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
811 return -ENOMEM;
812
813 aac_fib_init(cmd_fibcontext);
814 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
815
816 dinfo->command = cpu_to_le32(VM_ContainerConfig);
817 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
818 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
819
820 status = aac_fib_send(ContainerCommand,
821 cmd_fibcontext,
822 sizeof (struct aac_get_serial),
823 FsaNormal,
824 0, 1,
825 (fib_callback) get_container_serial_callback,
826 (void *) scsicmd);
827
828 /*
829 * Check that the command queued to the controller
830 */
831 if (status == -EINPROGRESS) {
832 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
833 return 0;
834 }
835
836 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
837 aac_fib_complete(cmd_fibcontext);
838 aac_fib_free(cmd_fibcontext);
839 return -1;
840}
841
842/* Function: setinqserial
843 *
844 * Arguments: [1] pointer to void [1] int
845 *
846 * Purpose: Sets SCSI Unit Serial number.
847 * This is a fake. We should read a proper
848 * serial number from the container. <SuSE>But
849 * without docs it's quite hard to do it :-)
850 * So this will have to do in the meantime.</SuSE>
851 */
852
853static int setinqserial(struct aac_dev *dev, void *data, int cid)
854{
855 /*
856 * This breaks array migration.
857 */
858 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
859 le32_to_cpu(dev->adapter_info.serial[0]), cid);
860}
861
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800862static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
863 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800865 u8 *sense_buf = (u8 *)sense_data;
866 /* Sense data valid, err code 70h */
867 sense_buf[0] = 0x70; /* No info field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 sense_buf[1] = 0; /* Segment number, always zero */
869
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800870 sense_buf[2] = sense_key; /* Sense key */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 sense_buf[12] = sense_code; /* Additional sense code */
873 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 if (sense_key == ILLEGAL_REQUEST) {
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800876 sense_buf[7] = 10; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800878 sense_buf[15] = bit_pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 /* Illegal parameter is in the parameter block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 if (sense_code == SENCODE_INVALID_CDB_FIELD)
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800881 sense_buf[15] |= 0xc0;/* Std sense key specific field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 /* Illegal parameter is in the CDB block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 sense_buf[16] = field_pointer >> 8; /* MSB */
884 sense_buf[17] = field_pointer; /* LSB */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800885 } else
886 sense_buf[7] = 6; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887}
888
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800889static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
890{
891 if (lba & 0xffffffff00000000LL) {
892 int cid = scmd_id(cmd);
893 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
894 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
895 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800896 set_sense(&dev->fsa_dev[cid].sense_data,
897 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
898 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800899 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -0800900 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
901 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800902 cmd->scsi_done(cmd);
903 return 1;
904 }
905 return 0;
906}
907
908static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
909{
910 return 0;
911}
912
913static void io_callback(void *context, struct fib * fibptr);
914
915static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
916{
917 u16 fibsize;
918 struct aac_raw_io *readcmd;
919 aac_fib_init(fib);
920 readcmd = (struct aac_raw_io *) fib_data(fib);
921 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
922 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
923 readcmd->count = cpu_to_le32(count<<9);
924 readcmd->cid = cpu_to_le16(scmd_id(cmd));
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -0400925 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800926 readcmd->bpTotal = 0;
927 readcmd->bpComplete = 0;
928
929 aac_build_sgraw(cmd, &readcmd->sg);
930 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
931 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
932 /*
933 * Now send the Fib to the adapter
934 */
935 return aac_fib_send(ContainerRawIo,
936 fib,
937 fibsize,
938 FsaNormal,
939 0, 1,
940 (fib_callback) io_callback,
941 (void *) cmd);
942}
943
944static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
945{
946 u16 fibsize;
947 struct aac_read64 *readcmd;
948 aac_fib_init(fib);
949 readcmd = (struct aac_read64 *) fib_data(fib);
950 readcmd->command = cpu_to_le32(VM_CtHostRead64);
951 readcmd->cid = cpu_to_le16(scmd_id(cmd));
952 readcmd->sector_count = cpu_to_le16(count);
953 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
954 readcmd->pad = 0;
955 readcmd->flags = 0;
956
957 aac_build_sg64(cmd, &readcmd->sg);
958 fibsize = sizeof(struct aac_read64) +
959 ((le32_to_cpu(readcmd->sg.count) - 1) *
960 sizeof (struct sgentry64));
961 BUG_ON (fibsize > (fib->dev->max_fib_size -
962 sizeof(struct aac_fibhdr)));
963 /*
964 * Now send the Fib to the adapter
965 */
966 return aac_fib_send(ContainerCommand64,
967 fib,
968 fibsize,
969 FsaNormal,
970 0, 1,
971 (fib_callback) io_callback,
972 (void *) cmd);
973}
974
975static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
976{
977 u16 fibsize;
978 struct aac_read *readcmd;
979 aac_fib_init(fib);
980 readcmd = (struct aac_read *) fib_data(fib);
981 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +0000982 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800983 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
984 readcmd->count = cpu_to_le32(count * 512);
985
986 aac_build_sg(cmd, &readcmd->sg);
987 fibsize = sizeof(struct aac_read) +
988 ((le32_to_cpu(readcmd->sg.count) - 1) *
989 sizeof (struct sgentry));
990 BUG_ON (fibsize > (fib->dev->max_fib_size -
991 sizeof(struct aac_fibhdr)));
992 /*
993 * Now send the Fib to the adapter
994 */
995 return aac_fib_send(ContainerCommand,
996 fib,
997 fibsize,
998 FsaNormal,
999 0, 1,
1000 (fib_callback) io_callback,
1001 (void *) cmd);
1002}
1003
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001004static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001005{
1006 u16 fibsize;
1007 struct aac_raw_io *writecmd;
1008 aac_fib_init(fib);
1009 writecmd = (struct aac_raw_io *) fib_data(fib);
1010 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1011 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1012 writecmd->count = cpu_to_le32(count<<9);
1013 writecmd->cid = cpu_to_le16(scmd_id(cmd));
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001014 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1015 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001016 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
1017 cpu_to_le16(IO_TYPE_WRITE);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001018 writecmd->bpTotal = 0;
1019 writecmd->bpComplete = 0;
1020
1021 aac_build_sgraw(cmd, &writecmd->sg);
1022 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1023 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1024 /*
1025 * Now send the Fib to the adapter
1026 */
1027 return aac_fib_send(ContainerRawIo,
1028 fib,
1029 fibsize,
1030 FsaNormal,
1031 0, 1,
1032 (fib_callback) io_callback,
1033 (void *) cmd);
1034}
1035
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001036static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001037{
1038 u16 fibsize;
1039 struct aac_write64 *writecmd;
1040 aac_fib_init(fib);
1041 writecmd = (struct aac_write64 *) fib_data(fib);
1042 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1043 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1044 writecmd->sector_count = cpu_to_le16(count);
1045 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1046 writecmd->pad = 0;
1047 writecmd->flags = 0;
1048
1049 aac_build_sg64(cmd, &writecmd->sg);
1050 fibsize = sizeof(struct aac_write64) +
1051 ((le32_to_cpu(writecmd->sg.count) - 1) *
1052 sizeof (struct sgentry64));
1053 BUG_ON (fibsize > (fib->dev->max_fib_size -
1054 sizeof(struct aac_fibhdr)));
1055 /*
1056 * Now send the Fib to the adapter
1057 */
1058 return aac_fib_send(ContainerCommand64,
1059 fib,
1060 fibsize,
1061 FsaNormal,
1062 0, 1,
1063 (fib_callback) io_callback,
1064 (void *) cmd);
1065}
1066
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001067static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001068{
1069 u16 fibsize;
1070 struct aac_write *writecmd;
1071 aac_fib_init(fib);
1072 writecmd = (struct aac_write *) fib_data(fib);
1073 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001074 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001075 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1076 writecmd->count = cpu_to_le32(count * 512);
1077 writecmd->sg.count = cpu_to_le32(1);
1078 /* ->stable is not used - it did mean which type of write */
1079
1080 aac_build_sg(cmd, &writecmd->sg);
1081 fibsize = sizeof(struct aac_write) +
1082 ((le32_to_cpu(writecmd->sg.count) - 1) *
1083 sizeof (struct sgentry));
1084 BUG_ON (fibsize > (fib->dev->max_fib_size -
1085 sizeof(struct aac_fibhdr)));
1086 /*
1087 * Now send the Fib to the adapter
1088 */
1089 return aac_fib_send(ContainerCommand,
1090 fib,
1091 fibsize,
1092 FsaNormal,
1093 0, 1,
1094 (fib_callback) io_callback,
1095 (void *) cmd);
1096}
1097
1098static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1099{
1100 struct aac_srb * srbcmd;
1101 u32 flag;
1102 u32 timeout;
1103
1104 aac_fib_init(fib);
1105 switch(cmd->sc_data_direction){
1106 case DMA_TO_DEVICE:
1107 flag = SRB_DataOut;
1108 break;
1109 case DMA_BIDIRECTIONAL:
1110 flag = SRB_DataIn | SRB_DataOut;
1111 break;
1112 case DMA_FROM_DEVICE:
1113 flag = SRB_DataIn;
1114 break;
1115 case DMA_NONE:
1116 default: /* shuts up some versions of gcc */
1117 flag = SRB_NoDataXfer;
1118 break;
1119 }
1120
1121 srbcmd = (struct aac_srb*) fib_data(fib);
1122 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1123 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1124 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1125 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1126 srbcmd->flags = cpu_to_le32(flag);
1127 timeout = cmd->timeout_per_command/HZ;
1128 if (timeout == 0)
1129 timeout = 1;
1130 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1131 srbcmd->retry_limit = 0; /* Obsolete parameter */
1132 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1133 return srbcmd;
1134}
1135
1136static void aac_srb_callback(void *context, struct fib * fibptr);
1137
1138static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1139{
1140 u16 fibsize;
1141 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1142
1143 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001144 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001145
1146 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1147 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1148 /*
1149 * Build Scatter/Gather list
1150 */
1151 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1152 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1153 sizeof (struct sgentry64));
1154 BUG_ON (fibsize > (fib->dev->max_fib_size -
1155 sizeof(struct aac_fibhdr)));
1156
1157 /*
1158 * Now send the Fib to the adapter
1159 */
1160 return aac_fib_send(ScsiPortCommand64, fib,
1161 fibsize, FsaNormal, 0, 1,
1162 (fib_callback) aac_srb_callback,
1163 (void *) cmd);
1164}
1165
1166static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1167{
1168 u16 fibsize;
1169 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1170
1171 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001172 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001173
1174 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1175 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1176 /*
1177 * Build Scatter/Gather list
1178 */
1179 fibsize = sizeof (struct aac_srb) +
1180 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1181 sizeof (struct sgentry));
1182 BUG_ON (fibsize > (fib->dev->max_fib_size -
1183 sizeof(struct aac_fibhdr)));
1184
1185 /*
1186 * Now send the Fib to the adapter
1187 */
1188 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1189 (fib_callback) aac_srb_callback, (void *) cmd);
1190}
1191
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001192static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1193{
1194 if ((sizeof(dma_addr_t) > 4) &&
1195 (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) &&
1196 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1197 return FAILED;
1198 return aac_scsi_32(fib, cmd);
1199}
1200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201int aac_get_adapter_info(struct aac_dev* dev)
1202{
1203 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 int rcode;
1205 u32 tmp;
Mark Haverkamp84971732005-06-20 11:55:24 -07001206 struct aac_adapter_info *info;
1207 struct aac_bus_info *command;
1208 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001209
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001210 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 return -ENOMEM;
1212
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001213 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001214 info = (struct aac_adapter_info *) fib_data(fibptr);
1215 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001217 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001218 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001219 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001220 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07001221 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001222 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001223 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001225 if (rcode < 0) {
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001226 aac_fib_complete(fibptr);
1227 aac_fib_free(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001228 return rcode;
1229 }
1230 memcpy(&dev->adapter_info, info, sizeof(*info));
1231
1232 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001233 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001234
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001235 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001236
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001237 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001238
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001239 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001240
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001241 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001242 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001243 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001244 FsaNormal,
1245 1, 1,
1246 NULL,
1247 NULL);
1248
1249 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001250 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Mark Haverkamp84971732005-06-20 11:55:24 -07001253
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001254 /*
1255 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07001256 */
1257
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001258 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07001259
1260 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1261
1262 memset(bus_info, 0, sizeof(*bus_info));
1263
1264 command = (struct aac_bus_info *)bus_info;
1265
1266 command->Command = cpu_to_le32(VM_Ioctl);
1267 command->ObjType = cpu_to_le32(FT_DRIVE);
1268 command->MethodId = cpu_to_le32(1);
1269 command->CtlCmd = cpu_to_le32(GetBusInfo);
1270
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001271 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07001272 fibptr,
1273 sizeof (*bus_info),
1274 FsaNormal,
1275 1, 1,
1276 NULL, NULL);
1277
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001278 /* reasoned default */
1279 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07001280 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1281 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1282 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1283 }
1284
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001285 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001286 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001287 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1288 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001289 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 dev->id,
1291 tmp>>24,
1292 (tmp>>16)&0xff,
1293 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001294 le32_to_cpu(dev->adapter_info.kernelbuild),
1295 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1296 dev->supplement_adapter_info.BuildDate);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001297 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1298 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 dev->name, dev->id,
1300 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1301 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001302 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1303 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 dev->name, dev->id,
1305 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1306 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001307 buffer[0] = '\0';
1308 if (aac_show_serial_number(
1309 shost_to_class(dev->scsi_host_ptr), buffer))
1310 printk(KERN_INFO "%s%d: serial %s",
1311 dev->name, dev->id, buffer);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04001312 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1313 printk(KERN_INFO "%s%d: TSID %.*s\n",
1314 dev->name, dev->id,
1315 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1316 dev->supplement_adapter_info.VpdInfo.Tsid);
1317 }
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001318 if (!aac_check_reset || ((aac_check_reset != 1) &&
1319 (dev->supplement_adapter_info.SupportedOptions2 &
1320 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001321 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1322 dev->name, dev->id);
1323 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001326 dev->cache_protected = 0;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001327 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1328 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 dev->nondasd_support = 0;
1330 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001331 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 /*
1335 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1336 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1337 * force nondasd support on. If we decide to allow the non-dasd flag
1338 * additional changes changes will have to be made to support
1339 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1340 * changed to support the new dev->raid_scsi_mode flag instead of
1341 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1342 * function aac_detect will have to be modified where it sets up the
1343 * max number of channels based on the aac->nondasd_support flag only.
1344 */
1345 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1346 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1347 dev->nondasd_support = 1;
1348 dev->raid_scsi_mode = 1;
1349 }
1350 if (dev->raid_scsi_mode != 0)
1351 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1352 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001353
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001354 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001356 if(dev->nondasd_support != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1358 }
1359
1360 dev->dac_support = 0;
1361 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1362 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1363 dev->dac_support = 1;
1364 }
1365
1366 if(dacmode != -1) {
1367 dev->dac_support = (dacmode!=0);
1368 }
1369 if(dev->dac_support != 0) {
James Bottomley71e0f322005-10-28 11:21:10 -05001370 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1371 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1373 dev->name, dev->id);
James Bottomley71e0f322005-10-28 11:21:10 -05001374 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1375 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1377 dev->name, dev->id);
1378 dev->dac_support = 0;
1379 } else {
1380 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1381 dev->name, dev->id);
1382 rcode = -ENOMEM;
1383 }
1384 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001385 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001386 * Deal with configuring for the individualized limits of each packet
1387 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001388 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001389 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001390 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1391 ? aac_scsi_32_64
1392 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001393 : aac_scsi_32;
1394 if (dev->raw_io_interface) {
1395 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1396 ? aac_bounds_64
1397 : aac_bounds_32;
1398 dev->a_ops.adapter_read = aac_read_raw_io;
1399 dev->a_ops.adapter_write = aac_write_raw_io;
1400 } else {
1401 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001402 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001403 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001404 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1405 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001406 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001407 dev->a_ops.adapter_read = aac_read_block64;
1408 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001409 /*
1410 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001411 */
1412 dev->scsi_host_ptr->sg_tablesize =
1413 (dev->max_fib_size -
1414 sizeof(struct aac_fibhdr) -
1415 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001416 sizeof(struct sgentry64)) /
1417 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001418 } else {
1419 dev->a_ops.adapter_read = aac_read_block;
1420 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001421 }
1422 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1423 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1424 /*
1425 * Worst case size that could cause sg overflow when
1426 * we break up SG elements that are larger than 64KB.
1427 * Would be nice if we could tell the SCSI layer what
1428 * the maximum SG element size can be. Worst case is
1429 * (sg_tablesize-1) 4KB elements with one 64KB
1430 * element.
1431 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1432 */
1433 dev->scsi_host_ptr->max_sectors =
1434 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1435 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001438 aac_fib_complete(fibptr);
1439 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
1441 return rcode;
1442}
1443
1444
Mark Haverkampe53cb352005-08-03 15:39:09 -07001445static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
1447 struct aac_dev *dev;
1448 struct aac_read_reply *readreply;
1449 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 u32 cid;
1451
1452 scsicmd = (struct scsi_cmnd *) context;
1453
Mark Haverkamp03d44332007-03-15 10:27:45 -07001454 if (!aac_valid_context(scsicmd, fibptr))
1455 return;
1456
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001457 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001458 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001460 if (nblank(dprintk(x))) {
1461 u64 lba;
1462 switch (scsicmd->cmnd[0]) {
1463 case WRITE_6:
1464 case READ_6:
1465 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1466 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1467 break;
1468 case WRITE_16:
1469 case READ_16:
1470 lba = ((u64)scsicmd->cmnd[2] << 56) |
1471 ((u64)scsicmd->cmnd[3] << 48) |
1472 ((u64)scsicmd->cmnd[4] << 40) |
1473 ((u64)scsicmd->cmnd[5] << 32) |
1474 ((u64)scsicmd->cmnd[6] << 24) |
1475 (scsicmd->cmnd[7] << 16) |
1476 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1477 break;
1478 case WRITE_12:
1479 case READ_12:
1480 lba = ((u64)scsicmd->cmnd[2] << 24) |
1481 (scsicmd->cmnd[3] << 16) |
1482 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1483 break;
1484 default:
1485 lba = ((u64)scsicmd->cmnd[2] << 24) |
1486 (scsicmd->cmnd[3] << 16) |
1487 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1488 break;
1489 }
1490 printk(KERN_DEBUG
1491 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1492 smp_processor_id(), (unsigned long long)lba, jiffies);
1493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Eric Sesterhenn125e1872006-06-23 02:06:06 -07001495 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001496
1497 scsi_dma_unmap(scsicmd);
1498
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 readreply = (struct aac_read_reply *)fib_data(fibptr);
1500 if (le32_to_cpu(readreply->status) == ST_OK)
1501 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1502 else {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001503#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07001504 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001505 le32_to_cpu(readreply->status));
1506#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001508 set_sense(&dev->fsa_dev[cid].sense_data,
1509 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1510 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001512 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1513 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001515 aac_fib_complete(fibptr);
1516 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001518 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001521static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001523 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 u32 count;
1525 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 struct aac_dev *dev;
1527 struct fib * cmd_fibcontext;
1528
1529 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1530 /*
1531 * Get block address and transfer length
1532 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001533 switch (scsicmd->cmnd[0]) {
1534 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001535 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001537 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001538 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 count = scsicmd->cmnd[4];
1540
1541 if (count == 0)
1542 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001543 break;
1544 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001545 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001546
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001547 lba = ((u64)scsicmd->cmnd[2] << 56) |
1548 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001549 ((u64)scsicmd->cmnd[4] << 40) |
1550 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001551 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001552 (scsicmd->cmnd[7] << 16) |
1553 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001554 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001555 (scsicmd->cmnd[11] << 16) |
1556 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1557 break;
1558 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001559 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001560
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001561 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001562 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001563 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1564 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001565 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001566 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001567 break;
1568 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001569 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001571 lba = ((u64)scsicmd->cmnd[2] << 24) |
1572 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001573 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001575 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001577 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001578 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001579 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001580 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 /*
1582 * Alocate and initialize a Fib
1583 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001584 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 return -1;
1586 }
1587
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001588 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
1590 /*
1591 * Check that the command queued to the controller
1592 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001593 if (status == -EINPROGRESS) {
1594 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001596 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001597
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001598 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 /*
1600 * For some reason, the Fib didn't queue, return QUEUE_FULL
1601 */
1602 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001603 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001604 aac_fib_complete(cmd_fibcontext);
1605 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 return 0;
1607}
1608
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001609static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001611 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001613 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 struct aac_dev *dev;
1616 struct fib * cmd_fibcontext;
1617
1618 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1619 /*
1620 * Get block address and transfer length
1621 */
1622 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1623 {
1624 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1625 count = scsicmd->cmnd[4];
1626 if (count == 0)
1627 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001628 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001629 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001630 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001631
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001632 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001633 ((u64)scsicmd->cmnd[3] << 48) |
1634 ((u64)scsicmd->cmnd[4] << 40) |
1635 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001636 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001637 (scsicmd->cmnd[7] << 16) |
1638 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1639 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1640 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001641 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001642 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001643 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001644
1645 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1646 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1647 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1648 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001649 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001651 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001652 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001654 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001656 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001658 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001659 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 /*
1661 * Allocate and initialize a Fib then setup a BlockWrite command
1662 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001663 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 scsicmd->result = DID_ERROR << 16;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001665 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 return 0;
1667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001669 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 /*
1672 * Check that the command queued to the controller
1673 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001674 if (status == -EINPROGRESS) {
1675 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 return 0;
1677 }
1678
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001679 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 /*
1681 * For some reason, the Fib didn't queue, return QUEUE_FULL
1682 */
1683 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001684 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001686 aac_fib_complete(cmd_fibcontext);
1687 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 return 0;
1689}
1690
1691static void synchronize_callback(void *context, struct fib *fibptr)
1692{
1693 struct aac_synchronize_reply *synchronizereply;
1694 struct scsi_cmnd *cmd;
1695
1696 cmd = context;
1697
Mark Haverkamp03d44332007-03-15 10:27:45 -07001698 if (!aac_valid_context(cmd, fibptr))
1699 return;
1700
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001701 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 smp_processor_id(), jiffies));
1703 BUG_ON(fibptr == NULL);
1704
1705
1706 synchronizereply = fib_data(fibptr);
1707 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001708 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1710 else {
1711 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001712 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001713 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001714 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 "synchronize_callback: synchronize failed, status = %d\n",
1716 le32_to_cpu(synchronizereply->status));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001717 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001719 set_sense(&dev->fsa_dev[cid].sense_data,
1720 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1721 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001723 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1724 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 }
1726
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001727 aac_fib_complete(fibptr);
1728 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001729 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
1731
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001732static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733{
1734 int status;
1735 struct fib *cmd_fibcontext;
1736 struct aac_synchronize *synchronizecmd;
1737 struct scsi_cmnd *cmd;
1738 struct scsi_device *sdev = scsicmd->device;
1739 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001740 struct aac_dev *aac;
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001741 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1742 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1743 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 unsigned long flags;
1745
1746 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001747 * Wait for all outstanding queued commands to complete to this
1748 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 */
1750 spin_lock_irqsave(&sdev->list_lock, flags);
1751 list_for_each_entry(cmd, &sdev->cmd_list, list)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001752 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1753 u64 cmnd_lba;
1754 u32 cmnd_count;
1755
1756 if (cmd->cmnd[0] == WRITE_6) {
1757 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1758 (cmd->cmnd[2] << 8) |
1759 cmd->cmnd[3];
1760 cmnd_count = cmd->cmnd[4];
1761 if (cmnd_count == 0)
1762 cmnd_count = 256;
1763 } else if (cmd->cmnd[0] == WRITE_16) {
1764 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1765 ((u64)cmd->cmnd[3] << 48) |
1766 ((u64)cmd->cmnd[4] << 40) |
1767 ((u64)cmd->cmnd[5] << 32) |
1768 ((u64)cmd->cmnd[6] << 24) |
1769 (cmd->cmnd[7] << 16) |
1770 (cmd->cmnd[8] << 8) |
1771 cmd->cmnd[9];
1772 cmnd_count = (cmd->cmnd[10] << 24) |
1773 (cmd->cmnd[11] << 16) |
1774 (cmd->cmnd[12] << 8) |
1775 cmd->cmnd[13];
1776 } else if (cmd->cmnd[0] == WRITE_12) {
1777 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1778 (cmd->cmnd[3] << 16) |
1779 (cmd->cmnd[4] << 8) |
1780 cmd->cmnd[5];
1781 cmnd_count = (cmd->cmnd[6] << 24) |
1782 (cmd->cmnd[7] << 16) |
1783 (cmd->cmnd[8] << 8) |
1784 cmd->cmnd[9];
1785 } else if (cmd->cmnd[0] == WRITE_10) {
1786 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1787 (cmd->cmnd[3] << 16) |
1788 (cmd->cmnd[4] << 8) |
1789 cmd->cmnd[5];
1790 cmnd_count = (cmd->cmnd[7] << 8) |
1791 cmd->cmnd[8];
1792 } else
1793 continue;
1794 if (((cmnd_lba + cmnd_count) < lba) ||
1795 (count && ((lba + count) < cmnd_lba)))
1796 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 ++active;
1798 break;
1799 }
1800
1801 spin_unlock_irqrestore(&sdev->list_lock, flags);
1802
1803 /*
1804 * Yield the processor (requeue for later)
1805 */
1806 if (active)
1807 return SCSI_MLQUEUE_DEVICE_BUSY;
1808
Salyzyn, Markf8583172007-10-30 15:50:49 -04001809 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001810 if (aac->in_reset)
1811 return SCSI_MLQUEUE_HOST_BUSY;
1812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001814 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001816 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 return SCSI_MLQUEUE_HOST_BUSY;
1818
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001819 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
1821 synchronizecmd = fib_data(cmd_fibcontext);
1822 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1823 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001824 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001825 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1827
1828 /*
1829 * Now send the Fib to the adapter
1830 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001831 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 cmd_fibcontext,
1833 sizeof(struct aac_synchronize),
1834 FsaNormal,
1835 0, 1,
1836 (fib_callback)synchronize_callback,
1837 (void *)scsicmd);
1838
1839 /*
1840 * Check that the command queued to the controller
1841 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001842 if (status == -EINPROGRESS) {
1843 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001845 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001847 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001848 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1849 aac_fib_complete(cmd_fibcontext);
1850 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 return SCSI_MLQUEUE_HOST_BUSY;
1852}
1853
1854/**
1855 * aac_scsi_cmd() - Process SCSI command
1856 * @scsicmd: SCSI command block
1857 *
1858 * Emulate a SCSI command and queue the required request for the
1859 * aacraid firmware.
1860 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1863{
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001864 u32 cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 struct Scsi_Host *host = scsicmd->device->host;
1866 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1867 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001868
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001869 if (fsa_dev_ptr == NULL)
1870 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 /*
1872 * If the bus, id or lun is out of range, return fail
1873 * Test does not apply to ID 16, the pseudo id for the controller
1874 * itself.
1875 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001876 cid = scmd_id(scsicmd);
1877 if (cid != host->this_id) {
1878 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
1879 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08001880 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 scsicmd->result = DID_NO_CONNECT << 16;
1882 scsicmd->scsi_done(scsicmd);
1883 return 0;
1884 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 /*
1887 * If the target container doesn't exist, it may have
1888 * been newly created
1889 */
1890 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1891 switch (scsicmd->cmnd[0]) {
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001892 case SERVICE_ACTION_IN:
1893 if (!(dev->raw_io_interface) ||
1894 !(dev->raw_io_64) ||
1895 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1896 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 case INQUIRY:
1898 case READ_CAPACITY:
1899 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001900 if (dev->in_reset)
1901 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07001902 return _aac_probe_container(scsicmd,
1903 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 default:
1905 break;
1906 }
1907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 } else { /* check for physical non-dasd devices */
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001909 if (dev->nondasd_support || expose_physicals ||
1910 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001911 if (dev->in_reset)
1912 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 return aac_send_srb_fib(scsicmd);
1914 } else {
1915 scsicmd->result = DID_NO_CONNECT << 16;
1916 scsicmd->scsi_done(scsicmd);
1917 return 0;
1918 }
1919 }
1920 }
1921 /*
1922 * else Command for the controller itself
1923 */
1924 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001925 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 {
1927 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1928 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001929 set_sense(&dev->fsa_dev[cid].sense_data,
1930 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1931 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001933 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1934 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 scsicmd->scsi_done(scsicmd);
1936 return 0;
1937 }
1938
1939
1940 /* Handle commands here that don't really require going out to the adapter */
1941 switch (scsicmd->cmnd[0]) {
1942 case INQUIRY:
1943 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001944 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001946 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001947 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001949 if (scsicmd->cmnd[1] & 0x1) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001950 char *arr = (char *)&inq_data;
1951
1952 /* EVPD bit set */
1953 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
1954 INQD_PDT_PROC : INQD_PDT_DA;
1955 if (scsicmd->cmnd[2] == 0) {
1956 /* supported vital product data pages */
1957 arr[3] = 2;
1958 arr[4] = 0x0;
1959 arr[5] = 0x80;
1960 arr[1] = scsicmd->cmnd[2];
1961 aac_internal_transfer(scsicmd, &inq_data, 0,
1962 sizeof(inq_data));
1963 scsicmd->result = DID_OK << 16 |
1964 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1965 } else if (scsicmd->cmnd[2] == 0x80) {
1966 /* unit serial number page */
1967 arr[3] = setinqserial(dev, &arr[4],
1968 scmd_id(scsicmd));
1969 arr[1] = scsicmd->cmnd[2];
1970 aac_internal_transfer(scsicmd, &inq_data, 0,
1971 sizeof(inq_data));
1972 return aac_get_container_serial(scsicmd);
1973 } else {
1974 /* vpd page not implemented */
1975 scsicmd->result = DID_OK << 16 |
1976 COMMAND_COMPLETE << 8 |
1977 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001978 set_sense(&dev->fsa_dev[cid].sense_data,
1979 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
1980 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001981 memcpy(scsicmd->sense_buffer,
1982 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001983 min_t(size_t,
1984 sizeof(dev->fsa_dev[cid].sense_data),
1985 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001986 }
1987 scsicmd->scsi_done(scsicmd);
1988 return 0;
1989 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001990 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001991 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 */
1992 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001994 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 /*
1996 * Set the Vendor, Product, and Revision Level
1997 * see: <vendor>.c i.e. aac.c
1998 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001999 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07002000 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002001 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
2002 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2004 scsicmd->scsi_done(scsicmd);
2005 return 0;
2006 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002007 if (dev->in_reset)
2008 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07002009 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002010 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
2011 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002012 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002014 case SERVICE_ACTION_IN:
2015 if (!(dev->raw_io_interface) ||
2016 !(dev->raw_io_64) ||
2017 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2018 break;
2019 {
2020 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002021 char cp[13];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002022
2023 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2024 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002025 cp[0] = (capacity >> 56) & 0xff;
2026 cp[1] = (capacity >> 48) & 0xff;
2027 cp[2] = (capacity >> 40) & 0xff;
2028 cp[3] = (capacity >> 32) & 0xff;
2029 cp[4] = (capacity >> 24) & 0xff;
2030 cp[5] = (capacity >> 16) & 0xff;
2031 cp[6] = (capacity >> 8) & 0xff;
2032 cp[7] = (capacity >> 0) & 0xff;
2033 cp[8] = 0;
2034 cp[9] = 0;
2035 cp[10] = 2;
2036 cp[11] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002037 cp[12] = 0;
2038 aac_internal_transfer(scsicmd, cp, 0,
Mark Haverkamp1241f352006-03-27 09:44:23 -08002039 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002040 if (sizeof(cp) < scsicmd->cmnd[13]) {
2041 unsigned int len, offset = sizeof(cp);
2042
2043 memset(cp, 0, offset);
2044 do {
Mark Haverkamp1241f352006-03-27 09:44:23 -08002045 len = min_t(size_t, scsicmd->cmnd[13] - offset,
2046 sizeof(cp));
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002047 aac_internal_transfer(scsicmd, cp, offset, len);
2048 } while ((offset += len) < scsicmd->cmnd[13]);
2049 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002050
2051 /* Do not cache partition table for arrays */
2052 scsicmd->device->removable = 1;
2053
2054 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2055 scsicmd->scsi_done(scsicmd);
2056
2057 return 0;
2058 }
2059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 case READ_CAPACITY:
2061 {
2062 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002063 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002066 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 capacity = fsa_dev_ptr[cid].size - 1;
2068 else
2069 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002070
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 cp[0] = (capacity >> 24) & 0xff;
2072 cp[1] = (capacity >> 16) & 0xff;
2073 cp[2] = (capacity >> 8) & 0xff;
2074 cp[3] = (capacity >> 0) & 0xff;
2075 cp[4] = 0;
2076 cp[5] = 0;
2077 cp[6] = 2;
2078 cp[7] = 0;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002079 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002080 /* Do not cache partition table for arrays */
2081 scsicmd->device->removable = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
2083 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2084 scsicmd->scsi_done(scsicmd);
2085
2086 return 0;
2087 }
2088
2089 case MODE_SENSE:
2090 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002091 char mode_buf[7];
2092 int mode_buf_length = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
2094 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 mode_buf[0] = 3; /* Mode data length */
2096 mode_buf[1] = 0; /* Medium type - default */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002097 mode_buf[2] = 0; /* Device-specific param,
2098 bit 8: 0/1 = write enabled/protected
2099 bit 4: 0/1 = FUA enabled */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002100 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002101 mode_buf[2] = 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 mode_buf[3] = 0; /* Block descriptor length */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002103 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2104 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2105 mode_buf[0] = 6;
2106 mode_buf[4] = 8;
2107 mode_buf[5] = 1;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002108 mode_buf[6] = ((aac_cache & 6) == 2)
2109 ? 0 : 0x04; /* WCE */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002110 mode_buf_length = 7;
2111 if (mode_buf_length > scsicmd->cmnd[4])
2112 mode_buf_length = scsicmd->cmnd[4];
2113 }
2114 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2116 scsicmd->scsi_done(scsicmd);
2117
2118 return 0;
2119 }
2120 case MODE_SENSE_10:
2121 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002122 char mode_buf[11];
2123 int mode_buf_length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
2125 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 mode_buf[0] = 0; /* Mode data length (MSB) */
2127 mode_buf[1] = 6; /* Mode data length (LSB) */
2128 mode_buf[2] = 0; /* Medium type - default */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002129 mode_buf[3] = 0; /* Device-specific param,
2130 bit 8: 0/1 = write enabled/protected
2131 bit 4: 0/1 = FUA enabled */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002132 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002133 mode_buf[3] = 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 mode_buf[4] = 0; /* reserved */
2135 mode_buf[5] = 0; /* reserved */
2136 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2137 mode_buf[7] = 0; /* Block descriptor length (LSB) */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002138 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2139 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2140 mode_buf[1] = 9;
2141 mode_buf[8] = 8;
2142 mode_buf[9] = 1;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002143 mode_buf[10] = ((aac_cache & 6) == 2)
2144 ? 0 : 0x04; /* WCE */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002145 mode_buf_length = 11;
2146 if (mode_buf_length > scsicmd->cmnd[8])
2147 mode_buf_length = scsicmd->cmnd[8];
2148 }
2149 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
2151 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2152 scsicmd->scsi_done(scsicmd);
2153
2154 return 0;
2155 }
2156 case REQUEST_SENSE:
2157 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2158 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2159 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2160 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2161 scsicmd->scsi_done(scsicmd);
2162 return 0;
2163
2164 case ALLOW_MEDIUM_REMOVAL:
2165 dprintk((KERN_DEBUG "LOCK command.\n"));
2166 if (scsicmd->cmnd[4])
2167 fsa_dev_ptr[cid].locked = 1;
2168 else
2169 fsa_dev_ptr[cid].locked = 0;
2170
2171 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2172 scsicmd->scsi_done(scsicmd);
2173 return 0;
2174 /*
2175 * These commands are all No-Ops
2176 */
2177 case TEST_UNIT_READY:
2178 case RESERVE:
2179 case RELEASE:
2180 case REZERO_UNIT:
2181 case REASSIGN_BLOCKS:
2182 case SEEK_10:
2183 case START_STOP:
2184 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2185 scsicmd->scsi_done(scsicmd);
2186 return 0;
2187 }
2188
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002189 switch (scsicmd->cmnd[0])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 {
2191 case READ_6:
2192 case READ_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002193 case READ_12:
2194 case READ_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002195 if (dev->in_reset)
2196 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 /*
2198 * Hack to keep track of ordinal number of the device that
2199 * corresponds to a container. Needed to convert
2200 * containers to /dev/sd device names
2201 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002202
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002203 if (scsicmd->request->rq_disk)
2204 strlcpy(fsa_dev_ptr[cid].devname,
2205 scsicmd->request->rq_disk->disk_name,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002206 min(sizeof(fsa_dev_ptr[cid].devname),
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002207 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002208
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002209 return aac_read(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
2211 case WRITE_6:
2212 case WRITE_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002213 case WRITE_12:
2214 case WRITE_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002215 if (dev->in_reset)
2216 return -1;
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002217 return aac_write(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
2219 case SYNCHRONIZE_CACHE:
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002220 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2221 scsicmd->result = DID_OK << 16 |
2222 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2223 scsicmd->scsi_done(scsicmd);
2224 return 0;
2225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 /* Issue FIB to tell Firmware to flush it's cache */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002227 if ((aac_cache & 6) != 2)
2228 return aac_synchronize(scsicmd);
2229 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 default:
2231 /*
2232 * Unhandled commands
2233 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002234 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002236 set_sense(&dev->fsa_dev[cid].sense_data,
2237 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2238 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002240 min_t(size_t,
2241 sizeof(dev->fsa_dev[cid].sense_data),
2242 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 scsicmd->scsi_done(scsicmd);
2244 return 0;
2245 }
2246}
2247
2248static int query_disk(struct aac_dev *dev, void __user *arg)
2249{
2250 struct aac_query_disk qd;
2251 struct fsa_dev_info *fsa_dev_ptr;
2252
2253 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002254 if (!fsa_dev_ptr)
Mark Haverkamp651013552006-09-19 08:59:23 -07002255 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2257 return -EFAULT;
2258 if (qd.cnum == -1)
Mark Haverkampe5718772006-03-27 09:43:25 -08002259 qd.cnum = qd.id;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002260 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 {
2262 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2263 return -EINVAL;
2264 qd.instance = dev->scsi_host_ptr->host_no;
2265 qd.bus = 0;
2266 qd.id = CONTAINER_TO_ID(qd.cnum);
2267 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2268 }
2269 else return -EINVAL;
2270
Salyzyn, Markfd622b12007-07-17 10:59:19 -04002271 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2273 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2274
2275 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2276 qd.unmapped = 1;
2277 else
2278 qd.unmapped = 0;
2279
2280 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2281 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2282
2283 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2284 return -EFAULT;
2285 return 0;
2286}
2287
2288static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2289{
2290 struct aac_delete_disk dd;
2291 struct fsa_dev_info *fsa_dev_ptr;
2292
2293 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp651013552006-09-19 08:59:23 -07002294 if (!fsa_dev_ptr)
2295 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
2297 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2298 return -EFAULT;
2299
2300 if (dd.cnum >= dev->maximum_num_containers)
2301 return -EINVAL;
2302 /*
2303 * Mark this container as being deleted.
2304 */
2305 fsa_dev_ptr[dd.cnum].deleted = 1;
2306 /*
2307 * Mark the container as no longer valid
2308 */
2309 fsa_dev_ptr[dd.cnum].valid = 0;
2310 return 0;
2311}
2312
2313static int delete_disk(struct aac_dev *dev, void __user *arg)
2314{
2315 struct aac_delete_disk dd;
2316 struct fsa_dev_info *fsa_dev_ptr;
2317
2318 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002319 if (!fsa_dev_ptr)
Mark Haverkamp651013552006-09-19 08:59:23 -07002320 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
2322 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2323 return -EFAULT;
2324
2325 if (dd.cnum >= dev->maximum_num_containers)
2326 return -EINVAL;
2327 /*
2328 * If the container is locked, it can not be deleted by the API.
2329 */
2330 if (fsa_dev_ptr[dd.cnum].locked)
2331 return -EBUSY;
2332 else {
2333 /*
2334 * Mark the container as no longer being valid.
2335 */
2336 fsa_dev_ptr[dd.cnum].valid = 0;
2337 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2338 return 0;
2339 }
2340}
2341
2342int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2343{
2344 switch (cmd) {
2345 case FSACTL_QUERY_DISK:
2346 return query_disk(dev, arg);
2347 case FSACTL_DELETE_DISK:
2348 return delete_disk(dev, arg);
2349 case FSACTL_FORCE_DELETE_DISK:
2350 return force_delete_disk(dev, arg);
2351 case FSACTL_GET_CONTAINERS:
2352 return aac_get_containers(dev);
2353 default:
2354 return -ENOTTY;
2355 }
2356}
2357
2358/**
2359 *
2360 * aac_srb_callback
2361 * @context: the context set in the fib - here it is scsi cmd
2362 * @fibptr: pointer to the fib
2363 *
2364 * Handles the completion of a scsi command to a non dasd device
2365 *
2366 */
2367
2368static void aac_srb_callback(void *context, struct fib * fibptr)
2369{
2370 struct aac_dev *dev;
2371 struct aac_srb_reply *srbreply;
2372 struct scsi_cmnd *scsicmd;
2373
2374 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07002375
2376 if (!aac_valid_context(scsicmd, fibptr))
2377 return;
2378
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002379 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002381 dev = fibptr->dev;
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2384
2385 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2386 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002387 * Calculate resid for sg
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002390 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2391 - le32_to_cpu(srbreply->data_xfer_length));
2392
2393 scsi_dma_unmap(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
2395 /*
2396 * First check the fib status
2397 */
2398
2399 if (le32_to_cpu(srbreply->status) != ST_OK){
2400 int len;
2401 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002402 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2403 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2405 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2406 }
2407
2408 /*
2409 * Next check the srb status
2410 */
2411 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2412 case SRB_STATUS_ERROR_RECOVERY:
2413 case SRB_STATUS_PENDING:
2414 case SRB_STATUS_SUCCESS:
Mark Haverkampbb08f922006-02-01 09:30:44 -08002415 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 break;
2417 case SRB_STATUS_DATA_OVERRUN:
2418 switch(scsicmd->cmnd[0]){
2419 case READ_6:
2420 case WRITE_6:
2421 case READ_10:
2422 case WRITE_10:
2423 case READ_12:
2424 case WRITE_12:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002425 case READ_16:
2426 case WRITE_16:
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002427 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2429 } else {
2430 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2431 }
2432 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2433 break;
2434 case INQUIRY: {
Mark Haverkampbb08f922006-02-01 09:30:44 -08002435 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 break;
2437 }
2438 default:
2439 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2440 break;
2441 }
2442 break;
2443 case SRB_STATUS_ABORTED:
2444 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2445 break;
2446 case SRB_STATUS_ABORT_FAILED:
2447 // Not sure about this one - but assuming the hba was trying to abort for some reason
2448 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2449 break;
2450 case SRB_STATUS_PARITY_ERROR:
2451 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2452 break;
2453 case SRB_STATUS_NO_DEVICE:
2454 case SRB_STATUS_INVALID_PATH_ID:
2455 case SRB_STATUS_INVALID_TARGET_ID:
2456 case SRB_STATUS_INVALID_LUN:
2457 case SRB_STATUS_SELECTION_TIMEOUT:
2458 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2459 break;
2460
2461 case SRB_STATUS_COMMAND_TIMEOUT:
2462 case SRB_STATUS_TIMEOUT:
2463 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2464 break;
2465
2466 case SRB_STATUS_BUSY:
Salyzyn, Mark760af102007-06-19 11:41:21 -04002467 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 break;
2469
2470 case SRB_STATUS_BUS_RESET:
2471 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2472 break;
2473
2474 case SRB_STATUS_MESSAGE_REJECTED:
2475 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2476 break;
2477 case SRB_STATUS_REQUEST_FLUSHED:
2478 case SRB_STATUS_ERROR:
2479 case SRB_STATUS_INVALID_REQUEST:
2480 case SRB_STATUS_REQUEST_SENSE_FAILED:
2481 case SRB_STATUS_NO_HBA:
2482 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2483 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2484 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2485 case SRB_STATUS_DELAYED_RETRY:
2486 case SRB_STATUS_BAD_FUNCTION:
2487 case SRB_STATUS_NOT_STARTED:
2488 case SRB_STATUS_NOT_IN_USE:
2489 case SRB_STATUS_FORCE_ABORT:
2490 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2491 default:
2492#ifdef AAC_DETAILED_STATUS_INFO
2493 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2494 le32_to_cpu(srbreply->srb_status) & 0x3F,
2495 aac_get_status_string(
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002496 le32_to_cpu(srbreply->srb_status) & 0x3F),
2497 scsicmd->cmnd[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 le32_to_cpu(srbreply->scsi_status));
2499#endif
2500 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2501 break;
2502 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002503 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 int len;
2505 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002506 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2507 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002509 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2510 le32_to_cpu(srbreply->status), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511#endif
2512 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 }
2514 /*
2515 * OR in the scsi status (already shifted up a bit)
2516 */
2517 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2518
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002519 aac_fib_complete(fibptr);
2520 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002521 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522}
2523
2524/**
2525 *
2526 * aac_send_scb_fib
2527 * @scsicmd: the scsi command block
2528 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002529 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 * scsicmd passed in.
2531 */
2532
2533static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2534{
2535 struct fib* cmd_fibcontext;
2536 struct aac_dev* dev;
2537 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Mark Haverkamp84971732005-06-20 11:55:24 -07002539 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08002540 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07002541 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 scsicmd->result = DID_NO_CONNECT << 16;
2543 scsicmd->scsi_done(scsicmd);
2544 return 0;
2545 }
2546
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 /*
2548 * Allocate and initialize a Fib then setup a BlockWrite command
2549 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002550 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 return -1;
2552 }
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002553 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 /*
2556 * Check that the command queued to the controller
2557 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002558 if (status == -EINPROGRESS) {
2559 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 return 0;
2561 }
2562
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002563 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2564 aac_fib_complete(cmd_fibcontext);
2565 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
2567 return -1;
2568}
2569
2570static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2571{
2572 struct aac_dev *dev;
2573 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002574 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
2576 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2577 // Get rid of old data
2578 psg->count = 0;
2579 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002580 psg->sg[0].count = 0;
2581
2582 nseg = scsi_dma_map(scsicmd);
2583 BUG_ON(nseg < 0);
2584 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 struct scatterlist *sg;
2586 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002588 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002590 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2592 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2593 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 }
2595 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002596 if (byte_count > scsi_bufflen(scsicmd)) {
2597 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2598 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002599 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002600 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 }
2602 /* Check for command underflow */
2603 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2604 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2605 byte_count, scsicmd->underflow);
2606 }
2607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 return byte_count;
2609}
2610
2611
2612static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2613{
2614 struct aac_dev *dev;
2615 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002616 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002617 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
2619 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2620 // Get rid of old data
2621 psg->count = 0;
2622 psg->sg[0].addr[0] = 0;
2623 psg->sg[0].addr[1] = 0;
2624 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002625
2626 nseg = scsi_dma_map(scsicmd);
2627 BUG_ON(nseg < 0);
2628 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 struct scatterlist *sg;
2630 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002632 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp1241f352006-03-27 09:44:23 -08002633 int count = sg_dma_len(sg);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002634 addr = sg_dma_address(sg);
2635 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2636 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
Mark Haverkamp1241f352006-03-27 09:44:23 -08002637 psg->sg[i].count = cpu_to_le32(count);
2638 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002640 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002642 if (byte_count > scsi_bufflen(scsicmd)) {
2643 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2644 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002645 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002646 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 }
2648 /* Check for command underflow */
2649 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2650 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2651 byte_count, scsicmd->underflow);
2652 }
2653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 return byte_count;
2655}
2656
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002657static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2658{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002659 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002660 int nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002661
2662 // Get rid of old data
2663 psg->count = 0;
2664 psg->sg[0].next = 0;
2665 psg->sg[0].prev = 0;
2666 psg->sg[0].addr[0] = 0;
2667 psg->sg[0].addr[1] = 0;
2668 psg->sg[0].count = 0;
2669 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002670
2671 nseg = scsi_dma_map(scsicmd);
2672 BUG_ON(nseg < 0);
2673 if (nseg) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002674 struct scatterlist *sg;
2675 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002676
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002677 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002678 int count = sg_dma_len(sg);
2679 u64 addr = sg_dma_address(sg);
2680 psg->sg[i].next = 0;
2681 psg->sg[i].prev = 0;
2682 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2683 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2684 psg->sg[i].count = cpu_to_le32(count);
2685 psg->sg[i].flags = 0;
2686 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002687 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002688 psg->count = cpu_to_le32(nseg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002689 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002690 if (byte_count > scsi_bufflen(scsicmd)) {
2691 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2692 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002693 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002694 byte_count = scsi_bufflen(scsicmd);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002695 }
2696 /* Check for command underflow */
2697 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2698 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2699 byte_count, scsicmd->underflow);
2700 }
2701 }
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002702 return byte_count;
2703}
2704
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705#ifdef AAC_DETAILED_STATUS_INFO
2706
2707struct aac_srb_status_info {
2708 u32 status;
2709 char *str;
2710};
2711
2712
2713static struct aac_srb_status_info srb_status_info[] = {
2714 { SRB_STATUS_PENDING, "Pending Status"},
2715 { SRB_STATUS_SUCCESS, "Success"},
2716 { SRB_STATUS_ABORTED, "Aborted Command"},
2717 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07002718 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 { SRB_STATUS_BUSY, "Device Busy"},
2720 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2721 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2722 { SRB_STATUS_NO_DEVICE, "No Device"},
2723 { SRB_STATUS_TIMEOUT, "Timeout"},
2724 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2725 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2726 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2727 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2728 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2729 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2730 { SRB_STATUS_NO_HBA, "No HBA"},
2731 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2732 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2733 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2734 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2735 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2736 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07002737 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2739 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2740 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2741 { SRB_STATUS_NOT_STARTED, "Not Started"},
2742 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002743 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2745 { 0xff, "Unknown Error"}
2746};
2747
2748char *aac_get_status_string(u32 status)
2749{
2750 int i;
2751
Tobias Klauser6391a112006-06-08 22:23:48 -07002752 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2753 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
2756 return "Bad Status Code";
2757}
2758
2759#endif