blob: 09027e9edfd5922eb5e4fa5e965ddea4b145cd46 [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, Mark3a0086a2008-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
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400114/* MODE_SENSE data format */
115typedef struct {
116 struct {
117 u8 data_length;
118 u8 med_type;
119 u8 dev_par;
120 u8 bd_length;
121 } __attribute__((packed)) hd;
122 struct {
123 u8 dens_code;
124 u8 block_count[3];
125 u8 reserved;
126 u8 block_length[3];
127 } __attribute__((packed)) bd;
128 u8 mpc_buf[3];
129} __attribute__((packed)) aac_modep_data;
130
131/* MODE_SENSE_10 data format */
132typedef struct {
133 struct {
134 u8 data_length[2];
135 u8 med_type;
136 u8 dev_par;
137 u8 rsrvd[2];
138 u8 bd_length[2];
139 } __attribute__((packed)) hd;
140 struct {
141 u8 dens_code;
142 u8 block_count[3];
143 u8 reserved;
144 u8 block_length[3];
145 } __attribute__((packed)) bd;
146 u8 mpc_buf[3];
147} __attribute__((packed)) aac_modep10_data;
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149/*------------------------------------------------------------------------------
150 * S T R U C T S / T Y P E D E F S
151 *----------------------------------------------------------------------------*/
152/* SCSI inquiry data */
153struct inquiry_data {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800154 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
155 u8 inqd_dtq; /* RMB | Device Type Qualifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
157 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
158 u8 inqd_len; /* Additional length (n-4) */
159 u8 inqd_pad1[2];/* Reserved - must be zero */
160 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
161 u8 inqd_vid[8]; /* Vendor ID */
162 u8 inqd_pid[16];/* Product ID */
163 u8 inqd_prl[4]; /* Product Revision Level */
164};
165
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400166/* Added for VPD 0x83 */
167typedef struct {
168 u8 CodeSet:4; /* VPD_CODE_SET */
169 u8 Reserved:4;
170 u8 IdentifierType:4; /* VPD_IDENTIFIER_TYPE */
171 u8 Reserved2:4;
172 u8 Reserved3;
173 u8 IdentifierLength;
174 u8 VendId[8];
175 u8 ProductId[16];
176 u8 SerialNumber[8]; /* SN in ASCII */
177
178} TVPD_ID_Descriptor_Type_1;
179
180typedef struct {
181 u8 CodeSet:4; /* VPD_CODE_SET */
182 u8 Reserved:4;
183 u8 IdentifierType:4; /* VPD_IDENTIFIER_TYPE */
184 u8 Reserved2:4;
185 u8 Reserved3;
186 u8 IdentifierLength;
187 struct TEU64Id {
188 u32 Serial;
189 /* The serial number supposed to be 40 bits,
190 * bit we only support 32, so make the last byte zero. */
191 u8 Reserved;
192 u8 VendId[3];
193 } EU64Id;
194
195} TVPD_ID_Descriptor_Type_2;
196
197typedef struct {
198 u8 DeviceType:5;
199 u8 DeviceTypeQualifier:3;
200 u8 PageCode;
201 u8 Reserved;
202 u8 PageLength;
203 TVPD_ID_Descriptor_Type_1 IdDescriptorType1;
204 TVPD_ID_Descriptor_Type_2 IdDescriptorType2;
205
206} TVPD_Page83;
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208/*
209 * M O D U L E G L O B A L S
210 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800211
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +0530212static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
213static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
214static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
215static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
216 struct aac_raw_io2 *rio2, int sg_max);
217static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
218 int pages, int nseg, int nseg_new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
220#ifdef AAC_DETAILED_STATUS_INFO
221static char *aac_get_status_string(u32 status);
222#endif
223
224/*
225 * Non dasd selection is handled entirely in aachba now
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800226 */
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228static int nondasd = -1;
Leubner, Achimd8e965072009-04-01 07:16:08 -0700229static int aac_cache = 2; /* WCE=0 to avoid performance problems */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static int dacmode = -1;
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800231int aac_msi;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400232int aac_commit = -1;
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700233int startup_timeout = 180;
234int aif_timeout = 120;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800235int aac_sync_mode; /* Only Sync. transfer - disabled */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530236int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800238module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
239MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
240 " 0=off, 1=on");
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530241module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
242MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
243 " 0=off, 1=on");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800244module_param(nondasd, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800245MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
246 " 0=off, 1=on");
Salyzyn, Mark95e852e2008-01-08 12:01:07 -0800247module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800248MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
249 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
250 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
Leubner, Achimd8e965072009-04-01 07:16:08 -0700251 "\tbit 2 - Disable only if Battery is protecting Cache");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800252module_param(dacmode, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800253MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
254 " 0=off, 1=on");
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400255module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800256MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
257 " adapter for foreign arrays.\n"
258 "This is typically needed in systems that do not have a BIOS."
259 " 0=off, 1=on");
260module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
261MODULE_PARM_DESC(msi, "IRQ handling."
262 " 0=PIC(default), 1=MSI, 2=MSI-X(unsupported, uses MSI)");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700263module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800264MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
265 " adapter to have it's kernel up and\n"
266 "running. This is typically adjusted for large systems that do not"
267 " have a BIOS.");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700268module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800269MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
270 " applications to pick up AIFs before\n"
271 "deregistering them. This is typically adjusted for heavily burdened"
272 " systems.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700274int numacb = -1;
275module_param(numacb, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800276MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
277 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
278 " to use suggestion from Firmware.");
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700279
280int acbsize = -1;
281module_param(acbsize, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800282MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
283 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
284 " suggestion from Firmware.");
Mark Haverkamp653ba582006-09-19 08:59:43 -0700285
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400286int update_interval = 30 * 60;
287module_param(update_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800288MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
289 " updates issued to adapter.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400290
291int check_interval = 24 * 60 * 60;
292module_param(check_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800293MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
294 " checks.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400295
Andrew Morton87f3bda2007-08-10 14:50:30 -0700296int aac_check_reset = 1;
297module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
Paul Bolle95e7a8e2008-04-16 14:43:00 +0200298MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800299 " adapter. a value of -1 forces the reset to adapters programmed to"
300 " ignore it.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400301
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800302int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700303module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800304MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
305 " -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700306
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800307int aac_reset_devices;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400308module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
309MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700310
Leubner, Achimd8e965072009-04-01 07:16:08 -0700311int aac_wwn = 1;
312module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
313MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
314 "\t0 - Disable\n"
315 "\t1 - Array Meta Data Signature (default)\n"
316 "\t2 - Adapter Serial Number");
317
318
Mark Haverkamp03d44332007-03-15 10:27:45 -0700319static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
320 struct fib *fibptr) {
321 struct scsi_device *device;
322
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800323 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
Salyzyn, Markc835e372007-07-26 14:20:02 -0400324 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800325 aac_fib_complete(fibptr);
326 aac_fib_free(fibptr);
327 return 0;
328 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700329 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
330 device = scsicmd->device;
331 if (unlikely(!device || !scsi_device_online(device))) {
332 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
333 aac_fib_complete(fibptr);
334 aac_fib_free(fibptr);
335 return 0;
336 }
337 return 1;
338}
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340/**
341 * aac_get_config_status - check the adapter configuration
342 * @common: adapter to query
343 *
344 * Query config status, and commit the configuration if needed.
345 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700346int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
348 int status = 0;
349 struct fib * fibptr;
350
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800351 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return -ENOMEM;
353
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800354 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 {
356 struct aac_get_config_status *dinfo;
357 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
358
359 dinfo->command = cpu_to_le32(VM_ContainerConfig);
360 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
361 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
362 }
363
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800364 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 fibptr,
366 sizeof (struct aac_get_config_status),
367 FsaNormal,
368 1, 1,
369 NULL, NULL);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800370 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
372 } else {
373 struct aac_get_config_status_resp *reply
374 = (struct aac_get_config_status_resp *) fib_data(fibptr);
375 dprintk((KERN_WARNING
376 "aac_get_config_status: response=%d status=%d action=%d\n",
377 le32_to_cpu(reply->response),
378 le32_to_cpu(reply->status),
379 le32_to_cpu(reply->data.action)));
380 if ((le32_to_cpu(reply->response) != ST_OK) ||
381 (le32_to_cpu(reply->status) != CT_OK) ||
382 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
383 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
384 status = -EINVAL;
385 }
386 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530387 /* Do not set XferState to zero unless receives a response from F/W */
388 if (status >= 0)
389 aac_fib_complete(fibptr);
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
392 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400393 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800395 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 dinfo = (struct aac_commit_config *) fib_data(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 dinfo->command = cpu_to_le32(VM_ContainerConfig);
399 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800400
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800401 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 fibptr,
403 sizeof (struct aac_commit_config),
404 FsaNormal,
405 1, 1,
406 NULL, NULL);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530407 /* Do not set XferState to zero unless
408 * receives a response from F/W */
409 if (status >= 0)
410 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400411 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 printk(KERN_WARNING
413 "aac_get_config_status: Foreign device configurations are being ignored\n");
414 }
415 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530416 /* FIB should be freed only after getting the response from the F/W */
417 if (status != -ERESTARTSYS)
418 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 return status;
420}
421
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -0700422static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
423{
424 char inq_data;
425 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
426 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
427 inq_data &= 0xdf;
428 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
429 }
430}
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432/**
433 * aac_get_containers - list containers
434 * @common: adapter to probe
435 *
436 * Make a list of all containers on this controller
437 */
438int aac_get_containers(struct aac_dev *dev)
439{
440 struct fsa_dev_info *fsa_dev_ptr;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800441 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 int status = 0;
443 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 struct aac_get_container_count *dinfo;
445 struct aac_get_container_count_resp *dresp;
446 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
447
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800448 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 return -ENOMEM;
450
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800451 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
453 dinfo->command = cpu_to_le32(VM_ContainerConfig);
454 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
455
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800456 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 fibptr,
458 sizeof (struct aac_get_container_count),
459 FsaNormal,
460 1, 1,
461 NULL, NULL);
462 if (status >= 0) {
463 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
464 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800465 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530467 /* FIB should be freed only after getting the response from the F/W */
468 if (status != -ERESTARTSYS)
469 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
472 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400473 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700474 GFP_KERNEL);
475 if (!fsa_dev_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 dev->fsa_dev = fsa_dev_ptr;
479 dev->maximum_num_containers = maximum_num_containers;
480
Mark Haverkampfe76df42007-03-15 12:55:07 -0700481 for (index = 0; index < dev->maximum_num_containers; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 fsa_dev_ptr[index].devname[0] = '\0';
483
Mark Haverkampfe76df42007-03-15 12:55:07 -0700484 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Mark Haverkampfe76df42007-03-15 12:55:07 -0700486 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
488 break;
489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 /*
492 * If there are no more containers, then stop asking.
493 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700494 if (++index >= status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 return status;
498}
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500static void get_container_name_callback(void *context, struct fib * fibptr)
501{
502 struct aac_get_name_resp * get_name_reply;
503 struct scsi_cmnd * scsicmd;
504
505 scsicmd = (struct scsi_cmnd *) context;
506
Mark Haverkamp03d44332007-03-15 10:27:45 -0700507 if (!aac_valid_context(scsicmd, fibptr))
508 return;
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700511 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
514 /* Failure is irrelevant, using default value instead */
515 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
516 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700517 char *sp = get_name_reply->data;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400518 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 while (*sp == ' ')
520 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700521 if (*sp) {
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900522 struct inquiry_data inq;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700523 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
524 int count = sizeof(d);
525 char *dp = d;
526 do {
527 *dp++ = (*sp) ? *sp++ : ' ';
528 } while (--count > 0);
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900529
530 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
531 memcpy(inq.inqd_pid, d, sizeof(d));
532 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
537
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800538 aac_fib_complete(fibptr);
539 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700540 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541}
542
543/**
544 * aac_get_container_name - get container name, none blocking.
545 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700546static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
548 int status;
549 struct aac_get_name *dinfo;
550 struct fib * cmd_fibcontext;
551 struct aac_dev * dev;
552
553 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
554
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800555 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 return -ENOMEM;
557
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800558 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
560
561 dinfo->command = cpu_to_le32(VM_ContainerConfig);
562 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700563 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
565
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800566 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800567 cmd_fibcontext,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 sizeof (struct aac_get_name),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800569 FsaNormal,
570 0, 1,
571 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /*
575 * Check that the command queued to the controller
576 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800577 if (status == -EINPROGRESS) {
578 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800580 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800581
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800582 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
583 aac_fib_complete(cmd_fibcontext);
584 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 return -1;
586}
587
Mark Haverkampfe76df42007-03-15 12:55:07 -0700588static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
589{
590 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
591
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400592 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700593 return aac_scsi_cmd(scsicmd);
594
595 scsicmd->result = DID_NO_CONNECT << 16;
596 scsicmd->scsi_done(scsicmd);
597 return 0;
598}
599
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400600static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700601{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700602 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700603 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700604 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
605
Mark Haverkamp03d44332007-03-15 10:27:45 -0700606
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400607 if (!aac_valid_context(scsicmd, fibptr))
608 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700609
610 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400611 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700612 if (fsa_dev_ptr) {
613 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
614 fsa_dev_ptr += scmd_id(scsicmd);
615
616 if ((le32_to_cpu(dresp->status) == ST_OK) &&
617 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
618 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400619 if (!(fibptr->dev->supplement_adapter_info.SupportedOptions2 &
620 AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
621 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
622 fsa_dev_ptr->block_size = 0x200;
623 } else {
624 fsa_dev_ptr->block_size =
625 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
626 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700627 fsa_dev_ptr->valid = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -0400628 /* sense_key holds the current state of the spin-up */
629 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
630 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
631 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
632 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700633 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
634 fsa_dev_ptr->size
635 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
636 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
637 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
638 }
639 if ((fsa_dev_ptr->valid & 1) == 0)
640 fsa_dev_ptr->valid = 0;
641 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
642 }
643 aac_fib_complete(fibptr);
644 aac_fib_free(fibptr);
645 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
646 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400647 (*callback)(scsicmd);
648 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700649}
650
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400651static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700652{
653 struct scsi_cmnd * scsicmd;
654 struct aac_mount * dresp;
655 struct aac_query_mount *dinfo;
656 int status;
657
658 dresp = (struct aac_mount *) fib_data(fibptr);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400659 if (!(fibptr->dev->supplement_adapter_info.SupportedOptions2 &
660 AAC_OPTION_VARIABLE_BLOCK_SIZE))
661 dresp->mnt[0].capacityhigh = 0;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700662 if ((le32_to_cpu(dresp->status) != ST_OK) ||
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400663 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
664 _aac_probe_container2(context, fibptr);
665 return;
666 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700667 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700668
Mark Haverkamp03d44332007-03-15 10:27:45 -0700669 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400670 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700671
Mark Haverkampfe76df42007-03-15 12:55:07 -0700672 aac_fib_init(fibptr);
673
674 dinfo = (struct aac_query_mount *)fib_data(fibptr);
675
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400676 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
677 AAC_OPTION_VARIABLE_BLOCK_SIZE)
678 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
679 else
680 dinfo->command = cpu_to_le32(VM_NameServe64);
681
Mark Haverkampfe76df42007-03-15 12:55:07 -0700682 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
683 dinfo->type = cpu_to_le32(FT_FILESYS);
684
685 status = aac_fib_send(ContainerCommand,
686 fibptr,
687 sizeof(struct aac_query_mount),
688 FsaNormal,
689 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400690 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700691 (void *) scsicmd);
692 /*
693 * Check that the command queued to the controller
694 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400695 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700696 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400697 else if (status < 0) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700698 /* Inherit results from VM_NameServe, if any */
699 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400700 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700701 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700702}
703
704static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
705{
706 struct fib * fibptr;
707 int status = -ENOMEM;
708
709 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
710 struct aac_query_mount *dinfo;
711
712 aac_fib_init(fibptr);
713
714 dinfo = (struct aac_query_mount *)fib_data(fibptr);
715
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400716 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
717 AAC_OPTION_VARIABLE_BLOCK_SIZE)
718 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
719 else
720 dinfo->command = cpu_to_le32(VM_NameServe);
721
Mark Haverkampfe76df42007-03-15 12:55:07 -0700722 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
723 dinfo->type = cpu_to_le32(FT_FILESYS);
724 scsicmd->SCp.ptr = (char *)callback;
725
726 status = aac_fib_send(ContainerCommand,
727 fibptr,
728 sizeof(struct aac_query_mount),
729 FsaNormal,
730 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400731 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700732 (void *) scsicmd);
733 /*
734 * Check that the command queued to the controller
735 */
736 if (status == -EINPROGRESS) {
737 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
738 return 0;
739 }
740 if (status < 0) {
741 scsicmd->SCp.ptr = NULL;
742 aac_fib_complete(fibptr);
743 aac_fib_free(fibptr);
744 }
745 }
746 if (status < 0) {
747 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
748 if (fsa_dev_ptr) {
749 fsa_dev_ptr += scmd_id(scsicmd);
750 if ((fsa_dev_ptr->valid & 1) == 0) {
751 fsa_dev_ptr->valid = 0;
752 return (*callback)(scsicmd);
753 }
754 }
755 }
756 return status;
757}
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800760 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 * @dev: device to query
762 * @cid: container identifier
763 *
764 * Queries the controller about the given volume. The volume information
765 * is updated in the struct fsa_dev_info structure rather than returned.
766 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700767static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
768{
769 scsicmd->device = NULL;
770 return 0;
771}
772
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800773int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700775 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
776 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Mark Haverkampfe76df42007-03-15 12:55:07 -0700779 if (!scsicmd || !scsidev) {
780 kfree(scsicmd);
781 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700782 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700784 scsicmd->list.next = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400785 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Mark Haverkampfe76df42007-03-15 12:55:07 -0700787 scsicmd->device = scsidev;
788 scsidev->sdev_state = 0;
789 scsidev->id = cid;
790 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Mark Haverkampfe76df42007-03-15 12:55:07 -0700792 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
793 while (scsicmd->device == scsidev)
794 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400795 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700796 status = scsicmd->SCp.Status;
797 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 return status;
799}
800
801/* Local Structure to set SCSI inquiry data strings */
802struct scsi_inq {
803 char vid[8]; /* Vendor ID */
804 char pid[16]; /* Product ID */
805 char prl[4]; /* Product Revision Level */
806};
807
808/**
809 * InqStrCopy - string merge
810 * @a: string to copy from
811 * @b: string to copy to
812 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800813 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 * without copying \0
815 */
816
817static void inqstrcpy(char *a, char *b)
818{
819
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800820 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 *b++ = *a++;
822}
823
824static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800825 "None",
826 "Volume",
827 "Mirror",
828 "Stripe",
829 "RAID5",
830 "SSRW",
831 "SSRO",
832 "Morph",
833 "Legacy",
834 "RAID4",
835 "RAID10",
836 "RAID00",
837 "V-MIRRORS",
838 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700840 "RAID5D",
841 "RAID5D0",
842 "RAID1E",
843 "RAID6",
844 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800845 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846};
847
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800848char * get_container_type(unsigned tindex)
849{
850 if (tindex >= ARRAY_SIZE(container_types))
851 tindex = ARRAY_SIZE(container_types) - 1;
852 return container_types[tindex];
853}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855/* Function: setinqstr
856 *
857 * Arguments: [1] pointer to void [1] int
858 *
859 * Purpose: Sets SCSI inquiry data strings for vendor, product
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300860 * and revision level. Allows strings to be set in platform dependent
861 * files instead of in OS dependent driver source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 */
863
Mark Haverkamp794d0602005-10-24 10:51:53 -0700864static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
866 struct scsi_inq *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700869 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Mark Haverkamp794d0602005-10-24 10:51:53 -0700871 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
872 char * cp = dev->supplement_adapter_info.AdapterTypeText;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800873 int c;
874 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
875 inqstrcpy("SMC", str->vid);
876 else {
877 c = sizeof(str->vid);
878 while (*cp && *cp != ' ' && --c)
879 ++cp;
880 c = *cp;
881 *cp = '\0';
882 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
883 str->vid);
884 *cp = c;
885 while (*cp && *cp != ' ')
886 ++cp;
887 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700888 while (*cp == ' ')
889 ++cp;
890 /* last six chars reserved for vol type */
891 c = 0;
892 if (strlen(cp) > sizeof(str->pid)) {
893 c = cp[sizeof(str->pid)];
894 cp[sizeof(str->pid)] = '\0';
895 }
896 inqstrcpy (cp, str->pid);
897 if (c)
898 cp[sizeof(str->pid)] = c;
899 } else {
900 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700901
902 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700903 /* last six chars reserved for vol type */
904 inqstrcpy (mp->model, str->pid);
905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Tobias Klauser6391a112006-06-08 22:23:48 -0700907 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 char *findit = str->pid;
909
910 for ( ; *findit != ' '; findit++); /* walk till we find a space */
911 /* RAID is superfluous in the context of a RAID device */
912 if (memcmp(findit-4, "RAID", 4) == 0)
913 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700914 if (((findit - str->pid) + strlen(container_types[tindex]))
915 < (sizeof(str->pid) + sizeof(str->prl)))
916 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918 inqstrcpy ("V1.0", str->prl);
919}
920
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400921static void get_container_serial_callback(void *context, struct fib * fibptr)
922{
923 struct aac_get_serial_resp * get_serial_reply;
924 struct scsi_cmnd * scsicmd;
925
926 BUG_ON(fibptr == NULL);
927
928 scsicmd = (struct scsi_cmnd *) context;
929 if (!aac_valid_context(scsicmd, fibptr))
930 return;
931
932 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
933 /* Failure is irrelevant, using default value instead */
934 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400935 /*Check to see if it's for VPD 0x83 or 0x80 */
936 if (scsicmd->cmnd[2] == 0x83) {
937 /* vpd page 0x83 - Device Identification Page */
938 int i;
939 TVPD_Page83 VPDPage83Data;
940
941 memset(((u8 *)&VPDPage83Data), 0,
942 sizeof(VPDPage83Data));
943
944 /* DIRECT_ACCESS_DEVIC */
945 VPDPage83Data.DeviceType = 0;
946 /* DEVICE_CONNECTED */
947 VPDPage83Data.DeviceTypeQualifier = 0;
948 /* VPD_DEVICE_IDENTIFIERS */
949 VPDPage83Data.PageCode = 0x83;
950 VPDPage83Data.Reserved = 0;
951 VPDPage83Data.PageLength =
952 sizeof(VPDPage83Data.IdDescriptorType1) +
953 sizeof(VPDPage83Data.IdDescriptorType2);
954
955 /* T10 Vendor Identifier Field Format */
956 /* VpdCodeSetAscii */
957 VPDPage83Data.IdDescriptorType1.CodeSet = 2;
958 /* VpdIdentifierTypeVendorId */
959 VPDPage83Data.IdDescriptorType1.IdentifierType = 1;
960 VPDPage83Data.IdDescriptorType1.IdentifierLength =
961 sizeof(VPDPage83Data.IdDescriptorType1) - 4;
962
963 /* "ADAPTEC " for adaptec */
964 memcpy(VPDPage83Data.IdDescriptorType1.VendId,
965 "ADAPTEC ",
966 sizeof(VPDPage83Data.IdDescriptorType1.VendId));
967 memcpy(VPDPage83Data.IdDescriptorType1.ProductId,
968 "ARRAY ",
969 sizeof(
970 VPDPage83Data.IdDescriptorType1.ProductId));
971
972 /* Convert to ascii based serial number.
973 * The LSB is the the end.
974 */
975 for (i = 0; i < 8; i++) {
976 u8 temp =
977 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
978 if (temp > 0x9) {
979 VPDPage83Data.IdDescriptorType1.SerialNumber[i] =
980 'A' + (temp - 0xA);
981 } else {
982 VPDPage83Data.IdDescriptorType1.SerialNumber[i] =
983 '0' + temp;
984 }
985 }
986
987 /* VpdCodeSetBinary */
988 VPDPage83Data.IdDescriptorType2.CodeSet = 1;
989 /* VpdIdentifierTypeEUI64 */
990 VPDPage83Data.IdDescriptorType2.IdentifierType = 2;
991 VPDPage83Data.IdDescriptorType2.IdentifierLength =
992 sizeof(VPDPage83Data.IdDescriptorType2) - 4;
993
994 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[0] = 0xD0;
995 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[1] = 0;
996 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[2] = 0;
997
998 VPDPage83Data.IdDescriptorType2.EU64Id.Serial =
999 get_serial_reply->uid;
1000 VPDPage83Data.IdDescriptorType2.EU64Id.Reserved = 0;
1001
1002 /* Move the inquiry data to the response buffer. */
1003 scsi_sg_copy_from_buffer(scsicmd, &VPDPage83Data,
1004 sizeof(VPDPage83Data));
1005 } else {
1006 /* It must be for VPD 0x80 */
1007 char sp[13];
1008 /* EVPD bit set */
1009 sp[0] = INQD_PDT_DA;
1010 sp[1] = scsicmd->cmnd[2];
1011 sp[2] = 0;
1012 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1013 le32_to_cpu(get_serial_reply->uid));
1014 scsi_sg_copy_from_buffer(scsicmd, sp,
1015 sizeof(sp));
1016 }
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001017 }
1018
1019 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1020
1021 aac_fib_complete(fibptr);
1022 aac_fib_free(fibptr);
1023 scsicmd->scsi_done(scsicmd);
1024}
1025
1026/**
1027 * aac_get_container_serial - get container serial, none blocking.
1028 */
1029static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1030{
1031 int status;
1032 struct aac_get_serial *dinfo;
1033 struct fib * cmd_fibcontext;
1034 struct aac_dev * dev;
1035
1036 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1037
1038 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
1039 return -ENOMEM;
1040
1041 aac_fib_init(cmd_fibcontext);
1042 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1043
1044 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1045 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1046 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1047
1048 status = aac_fib_send(ContainerCommand,
1049 cmd_fibcontext,
1050 sizeof (struct aac_get_serial),
1051 FsaNormal,
1052 0, 1,
1053 (fib_callback) get_container_serial_callback,
1054 (void *) scsicmd);
1055
1056 /*
1057 * Check that the command queued to the controller
1058 */
1059 if (status == -EINPROGRESS) {
1060 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1061 return 0;
1062 }
1063
1064 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1065 aac_fib_complete(cmd_fibcontext);
1066 aac_fib_free(cmd_fibcontext);
1067 return -1;
1068}
1069
1070/* Function: setinqserial
1071 *
1072 * Arguments: [1] pointer to void [1] int
1073 *
1074 * Purpose: Sets SCSI Unit Serial number.
1075 * This is a fake. We should read a proper
1076 * serial number from the container. <SuSE>But
1077 * without docs it's quite hard to do it :-)
1078 * So this will have to do in the meantime.</SuSE>
1079 */
1080
1081static int setinqserial(struct aac_dev *dev, void *data, int cid)
1082{
1083 /*
1084 * This breaks array migration.
1085 */
1086 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1087 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1088}
1089
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001090static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1091 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092{
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001093 u8 *sense_buf = (u8 *)sense_data;
1094 /* Sense data valid, err code 70h */
1095 sense_buf[0] = 0x70; /* No info field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 sense_buf[1] = 0; /* Segment number, always zero */
1097
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001098 sense_buf[2] = sense_key; /* Sense key */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 sense_buf[12] = sense_code; /* Additional sense code */
1101 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001102
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 if (sense_key == ILLEGAL_REQUEST) {
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001104 sense_buf[7] = 10; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001106 sense_buf[15] = bit_pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 /* Illegal parameter is in the parameter block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 if (sense_code == SENCODE_INVALID_CDB_FIELD)
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001109 sense_buf[15] |= 0xc0;/* Std sense key specific field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 /* Illegal parameter is in the CDB block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 sense_buf[16] = field_pointer >> 8; /* MSB */
1112 sense_buf[17] = field_pointer; /* LSB */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001113 } else
1114 sense_buf[7] = 6; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001117static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1118{
1119 if (lba & 0xffffffff00000000LL) {
1120 int cid = scmd_id(cmd);
1121 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1122 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1123 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001124 set_sense(&dev->fsa_dev[cid].sense_data,
1125 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1126 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001127 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001128 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1129 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001130 cmd->scsi_done(cmd);
1131 return 1;
1132 }
1133 return 0;
1134}
1135
1136static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1137{
1138 return 0;
1139}
1140
1141static void io_callback(void *context, struct fib * fibptr);
1142
1143static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1144{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301145 struct aac_dev *dev = fib->dev;
1146 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301147 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001148
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301149 aac_fib_init(fib);
1150 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1151 struct aac_raw_io2 *readcmd2;
1152 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1153 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1154 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1155 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001156 readcmd2->byteCount = cpu_to_le32(count *
1157 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301158 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1159 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301160 ret = aac_build_sgraw2(cmd, readcmd2,
1161 dev->scsi_host_ptr->sg_tablesize);
1162 if (ret < 0)
1163 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301164 command = ContainerRawIo2;
1165 fibsize = sizeof(struct aac_raw_io2) +
1166 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1167 } else {
1168 struct aac_raw_io *readcmd;
1169 readcmd = (struct aac_raw_io *) fib_data(fib);
1170 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1171 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001172 readcmd->count = cpu_to_le32(count *
1173 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301174 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1175 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1176 readcmd->bpTotal = 0;
1177 readcmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301178 ret = aac_build_sgraw(cmd, &readcmd->sg);
1179 if (ret < 0)
1180 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301181 command = ContainerRawIo;
1182 fibsize = sizeof(struct aac_raw_io) +
1183 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1184 }
1185
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001186 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1187 /*
1188 * Now send the Fib to the adapter
1189 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301190 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001191 fib,
1192 fibsize,
1193 FsaNormal,
1194 0, 1,
1195 (fib_callback) io_callback,
1196 (void *) cmd);
1197}
1198
1199static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1200{
1201 u16 fibsize;
1202 struct aac_read64 *readcmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301203 long ret;
1204
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001205 aac_fib_init(fib);
1206 readcmd = (struct aac_read64 *) fib_data(fib);
1207 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1208 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1209 readcmd->sector_count = cpu_to_le16(count);
1210 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1211 readcmd->pad = 0;
1212 readcmd->flags = 0;
1213
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301214 ret = aac_build_sg64(cmd, &readcmd->sg);
1215 if (ret < 0)
1216 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001217 fibsize = sizeof(struct aac_read64) +
1218 ((le32_to_cpu(readcmd->sg.count) - 1) *
1219 sizeof (struct sgentry64));
1220 BUG_ON (fibsize > (fib->dev->max_fib_size -
1221 sizeof(struct aac_fibhdr)));
1222 /*
1223 * Now send the Fib to the adapter
1224 */
1225 return aac_fib_send(ContainerCommand64,
1226 fib,
1227 fibsize,
1228 FsaNormal,
1229 0, 1,
1230 (fib_callback) io_callback,
1231 (void *) cmd);
1232}
1233
1234static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1235{
1236 u16 fibsize;
1237 struct aac_read *readcmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001238 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301239 long ret;
1240
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001241 aac_fib_init(fib);
1242 readcmd = (struct aac_read *) fib_data(fib);
1243 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001244 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001245 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001246 readcmd->count = cpu_to_le32(count *
1247 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001248
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301249 ret = aac_build_sg(cmd, &readcmd->sg);
1250 if (ret < 0)
1251 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001252 fibsize = sizeof(struct aac_read) +
1253 ((le32_to_cpu(readcmd->sg.count) - 1) *
1254 sizeof (struct sgentry));
1255 BUG_ON (fibsize > (fib->dev->max_fib_size -
1256 sizeof(struct aac_fibhdr)));
1257 /*
1258 * Now send the Fib to the adapter
1259 */
1260 return aac_fib_send(ContainerCommand,
1261 fib,
1262 fibsize,
1263 FsaNormal,
1264 0, 1,
1265 (fib_callback) io_callback,
1266 (void *) cmd);
1267}
1268
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001269static 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 -08001270{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301271 struct aac_dev *dev = fib->dev;
1272 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301273 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001274
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301275 aac_fib_init(fib);
1276 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1277 struct aac_raw_io2 *writecmd2;
1278 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1279 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1280 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1281 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001282 writecmd2->byteCount = cpu_to_le32(count *
1283 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301284 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1285 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1286 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1287 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1288 cpu_to_le16(RIO2_IO_TYPE_WRITE);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301289 ret = aac_build_sgraw2(cmd, writecmd2,
1290 dev->scsi_host_ptr->sg_tablesize);
1291 if (ret < 0)
1292 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301293 command = ContainerRawIo2;
1294 fibsize = sizeof(struct aac_raw_io2) +
1295 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1296 } else {
1297 struct aac_raw_io *writecmd;
1298 writecmd = (struct aac_raw_io *) fib_data(fib);
1299 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1300 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001301 writecmd->count = cpu_to_le32(count *
1302 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301303 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1304 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1305 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1306 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1307 cpu_to_le16(RIO_TYPE_WRITE);
1308 writecmd->bpTotal = 0;
1309 writecmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301310 ret = aac_build_sgraw(cmd, &writecmd->sg);
1311 if (ret < 0)
1312 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301313 command = ContainerRawIo;
1314 fibsize = sizeof(struct aac_raw_io) +
1315 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1316 }
1317
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001318 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1319 /*
1320 * Now send the Fib to the adapter
1321 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301322 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001323 fib,
1324 fibsize,
1325 FsaNormal,
1326 0, 1,
1327 (fib_callback) io_callback,
1328 (void *) cmd);
1329}
1330
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001331static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001332{
1333 u16 fibsize;
1334 struct aac_write64 *writecmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301335 long ret;
1336
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001337 aac_fib_init(fib);
1338 writecmd = (struct aac_write64 *) fib_data(fib);
1339 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1340 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1341 writecmd->sector_count = cpu_to_le16(count);
1342 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1343 writecmd->pad = 0;
1344 writecmd->flags = 0;
1345
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301346 ret = aac_build_sg64(cmd, &writecmd->sg);
1347 if (ret < 0)
1348 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001349 fibsize = sizeof(struct aac_write64) +
1350 ((le32_to_cpu(writecmd->sg.count) - 1) *
1351 sizeof (struct sgentry64));
1352 BUG_ON (fibsize > (fib->dev->max_fib_size -
1353 sizeof(struct aac_fibhdr)));
1354 /*
1355 * Now send the Fib to the adapter
1356 */
1357 return aac_fib_send(ContainerCommand64,
1358 fib,
1359 fibsize,
1360 FsaNormal,
1361 0, 1,
1362 (fib_callback) io_callback,
1363 (void *) cmd);
1364}
1365
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001366static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001367{
1368 u16 fibsize;
1369 struct aac_write *writecmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001370 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301371 long ret;
1372
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001373 aac_fib_init(fib);
1374 writecmd = (struct aac_write *) fib_data(fib);
1375 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001376 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001377 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001378 writecmd->count = cpu_to_le32(count *
1379 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001380 writecmd->sg.count = cpu_to_le32(1);
1381 /* ->stable is not used - it did mean which type of write */
1382
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301383 ret = aac_build_sg(cmd, &writecmd->sg);
1384 if (ret < 0)
1385 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001386 fibsize = sizeof(struct aac_write) +
1387 ((le32_to_cpu(writecmd->sg.count) - 1) *
1388 sizeof (struct sgentry));
1389 BUG_ON (fibsize > (fib->dev->max_fib_size -
1390 sizeof(struct aac_fibhdr)));
1391 /*
1392 * Now send the Fib to the adapter
1393 */
1394 return aac_fib_send(ContainerCommand,
1395 fib,
1396 fibsize,
1397 FsaNormal,
1398 0, 1,
1399 (fib_callback) io_callback,
1400 (void *) cmd);
1401}
1402
1403static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1404{
1405 struct aac_srb * srbcmd;
1406 u32 flag;
1407 u32 timeout;
1408
1409 aac_fib_init(fib);
1410 switch(cmd->sc_data_direction){
1411 case DMA_TO_DEVICE:
1412 flag = SRB_DataOut;
1413 break;
1414 case DMA_BIDIRECTIONAL:
1415 flag = SRB_DataIn | SRB_DataOut;
1416 break;
1417 case DMA_FROM_DEVICE:
1418 flag = SRB_DataIn;
1419 break;
1420 case DMA_NONE:
1421 default: /* shuts up some versions of gcc */
1422 flag = SRB_NoDataXfer;
1423 break;
1424 }
1425
1426 srbcmd = (struct aac_srb*) fib_data(fib);
1427 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1428 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1429 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1430 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1431 srbcmd->flags = cpu_to_le32(flag);
Jens Axboe242f9dc2008-09-14 05:55:09 -07001432 timeout = cmd->request->timeout/HZ;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001433 if (timeout == 0)
1434 timeout = 1;
1435 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1436 srbcmd->retry_limit = 0; /* Obsolete parameter */
1437 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1438 return srbcmd;
1439}
1440
1441static void aac_srb_callback(void *context, struct fib * fibptr);
1442
1443static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1444{
1445 u16 fibsize;
1446 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301447 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001448
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301449 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1450 if (ret < 0)
1451 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001452 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001453
1454 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1455 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1456 /*
1457 * Build Scatter/Gather list
1458 */
1459 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1460 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1461 sizeof (struct sgentry64));
1462 BUG_ON (fibsize > (fib->dev->max_fib_size -
1463 sizeof(struct aac_fibhdr)));
1464
1465 /*
1466 * Now send the Fib to the adapter
1467 */
1468 return aac_fib_send(ScsiPortCommand64, fib,
1469 fibsize, FsaNormal, 0, 1,
1470 (fib_callback) aac_srb_callback,
1471 (void *) cmd);
1472}
1473
1474static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1475{
1476 u16 fibsize;
1477 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301478 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001479
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301480 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1481 if (ret < 0)
1482 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001483 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001484
1485 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1486 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1487 /*
1488 * Build Scatter/Gather list
1489 */
1490 fibsize = sizeof (struct aac_srb) +
1491 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1492 sizeof (struct sgentry));
1493 BUG_ON (fibsize > (fib->dev->max_fib_size -
1494 sizeof(struct aac_fibhdr)));
1495
1496 /*
1497 * Now send the Fib to the adapter
1498 */
1499 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1500 (fib_callback) aac_srb_callback, (void *) cmd);
1501}
1502
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001503static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1504{
Leubner, Achimd8e965072009-04-01 07:16:08 -07001505 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1506 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001507 return FAILED;
1508 return aac_scsi_32(fib, cmd);
1509}
1510
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511int aac_get_adapter_info(struct aac_dev* dev)
1512{
1513 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 int rcode;
1515 u32 tmp;
Mark Haverkamp84971732005-06-20 11:55:24 -07001516 struct aac_adapter_info *info;
1517 struct aac_bus_info *command;
1518 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001519
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001520 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 return -ENOMEM;
1522
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001523 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001524 info = (struct aac_adapter_info *) fib_data(fibptr);
1525 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001527 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001528 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001529 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001530 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07001531 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001532 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001533 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001535 if (rcode < 0) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301536 /* FIB should be freed only after
1537 * getting the response from the F/W */
1538 if (rcode != -ERESTARTSYS) {
1539 aac_fib_complete(fibptr);
1540 aac_fib_free(fibptr);
1541 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001542 return rcode;
1543 }
1544 memcpy(&dev->adapter_info, info, sizeof(*info));
1545
1546 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001547 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001548
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001549 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001550
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001551 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001552
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001553 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001554
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001555 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001556 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001557 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001558 FsaNormal,
1559 1, 1,
1560 NULL,
1561 NULL);
1562
1563 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001564 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301565 if (rcode == -ERESTARTSYS) {
1566 fibptr = aac_fib_alloc(dev);
1567 if (!fibptr)
1568 return -ENOMEM;
1569 }
1570
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Mark Haverkamp84971732005-06-20 11:55:24 -07001573
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001574 /*
1575 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07001576 */
1577
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001578 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07001579
1580 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1581
1582 memset(bus_info, 0, sizeof(*bus_info));
1583
1584 command = (struct aac_bus_info *)bus_info;
1585
1586 command->Command = cpu_to_le32(VM_Ioctl);
1587 command->ObjType = cpu_to_le32(FT_DRIVE);
1588 command->MethodId = cpu_to_le32(1);
1589 command->CtlCmd = cpu_to_le32(GetBusInfo);
1590
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001591 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07001592 fibptr,
1593 sizeof (*bus_info),
1594 FsaNormal,
1595 1, 1,
1596 NULL, NULL);
1597
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001598 /* reasoned default */
1599 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07001600 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1601 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1602 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1603 }
1604
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001605 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001606 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001607 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1608 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001609 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 dev->id,
1611 tmp>>24,
1612 (tmp>>16)&0xff,
1613 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001614 le32_to_cpu(dev->adapter_info.kernelbuild),
1615 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1616 dev->supplement_adapter_info.BuildDate);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001617 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1618 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 dev->name, dev->id,
1620 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1621 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001622 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1623 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 dev->name, dev->id,
1625 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1626 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001627 buffer[0] = '\0';
Tony Jonesee959b02008-02-22 00:13:36 +01001628 if (aac_get_serial_number(
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001629 shost_to_class(dev->scsi_host_ptr), buffer))
1630 printk(KERN_INFO "%s%d: serial %s",
1631 dev->name, dev->id, buffer);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04001632 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1633 printk(KERN_INFO "%s%d: TSID %.*s\n",
1634 dev->name, dev->id,
1635 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1636 dev->supplement_adapter_info.VpdInfo.Tsid);
1637 }
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001638 if (!aac_check_reset || ((aac_check_reset == 1) &&
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001639 (dev->supplement_adapter_info.SupportedOptions2 &
1640 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001641 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1642 dev->name, dev->id);
1643 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001646 dev->cache_protected = 0;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001647 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1648 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 dev->nondasd_support = 0;
1650 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001651 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 /*
1655 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1656 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1657 * force nondasd support on. If we decide to allow the non-dasd flag
1658 * additional changes changes will have to be made to support
1659 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1660 * changed to support the new dev->raid_scsi_mode flag instead of
1661 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1662 * function aac_detect will have to be modified where it sets up the
1663 * max number of channels based on the aac->nondasd_support flag only.
1664 */
1665 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1666 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1667 dev->nondasd_support = 1;
1668 dev->raid_scsi_mode = 1;
1669 }
1670 if (dev->raid_scsi_mode != 0)
1671 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1672 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001673
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001674 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001676 if (dev->nondasd_support && !dev->in_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Yang Hongyange9304382009-04-13 14:40:14 -07001679 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
Leubner, Achimd8e965072009-04-01 07:16:08 -07001680 dev->needs_dac = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 dev->dac_support = 0;
Leubner, Achimd8e965072009-04-01 07:16:08 -07001682 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
1683 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001684 if (!dev->in_reset)
1685 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
1686 dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 dev->dac_support = 1;
1688 }
1689
1690 if(dacmode != -1) {
1691 dev->dac_support = (dacmode!=0);
1692 }
Leubner, Achimd8e965072009-04-01 07:16:08 -07001693
1694 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1695 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
1696 & AAC_QUIRK_SCSI_32)) {
1697 dev->nondasd_support = 0;
1698 dev->jbod = 0;
1699 expose_physicals = 0;
1700 }
1701
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 if(dev->dac_support != 0) {
Yang Hongyang6a355282009-04-06 19:01:13 -07001703 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64)) &&
1704 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001705 if (!dev->in_reset)
1706 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1707 dev->name, dev->id);
Yang Hongyang284901a2009-04-06 19:01:15 -07001708 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32)) &&
1709 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1711 dev->name, dev->id);
1712 dev->dac_support = 0;
1713 } else {
1714 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1715 dev->name, dev->id);
1716 rcode = -ENOMEM;
1717 }
1718 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001719 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001720 * Deal with configuring for the individualized limits of each packet
1721 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001722 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001723 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001724 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1725 ? aac_scsi_32_64
1726 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001727 : aac_scsi_32;
1728 if (dev->raw_io_interface) {
1729 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1730 ? aac_bounds_64
1731 : aac_bounds_32;
1732 dev->a_ops.adapter_read = aac_read_raw_io;
1733 dev->a_ops.adapter_write = aac_write_raw_io;
1734 } else {
1735 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001736 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001737 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001738 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1739 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001740 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001741 dev->a_ops.adapter_read = aac_read_block64;
1742 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001743 /*
1744 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001745 */
1746 dev->scsi_host_ptr->sg_tablesize =
1747 (dev->max_fib_size -
1748 sizeof(struct aac_fibhdr) -
1749 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001750 sizeof(struct sgentry64)) /
1751 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001752 } else {
1753 dev->a_ops.adapter_read = aac_read_block;
1754 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001755 }
1756 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07001757 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001758 /*
1759 * Worst case size that could cause sg overflow when
1760 * we break up SG elements that are larger than 64KB.
1761 * Would be nice if we could tell the SCSI layer what
1762 * the maximum SG element size can be. Worst case is
1763 * (sg_tablesize-1) 4KB elements with one 64KB
1764 * element.
1765 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1766 */
1767 dev->scsi_host_ptr->max_sectors =
1768 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1769 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001770 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301771 /* FIB should be freed only after getting the response from the F/W */
1772 if (rcode != -ERESTARTSYS) {
1773 aac_fib_complete(fibptr);
1774 aac_fib_free(fibptr);
1775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
1777 return rcode;
1778}
1779
1780
Mark Haverkampe53cb352005-08-03 15:39:09 -07001781static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782{
1783 struct aac_dev *dev;
1784 struct aac_read_reply *readreply;
1785 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 u32 cid;
1787
1788 scsicmd = (struct scsi_cmnd *) context;
1789
Mark Haverkamp03d44332007-03-15 10:27:45 -07001790 if (!aac_valid_context(scsicmd, fibptr))
1791 return;
1792
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001793 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001794 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001796 if (nblank(dprintk(x))) {
1797 u64 lba;
1798 switch (scsicmd->cmnd[0]) {
1799 case WRITE_6:
1800 case READ_6:
1801 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1802 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1803 break;
1804 case WRITE_16:
1805 case READ_16:
1806 lba = ((u64)scsicmd->cmnd[2] << 56) |
1807 ((u64)scsicmd->cmnd[3] << 48) |
1808 ((u64)scsicmd->cmnd[4] << 40) |
1809 ((u64)scsicmd->cmnd[5] << 32) |
1810 ((u64)scsicmd->cmnd[6] << 24) |
1811 (scsicmd->cmnd[7] << 16) |
1812 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1813 break;
1814 case WRITE_12:
1815 case READ_12:
1816 lba = ((u64)scsicmd->cmnd[2] << 24) |
1817 (scsicmd->cmnd[3] << 16) |
1818 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1819 break;
1820 default:
1821 lba = ((u64)scsicmd->cmnd[2] << 24) |
1822 (scsicmd->cmnd[3] << 16) |
1823 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1824 break;
1825 }
1826 printk(KERN_DEBUG
1827 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1828 smp_processor_id(), (unsigned long long)lba, jiffies);
1829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Eric Sesterhenn125e1872006-06-23 02:06:06 -07001831 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001832
1833 scsi_dma_unmap(scsicmd);
1834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 readreply = (struct aac_read_reply *)fib_data(fibptr);
Mark Salyzyn655d7222008-04-30 16:03:42 -04001836 switch (le32_to_cpu(readreply->status)) {
1837 case ST_OK:
1838 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1839 SAM_STAT_GOOD;
1840 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
1841 break;
1842 case ST_NOT_READY:
1843 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1844 SAM_STAT_CHECK_CONDITION;
1845 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
1846 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
1847 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1848 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1849 SCSI_SENSE_BUFFERSIZE));
1850 break;
1851 default:
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001852#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07001853 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001854 le32_to_cpu(readreply->status));
1855#endif
Mark Salyzyn655d7222008-04-30 16:03:42 -04001856 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1857 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001858 set_sense(&dev->fsa_dev[cid].sense_data,
1859 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1860 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001862 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1863 SCSI_SENSE_BUFFERSIZE));
Mark Salyzyn655d7222008-04-30 16:03:42 -04001864 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001866 aac_fib_complete(fibptr);
1867 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001869 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870}
1871
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001872static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001874 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 u32 count;
1876 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 struct aac_dev *dev;
1878 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001879 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
1881 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1882 /*
1883 * Get block address and transfer length
1884 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001885 switch (scsicmd->cmnd[0]) {
1886 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001887 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001889 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001890 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 count = scsicmd->cmnd[4];
1892
1893 if (count == 0)
1894 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001895 break;
1896 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001897 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001898
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001899 lba = ((u64)scsicmd->cmnd[2] << 56) |
1900 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001901 ((u64)scsicmd->cmnd[4] << 40) |
1902 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001903 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001904 (scsicmd->cmnd[7] << 16) |
1905 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001906 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001907 (scsicmd->cmnd[11] << 16) |
1908 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1909 break;
1910 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001911 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001912
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001913 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001914 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001915 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1916 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001917 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001918 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001919 break;
1920 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001921 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001923 lba = ((u64)scsicmd->cmnd[2] << 24) |
1924 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001925 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001927 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001929
1930 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1931 cid = scmd_id(scsicmd);
1932 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1933 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1934 SAM_STAT_CHECK_CONDITION;
1935 set_sense(&dev->fsa_dev[cid].sense_data,
1936 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1937 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1938 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1939 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1940 SCSI_SENSE_BUFFERSIZE));
1941 scsicmd->scsi_done(scsicmd);
1942 return 1;
1943 }
1944
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001945 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001946 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001947 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001948 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 /*
1950 * Alocate and initialize a Fib
1951 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001952 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301953 printk(KERN_WARNING "aac_read: fib allocation failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 return -1;
1955 }
1956
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001957 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
1959 /*
1960 * Check that the command queued to the controller
1961 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001962 if (status == -EINPROGRESS) {
1963 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001965 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001966
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001967 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 /*
1969 * For some reason, the Fib didn't queue, return QUEUE_FULL
1970 */
1971 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001972 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001973 aac_fib_complete(cmd_fibcontext);
1974 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 return 0;
1976}
1977
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001978static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001980 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001982 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 struct aac_dev *dev;
1985 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001986 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1989 /*
1990 * Get block address and transfer length
1991 */
1992 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1993 {
1994 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1995 count = scsicmd->cmnd[4];
1996 if (count == 0)
1997 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001998 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001999 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002000 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002001
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002002 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002003 ((u64)scsicmd->cmnd[3] << 48) |
2004 ((u64)scsicmd->cmnd[4] << 40) |
2005 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002006 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002007 (scsicmd->cmnd[7] << 16) |
2008 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2009 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2010 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002011 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002012 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002013 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002014
2015 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2016 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2017 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2018 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002019 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002021 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002022 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002024 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002026
2027 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2028 cid = scmd_id(scsicmd);
2029 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2030 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2031 SAM_STAT_CHECK_CONDITION;
2032 set_sense(&dev->fsa_dev[cid].sense_data,
2033 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2034 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2035 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2036 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2037 SCSI_SENSE_BUFFERSIZE));
2038 scsicmd->scsi_done(scsicmd);
2039 return 1;
2040 }
2041
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002042 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002044 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002045 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 /*
2047 * Allocate and initialize a Fib then setup a BlockWrite command
2048 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002049 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302050 /* FIB temporarily unavailable,not catastrophic failure */
2051
2052 /* scsicmd->result = DID_ERROR << 16;
2053 * scsicmd->scsi_done(scsicmd);
2054 * return 0;
2055 */
2056 printk(KERN_WARNING "aac_write: fib allocation failed\n");
2057 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002060 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
2062 /*
2063 * Check that the command queued to the controller
2064 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002065 if (status == -EINPROGRESS) {
2066 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 return 0;
2068 }
2069
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002070 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 /*
2072 * For some reason, the Fib didn't queue, return QUEUE_FULL
2073 */
2074 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002075 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002077 aac_fib_complete(cmd_fibcontext);
2078 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 return 0;
2080}
2081
2082static void synchronize_callback(void *context, struct fib *fibptr)
2083{
2084 struct aac_synchronize_reply *synchronizereply;
2085 struct scsi_cmnd *cmd;
2086
2087 cmd = context;
2088
Mark Haverkamp03d44332007-03-15 10:27:45 -07002089 if (!aac_valid_context(cmd, fibptr))
2090 return;
2091
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002092 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 smp_processor_id(), jiffies));
2094 BUG_ON(fibptr == NULL);
2095
2096
2097 synchronizereply = fib_data(fibptr);
2098 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002099 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2101 else {
2102 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002103 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002104 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002105 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 "synchronize_callback: synchronize failed, status = %d\n",
2107 le32_to_cpu(synchronizereply->status));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002108 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002110 set_sense(&dev->fsa_dev[cid].sense_data,
2111 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2112 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002114 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2115 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 }
2117
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002118 aac_fib_complete(fibptr);
2119 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002120 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121}
2122
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002123static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 int status;
2126 struct fib *cmd_fibcontext;
2127 struct aac_synchronize *synchronizecmd;
2128 struct scsi_cmnd *cmd;
2129 struct scsi_device *sdev = scsicmd->device;
2130 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002131 struct aac_dev *aac;
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002132 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2133 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2134 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 unsigned long flags;
2136
2137 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002138 * Wait for all outstanding queued commands to complete to this
2139 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 */
2141 spin_lock_irqsave(&sdev->list_lock, flags);
2142 list_for_each_entry(cmd, &sdev->cmd_list, list)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002143 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2144 u64 cmnd_lba;
2145 u32 cmnd_count;
2146
2147 if (cmd->cmnd[0] == WRITE_6) {
2148 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2149 (cmd->cmnd[2] << 8) |
2150 cmd->cmnd[3];
2151 cmnd_count = cmd->cmnd[4];
2152 if (cmnd_count == 0)
2153 cmnd_count = 256;
2154 } else if (cmd->cmnd[0] == WRITE_16) {
2155 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2156 ((u64)cmd->cmnd[3] << 48) |
2157 ((u64)cmd->cmnd[4] << 40) |
2158 ((u64)cmd->cmnd[5] << 32) |
2159 ((u64)cmd->cmnd[6] << 24) |
2160 (cmd->cmnd[7] << 16) |
2161 (cmd->cmnd[8] << 8) |
2162 cmd->cmnd[9];
2163 cmnd_count = (cmd->cmnd[10] << 24) |
2164 (cmd->cmnd[11] << 16) |
2165 (cmd->cmnd[12] << 8) |
2166 cmd->cmnd[13];
2167 } else if (cmd->cmnd[0] == WRITE_12) {
2168 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2169 (cmd->cmnd[3] << 16) |
2170 (cmd->cmnd[4] << 8) |
2171 cmd->cmnd[5];
2172 cmnd_count = (cmd->cmnd[6] << 24) |
2173 (cmd->cmnd[7] << 16) |
2174 (cmd->cmnd[8] << 8) |
2175 cmd->cmnd[9];
2176 } else if (cmd->cmnd[0] == WRITE_10) {
2177 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2178 (cmd->cmnd[3] << 16) |
2179 (cmd->cmnd[4] << 8) |
2180 cmd->cmnd[5];
2181 cmnd_count = (cmd->cmnd[7] << 8) |
2182 cmd->cmnd[8];
2183 } else
2184 continue;
2185 if (((cmnd_lba + cmnd_count) < lba) ||
2186 (count && ((lba + count) < cmnd_lba)))
2187 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 ++active;
2189 break;
2190 }
2191
2192 spin_unlock_irqrestore(&sdev->list_lock, flags);
2193
2194 /*
2195 * Yield the processor (requeue for later)
2196 */
2197 if (active)
2198 return SCSI_MLQUEUE_DEVICE_BUSY;
2199
Salyzyn, Markf8583172007-10-30 15:50:49 -04002200 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002201 if (aac->in_reset)
2202 return SCSI_MLQUEUE_HOST_BUSY;
2203
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002205 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002207 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 return SCSI_MLQUEUE_HOST_BUSY;
2209
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002210 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
2212 synchronizecmd = fib_data(cmd_fibcontext);
2213 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2214 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002215 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002216 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2218
2219 /*
2220 * Now send the Fib to the adapter
2221 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002222 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 cmd_fibcontext,
2224 sizeof(struct aac_synchronize),
2225 FsaNormal,
2226 0, 1,
2227 (fib_callback)synchronize_callback,
2228 (void *)scsicmd);
2229
2230 /*
2231 * Check that the command queued to the controller
2232 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002233 if (status == -EINPROGRESS) {
2234 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002238 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002239 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2240 aac_fib_complete(cmd_fibcontext);
2241 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 return SCSI_MLQUEUE_HOST_BUSY;
2243}
2244
Mark Salyzyn655d7222008-04-30 16:03:42 -04002245static void aac_start_stop_callback(void *context, struct fib *fibptr)
2246{
2247 struct scsi_cmnd *scsicmd = context;
2248
2249 if (!aac_valid_context(scsicmd, fibptr))
2250 return;
2251
2252 BUG_ON(fibptr == NULL);
2253
2254 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2255
2256 aac_fib_complete(fibptr);
2257 aac_fib_free(fibptr);
2258 scsicmd->scsi_done(scsicmd);
2259}
2260
2261static int aac_start_stop(struct scsi_cmnd *scsicmd)
2262{
2263 int status;
2264 struct fib *cmd_fibcontext;
2265 struct aac_power_management *pmcmd;
2266 struct scsi_device *sdev = scsicmd->device;
2267 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2268
2269 if (!(aac->supplement_adapter_info.SupportedOptions2 &
2270 AAC_OPTION_POWER_MANAGEMENT)) {
2271 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2272 SAM_STAT_GOOD;
2273 scsicmd->scsi_done(scsicmd);
2274 return 0;
2275 }
2276
2277 if (aac->in_reset)
2278 return SCSI_MLQUEUE_HOST_BUSY;
2279
2280 /*
2281 * Allocate and initialize a Fib
2282 */
2283 cmd_fibcontext = aac_fib_alloc(aac);
2284 if (!cmd_fibcontext)
2285 return SCSI_MLQUEUE_HOST_BUSY;
2286
2287 aac_fib_init(cmd_fibcontext);
2288
2289 pmcmd = fib_data(cmd_fibcontext);
2290 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2291 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2292 /* Eject bit ignored, not relevant */
2293 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2294 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2295 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2296 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2297 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2298
2299 /*
2300 * Now send the Fib to the adapter
2301 */
2302 status = aac_fib_send(ContainerCommand,
2303 cmd_fibcontext,
2304 sizeof(struct aac_power_management),
2305 FsaNormal,
2306 0, 1,
2307 (fib_callback)aac_start_stop_callback,
2308 (void *)scsicmd);
2309
2310 /*
2311 * Check that the command queued to the controller
2312 */
2313 if (status == -EINPROGRESS) {
2314 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2315 return 0;
2316 }
2317
2318 aac_fib_complete(cmd_fibcontext);
2319 aac_fib_free(cmd_fibcontext);
2320 return SCSI_MLQUEUE_HOST_BUSY;
2321}
2322
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323/**
2324 * aac_scsi_cmd() - Process SCSI command
2325 * @scsicmd: SCSI command block
2326 *
2327 * Emulate a SCSI command and queue the required request for the
2328 * aacraid firmware.
2329 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002330
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2332{
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002333 u32 cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 struct Scsi_Host *host = scsicmd->device->host;
2335 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2336 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002337
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002338 if (fsa_dev_ptr == NULL)
2339 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 /*
2341 * If the bus, id or lun is out of range, return fail
2342 * Test does not apply to ID 16, the pseudo id for the controller
2343 * itself.
2344 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002345 cid = scmd_id(scsicmd);
2346 if (cid != host->this_id) {
2347 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2348 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08002349 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 scsicmd->result = DID_NO_CONNECT << 16;
2351 scsicmd->scsi_done(scsicmd);
2352 return 0;
2353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
2355 /*
2356 * If the target container doesn't exist, it may have
2357 * been newly created
2358 */
Mark Salyzyn655d7222008-04-30 16:03:42 -04002359 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2360 (fsa_dev_ptr[cid].sense_data.sense_key ==
2361 NOT_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 switch (scsicmd->cmnd[0]) {
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002363 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002364 if (!(dev->raw_io_interface) ||
2365 !(dev->raw_io_64) ||
2366 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2367 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 case INQUIRY:
2369 case READ_CAPACITY:
2370 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002371 if (dev->in_reset)
2372 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07002373 return _aac_probe_container(scsicmd,
2374 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 default:
2376 break;
2377 }
2378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 } else { /* check for physical non-dasd devices */
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08002380 if (dev->nondasd_support || expose_physicals ||
2381 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002382 if (dev->in_reset)
2383 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 return aac_send_srb_fib(scsicmd);
2385 } else {
2386 scsicmd->result = DID_NO_CONNECT << 16;
2387 scsicmd->scsi_done(scsicmd);
2388 return 0;
2389 }
2390 }
2391 }
2392 /*
2393 * else Command for the controller itself
2394 */
2395 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002396 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 {
2398 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2399 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002400 set_sense(&dev->fsa_dev[cid].sense_data,
2401 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2402 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002404 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2405 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 scsicmd->scsi_done(scsicmd);
2407 return 0;
2408 }
2409
2410
2411 /* Handle commands here that don't really require going out to the adapter */
2412 switch (scsicmd->cmnd[0]) {
2413 case INQUIRY:
2414 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002415 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002417 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002418 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Leubner, Achimd8e965072009-04-01 07:16:08 -07002420 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002421 char *arr = (char *)&inq_data;
2422
2423 /* EVPD bit set */
2424 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2425 INQD_PDT_PROC : INQD_PDT_DA;
2426 if (scsicmd->cmnd[2] == 0) {
2427 /* supported vital product data pages */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002428 arr[3] = 3;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002429 arr[4] = 0x0;
2430 arr[5] = 0x80;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002431 arr[6] = 0x83;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002432 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002433 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2434 sizeof(inq_data));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002435 scsicmd->result = DID_OK << 16 |
2436 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2437 } else if (scsicmd->cmnd[2] == 0x80) {
2438 /* unit serial number page */
2439 arr[3] = setinqserial(dev, &arr[4],
2440 scmd_id(scsicmd));
2441 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002442 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2443 sizeof(inq_data));
Leubner, Achimd8e965072009-04-01 07:16:08 -07002444 if (aac_wwn != 2)
2445 return aac_get_container_serial(
2446 scsicmd);
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002447 scsicmd->result = DID_OK << 16 |
2448 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2449 } else if (scsicmd->cmnd[2] == 0x83) {
2450 /* vpd page 0x83 - Device Identification Page */
2451 char *sno = (char *)&inq_data;
2452 sno[3] = setinqserial(dev, &sno[4],
2453 scmd_id(scsicmd));
2454 if (aac_wwn != 2)
2455 return aac_get_container_serial(
2456 scsicmd);
Leubner, Achimd8e965072009-04-01 07:16:08 -07002457 scsicmd->result = DID_OK << 16 |
2458 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002459 } else {
2460 /* vpd page not implemented */
2461 scsicmd->result = DID_OK << 16 |
2462 COMMAND_COMPLETE << 8 |
2463 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002464 set_sense(&dev->fsa_dev[cid].sense_data,
2465 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2466 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002467 memcpy(scsicmd->sense_buffer,
2468 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002469 min_t(size_t,
2470 sizeof(dev->fsa_dev[cid].sense_data),
2471 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002472 }
2473 scsicmd->scsi_done(scsicmd);
2474 return 0;
2475 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002476 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002477 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 */
2478 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002480 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 /*
2482 * Set the Vendor, Product, and Revision Level
2483 * see: <vendor>.c i.e. aac.c
2484 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002485 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07002486 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002487 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002488 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2489 sizeof(inq_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2491 scsicmd->scsi_done(scsicmd);
2492 return 0;
2493 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002494 if (dev->in_reset)
2495 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07002496 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002497 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002498 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002499 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 }
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002501 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002502 if (!(dev->raw_io_interface) ||
2503 !(dev->raw_io_64) ||
2504 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2505 break;
2506 {
2507 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002508 char cp[13];
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002509 unsigned int alloc_len;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002510
2511 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2512 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002513 cp[0] = (capacity >> 56) & 0xff;
2514 cp[1] = (capacity >> 48) & 0xff;
2515 cp[2] = (capacity >> 40) & 0xff;
2516 cp[3] = (capacity >> 32) & 0xff;
2517 cp[4] = (capacity >> 24) & 0xff;
2518 cp[5] = (capacity >> 16) & 0xff;
2519 cp[6] = (capacity >> 8) & 0xff;
2520 cp[7] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002521 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2522 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2523 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2524 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002525 cp[12] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002526
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002527 alloc_len = ((scsicmd->cmnd[10] << 24)
2528 + (scsicmd->cmnd[11] << 16)
2529 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2530
2531 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002532 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002533 if (alloc_len < scsi_bufflen(scsicmd))
2534 scsi_set_resid(scsicmd,
2535 scsi_bufflen(scsicmd) - alloc_len);
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002536
2537 /* Do not cache partition table for arrays */
2538 scsicmd->device->removable = 1;
2539
2540 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2541 scsicmd->scsi_done(scsicmd);
2542
2543 return 0;
2544 }
2545
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 case READ_CAPACITY:
2547 {
2548 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002549 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
2551 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002552 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 capacity = fsa_dev_ptr[cid].size - 1;
2554 else
2555 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002556
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 cp[0] = (capacity >> 24) & 0xff;
2558 cp[1] = (capacity >> 16) & 0xff;
2559 cp[2] = (capacity >> 8) & 0xff;
2560 cp[3] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002561 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2562 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2563 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2564 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002565 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002566 /* Do not cache partition table for arrays */
2567 scsicmd->device->removable = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002568 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2569 SAM_STAT_GOOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 scsicmd->scsi_done(scsicmd);
2571
2572 return 0;
2573 }
2574
2575 case MODE_SENSE:
2576 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002577 int mode_buf_length = 4;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002578 u32 capacity;
2579 aac_modep_data mpd;
2580
2581 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2582 capacity = fsa_dev_ptr[cid].size - 1;
2583 else
2584 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
2586 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002587 memset((char *)&mpd, 0, sizeof(aac_modep_data));
2588
2589 /* Mode data length */
2590 mpd.hd.data_length = sizeof(mpd.hd) - 1;
2591 /* Medium type - default */
2592 mpd.hd.med_type = 0;
2593 /* Device-specific param,
2594 bit 8: 0/1 = write enabled/protected
2595 bit 4: 0/1 = FUA enabled */
2596 mpd.hd.dev_par = 0;
2597
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002598 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002599 mpd.hd.dev_par = 0x10;
2600 if (scsicmd->cmnd[1] & 0x8)
2601 mpd.hd.bd_length = 0; /* Block descriptor length */
2602 else {
2603 mpd.hd.bd_length = sizeof(mpd.bd);
2604 mpd.hd.data_length += mpd.hd.bd_length;
2605 mpd.bd.block_length[0] =
2606 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2607 mpd.bd.block_length[1] =
2608 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2609 mpd.bd.block_length[2] =
2610 fsa_dev_ptr[cid].block_size & 0xff;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002611
2612 mpd.mpc_buf[0] = scsicmd->cmnd[2];
2613 if (scsicmd->cmnd[2] == 0x1C) {
2614 /* page length */
2615 mpd.mpc_buf[1] = 0xa;
2616 /* Mode data length */
2617 mpd.hd.data_length = 23;
2618 } else {
2619 /* Mode data length */
2620 mpd.hd.data_length = 15;
2621 }
2622
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002623 if (capacity > 0xffffff) {
2624 mpd.bd.block_count[0] = 0xff;
2625 mpd.bd.block_count[1] = 0xff;
2626 mpd.bd.block_count[2] = 0xff;
2627 } else {
2628 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
2629 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
2630 mpd.bd.block_count[2] = capacity & 0xff;
2631 }
2632 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002633 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2634 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002635 mpd.hd.data_length += 3;
2636 mpd.mpc_buf[0] = 8;
2637 mpd.mpc_buf[1] = 1;
2638 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002639 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002640 mode_buf_length = sizeof(mpd);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002641 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002642
2643 if (mode_buf_length > scsicmd->cmnd[4])
2644 mode_buf_length = scsicmd->cmnd[4];
2645 else
2646 mode_buf_length = sizeof(mpd);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002647 scsi_sg_copy_from_buffer(scsicmd,
2648 (char *)&mpd,
2649 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2651 scsicmd->scsi_done(scsicmd);
2652
2653 return 0;
2654 }
2655 case MODE_SENSE_10:
2656 {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002657 u32 capacity;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002658 int mode_buf_length = 8;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002659 aac_modep10_data mpd10;
2660
2661 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2662 capacity = fsa_dev_ptr[cid].size - 1;
2663 else
2664 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
2666 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002667 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
2668 /* Mode data length (MSB) */
2669 mpd10.hd.data_length[0] = 0;
2670 /* Mode data length (LSB) */
2671 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
2672 /* Medium type - default */
2673 mpd10.hd.med_type = 0;
2674 /* Device-specific param,
2675 bit 8: 0/1 = write enabled/protected
2676 bit 4: 0/1 = FUA enabled */
2677 mpd10.hd.dev_par = 0;
2678
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002679 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002680 mpd10.hd.dev_par = 0x10;
2681 mpd10.hd.rsrvd[0] = 0; /* reserved */
2682 mpd10.hd.rsrvd[1] = 0; /* reserved */
2683 if (scsicmd->cmnd[1] & 0x8) {
2684 /* Block descriptor length (MSB) */
2685 mpd10.hd.bd_length[0] = 0;
2686 /* Block descriptor length (LSB) */
2687 mpd10.hd.bd_length[1] = 0;
2688 } else {
2689 mpd10.hd.bd_length[0] = 0;
2690 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
2691
2692 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
2693
2694 mpd10.bd.block_length[0] =
2695 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2696 mpd10.bd.block_length[1] =
2697 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2698 mpd10.bd.block_length[2] =
2699 fsa_dev_ptr[cid].block_size & 0xff;
2700
2701 if (capacity > 0xffffff) {
2702 mpd10.bd.block_count[0] = 0xff;
2703 mpd10.bd.block_count[1] = 0xff;
2704 mpd10.bd.block_count[2] = 0xff;
2705 } else {
2706 mpd10.bd.block_count[0] =
2707 (capacity >> 16) & 0xff;
2708 mpd10.bd.block_count[1] =
2709 (capacity >> 8) & 0xff;
2710 mpd10.bd.block_count[2] =
2711 capacity & 0xff;
2712 }
2713 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002714 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2715 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002716 mpd10.hd.data_length[1] += 3;
2717 mpd10.mpc_buf[0] = 8;
2718 mpd10.mpc_buf[1] = 1;
2719 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002720 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002721 mode_buf_length = sizeof(mpd10);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002722 if (mode_buf_length > scsicmd->cmnd[8])
2723 mode_buf_length = scsicmd->cmnd[8];
2724 }
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002725 scsi_sg_copy_from_buffer(scsicmd,
2726 (char *)&mpd10,
2727 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
2729 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2730 scsicmd->scsi_done(scsicmd);
2731
2732 return 0;
2733 }
2734 case REQUEST_SENSE:
2735 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2736 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2737 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2738 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2739 scsicmd->scsi_done(scsicmd);
2740 return 0;
2741
2742 case ALLOW_MEDIUM_REMOVAL:
2743 dprintk((KERN_DEBUG "LOCK command.\n"));
2744 if (scsicmd->cmnd[4])
2745 fsa_dev_ptr[cid].locked = 1;
2746 else
2747 fsa_dev_ptr[cid].locked = 0;
2748
2749 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2750 scsicmd->scsi_done(scsicmd);
2751 return 0;
2752 /*
2753 * These commands are all No-Ops
2754 */
2755 case TEST_UNIT_READY:
Mark Salyzyn655d7222008-04-30 16:03:42 -04002756 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
2757 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2758 SAM_STAT_CHECK_CONDITION;
2759 set_sense(&dev->fsa_dev[cid].sense_data,
2760 NOT_READY, SENCODE_BECOMING_READY,
2761 ASENCODE_BECOMING_READY, 0, 0);
2762 memcpy(scsicmd->sense_buffer,
2763 &dev->fsa_dev[cid].sense_data,
2764 min_t(size_t,
2765 sizeof(dev->fsa_dev[cid].sense_data),
2766 SCSI_SENSE_BUFFERSIZE));
2767 scsicmd->scsi_done(scsicmd);
2768 return 0;
2769 }
2770 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 case RESERVE:
2772 case RELEASE:
2773 case REZERO_UNIT:
2774 case REASSIGN_BLOCKS:
2775 case SEEK_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2777 scsicmd->scsi_done(scsicmd);
2778 return 0;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002779
2780 case START_STOP:
2781 return aac_start_stop(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 }
2783
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002784 switch (scsicmd->cmnd[0])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 {
2786 case READ_6:
2787 case READ_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002788 case READ_12:
2789 case READ_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002790 if (dev->in_reset)
2791 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 /*
2793 * Hack to keep track of ordinal number of the device that
2794 * corresponds to a container. Needed to convert
2795 * containers to /dev/sd device names
2796 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002797
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002798 if (scsicmd->request->rq_disk)
2799 strlcpy(fsa_dev_ptr[cid].devname,
2800 scsicmd->request->rq_disk->disk_name,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002801 min(sizeof(fsa_dev_ptr[cid].devname),
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002802 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002803
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002804 return aac_read(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806 case WRITE_6:
2807 case WRITE_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002808 case WRITE_12:
2809 case WRITE_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002810 if (dev->in_reset)
2811 return -1;
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002812 return aac_write(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
2814 case SYNCHRONIZE_CACHE:
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002815 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2816 scsicmd->result = DID_OK << 16 |
2817 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2818 scsicmd->scsi_done(scsicmd);
2819 return 0;
2820 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 /* Issue FIB to tell Firmware to flush it's cache */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002822 if ((aac_cache & 6) != 2)
2823 return aac_synchronize(scsicmd);
2824 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 default:
2826 /*
2827 * Unhandled commands
2828 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002829 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002831 set_sense(&dev->fsa_dev[cid].sense_data,
2832 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2833 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002835 min_t(size_t,
2836 sizeof(dev->fsa_dev[cid].sense_data),
2837 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 scsicmd->scsi_done(scsicmd);
2839 return 0;
2840 }
2841}
2842
2843static int query_disk(struct aac_dev *dev, void __user *arg)
2844{
2845 struct aac_query_disk qd;
2846 struct fsa_dev_info *fsa_dev_ptr;
2847
2848 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002849 if (!fsa_dev_ptr)
Mark Haverkamp651013552006-09-19 08:59:23 -07002850 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2852 return -EFAULT;
2853 if (qd.cnum == -1)
Mark Haverkampe5718772006-03-27 09:43:25 -08002854 qd.cnum = qd.id;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002855 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 {
2857 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2858 return -EINVAL;
2859 qd.instance = dev->scsi_host_ptr->host_no;
2860 qd.bus = 0;
2861 qd.id = CONTAINER_TO_ID(qd.cnum);
2862 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2863 }
2864 else return -EINVAL;
2865
Salyzyn, Markfd622b12007-07-17 10:59:19 -04002866 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2868 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2869
2870 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2871 qd.unmapped = 1;
2872 else
2873 qd.unmapped = 0;
2874
2875 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2876 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2877
2878 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2879 return -EFAULT;
2880 return 0;
2881}
2882
2883static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2884{
2885 struct aac_delete_disk dd;
2886 struct fsa_dev_info *fsa_dev_ptr;
2887
2888 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp651013552006-09-19 08:59:23 -07002889 if (!fsa_dev_ptr)
2890 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891
2892 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2893 return -EFAULT;
2894
2895 if (dd.cnum >= dev->maximum_num_containers)
2896 return -EINVAL;
2897 /*
2898 * Mark this container as being deleted.
2899 */
2900 fsa_dev_ptr[dd.cnum].deleted = 1;
2901 /*
2902 * Mark the container as no longer valid
2903 */
2904 fsa_dev_ptr[dd.cnum].valid = 0;
2905 return 0;
2906}
2907
2908static int delete_disk(struct aac_dev *dev, void __user *arg)
2909{
2910 struct aac_delete_disk dd;
2911 struct fsa_dev_info *fsa_dev_ptr;
2912
2913 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002914 if (!fsa_dev_ptr)
Mark Haverkamp651013552006-09-19 08:59:23 -07002915 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
2917 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2918 return -EFAULT;
2919
2920 if (dd.cnum >= dev->maximum_num_containers)
2921 return -EINVAL;
2922 /*
2923 * If the container is locked, it can not be deleted by the API.
2924 */
2925 if (fsa_dev_ptr[dd.cnum].locked)
2926 return -EBUSY;
2927 else {
2928 /*
2929 * Mark the container as no longer being valid.
2930 */
2931 fsa_dev_ptr[dd.cnum].valid = 0;
2932 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2933 return 0;
2934 }
2935}
2936
2937int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2938{
2939 switch (cmd) {
2940 case FSACTL_QUERY_DISK:
2941 return query_disk(dev, arg);
2942 case FSACTL_DELETE_DISK:
2943 return delete_disk(dev, arg);
2944 case FSACTL_FORCE_DELETE_DISK:
2945 return force_delete_disk(dev, arg);
2946 case FSACTL_GET_CONTAINERS:
2947 return aac_get_containers(dev);
2948 default:
2949 return -ENOTTY;
2950 }
2951}
2952
2953/**
2954 *
2955 * aac_srb_callback
2956 * @context: the context set in the fib - here it is scsi cmd
2957 * @fibptr: pointer to the fib
2958 *
2959 * Handles the completion of a scsi command to a non dasd device
2960 *
2961 */
2962
2963static void aac_srb_callback(void *context, struct fib * fibptr)
2964{
2965 struct aac_dev *dev;
2966 struct aac_srb_reply *srbreply;
2967 struct scsi_cmnd *scsicmd;
2968
2969 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07002970
2971 if (!aac_valid_context(scsicmd, fibptr))
2972 return;
2973
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002974 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002976 dev = fibptr->dev;
2977
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
2979
2980 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05302982 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
2983 /* fast response */
2984 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
2985 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
2986 } else {
2987 /*
2988 * Calculate resid for sg
2989 */
2990 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2991 - le32_to_cpu(srbreply->data_xfer_length));
2992 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002993
2994 scsi_dma_unmap(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -07002996 /* expose physical device if expose_physicald flag is on */
2997 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
2998 && expose_physicals > 0)
2999 aac_expose_phy_device(scsicmd);
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 /*
3002 * First check the fib status
3003 */
3004
3005 if (le32_to_cpu(srbreply->status) != ST_OK){
3006 int len;
3007 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08003008 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3009 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
3011 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
3012 }
3013
3014 /*
3015 * Next check the srb status
3016 */
3017 switch( (le32_to_cpu(srbreply->srb_status))&0x3f){
3018 case SRB_STATUS_ERROR_RECOVERY:
3019 case SRB_STATUS_PENDING:
3020 case SRB_STATUS_SUCCESS:
Mark Haverkampbb08f922006-02-01 09:30:44 -08003021 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 break;
3023 case SRB_STATUS_DATA_OVERRUN:
3024 switch(scsicmd->cmnd[0]){
3025 case READ_6:
3026 case WRITE_6:
3027 case READ_10:
3028 case WRITE_10:
3029 case READ_12:
3030 case WRITE_12:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003031 case READ_16:
3032 case WRITE_16:
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003033 if (le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
3035 } else {
3036 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
3037 }
3038 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3039 break;
3040 case INQUIRY: {
Mark Haverkampbb08f922006-02-01 09:30:44 -08003041 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 break;
3043 }
3044 default:
3045 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3046 break;
3047 }
3048 break;
3049 case SRB_STATUS_ABORTED:
3050 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3051 break;
3052 case SRB_STATUS_ABORT_FAILED:
3053 // Not sure about this one - but assuming the hba was trying to abort for some reason
3054 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3055 break;
3056 case SRB_STATUS_PARITY_ERROR:
3057 scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8;
3058 break;
3059 case SRB_STATUS_NO_DEVICE:
3060 case SRB_STATUS_INVALID_PATH_ID:
3061 case SRB_STATUS_INVALID_TARGET_ID:
3062 case SRB_STATUS_INVALID_LUN:
3063 case SRB_STATUS_SELECTION_TIMEOUT:
3064 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3065 break;
3066
3067 case SRB_STATUS_COMMAND_TIMEOUT:
3068 case SRB_STATUS_TIMEOUT:
3069 scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8;
3070 break;
3071
3072 case SRB_STATUS_BUSY:
Salyzyn, Mark760af102007-06-19 11:41:21 -04003073 scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 break;
3075
3076 case SRB_STATUS_BUS_RESET:
3077 scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8;
3078 break;
3079
3080 case SRB_STATUS_MESSAGE_REJECTED:
3081 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
3082 break;
3083 case SRB_STATUS_REQUEST_FLUSHED:
3084 case SRB_STATUS_ERROR:
3085 case SRB_STATUS_INVALID_REQUEST:
3086 case SRB_STATUS_REQUEST_SENSE_FAILED:
3087 case SRB_STATUS_NO_HBA:
3088 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3089 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3090 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3091 case SRB_STATUS_DELAYED_RETRY:
3092 case SRB_STATUS_BAD_FUNCTION:
3093 case SRB_STATUS_NOT_STARTED:
3094 case SRB_STATUS_NOT_IN_USE:
3095 case SRB_STATUS_FORCE_ABORT:
3096 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3097 default:
3098#ifdef AAC_DETAILED_STATUS_INFO
3099 printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
3100 le32_to_cpu(srbreply->srb_status) & 0x3F,
3101 aac_get_status_string(
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003102 le32_to_cpu(srbreply->srb_status) & 0x3F),
3103 scsicmd->cmnd[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 le32_to_cpu(srbreply->scsi_status));
3105#endif
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003106 if ((scsicmd->cmnd[0] == ATA_12)
3107 || (scsicmd->cmnd[0] == ATA_16)) {
3108 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3109 scsicmd->result = DID_OK << 16
3110 | COMMAND_COMPLETE << 8;
3111 break;
3112 } else {
3113 scsicmd->result = DID_ERROR << 16
3114 | COMMAND_COMPLETE << 8;
3115 break;
3116 }
3117 } else {
3118 scsicmd->result = DID_ERROR << 16
3119 | COMMAND_COMPLETE << 8;
3120 break;
3121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003123 if (le32_to_cpu(srbreply->scsi_status) == SAM_STAT_CHECK_CONDITION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 int len;
3125 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08003126 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3127 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003129 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
3130 le32_to_cpu(srbreply->status), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131#endif
3132 memcpy(scsicmd->sense_buffer, srbreply->sense_data, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 }
3134 /*
3135 * OR in the scsi status (already shifted up a bit)
3136 */
3137 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3138
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003139 aac_fib_complete(fibptr);
3140 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07003141 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142}
3143
3144/**
3145 *
3146 * aac_send_scb_fib
3147 * @scsicmd: the scsi command block
3148 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003149 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 * scsicmd passed in.
3151 */
3152
3153static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3154{
3155 struct fib* cmd_fibcontext;
3156 struct aac_dev* dev;
3157 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158
Mark Haverkamp84971732005-06-20 11:55:24 -07003159 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08003160 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07003161 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 scsicmd->result = DID_NO_CONNECT << 16;
3163 scsicmd->scsi_done(scsicmd);
3164 return 0;
3165 }
3166
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 /*
3168 * Allocate and initialize a Fib then setup a BlockWrite command
3169 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003170 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 return -1;
3172 }
Mark Haverkampe8f32de2007-01-23 15:00:30 -08003173 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 /*
3176 * Check that the command queued to the controller
3177 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08003178 if (status == -EINPROGRESS) {
3179 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 return 0;
3181 }
3182
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003183 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3184 aac_fib_complete(cmd_fibcontext);
3185 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186
3187 return -1;
3188}
3189
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303190static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191{
3192 struct aac_dev *dev;
3193 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003194 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
3196 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3197 // Get rid of old data
3198 psg->count = 0;
3199 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003200 psg->sg[0].count = 0;
3201
3202 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303203 if (nseg < 0)
3204 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003205 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 struct scatterlist *sg;
3207 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003209 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003211 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3213 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3214 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 }
3216 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003217 if (byte_count > scsi_bufflen(scsicmd)) {
3218 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3219 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003220 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003221 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 }
3223 /* Check for command underflow */
3224 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3225 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3226 byte_count, scsicmd->underflow);
3227 }
3228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 return byte_count;
3230}
3231
3232
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303233static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234{
3235 struct aac_dev *dev;
3236 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003237 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003238 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239
3240 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3241 // Get rid of old data
3242 psg->count = 0;
3243 psg->sg[0].addr[0] = 0;
3244 psg->sg[0].addr[1] = 0;
3245 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003246
3247 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303248 if (nseg < 0)
3249 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003250 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 struct scatterlist *sg;
3252 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003254 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp1241f352006-03-27 09:44:23 -08003255 int count = sg_dma_len(sg);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003256 addr = sg_dma_address(sg);
3257 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3258 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
Mark Haverkamp1241f352006-03-27 09:44:23 -08003259 psg->sg[i].count = cpu_to_le32(count);
3260 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003262 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003264 if (byte_count > scsi_bufflen(scsicmd)) {
3265 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3266 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003267 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003268 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 }
3270 /* Check for command underflow */
3271 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3272 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3273 byte_count, scsicmd->underflow);
3274 }
3275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 return byte_count;
3277}
3278
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303279static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003280{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003281 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003282 int nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003283
3284 // Get rid of old data
3285 psg->count = 0;
3286 psg->sg[0].next = 0;
3287 psg->sg[0].prev = 0;
3288 psg->sg[0].addr[0] = 0;
3289 psg->sg[0].addr[1] = 0;
3290 psg->sg[0].count = 0;
3291 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003292
3293 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303294 if (nseg < 0)
3295 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003296 if (nseg) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003297 struct scatterlist *sg;
3298 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003299
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003300 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003301 int count = sg_dma_len(sg);
3302 u64 addr = sg_dma_address(sg);
3303 psg->sg[i].next = 0;
3304 psg->sg[i].prev = 0;
3305 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
3306 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
3307 psg->sg[i].count = cpu_to_le32(count);
3308 psg->sg[i].flags = 0;
3309 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003310 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003311 psg->count = cpu_to_le32(nseg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003312 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003313 if (byte_count > scsi_bufflen(scsicmd)) {
3314 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3315 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003316 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003317 byte_count = scsi_bufflen(scsicmd);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003318 }
3319 /* Check for command underflow */
3320 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3321 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3322 byte_count, scsicmd->underflow);
3323 }
3324 }
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003325 return byte_count;
3326}
3327
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303328static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
3329 struct aac_raw_io2 *rio2, int sg_max)
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303330{
3331 unsigned long byte_count = 0;
3332 int nseg;
3333
3334 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303335 if (nseg < 0)
3336 return nseg;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303337 if (nseg) {
3338 struct scatterlist *sg;
3339 int i, conformable = 0;
3340 u32 min_size = PAGE_SIZE, cur_size;
3341
3342 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3343 int count = sg_dma_len(sg);
3344 u64 addr = sg_dma_address(sg);
3345
3346 BUG_ON(i >= sg_max);
3347 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3348 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3349 cur_size = cpu_to_le32(count);
3350 rio2->sge[i].length = cur_size;
3351 rio2->sge[i].flags = 0;
3352 if (i == 0) {
3353 conformable = 1;
3354 rio2->sgeFirstSize = cur_size;
3355 } else if (i == 1) {
3356 rio2->sgeNominalSize = cur_size;
3357 min_size = cur_size;
3358 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3359 conformable = 0;
3360 if (cur_size < min_size)
3361 min_size = cur_size;
3362 }
3363 byte_count += count;
3364 }
3365
3366 /* hba wants the size to be exact */
3367 if (byte_count > scsi_bufflen(scsicmd)) {
3368 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3369 (byte_count - scsi_bufflen(scsicmd));
3370 rio2->sge[i-1].length = cpu_to_le32(temp);
3371 byte_count = scsi_bufflen(scsicmd);
3372 }
3373
3374 rio2->sgeCnt = cpu_to_le32(nseg);
3375 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3376 /* not conformable: evaluate required sg elements */
3377 if (!conformable) {
3378 int j, nseg_new = nseg, err_found;
3379 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3380 err_found = 0;
3381 nseg_new = 2;
3382 for (j = 1; j < nseg - 1; ++j) {
3383 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3384 err_found = 1;
3385 break;
3386 }
3387 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3388 }
3389 if (!err_found)
3390 break;
3391 }
3392 if (i > 0 && nseg_new <= sg_max)
3393 aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3394 } else
3395 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3396
3397 /* Check for command underflow */
3398 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3399 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3400 byte_count, scsicmd->underflow);
3401 }
3402 }
3403
3404 return byte_count;
3405}
3406
3407static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3408{
3409 struct sge_ieee1212 *sge;
3410 int i, j, pos;
3411 u32 addr_low;
3412
3413 if (aac_convert_sgl == 0)
3414 return 0;
3415
3416 sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
3417 if (sge == NULL)
3418 return -1;
3419
3420 for (i = 1, pos = 1; i < nseg-1; ++i) {
3421 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
3422 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
3423 sge[pos].addrLow = addr_low;
3424 sge[pos].addrHigh = rio2->sge[i].addrHigh;
3425 if (addr_low < rio2->sge[i].addrLow)
3426 sge[pos].addrHigh++;
3427 sge[pos].length = pages * PAGE_SIZE;
3428 sge[pos].flags = 0;
3429 pos++;
3430 }
3431 }
3432 sge[pos] = rio2->sge[nseg-1];
3433 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
3434
3435 kfree(sge);
3436 rio2->sgeCnt = cpu_to_le32(nseg_new);
3437 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3438 rio2->sgeNominalSize = pages * PAGE_SIZE;
3439 return 0;
3440}
3441
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442#ifdef AAC_DETAILED_STATUS_INFO
3443
3444struct aac_srb_status_info {
3445 u32 status;
3446 char *str;
3447};
3448
3449
3450static struct aac_srb_status_info srb_status_info[] = {
3451 { SRB_STATUS_PENDING, "Pending Status"},
3452 { SRB_STATUS_SUCCESS, "Success"},
3453 { SRB_STATUS_ABORTED, "Aborted Command"},
3454 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07003455 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 { SRB_STATUS_BUSY, "Device Busy"},
3457 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
3458 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
3459 { SRB_STATUS_NO_DEVICE, "No Device"},
3460 { SRB_STATUS_TIMEOUT, "Timeout"},
3461 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
3462 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
3463 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
3464 { SRB_STATUS_BUS_RESET, "Bus Reset"},
3465 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
3466 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
3467 { SRB_STATUS_NO_HBA, "No HBA"},
3468 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
3469 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
3470 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
3471 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
3472 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
3473 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07003474 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
3476 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
3477 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
3478 { SRB_STATUS_NOT_STARTED, "Not Started"},
3479 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003480 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
3482 { 0xff, "Unknown Error"}
3483};
3484
3485char *aac_get_status_string(u32 status)
3486{
3487 int i;
3488
Tobias Klauser6391a112006-06-08 22:23:48 -07003489 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
3490 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
3493 return "Bad Status Code";
3494}
3495
3496#endif