blob: d79457ac8beff1628787ce8b9b4c632ed0b5e77d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
Alan Coxfa195af2008-10-27 15:16:36 +00003 * (c) Copyright 2001 Red Hat Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07008 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 */
26
27#include <linux/kernel.h>
28#include <linux/init.h>
29#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/pci.h>
31#include <linux/spinlock.h>
32#include <linux/slab.h>
33#include <linux/completion.h>
34#include <linux/blkdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/uaccess.h>
Salyzyn, Mark3a0086a82008-01-11 11:46:44 -080036#include <linux/highmem.h> /* For flush_kernel_dcache_page */
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040037#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#include <scsi/scsi.h>
40#include <scsi/scsi_cmnd.h>
41#include <scsi/scsi_device.h>
42#include <scsi/scsi_host.h>
43
44#include "aacraid.h"
45
46/* values for inqd_pdt: Peripheral device type in plain English */
47#define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
48#define INQD_PDT_PROC 0x03 /* Processor device */
49#define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
50#define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
51#define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
52#define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
53
54#define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
55#define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
58 * Sense codes
59 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080060
61#define SENCODE_NO_SENSE 0x00
62#define SENCODE_END_OF_DATA 0x00
63#define SENCODE_BECOMING_READY 0x04
64#define SENCODE_INIT_CMD_REQUIRED 0x04
65#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
66#define SENCODE_INVALID_COMMAND 0x20
67#define SENCODE_LBA_OUT_OF_RANGE 0x21
68#define SENCODE_INVALID_CDB_FIELD 0x24
69#define SENCODE_LUN_NOT_SUPPORTED 0x25
70#define SENCODE_INVALID_PARAM_FIELD 0x26
71#define SENCODE_PARAM_NOT_SUPPORTED 0x26
72#define SENCODE_PARAM_VALUE_INVALID 0x26
73#define SENCODE_RESET_OCCURRED 0x29
74#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
75#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
76#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
77#define SENCODE_DIAGNOSTIC_FAILURE 0x40
78#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
79#define SENCODE_INVALID_MESSAGE_ERROR 0x49
80#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
81#define SENCODE_OVERLAPPED_COMMAND 0x4E
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83/*
84 * Additional sense codes
85 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080086
87#define ASENCODE_NO_SENSE 0x00
88#define ASENCODE_END_OF_DATA 0x05
89#define ASENCODE_BECOMING_READY 0x01
90#define ASENCODE_INIT_CMD_REQUIRED 0x02
91#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
92#define ASENCODE_INVALID_COMMAND 0x00
93#define ASENCODE_LBA_OUT_OF_RANGE 0x00
94#define ASENCODE_INVALID_CDB_FIELD 0x00
95#define ASENCODE_LUN_NOT_SUPPORTED 0x00
96#define ASENCODE_INVALID_PARAM_FIELD 0x00
97#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
98#define ASENCODE_PARAM_VALUE_INVALID 0x02
99#define ASENCODE_RESET_OCCURRED 0x00
100#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
101#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
102#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
103#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
104#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
105#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
106#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
107#define ASENCODE_OVERLAPPED_COMMAND 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109#define BYTE0(x) (unsigned char)(x)
110#define BYTE1(x) (unsigned char)((x) >> 8)
111#define BYTE2(x) (unsigned char)((x) >> 16)
112#define BYTE3(x) (unsigned char)((x) >> 24)
113
114/*------------------------------------------------------------------------------
115 * S T R U C T S / T Y P E D E F S
116 *----------------------------------------------------------------------------*/
117/* SCSI inquiry data */
118struct inquiry_data {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800119 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
120 u8 inqd_dtq; /* RMB | Device Type Qualifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
122 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
123 u8 inqd_len; /* Additional length (n-4) */
124 u8 inqd_pad1[2];/* Reserved - must be zero */
125 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
126 u8 inqd_vid[8]; /* Vendor ID */
127 u8 inqd_pid[16];/* Product ID */
128 u8 inqd_prl[4]; /* Product Revision Level */
129};
130
131/*
132 * M O D U L E G L O B A L S
133 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
136static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -0700137static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530138static unsigned long aac_build_sgraw2(struct scsi_cmnd *scsicmd, struct aac_raw_io2 *rio2, int sg_max);
139static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
141#ifdef AAC_DETAILED_STATUS_INFO
142static char *aac_get_status_string(u32 status);
143#endif
144
145/*
146 * Non dasd selection is handled entirely in aachba now
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800147 */
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static int nondasd = -1;
Leubner, Achimd8e965072009-04-01 07:16:08 -0700150static int aac_cache = 2; /* WCE=0 to avoid performance problems */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static int dacmode = -1;
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800152int aac_msi;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400153int aac_commit = -1;
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700154int startup_timeout = 180;
155int aif_timeout = 120;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800156int aac_sync_mode; /* Only Sync. transfer - disabled */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530157int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800159module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
160MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
161 " 0=off, 1=on");
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530162module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
163MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
164 " 0=off, 1=on");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800165module_param(nondasd, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800166MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
167 " 0=off, 1=on");
Salyzyn, Mark95e852e2008-01-08 12:01:07 -0800168module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800169MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
170 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
171 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
Leubner, Achimd8e965072009-04-01 07:16:08 -0700172 "\tbit 2 - Disable only if Battery is protecting Cache");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800173module_param(dacmode, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800174MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
175 " 0=off, 1=on");
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400176module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800177MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
178 " adapter for foreign arrays.\n"
179 "This is typically needed in systems that do not have a BIOS."
180 " 0=off, 1=on");
181module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
182MODULE_PARM_DESC(msi, "IRQ handling."
183 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700184module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800185MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
186 " adapter to have it's kernel up and\n"
187 "running. This is typically adjusted for large systems that do not"
188 " have a BIOS.");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700189module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800190MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
191 " applications to pick up AIFs before\n"
192 "deregistering them. This is typically adjusted for heavily burdened"
193 " systems.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700195int numacb = -1;
196module_param(numacb, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800197MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
198 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
199 " to use suggestion from Firmware.");
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700200
201int acbsize = -1;
202module_param(acbsize, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800203MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
204 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
205 " suggestion from Firmware.");
Mark Haverkamp653ba582006-09-19 08:59:43 -0700206
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400207int update_interval = 30 * 60;
208module_param(update_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800209MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
210 " updates issued to adapter.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400211
212int check_interval = 24 * 60 * 60;
213module_param(check_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800214MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
215 " checks.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400216
Andrew Morton87f3bda2007-08-10 14:50:30 -0700217int aac_check_reset = 1;
218module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
Paul Bolle95e7a8e2008-04-16 14:43:00 +0200219MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800220 " adapter. a value of -1 forces the reset to adapters programmed to"
221 " ignore it.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400222
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800223int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700224module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800225MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
226 " -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700227
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800228int aac_reset_devices;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400229module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
230MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700231
Leubner, Achimd8e965072009-04-01 07:16:08 -0700232int aac_wwn = 1;
233module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
234MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
235 "\t0 - Disable\n"
236 "\t1 - Array Meta Data Signature (default)\n"
237 "\t2 - Adapter Serial Number");
238
239
Mark Haverkamp03d44332007-03-15 10:27:45 -0700240static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
241 struct fib *fibptr) {
242 struct scsi_device *device;
243
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800244 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
Salyzyn, Markc835e372007-07-26 14:20:02 -0400245 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800246 aac_fib_complete(fibptr);
247 aac_fib_free(fibptr);
248 return 0;
249 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700250 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
251 device = scsicmd->device;
252 if (unlikely(!device || !scsi_device_online(device))) {
253 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
254 aac_fib_complete(fibptr);
255 aac_fib_free(fibptr);
256 return 0;
257 }
258 return 1;
259}
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/**
262 * aac_get_config_status - check the adapter configuration
263 * @common: adapter to query
264 *
265 * Query config status, and commit the configuration if needed.
266 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700267int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 int status = 0;
270 struct fib * fibptr;
271
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800272 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return -ENOMEM;
274
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800275 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 {
277 struct aac_get_config_status *dinfo;
278 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
279
280 dinfo->command = cpu_to_le32(VM_ContainerConfig);
281 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
282 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
283 }
284
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800285 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 fibptr,
287 sizeof (struct aac_get_config_status),
288 FsaNormal,
289 1, 1,
290 NULL, NULL);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800291 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
293 } else {
294 struct aac_get_config_status_resp *reply
295 = (struct aac_get_config_status_resp *) fib_data(fibptr);
296 dprintk((KERN_WARNING
297 "aac_get_config_status: response=%d status=%d action=%d\n",
298 le32_to_cpu(reply->response),
299 le32_to_cpu(reply->status),
300 le32_to_cpu(reply->data.action)));
301 if ((le32_to_cpu(reply->response) != ST_OK) ||
302 (le32_to_cpu(reply->status) != CT_OK) ||
303 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
304 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
305 status = -EINVAL;
306 }
307 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530308 /* Do not set XferState to zero unless receives a response from F/W */
309 if (status >= 0)
310 aac_fib_complete(fibptr);
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
313 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400314 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800316 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 dinfo = (struct aac_commit_config *) fib_data(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 dinfo->command = cpu_to_le32(VM_ContainerConfig);
320 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800321
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800322 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 fibptr,
324 sizeof (struct aac_commit_config),
325 FsaNormal,
326 1, 1,
327 NULL, NULL);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530328 /* Do not set XferState to zero unless
329 * receives a response from F/W */
330 if (status >= 0)
331 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400332 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 printk(KERN_WARNING
334 "aac_get_config_status: Foreign device configurations are being ignored\n");
335 }
336 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530337 /* FIB should be freed only after getting the response from the F/W */
338 if (status != -ERESTARTSYS)
339 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return status;
341}
342
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -0700343static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
344{
345 char inq_data;
346 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
347 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
348 inq_data &= 0xdf;
349 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
350 }
351}
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353/**
354 * aac_get_containers - list containers
355 * @common: adapter to probe
356 *
357 * Make a list of all containers on this controller
358 */
359int aac_get_containers(struct aac_dev *dev)
360{
361 struct fsa_dev_info *fsa_dev_ptr;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800362 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 int status = 0;
364 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 struct aac_get_container_count *dinfo;
366 struct aac_get_container_count_resp *dresp;
367 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
368
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800369 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 return -ENOMEM;
371
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800372 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
374 dinfo->command = cpu_to_le32(VM_ContainerConfig);
375 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
376
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800377 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 fibptr,
379 sizeof (struct aac_get_container_count),
380 FsaNormal,
381 1, 1,
382 NULL, NULL);
383 if (status >= 0) {
384 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
385 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800386 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530388 /* FIB should be freed only after getting the response from the F/W */
389 if (status != -ERESTARTSYS)
390 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
393 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400394 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700395 GFP_KERNEL);
396 if (!fsa_dev_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 dev->fsa_dev = fsa_dev_ptr;
400 dev->maximum_num_containers = maximum_num_containers;
401
Mark Haverkampfe76df42007-03-15 12:55:07 -0700402 for (index = 0; index < dev->maximum_num_containers; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 fsa_dev_ptr[index].devname[0] = '\0';
404
Mark Haverkampfe76df42007-03-15 12:55:07 -0700405 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Mark Haverkampfe76df42007-03-15 12:55:07 -0700407 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
409 break;
410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /*
413 * If there are no more containers, then stop asking.
414 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700415 if (++index >= status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return status;
419}
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421static void get_container_name_callback(void *context, struct fib * fibptr)
422{
423 struct aac_get_name_resp * get_name_reply;
424 struct scsi_cmnd * scsicmd;
425
426 scsicmd = (struct scsi_cmnd *) context;
427
Mark Haverkamp03d44332007-03-15 10:27:45 -0700428 if (!aac_valid_context(scsicmd, fibptr))
429 return;
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700432 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
435 /* Failure is irrelevant, using default value instead */
436 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
437 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700438 char *sp = get_name_reply->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
440 while (*sp == ' ')
441 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700442 if (*sp) {
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900443 struct inquiry_data inq;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700444 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
445 int count = sizeof(d);
446 char *dp = d;
447 do {
448 *dp++ = (*sp) ? *sp++ : ' ';
449 } while (--count > 0);
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900450
451 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
452 memcpy(inq.inqd_pid, d, sizeof(d));
453 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
458
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800459 aac_fib_complete(fibptr);
460 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700461 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
464/**
465 * aac_get_container_name - get container name, none blocking.
466 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700467static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
469 int status;
470 struct aac_get_name *dinfo;
471 struct fib * cmd_fibcontext;
472 struct aac_dev * dev;
473
474 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
475
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800476 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 return -ENOMEM;
478
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800479 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
481
482 dinfo->command = cpu_to_le32(VM_ContainerConfig);
483 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700484 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
486
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800487 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800488 cmd_fibcontext,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 sizeof (struct aac_get_name),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800490 FsaNormal,
491 0, 1,
492 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 /*
496 * Check that the command queued to the controller
497 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800498 if (status == -EINPROGRESS) {
499 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800501 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800502
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800503 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
504 aac_fib_complete(cmd_fibcontext);
505 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 return -1;
507}
508
Mark Haverkampfe76df42007-03-15 12:55:07 -0700509static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
510{
511 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
512
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400513 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700514 return aac_scsi_cmd(scsicmd);
515
516 scsicmd->result = DID_NO_CONNECT << 16;
517 scsicmd->scsi_done(scsicmd);
518 return 0;
519}
520
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400521static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700522{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700523 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700524 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700525 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
526
Mark Haverkamp03d44332007-03-15 10:27:45 -0700527
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400528 if (!aac_valid_context(scsicmd, fibptr))
529 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700530
531 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400532 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700533 if (fsa_dev_ptr) {
534 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
535 fsa_dev_ptr += scmd_id(scsicmd);
536
537 if ((le32_to_cpu(dresp->status) == ST_OK) &&
538 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
539 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
540 fsa_dev_ptr->valid = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -0400541 /* sense_key holds the current state of the spin-up */
542 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
543 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
544 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
545 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700546 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
547 fsa_dev_ptr->size
548 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
549 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
550 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
551 }
552 if ((fsa_dev_ptr->valid & 1) == 0)
553 fsa_dev_ptr->valid = 0;
554 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
555 }
556 aac_fib_complete(fibptr);
557 aac_fib_free(fibptr);
558 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
559 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400560 (*callback)(scsicmd);
561 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700562}
563
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400564static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700565{
566 struct scsi_cmnd * scsicmd;
567 struct aac_mount * dresp;
568 struct aac_query_mount *dinfo;
569 int status;
570
571 dresp = (struct aac_mount *) fib_data(fibptr);
572 dresp->mnt[0].capacityhigh = 0;
573 if ((le32_to_cpu(dresp->status) != ST_OK) ||
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400574 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
575 _aac_probe_container2(context, fibptr);
576 return;
577 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700578 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700579
Mark Haverkamp03d44332007-03-15 10:27:45 -0700580 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400581 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700582
Mark Haverkampfe76df42007-03-15 12:55:07 -0700583 aac_fib_init(fibptr);
584
585 dinfo = (struct aac_query_mount *)fib_data(fibptr);
586
587 dinfo->command = cpu_to_le32(VM_NameServe64);
588 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
589 dinfo->type = cpu_to_le32(FT_FILESYS);
590
591 status = aac_fib_send(ContainerCommand,
592 fibptr,
593 sizeof(struct aac_query_mount),
594 FsaNormal,
595 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400596 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700597 (void *) scsicmd);
598 /*
599 * Check that the command queued to the controller
600 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400601 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700602 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400603 else if (status < 0) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700604 /* Inherit results from VM_NameServe, if any */
605 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400606 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700607 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700608}
609
610static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
611{
612 struct fib * fibptr;
613 int status = -ENOMEM;
614
615 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
616 struct aac_query_mount *dinfo;
617
618 aac_fib_init(fibptr);
619
620 dinfo = (struct aac_query_mount *)fib_data(fibptr);
621
622 dinfo->command = cpu_to_le32(VM_NameServe);
623 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
624 dinfo->type = cpu_to_le32(FT_FILESYS);
625 scsicmd->SCp.ptr = (char *)callback;
626
627 status = aac_fib_send(ContainerCommand,
628 fibptr,
629 sizeof(struct aac_query_mount),
630 FsaNormal,
631 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400632 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700633 (void *) scsicmd);
634 /*
635 * Check that the command queued to the controller
636 */
637 if (status == -EINPROGRESS) {
638 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
639 return 0;
640 }
641 if (status < 0) {
642 scsicmd->SCp.ptr = NULL;
643 aac_fib_complete(fibptr);
644 aac_fib_free(fibptr);
645 }
646 }
647 if (status < 0) {
648 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
649 if (fsa_dev_ptr) {
650 fsa_dev_ptr += scmd_id(scsicmd);
651 if ((fsa_dev_ptr->valid & 1) == 0) {
652 fsa_dev_ptr->valid = 0;
653 return (*callback)(scsicmd);
654 }
655 }
656 }
657 return status;
658}
659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800661 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 * @dev: device to query
663 * @cid: container identifier
664 *
665 * Queries the controller about the given volume. The volume information
666 * is updated in the struct fsa_dev_info structure rather than returned.
667 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700668static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
669{
670 scsicmd->device = NULL;
671 return 0;
672}
673
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800674int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700676 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
677 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Mark Haverkampfe76df42007-03-15 12:55:07 -0700680 if (!scsicmd || !scsidev) {
681 kfree(scsicmd);
682 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700683 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700685 scsicmd->list.next = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400686 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Mark Haverkampfe76df42007-03-15 12:55:07 -0700688 scsicmd->device = scsidev;
689 scsidev->sdev_state = 0;
690 scsidev->id = cid;
691 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Mark Haverkampfe76df42007-03-15 12:55:07 -0700693 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
694 while (scsicmd->device == scsidev)
695 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400696 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700697 status = scsicmd->SCp.Status;
698 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 return status;
700}
701
702/* Local Structure to set SCSI inquiry data strings */
703struct scsi_inq {
704 char vid[8]; /* Vendor ID */
705 char pid[16]; /* Product ID */
706 char prl[4]; /* Product Revision Level */
707};
708
709/**
710 * InqStrCopy - string merge
711 * @a: string to copy from
712 * @b: string to copy to
713 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800714 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 * without copying \0
716 */
717
718static void inqstrcpy(char *a, char *b)
719{
720
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800721 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 *b++ = *a++;
723}
724
725static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800726 "None",
727 "Volume",
728 "Mirror",
729 "Stripe",
730 "RAID5",
731 "SSRW",
732 "SSRO",
733 "Morph",
734 "Legacy",
735 "RAID4",
736 "RAID10",
737 "RAID00",
738 "V-MIRRORS",
739 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700741 "RAID5D",
742 "RAID5D0",
743 "RAID1E",
744 "RAID6",
745 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800746 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747};
748
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800749char * get_container_type(unsigned tindex)
750{
751 if (tindex >= ARRAY_SIZE(container_types))
752 tindex = ARRAY_SIZE(container_types) - 1;
753 return container_types[tindex];
754}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756/* Function: setinqstr
757 *
758 * Arguments: [1] pointer to void [1] int
759 *
760 * Purpose: Sets SCSI inquiry data strings for vendor, product
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300761 * and revision level. Allows strings to be set in platform dependent
762 * files instead of in OS dependent driver source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 */
764
Mark Haverkamp794d0602005-10-24 10:51:53 -0700765static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
767 struct scsi_inq *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700770 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Mark Haverkamp794d0602005-10-24 10:51:53 -0700772 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
773 char * cp = dev->supplement_adapter_info.AdapterTypeText;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800774 int c;
775 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
776 inqstrcpy("SMC", str->vid);
777 else {
778 c = sizeof(str->vid);
779 while (*cp && *cp != ' ' && --c)
780 ++cp;
781 c = *cp;
782 *cp = '\0';
783 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
784 str->vid);
785 *cp = c;
786 while (*cp && *cp != ' ')
787 ++cp;
788 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700789 while (*cp == ' ')
790 ++cp;
791 /* last six chars reserved for vol type */
792 c = 0;
793 if (strlen(cp) > sizeof(str->pid)) {
794 c = cp[sizeof(str->pid)];
795 cp[sizeof(str->pid)] = '\0';
796 }
797 inqstrcpy (cp, str->pid);
798 if (c)
799 cp[sizeof(str->pid)] = c;
800 } else {
801 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700802
803 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700804 /* last six chars reserved for vol type */
805 inqstrcpy (mp->model, str->pid);
806 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Tobias Klauser6391a112006-06-08 22:23:48 -0700808 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 char *findit = str->pid;
810
811 for ( ; *findit != ' '; findit++); /* walk till we find a space */
812 /* RAID is superfluous in the context of a RAID device */
813 if (memcmp(findit-4, "RAID", 4) == 0)
814 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700815 if (((findit - str->pid) + strlen(container_types[tindex]))
816 < (sizeof(str->pid) + sizeof(str->prl)))
817 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 }
819 inqstrcpy ("V1.0", str->prl);
820}
821
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400822static void get_container_serial_callback(void *context, struct fib * fibptr)
823{
824 struct aac_get_serial_resp * get_serial_reply;
825 struct scsi_cmnd * scsicmd;
826
827 BUG_ON(fibptr == NULL);
828
829 scsicmd = (struct scsi_cmnd *) context;
830 if (!aac_valid_context(scsicmd, fibptr))
831 return;
832
833 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
834 /* Failure is irrelevant, using default value instead */
835 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
836 char sp[13];
837 /* EVPD bit set */
838 sp[0] = INQD_PDT_DA;
839 sp[1] = scsicmd->cmnd[2];
840 sp[2] = 0;
841 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
842 le32_to_cpu(get_serial_reply->uid));
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900843 scsi_sg_copy_from_buffer(scsicmd, sp, sizeof(sp));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400844 }
845
846 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
847
848 aac_fib_complete(fibptr);
849 aac_fib_free(fibptr);
850 scsicmd->scsi_done(scsicmd);
851}
852
853/**
854 * aac_get_container_serial - get container serial, none blocking.
855 */
856static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
857{
858 int status;
859 struct aac_get_serial *dinfo;
860 struct fib * cmd_fibcontext;
861 struct aac_dev * dev;
862
863 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
864
865 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
866 return -ENOMEM;
867
868 aac_fib_init(cmd_fibcontext);
869 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
870
871 dinfo->command = cpu_to_le32(VM_ContainerConfig);
872 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
873 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
874
875 status = aac_fib_send(ContainerCommand,
876 cmd_fibcontext,
877 sizeof (struct aac_get_serial),
878 FsaNormal,
879 0, 1,
880 (fib_callback) get_container_serial_callback,
881 (void *) scsicmd);
882
883 /*
884 * Check that the command queued to the controller
885 */
886 if (status == -EINPROGRESS) {
887 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
888 return 0;
889 }
890
891 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
892 aac_fib_complete(cmd_fibcontext);
893 aac_fib_free(cmd_fibcontext);
894 return -1;
895}
896
897/* Function: setinqserial
898 *
899 * Arguments: [1] pointer to void [1] int
900 *
901 * Purpose: Sets SCSI Unit Serial number.
902 * This is a fake. We should read a proper
903 * serial number from the container. <SuSE>But
904 * without docs it's quite hard to do it :-)
905 * So this will have to do in the meantime.</SuSE>
906 */
907
908static int setinqserial(struct aac_dev *dev, void *data, int cid)
909{
910 /*
911 * This breaks array migration.
912 */
913 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
914 le32_to_cpu(dev->adapter_info.serial[0]), cid);
915}
916
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800917static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
918 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800920 u8 *sense_buf = (u8 *)sense_data;
921 /* Sense data valid, err code 70h */
922 sense_buf[0] = 0x70; /* No info field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 sense_buf[1] = 0; /* Segment number, always zero */
924
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800925 sense_buf[2] = sense_key; /* Sense key */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 sense_buf[12] = sense_code; /* Additional sense code */
928 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 if (sense_key == ILLEGAL_REQUEST) {
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800931 sense_buf[7] = 10; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800933 sense_buf[15] = bit_pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 /* Illegal parameter is in the parameter block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 if (sense_code == SENCODE_INVALID_CDB_FIELD)
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800936 sense_buf[15] |= 0xc0;/* Std sense key specific field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 /* Illegal parameter is in the CDB block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 sense_buf[16] = field_pointer >> 8; /* MSB */
939 sense_buf[17] = field_pointer; /* LSB */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800940 } else
941 sense_buf[7] = 6; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800944static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
945{
946 if (lba & 0xffffffff00000000LL) {
947 int cid = scmd_id(cmd);
948 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
949 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
950 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -0800951 set_sense(&dev->fsa_dev[cid].sense_data,
952 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
953 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800954 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -0800955 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
956 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800957 cmd->scsi_done(cmd);
958 return 1;
959 }
960 return 0;
961}
962
963static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
964{
965 return 0;
966}
967
968static void io_callback(void *context, struct fib * fibptr);
969
970static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
971{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530972 struct aac_dev *dev = fib->dev;
973 u16 fibsize, command;
Mark Haverkampe8f32de2007-01-23 15:00:30 -0800974
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530975 aac_fib_init(fib);
976 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
977 struct aac_raw_io2 *readcmd2;
978 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
979 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
980 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
981 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
982 readcmd2->byteCount = cpu_to_le32(count<<9);
983 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
984 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
985 aac_build_sgraw2(cmd, readcmd2, dev->scsi_host_ptr->sg_tablesize);
986 command = ContainerRawIo2;
987 fibsize = sizeof(struct aac_raw_io2) +
988 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
989 } else {
990 struct aac_raw_io *readcmd;
991 readcmd = (struct aac_raw_io *) fib_data(fib);
992 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
993 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
994 readcmd->count = cpu_to_le32(count<<9);
995 readcmd->cid = cpu_to_le16(scmd_id(cmd));
996 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
997 readcmd->bpTotal = 0;
998 readcmd->bpComplete = 0;
999 aac_build_sgraw(cmd, &readcmd->sg);
1000 command = ContainerRawIo;
1001 fibsize = sizeof(struct aac_raw_io) +
1002 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1003 }
1004
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001005 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1006 /*
1007 * Now send the Fib to the adapter
1008 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301009 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001010 fib,
1011 fibsize,
1012 FsaNormal,
1013 0, 1,
1014 (fib_callback) io_callback,
1015 (void *) cmd);
1016}
1017
1018static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1019{
1020 u16 fibsize;
1021 struct aac_read64 *readcmd;
1022 aac_fib_init(fib);
1023 readcmd = (struct aac_read64 *) fib_data(fib);
1024 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1025 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1026 readcmd->sector_count = cpu_to_le16(count);
1027 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1028 readcmd->pad = 0;
1029 readcmd->flags = 0;
1030
1031 aac_build_sg64(cmd, &readcmd->sg);
1032 fibsize = sizeof(struct aac_read64) +
1033 ((le32_to_cpu(readcmd->sg.count) - 1) *
1034 sizeof (struct sgentry64));
1035 BUG_ON (fibsize > (fib->dev->max_fib_size -
1036 sizeof(struct aac_fibhdr)));
1037 /*
1038 * Now send the Fib to the adapter
1039 */
1040 return aac_fib_send(ContainerCommand64,
1041 fib,
1042 fibsize,
1043 FsaNormal,
1044 0, 1,
1045 (fib_callback) io_callback,
1046 (void *) cmd);
1047}
1048
1049static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1050{
1051 u16 fibsize;
1052 struct aac_read *readcmd;
1053 aac_fib_init(fib);
1054 readcmd = (struct aac_read *) fib_data(fib);
1055 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001056 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001057 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1058 readcmd->count = cpu_to_le32(count * 512);
1059
1060 aac_build_sg(cmd, &readcmd->sg);
1061 fibsize = sizeof(struct aac_read) +
1062 ((le32_to_cpu(readcmd->sg.count) - 1) *
1063 sizeof (struct sgentry));
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(ContainerCommand,
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_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001079{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301080 struct aac_dev *dev = fib->dev;
1081 u16 fibsize, command;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001082
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301083 aac_fib_init(fib);
1084 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1085 struct aac_raw_io2 *writecmd2;
1086 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1087 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1088 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1089 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1090 writecmd2->byteCount = cpu_to_le32(count<<9);
1091 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1092 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1093 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1094 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1095 cpu_to_le16(RIO2_IO_TYPE_WRITE);
1096 aac_build_sgraw2(cmd, writecmd2, dev->scsi_host_ptr->sg_tablesize);
1097 command = ContainerRawIo2;
1098 fibsize = sizeof(struct aac_raw_io2) +
1099 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1100 } else {
1101 struct aac_raw_io *writecmd;
1102 writecmd = (struct aac_raw_io *) fib_data(fib);
1103 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1104 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1105 writecmd->count = cpu_to_le32(count<<9);
1106 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1107 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1108 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1109 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1110 cpu_to_le16(RIO_TYPE_WRITE);
1111 writecmd->bpTotal = 0;
1112 writecmd->bpComplete = 0;
1113 aac_build_sgraw(cmd, &writecmd->sg);
1114 command = ContainerRawIo;
1115 fibsize = sizeof(struct aac_raw_io) +
1116 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1117 }
1118
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001119 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1120 /*
1121 * Now send the Fib to the adapter
1122 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301123 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001124 fib,
1125 fibsize,
1126 FsaNormal,
1127 0, 1,
1128 (fib_callback) io_callback,
1129 (void *) cmd);
1130}
1131
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001132static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001133{
1134 u16 fibsize;
1135 struct aac_write64 *writecmd;
1136 aac_fib_init(fib);
1137 writecmd = (struct aac_write64 *) fib_data(fib);
1138 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1139 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1140 writecmd->sector_count = cpu_to_le16(count);
1141 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1142 writecmd->pad = 0;
1143 writecmd->flags = 0;
1144
1145 aac_build_sg64(cmd, &writecmd->sg);
1146 fibsize = sizeof(struct aac_write64) +
1147 ((le32_to_cpu(writecmd->sg.count) - 1) *
1148 sizeof (struct sgentry64));
1149 BUG_ON (fibsize > (fib->dev->max_fib_size -
1150 sizeof(struct aac_fibhdr)));
1151 /*
1152 * Now send the Fib to the adapter
1153 */
1154 return aac_fib_send(ContainerCommand64,
1155 fib,
1156 fibsize,
1157 FsaNormal,
1158 0, 1,
1159 (fib_callback) io_callback,
1160 (void *) cmd);
1161}
1162
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001163static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001164{
1165 u16 fibsize;
1166 struct aac_write *writecmd;
1167 aac_fib_init(fib);
1168 writecmd = (struct aac_write *) fib_data(fib);
1169 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001170 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001171 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1172 writecmd->count = cpu_to_le32(count * 512);
1173 writecmd->sg.count = cpu_to_le32(1);
1174 /* ->stable is not used - it did mean which type of write */
1175
1176 aac_build_sg(cmd, &writecmd->sg);
1177 fibsize = sizeof(struct aac_write) +
1178 ((le32_to_cpu(writecmd->sg.count) - 1) *
1179 sizeof (struct sgentry));
1180 BUG_ON (fibsize > (fib->dev->max_fib_size -
1181 sizeof(struct aac_fibhdr)));
1182 /*
1183 * Now send the Fib to the adapter
1184 */
1185 return aac_fib_send(ContainerCommand,
1186 fib,
1187 fibsize,
1188 FsaNormal,
1189 0, 1,
1190 (fib_callback) io_callback,
1191 (void *) cmd);
1192}
1193
1194static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1195{
1196 struct aac_srb * srbcmd;
1197 u32 flag;
1198 u32 timeout;
1199
1200 aac_fib_init(fib);
1201 switch(cmd->sc_data_direction){
1202 case DMA_TO_DEVICE:
1203 flag = SRB_DataOut;
1204 break;
1205 case DMA_BIDIRECTIONAL:
1206 flag = SRB_DataIn | SRB_DataOut;
1207 break;
1208 case DMA_FROM_DEVICE:
1209 flag = SRB_DataIn;
1210 break;
1211 case DMA_NONE:
1212 default: /* shuts up some versions of gcc */
1213 flag = SRB_NoDataXfer;
1214 break;
1215 }
1216
1217 srbcmd = (struct aac_srb*) fib_data(fib);
1218 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1219 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1220 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1221 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1222 srbcmd->flags = cpu_to_le32(flag);
Jens Axboe242f9dc2008-09-14 05:55:09 -07001223 timeout = cmd->request->timeout/HZ;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001224 if (timeout == 0)
1225 timeout = 1;
1226 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1227 srbcmd->retry_limit = 0; /* Obsolete parameter */
1228 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1229 return srbcmd;
1230}
1231
1232static void aac_srb_callback(void *context, struct fib * fibptr);
1233
1234static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1235{
1236 u16 fibsize;
1237 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1238
1239 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001240 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001241
1242 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1243 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1244 /*
1245 * Build Scatter/Gather list
1246 */
1247 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1248 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1249 sizeof (struct sgentry64));
1250 BUG_ON (fibsize > (fib->dev->max_fib_size -
1251 sizeof(struct aac_fibhdr)));
1252
1253 /*
1254 * Now send the Fib to the adapter
1255 */
1256 return aac_fib_send(ScsiPortCommand64, fib,
1257 fibsize, FsaNormal, 0, 1,
1258 (fib_callback) aac_srb_callback,
1259 (void *) cmd);
1260}
1261
1262static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1263{
1264 u16 fibsize;
1265 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1266
1267 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001268 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001269
1270 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1271 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1272 /*
1273 * Build Scatter/Gather list
1274 */
1275 fibsize = sizeof (struct aac_srb) +
1276 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1277 sizeof (struct sgentry));
1278 BUG_ON (fibsize > (fib->dev->max_fib_size -
1279 sizeof(struct aac_fibhdr)));
1280
1281 /*
1282 * Now send the Fib to the adapter
1283 */
1284 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1285 (fib_callback) aac_srb_callback, (void *) cmd);
1286}
1287
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001288static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1289{
Leubner, Achimd8e965072009-04-01 07:16:08 -07001290 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1291 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001292 return FAILED;
1293 return aac_scsi_32(fib, cmd);
1294}
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296int aac_get_adapter_info(struct aac_dev* dev)
1297{
1298 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 int rcode;
1300 u32 tmp;
Mark Haverkamp84971732005-06-20 11:55:24 -07001301 struct aac_adapter_info *info;
1302 struct aac_bus_info *command;
1303 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001304
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001305 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 return -ENOMEM;
1307
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001308 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001309 info = (struct aac_adapter_info *) fib_data(fibptr);
1310 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001312 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001313 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001314 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001315 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07001316 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001317 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001318 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001320 if (rcode < 0) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301321 /* FIB should be freed only after
1322 * getting the response from the F/W */
1323 if (rcode != -ERESTARTSYS) {
1324 aac_fib_complete(fibptr);
1325 aac_fib_free(fibptr);
1326 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001327 return rcode;
1328 }
1329 memcpy(&dev->adapter_info, info, sizeof(*info));
1330
1331 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001332 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001333
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001334 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001335
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001336 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001337
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001338 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001339
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001340 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001341 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001342 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001343 FsaNormal,
1344 1, 1,
1345 NULL,
1346 NULL);
1347
1348 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001349 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301350 if (rcode == -ERESTARTSYS) {
1351 fibptr = aac_fib_alloc(dev);
1352 if (!fibptr)
1353 return -ENOMEM;
1354 }
1355
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Mark Haverkamp84971732005-06-20 11:55:24 -07001358
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001359 /*
1360 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07001361 */
1362
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001363 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07001364
1365 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1366
1367 memset(bus_info, 0, sizeof(*bus_info));
1368
1369 command = (struct aac_bus_info *)bus_info;
1370
1371 command->Command = cpu_to_le32(VM_Ioctl);
1372 command->ObjType = cpu_to_le32(FT_DRIVE);
1373 command->MethodId = cpu_to_le32(1);
1374 command->CtlCmd = cpu_to_le32(GetBusInfo);
1375
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001376 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07001377 fibptr,
1378 sizeof (*bus_info),
1379 FsaNormal,
1380 1, 1,
1381 NULL, NULL);
1382
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001383 /* reasoned default */
1384 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07001385 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1386 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1387 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1388 }
1389
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001390 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001391 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001392 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1393 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001394 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 dev->id,
1396 tmp>>24,
1397 (tmp>>16)&0xff,
1398 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001399 le32_to_cpu(dev->adapter_info.kernelbuild),
1400 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1401 dev->supplement_adapter_info.BuildDate);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001402 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1403 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 dev->name, dev->id,
1405 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1406 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001407 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1408 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 dev->name, dev->id,
1410 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1411 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001412 buffer[0] = '\0';
Tony Jonesee959b02008-02-22 00:13:36 +01001413 if (aac_get_serial_number(
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001414 shost_to_class(dev->scsi_host_ptr), buffer))
1415 printk(KERN_INFO "%s%d: serial %s",
1416 dev->name, dev->id, buffer);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04001417 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1418 printk(KERN_INFO "%s%d: TSID %.*s\n",
1419 dev->name, dev->id,
1420 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1421 dev->supplement_adapter_info.VpdInfo.Tsid);
1422 }
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001423 if (!aac_check_reset || ((aac_check_reset == 1) &&
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001424 (dev->supplement_adapter_info.SupportedOptions2 &
1425 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001426 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1427 dev->name, dev->id);
1428 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001431 dev->cache_protected = 0;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001432 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1433 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 dev->nondasd_support = 0;
1435 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001436 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
1439 /*
1440 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1441 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1442 * force nondasd support on. If we decide to allow the non-dasd flag
1443 * additional changes changes will have to be made to support
1444 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1445 * changed to support the new dev->raid_scsi_mode flag instead of
1446 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1447 * function aac_detect will have to be modified where it sets up the
1448 * max number of channels based on the aac->nondasd_support flag only.
1449 */
1450 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1451 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1452 dev->nondasd_support = 1;
1453 dev->raid_scsi_mode = 1;
1454 }
1455 if (dev->raid_scsi_mode != 0)
1456 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1457 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001458
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001459 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001461 if (dev->nondasd_support && !dev->in_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Yang Hongyange9304382009-04-13 14:40:14 -07001464 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
Leubner, Achimd8e965072009-04-01 07:16:08 -07001465 dev->needs_dac = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 dev->dac_support = 0;
Leubner, Achimd8e965072009-04-01 07:16:08 -07001467 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
1468 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001469 if (!dev->in_reset)
1470 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
1471 dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 dev->dac_support = 1;
1473 }
1474
1475 if(dacmode != -1) {
1476 dev->dac_support = (dacmode!=0);
1477 }
Leubner, Achimd8e965072009-04-01 07:16:08 -07001478
1479 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1480 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
1481 & AAC_QUIRK_SCSI_32)) {
1482 dev->nondasd_support = 0;
1483 dev->jbod = 0;
1484 expose_physicals = 0;
1485 }
1486
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 if(dev->dac_support != 0) {
Yang Hongyang6a355282009-04-06 19:01:13 -07001488 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64)) &&
1489 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001490 if (!dev->in_reset)
1491 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1492 dev->name, dev->id);
Yang Hongyang284901a2009-04-06 19:01:15 -07001493 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32)) &&
1494 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1496 dev->name, dev->id);
1497 dev->dac_support = 0;
1498 } else {
1499 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1500 dev->name, dev->id);
1501 rcode = -ENOMEM;
1502 }
1503 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001504 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001505 * Deal with configuring for the individualized limits of each packet
1506 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001507 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001508 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001509 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1510 ? aac_scsi_32_64
1511 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001512 : aac_scsi_32;
1513 if (dev->raw_io_interface) {
1514 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1515 ? aac_bounds_64
1516 : aac_bounds_32;
1517 dev->a_ops.adapter_read = aac_read_raw_io;
1518 dev->a_ops.adapter_write = aac_write_raw_io;
1519 } else {
1520 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001521 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001522 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001523 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1524 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001525 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001526 dev->a_ops.adapter_read = aac_read_block64;
1527 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001528 /*
1529 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001530 */
1531 dev->scsi_host_ptr->sg_tablesize =
1532 (dev->max_fib_size -
1533 sizeof(struct aac_fibhdr) -
1534 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001535 sizeof(struct sgentry64)) /
1536 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001537 } else {
1538 dev->a_ops.adapter_read = aac_read_block;
1539 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001540 }
1541 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07001542 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001543 /*
1544 * Worst case size that could cause sg overflow when
1545 * we break up SG elements that are larger than 64KB.
1546 * Would be nice if we could tell the SCSI layer what
1547 * the maximum SG element size can be. Worst case is
1548 * (sg_tablesize-1) 4KB elements with one 64KB
1549 * element.
1550 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1551 */
1552 dev->scsi_host_ptr->max_sectors =
1553 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1554 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001555 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301556 /* FIB should be freed only after getting the response from the F/W */
1557 if (rcode != -ERESTARTSYS) {
1558 aac_fib_complete(fibptr);
1559 aac_fib_free(fibptr);
1560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
1562 return rcode;
1563}
1564
1565
Mark Haverkampe53cb352005-08-03 15:39:09 -07001566static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
1568 struct aac_dev *dev;
1569 struct aac_read_reply *readreply;
1570 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 u32 cid;
1572
1573 scsicmd = (struct scsi_cmnd *) context;
1574
Mark Haverkamp03d44332007-03-15 10:27:45 -07001575 if (!aac_valid_context(scsicmd, fibptr))
1576 return;
1577
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001578 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001579 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001581 if (nblank(dprintk(x))) {
1582 u64 lba;
1583 switch (scsicmd->cmnd[0]) {
1584 case WRITE_6:
1585 case READ_6:
1586 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1587 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1588 break;
1589 case WRITE_16:
1590 case READ_16:
1591 lba = ((u64)scsicmd->cmnd[2] << 56) |
1592 ((u64)scsicmd->cmnd[3] << 48) |
1593 ((u64)scsicmd->cmnd[4] << 40) |
1594 ((u64)scsicmd->cmnd[5] << 32) |
1595 ((u64)scsicmd->cmnd[6] << 24) |
1596 (scsicmd->cmnd[7] << 16) |
1597 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1598 break;
1599 case WRITE_12:
1600 case READ_12:
1601 lba = ((u64)scsicmd->cmnd[2] << 24) |
1602 (scsicmd->cmnd[3] << 16) |
1603 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1604 break;
1605 default:
1606 lba = ((u64)scsicmd->cmnd[2] << 24) |
1607 (scsicmd->cmnd[3] << 16) |
1608 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1609 break;
1610 }
1611 printk(KERN_DEBUG
1612 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1613 smp_processor_id(), (unsigned long long)lba, jiffies);
1614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Eric Sesterhenn125e1872006-06-23 02:06:06 -07001616 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001617
1618 scsi_dma_unmap(scsicmd);
1619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 readreply = (struct aac_read_reply *)fib_data(fibptr);
Mark Salyzyn655d7222008-04-30 16:03:42 -04001621 switch (le32_to_cpu(readreply->status)) {
1622 case ST_OK:
1623 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1624 SAM_STAT_GOOD;
1625 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
1626 break;
1627 case ST_NOT_READY:
1628 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1629 SAM_STAT_CHECK_CONDITION;
1630 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
1631 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
1632 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1633 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1634 SCSI_SENSE_BUFFERSIZE));
1635 break;
1636 default:
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001637#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07001638 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001639 le32_to_cpu(readreply->status));
1640#endif
Mark Salyzyn655d7222008-04-30 16:03:42 -04001641 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1642 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001643 set_sense(&dev->fsa_dev[cid].sense_data,
1644 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1645 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001647 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1648 SCSI_SENSE_BUFFERSIZE));
Mark Salyzyn655d7222008-04-30 16:03:42 -04001649 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001651 aac_fib_complete(fibptr);
1652 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001654 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655}
1656
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001657static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001659 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 u32 count;
1661 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 struct aac_dev *dev;
1663 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001664 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
1666 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1667 /*
1668 * Get block address and transfer length
1669 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001670 switch (scsicmd->cmnd[0]) {
1671 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001672 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001674 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001675 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 count = scsicmd->cmnd[4];
1677
1678 if (count == 0)
1679 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001680 break;
1681 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001682 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001683
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001684 lba = ((u64)scsicmd->cmnd[2] << 56) |
1685 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001686 ((u64)scsicmd->cmnd[4] << 40) |
1687 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001688 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001689 (scsicmd->cmnd[7] << 16) |
1690 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001691 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001692 (scsicmd->cmnd[11] << 16) |
1693 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1694 break;
1695 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001696 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001697
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001698 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001699 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001700 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1701 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001702 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001703 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001704 break;
1705 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001706 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001708 lba = ((u64)scsicmd->cmnd[2] << 24) |
1709 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001710 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001712 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001714
1715 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1716 cid = scmd_id(scsicmd);
1717 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1718 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1719 SAM_STAT_CHECK_CONDITION;
1720 set_sense(&dev->fsa_dev[cid].sense_data,
1721 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1722 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1723 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1724 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1725 SCSI_SENSE_BUFFERSIZE));
1726 scsicmd->scsi_done(scsicmd);
1727 return 1;
1728 }
1729
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001730 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001731 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001732 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001733 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 /*
1735 * Alocate and initialize a Fib
1736 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001737 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301738 printk(KERN_WARNING "aac_read: fib allocation failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 return -1;
1740 }
1741
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001742 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744 /*
1745 * Check that the command queued to the controller
1746 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001747 if (status == -EINPROGRESS) {
1748 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001750 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001751
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001752 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 /*
1754 * For some reason, the Fib didn't queue, return QUEUE_FULL
1755 */
1756 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001757 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001758 aac_fib_complete(cmd_fibcontext);
1759 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 return 0;
1761}
1762
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001763static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001765 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001767 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 struct aac_dev *dev;
1770 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001771 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
1773 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1774 /*
1775 * Get block address and transfer length
1776 */
1777 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1778 {
1779 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1780 count = scsicmd->cmnd[4];
1781 if (count == 0)
1782 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001783 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001784 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001785 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001786
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001787 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001788 ((u64)scsicmd->cmnd[3] << 48) |
1789 ((u64)scsicmd->cmnd[4] << 40) |
1790 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001791 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001792 (scsicmd->cmnd[7] << 16) |
1793 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1794 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
1795 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001796 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001797 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001798 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001799
1800 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
1801 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1802 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
1803 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001804 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001806 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001807 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001809 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001811
1812 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1813 cid = scmd_id(scsicmd);
1814 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1815 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1816 SAM_STAT_CHECK_CONDITION;
1817 set_sense(&dev->fsa_dev[cid].sense_data,
1818 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1819 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1820 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1821 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1822 SCSI_SENSE_BUFFERSIZE));
1823 scsicmd->scsi_done(scsicmd);
1824 return 1;
1825 }
1826
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001827 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001829 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001830 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 /*
1832 * Allocate and initialize a Fib then setup a BlockWrite command
1833 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001834 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301835 /* FIB temporarily unavailable,not catastrophic failure */
1836
1837 /* scsicmd->result = DID_ERROR << 16;
1838 * scsicmd->scsi_done(scsicmd);
1839 * return 0;
1840 */
1841 printk(KERN_WARNING "aac_write: fib allocation failed\n");
1842 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001845 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847 /*
1848 * Check that the command queued to the controller
1849 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001850 if (status == -EINPROGRESS) {
1851 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 return 0;
1853 }
1854
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001855 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 /*
1857 * For some reason, the Fib didn't queue, return QUEUE_FULL
1858 */
1859 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001860 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001862 aac_fib_complete(cmd_fibcontext);
1863 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 return 0;
1865}
1866
1867static void synchronize_callback(void *context, struct fib *fibptr)
1868{
1869 struct aac_synchronize_reply *synchronizereply;
1870 struct scsi_cmnd *cmd;
1871
1872 cmd = context;
1873
Mark Haverkamp03d44332007-03-15 10:27:45 -07001874 if (!aac_valid_context(cmd, fibptr))
1875 return;
1876
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001877 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 smp_processor_id(), jiffies));
1879 BUG_ON(fibptr == NULL);
1880
1881
1882 synchronizereply = fib_data(fibptr);
1883 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001884 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1886 else {
1887 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001888 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001889 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001890 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 "synchronize_callback: synchronize failed, status = %d\n",
1892 le32_to_cpu(synchronizereply->status));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001893 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001895 set_sense(&dev->fsa_dev[cid].sense_data,
1896 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1897 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09001899 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1900 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 }
1902
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001903 aac_fib_complete(fibptr);
1904 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001905 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906}
1907
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001908static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
1910 int status;
1911 struct fib *cmd_fibcontext;
1912 struct aac_synchronize *synchronizecmd;
1913 struct scsi_cmnd *cmd;
1914 struct scsi_device *sdev = scsicmd->device;
1915 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001916 struct aac_dev *aac;
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001917 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
1918 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1919 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 unsigned long flags;
1921
1922 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001923 * Wait for all outstanding queued commands to complete to this
1924 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 */
1926 spin_lock_irqsave(&sdev->list_lock, flags);
1927 list_for_each_entry(cmd, &sdev->cmd_list, list)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04001928 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1929 u64 cmnd_lba;
1930 u32 cmnd_count;
1931
1932 if (cmd->cmnd[0] == WRITE_6) {
1933 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
1934 (cmd->cmnd[2] << 8) |
1935 cmd->cmnd[3];
1936 cmnd_count = cmd->cmnd[4];
1937 if (cmnd_count == 0)
1938 cmnd_count = 256;
1939 } else if (cmd->cmnd[0] == WRITE_16) {
1940 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
1941 ((u64)cmd->cmnd[3] << 48) |
1942 ((u64)cmd->cmnd[4] << 40) |
1943 ((u64)cmd->cmnd[5] << 32) |
1944 ((u64)cmd->cmnd[6] << 24) |
1945 (cmd->cmnd[7] << 16) |
1946 (cmd->cmnd[8] << 8) |
1947 cmd->cmnd[9];
1948 cmnd_count = (cmd->cmnd[10] << 24) |
1949 (cmd->cmnd[11] << 16) |
1950 (cmd->cmnd[12] << 8) |
1951 cmd->cmnd[13];
1952 } else if (cmd->cmnd[0] == WRITE_12) {
1953 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1954 (cmd->cmnd[3] << 16) |
1955 (cmd->cmnd[4] << 8) |
1956 cmd->cmnd[5];
1957 cmnd_count = (cmd->cmnd[6] << 24) |
1958 (cmd->cmnd[7] << 16) |
1959 (cmd->cmnd[8] << 8) |
1960 cmd->cmnd[9];
1961 } else if (cmd->cmnd[0] == WRITE_10) {
1962 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
1963 (cmd->cmnd[3] << 16) |
1964 (cmd->cmnd[4] << 8) |
1965 cmd->cmnd[5];
1966 cmnd_count = (cmd->cmnd[7] << 8) |
1967 cmd->cmnd[8];
1968 } else
1969 continue;
1970 if (((cmnd_lba + cmnd_count) < lba) ||
1971 (count && ((lba + count) < cmnd_lba)))
1972 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 ++active;
1974 break;
1975 }
1976
1977 spin_unlock_irqrestore(&sdev->list_lock, flags);
1978
1979 /*
1980 * Yield the processor (requeue for later)
1981 */
1982 if (active)
1983 return SCSI_MLQUEUE_DEVICE_BUSY;
1984
Salyzyn, Markf8583172007-10-30 15:50:49 -04001985 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001986 if (aac->in_reset)
1987 return SCSI_MLQUEUE_HOST_BUSY;
1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001990 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001992 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 return SCSI_MLQUEUE_HOST_BUSY;
1994
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001995 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
1997 synchronizecmd = fib_data(cmd_fibcontext);
1998 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
1999 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002000 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002001 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2003
2004 /*
2005 * Now send the Fib to the adapter
2006 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002007 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 cmd_fibcontext,
2009 sizeof(struct aac_synchronize),
2010 FsaNormal,
2011 0, 1,
2012 (fib_callback)synchronize_callback,
2013 (void *)scsicmd);
2014
2015 /*
2016 * Check that the command queued to the controller
2017 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002018 if (status == -EINPROGRESS) {
2019 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002023 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002024 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2025 aac_fib_complete(cmd_fibcontext);
2026 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 return SCSI_MLQUEUE_HOST_BUSY;
2028}
2029
Mark Salyzyn655d7222008-04-30 16:03:42 -04002030static void aac_start_stop_callback(void *context, struct fib *fibptr)
2031{
2032 struct scsi_cmnd *scsicmd = context;
2033
2034 if (!aac_valid_context(scsicmd, fibptr))
2035 return;
2036
2037 BUG_ON(fibptr == NULL);
2038
2039 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2040
2041 aac_fib_complete(fibptr);
2042 aac_fib_free(fibptr);
2043 scsicmd->scsi_done(scsicmd);
2044}
2045
2046static int aac_start_stop(struct scsi_cmnd *scsicmd)
2047{
2048 int status;
2049 struct fib *cmd_fibcontext;
2050 struct aac_power_management *pmcmd;
2051 struct scsi_device *sdev = scsicmd->device;
2052 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2053
2054 if (!(aac->supplement_adapter_info.SupportedOptions2 &
2055 AAC_OPTION_POWER_MANAGEMENT)) {
2056 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2057 SAM_STAT_GOOD;
2058 scsicmd->scsi_done(scsicmd);
2059 return 0;
2060 }
2061
2062 if (aac->in_reset)
2063 return SCSI_MLQUEUE_HOST_BUSY;
2064
2065 /*
2066 * Allocate and initialize a Fib
2067 */
2068 cmd_fibcontext = aac_fib_alloc(aac);
2069 if (!cmd_fibcontext)
2070 return SCSI_MLQUEUE_HOST_BUSY;
2071
2072 aac_fib_init(cmd_fibcontext);
2073
2074 pmcmd = fib_data(cmd_fibcontext);
2075 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2076 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2077 /* Eject bit ignored, not relevant */
2078 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2079 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2080 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2081 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2082 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2083
2084 /*
2085 * Now send the Fib to the adapter
2086 */
2087 status = aac_fib_send(ContainerCommand,
2088 cmd_fibcontext,
2089 sizeof(struct aac_power_management),
2090 FsaNormal,
2091 0, 1,
2092 (fib_callback)aac_start_stop_callback,
2093 (void *)scsicmd);
2094
2095 /*
2096 * Check that the command queued to the controller
2097 */
2098 if (status == -EINPROGRESS) {
2099 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2100 return 0;
2101 }
2102
2103 aac_fib_complete(cmd_fibcontext);
2104 aac_fib_free(cmd_fibcontext);
2105 return SCSI_MLQUEUE_HOST_BUSY;
2106}
2107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108/**
2109 * aac_scsi_cmd() - Process SCSI command
2110 * @scsicmd: SCSI command block
2111 *
2112 * Emulate a SCSI command and queue the required request for the
2113 * aacraid firmware.
2114 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002115
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2117{
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002118 u32 cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct Scsi_Host *host = scsicmd->device->host;
2120 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2121 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002122
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002123 if (fsa_dev_ptr == NULL)
2124 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 /*
2126 * If the bus, id or lun is out of range, return fail
2127 * Test does not apply to ID 16, the pseudo id for the controller
2128 * itself.
2129 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002130 cid = scmd_id(scsicmd);
2131 if (cid != host->this_id) {
2132 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2133 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08002134 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 scsicmd->result = DID_NO_CONNECT << 16;
2136 scsicmd->scsi_done(scsicmd);
2137 return 0;
2138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 /*
2141 * If the target container doesn't exist, it may have
2142 * been newly created
2143 */
Mark Salyzyn655d7222008-04-30 16:03:42 -04002144 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2145 (fsa_dev_ptr[cid].sense_data.sense_key ==
2146 NOT_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 switch (scsicmd->cmnd[0]) {
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002148 case SERVICE_ACTION_IN:
2149 if (!(dev->raw_io_interface) ||
2150 !(dev->raw_io_64) ||
2151 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2152 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 case INQUIRY:
2154 case READ_CAPACITY:
2155 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002156 if (dev->in_reset)
2157 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07002158 return _aac_probe_container(scsicmd,
2159 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 default:
2161 break;
2162 }
2163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 } else { /* check for physical non-dasd devices */
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08002165 if (dev->nondasd_support || expose_physicals ||
2166 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002167 if (dev->in_reset)
2168 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 return aac_send_srb_fib(scsicmd);
2170 } else {
2171 scsicmd->result = DID_NO_CONNECT << 16;
2172 scsicmd->scsi_done(scsicmd);
2173 return 0;
2174 }
2175 }
2176 }
2177 /*
2178 * else Command for the controller itself
2179 */
2180 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002181 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 {
2183 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2184 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002185 set_sense(&dev->fsa_dev[cid].sense_data,
2186 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2187 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002189 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2190 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 scsicmd->scsi_done(scsicmd);
2192 return 0;
2193 }
2194
2195
2196 /* Handle commands here that don't really require going out to the adapter */
2197 switch (scsicmd->cmnd[0]) {
2198 case INQUIRY:
2199 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002200 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002202 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002203 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
Leubner, Achimd8e965072009-04-01 07:16:08 -07002205 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002206 char *arr = (char *)&inq_data;
2207
2208 /* EVPD bit set */
2209 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2210 INQD_PDT_PROC : INQD_PDT_DA;
2211 if (scsicmd->cmnd[2] == 0) {
2212 /* supported vital product data pages */
2213 arr[3] = 2;
2214 arr[4] = 0x0;
2215 arr[5] = 0x80;
2216 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002217 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2218 sizeof(inq_data));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002219 scsicmd->result = DID_OK << 16 |
2220 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2221 } else if (scsicmd->cmnd[2] == 0x80) {
2222 /* unit serial number page */
2223 arr[3] = setinqserial(dev, &arr[4],
2224 scmd_id(scsicmd));
2225 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002226 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2227 sizeof(inq_data));
Leubner, Achimd8e965072009-04-01 07:16:08 -07002228 if (aac_wwn != 2)
2229 return aac_get_container_serial(
2230 scsicmd);
2231 /* SLES 10 SP1 special */
2232 scsicmd->result = DID_OK << 16 |
2233 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002234 } else {
2235 /* vpd page not implemented */
2236 scsicmd->result = DID_OK << 16 |
2237 COMMAND_COMPLETE << 8 |
2238 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002239 set_sense(&dev->fsa_dev[cid].sense_data,
2240 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2241 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002242 memcpy(scsicmd->sense_buffer,
2243 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002244 min_t(size_t,
2245 sizeof(dev->fsa_dev[cid].sense_data),
2246 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002247 }
2248 scsicmd->scsi_done(scsicmd);
2249 return 0;
2250 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002251 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002252 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 */
2253 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002255 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 /*
2257 * Set the Vendor, Product, and Revision Level
2258 * see: <vendor>.c i.e. aac.c
2259 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002260 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07002261 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002262 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002263 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2264 sizeof(inq_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2266 scsicmd->scsi_done(scsicmd);
2267 return 0;
2268 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002269 if (dev->in_reset)
2270 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07002271 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002272 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002273 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002274 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 }
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002276 case SERVICE_ACTION_IN:
2277 if (!(dev->raw_io_interface) ||
2278 !(dev->raw_io_64) ||
2279 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2280 break;
2281 {
2282 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002283 char cp[13];
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002284 unsigned int alloc_len;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002285
2286 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2287 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002288 cp[0] = (capacity >> 56) & 0xff;
2289 cp[1] = (capacity >> 48) & 0xff;
2290 cp[2] = (capacity >> 40) & 0xff;
2291 cp[3] = (capacity >> 32) & 0xff;
2292 cp[4] = (capacity >> 24) & 0xff;
2293 cp[5] = (capacity >> 16) & 0xff;
2294 cp[6] = (capacity >> 8) & 0xff;
2295 cp[7] = (capacity >> 0) & 0xff;
2296 cp[8] = 0;
2297 cp[9] = 0;
2298 cp[10] = 2;
2299 cp[11] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002300 cp[12] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002301
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002302 alloc_len = ((scsicmd->cmnd[10] << 24)
2303 + (scsicmd->cmnd[11] << 16)
2304 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2305
2306 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002307 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002308 if (alloc_len < scsi_bufflen(scsicmd))
2309 scsi_set_resid(scsicmd,
2310 scsi_bufflen(scsicmd) - alloc_len);
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002311
2312 /* Do not cache partition table for arrays */
2313 scsicmd->device->removable = 1;
2314
2315 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2316 scsicmd->scsi_done(scsicmd);
2317
2318 return 0;
2319 }
2320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 case READ_CAPACITY:
2322 {
2323 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002324 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002327 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 capacity = fsa_dev_ptr[cid].size - 1;
2329 else
2330 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 cp[0] = (capacity >> 24) & 0xff;
2333 cp[1] = (capacity >> 16) & 0xff;
2334 cp[2] = (capacity >> 8) & 0xff;
2335 cp[3] = (capacity >> 0) & 0xff;
2336 cp[4] = 0;
2337 cp[5] = 0;
2338 cp[6] = 2;
2339 cp[7] = 0;
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002340 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002341 /* Do not cache partition table for arrays */
2342 scsicmd->device->removable = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002343 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2344 SAM_STAT_GOOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 scsicmd->scsi_done(scsicmd);
2346
2347 return 0;
2348 }
2349
2350 case MODE_SENSE:
2351 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002352 char mode_buf[7];
2353 int mode_buf_length = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
2355 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 mode_buf[0] = 3; /* Mode data length */
2357 mode_buf[1] = 0; /* Medium type - default */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002358 mode_buf[2] = 0; /* Device-specific param,
2359 bit 8: 0/1 = write enabled/protected
2360 bit 4: 0/1 = FUA enabled */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002361 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002362 mode_buf[2] = 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 mode_buf[3] = 0; /* Block descriptor length */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002364 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2365 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2366 mode_buf[0] = 6;
2367 mode_buf[4] = 8;
2368 mode_buf[5] = 1;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002369 mode_buf[6] = ((aac_cache & 6) == 2)
2370 ? 0 : 0x04; /* WCE */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002371 mode_buf_length = 7;
2372 if (mode_buf_length > scsicmd->cmnd[4])
2373 mode_buf_length = scsicmd->cmnd[4];
2374 }
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002375 scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2377 scsicmd->scsi_done(scsicmd);
2378
2379 return 0;
2380 }
2381 case MODE_SENSE_10:
2382 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002383 char mode_buf[11];
2384 int mode_buf_length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
2386 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 mode_buf[0] = 0; /* Mode data length (MSB) */
2388 mode_buf[1] = 6; /* Mode data length (LSB) */
2389 mode_buf[2] = 0; /* Medium type - default */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002390 mode_buf[3] = 0; /* Device-specific param,
2391 bit 8: 0/1 = write enabled/protected
2392 bit 4: 0/1 = FUA enabled */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002393 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002394 mode_buf[3] = 0x10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 mode_buf[4] = 0; /* reserved */
2396 mode_buf[5] = 0; /* reserved */
2397 mode_buf[6] = 0; /* Block descriptor length (MSB) */
2398 mode_buf[7] = 0; /* Block descriptor length (LSB) */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002399 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2400 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
2401 mode_buf[1] = 9;
2402 mode_buf[8] = 8;
2403 mode_buf[9] = 1;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002404 mode_buf[10] = ((aac_cache & 6) == 2)
2405 ? 0 : 0x04; /* WCE */
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002406 mode_buf_length = 11;
2407 if (mode_buf_length > scsicmd->cmnd[8])
2408 mode_buf_length = scsicmd->cmnd[8];
2409 }
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002410 scsi_sg_copy_from_buffer(scsicmd, mode_buf, mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
2412 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2413 scsicmd->scsi_done(scsicmd);
2414
2415 return 0;
2416 }
2417 case REQUEST_SENSE:
2418 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2419 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2420 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2421 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2422 scsicmd->scsi_done(scsicmd);
2423 return 0;
2424
2425 case ALLOW_MEDIUM_REMOVAL:
2426 dprintk((KERN_DEBUG "LOCK command.\n"));
2427 if (scsicmd->cmnd[4])
2428 fsa_dev_ptr[cid].locked = 1;
2429 else
2430 fsa_dev_ptr[cid].locked = 0;
2431
2432 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2433 scsicmd->scsi_done(scsicmd);
2434 return 0;
2435 /*
2436 * These commands are all No-Ops
2437 */
2438 case TEST_UNIT_READY:
Mark Salyzyn655d7222008-04-30 16:03:42 -04002439 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
2440 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2441 SAM_STAT_CHECK_CONDITION;
2442 set_sense(&dev->fsa_dev[cid].sense_data,
2443 NOT_READY, SENCODE_BECOMING_READY,
2444 ASENCODE_BECOMING_READY, 0, 0);
2445 memcpy(scsicmd->sense_buffer,
2446 &dev->fsa_dev[cid].sense_data,
2447 min_t(size_t,
2448 sizeof(dev->fsa_dev[cid].sense_data),
2449 SCSI_SENSE_BUFFERSIZE));
2450 scsicmd->scsi_done(scsicmd);
2451 return 0;
2452 }
2453 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 case RESERVE:
2455 case RELEASE:
2456 case REZERO_UNIT:
2457 case REASSIGN_BLOCKS:
2458 case SEEK_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2460 scsicmd->scsi_done(scsicmd);
2461 return 0;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002462
2463 case START_STOP:
2464 return aac_start_stop(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 }
2466
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002467 switch (scsicmd->cmnd[0])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 {
2469 case READ_6:
2470 case READ_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002471 case READ_12:
2472 case READ_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002473 if (dev->in_reset)
2474 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 /*
2476 * Hack to keep track of ordinal number of the device that
2477 * corresponds to a container. Needed to convert
2478 * containers to /dev/sd device names
2479 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002480
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002481 if (scsicmd->request->rq_disk)
2482 strlcpy(fsa_dev_ptr[cid].devname,
2483 scsicmd->request->rq_disk->disk_name,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002484 min(sizeof(fsa_dev_ptr[cid].devname),
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002485 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002486
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002487 return aac_read(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
2489 case WRITE_6:
2490 case WRITE_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002491 case WRITE_12:
2492 case WRITE_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002493 if (dev->in_reset)
2494 return -1;
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002495 return aac_write(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
2497 case SYNCHRONIZE_CACHE:
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002498 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2499 scsicmd->result = DID_OK << 16 |
2500 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2501 scsicmd->scsi_done(scsicmd);
2502 return 0;
2503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 /* Issue FIB to tell Firmware to flush it's cache */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002505 if ((aac_cache & 6) != 2)
2506 return aac_synchronize(scsicmd);
2507 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 default:
2509 /*
2510 * Unhandled commands
2511 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002512 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002514 set_sense(&dev->fsa_dev[cid].sense_data,
2515 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2516 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002518 min_t(size_t,
2519 sizeof(dev->fsa_dev[cid].sense_data),
2520 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 scsicmd->scsi_done(scsicmd);
2522 return 0;
2523 }
2524}
2525
2526static int query_disk(struct aac_dev *dev, void __user *arg)
2527{
2528 struct aac_query_disk qd;
2529 struct fsa_dev_info *fsa_dev_ptr;
2530
2531 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002532 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07002533 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2535 return -EFAULT;
2536 if (qd.cnum == -1)
Mark Haverkampe5718772006-03-27 09:43:25 -08002537 qd.cnum = qd.id;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002538 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 {
2540 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2541 return -EINVAL;
2542 qd.instance = dev->scsi_host_ptr->host_no;
2543 qd.bus = 0;
2544 qd.id = CONTAINER_TO_ID(qd.cnum);
2545 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2546 }
2547 else return -EINVAL;
2548
Salyzyn, Markfd622b12007-07-17 10:59:19 -04002549 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2551 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2552
2553 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2554 qd.unmapped = 1;
2555 else
2556 qd.unmapped = 0;
2557
2558 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2559 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2560
2561 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2562 return -EFAULT;
2563 return 0;
2564}
2565
2566static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2567{
2568 struct aac_delete_disk dd;
2569 struct fsa_dev_info *fsa_dev_ptr;
2570
2571 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp65101352006-09-19 08:59:23 -07002572 if (!fsa_dev_ptr)
2573 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
2575 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2576 return -EFAULT;
2577
2578 if (dd.cnum >= dev->maximum_num_containers)
2579 return -EINVAL;
2580 /*
2581 * Mark this container as being deleted.
2582 */
2583 fsa_dev_ptr[dd.cnum].deleted = 1;
2584 /*
2585 * Mark the container as no longer valid
2586 */
2587 fsa_dev_ptr[dd.cnum].valid = 0;
2588 return 0;
2589}
2590
2591static int delete_disk(struct aac_dev *dev, void __user *arg)
2592{
2593 struct aac_delete_disk dd;
2594 struct fsa_dev_info *fsa_dev_ptr;
2595
2596 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002597 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07002598 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
2600 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2601 return -EFAULT;
2602
2603 if (dd.cnum >= dev->maximum_num_containers)
2604 return -EINVAL;
2605 /*
2606 * If the container is locked, it can not be deleted by the API.
2607 */
2608 if (fsa_dev_ptr[dd.cnum].locked)
2609 return -EBUSY;
2610 else {
2611 /*
2612 * Mark the container as no longer being valid.
2613 */
2614 fsa_dev_ptr[dd.cnum].valid = 0;
2615 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2616 return 0;
2617 }
2618}
2619
2620int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2621{
2622 switch (cmd) {
2623 case FSACTL_QUERY_DISK:
2624 return query_disk(dev, arg);
2625 case FSACTL_DELETE_DISK:
2626 return delete_disk(dev, arg);
2627 case FSACTL_FORCE_DELETE_DISK:
2628 return force_delete_disk(dev, arg);
2629 case FSACTL_GET_CONTAINERS:
2630 return aac_get_containers(dev);
2631 default:
2632 return -ENOTTY;
2633 }
2634}
2635
2636/**
2637 *
2638 * aac_srb_callback
2639 * @context: the context set in the fib - here it is scsi cmd
2640 * @fibptr: pointer to the fib
2641 *
2642 * Handles the completion of a scsi command to a non dasd device
2643 *
2644 */
2645
2646static void aac_srb_callback(void *context, struct fib * fibptr)
2647{
2648 struct aac_dev *dev;
2649 struct aac_srb_reply *srbreply;
2650 struct scsi_cmnd *scsicmd;
2651
2652 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07002653
2654 if (!aac_valid_context(scsicmd, fibptr))
2655 return;
2656
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002657 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002659 dev = fibptr->dev;
2660
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2662
2663 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05302665 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
2666 /* fast response */
2667 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
2668 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
2669 } else {
2670 /*
2671 * Calculate resid for sg
2672 */
2673 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2674 - le32_to_cpu(srbreply->data_xfer_length));
2675 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002676
2677 scsi_dma_unmap(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -07002679 /* expose physical device if expose_physicald flag is on */
2680 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
2681 && expose_physicals > 0)
2682 aac_expose_phy_device(scsicmd);
2683
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 /*
2685 * First check the fib status
2686 */
2687
2688 if (le32_to_cpu(srbreply->status) != ST_OK){
2689 int len;
2690 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002691 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2692 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
2694 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
2695 }
2696
2697 /*
2698 * Next check the srb status
2699 */
2700 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
2701 case SRB_STATUS_ERROR_RECOVERY:
2702 case SRB_STATUS_PENDING:
2703 case SRB_STATUS_SUCCESS:
Mark Haverkampbb08f922006-02-01 09:30:44 -08002704 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 break;
2706 case SRB_STATUS_DATA_OVERRUN:
2707 switch(scsicmd->cmnd[0]){
2708 case READ_6:
2709 case WRITE_6:
2710 case READ_10:
2711 case WRITE_10:
2712 case READ_12:
2713 case WRITE_12:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002714 case READ_16:
2715 case WRITE_16:
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002716 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
2718 } else {
2719 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
2720 }
2721 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
2722 break;
2723 case INQUIRY: {
Mark Haverkampbb08f922006-02-01 09:30:44 -08002724 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 break;
2726 }
2727 default:
2728 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
2729 break;
2730 }
2731 break;
2732 case SRB_STATUS_ABORTED:
2733 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
2734 break;
2735 case SRB_STATUS_ABORT_FAILED:
2736 // Not sure about this one - but assuming the hba was trying to abort for some reason
2737 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
2738 break;
2739 case SRB_STATUS_PARITY_ERROR:
2740 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
2741 break;
2742 case SRB_STATUS_NO_DEVICE:
2743 case SRB_STATUS_INVALID_PATH_ID:
2744 case SRB_STATUS_INVALID_TARGET_ID:
2745 case SRB_STATUS_INVALID_LUN:
2746 case SRB_STATUS_SELECTION_TIMEOUT:
2747 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
2748 break;
2749
2750 case SRB_STATUS_COMMAND_TIMEOUT:
2751 case SRB_STATUS_TIMEOUT:
2752 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
2753 break;
2754
2755 case SRB_STATUS_BUSY:
Salyzyn, Mark760af102007-06-19 11:41:21 -04002756 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 break;
2758
2759 case SRB_STATUS_BUS_RESET:
2760 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
2761 break;
2762
2763 case SRB_STATUS_MESSAGE_REJECTED:
2764 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
2765 break;
2766 case SRB_STATUS_REQUEST_FLUSHED:
2767 case SRB_STATUS_ERROR:
2768 case SRB_STATUS_INVALID_REQUEST:
2769 case SRB_STATUS_REQUEST_SENSE_FAILED:
2770 case SRB_STATUS_NO_HBA:
2771 case SRB_STATUS_UNEXPECTED_BUS_FREE:
2772 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
2773 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
2774 case SRB_STATUS_DELAYED_RETRY:
2775 case SRB_STATUS_BAD_FUNCTION:
2776 case SRB_STATUS_NOT_STARTED:
2777 case SRB_STATUS_NOT_IN_USE:
2778 case SRB_STATUS_FORCE_ABORT:
2779 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
2780 default:
2781#ifdef AAC_DETAILED_STATUS_INFO
2782 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
2783 le32_to_cpu(srbreply->srb_status) & 0x3F,
2784 aac_get_status_string(
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002785 le32_to_cpu(srbreply->srb_status) & 0x3F),
2786 scsicmd->cmnd[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 le32_to_cpu(srbreply->scsi_status));
2788#endif
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07002789 if ((scsicmd->cmnd[0] == ATA_12)
2790 || (scsicmd->cmnd[0] == ATA_16)) {
2791 if (scsicmd->cmnd[2] & (0x01 << 5)) {
2792 scsicmd->result = DID_OK << 16
2793 | COMMAND_COMPLETE << 8;
2794 break;
2795 } else {
2796 scsicmd->result = DID_ERROR << 16
2797 | COMMAND_COMPLETE << 8;
2798 break;
2799 }
2800 } else {
2801 scsicmd->result = DID_ERROR << 16
2802 | COMMAND_COMPLETE << 8;
2803 break;
2804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002806 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 int len;
2808 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002809 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2810 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002812 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
2813 le32_to_cpu(srbreply->status), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814#endif
2815 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 }
2817 /*
2818 * OR in the scsi status (already shifted up a bit)
2819 */
2820 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
2821
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002822 aac_fib_complete(fibptr);
2823 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002824 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825}
2826
2827/**
2828 *
2829 * aac_send_scb_fib
2830 * @scsicmd: the scsi command block
2831 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002832 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 * scsicmd passed in.
2834 */
2835
2836static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2837{
2838 struct fib* cmd_fibcontext;
2839 struct aac_dev* dev;
2840 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841
Mark Haverkamp84971732005-06-20 11:55:24 -07002842 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08002843 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07002844 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 scsicmd->result = DID_NO_CONNECT << 16;
2846 scsicmd->scsi_done(scsicmd);
2847 return 0;
2848 }
2849
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 /*
2851 * Allocate and initialize a Fib then setup a BlockWrite command
2852 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002853 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 return -1;
2855 }
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002856 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 /*
2859 * Check that the command queued to the controller
2860 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002861 if (status == -EINPROGRESS) {
2862 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 return 0;
2864 }
2865
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002866 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
2867 aac_fib_complete(cmd_fibcontext);
2868 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
2870 return -1;
2871}
2872
2873static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2874{
2875 struct aac_dev *dev;
2876 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002877 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
2879 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2880 // Get rid of old data
2881 psg->count = 0;
2882 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002883 psg->sg[0].count = 0;
2884
2885 nseg = scsi_dma_map(scsicmd);
2886 BUG_ON(nseg < 0);
2887 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 struct scatterlist *sg;
2889 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002891 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002893 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2895 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
2896 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 }
2898 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002899 if (byte_count > scsi_bufflen(scsicmd)) {
2900 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2901 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002902 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002903 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 }
2905 /* Check for command underflow */
2906 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2907 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2908 byte_count, scsicmd->underflow);
2909 }
2910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 return byte_count;
2912}
2913
2914
2915static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg)
2916{
2917 struct aac_dev *dev;
2918 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002919 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002920 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
2922 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2923 // Get rid of old data
2924 psg->count = 0;
2925 psg->sg[0].addr[0] = 0;
2926 psg->sg[0].addr[1] = 0;
2927 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002928
2929 nseg = scsi_dma_map(scsicmd);
2930 BUG_ON(nseg < 0);
2931 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 struct scatterlist *sg;
2933 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002935 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp1241f352006-03-27 09:44:23 -08002936 int count = sg_dma_len(sg);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002937 addr = sg_dma_address(sg);
2938 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2939 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
Mark Haverkamp1241f352006-03-27 09:44:23 -08002940 psg->sg[i].count = cpu_to_le32(count);
2941 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002943 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002945 if (byte_count > scsi_bufflen(scsicmd)) {
2946 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2947 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07002948 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002949 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 }
2951 /* Check for command underflow */
2952 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2953 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2954 byte_count, scsicmd->underflow);
2955 }
2956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 return byte_count;
2958}
2959
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002960static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2961{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002962 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002963 int nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002964
2965 // Get rid of old data
2966 psg->count = 0;
2967 psg->sg[0].next = 0;
2968 psg->sg[0].prev = 0;
2969 psg->sg[0].addr[0] = 0;
2970 psg->sg[0].addr[1] = 0;
2971 psg->sg[0].count = 0;
2972 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002973
2974 nseg = scsi_dma_map(scsicmd);
2975 BUG_ON(nseg < 0);
2976 if (nseg) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002977 struct scatterlist *sg;
2978 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002979
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002980 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002981 int count = sg_dma_len(sg);
2982 u64 addr = sg_dma_address(sg);
2983 psg->sg[i].next = 0;
2984 psg->sg[i].prev = 0;
2985 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2986 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2987 psg->sg[i].count = cpu_to_le32(count);
2988 psg->sg[i].flags = 0;
2989 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002990 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002991 psg->count = cpu_to_le32(nseg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002992 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002993 if (byte_count > scsi_bufflen(scsicmd)) {
2994 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2995 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002996 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002997 byte_count = scsi_bufflen(scsicmd);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002998 }
2999 /* Check for command underflow */
3000 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3001 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3002 byte_count, scsicmd->underflow);
3003 }
3004 }
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003005 return byte_count;
3006}
3007
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303008static unsigned long aac_build_sgraw2(struct scsi_cmnd *scsicmd, struct aac_raw_io2 *rio2, int sg_max)
3009{
3010 unsigned long byte_count = 0;
3011 int nseg;
3012
3013 nseg = scsi_dma_map(scsicmd);
3014 BUG_ON(nseg < 0);
3015 if (nseg) {
3016 struct scatterlist *sg;
3017 int i, conformable = 0;
3018 u32 min_size = PAGE_SIZE, cur_size;
3019
3020 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3021 int count = sg_dma_len(sg);
3022 u64 addr = sg_dma_address(sg);
3023
3024 BUG_ON(i >= sg_max);
3025 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3026 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3027 cur_size = cpu_to_le32(count);
3028 rio2->sge[i].length = cur_size;
3029 rio2->sge[i].flags = 0;
3030 if (i == 0) {
3031 conformable = 1;
3032 rio2->sgeFirstSize = cur_size;
3033 } else if (i == 1) {
3034 rio2->sgeNominalSize = cur_size;
3035 min_size = cur_size;
3036 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3037 conformable = 0;
3038 if (cur_size < min_size)
3039 min_size = cur_size;
3040 }
3041 byte_count += count;
3042 }
3043
3044 /* hba wants the size to be exact */
3045 if (byte_count > scsi_bufflen(scsicmd)) {
3046 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3047 (byte_count - scsi_bufflen(scsicmd));
3048 rio2->sge[i-1].length = cpu_to_le32(temp);
3049 byte_count = scsi_bufflen(scsicmd);
3050 }
3051
3052 rio2->sgeCnt = cpu_to_le32(nseg);
3053 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3054 /* not conformable: evaluate required sg elements */
3055 if (!conformable) {
3056 int j, nseg_new = nseg, err_found;
3057 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3058 err_found = 0;
3059 nseg_new = 2;
3060 for (j = 1; j < nseg - 1; ++j) {
3061 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3062 err_found = 1;
3063 break;
3064 }
3065 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3066 }
3067 if (!err_found)
3068 break;
3069 }
3070 if (i > 0 && nseg_new <= sg_max)
3071 aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3072 } else
3073 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3074
3075 /* Check for command underflow */
3076 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3077 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3078 byte_count, scsicmd->underflow);
3079 }
3080 }
3081
3082 return byte_count;
3083}
3084
3085static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3086{
3087 struct sge_ieee1212 *sge;
3088 int i, j, pos;
3089 u32 addr_low;
3090
3091 if (aac_convert_sgl == 0)
3092 return 0;
3093
3094 sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
3095 if (sge == NULL)
3096 return -1;
3097
3098 for (i = 1, pos = 1; i < nseg-1; ++i) {
3099 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
3100 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
3101 sge[pos].addrLow = addr_low;
3102 sge[pos].addrHigh = rio2->sge[i].addrHigh;
3103 if (addr_low < rio2->sge[i].addrLow)
3104 sge[pos].addrHigh++;
3105 sge[pos].length = pages * PAGE_SIZE;
3106 sge[pos].flags = 0;
3107 pos++;
3108 }
3109 }
3110 sge[pos] = rio2->sge[nseg-1];
3111 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
3112
3113 kfree(sge);
3114 rio2->sgeCnt = cpu_to_le32(nseg_new);
3115 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3116 rio2->sgeNominalSize = pages * PAGE_SIZE;
3117 return 0;
3118}
3119
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120#ifdef AAC_DETAILED_STATUS_INFO
3121
3122struct aac_srb_status_info {
3123 u32 status;
3124 char *str;
3125};
3126
3127
3128static struct aac_srb_status_info srb_status_info[] = {
3129 { SRB_STATUS_PENDING, "Pending Status"},
3130 { SRB_STATUS_SUCCESS, "Success"},
3131 { SRB_STATUS_ABORTED, "Aborted Command"},
3132 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07003133 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 { SRB_STATUS_BUSY, "Device Busy"},
3135 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
3136 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
3137 { SRB_STATUS_NO_DEVICE, "No Device"},
3138 { SRB_STATUS_TIMEOUT, "Timeout"},
3139 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
3140 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
3141 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
3142 { SRB_STATUS_BUS_RESET, "Bus Reset"},
3143 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
3144 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
3145 { SRB_STATUS_NO_HBA, "No HBA"},
3146 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
3147 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
3148 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
3149 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
3150 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
3151 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07003152 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
3154 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
3155 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
3156 { SRB_STATUS_NOT_STARTED, "Not Started"},
3157 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003158 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
3160 { 0xff, "Unknown Error"}
3161};
3162
3163char *aac_get_status_string(u32 status)
3164{
3165 int i;
3166
Tobias Klauser6391a112006-06-08 22:23:48 -07003167 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
3168 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 return "Bad Status Code";
3172}
3173
3174#endif