blob: 369fcf78f39612303787a8c1c3fdb5598f79d982 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
4 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mark Haverkamp03d44332007-03-15 10:27:45 -07008 * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/pci.h>
30#include <linux/spinlock.h>
31#include <linux/slab.h>
32#include <linux/completion.h>
33#include <linux/blkdev.h>
34#include <asm/semaphore.h>
35#include <asm/uaccess.h>
Salyzyn, Mark3a0086a2008-01-11 11:46:44 -080036#include <linux/highmem.h> /* For flush_kernel_dcache_page */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <scsi/scsi.h>
39#include <scsi/scsi_cmnd.h>
40#include <scsi/scsi_device.h>
41#include <scsi/scsi_host.h>
42
43#include "aacraid.h"
44
45/* values for inqd_pdt: Peripheral device type in plain English */
46#define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
47#define INQD_PDT_PROC 0x03 /* Processor device */
48#define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
49#define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
50#define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
51#define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
52
53#define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
54#define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*
57 * Sense codes
58 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080059
60#define SENCODE_NO_SENSE 0x00
61#define SENCODE_END_OF_DATA 0x00
62#define SENCODE_BECOMING_READY 0x04
63#define SENCODE_INIT_CMD_REQUIRED 0x04
64#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
65#define SENCODE_INVALID_COMMAND 0x20
66#define SENCODE_LBA_OUT_OF_RANGE 0x21
67#define SENCODE_INVALID_CDB_FIELD 0x24
68#define SENCODE_LUN_NOT_SUPPORTED 0x25
69#define SENCODE_INVALID_PARAM_FIELD 0x26
70#define SENCODE_PARAM_NOT_SUPPORTED 0x26
71#define SENCODE_PARAM_VALUE_INVALID 0x26
72#define SENCODE_RESET_OCCURRED 0x29
73#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
74#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
75#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
76#define SENCODE_DIAGNOSTIC_FAILURE 0x40
77#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
78#define SENCODE_INVALID_MESSAGE_ERROR 0x49
79#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
80#define SENCODE_OVERLAPPED_COMMAND 0x4E
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
83 * Additional sense codes
84 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080085
86#define ASENCODE_NO_SENSE 0x00
87#define ASENCODE_END_OF_DATA 0x05
88#define ASENCODE_BECOMING_READY 0x01
89#define ASENCODE_INIT_CMD_REQUIRED 0x02
90#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
91#define ASENCODE_INVALID_COMMAND 0x00
92#define ASENCODE_LBA_OUT_OF_RANGE 0x00
93#define ASENCODE_INVALID_CDB_FIELD 0x00
94#define ASENCODE_LUN_NOT_SUPPORTED 0x00
95#define ASENCODE_INVALID_PARAM_FIELD 0x00
96#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
97#define ASENCODE_PARAM_VALUE_INVALID 0x02
98#define ASENCODE_RESET_OCCURRED 0x00
99#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
100#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
101#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
102#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
103#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
104#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
105#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
106#define ASENCODE_OVERLAPPED_COMMAND 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108#define BYTE0(x) (unsigned char)(x)
109#define BYTE1(x) (unsigned char)((x) >> 8)
110#define BYTE2(x) (unsigned char)((x) >> 16)
111#define BYTE3(x) (unsigned char)((x) >> 24)
112
113/*------------------------------------------------------------------------------
114 * S T R U C T S / T Y P E D E F S
115 *----------------------------------------------------------------------------*/
116/* SCSI inquiry data */
117struct inquiry_data {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800118 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
119 u8 inqd_dtq; /* RMB | Device Type Qualifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
121 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
122 u8 inqd_len; /* Additional length (n-4) */
123 u8 inqd_pad1[2];/* Reserved - must be zero */
124 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
125 u8 inqd_vid[8]; /* Vendor ID */
126 u8 inqd_pid[16];/* Product ID */
127 u8 inqd_prl[4]; /* Product Revision Level */
128};
129
130/*
131 * M O D U L E G L O B A L S
132 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -0700136static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
138#ifdef AAC_DETAILED_STATUS_INFO
139static char *aac_get_status_string(u32 status);
140#endif
141
142/*
143 * Non dasd selection is handled entirely in aachba now
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800144 */
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static int nondasd = -1;
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800147static int aac_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static int dacmode = -1;
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800149int aac_msi;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400150int aac_commit = -1;
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700151int startup_timeout = 180;
152int aif_timeout = 120;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800154module_param(nondasd, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800155MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
156 " 0=off, 1=on");
Salyzyn, Mark95e852e2008-01-08 12:01:07 -0800157module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800158MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
159 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
160 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
161 "\tbit 2 - Disable only if Battery not protecting Cache");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800162module_param(dacmode, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800163MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
164 " 0=off, 1=on");
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400165module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800166MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
167 " adapter for foreign arrays.\n"
168 "This is typically needed in systems that do not have a BIOS."
169 " 0=off, 1=on");
170module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
171MODULE_PARM_DESC(msi, "IRQ handling."
172 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700173module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800174MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
175 " adapter to have it's kernel up and\n"
176 "running. This is typically adjusted for large systems that do not"
177 " have a BIOS.");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700178module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800179MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
180 " applications to pick up AIFs before\n"
181 "deregistering them. This is typically adjusted for heavily burdened"
182 " systems.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700184int numacb = -1;
185module_param(numacb, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800186MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
187 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
188 " to use suggestion from Firmware.");
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700189
190int acbsize = -1;
191module_param(acbsize, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800192MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
193 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
194 " suggestion from Firmware.");
Mark Haverkamp653ba582006-09-19 08:59:43 -0700195
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400196int update_interval = 30 * 60;
197module_param(update_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800198MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
199 " updates issued to adapter.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400200
201int check_interval = 24 * 60 * 60;
202module_param(check_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800203MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
204 " checks.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400205
Andrew Morton87f3bda2007-08-10 14:50:30 -0700206int aac_check_reset = 1;
207module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
Paul Bolle95e7a8e2008-04-16 14:43:00 +0200208MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800209 " adapter. a value of -1 forces the reset to adapters programmed to"
210 " ignore it.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400211
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800212int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700213module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800214MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
215 " -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700216
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800217int aac_reset_devices;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400218module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
219MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700220
221static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
222 struct fib *fibptr) {
223 struct scsi_device *device;
224
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800225 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
Salyzyn, Markc835e372007-07-26 14:20:02 -0400226 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800227 aac_fib_complete(fibptr);
228 aac_fib_free(fibptr);
229 return 0;
230 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700231 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
232 device = scsicmd->device;
233 if (unlikely(!device || !scsi_device_online(device))) {
234 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
235 aac_fib_complete(fibptr);
236 aac_fib_free(fibptr);
237 return 0;
238 }
239 return 1;
240}
241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242/**
243 * aac_get_config_status - check the adapter configuration
244 * @common: adapter to query
245 *
246 * Query config status, and commit the configuration if needed.
247 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700248int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
250 int status = 0;
251 struct fib * fibptr;
252
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800253 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return -ENOMEM;
255
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800256 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 {
258 struct aac_get_config_status *dinfo;
259 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
260
261 dinfo->command = cpu_to_le32(VM_ContainerConfig);
262 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
263 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
264 }
265
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800266 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 fibptr,
268 sizeof (struct aac_get_config_status),
269 FsaNormal,
270 1, 1,
271 NULL, NULL);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800272 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
274 } else {
275 struct aac_get_config_status_resp *reply
276 = (struct aac_get_config_status_resp *) fib_data(fibptr);
277 dprintk((KERN_WARNING
278 "aac_get_config_status: response=%d status=%d action=%d\n",
279 le32_to_cpu(reply->response),
280 le32_to_cpu(reply->status),
281 le32_to_cpu(reply->data.action)));
282 if ((le32_to_cpu(reply->response) != ST_OK) ||
283 (le32_to_cpu(reply->status) != CT_OK) ||
284 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
285 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
286 status = -EINVAL;
287 }
288 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800289 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
291 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400292 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800294 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 dinfo = (struct aac_commit_config *) fib_data(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 dinfo->command = cpu_to_le32(VM_ContainerConfig);
298 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800299
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_commit_config),
303 FsaNormal,
304 1, 1,
305 NULL, NULL);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800306 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400307 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 printk(KERN_WARNING
309 "aac_get_config_status: Foreign device configurations are being ignored\n");
310 }
311 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800312 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return status;
314}
315
316/**
317 * aac_get_containers - list containers
318 * @common: adapter to probe
319 *
320 * Make a list of all containers on this controller
321 */
322int aac_get_containers(struct aac_dev *dev)
323{
324 struct fsa_dev_info *fsa_dev_ptr;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800325 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 int status = 0;
327 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 struct aac_get_container_count *dinfo;
329 struct aac_get_container_count_resp *dresp;
330 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
331
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800332 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 return -ENOMEM;
334
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800335 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
337 dinfo->command = cpu_to_le32(VM_ContainerConfig);
338 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
339
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800340 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 fibptr,
342 sizeof (struct aac_get_container_count),
343 FsaNormal,
344 1, 1,
345 NULL, NULL);
346 if (status >= 0) {
347 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
348 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800349 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700351 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
354 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400355 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700356 GFP_KERNEL);
357 if (!fsa_dev_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 dev->fsa_dev = fsa_dev_ptr;
361 dev->maximum_num_containers = maximum_num_containers;
362
Mark Haverkampfe76df42007-03-15 12:55:07 -0700363 for (index = 0; index < dev->maximum_num_containers; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 fsa_dev_ptr[index].devname[0] = '\0';
365
Mark Haverkampfe76df42007-03-15 12:55:07 -0700366 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Mark Haverkampfe76df42007-03-15 12:55:07 -0700368 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
370 break;
371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 /*
374 * If there are no more containers, then stop asking.
375 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700376 if (++index >= status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return status;
380}
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382static void get_container_name_callback(void *context, struct fib * fibptr)
383{
384 struct aac_get_name_resp * get_name_reply;
385 struct scsi_cmnd * scsicmd;
386
387 scsicmd = (struct scsi_cmnd *) context;
388
Mark Haverkamp03d44332007-03-15 10:27:45 -0700389 if (!aac_valid_context(scsicmd, fibptr))
390 return;
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700393 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
396 /* Failure is irrelevant, using default value instead */
397 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
398 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700399 char *sp = get_name_reply->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
401 while (*sp == ' ')
402 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700403 if (*sp) {
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900404 struct inquiry_data inq;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700405 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
406 int count = sizeof(d);
407 char *dp = d;
408 do {
409 *dp++ = (*sp) ? *sp++ : ' ';
410 } while (--count > 0);
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900411
412 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
413 memcpy(inq.inqd_pid, d, sizeof(d));
414 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
419
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800420 aac_fib_complete(fibptr);
421 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700422 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424
425/**
426 * aac_get_container_name - get container name, none blocking.
427 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700428static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 int status;
431 struct aac_get_name *dinfo;
432 struct fib * cmd_fibcontext;
433 struct aac_dev * dev;
434
435 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
436
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800437 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 return -ENOMEM;
439
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800440 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
442
443 dinfo->command = cpu_to_le32(VM_ContainerConfig);
444 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700445 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
447
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800448 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800449 cmd_fibcontext,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 sizeof (struct aac_get_name),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800451 FsaNormal,
452 0, 1,
453 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 /*
457 * Check that the command queued to the controller
458 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800459 if (status == -EINPROGRESS) {
460 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800462 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800463
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800464 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
465 aac_fib_complete(cmd_fibcontext);
466 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return -1;
468}
469
Mark Haverkampfe76df42007-03-15 12:55:07 -0700470static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
471{
472 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
473
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400474 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700475 return aac_scsi_cmd(scsicmd);
476
477 scsicmd->result = DID_NO_CONNECT << 16;
478 scsicmd->scsi_done(scsicmd);
479 return 0;
480}
481
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400482static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700483{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700484 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700485 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700486 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
487
Mark Haverkamp03d44332007-03-15 10:27:45 -0700488
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400489 if (!aac_valid_context(scsicmd, fibptr))
490 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700491
492 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400493 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700494 if (fsa_dev_ptr) {
495 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
496 fsa_dev_ptr += scmd_id(scsicmd);
497
498 if ((le32_to_cpu(dresp->status) == ST_OK) &&
499 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
500 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
501 fsa_dev_ptr->valid = 1;
502 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
503 fsa_dev_ptr->size
504 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
505 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
506 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
507 }
508 if ((fsa_dev_ptr->valid & 1) == 0)
509 fsa_dev_ptr->valid = 0;
510 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
511 }
512 aac_fib_complete(fibptr);
513 aac_fib_free(fibptr);
514 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
515 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400516 (*callback)(scsicmd);
517 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700518}
519
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400520static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700521{
522 struct scsi_cmnd * scsicmd;
523 struct aac_mount * dresp;
524 struct aac_query_mount *dinfo;
525 int status;
526
527 dresp = (struct aac_mount *) fib_data(fibptr);
528 dresp->mnt[0].capacityhigh = 0;
529 if ((le32_to_cpu(dresp->status) != ST_OK) ||
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400530 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
531 _aac_probe_container2(context, fibptr);
532 return;
533 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700534 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700535
Mark Haverkamp03d44332007-03-15 10:27:45 -0700536 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400537 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700538
Mark Haverkampfe76df42007-03-15 12:55:07 -0700539 aac_fib_init(fibptr);
540
541 dinfo = (struct aac_query_mount *)fib_data(fibptr);
542
543 dinfo->command = cpu_to_le32(VM_NameServe64);
544 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
545 dinfo->type = cpu_to_le32(FT_FILESYS);
546
547 status = aac_fib_send(ContainerCommand,
548 fibptr,
549 sizeof(struct aac_query_mount),
550 FsaNormal,
551 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400552 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700553 (void *) scsicmd);
554 /*
555 * Check that the command queued to the controller
556 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400557 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700558 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400559 else if (status < 0) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700560 /* Inherit results from VM_NameServe, if any */
561 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400562 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700563 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700564}
565
566static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
567{
568 struct fib * fibptr;
569 int status = -ENOMEM;
570
571 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
572 struct aac_query_mount *dinfo;
573
574 aac_fib_init(fibptr);
575
576 dinfo = (struct aac_query_mount *)fib_data(fibptr);
577
578 dinfo->command = cpu_to_le32(VM_NameServe);
579 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
580 dinfo->type = cpu_to_le32(FT_FILESYS);
581 scsicmd->SCp.ptr = (char *)callback;
582
583 status = aac_fib_send(ContainerCommand,
584 fibptr,
585 sizeof(struct aac_query_mount),
586 FsaNormal,
587 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400588 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700589 (void *) scsicmd);
590 /*
591 * Check that the command queued to the controller
592 */
593 if (status == -EINPROGRESS) {
594 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
595 return 0;
596 }
597 if (status < 0) {
598 scsicmd->SCp.ptr = NULL;
599 aac_fib_complete(fibptr);
600 aac_fib_free(fibptr);
601 }
602 }
603 if (status < 0) {
604 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
605 if (fsa_dev_ptr) {
606 fsa_dev_ptr += scmd_id(scsicmd);
607 if ((fsa_dev_ptr->valid & 1) == 0) {
608 fsa_dev_ptr->valid = 0;
609 return (*callback)(scsicmd);
610 }
611 }
612 }
613 return status;
614}
615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800617 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 * @dev: device to query
619 * @cid: container identifier
620 *
621 * Queries the controller about the given volume. The volume information
622 * is updated in the struct fsa_dev_info structure rather than returned.
623 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700624static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
625{
626 scsicmd->device = NULL;
627 return 0;
628}
629
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800630int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700632 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
633 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Mark Haverkampfe76df42007-03-15 12:55:07 -0700636 if (!scsicmd || !scsidev) {
637 kfree(scsicmd);
638 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700639 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700641 scsicmd->list.next = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400642 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Mark Haverkampfe76df42007-03-15 12:55:07 -0700644 scsicmd->device = scsidev;
645 scsidev->sdev_state = 0;
646 scsidev->id = cid;
647 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Mark Haverkampfe76df42007-03-15 12:55:07 -0700649 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
650 while (scsicmd->device == scsidev)
651 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400652 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700653 status = scsicmd->SCp.Status;
654 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 return status;
656}
657
658/* Local Structure to set SCSI inquiry data strings */
659struct scsi_inq {
660 char vid[8]; /* Vendor ID */
661 char pid[16]; /* Product ID */
662 char prl[4]; /* Product Revision Level */
663};
664
665/**
666 * InqStrCopy - string merge
667 * @a: string to copy from
668 * @b: string to copy to
669 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800670 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 * without copying \0
672 */
673
674static void inqstrcpy(char *a, char *b)
675{
676
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800677 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 *b++ = *a++;
679}
680
681static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800682 "None",
683 "Volume",
684 "Mirror",
685 "Stripe",
686 "RAID5",
687 "SSRW",
688 "SSRO",
689 "Morph",
690 "Legacy",
691 "RAID4",
692 "RAID10",
693 "RAID00",
694 "V-MIRRORS",
695 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700697 "RAID5D",
698 "RAID5D0",
699 "RAID1E",
700 "RAID6",
701 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800702 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703};
704
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800705char * get_container_type(unsigned tindex)
706{
707 if (tindex >= ARRAY_SIZE(container_types))
708 tindex = ARRAY_SIZE(container_types) - 1;
709 return container_types[tindex];
710}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712/* Function: setinqstr
713 *
714 * Arguments: [1] pointer to void [1] int
715 *
716 * Purpose: Sets SCSI inquiry data strings for vendor, product
717 * and revision level. Allows strings to be set in platform dependant
718 * files instead of in OS dependant driver source.
719 */
720
Mark Haverkamp794d0602005-10-24 10:51:53 -0700721static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
723 struct scsi_inq *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700726 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Mark Haverkamp794d0602005-10-24 10:51:53 -0700728 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
729 char * cp = dev->supplement_adapter_info.AdapterTypeText;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800730 int c;
731 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
732 inqstrcpy("SMC", str->vid);
733 else {
734 c = sizeof(str->vid);
735 while (*cp && *cp != ' ' && --c)
736 ++cp;
737 c = *cp;
738 *cp = '\0';
739 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
740 str->vid);
741 *cp = c;
742 while (*cp && *cp != ' ')
743 ++cp;
744 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700745 while (*cp == ' ')
746 ++cp;
747 /* last six chars reserved for vol type */
748 c = 0;
749 if (strlen(cp) > sizeof(str->pid)) {
750 c = cp[sizeof(str->pid)];
751 cp[sizeof(str->pid)] = '\0';
752 }
753 inqstrcpy (cp, str->pid);
754 if (c)
755 cp[sizeof(str->pid)] = c;
756 } else {
757 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700758
759 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700760 /* last six chars reserved for vol type */
761 inqstrcpy (mp->model, str->pid);
762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Tobias Klauser6391a112006-06-08 22:23:48 -0700764 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 char *findit = str->pid;
766
767 for ( ; *findit != ' '; findit++); /* walk till we find a space */
768 /* RAID is superfluous in the context of a RAID device */
769 if (memcmp(findit-4, "RAID", 4) == 0)
770 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700771 if (((findit - str->pid) + strlen(container_types[tindex]))
772 < (sizeof(str->pid) + sizeof(str->prl)))
773 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
775 inqstrcpy ("V1.0", str->prl);
776}
777
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400778static void get_container_serial_callback(void *context, struct fib * fibptr)
779{
780 struct aac_get_serial_resp * get_serial_reply;
781 struct scsi_cmnd * scsicmd;
782
783 BUG_ON(fibptr == NULL);
784
785 scsicmd = (struct scsi_cmnd *) context;
786 if (!aac_valid_context(scsicmd, fibptr))
787 return;
788
789 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
790 /* Failure is irrelevant, using default value instead */
791 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
792 char sp[13];
793 /* EVPD bit set */
794 sp[0] = INQD_PDT_DA;
795 sp[1] = scsicmd->cmnd[2];
796 sp[2] = 0;
797 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
798 le32_to_cpu(get_serial_reply->uid));
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900799 scsi_sg_copy_from_buffer(scsicmd, sp, sizeof(sp));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400800 }
801
802 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
803
804 aac_fib_complete(fibptr);
805 aac_fib_free(fibptr);
806 scsicmd->scsi_done(scsicmd);
807}
808
809/**
810 * aac_get_container_serial - get container serial, none blocking.
811 */
812static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
813{
814 int status;
815 struct aac_get_serial *dinfo;
816 struct fib * cmd_fibcontext;
817 struct aac_dev * dev;
818
819 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
820
821 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
822 return -ENOMEM;
823
824 aac_fib_init(cmd_fibcontext);
825 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
826
827 dinfo->command = cpu_to_le32(VM_ContainerConfig);
828 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
829 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
830
831 status = aac_fib_send(ContainerCommand,
832 cmd_fibcontext,
833 sizeof (struct aac_get_serial),
834 FsaNormal,
835 0, 1,
836 (fib_callback) get_container_serial_callback,
837 (void *) scsicmd);
838
839 /*
840 * Check that the command queued to the controller
841 */
842 if (status == -EINPROGRESS) {
843 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
844 return 0;
845 }
846
847 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
848 aac_fib_complete(cmd_fibcontext);
849 aac_fib_free(cmd_fibcontext);
850 return -1;
851}
852
853/* Function: setinqserial
854 *
855 * Arguments: [1] pointer to void [1] int
856 *
857 * Purpose: Sets SCSI Unit Serial number.
858 * This is a fake. We should read a proper
859 * serial number from the container. <SuSE>But
860 * without docs it's quite hard to do it :-)
861 * So this will have to do in the meantime.</SuSE>
862 */
863
864static int setinqserial(struct aac_dev *dev, void *data, int cid)
865{
866 /*
867 * This breaks array migration.
868 */
869 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
870 le32_to_cpu(dev->adapter_info.serial[0]), cid);
871}
872
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800873static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
874 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800876 u8 *sense_buf = (u8 *)sense_data;
877 /* Sense data valid, err code 70h */
878 sense_buf[0] = 0x70; /* No info field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 sense_buf[1] = 0; /* Segment number, always zero */
880
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800881 sense_buf[2] = sense_key; /* Sense key */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 sense_buf[12] = sense_code; /* Additional sense code */
884 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 if (sense_key == ILLEGAL_REQUEST) {
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800887 sense_buf[7] = 10; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800889 sense_buf[15] = bit_pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 /* Illegal parameter is in the parameter block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 if (sense_code == SENCODE_INVALID_CDB_FIELD)
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800892 sense_buf[15] |= 0xc0;/* Std sense key specific field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 /* Illegal parameter is in the CDB block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 sense_buf[16] = field_pointer >> 8; /* MSB */
895 sense_buf[17] = field_pointer; /* LSB */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800896 } else
897 sense_buf[7] = 6; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898}
899
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800900static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
901{
902 if (lba & 0xffffffff00000000LL) {
903 int cid = scmd_id(cmd);
904 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
905 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
906 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800907 set_sense(&dev->fsa_dev[cid].sense_data,
908 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
909 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800910 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -0800911 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
912 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800913 cmd->scsi_done(cmd);
914 return 1;
915 }
916 return 0;
917}
918
919static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
920{
921 return 0;
922}
923
924static void io_callback(void *context, struct fib * fibptr);
925
926static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
927{
928 u16 fibsize;
929 struct aac_raw_io *readcmd;
930 aac_fib_init(fib);
931 readcmd = (struct aac_raw_io *) fib_data(fib);
932 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
933 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
934 readcmd->count = cpu_to_le32(count<<9);
935 readcmd->cid = cpu_to_le16(scmd_id(cmd));
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -0400936 readcmd->flags = cpu_to_le16(IO_TYPE_READ);
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800937 readcmd->bpTotal = 0;
938 readcmd->bpComplete = 0;
939
940 aac_build_sgraw(cmd, &readcmd->sg);
941 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
942 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
943 /*
944 * Now send the Fib to the adapter
945 */
946 return aac_fib_send(ContainerRawIo,
947 fib,
948 fibsize,
949 FsaNormal,
950 0, 1,
951 (fib_callback) io_callback,
952 (void *) cmd);
953}
954
955static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
956{
957 u16 fibsize;
958 struct aac_read64 *readcmd;
959 aac_fib_init(fib);
960 readcmd = (struct aac_read64 *) fib_data(fib);
961 readcmd->command = cpu_to_le32(VM_CtHostRead64);
962 readcmd->cid = cpu_to_le16(scmd_id(cmd));
963 readcmd->sector_count = cpu_to_le16(count);
964 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
965 readcmd->pad = 0;
966 readcmd->flags = 0;
967
968 aac_build_sg64(cmd, &readcmd->sg);
969 fibsize = sizeof(struct aac_read64) +
970 ((le32_to_cpu(readcmd->sg.count) - 1) *
971 sizeof (struct sgentry64));
972 BUG_ON (fibsize > (fib->dev->max_fib_size -
973 sizeof(struct aac_fibhdr)));
974 /*
975 * Now send the Fib to the adapter
976 */
977 return aac_fib_send(ContainerCommand64,
978 fib,
979 fibsize,
980 FsaNormal,
981 0, 1,
982 (fib_callback) io_callback,
983 (void *) cmd);
984}
985
986static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
987{
988 u16 fibsize;
989 struct aac_read *readcmd;
990 aac_fib_init(fib);
991 readcmd = (struct aac_read *) fib_data(fib);
992 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +0000993 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800994 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
995 readcmd->count = cpu_to_le32(count * 512);
996
997 aac_build_sg(cmd, &readcmd->sg);
998 fibsize = sizeof(struct aac_read) +
999 ((le32_to_cpu(readcmd->sg.count) - 1) *
1000 sizeof (struct sgentry));
1001 BUG_ON (fibsize > (fib->dev->max_fib_size -
1002 sizeof(struct aac_fibhdr)));
1003 /*
1004 * Now send the Fib to the adapter
1005 */
1006 return aac_fib_send(ContainerCommand,
1007 fib,
1008 fibsize,
1009 FsaNormal,
1010 0, 1,
1011 (fib_callback) io_callback,
1012 (void *) cmd);
1013}
1014
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001015static 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 -08001016{
1017 u16 fibsize;
1018 struct aac_raw_io *writecmd;
1019 aac_fib_init(fib);
1020 writecmd = (struct aac_raw_io *) fib_data(fib);
1021 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1022 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1023 writecmd->count = cpu_to_le32(count<<9);
1024 writecmd->cid = cpu_to_le16(scmd_id(cmd));
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001025 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1026 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001027 cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) :
1028 cpu_to_le16(IO_TYPE_WRITE);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001029 writecmd->bpTotal = 0;
1030 writecmd->bpComplete = 0;
1031
1032 aac_build_sgraw(cmd, &writecmd->sg);
1033 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1034 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1035 /*
1036 * Now send the Fib to the adapter
1037 */
1038 return aac_fib_send(ContainerRawIo,
1039 fib,
1040 fibsize,
1041 FsaNormal,
1042 0, 1,
1043 (fib_callback) io_callback,
1044 (void *) cmd);
1045}
1046
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001047static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001048{
1049 u16 fibsize;
1050 struct aac_write64 *writecmd;
1051 aac_fib_init(fib);
1052 writecmd = (struct aac_write64 *) fib_data(fib);
1053 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1054 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1055 writecmd->sector_count = cpu_to_le16(count);
1056 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1057 writecmd->pad = 0;
1058 writecmd->flags = 0;
1059
1060 aac_build_sg64(cmd, &writecmd->sg);
1061 fibsize = sizeof(struct aac_write64) +
1062 ((le32_to_cpu(writecmd->sg.count) - 1) *
1063 sizeof (struct sgentry64));
1064 BUG_ON (fibsize > (fib->dev->max_fib_size -
1065 sizeof(struct aac_fibhdr)));
1066 /*
1067 * Now send the Fib to the adapter
1068 */
1069 return aac_fib_send(ContainerCommand64,
1070 fib,
1071 fibsize,
1072 FsaNormal,
1073 0, 1,
1074 (fib_callback) io_callback,
1075 (void *) cmd);
1076}
1077
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001078static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001079{
1080 u16 fibsize;
1081 struct aac_write *writecmd;
1082 aac_fib_init(fib);
1083 writecmd = (struct aac_write *) fib_data(fib);
1084 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001085 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001086 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1087 writecmd->count = cpu_to_le32(count * 512);
1088 writecmd->sg.count = cpu_to_le32(1);
1089 /* ->stable is not used - it did mean which type of write */
1090
1091 aac_build_sg(cmd, &writecmd->sg);
1092 fibsize = sizeof(struct aac_write) +
1093 ((le32_to_cpu(writecmd->sg.count) - 1) *
1094 sizeof (struct sgentry));
1095 BUG_ON (fibsize > (fib->dev->max_fib_size -
1096 sizeof(struct aac_fibhdr)));
1097 /*
1098 * Now send the Fib to the adapter
1099 */
1100 return aac_fib_send(ContainerCommand,
1101 fib,
1102 fibsize,
1103 FsaNormal,
1104 0, 1,
1105 (fib_callback) io_callback,
1106 (void *) cmd);
1107}
1108
1109static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1110{
1111 struct aac_srb * srbcmd;
1112 u32 flag;
1113 u32 timeout;
1114
1115 aac_fib_init(fib);
1116 switch(cmd->sc_data_direction){
1117 case DMA_TO_DEVICE:
1118 flag = SRB_DataOut;
1119 break;
1120 case DMA_BIDIRECTIONAL:
1121 flag = SRB_DataIn | SRB_DataOut;
1122 break;
1123 case DMA_FROM_DEVICE:
1124 flag = SRB_DataIn;
1125 break;
1126 case DMA_NONE:
1127 default: /* shuts up some versions of gcc */
1128 flag = SRB_NoDataXfer;
1129 break;
1130 }
1131
1132 srbcmd = (struct aac_srb*) fib_data(fib);
1133 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1134 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1135 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1136 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1137 srbcmd->flags = cpu_to_le32(flag);
1138 timeout = cmd->timeout_per_command/HZ;
1139 if (timeout == 0)
1140 timeout = 1;
1141 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1142 srbcmd->retry_limit = 0; /* Obsolete parameter */
1143 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1144 return srbcmd;
1145}
1146
1147static void aac_srb_callback(void *context, struct fib * fibptr);
1148
1149static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1150{
1151 u16 fibsize;
1152 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1153
1154 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001155 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001156
1157 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1158 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1159 /*
1160 * Build Scatter/Gather list
1161 */
1162 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1163 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1164 sizeof (struct sgentry64));
1165 BUG_ON (fibsize > (fib->dev->max_fib_size -
1166 sizeof(struct aac_fibhdr)));
1167
1168 /*
1169 * Now send the Fib to the adapter
1170 */
1171 return aac_fib_send(ScsiPortCommand64, fib,
1172 fibsize, FsaNormal, 0, 1,
1173 (fib_callback) aac_srb_callback,
1174 (void *) cmd);
1175}
1176
1177static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1178{
1179 u16 fibsize;
1180 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1181
1182 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001183 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001184
1185 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1186 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1187 /*
1188 * Build Scatter/Gather list
1189 */
1190 fibsize = sizeof (struct aac_srb) +
1191 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1192 sizeof (struct sgentry));
1193 BUG_ON (fibsize > (fib->dev->max_fib_size -
1194 sizeof(struct aac_fibhdr)));
1195
1196 /*
1197 * Now send the Fib to the adapter
1198 */
1199 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1200 (fib_callback) aac_srb_callback, (void *) cmd);
1201}
1202
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001203static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1204{
1205 if ((sizeof(dma_addr_t) > 4) &&
1206 (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) &&
1207 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1208 return FAILED;
1209 return aac_scsi_32(fib, cmd);
1210}
1211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212int aac_get_adapter_info(struct aac_dev* dev)
1213{
1214 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 int rcode;
1216 u32 tmp;
Mark Haverkamp84971732005-06-20 11:55:24 -07001217 struct aac_adapter_info *info;
1218 struct aac_bus_info *command;
1219 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001220
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001221 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 return -ENOMEM;
1223
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001224 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001225 info = (struct aac_adapter_info *) fib_data(fibptr);
1226 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001228 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001229 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001230 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001231 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07001232 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001233 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001234 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001236 if (rcode < 0) {
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001237 aac_fib_complete(fibptr);
1238 aac_fib_free(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001239 return rcode;
1240 }
1241 memcpy(&dev->adapter_info, info, sizeof(*info));
1242
1243 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001244 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001245
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001246 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001247
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001248 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001249
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001250 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001251
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001252 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001253 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001254 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001255 FsaNormal,
1256 1, 1,
1257 NULL,
1258 NULL);
1259
1260 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001261 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Mark Haverkamp84971732005-06-20 11:55:24 -07001264
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001265 /*
1266 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07001267 */
1268
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001269 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07001270
1271 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1272
1273 memset(bus_info, 0, sizeof(*bus_info));
1274
1275 command = (struct aac_bus_info *)bus_info;
1276
1277 command->Command = cpu_to_le32(VM_Ioctl);
1278 command->ObjType = cpu_to_le32(FT_DRIVE);
1279 command->MethodId = cpu_to_le32(1);
1280 command->CtlCmd = cpu_to_le32(GetBusInfo);
1281
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001282 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07001283 fibptr,
1284 sizeof (*bus_info),
1285 FsaNormal,
1286 1, 1,
1287 NULL, NULL);
1288
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001289 /* reasoned default */
1290 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07001291 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1292 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1293 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1294 }
1295
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001296 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001297 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001298 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1299 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001300 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 dev->id,
1302 tmp>>24,
1303 (tmp>>16)&0xff,
1304 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001305 le32_to_cpu(dev->adapter_info.kernelbuild),
1306 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1307 dev->supplement_adapter_info.BuildDate);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001308 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1309 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 dev->name, dev->id,
1311 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1312 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001313 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1314 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 dev->name, dev->id,
1316 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1317 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001318 buffer[0] = '\0';
1319 if (aac_show_serial_number(
1320 shost_to_class(dev->scsi_host_ptr), buffer))
1321 printk(KERN_INFO "%s%d: serial %s",
1322 dev->name, dev->id, buffer);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04001323 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1324 printk(KERN_INFO "%s%d: TSID %.*s\n",
1325 dev->name, dev->id,
1326 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1327 dev->supplement_adapter_info.VpdInfo.Tsid);
1328 }
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001329 if (!aac_check_reset || ((aac_check_reset == 1) &&
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001330 (dev->supplement_adapter_info.SupportedOptions2 &
1331 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001332 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1333 dev->name, dev->id);
1334 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001337 dev->cache_protected = 0;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001338 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1339 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 dev->nondasd_support = 0;
1341 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001342 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 /*
1346 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1347 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1348 * force nondasd support on. If we decide to allow the non-dasd flag
1349 * additional changes changes will have to be made to support
1350 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1351 * changed to support the new dev->raid_scsi_mode flag instead of
1352 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1353 * function aac_detect will have to be modified where it sets up the
1354 * max number of channels based on the aac->nondasd_support flag only.
1355 */
1356 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1357 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1358 dev->nondasd_support = 1;
1359 dev->raid_scsi_mode = 1;
1360 }
1361 if (dev->raid_scsi_mode != 0)
1362 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1363 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001364
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001365 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001367 if (dev->nondasd_support && !dev->in_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
1370 dev->dac_support = 0;
1371 if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001372 if (!dev->in_reset)
1373 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
1374 dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 dev->dac_support = 1;
1376 }
1377
1378 if(dacmode != -1) {
1379 dev->dac_support = (dacmode!=0);
1380 }
1381 if(dev->dac_support != 0) {
James Bottomley71e0f322005-10-28 11:21:10 -05001382 if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) &&
1383 !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001384 if (!dev->in_reset)
1385 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1386 dev->name, dev->id);
James Bottomley71e0f322005-10-28 11:21:10 -05001387 } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) &&
1388 !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1390 dev->name, dev->id);
1391 dev->dac_support = 0;
1392 } else {
1393 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1394 dev->name, dev->id);
1395 rcode = -ENOMEM;
1396 }
1397 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001398 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001399 * Deal with configuring for the individualized limits of each packet
1400 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001401 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001402 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001403 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1404 ? aac_scsi_32_64
1405 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001406 : aac_scsi_32;
1407 if (dev->raw_io_interface) {
1408 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1409 ? aac_bounds_64
1410 : aac_bounds_32;
1411 dev->a_ops.adapter_read = aac_read_raw_io;
1412 dev->a_ops.adapter_write = aac_write_raw_io;
1413 } else {
1414 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001415 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001416 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001417 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1418 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001419 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001420 dev->a_ops.adapter_read = aac_read_block64;
1421 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001422 /*
1423 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001424 */
1425 dev->scsi_host_ptr->sg_tablesize =
1426 (dev->max_fib_size -
1427 sizeof(struct aac_fibhdr) -
1428 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001429 sizeof(struct sgentry64)) /
1430 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001431 } else {
1432 dev->a_ops.adapter_read = aac_read_block;
1433 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001434 }
1435 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
1436 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
1437 /*
1438 * Worst case size that could cause sg overflow when
1439 * we break up SG elements that are larger than 64KB.
1440 * Would be nice if we could tell the SCSI layer what
1441 * the maximum SG element size can be. Worst case is
1442 * (sg_tablesize-1) 4KB elements with one 64KB
1443 * element.
1444 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1445 */
1446 dev->scsi_host_ptr->max_sectors =
1447 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1448 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001451 aac_fib_complete(fibptr);
1452 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
1454 return rcode;
1455}
1456
1457
Mark Haverkampe53cb352005-08-03 15:39:09 -07001458static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
1460 struct aac_dev *dev;
1461 struct aac_read_reply *readreply;
1462 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 u32 cid;
1464
1465 scsicmd = (struct scsi_cmnd *) context;
1466
Mark Haverkamp03d44332007-03-15 10:27:45 -07001467 if (!aac_valid_context(scsicmd, fibptr))
1468 return;
1469
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001470 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001471 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001473 if (nblank(dprintk(x))) {
1474 u64 lba;
1475 switch (scsicmd->cmnd[0]) {
1476 case WRITE_6:
1477 case READ_6:
1478 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1479 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1480 break;
1481 case WRITE_16:
1482 case READ_16:
1483 lba = ((u64)scsicmd->cmnd[2] << 56) |
1484 ((u64)scsicmd->cmnd[3] << 48) |
1485 ((u64)scsicmd->cmnd[4] << 40) |
1486 ((u64)scsicmd->cmnd[5] << 32) |
1487 ((u64)scsicmd->cmnd[6] << 24) |
1488 (scsicmd->cmnd[7] << 16) |
1489 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1490 break;
1491 case WRITE_12:
1492 case READ_12:
1493 lba = ((u64)scsicmd->cmnd[2] << 24) |
1494 (scsicmd->cmnd[3] << 16) |
1495 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1496 break;
1497 default:
1498 lba = ((u64)scsicmd->cmnd[2] << 24) |
1499 (scsicmd->cmnd[3] << 16) |
1500 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1501 break;
1502 }
1503 printk(KERN_DEBUG
1504 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1505 smp_processor_id(), (unsigned long long)lba, jiffies);
1506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Eric Sesterhenn125e1872006-06-23 02:06:06 -07001508 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001509
1510 scsi_dma_unmap(scsicmd);
1511
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 readreply = (struct aac_read_reply *)fib_data(fibptr);
1513 if (le32_to_cpu(readreply->status) == ST_OK)
1514 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1515 else {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001516#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07001517 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001518 le32_to_cpu(readreply->status));
1519#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001521 set_sense(&dev->fsa_dev[cid].sense_data,
1522 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1523 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001525 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1526 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001528 aac_fib_complete(fibptr);
1529 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001531 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532}
1533
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001534static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001536 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 u32 count;
1538 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 struct aac_dev *dev;
1540 struct fib * cmd_fibcontext;
1541
1542 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1543 /*
1544 * Get block address and transfer length
1545 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001546 switch (scsicmd->cmnd[0]) {
1547 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001548 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001550 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001551 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 count = scsicmd->cmnd[4];
1553
1554 if (count == 0)
1555 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001556 break;
1557 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001558 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001559
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001560 lba = ((u64)scsicmd->cmnd[2] << 56) |
1561 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001562 ((u64)scsicmd->cmnd[4] << 40) |
1563 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001564 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001565 (scsicmd->cmnd[7] << 16) |
1566 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001567 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001568 (scsicmd->cmnd[11] << 16) |
1569 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1570 break;
1571 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001572 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001573
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001574 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001575 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001576 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1577 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001578 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001579 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001580 break;
1581 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001582 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001584 lba = ((u64)scsicmd->cmnd[2] << 24) |
1585 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001586 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001588 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001590 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001591 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001592 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001593 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 /*
1595 * Alocate and initialize a Fib
1596 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001597 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 return -1;
1599 }
1600
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001601 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
1603 /*
1604 * Check that the command queued to the controller
1605 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001606 if (status == -EINPROGRESS) {
1607 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001609 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001610
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001611 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 /*
1613 * For some reason, the Fib didn't queue, return QUEUE_FULL
1614 */
1615 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001616 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001617 aac_fib_complete(cmd_fibcontext);
1618 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 return 0;
1620}
1621
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001622static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001624 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001626 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 struct aac_dev *dev;
1629 struct fib * cmd_fibcontext;
1630
1631 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1632 /*
1633 * Get block address and transfer length
1634 */
1635 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1636 {
1637 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1638 count = scsicmd->cmnd[4];
1639 if (count == 0)
1640 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001641 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001642 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001643 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001644
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001645 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001646 ((u64)scsicmd->cmnd[3] << 48) |
1647 ((u64)scsicmd->cmnd[4] << 40) |
1648 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001649 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001650 (scsicmd->cmnd[7] << 16) |
1651 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1652 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1653 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001654 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001655 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001656 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001657
1658 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1659 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1660 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1661 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001662 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001664 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001665 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001667 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001669 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001671 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001672 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 /*
1674 * Allocate and initialize a Fib then setup a BlockWrite command
1675 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001676 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 scsicmd->result = DID_ERROR << 16;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001678 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 return 0;
1680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001682 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
1684 /*
1685 * Check that the command queued to the controller
1686 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001687 if (status == -EINPROGRESS) {
1688 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 return 0;
1690 }
1691
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001692 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 /*
1694 * For some reason, the Fib didn't queue, return QUEUE_FULL
1695 */
1696 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001697 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001699 aac_fib_complete(cmd_fibcontext);
1700 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 return 0;
1702}
1703
1704static void synchronize_callback(void *context, struct fib *fibptr)
1705{
1706 struct aac_synchronize_reply *synchronizereply;
1707 struct scsi_cmnd *cmd;
1708
1709 cmd = context;
1710
Mark Haverkamp03d44332007-03-15 10:27:45 -07001711 if (!aac_valid_context(cmd, fibptr))
1712 return;
1713
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001714 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 smp_processor_id(), jiffies));
1716 BUG_ON(fibptr == NULL);
1717
1718
1719 synchronizereply = fib_data(fibptr);
1720 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001721 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1723 else {
1724 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001725 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001726 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001727 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 "synchronize_callback: synchronize failed, status = %d\n",
1729 le32_to_cpu(synchronizereply->status));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001730 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001732 set_sense(&dev->fsa_dev[cid].sense_data,
1733 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1734 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001736 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1737 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 }
1739
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001740 aac_fib_complete(fibptr);
1741 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001742 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
1744
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001745static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746{
1747 int status;
1748 struct fib *cmd_fibcontext;
1749 struct aac_synchronize *synchronizecmd;
1750 struct scsi_cmnd *cmd;
1751 struct scsi_device *sdev = scsicmd->device;
1752 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001753 struct aac_dev *aac;
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001754 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1755 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1756 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 unsigned long flags;
1758
1759 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001760 * Wait for all outstanding queued commands to complete to this
1761 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 */
1763 spin_lock_irqsave(&sdev->list_lock, flags);
1764 list_for_each_entry(cmd, &sdev->cmd_list, list)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001765 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1766 u64 cmnd_lba;
1767 u32 cmnd_count;
1768
1769 if (cmd->cmnd[0] == WRITE_6) {
1770 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1771 (cmd->cmnd[2] << 8) |
1772 cmd->cmnd[3];
1773 cmnd_count = cmd->cmnd[4];
1774 if (cmnd_count == 0)
1775 cmnd_count = 256;
1776 } else if (cmd->cmnd[0] == WRITE_16) {
1777 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1778 ((u64)cmd->cmnd[3] << 48) |
1779 ((u64)cmd->cmnd[4] << 40) |
1780 ((u64)cmd->cmnd[5] << 32) |
1781 ((u64)cmd->cmnd[6] << 24) |
1782 (cmd->cmnd[7] << 16) |
1783 (cmd->cmnd[8] << 8) |
1784 cmd->cmnd[9];
1785 cmnd_count = (cmd->cmnd[10] << 24) |
1786 (cmd->cmnd[11] << 16) |
1787 (cmd->cmnd[12] << 8) |
1788 cmd->cmnd[13];
1789 } else if (cmd->cmnd[0] == WRITE_12) {
1790 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1791 (cmd->cmnd[3] << 16) |
1792 (cmd->cmnd[4] << 8) |
1793 cmd->cmnd[5];
1794 cmnd_count = (cmd->cmnd[6] << 24) |
1795 (cmd->cmnd[7] << 16) |
1796 (cmd->cmnd[8] << 8) |
1797 cmd->cmnd[9];
1798 } else if (cmd->cmnd[0] == WRITE_10) {
1799 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1800 (cmd->cmnd[3] << 16) |
1801 (cmd->cmnd[4] << 8) |
1802 cmd->cmnd[5];
1803 cmnd_count = (cmd->cmnd[7] << 8) |
1804 cmd->cmnd[8];
1805 } else
1806 continue;
1807 if (((cmnd_lba + cmnd_count) < lba) ||
1808 (count && ((lba + count) < cmnd_lba)))
1809 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 ++active;
1811 break;
1812 }
1813
1814 spin_unlock_irqrestore(&sdev->list_lock, flags);
1815
1816 /*
1817 * Yield the processor (requeue for later)
1818 */
1819 if (active)
1820 return SCSI_MLQUEUE_DEVICE_BUSY;
1821
Salyzyn, Markf8583172007-10-30 15:50:49 -04001822 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001823 if (aac->in_reset)
1824 return SCSI_MLQUEUE_HOST_BUSY;
1825
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001827 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001829 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 return SCSI_MLQUEUE_HOST_BUSY;
1831
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001832 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834 synchronizecmd = fib_data(cmd_fibcontext);
1835 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1836 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001837 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001838 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
1840
1841 /*
1842 * Now send the Fib to the adapter
1843 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001844 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 cmd_fibcontext,
1846 sizeof(struct aac_synchronize),
1847 FsaNormal,
1848 0, 1,
1849 (fib_callback)synchronize_callback,
1850 (void *)scsicmd);
1851
1852 /*
1853 * Check that the command queued to the controller
1854 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001855 if (status == -EINPROGRESS) {
1856 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001860 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001861 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
1862 aac_fib_complete(cmd_fibcontext);
1863 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 return SCSI_MLQUEUE_HOST_BUSY;
1865}
1866
1867/**
1868 * aac_scsi_cmd() - Process SCSI command
1869 * @scsicmd: SCSI command block
1870 *
1871 * Emulate a SCSI command and queue the required request for the
1872 * aacraid firmware.
1873 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001874
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1876{
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001877 u32 cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 struct Scsi_Host *host = scsicmd->device->host;
1879 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1880 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001881
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001882 if (fsa_dev_ptr == NULL)
1883 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 /*
1885 * If the bus, id or lun is out of range, return fail
1886 * Test does not apply to ID 16, the pseudo id for the controller
1887 * itself.
1888 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001889 cid = scmd_id(scsicmd);
1890 if (cid != host->this_id) {
1891 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
1892 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08001893 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 scsicmd->result = DID_NO_CONNECT << 16;
1895 scsicmd->scsi_done(scsicmd);
1896 return 0;
1897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899 /*
1900 * If the target container doesn't exist, it may have
1901 * been newly created
1902 */
1903 if ((fsa_dev_ptr[cid].valid & 1) == 0) {
1904 switch (scsicmd->cmnd[0]) {
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001905 case SERVICE_ACTION_IN:
1906 if (!(dev->raw_io_interface) ||
1907 !(dev->raw_io_64) ||
1908 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
1909 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 case INQUIRY:
1911 case READ_CAPACITY:
1912 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001913 if (dev->in_reset)
1914 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07001915 return _aac_probe_container(scsicmd,
1916 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 default:
1918 break;
1919 }
1920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 } else { /* check for physical non-dasd devices */
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001922 if (dev->nondasd_support || expose_physicals ||
1923 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001924 if (dev->in_reset)
1925 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 return aac_send_srb_fib(scsicmd);
1927 } else {
1928 scsicmd->result = DID_NO_CONNECT << 16;
1929 scsicmd->scsi_done(scsicmd);
1930 return 0;
1931 }
1932 }
1933 }
1934 /*
1935 * else Command for the controller itself
1936 */
1937 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001938 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 {
1940 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
1941 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001942 set_sense(&dev->fsa_dev[cid].sense_data,
1943 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
1944 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001946 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1947 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 scsicmd->scsi_done(scsicmd);
1949 return 0;
1950 }
1951
1952
1953 /* Handle commands here that don't really require going out to the adapter */
1954 switch (scsicmd->cmnd[0]) {
1955 case INQUIRY:
1956 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001957 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001959 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07001960 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001962 if (scsicmd->cmnd[1] & 0x1) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001963 char *arr = (char *)&inq_data;
1964
1965 /* EVPD bit set */
1966 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
1967 INQD_PDT_PROC : INQD_PDT_DA;
1968 if (scsicmd->cmnd[2] == 0) {
1969 /* supported vital product data pages */
1970 arr[3] = 2;
1971 arr[4] = 0x0;
1972 arr[5] = 0x80;
1973 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09001974 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
1975 sizeof(inq_data));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001976 scsicmd->result = DID_OK << 16 |
1977 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1978 } else if (scsicmd->cmnd[2] == 0x80) {
1979 /* unit serial number page */
1980 arr[3] = setinqserial(dev, &arr[4],
1981 scmd_id(scsicmd));
1982 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09001983 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
1984 sizeof(inq_data));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001985 return aac_get_container_serial(scsicmd);
1986 } else {
1987 /* vpd page not implemented */
1988 scsicmd->result = DID_OK << 16 |
1989 COMMAND_COMPLETE << 8 |
1990 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001991 set_sense(&dev->fsa_dev[cid].sense_data,
1992 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
1993 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001994 memcpy(scsicmd->sense_buffer,
1995 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001996 min_t(size_t,
1997 sizeof(dev->fsa_dev[cid].sense_data),
1998 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001999 }
2000 scsicmd->scsi_done(scsicmd);
2001 return 0;
2002 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002003 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002004 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 */
2005 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002007 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 /*
2009 * Set the Vendor, Product, and Revision Level
2010 * see: <vendor>.c i.e. aac.c
2011 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002012 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07002013 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002014 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002015 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2016 sizeof(inq_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2018 scsicmd->scsi_done(scsicmd);
2019 return 0;
2020 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002021 if (dev->in_reset)
2022 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07002023 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002024 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002025 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002026 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002028 case SERVICE_ACTION_IN:
2029 if (!(dev->raw_io_interface) ||
2030 !(dev->raw_io_64) ||
2031 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2032 break;
2033 {
2034 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002035 char cp[13];
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002036 unsigned int alloc_len;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002037
2038 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2039 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002040 cp[0] = (capacity >> 56) & 0xff;
2041 cp[1] = (capacity >> 48) & 0xff;
2042 cp[2] = (capacity >> 40) & 0xff;
2043 cp[3] = (capacity >> 32) & 0xff;
2044 cp[4] = (capacity >> 24) & 0xff;
2045 cp[5] = (capacity >> 16) & 0xff;
2046 cp[6] = (capacity >> 8) & 0xff;
2047 cp[7] = (capacity >> 0) & 0xff;
2048 cp[8] = 0;
2049 cp[9] = 0;
2050 cp[10] = 2;
2051 cp[11] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002052 cp[12] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002053
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002054 alloc_len = ((scsicmd->cmnd[10] << 24)
2055 + (scsicmd->cmnd[11] << 16)
2056 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2057
2058 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002059 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002060 if (alloc_len < scsi_bufflen(scsicmd))
2061 scsi_set_resid(scsicmd,
2062 scsi_bufflen(scsicmd) - alloc_len);
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002063
2064 /* Do not cache partition table for arrays */
2065 scsicmd->device->removable = 1;
2066
2067 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2068 scsicmd->scsi_done(scsicmd);
2069
2070 return 0;
2071 }
2072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 case READ_CAPACITY:
2074 {
2075 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002076 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
2078 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002079 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 capacity = fsa_dev_ptr[cid].size - 1;
2081 else
2082 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002083
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 cp[0] = (capacity >> 24) & 0xff;
2085 cp[1] = (capacity >> 16) & 0xff;
2086 cp[2] = (capacity >> 8) & 0xff;
2087 cp[3] = (capacity >> 0) & 0xff;
2088 cp[4] = 0;
2089 cp[5] = 0;
2090 cp[6] = 2;
2091 cp[7] = 0;
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002092 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002093 /* Do not cache partition table for arrays */
2094 scsicmd->device->removable = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
2096 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2097 scsicmd->scsi_done(scsicmd);
2098
2099 return 0;
2100 }
2101
2102 case MODE_SENSE:
2103 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002104 char mode_buf[7];
2105 int mode_buf_length = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
2107 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 mode_buf[0] = 3; /* Mode data length */
2109 mode_buf[1] = 0; /* Medium type - default */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002110 mode_buf[2] = 0; /* Device-specific param,
2111 bit 8: 0/1 = write enabled/protected
2112 bit 4: 0/1 = FUA enabled */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002113 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002114 mode_buf[2] = 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 mode_buf[3] = 0; /* Block descriptor length */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002116 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2117 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2118 mode_buf[0] = 6;
2119 mode_buf[4] = 8;
2120 mode_buf[5] = 1;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002121 mode_buf[6] = ((aac_cache & 6) == 2)
2122 ? 0 : 0x04; /* WCE */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002123 mode_buf_length = 7;
2124 if (mode_buf_length > scsicmd->cmnd[4])
2125 mode_buf_length = scsicmd->cmnd[4];
2126 }
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002127 scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2129 scsicmd->scsi_done(scsicmd);
2130
2131 return 0;
2132 }
2133 case MODE_SENSE_10:
2134 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002135 char mode_buf[11];
2136 int mode_buf_length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
2138 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 mode_buf[0] = 0; /* Mode data length (MSB) */
2140 mode_buf[1] = 6; /* Mode data length (LSB) */
2141 mode_buf[2] = 0; /* Medium type - default */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002142 mode_buf[3] = 0; /* Device-specific param,
2143 bit 8: 0/1 = write enabled/protected
2144 bit 4: 0/1 = FUA enabled */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002145 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002146 mode_buf[3] = 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 mode_buf[4] = 0; /* reserved */
2148 mode_buf[5] = 0; /* reserved */
2149 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2150 mode_buf[7] = 0; /* Block descriptor length (LSB) */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002151 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2152 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2153 mode_buf[1] = 9;
2154 mode_buf[8] = 8;
2155 mode_buf[9] = 1;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002156 mode_buf[10] = ((aac_cache & 6) == 2)
2157 ? 0 : 0x04; /* WCE */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002158 mode_buf_length = 11;
2159 if (mode_buf_length > scsicmd->cmnd[8])
2160 mode_buf_length = scsicmd->cmnd[8];
2161 }
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002162 scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2165 scsicmd->scsi_done(scsicmd);
2166
2167 return 0;
2168 }
2169 case REQUEST_SENSE:
2170 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2171 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2172 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2173 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2174 scsicmd->scsi_done(scsicmd);
2175 return 0;
2176
2177 case ALLOW_MEDIUM_REMOVAL:
2178 dprintk((KERN_DEBUG "LOCK command.\n"));
2179 if (scsicmd->cmnd[4])
2180 fsa_dev_ptr[cid].locked = 1;
2181 else
2182 fsa_dev_ptr[cid].locked = 0;
2183
2184 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2185 scsicmd->scsi_done(scsicmd);
2186 return 0;
2187 /*
2188 * These commands are all No-Ops
2189 */
2190 case TEST_UNIT_READY:
2191 case RESERVE:
2192 case RELEASE:
2193 case REZERO_UNIT:
2194 case REASSIGN_BLOCKS:
2195 case SEEK_10:
2196 case START_STOP:
2197 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2198 scsicmd->scsi_done(scsicmd);
2199 return 0;
2200 }
2201
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002202 switch (scsicmd->cmnd[0])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 {
2204 case READ_6:
2205 case READ_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002206 case READ_12:
2207 case READ_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002208 if (dev->in_reset)
2209 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 /*
2211 * Hack to keep track of ordinal number of the device that
2212 * corresponds to a container. Needed to convert
2213 * containers to /dev/sd device names
2214 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002215
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002216 if (scsicmd->request->rq_disk)
2217 strlcpy(fsa_dev_ptr[cid].devname,
2218 scsicmd->request->rq_disk->disk_name,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002219 min(sizeof(fsa_dev_ptr[cid].devname),
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002220 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002221
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002222 return aac_read(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
2224 case WRITE_6:
2225 case WRITE_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002226 case WRITE_12:
2227 case WRITE_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002228 if (dev->in_reset)
2229 return -1;
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002230 return aac_write(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
2232 case SYNCHRONIZE_CACHE:
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002233 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2234 scsicmd->result = DID_OK << 16 |
2235 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2236 scsicmd->scsi_done(scsicmd);
2237 return 0;
2238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 /* Issue FIB to tell Firmware to flush it's cache */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002240 if ((aac_cache & 6) != 2)
2241 return aac_synchronize(scsicmd);
2242 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 default:
2244 /*
2245 * Unhandled commands
2246 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002247 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002249 set_sense(&dev->fsa_dev[cid].sense_data,
2250 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2251 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002253 min_t(size_t,
2254 sizeof(dev->fsa_dev[cid].sense_data),
2255 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 scsicmd->scsi_done(scsicmd);
2257 return 0;
2258 }
2259}
2260
2261static int query_disk(struct aac_dev *dev, void __user *arg)
2262{
2263 struct aac_query_disk qd;
2264 struct fsa_dev_info *fsa_dev_ptr;
2265
2266 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002267 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07002268 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2270 return -EFAULT;
2271 if (qd.cnum == -1)
Mark Haverkampe5718772006-03-27 09:43:25 -08002272 qd.cnum = qd.id;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002273 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 {
2275 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2276 return -EINVAL;
2277 qd.instance = dev->scsi_host_ptr->host_no;
2278 qd.bus = 0;
2279 qd.id = CONTAINER_TO_ID(qd.cnum);
2280 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2281 }
2282 else return -EINVAL;
2283
Salyzyn, Markfd622b12007-07-17 10:59:19 -04002284 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2286 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2287
2288 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2289 qd.unmapped = 1;
2290 else
2291 qd.unmapped = 0;
2292
2293 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2294 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2295
2296 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2297 return -EFAULT;
2298 return 0;
2299}
2300
2301static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2302{
2303 struct aac_delete_disk dd;
2304 struct fsa_dev_info *fsa_dev_ptr;
2305
2306 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp65101352006-09-19 08:59:23 -07002307 if (!fsa_dev_ptr)
2308 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
2310 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2311 return -EFAULT;
2312
2313 if (dd.cnum >= dev->maximum_num_containers)
2314 return -EINVAL;
2315 /*
2316 * Mark this container as being deleted.
2317 */
2318 fsa_dev_ptr[dd.cnum].deleted = 1;
2319 /*
2320 * Mark the container as no longer valid
2321 */
2322 fsa_dev_ptr[dd.cnum].valid = 0;
2323 return 0;
2324}
2325
2326static int delete_disk(struct aac_dev *dev, void __user *arg)
2327{
2328 struct aac_delete_disk dd;
2329 struct fsa_dev_info *fsa_dev_ptr;
2330
2331 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002332 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07002333 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
2335 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2336 return -EFAULT;
2337
2338 if (dd.cnum >= dev->maximum_num_containers)
2339 return -EINVAL;
2340 /*
2341 * If the container is locked, it can not be deleted by the API.
2342 */
2343 if (fsa_dev_ptr[dd.cnum].locked)
2344 return -EBUSY;
2345 else {
2346 /*
2347 * Mark the container as no longer being valid.
2348 */
2349 fsa_dev_ptr[dd.cnum].valid = 0;
2350 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2351 return 0;
2352 }
2353}
2354
2355int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2356{
2357 switch (cmd) {
2358 case FSACTL_QUERY_DISK:
2359 return query_disk(dev, arg);
2360 case FSACTL_DELETE_DISK:
2361 return delete_disk(dev, arg);
2362 case FSACTL_FORCE_DELETE_DISK:
2363 return force_delete_disk(dev, arg);
2364 case FSACTL_GET_CONTAINERS:
2365 return aac_get_containers(dev);
2366 default:
2367 return -ENOTTY;
2368 }
2369}
2370
2371/**
2372 *
2373 * aac_srb_callback
2374 * @context: the context set in the fib - here it is scsi cmd
2375 * @fibptr: pointer to the fib
2376 *
2377 * Handles the completion of a scsi command to a non dasd device
2378 *
2379 */
2380
2381static void aac_srb_callback(void *context, struct fib * fibptr)
2382{
2383 struct aac_dev *dev;
2384 struct aac_srb_reply *srbreply;
2385 struct scsi_cmnd *scsicmd;
2386
2387 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07002388
2389 if (!aac_valid_context(scsicmd, fibptr))
2390 return;
2391
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002392 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002394 dev = fibptr->dev;
2395
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2397
2398 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
2399 /*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002400 * Calculate resid for sg
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002403 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2404 - le32_to_cpu(srbreply->data_xfer_length));
2405
2406 scsi_dma_unmap(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
2408 /*
2409 * First check the fib status
2410 */
2411
2412 if (le32_to_cpu(srbreply->status) != ST_OK){
2413 int len;
2414 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002415 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2416 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2418 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2419 }
2420
2421 /*
2422 * Next check the srb status
2423 */
2424 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2425 case SRB_STATUS_ERROR_RECOVERY:
2426 case SRB_STATUS_PENDING:
2427 case SRB_STATUS_SUCCESS:
Mark Haverkampbb08f922006-02-01 09:30:44 -08002428 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 break;
2430 case SRB_STATUS_DATA_OVERRUN:
2431 switch(scsicmd->cmnd[0]){
2432 case READ_6:
2433 case WRITE_6:
2434 case READ_10:
2435 case WRITE_10:
2436 case READ_12:
2437 case WRITE_12:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002438 case READ_16:
2439 case WRITE_16:
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002440 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2442 } else {
2443 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2444 }
2445 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2446 break;
2447 case INQUIRY: {
Mark Haverkampbb08f922006-02-01 09:30:44 -08002448 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 break;
2450 }
2451 default:
2452 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2453 break;
2454 }
2455 break;
2456 case SRB_STATUS_ABORTED:
2457 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2458 break;
2459 case SRB_STATUS_ABORT_FAILED:
2460 // Not sure about this one - but assuming the hba was trying to abort for some reason
2461 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2462 break;
2463 case SRB_STATUS_PARITY_ERROR:
2464 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2465 break;
2466 case SRB_STATUS_NO_DEVICE:
2467 case SRB_STATUS_INVALID_PATH_ID:
2468 case SRB_STATUS_INVALID_TARGET_ID:
2469 case SRB_STATUS_INVALID_LUN:
2470 case SRB_STATUS_SELECTION_TIMEOUT:
2471 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2472 break;
2473
2474 case SRB_STATUS_COMMAND_TIMEOUT:
2475 case SRB_STATUS_TIMEOUT:
2476 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2477 break;
2478
2479 case SRB_STATUS_BUSY:
Salyzyn, Mark760af102007-06-19 11:41:21 -04002480 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 break;
2482
2483 case SRB_STATUS_BUS_RESET:
2484 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2485 break;
2486
2487 case SRB_STATUS_MESSAGE_REJECTED:
2488 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2489 break;
2490 case SRB_STATUS_REQUEST_FLUSHED:
2491 case SRB_STATUS_ERROR:
2492 case SRB_STATUS_INVALID_REQUEST:
2493 case SRB_STATUS_REQUEST_SENSE_FAILED:
2494 case SRB_STATUS_NO_HBA:
2495 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2496 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2497 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2498 case SRB_STATUS_DELAYED_RETRY:
2499 case SRB_STATUS_BAD_FUNCTION:
2500 case SRB_STATUS_NOT_STARTED:
2501 case SRB_STATUS_NOT_IN_USE:
2502 case SRB_STATUS_FORCE_ABORT:
2503 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2504 default:
2505#ifdef AAC_DETAILED_STATUS_INFO
2506 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2507 le32_to_cpu(srbreply->srb_status) & 0x3F,
2508 aac_get_status_string(
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002509 le32_to_cpu(srbreply->srb_status) & 0x3F),
2510 scsicmd->cmnd[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 le32_to_cpu(srbreply->scsi_status));
2512#endif
2513 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2514 break;
2515 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002516 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 int len;
2518 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002519 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2520 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002522 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2523 le32_to_cpu(srbreply->status), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524#endif
2525 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 }
2527 /*
2528 * OR in the scsi status (already shifted up a bit)
2529 */
2530 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2531
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002532 aac_fib_complete(fibptr);
2533 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002534 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537/**
2538 *
2539 * aac_send_scb_fib
2540 * @scsicmd: the scsi command block
2541 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002542 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 * scsicmd passed in.
2544 */
2545
2546static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2547{
2548 struct fib* cmd_fibcontext;
2549 struct aac_dev* dev;
2550 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551
Mark Haverkamp84971732005-06-20 11:55:24 -07002552 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08002553 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07002554 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 scsicmd->result = DID_NO_CONNECT << 16;
2556 scsicmd->scsi_done(scsicmd);
2557 return 0;
2558 }
2559
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 /*
2561 * Allocate and initialize a Fib then setup a BlockWrite command
2562 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002563 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 return -1;
2565 }
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002566 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 /*
2569 * Check that the command queued to the controller
2570 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002571 if (status == -EINPROGRESS) {
2572 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 return 0;
2574 }
2575
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002576 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2577 aac_fib_complete(cmd_fibcontext);
2578 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
2580 return -1;
2581}
2582
2583static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2584{
2585 struct aac_dev *dev;
2586 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002587 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588
2589 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2590 // Get rid of old data
2591 psg->count = 0;
2592 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002593 psg->sg[0].count = 0;
2594
2595 nseg = scsi_dma_map(scsicmd);
2596 BUG_ON(nseg < 0);
2597 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 struct scatterlist *sg;
2599 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002601 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002603 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2605 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2606 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 }
2608 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002609 if (byte_count > scsi_bufflen(scsicmd)) {
2610 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2611 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002612 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002613 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 }
2615 /* Check for command underflow */
2616 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2617 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2618 byte_count, scsicmd->underflow);
2619 }
2620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 return byte_count;
2622}
2623
2624
2625static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2626{
2627 struct aac_dev *dev;
2628 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002629 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002630 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
2632 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2633 // Get rid of old data
2634 psg->count = 0;
2635 psg->sg[0].addr[0] = 0;
2636 psg->sg[0].addr[1] = 0;
2637 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002638
2639 nseg = scsi_dma_map(scsicmd);
2640 BUG_ON(nseg < 0);
2641 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 struct scatterlist *sg;
2643 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002645 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp1241f352006-03-27 09:44:23 -08002646 int count = sg_dma_len(sg);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002647 addr = sg_dma_address(sg);
2648 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2649 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
Mark Haverkamp1241f352006-03-27 09:44:23 -08002650 psg->sg[i].count = cpu_to_le32(count);
2651 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002653 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002655 if (byte_count > scsi_bufflen(scsicmd)) {
2656 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2657 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002658 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002659 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 }
2661 /* Check for command underflow */
2662 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2663 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2664 byte_count, scsicmd->underflow);
2665 }
2666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 return byte_count;
2668}
2669
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002670static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2671{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002672 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002673 int nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002674
2675 // Get rid of old data
2676 psg->count = 0;
2677 psg->sg[0].next = 0;
2678 psg->sg[0].prev = 0;
2679 psg->sg[0].addr[0] = 0;
2680 psg->sg[0].addr[1] = 0;
2681 psg->sg[0].count = 0;
2682 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002683
2684 nseg = scsi_dma_map(scsicmd);
2685 BUG_ON(nseg < 0);
2686 if (nseg) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002687 struct scatterlist *sg;
2688 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002689
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002690 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002691 int count = sg_dma_len(sg);
2692 u64 addr = sg_dma_address(sg);
2693 psg->sg[i].next = 0;
2694 psg->sg[i].prev = 0;
2695 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2696 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2697 psg->sg[i].count = cpu_to_le32(count);
2698 psg->sg[i].flags = 0;
2699 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002700 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002701 psg->count = cpu_to_le32(nseg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002702 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002703 if (byte_count > scsi_bufflen(scsicmd)) {
2704 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2705 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002706 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002707 byte_count = scsi_bufflen(scsicmd);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002708 }
2709 /* Check for command underflow */
2710 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2711 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2712 byte_count, scsicmd->underflow);
2713 }
2714 }
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002715 return byte_count;
2716}
2717
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718#ifdef AAC_DETAILED_STATUS_INFO
2719
2720struct aac_srb_status_info {
2721 u32 status;
2722 char *str;
2723};
2724
2725
2726static struct aac_srb_status_info srb_status_info[] = {
2727 { SRB_STATUS_PENDING, "Pending Status"},
2728 { SRB_STATUS_SUCCESS, "Success"},
2729 { SRB_STATUS_ABORTED, "Aborted Command"},
2730 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07002731 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 { SRB_STATUS_BUSY, "Device Busy"},
2733 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
2734 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
2735 { SRB_STATUS_NO_DEVICE, "No Device"},
2736 { SRB_STATUS_TIMEOUT, "Timeout"},
2737 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
2738 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
2739 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
2740 { SRB_STATUS_BUS_RESET, "Bus Reset"},
2741 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
2742 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
2743 { SRB_STATUS_NO_HBA, "No HBA"},
2744 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
2745 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
2746 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
2747 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
2748 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
2749 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07002750 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
2752 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
2753 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
2754 { SRB_STATUS_NOT_STARTED, "Not Started"},
2755 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002756 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
2758 { 0xff, "Unknown Error"}
2759};
2760
2761char *aac_get_status_string(u32 status)
2762{
2763 int i;
2764
Tobias Klauser6391a112006-06-08 22:23:48 -07002765 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
2766 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
2769 return "Bad Status Code";
2770}
2771
2772#endif