blob: 2dbfbe3cf453c1dcbda3888deb61226890a88a70 [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>
Matthias Gehre910638a2006-03-28 01:56:48 -080034#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/semaphore.h>
36#include <asm/uaccess.h>
37
38#include <scsi/scsi.h>
39#include <scsi/scsi_cmnd.h>
40#include <scsi/scsi_device.h>
41#include <scsi/scsi_host.h>
42
43#include "aacraid.h"
44
45/* values for inqd_pdt: Peripheral device type in plain English */
46#define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
47#define INQD_PDT_PROC 0x03 /* Processor device */
48#define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
49#define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
50#define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
51#define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
52
53#define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
54#define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*
57 * Sense codes
58 */
59
60#define SENCODE_NO_SENSE 0x00
61#define SENCODE_END_OF_DATA 0x00
62#define SENCODE_BECOMING_READY 0x04
63#define SENCODE_INIT_CMD_REQUIRED 0x04
64#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65#define SENCODE_INVALID_COMMAND 0x20
66#define SENCODE_LBA_OUT_OF_RANGE 0x21
67#define SENCODE_INVALID_CDB_FIELD 0x24
68#define SENCODE_LUN_NOT_SUPPORTED 0x25
69#define SENCODE_INVALID_PARAM_FIELD 0x26
70#define SENCODE_PARAM_NOT_SUPPORTED 0x26
71#define SENCODE_PARAM_VALUE_INVALID 0x26
72#define SENCODE_RESET_OCCURRED 0x29
73#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76#define SENCODE_DIAGNOSTIC_FAILURE 0x40
77#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78#define SENCODE_INVALID_MESSAGE_ERROR 0x49
79#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80#define SENCODE_OVERLAPPED_COMMAND 0x4E
81
82/*
83 * Additional sense codes
84 */
85
86#define ASENCODE_NO_SENSE 0x00
87#define ASENCODE_END_OF_DATA 0x05
88#define ASENCODE_BECOMING_READY 0x01
89#define ASENCODE_INIT_CMD_REQUIRED 0x02
90#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91#define ASENCODE_INVALID_COMMAND 0x00
92#define ASENCODE_LBA_OUT_OF_RANGE 0x00
93#define ASENCODE_INVALID_CDB_FIELD 0x00
94#define ASENCODE_LUN_NOT_SUPPORTED 0x00
95#define ASENCODE_INVALID_PARAM_FIELD 0x00
96#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97#define ASENCODE_PARAM_VALUE_INVALID 0x02
98#define ASENCODE_RESET_OCCURRED 0x00
99#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106#define ASENCODE_OVERLAPPED_COMMAND 0x00
107
108#define BYTE0(x) (unsigned char)(x)
109#define BYTE1(x) (unsigned char)((x) >> 8)
110#define BYTE2(x) (unsigned char)((x) >> 16)
111#define BYTE3(x) (unsigned char)((x) >> 24)
112
113/*------------------------------------------------------------------------------
114 * S T R U C T S / T Y P E D E F S
115 *----------------------------------------------------------------------------*/
116/* SCSI inquiry data */
117struct inquiry_data {
118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq; /* RMB | Device Type Qualifier */
120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len; /* Additional length (n-4) */
123 u8 inqd_pad1[2];/* Reserved - must be zero */
124 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
125 u8 inqd_vid[8]; /* Vendor ID */
126 u8 inqd_pid[16];/* Product ID */
127 u8 inqd_prl[4]; /* Product Revision Level */
128};
129
130/*
131 * M O D U L E G L O B A L S
132 */
133
134static 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
144 */
145
146static int nondasd = -1;
147static int dacmode = -1;
148
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400149int aac_commit = -1;
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700150int startup_timeout = 180;
151int aif_timeout = 120;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800153module_param(nondasd, int, S_IRUGO|S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800155module_param(dacmode, int, S_IRUGO|S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400157module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158MODULE_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 -0700159module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
160MODULE_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.");
161module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
162MODULE_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 -0700163
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700164int numacb = -1;
165module_param(numacb, int, S_IRUGO|S_IWUSR);
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800166MODULE_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 -0700167
168int acbsize = -1;
169module_param(acbsize, int, S_IRUGO|S_IWUSR);
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800170MODULE_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 -0700171
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800172int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700173module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800174MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700175
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400176int aac_reset_devices = 0;
177module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
178MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700179
180static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
181 struct fib *fibptr) {
182 struct scsi_device *device;
183
184 if (unlikely(!scsicmd || !scsicmd->scsi_done )) {
185 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"))
186;
187 aac_fib_complete(fibptr);
188 aac_fib_free(fibptr);
189 return 0;
190 }
191 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
192 device = scsicmd->device;
193 if (unlikely(!device || !scsi_device_online(device))) {
194 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
195 aac_fib_complete(fibptr);
196 aac_fib_free(fibptr);
197 return 0;
198 }
199 return 1;
200}
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202/**
203 * aac_get_config_status - check the adapter configuration
204 * @common: adapter to query
205 *
206 * Query config status, and commit the configuration if needed.
207 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700208int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 int status = 0;
211 struct fib * fibptr;
212
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800213 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 return -ENOMEM;
215
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800216 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 {
218 struct aac_get_config_status *dinfo;
219 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
220
221 dinfo->command = cpu_to_le32(VM_ContainerConfig);
222 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
223 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
224 }
225
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800226 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 fibptr,
228 sizeof (struct aac_get_config_status),
229 FsaNormal,
230 1, 1,
231 NULL, NULL);
232 if (status < 0 ) {
233 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
234 } else {
235 struct aac_get_config_status_resp *reply
236 = (struct aac_get_config_status_resp *) fib_data(fibptr);
237 dprintk((KERN_WARNING
238 "aac_get_config_status: response=%d status=%d action=%d\n",
239 le32_to_cpu(reply->response),
240 le32_to_cpu(reply->status),
241 le32_to_cpu(reply->data.action)));
242 if ((le32_to_cpu(reply->response) != ST_OK) ||
243 (le32_to_cpu(reply->status) != CT_OK) ||
244 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
245 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
246 status = -EINVAL;
247 }
248 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800249 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
251 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400252 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800254 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 dinfo = (struct aac_commit_config *) fib_data(fibptr);
256
257 dinfo->command = cpu_to_le32(VM_ContainerConfig);
258 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
259
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800260 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 fibptr,
262 sizeof (struct aac_commit_config),
263 FsaNormal,
264 1, 1,
265 NULL, NULL);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800266 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400267 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 printk(KERN_WARNING
269 "aac_get_config_status: Foreign device configurations are being ignored\n");
270 }
271 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800272 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return status;
274}
275
276/**
277 * aac_get_containers - list containers
278 * @common: adapter to probe
279 *
280 * Make a list of all containers on this controller
281 */
282int aac_get_containers(struct aac_dev *dev)
283{
284 struct fsa_dev_info *fsa_dev_ptr;
285 u32 index;
286 int status = 0;
287 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 struct aac_get_container_count *dinfo;
289 struct aac_get_container_count_resp *dresp;
290 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
291
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800292 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 return -ENOMEM;
294
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800295 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
297 dinfo->command = cpu_to_le32(VM_ContainerConfig);
298 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
299
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800300 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 fibptr,
302 sizeof (struct aac_get_container_count),
303 FsaNormal,
304 1, 1,
305 NULL, NULL);
306 if (status >= 0) {
307 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
308 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800309 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700311 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
314 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700315 fsa_dev_ptr = kmalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
316 GFP_KERNEL);
317 if (!fsa_dev_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 memset(fsa_dev_ptr, 0, sizeof(*fsa_dev_ptr) * maximum_num_containers);
320
321 dev->fsa_dev = fsa_dev_ptr;
322 dev->maximum_num_containers = maximum_num_containers;
323
Mark Haverkampfe76df42007-03-15 12:55:07 -0700324 for (index = 0; index < dev->maximum_num_containers; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 fsa_dev_ptr[index].devname[0] = '\0';
326
Mark Haverkampfe76df42007-03-15 12:55:07 -0700327 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Mark Haverkampfe76df42007-03-15 12:55:07 -0700329 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
331 break;
332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 /*
335 * If there are no more containers, then stop asking.
336 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700337 if (++index >= status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return status;
341}
342
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700343static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
344{
345 void *buf;
James Bottomleycab537d2007-05-16 10:06:39 -0400346 int transfer_len;
FUJITA Tomonori727eead2007-05-26 02:00:42 +0900347 struct scatterlist *sg = scsi_sglist(scsicmd);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700348
FUJITA Tomonori727eead2007-05-26 02:00:42 +0900349 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
350 transfer_len = min(sg->length, len + offset);
351
Salyzyn, Mark20235f32007-03-21 13:22:56 -0400352 transfer_len -= offset;
James Bottomleycab537d2007-05-16 10:06:39 -0400353 if (buf && transfer_len > 0)
Salyzyn, Mark20235f32007-03-21 13:22:56 -0400354 memcpy(buf + offset, data, transfer_len);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700355
FUJITA Tomonori727eead2007-05-26 02:00:42 +0900356 kunmap_atomic(buf - sg->offset, KM_IRQ0);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700357
358}
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360static void get_container_name_callback(void *context, struct fib * fibptr)
361{
362 struct aac_get_name_resp * get_name_reply;
363 struct scsi_cmnd * scsicmd;
364
365 scsicmd = (struct scsi_cmnd *) context;
366
Mark Haverkamp03d44332007-03-15 10:27:45 -0700367 if (!aac_valid_context(scsicmd, fibptr))
368 return;
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700371 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
374 /* Failure is irrelevant, using default value instead */
375 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
376 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700377 char *sp = get_name_reply->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
379 while (*sp == ' ')
380 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700381 if (*sp) {
382 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
383 int count = sizeof(d);
384 char *dp = d;
385 do {
386 *dp++ = (*sp) ? *sp++ : ' ';
387 } while (--count > 0);
388 aac_internal_transfer(scsicmd, d,
389 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
394
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800395 aac_fib_complete(fibptr);
396 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700397 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
400/**
401 * aac_get_container_name - get container name, none blocking.
402 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700403static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
405 int status;
406 struct aac_get_name *dinfo;
407 struct fib * cmd_fibcontext;
408 struct aac_dev * dev;
409
410 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
411
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800412 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return -ENOMEM;
414
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800415 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
417
418 dinfo->command = cpu_to_le32(VM_ContainerConfig);
419 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700420 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
422
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800423 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 cmd_fibcontext,
425 sizeof (struct aac_get_name),
426 FsaNormal,
427 0, 1,
428 (fib_callback) get_container_name_callback,
429 (void *) scsicmd);
430
431 /*
432 * Check that the command queued to the controller
433 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800434 if (status == -EINPROGRESS) {
435 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800439 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
440 aac_fib_complete(cmd_fibcontext);
441 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return -1;
443}
444
Mark Haverkampfe76df42007-03-15 12:55:07 -0700445static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
446{
447 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
448
449 if (fsa_dev_ptr[scmd_id(scsicmd)].valid)
450 return aac_scsi_cmd(scsicmd);
451
452 scsicmd->result = DID_NO_CONNECT << 16;
453 scsicmd->scsi_done(scsicmd);
454 return 0;
455}
456
457static int _aac_probe_container2(void * context, struct fib * fibptr)
458{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700459 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700460 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700461 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
462
463 if (!aac_valid_context(scsicmd, fibptr))
464 return 0;
465
466 fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700467
468 scsicmd->SCp.Status = 0;
469 if (fsa_dev_ptr) {
470 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
471 fsa_dev_ptr += scmd_id(scsicmd);
472
473 if ((le32_to_cpu(dresp->status) == ST_OK) &&
474 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
475 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
476 fsa_dev_ptr->valid = 1;
477 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
478 fsa_dev_ptr->size
479 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
480 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
481 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
482 }
483 if ((fsa_dev_ptr->valid & 1) == 0)
484 fsa_dev_ptr->valid = 0;
485 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
486 }
487 aac_fib_complete(fibptr);
488 aac_fib_free(fibptr);
489 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
490 scsicmd->SCp.ptr = NULL;
491 return (*callback)(scsicmd);
492}
493
494static int _aac_probe_container1(void * context, struct fib * fibptr)
495{
496 struct scsi_cmnd * scsicmd;
497 struct aac_mount * dresp;
498 struct aac_query_mount *dinfo;
499 int status;
500
501 dresp = (struct aac_mount *) fib_data(fibptr);
502 dresp->mnt[0].capacityhigh = 0;
503 if ((le32_to_cpu(dresp->status) != ST_OK) ||
Salyzyn, Mark4def7fa2007-04-13 08:35:25 -0400504 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700505 return _aac_probe_container2(context, fibptr);
506 scsicmd = (struct scsi_cmnd *) context;
507 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
508
Mark Haverkamp03d44332007-03-15 10:27:45 -0700509 if (!aac_valid_context(scsicmd, fibptr))
510 return 0;
511
Mark Haverkampfe76df42007-03-15 12:55:07 -0700512 aac_fib_init(fibptr);
513
514 dinfo = (struct aac_query_mount *)fib_data(fibptr);
515
516 dinfo->command = cpu_to_le32(VM_NameServe64);
517 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
518 dinfo->type = cpu_to_le32(FT_FILESYS);
519
520 status = aac_fib_send(ContainerCommand,
521 fibptr,
522 sizeof(struct aac_query_mount),
523 FsaNormal,
524 0, 1,
525 (fib_callback) _aac_probe_container2,
526 (void *) scsicmd);
527 /*
528 * Check that the command queued to the controller
529 */
530 if (status == -EINPROGRESS) {
531 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
532 return 0;
533 }
534 if (status < 0) {
535 /* Inherit results from VM_NameServe, if any */
536 dresp->status = cpu_to_le32(ST_OK);
537 return _aac_probe_container2(context, fibptr);
538 }
539 return 0;
540}
541
542static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
543{
544 struct fib * fibptr;
545 int status = -ENOMEM;
546
547 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
548 struct aac_query_mount *dinfo;
549
550 aac_fib_init(fibptr);
551
552 dinfo = (struct aac_query_mount *)fib_data(fibptr);
553
554 dinfo->command = cpu_to_le32(VM_NameServe);
555 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
556 dinfo->type = cpu_to_le32(FT_FILESYS);
557 scsicmd->SCp.ptr = (char *)callback;
558
559 status = aac_fib_send(ContainerCommand,
560 fibptr,
561 sizeof(struct aac_query_mount),
562 FsaNormal,
563 0, 1,
564 (fib_callback) _aac_probe_container1,
565 (void *) scsicmd);
566 /*
567 * Check that the command queued to the controller
568 */
569 if (status == -EINPROGRESS) {
570 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
571 return 0;
572 }
573 if (status < 0) {
574 scsicmd->SCp.ptr = NULL;
575 aac_fib_complete(fibptr);
576 aac_fib_free(fibptr);
577 }
578 }
579 if (status < 0) {
580 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
581 if (fsa_dev_ptr) {
582 fsa_dev_ptr += scmd_id(scsicmd);
583 if ((fsa_dev_ptr->valid & 1) == 0) {
584 fsa_dev_ptr->valid = 0;
585 return (*callback)(scsicmd);
586 }
587 }
588 }
589 return status;
590}
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800593 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 * @dev: device to query
595 * @cid: container identifier
596 *
597 * Queries the controller about the given volume. The volume information
598 * is updated in the struct fsa_dev_info structure rather than returned.
599 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700600static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
601{
602 scsicmd->device = NULL;
603 return 0;
604}
605
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800606int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700608 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
609 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Mark Haverkampfe76df42007-03-15 12:55:07 -0700612 if (!scsicmd || !scsidev) {
613 kfree(scsicmd);
614 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700615 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700617 scsicmd->list.next = NULL;
618 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))_aac_probe_container1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Mark Haverkampfe76df42007-03-15 12:55:07 -0700620 scsicmd->device = scsidev;
621 scsidev->sdev_state = 0;
622 scsidev->id = cid;
623 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Mark Haverkampfe76df42007-03-15 12:55:07 -0700625 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
626 while (scsicmd->device == scsidev)
627 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400628 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700629 status = scsicmd->SCp.Status;
630 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 return status;
632}
633
634/* Local Structure to set SCSI inquiry data strings */
635struct scsi_inq {
636 char vid[8]; /* Vendor ID */
637 char pid[16]; /* Product ID */
638 char prl[4]; /* Product Revision Level */
639};
640
641/**
642 * InqStrCopy - string merge
643 * @a: string to copy from
644 * @b: string to copy to
645 *
646 * Copy a String from one location to another
647 * without copying \0
648 */
649
650static void inqstrcpy(char *a, char *b)
651{
652
653 while(*a != (char)0)
654 *b++ = *a++;
655}
656
657static char *container_types[] = {
658 "None",
659 "Volume",
660 "Mirror",
661 "Stripe",
662 "RAID5",
663 "SSRW",
664 "SSRO",
665 "Morph",
666 "Legacy",
667 "RAID4",
668 "RAID10",
669 "RAID00",
670 "V-MIRRORS",
671 "PSEUDO R4",
672 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700673 "RAID5D",
674 "RAID5D0",
675 "RAID1E",
676 "RAID6",
677 "RAID60",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 "Unknown"
679};
680
681
682
683/* Function: setinqstr
684 *
685 * Arguments: [1] pointer to void [1] int
686 *
687 * Purpose: Sets SCSI inquiry data strings for vendor, product
688 * and revision level. Allows strings to be set in platform dependant
689 * files instead of in OS dependant driver source.
690 */
691
Mark Haverkamp794d0602005-10-24 10:51:53 -0700692static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
694 struct scsi_inq *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700697 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Mark Haverkamp794d0602005-10-24 10:51:53 -0700699 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
700 char * cp = dev->supplement_adapter_info.AdapterTypeText;
701 int c = sizeof(str->vid);
702 while (*cp && *cp != ' ' && --c)
703 ++cp;
704 c = *cp;
705 *cp = '\0';
706 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
707 str->vid);
708 *cp = c;
709 while (*cp && *cp != ' ')
710 ++cp;
711 while (*cp == ' ')
712 ++cp;
713 /* last six chars reserved for vol type */
714 c = 0;
715 if (strlen(cp) > sizeof(str->pid)) {
716 c = cp[sizeof(str->pid)];
717 cp[sizeof(str->pid)] = '\0';
718 }
719 inqstrcpy (cp, str->pid);
720 if (c)
721 cp[sizeof(str->pid)] = c;
722 } else {
723 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700724
725 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700726 /* last six chars reserved for vol type */
727 inqstrcpy (mp->model, str->pid);
728 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Tobias Klauser6391a112006-06-08 22:23:48 -0700730 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 char *findit = str->pid;
732
733 for ( ; *findit != ' '; findit++); /* walk till we find a space */
734 /* RAID is superfluous in the context of a RAID device */
735 if (memcmp(findit-4, "RAID", 4) == 0)
736 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700737 if (((findit - str->pid) + strlen(container_types[tindex]))
738 < (sizeof(str->pid) + sizeof(str->prl)))
739 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741 inqstrcpy ("V1.0", str->prl);
742}
743
Adrian Bunk 48338692005-04-25 19:45:58 -0700744static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
745 u8 a_sense_code, u8 incorrect_length,
746 u8 bit_pointer, u16 field_pointer,
747 u32 residue)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748{
749 sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */
750 sense_buf[1] = 0; /* Segment number, always zero */
751
752 if (incorrect_length) {
753 sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
754 sense_buf[3] = BYTE3(residue);
755 sense_buf[4] = BYTE2(residue);
756 sense_buf[5] = BYTE1(residue);
757 sense_buf[6] = BYTE0(residue);
758 } else
759 sense_buf[2] = sense_key; /* Sense key */
760
761 if (sense_key == ILLEGAL_REQUEST)
762 sense_buf[7] = 10; /* Additional sense length */
763 else
764 sense_buf[7] = 6; /* Additional sense length */
765
766 sense_buf[12] = sense_code; /* Additional sense code */
767 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
768 if (sense_key == ILLEGAL_REQUEST) {
769 sense_buf[15] = 0;
770
771 if (sense_code == SENCODE_INVALID_PARAM_FIELD)
772 sense_buf[15] = 0x80;/* Std sense key specific field */
773 /* Illegal parameter is in the parameter block */
774
775 if (sense_code == SENCODE_INVALID_CDB_FIELD)
776 sense_buf[15] = 0xc0;/* Std sense key specific field */
777 /* Illegal parameter is in the CDB block */
778 sense_buf[15] |= bit_pointer;
779 sense_buf[16] = field_pointer >> 8; /* MSB */
780 sense_buf[17] = field_pointer; /* LSB */
781 }
782}
783
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800784static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
785{
786 if (lba & 0xffffffff00000000LL) {
787 int cid = scmd_id(cmd);
788 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
789 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
790 SAM_STAT_CHECK_CONDITION;
791 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
792 HARDWARE_ERROR,
793 SENCODE_INTERNAL_TARGET_FAILURE,
794 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
795 0, 0);
796 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
797 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
798 ? sizeof(cmd->sense_buffer)
799 : sizeof(dev->fsa_dev[cid].sense_data));
800 cmd->scsi_done(cmd);
801 return 1;
802 }
803 return 0;
804}
805
806static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
807{
808 return 0;
809}
810
811static void io_callback(void *context, struct fib * fibptr);
812
813static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
814{
815 u16 fibsize;
816 struct aac_raw_io *readcmd;
817 aac_fib_init(fib);
818 readcmd = (struct aac_raw_io *) fib_data(fib);
819 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
820 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
821 readcmd->count = cpu_to_le32(count<<9);
822 readcmd->cid = cpu_to_le16(scmd_id(cmd));
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -0400823 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800824 readcmd->bpTotal = 0;
825 readcmd->bpComplete = 0;
826
827 aac_build_sgraw(cmd, &readcmd->sg);
828 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
829 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
830 /*
831 * Now send the Fib to the adapter
832 */
833 return aac_fib_send(ContainerRawIo,
834 fib,
835 fibsize,
836 FsaNormal,
837 0, 1,
838 (fib_callback) io_callback,
839 (void *) cmd);
840}
841
842static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
843{
844 u16 fibsize;
845 struct aac_read64 *readcmd;
846 aac_fib_init(fib);
847 readcmd = (struct aac_read64 *) fib_data(fib);
848 readcmd->command = cpu_to_le32(VM_CtHostRead64);
849 readcmd->cid = cpu_to_le16(scmd_id(cmd));
850 readcmd->sector_count = cpu_to_le16(count);
851 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
852 readcmd->pad = 0;
853 readcmd->flags = 0;
854
855 aac_build_sg64(cmd, &readcmd->sg);
856 fibsize = sizeof(struct aac_read64) +
857 ((le32_to_cpu(readcmd->sg.count) - 1) *
858 sizeof (struct sgentry64));
859 BUG_ON (fibsize > (fib->dev->max_fib_size -
860 sizeof(struct aac_fibhdr)));
861 /*
862 * Now send the Fib to the adapter
863 */
864 return aac_fib_send(ContainerCommand64,
865 fib,
866 fibsize,
867 FsaNormal,
868 0, 1,
869 (fib_callback) io_callback,
870 (void *) cmd);
871}
872
873static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
874{
875 u16 fibsize;
876 struct aac_read *readcmd;
877 aac_fib_init(fib);
878 readcmd = (struct aac_read *) fib_data(fib);
879 readcmd->command = cpu_to_le32(VM_CtBlockRead);
880 readcmd->cid = cpu_to_le16(scmd_id(cmd));
881 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
882 readcmd->count = cpu_to_le32(count * 512);
883
884 aac_build_sg(cmd, &readcmd->sg);
885 fibsize = sizeof(struct aac_read) +
886 ((le32_to_cpu(readcmd->sg.count) - 1) *
887 sizeof (struct sgentry));
888 BUG_ON (fibsize > (fib->dev->max_fib_size -
889 sizeof(struct aac_fibhdr)));
890 /*
891 * Now send the Fib to the adapter
892 */
893 return aac_fib_send(ContainerCommand,
894 fib,
895 fibsize,
896 FsaNormal,
897 0, 1,
898 (fib_callback) io_callback,
899 (void *) cmd);
900}
901
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -0400902static 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 -0800903{
904 u16 fibsize;
905 struct aac_raw_io *writecmd;
906 aac_fib_init(fib);
907 writecmd = (struct aac_raw_io *) fib_data(fib);
908 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
909 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
910 writecmd->count = cpu_to_le32(count<<9);
911 writecmd->cid = cpu_to_le16(scmd_id(cmd));
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -0400912 writecmd->flags = fua ?
913 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
914 cpu_to_le16(IO_TYPE_WRITE);
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800915 writecmd->bpTotal = 0;
916 writecmd->bpComplete = 0;
917
918 aac_build_sgraw(cmd, &writecmd->sg);
919 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
920 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
921 /*
922 * Now send the Fib to the adapter
923 */
924 return aac_fib_send(ContainerRawIo,
925 fib,
926 fibsize,
927 FsaNormal,
928 0, 1,
929 (fib_callback) io_callback,
930 (void *) cmd);
931}
932
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -0400933static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800934{
935 u16 fibsize;
936 struct aac_write64 *writecmd;
937 aac_fib_init(fib);
938 writecmd = (struct aac_write64 *) fib_data(fib);
939 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
940 writecmd->cid = cpu_to_le16(scmd_id(cmd));
941 writecmd->sector_count = cpu_to_le16(count);
942 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
943 writecmd->pad = 0;
944 writecmd->flags = 0;
945
946 aac_build_sg64(cmd, &writecmd->sg);
947 fibsize = sizeof(struct aac_write64) +
948 ((le32_to_cpu(writecmd->sg.count) - 1) *
949 sizeof (struct sgentry64));
950 BUG_ON (fibsize > (fib->dev->max_fib_size -
951 sizeof(struct aac_fibhdr)));
952 /*
953 * Now send the Fib to the adapter
954 */
955 return aac_fib_send(ContainerCommand64,
956 fib,
957 fibsize,
958 FsaNormal,
959 0, 1,
960 (fib_callback) io_callback,
961 (void *) cmd);
962}
963
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -0400964static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800965{
966 u16 fibsize;
967 struct aac_write *writecmd;
968 aac_fib_init(fib);
969 writecmd = (struct aac_write *) fib_data(fib);
970 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
971 writecmd->cid = cpu_to_le16(scmd_id(cmd));
972 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
973 writecmd->count = cpu_to_le32(count * 512);
974 writecmd->sg.count = cpu_to_le32(1);
975 /* ->stable is not used - it did mean which type of write */
976
977 aac_build_sg(cmd, &writecmd->sg);
978 fibsize = sizeof(struct aac_write) +
979 ((le32_to_cpu(writecmd->sg.count) - 1) *
980 sizeof (struct sgentry));
981 BUG_ON (fibsize > (fib->dev->max_fib_size -
982 sizeof(struct aac_fibhdr)));
983 /*
984 * Now send the Fib to the adapter
985 */
986 return aac_fib_send(ContainerCommand,
987 fib,
988 fibsize,
989 FsaNormal,
990 0, 1,
991 (fib_callback) io_callback,
992 (void *) cmd);
993}
994
995static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
996{
997 struct aac_srb * srbcmd;
998 u32 flag;
999 u32 timeout;
1000
1001 aac_fib_init(fib);
1002 switch(cmd->sc_data_direction){
1003 case DMA_TO_DEVICE:
1004 flag = SRB_DataOut;
1005 break;
1006 case DMA_BIDIRECTIONAL:
1007 flag = SRB_DataIn | SRB_DataOut;
1008 break;
1009 case DMA_FROM_DEVICE:
1010 flag = SRB_DataIn;
1011 break;
1012 case DMA_NONE:
1013 default: /* shuts up some versions of gcc */
1014 flag = SRB_NoDataXfer;
1015 break;
1016 }
1017
1018 srbcmd = (struct aac_srb*) fib_data(fib);
1019 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1020 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1021 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1022 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1023 srbcmd->flags = cpu_to_le32(flag);
1024 timeout = cmd->timeout_per_command/HZ;
1025 if (timeout == 0)
1026 timeout = 1;
1027 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1028 srbcmd->retry_limit = 0; /* Obsolete parameter */
1029 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1030 return srbcmd;
1031}
1032
1033static void aac_srb_callback(void *context, struct fib * fibptr);
1034
1035static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1036{
1037 u16 fibsize;
1038 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1039
1040 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001041 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001042
1043 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1044 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1045 /*
1046 * Build Scatter/Gather list
1047 */
1048 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1049 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1050 sizeof (struct sgentry64));
1051 BUG_ON (fibsize > (fib->dev->max_fib_size -
1052 sizeof(struct aac_fibhdr)));
1053
1054 /*
1055 * Now send the Fib to the adapter
1056 */
1057 return aac_fib_send(ScsiPortCommand64, fib,
1058 fibsize, FsaNormal, 0, 1,
1059 (fib_callback) aac_srb_callback,
1060 (void *) cmd);
1061}
1062
1063static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1064{
1065 u16 fibsize;
1066 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1067
1068 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001069 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001070
1071 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1072 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1073 /*
1074 * Build Scatter/Gather list
1075 */
1076 fibsize = sizeof (struct aac_srb) +
1077 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1078 sizeof (struct sgentry));
1079 BUG_ON (fibsize > (fib->dev->max_fib_size -
1080 sizeof(struct aac_fibhdr)));
1081
1082 /*
1083 * Now send the Fib to the adapter
1084 */
1085 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1086 (fib_callback) aac_srb_callback, (void *) cmd);
1087}
1088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089int aac_get_adapter_info(struct aac_dev* dev)
1090{
1091 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 int rcode;
1093 u32 tmp;
Mark Haverkamp84971732005-06-20 11:55:24 -07001094 struct aac_adapter_info *info;
1095 struct aac_bus_info *command;
1096 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001097
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001098 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 return -ENOMEM;
1100
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001101 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001102 info = (struct aac_adapter_info *) fib_data(fibptr);
1103 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001105 rcode = aac_fib_send(RequestAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001106 fibptr,
1107 sizeof(*info),
1108 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07001109 -1, 1, /* First `interrupt' command uses special wait */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001110 NULL,
1111 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001113 if (rcode < 0) {
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001114 aac_fib_complete(fibptr);
1115 aac_fib_free(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001116 return rcode;
1117 }
1118 memcpy(&dev->adapter_info, info, sizeof(*info));
1119
1120 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
1121 struct aac_supplement_adapter_info * info;
1122
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001123 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001124
1125 info = (struct aac_supplement_adapter_info *) fib_data(fibptr);
1126
1127 memset(info,0,sizeof(*info));
1128
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001129 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001130 fibptr,
1131 sizeof(*info),
1132 FsaNormal,
1133 1, 1,
1134 NULL,
1135 NULL);
1136
1137 if (rcode >= 0)
1138 memcpy(&dev->supplement_adapter_info, info, sizeof(*info));
1139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Mark Haverkamp84971732005-06-20 11:55:24 -07001141
1142 /*
1143 * GetBusInfo
1144 */
1145
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001146 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07001147
1148 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1149
1150 memset(bus_info, 0, sizeof(*bus_info));
1151
1152 command = (struct aac_bus_info *)bus_info;
1153
1154 command->Command = cpu_to_le32(VM_Ioctl);
1155 command->ObjType = cpu_to_le32(FT_DRIVE);
1156 command->MethodId = cpu_to_le32(1);
1157 command->CtlCmd = cpu_to_le32(GetBusInfo);
1158
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001159 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07001160 fibptr,
1161 sizeof (*bus_info),
1162 FsaNormal,
1163 1, 1,
1164 NULL, NULL);
1165
1166 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1167 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1168 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1169 }
1170
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001171 if (!dev->in_reset) {
1172 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1173 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 dev->name,
1175 dev->id,
1176 tmp>>24,
1177 (tmp>>16)&0xff,
1178 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001179 le32_to_cpu(dev->adapter_info.kernelbuild),
1180 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1181 dev->supplement_adapter_info.BuildDate);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001182 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1183 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 dev->name, dev->id,
1185 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1186 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001187 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1188 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 dev->name, dev->id,
1190 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1191 le32_to_cpu(dev->adapter_info.biosbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001192 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
1193 printk(KERN_INFO "%s%d: serial %x\n",
1194 dev->name, dev->id,
1195 le32_to_cpu(dev->adapter_info.serial[0]));
Salyzyn, Marka45c8632007-03-28 13:44:54 -04001196 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1197 printk(KERN_INFO "%s%d: TSID %.*s\n",
1198 dev->name, dev->id,
1199 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1200 dev->supplement_adapter_info.VpdInfo.Tsid);
1201 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
1204 dev->nondasd_support = 0;
1205 dev->raid_scsi_mode = 0;
1206 if(dev->adapter_info.options & AAC_OPT_NONDASD){
1207 dev->nondasd_support = 1;
1208 }
1209
1210 /*
1211 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1212 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1213 * force nondasd support on. If we decide to allow the non-dasd flag
1214 * additional changes changes will have to be made to support
1215 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1216 * changed to support the new dev->raid_scsi_mode flag instead of
1217 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1218 * function aac_detect will have to be modified where it sets up the
1219 * max number of channels based on the aac->nondasd_support flag only.
1220 */
1221 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1222 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1223 dev->nondasd_support = 1;
1224 dev->raid_scsi_mode = 1;
1225 }
1226 if (dev->raid_scsi_mode != 0)
1227 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1228 dev->name, dev->id);
1229
1230 if(nondasd != -1) {
1231 dev->nondasd_support = (nondasd!=0);
1232 }
1233 if(dev->nondasd_support != 0){
1234 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
1235 }
1236
1237 dev->dac_support = 0;
1238 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
1239 printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id);
1240 dev->dac_support = 1;
1241 }
1242
1243 if(dacmode != -1) {
1244 dev->dac_support = (dacmode!=0);
1245 }
1246 if(dev->dac_support != 0) {
James Bottomley71e0f322005-10-28 11:21:10 -05001247 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1248 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1250 dev->name, dev->id);
James Bottomley71e0f322005-10-28 11:21:10 -05001251 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1252 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1254 dev->name, dev->id);
1255 dev->dac_support = 0;
1256 } else {
1257 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1258 dev->name, dev->id);
1259 rcode = -ENOMEM;
1260 }
1261 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001262 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001263 * Deal with configuring for the individualized limits of each packet
1264 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001265 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001266 dev->a_ops.adapter_scsi = (dev->dac_support)
1267 ? aac_scsi_64
1268 : aac_scsi_32;
1269 if (dev->raw_io_interface) {
1270 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1271 ? aac_bounds_64
1272 : aac_bounds_32;
1273 dev->a_ops.adapter_read = aac_read_raw_io;
1274 dev->a_ops.adapter_write = aac_write_raw_io;
1275 } else {
1276 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001277 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001278 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001279 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1280 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001281 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001282 dev->a_ops.adapter_read = aac_read_block64;
1283 dev->a_ops.adapter_write = aac_write_block64;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001284 /*
1285 * 38 scatter gather elements
1286 */
1287 dev->scsi_host_ptr->sg_tablesize =
1288 (dev->max_fib_size -
1289 sizeof(struct aac_fibhdr) -
1290 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001291 sizeof(struct sgentry64)) /
1292 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001293 } else {
1294 dev->a_ops.adapter_read = aac_read_block;
1295 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001296 }
1297 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1298 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1299 /*
1300 * Worst case size that could cause sg overflow when
1301 * we break up SG elements that are larger than 64KB.
1302 * Would be nice if we could tell the SCSI layer what
1303 * the maximum SG element size can be. Worst case is
1304 * (sg_tablesize-1) 4KB elements with one 64KB
1305 * element.
1306 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1307 */
1308 dev->scsi_host_ptr->max_sectors =
1309 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1310 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001313 aac_fib_complete(fibptr);
1314 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316 return rcode;
1317}
1318
1319
Mark Haverkampe53cb352005-08-03 15:39:09 -07001320static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
1322 struct aac_dev *dev;
1323 struct aac_read_reply *readreply;
1324 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 u32 cid;
1326
1327 scsicmd = (struct scsi_cmnd *) context;
1328
Mark Haverkamp03d44332007-03-15 10:27:45 -07001329 if (!aac_valid_context(scsicmd, fibptr))
1330 return;
1331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08001333 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001335 if (nblank(dprintk(x))) {
1336 u64 lba;
1337 switch (scsicmd->cmnd[0]) {
1338 case WRITE_6:
1339 case READ_6:
1340 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1341 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1342 break;
1343 case WRITE_16:
1344 case READ_16:
1345 lba = ((u64)scsicmd->cmnd[2] << 56) |
1346 ((u64)scsicmd->cmnd[3] << 48) |
1347 ((u64)scsicmd->cmnd[4] << 40) |
1348 ((u64)scsicmd->cmnd[5] << 32) |
1349 ((u64)scsicmd->cmnd[6] << 24) |
1350 (scsicmd->cmnd[7] << 16) |
1351 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1352 break;
1353 case WRITE_12:
1354 case READ_12:
1355 lba = ((u64)scsicmd->cmnd[2] << 24) |
1356 (scsicmd->cmnd[3] << 16) |
1357 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1358 break;
1359 default:
1360 lba = ((u64)scsicmd->cmnd[2] << 24) |
1361 (scsicmd->cmnd[3] << 16) |
1362 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1363 break;
1364 }
1365 printk(KERN_DEBUG
1366 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1367 smp_processor_id(), (unsigned long long)lba, jiffies);
1368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Eric Sesterhenn125e1872006-06-23 02:06:06 -07001370 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001371
1372 scsi_dma_unmap(scsicmd);
1373
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 readreply = (struct aac_read_reply *)fib_data(fibptr);
1375 if (le32_to_cpu(readreply->status) == ST_OK)
1376 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1377 else {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001378#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07001379 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001380 le32_to_cpu(readreply->status));
1381#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1383 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1384 HARDWARE_ERROR,
1385 SENCODE_INTERNAL_TARGET_FAILURE,
1386 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1387 0, 0);
1388 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1389 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1390 ? sizeof(scsicmd->sense_buffer)
1391 : sizeof(dev->fsa_dev[cid].sense_data));
1392 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001393 aac_fib_complete(fibptr);
1394 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001396 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397}
1398
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001399static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001401 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 u32 count;
1403 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 struct aac_dev *dev;
1405 struct fib * cmd_fibcontext;
1406
1407 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1408 /*
1409 * Get block address and transfer length
1410 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001411 switch (scsicmd->cmnd[0]) {
1412 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001413 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001415 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1416 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 count = scsicmd->cmnd[4];
1418
1419 if (count == 0)
1420 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001421 break;
1422 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001423 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001424
1425 lba = ((u64)scsicmd->cmnd[2] << 56) |
1426 ((u64)scsicmd->cmnd[3] << 48) |
1427 ((u64)scsicmd->cmnd[4] << 40) |
1428 ((u64)scsicmd->cmnd[5] << 32) |
1429 ((u64)scsicmd->cmnd[6] << 24) |
1430 (scsicmd->cmnd[7] << 16) |
1431 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1432 count = (scsicmd->cmnd[10] << 24) |
1433 (scsicmd->cmnd[11] << 16) |
1434 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1435 break;
1436 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001437 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001438
1439 lba = ((u64)scsicmd->cmnd[2] << 24) |
1440 (scsicmd->cmnd[3] << 16) |
1441 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1442 count = (scsicmd->cmnd[6] << 24) |
1443 (scsicmd->cmnd[7] << 16) |
1444 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1445 break;
1446 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001447 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001449 lba = ((u64)scsicmd->cmnd[2] << 24) |
1450 (scsicmd->cmnd[3] << 16) |
1451 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001453 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001455 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001456 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001457 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001458 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 /*
1460 * Alocate and initialize a Fib
1461 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001462 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 return -1;
1464 }
1465
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001466 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 /*
1469 * Check that the command queued to the controller
1470 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001471 if (status == -EINPROGRESS) {
1472 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001476 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 /*
1478 * For some reason, the Fib didn't queue, return QUEUE_FULL
1479 */
1480 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001481 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001482 aac_fib_complete(cmd_fibcontext);
1483 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 return 0;
1485}
1486
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001487static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001489 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001491 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 struct aac_dev *dev;
1494 struct fib * cmd_fibcontext;
1495
1496 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1497 /*
1498 * Get block address and transfer length
1499 */
1500 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1501 {
1502 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1503 count = scsicmd->cmnd[4];
1504 if (count == 0)
1505 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001506 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001507 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001508 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001509
1510 lba = ((u64)scsicmd->cmnd[2] << 56) |
1511 ((u64)scsicmd->cmnd[3] << 48) |
1512 ((u64)scsicmd->cmnd[4] << 40) |
1513 ((u64)scsicmd->cmnd[5] << 32) |
1514 ((u64)scsicmd->cmnd[6] << 24) |
1515 (scsicmd->cmnd[7] << 16) |
1516 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1517 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1518 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001519 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001520 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001521 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001522
1523 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1524 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1525 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1526 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001527 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001529 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001530 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001532 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001534 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001536 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001537 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 /*
1539 * Allocate and initialize a Fib then setup a BlockWrite command
1540 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001541 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 scsicmd->result = DID_ERROR << 16;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001543 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 return 0;
1545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001547 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 /*
1550 * Check that the command queued to the controller
1551 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001552 if (status == -EINPROGRESS) {
1553 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 return 0;
1555 }
1556
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001557 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 /*
1559 * For some reason, the Fib didn't queue, return QUEUE_FULL
1560 */
1561 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001562 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001564 aac_fib_complete(cmd_fibcontext);
1565 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 return 0;
1567}
1568
1569static void synchronize_callback(void *context, struct fib *fibptr)
1570{
1571 struct aac_synchronize_reply *synchronizereply;
1572 struct scsi_cmnd *cmd;
1573
1574 cmd = context;
1575
Mark Haverkamp03d44332007-03-15 10:27:45 -07001576 if (!aac_valid_context(cmd, fibptr))
1577 return;
1578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1580 smp_processor_id(), jiffies));
1581 BUG_ON(fibptr == NULL);
1582
1583
1584 synchronizereply = fib_data(fibptr);
1585 if (le32_to_cpu(synchronizereply->status) == CT_OK)
1586 cmd->result = DID_OK << 16 |
1587 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1588 else {
1589 struct scsi_device *sdev = cmd->device;
1590 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08001591 u32 cid = sdev_id(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 printk(KERN_WARNING
1593 "synchronize_callback: synchronize failed, status = %d\n",
1594 le32_to_cpu(synchronizereply->status));
1595 cmd->result = DID_OK << 16 |
1596 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1597 set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
1598 HARDWARE_ERROR,
1599 SENCODE_INTERNAL_TARGET_FAILURE,
1600 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1601 0, 0);
1602 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1603 min(sizeof(dev->fsa_dev[cid].sense_data),
1604 sizeof(cmd->sense_buffer)));
1605 }
1606
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001607 aac_fib_complete(fibptr);
1608 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001609 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610}
1611
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001612static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613{
1614 int status;
1615 struct fib *cmd_fibcontext;
1616 struct aac_synchronize *synchronizecmd;
1617 struct scsi_cmnd *cmd;
1618 struct scsi_device *sdev = scsicmd->device;
1619 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001620 struct aac_dev *aac;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 unsigned long flags;
1622
1623 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001624 * Wait for all outstanding queued commands to complete to this
1625 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 */
1627 spin_lock_irqsave(&sdev->list_lock, flags);
1628 list_for_each_entry(cmd, &sdev->cmd_list, list)
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001629 if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 ++active;
1631 break;
1632 }
1633
1634 spin_unlock_irqrestore(&sdev->list_lock, flags);
1635
1636 /*
1637 * Yield the processor (requeue for later)
1638 */
1639 if (active)
1640 return SCSI_MLQUEUE_DEVICE_BUSY;
1641
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001642 aac = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001643 if (aac->in_reset)
1644 return SCSI_MLQUEUE_HOST_BUSY;
1645
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001647 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001649 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 return SCSI_MLQUEUE_HOST_BUSY;
1651
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001652 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 synchronizecmd = fib_data(cmd_fibcontext);
1655 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1656 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001657 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 synchronizecmd->count =
1659 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1660
1661 /*
1662 * Now send the Fib to the adapter
1663 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001664 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 cmd_fibcontext,
1666 sizeof(struct aac_synchronize),
1667 FsaNormal,
1668 0, 1,
1669 (fib_callback)synchronize_callback,
1670 (void *)scsicmd);
1671
1672 /*
1673 * Check that the command queued to the controller
1674 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001675 if (status == -EINPROGRESS) {
1676 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001678 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
1680 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001681 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1682 aac_fib_complete(cmd_fibcontext);
1683 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 return SCSI_MLQUEUE_HOST_BUSY;
1685}
1686
1687/**
1688 * aac_scsi_cmd() - Process SCSI command
1689 * @scsicmd: SCSI command block
1690 *
1691 * Emulate a SCSI command and queue the required request for the
1692 * aacraid firmware.
1693 */
1694
1695int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1696{
1697 u32 cid = 0;
1698 struct Scsi_Host *host = scsicmd->device->host;
1699 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1700 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001702 if (fsa_dev_ptr == NULL)
1703 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 /*
1705 * If the bus, id or lun is out of range, return fail
1706 * Test does not apply to ID 16, the pseudo id for the controller
1707 * itself.
1708 */
Jeff Garzik422c0d62005-10-24 18:05:09 -04001709 if (scmd_id(scsicmd) != host->this_id) {
Mark Haverkampe5718772006-03-27 09:43:25 -08001710 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
1711 if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
1712 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 scsicmd->result = DID_NO_CONNECT << 16;
1714 scsicmd->scsi_done(scsicmd);
1715 return 0;
1716 }
Mark Haverkampe5718772006-03-27 09:43:25 -08001717 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
1719 /*
1720 * If the target container doesn't exist, it may have
1721 * been newly created
1722 */
1723 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1724 switch (scsicmd->cmnd[0]) {
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001725 case SERVICE_ACTION_IN:
1726 if (!(dev->raw_io_interface) ||
1727 !(dev->raw_io_64) ||
1728 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1729 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 case INQUIRY:
1731 case READ_CAPACITY:
1732 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001733 if (dev->in_reset)
1734 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07001735 return _aac_probe_container(scsicmd,
1736 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 default:
1738 break;
1739 }
1740 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 } else { /* check for physical non-dasd devices */
Mark Haverkamp653ba582006-09-19 08:59:43 -07001742 if ((dev->nondasd_support == 1) || expose_physicals) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001743 if (dev->in_reset)
1744 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 return aac_send_srb_fib(scsicmd);
1746 } else {
1747 scsicmd->result = DID_NO_CONNECT << 16;
1748 scsicmd->scsi_done(scsicmd);
1749 return 0;
1750 }
1751 }
1752 }
1753 /*
1754 * else Command for the controller itself
1755 */
1756 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
1757 (scsicmd->cmnd[0] != TEST_UNIT_READY))
1758 {
1759 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1760 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1761 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1762 ILLEGAL_REQUEST,
1763 SENCODE_INVALID_COMMAND,
1764 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
1765 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1766 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1767 ? sizeof(scsicmd->sense_buffer)
1768 : sizeof(dev->fsa_dev[cid].sense_data));
1769 scsicmd->scsi_done(scsicmd);
1770 return 0;
1771 }
1772
1773
1774 /* Handle commands here that don't really require going out to the adapter */
1775 switch (scsicmd->cmnd[0]) {
1776 case INQUIRY:
1777 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001778 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Mark Haverkampe5718772006-03-27 09:43:25 -08001780 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001781 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001783 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001784 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 */
1785 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001787 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 /*
1789 * Set the Vendor, Product, and Revision Level
1790 * see: <vendor>.c i.e. aac.c
1791 */
Jeff Garzik422c0d62005-10-24 18:05:09 -04001792 if (scmd_id(scsicmd) == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07001793 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001794 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1795 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1797 scsicmd->scsi_done(scsicmd);
1798 return 0;
1799 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001800 if (dev->in_reset)
1801 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07001802 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001803 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1804 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001805 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001807 case SERVICE_ACTION_IN:
1808 if (!(dev->raw_io_interface) ||
1809 !(dev->raw_io_64) ||
1810 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1811 break;
1812 {
1813 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08001814 char cp[13];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001815
1816 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
1817 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001818 cp[0] = (capacity >> 56) & 0xff;
1819 cp[1] = (capacity >> 48) & 0xff;
1820 cp[2] = (capacity >> 40) & 0xff;
1821 cp[3] = (capacity >> 32) & 0xff;
1822 cp[4] = (capacity >> 24) & 0xff;
1823 cp[5] = (capacity >> 16) & 0xff;
1824 cp[6] = (capacity >> 8) & 0xff;
1825 cp[7] = (capacity >> 0) & 0xff;
1826 cp[8] = 0;
1827 cp[9] = 0;
1828 cp[10] = 2;
1829 cp[11] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08001830 cp[12] = 0;
1831 aac_internal_transfer(scsicmd, cp, 0,
Mark Haverkamp1241f352006-03-27 09:44:23 -08001832 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08001833 if (sizeof(cp) < scsicmd->cmnd[13]) {
1834 unsigned int len, offset = sizeof(cp);
1835
1836 memset(cp, 0, offset);
1837 do {
Mark Haverkamp1241f352006-03-27 09:44:23 -08001838 len = min_t(size_t, scsicmd->cmnd[13] - offset,
1839 sizeof(cp));
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08001840 aac_internal_transfer(scsicmd, cp, offset, len);
1841 } while ((offset += len) < scsicmd->cmnd[13]);
1842 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001843
1844 /* Do not cache partition table for arrays */
1845 scsicmd->device->removable = 1;
1846
1847 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1848 scsicmd->scsi_done(scsicmd);
1849
1850 return 0;
1851 }
1852
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 case READ_CAPACITY:
1854 {
1855 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001856 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
1858 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001859 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 capacity = fsa_dev_ptr[cid].size - 1;
1861 else
1862 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 cp[0] = (capacity >> 24) & 0xff;
1865 cp[1] = (capacity >> 16) & 0xff;
1866 cp[2] = (capacity >> 8) & 0xff;
1867 cp[3] = (capacity >> 0) & 0xff;
1868 cp[4] = 0;
1869 cp[5] = 0;
1870 cp[6] = 2;
1871 cp[7] = 0;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001872 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001873 /* Do not cache partition table for arrays */
1874 scsicmd->device->removable = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
1876 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1877 scsicmd->scsi_done(scsicmd);
1878
1879 return 0;
1880 }
1881
1882 case MODE_SENSE:
1883 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001884 char mode_buf[7];
1885 int mode_buf_length = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
1887 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 mode_buf[0] = 3; /* Mode data length */
1889 mode_buf[1] = 0; /* Medium type - default */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001890 mode_buf[2] = 0; /* Device-specific param,
1891 bit 8: 0/1 = write enabled/protected
1892 bit 4: 0/1 = FUA enabled */
1893 if (dev->raw_io_interface)
1894 mode_buf[2] = 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 mode_buf[3] = 0; /* Block descriptor length */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001896 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
1897 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
1898 mode_buf[0] = 6;
1899 mode_buf[4] = 8;
1900 mode_buf[5] = 1;
1901 mode_buf[6] = 0x04; /* WCE */
1902 mode_buf_length = 7;
1903 if (mode_buf_length > scsicmd->cmnd[4])
1904 mode_buf_length = scsicmd->cmnd[4];
1905 }
1906 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1908 scsicmd->scsi_done(scsicmd);
1909
1910 return 0;
1911 }
1912 case MODE_SENSE_10:
1913 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001914 char mode_buf[11];
1915 int mode_buf_length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
1917 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 mode_buf[0] = 0; /* Mode data length (MSB) */
1919 mode_buf[1] = 6; /* Mode data length (LSB) */
1920 mode_buf[2] = 0; /* Medium type - default */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001921 mode_buf[3] = 0; /* Device-specific param,
1922 bit 8: 0/1 = write enabled/protected
1923 bit 4: 0/1 = FUA enabled */
1924 if (dev->raw_io_interface)
1925 mode_buf[3] = 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 mode_buf[4] = 0; /* reserved */
1927 mode_buf[5] = 0; /* reserved */
1928 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1929 mode_buf[7] = 0; /* Block descriptor length (LSB) */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001930 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
1931 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
1932 mode_buf[1] = 9;
1933 mode_buf[8] = 8;
1934 mode_buf[9] = 1;
1935 mode_buf[10] = 0x04; /* WCE */
1936 mode_buf_length = 11;
1937 if (mode_buf_length > scsicmd->cmnd[8])
1938 mode_buf_length = scsicmd->cmnd[8];
1939 }
1940 aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
1942 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1943 scsicmd->scsi_done(scsicmd);
1944
1945 return 0;
1946 }
1947 case REQUEST_SENSE:
1948 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
1949 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
1950 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
1951 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1952 scsicmd->scsi_done(scsicmd);
1953 return 0;
1954
1955 case ALLOW_MEDIUM_REMOVAL:
1956 dprintk((KERN_DEBUG "LOCK command.\n"));
1957 if (scsicmd->cmnd[4])
1958 fsa_dev_ptr[cid].locked = 1;
1959 else
1960 fsa_dev_ptr[cid].locked = 0;
1961
1962 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1963 scsicmd->scsi_done(scsicmd);
1964 return 0;
1965 /*
1966 * These commands are all No-Ops
1967 */
1968 case TEST_UNIT_READY:
1969 case RESERVE:
1970 case RELEASE:
1971 case REZERO_UNIT:
1972 case REASSIGN_BLOCKS:
1973 case SEEK_10:
1974 case START_STOP:
1975 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1976 scsicmd->scsi_done(scsicmd);
1977 return 0;
1978 }
1979
1980 switch (scsicmd->cmnd[0])
1981 {
1982 case READ_6:
1983 case READ_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001984 case READ_12:
1985 case READ_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001986 if (dev->in_reset)
1987 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 /*
1989 * Hack to keep track of ordinal number of the device that
1990 * corresponds to a container. Needed to convert
1991 * containers to /dev/sd device names
1992 */
1993
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001994 if (scsicmd->request->rq_disk)
1995 strlcpy(fsa_dev_ptr[cid].devname,
1996 scsicmd->request->rq_disk->disk_name,
1997 min(sizeof(fsa_dev_ptr[cid].devname),
1998 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001999
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002000 return aac_read(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
2002 case WRITE_6:
2003 case WRITE_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002004 case WRITE_12:
2005 case WRITE_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002006 if (dev->in_reset)
2007 return -1;
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002008 return aac_write(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
2010 case SYNCHRONIZE_CACHE:
2011 /* Issue FIB to tell Firmware to flush it's cache */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002012 return aac_synchronize(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014 default:
2015 /*
2016 * Unhandled commands
2017 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002018 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2020 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
2021 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2022 ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
2023 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2024 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
2025 ? sizeof(scsicmd->sense_buffer)
2026 : sizeof(dev->fsa_dev[cid].sense_data));
2027 scsicmd->scsi_done(scsicmd);
2028 return 0;
2029 }
2030}
2031
2032static int query_disk(struct aac_dev *dev, void __user *arg)
2033{
2034 struct aac_query_disk qd;
2035 struct fsa_dev_info *fsa_dev_ptr;
2036
2037 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002038 if (!fsa_dev_ptr)
Mark Haverkamp651013552006-09-19 08:59:23 -07002039 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2041 return -EFAULT;
2042 if (qd.cnum == -1)
Mark Haverkampe5718772006-03-27 09:43:25 -08002043 qd.cnum = qd.id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
2045 {
2046 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2047 return -EINVAL;
2048 qd.instance = dev->scsi_host_ptr->host_no;
2049 qd.bus = 0;
2050 qd.id = CONTAINER_TO_ID(qd.cnum);
2051 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2052 }
2053 else return -EINVAL;
2054
2055 qd.valid = fsa_dev_ptr[qd.cnum].valid;
2056 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2057 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2058
2059 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2060 qd.unmapped = 1;
2061 else
2062 qd.unmapped = 0;
2063
2064 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2065 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2066
2067 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2068 return -EFAULT;
2069 return 0;
2070}
2071
2072static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2073{
2074 struct aac_delete_disk dd;
2075 struct fsa_dev_info *fsa_dev_ptr;
2076
2077 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp651013552006-09-19 08:59:23 -07002078 if (!fsa_dev_ptr)
2079 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
2081 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2082 return -EFAULT;
2083
2084 if (dd.cnum >= dev->maximum_num_containers)
2085 return -EINVAL;
2086 /*
2087 * Mark this container as being deleted.
2088 */
2089 fsa_dev_ptr[dd.cnum].deleted = 1;
2090 /*
2091 * Mark the container as no longer valid
2092 */
2093 fsa_dev_ptr[dd.cnum].valid = 0;
2094 return 0;
2095}
2096
2097static int delete_disk(struct aac_dev *dev, void __user *arg)
2098{
2099 struct aac_delete_disk dd;
2100 struct fsa_dev_info *fsa_dev_ptr;
2101
2102 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002103 if (!fsa_dev_ptr)
Mark Haverkamp651013552006-09-19 08:59:23 -07002104 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
2106 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2107 return -EFAULT;
2108
2109 if (dd.cnum >= dev->maximum_num_containers)
2110 return -EINVAL;
2111 /*
2112 * If the container is locked, it can not be deleted by the API.
2113 */
2114 if (fsa_dev_ptr[dd.cnum].locked)
2115 return -EBUSY;
2116 else {
2117 /*
2118 * Mark the container as no longer being valid.
2119 */
2120 fsa_dev_ptr[dd.cnum].valid = 0;
2121 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2122 return 0;
2123 }
2124}
2125
2126int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2127{
2128 switch (cmd) {
2129 case FSACTL_QUERY_DISK:
2130 return query_disk(dev, arg);
2131 case FSACTL_DELETE_DISK:
2132 return delete_disk(dev, arg);
2133 case FSACTL_FORCE_DELETE_DISK:
2134 return force_delete_disk(dev, arg);
2135 case FSACTL_GET_CONTAINERS:
2136 return aac_get_containers(dev);
2137 default:
2138 return -ENOTTY;
2139 }
2140}
2141
2142/**
2143 *
2144 * aac_srb_callback
2145 * @context: the context set in the fib - here it is scsi cmd
2146 * @fibptr: pointer to the fib
2147 *
2148 * Handles the completion of a scsi command to a non dasd device
2149 *
2150 */
2151
2152static void aac_srb_callback(void *context, struct fib * fibptr)
2153{
2154 struct aac_dev *dev;
2155 struct aac_srb_reply *srbreply;
2156 struct scsi_cmnd *scsicmd;
2157
2158 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07002159
2160 if (!aac_valid_context(scsicmd, fibptr))
2161 return;
2162
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2164
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002165 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2168
2169 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2170 /*
2171 * Calculate resid for sg
2172 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002174 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2175 - le32_to_cpu(srbreply->data_xfer_length));
2176
2177 scsi_dma_unmap(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
2179 /*
2180 * First check the fib status
2181 */
2182
2183 if (le32_to_cpu(srbreply->status) != ST_OK){
2184 int len;
2185 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2186 len = (le32_to_cpu(srbreply->sense_data_size) >
2187 sizeof(scsicmd->sense_buffer)) ?
2188 sizeof(scsicmd->sense_buffer) :
2189 le32_to_cpu(srbreply->sense_data_size);
2190 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2191 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2192 }
2193
2194 /*
2195 * Next check the srb status
2196 */
2197 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2198 case SRB_STATUS_ERROR_RECOVERY:
2199 case SRB_STATUS_PENDING:
2200 case SRB_STATUS_SUCCESS:
Mark Haverkampbb08f922006-02-01 09:30:44 -08002201 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 break;
2203 case SRB_STATUS_DATA_OVERRUN:
2204 switch(scsicmd->cmnd[0]){
2205 case READ_6:
2206 case WRITE_6:
2207 case READ_10:
2208 case WRITE_10:
2209 case READ_12:
2210 case WRITE_12:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002211 case READ_16:
2212 case WRITE_16:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) {
2214 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2215 } else {
2216 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2217 }
2218 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2219 break;
2220 case INQUIRY: {
Mark Haverkampbb08f922006-02-01 09:30:44 -08002221 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 break;
2223 }
2224 default:
2225 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2226 break;
2227 }
2228 break;
2229 case SRB_STATUS_ABORTED:
2230 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2231 break;
2232 case SRB_STATUS_ABORT_FAILED:
2233 // Not sure about this one - but assuming the hba was trying to abort for some reason
2234 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2235 break;
2236 case SRB_STATUS_PARITY_ERROR:
2237 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2238 break;
2239 case SRB_STATUS_NO_DEVICE:
2240 case SRB_STATUS_INVALID_PATH_ID:
2241 case SRB_STATUS_INVALID_TARGET_ID:
2242 case SRB_STATUS_INVALID_LUN:
2243 case SRB_STATUS_SELECTION_TIMEOUT:
2244 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2245 break;
2246
2247 case SRB_STATUS_COMMAND_TIMEOUT:
2248 case SRB_STATUS_TIMEOUT:
2249 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2250 break;
2251
2252 case SRB_STATUS_BUSY:
2253 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2254 break;
2255
2256 case SRB_STATUS_BUS_RESET:
2257 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2258 break;
2259
2260 case SRB_STATUS_MESSAGE_REJECTED:
2261 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2262 break;
2263 case SRB_STATUS_REQUEST_FLUSHED:
2264 case SRB_STATUS_ERROR:
2265 case SRB_STATUS_INVALID_REQUEST:
2266 case SRB_STATUS_REQUEST_SENSE_FAILED:
2267 case SRB_STATUS_NO_HBA:
2268 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2269 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2270 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2271 case SRB_STATUS_DELAYED_RETRY:
2272 case SRB_STATUS_BAD_FUNCTION:
2273 case SRB_STATUS_NOT_STARTED:
2274 case SRB_STATUS_NOT_IN_USE:
2275 case SRB_STATUS_FORCE_ABORT:
2276 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2277 default:
2278#ifdef AAC_DETAILED_STATUS_INFO
2279 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2280 le32_to_cpu(srbreply->srb_status) & 0x3F,
2281 aac_get_status_string(
2282 le32_to_cpu(srbreply->srb_status) & 0x3F),
2283 scsicmd->cmnd[0],
2284 le32_to_cpu(srbreply->scsi_status));
2285#endif
2286 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2287 break;
2288 }
2289 if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition
2290 int len;
2291 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
2292 len = (le32_to_cpu(srbreply->sense_data_size) >
2293 sizeof(scsicmd->sense_buffer)) ?
2294 sizeof(scsicmd->sense_buffer) :
2295 le32_to_cpu(srbreply->sense_data_size);
2296#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002297 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2298 le32_to_cpu(srbreply->status), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299#endif
2300 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2301
2302 }
2303 /*
2304 * OR in the scsi status (already shifted up a bit)
2305 */
2306 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2307
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002308 aac_fib_complete(fibptr);
2309 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002310 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311}
2312
2313/**
2314 *
2315 * aac_send_scb_fib
2316 * @scsicmd: the scsi command block
2317 *
2318 * This routine will form a FIB and fill in the aac_srb from the
2319 * scsicmd passed in.
2320 */
2321
2322static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2323{
2324 struct fib* cmd_fibcontext;
2325 struct aac_dev* dev;
2326 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Mark Haverkamp84971732005-06-20 11:55:24 -07002328 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08002329 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07002330 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 scsicmd->result = DID_NO_CONNECT << 16;
2332 scsicmd->scsi_done(scsicmd);
2333 return 0;
2334 }
2335
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 /*
2337 * Allocate and initialize a Fib then setup a BlockWrite command
2338 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002339 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 return -1;
2341 }
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002342 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 /*
2345 * Check that the command queued to the controller
2346 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002347 if (status == -EINPROGRESS) {
2348 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 return 0;
2350 }
2351
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002352 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2353 aac_fib_complete(cmd_fibcontext);
2354 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356 return -1;
2357}
2358
2359static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2360{
2361 struct aac_dev *dev;
2362 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002363 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
2365 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2366 // Get rid of old data
2367 psg->count = 0;
2368 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002369 psg->sg[0].count = 0;
2370
2371 nseg = scsi_dma_map(scsicmd);
2372 BUG_ON(nseg < 0);
2373 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 struct scatterlist *sg;
2375 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002377 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002379 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2381 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2382 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 }
2384 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002385 if (byte_count > scsi_bufflen(scsicmd)) {
2386 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2387 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002388 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002389 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 }
2391 /* Check for command underflow */
2392 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2393 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2394 byte_count, scsicmd->underflow);
2395 }
2396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 return byte_count;
2398}
2399
2400
2401static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2402{
2403 struct aac_dev *dev;
2404 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002405 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002406 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
2408 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2409 // Get rid of old data
2410 psg->count = 0;
2411 psg->sg[0].addr[0] = 0;
2412 psg->sg[0].addr[1] = 0;
2413 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002414
2415 nseg = scsi_dma_map(scsicmd);
2416 BUG_ON(nseg < 0);
2417 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 struct scatterlist *sg;
2419 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002421 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp1241f352006-03-27 09:44:23 -08002422 int count = sg_dma_len(sg);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002423 addr = sg_dma_address(sg);
2424 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2425 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
Mark Haverkamp1241f352006-03-27 09:44:23 -08002426 psg->sg[i].count = cpu_to_le32(count);
2427 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002429 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002431 if (byte_count > scsi_bufflen(scsicmd)) {
2432 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2433 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002434 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002435 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 }
2437 /* Check for command underflow */
2438 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2439 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2440 byte_count, scsicmd->underflow);
2441 }
2442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 return byte_count;
2444}
2445
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002446static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2447{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002448 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002449 int nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002450
2451 // Get rid of old data
2452 psg->count = 0;
2453 psg->sg[0].next = 0;
2454 psg->sg[0].prev = 0;
2455 psg->sg[0].addr[0] = 0;
2456 psg->sg[0].addr[1] = 0;
2457 psg->sg[0].count = 0;
2458 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002459
2460 nseg = scsi_dma_map(scsicmd);
2461 BUG_ON(nseg < 0);
2462 if (nseg) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002463 struct scatterlist *sg;
2464 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002465
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002466 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002467 int count = sg_dma_len(sg);
2468 u64 addr = sg_dma_address(sg);
2469 psg->sg[i].next = 0;
2470 psg->sg[i].prev = 0;
2471 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2472 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2473 psg->sg[i].count = cpu_to_le32(count);
2474 psg->sg[i].flags = 0;
2475 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002476 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002477 psg->count = cpu_to_le32(nseg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002478 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002479 if (byte_count > scsi_bufflen(scsicmd)) {
2480 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2481 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002482 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002483 byte_count = scsi_bufflen(scsicmd);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002484 }
2485 /* Check for command underflow */
2486 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2487 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2488 byte_count, scsicmd->underflow);
2489 }
2490 }
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002491 return byte_count;
2492}
2493
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494#ifdef AAC_DETAILED_STATUS_INFO
2495
2496struct aac_srb_status_info {
2497 u32 status;
2498 char *str;
2499};
2500
2501
2502static struct aac_srb_status_info srb_status_info[] = {
2503 { SRB_STATUS_PENDING, "Pending Status"},
2504 { SRB_STATUS_SUCCESS, "Success"},
2505 { SRB_STATUS_ABORTED, "Aborted Command"},
2506 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07002507 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 { SRB_STATUS_BUSY, "Device Busy"},
2509 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2510 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2511 { SRB_STATUS_NO_DEVICE, "No Device"},
2512 { SRB_STATUS_TIMEOUT, "Timeout"},
2513 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2514 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2515 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2516 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2517 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2518 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2519 { SRB_STATUS_NO_HBA, "No HBA"},
2520 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2521 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2522 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2523 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2524 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2525 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07002526 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2528 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2529 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2530 { SRB_STATUS_NOT_STARTED, "Not Started"},
2531 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
2532 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
2533 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2534 { 0xff, "Unknown Error"}
2535};
2536
2537char *aac_get_status_string(u32 status)
2538{
2539 int i;
2540
Tobias Klauser6391a112006-06-08 22:23:48 -07002541 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2542 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
2545 return "Bad Status Code";
2546}
2547
2548#endif