blob: e4c243748a97f97d2fa16b1b2ee6622e83b3905e [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."
Mahesh Rajashekhara9022d372015-08-28 06:38:35 -0400262 " 0=PIC(default), 1=MSI, 2=MSI-X)");
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 Haverkampe37ee4be2007-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);
Mahesh Rajashekharaa7129a52015-03-26 10:41:27 -0400465 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
466 AAC_OPTION_SUPPORTED_240_VOLUMES) {
467 maximum_num_containers =
468 le32_to_cpu(dresp->MaxSimpleVolumes);
469 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800470 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530472 /* FIB should be freed only after getting the response from the F/W */
473 if (status != -ERESTARTSYS)
474 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
477 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400478 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700479 GFP_KERNEL);
480 if (!fsa_dev_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 dev->fsa_dev = fsa_dev_ptr;
484 dev->maximum_num_containers = maximum_num_containers;
485
Mark Haverkampfe76df42007-03-15 12:55:07 -0700486 for (index = 0; index < dev->maximum_num_containers; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 fsa_dev_ptr[index].devname[0] = '\0';
488
Mark Haverkampfe76df42007-03-15 12:55:07 -0700489 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Mark Haverkampfe76df42007-03-15 12:55:07 -0700491 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
493 break;
494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 /*
497 * If there are no more containers, then stop asking.
498 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700499 if (++index >= status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 return status;
503}
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505static void get_container_name_callback(void *context, struct fib * fibptr)
506{
507 struct aac_get_name_resp * get_name_reply;
508 struct scsi_cmnd * scsicmd;
509
510 scsicmd = (struct scsi_cmnd *) context;
511
Mark Haverkamp03d44332007-03-15 10:27:45 -0700512 if (!aac_valid_context(scsicmd, fibptr))
513 return;
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700516 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
519 /* Failure is irrelevant, using default value instead */
520 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
521 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700522 char *sp = get_name_reply->data;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400523 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 while (*sp == ' ')
525 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700526 if (*sp) {
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900527 struct inquiry_data inq;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700528 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
529 int count = sizeof(d);
530 char *dp = d;
531 do {
532 *dp++ = (*sp) ? *sp++ : ' ';
533 } while (--count > 0);
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900534
535 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
536 memcpy(inq.inqd_pid, d, sizeof(d));
537 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
542
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800543 aac_fib_complete(fibptr);
544 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700545 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
548/**
549 * aac_get_container_name - get container name, none blocking.
550 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700551static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552{
553 int status;
554 struct aac_get_name *dinfo;
555 struct fib * cmd_fibcontext;
556 struct aac_dev * dev;
557
558 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
559
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800560 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 return -ENOMEM;
562
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800563 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
565
566 dinfo->command = cpu_to_le32(VM_ContainerConfig);
567 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700568 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
570
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800571 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800572 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -0400573 sizeof(struct aac_get_name_resp),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800574 FsaNormal,
575 0, 1,
576 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 /*
580 * Check that the command queued to the controller
581 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800582 if (status == -EINPROGRESS) {
583 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800585 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800586
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800587 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
588 aac_fib_complete(cmd_fibcontext);
589 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return -1;
591}
592
Mark Haverkampfe76df42007-03-15 12:55:07 -0700593static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
594{
595 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
596
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400597 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700598 return aac_scsi_cmd(scsicmd);
599
600 scsicmd->result = DID_NO_CONNECT << 16;
601 scsicmd->scsi_done(scsicmd);
602 return 0;
603}
604
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400605static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700606{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700607 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700608 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700609 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
610
Mark Haverkamp03d44332007-03-15 10:27:45 -0700611
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400612 if (!aac_valid_context(scsicmd, fibptr))
613 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700614
615 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400616 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700617 if (fsa_dev_ptr) {
618 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
619 fsa_dev_ptr += scmd_id(scsicmd);
620
621 if ((le32_to_cpu(dresp->status) == ST_OK) &&
622 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
623 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400624 if (!(fibptr->dev->supplement_adapter_info.SupportedOptions2 &
625 AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
626 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
627 fsa_dev_ptr->block_size = 0x200;
628 } else {
629 fsa_dev_ptr->block_size =
630 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
631 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700632 fsa_dev_ptr->valid = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -0400633 /* sense_key holds the current state of the spin-up */
634 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
635 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
636 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
637 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700638 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
639 fsa_dev_ptr->size
640 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
641 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
642 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
643 }
644 if ((fsa_dev_ptr->valid & 1) == 0)
645 fsa_dev_ptr->valid = 0;
646 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
647 }
648 aac_fib_complete(fibptr);
649 aac_fib_free(fibptr);
650 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
651 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400652 (*callback)(scsicmd);
653 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700654}
655
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400656static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700657{
658 struct scsi_cmnd * scsicmd;
659 struct aac_mount * dresp;
660 struct aac_query_mount *dinfo;
661 int status;
662
663 dresp = (struct aac_mount *) fib_data(fibptr);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400664 if (!(fibptr->dev->supplement_adapter_info.SupportedOptions2 &
665 AAC_OPTION_VARIABLE_BLOCK_SIZE))
666 dresp->mnt[0].capacityhigh = 0;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700667 if ((le32_to_cpu(dresp->status) != ST_OK) ||
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400668 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
669 _aac_probe_container2(context, fibptr);
670 return;
671 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700672 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700673
Mark Haverkamp03d44332007-03-15 10:27:45 -0700674 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400675 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700676
Mark Haverkampfe76df42007-03-15 12:55:07 -0700677 aac_fib_init(fibptr);
678
679 dinfo = (struct aac_query_mount *)fib_data(fibptr);
680
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400681 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
682 AAC_OPTION_VARIABLE_BLOCK_SIZE)
683 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
684 else
685 dinfo->command = cpu_to_le32(VM_NameServe64);
686
Mark Haverkampfe76df42007-03-15 12:55:07 -0700687 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
688 dinfo->type = cpu_to_le32(FT_FILESYS);
689
690 status = aac_fib_send(ContainerCommand,
691 fibptr,
692 sizeof(struct aac_query_mount),
693 FsaNormal,
694 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400695 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700696 (void *) scsicmd);
697 /*
698 * Check that the command queued to the controller
699 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400700 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700701 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400702 else if (status < 0) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700703 /* Inherit results from VM_NameServe, if any */
704 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400705 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700706 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700707}
708
709static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
710{
711 struct fib * fibptr;
712 int status = -ENOMEM;
713
714 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
715 struct aac_query_mount *dinfo;
716
717 aac_fib_init(fibptr);
718
719 dinfo = (struct aac_query_mount *)fib_data(fibptr);
720
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400721 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
722 AAC_OPTION_VARIABLE_BLOCK_SIZE)
723 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
724 else
725 dinfo->command = cpu_to_le32(VM_NameServe);
726
Mark Haverkampfe76df42007-03-15 12:55:07 -0700727 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
728 dinfo->type = cpu_to_le32(FT_FILESYS);
729 scsicmd->SCp.ptr = (char *)callback;
730
731 status = aac_fib_send(ContainerCommand,
732 fibptr,
733 sizeof(struct aac_query_mount),
734 FsaNormal,
735 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400736 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700737 (void *) scsicmd);
738 /*
739 * Check that the command queued to the controller
740 */
741 if (status == -EINPROGRESS) {
742 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
743 return 0;
744 }
745 if (status < 0) {
746 scsicmd->SCp.ptr = NULL;
747 aac_fib_complete(fibptr);
748 aac_fib_free(fibptr);
749 }
750 }
751 if (status < 0) {
752 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
753 if (fsa_dev_ptr) {
754 fsa_dev_ptr += scmd_id(scsicmd);
755 if ((fsa_dev_ptr->valid & 1) == 0) {
756 fsa_dev_ptr->valid = 0;
757 return (*callback)(scsicmd);
758 }
759 }
760 }
761 return status;
762}
763
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800765 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 * @dev: device to query
767 * @cid: container identifier
768 *
769 * Queries the controller about the given volume. The volume information
770 * is updated in the struct fsa_dev_info structure rather than returned.
771 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700772static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
773{
774 scsicmd->device = NULL;
775 return 0;
776}
777
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800778int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700780 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
781 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Mark Haverkampfe76df42007-03-15 12:55:07 -0700784 if (!scsicmd || !scsidev) {
785 kfree(scsicmd);
786 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700787 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700789 scsicmd->list.next = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400790 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Mark Haverkampfe76df42007-03-15 12:55:07 -0700792 scsicmd->device = scsidev;
793 scsidev->sdev_state = 0;
794 scsidev->id = cid;
795 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Mark Haverkampfe76df42007-03-15 12:55:07 -0700797 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
798 while (scsicmd->device == scsidev)
799 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400800 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700801 status = scsicmd->SCp.Status;
802 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return status;
804}
805
806/* Local Structure to set SCSI inquiry data strings */
807struct scsi_inq {
808 char vid[8]; /* Vendor ID */
809 char pid[16]; /* Product ID */
810 char prl[4]; /* Product Revision Level */
811};
812
813/**
814 * InqStrCopy - string merge
815 * @a: string to copy from
816 * @b: string to copy to
817 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800818 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 * without copying \0
820 */
821
822static void inqstrcpy(char *a, char *b)
823{
824
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800825 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 *b++ = *a++;
827}
828
829static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800830 "None",
831 "Volume",
832 "Mirror",
833 "Stripe",
834 "RAID5",
835 "SSRW",
836 "SSRO",
837 "Morph",
838 "Legacy",
839 "RAID4",
840 "RAID10",
841 "RAID00",
842 "V-MIRRORS",
843 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700845 "RAID5D",
846 "RAID5D0",
847 "RAID1E",
848 "RAID6",
849 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800850 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851};
852
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800853char * get_container_type(unsigned tindex)
854{
855 if (tindex >= ARRAY_SIZE(container_types))
856 tindex = ARRAY_SIZE(container_types) - 1;
857 return container_types[tindex];
858}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860/* Function: setinqstr
861 *
862 * Arguments: [1] pointer to void [1] int
863 *
864 * Purpose: Sets SCSI inquiry data strings for vendor, product
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300865 * and revision level. Allows strings to be set in platform dependent
866 * files instead of in OS dependent driver source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 */
868
Mark Haverkamp794d0602005-10-24 10:51:53 -0700869static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
871 struct scsi_inq *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700874 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Mark Haverkamp794d0602005-10-24 10:51:53 -0700876 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
877 char * cp = dev->supplement_adapter_info.AdapterTypeText;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800878 int c;
879 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
880 inqstrcpy("SMC", str->vid);
881 else {
882 c = sizeof(str->vid);
883 while (*cp && *cp != ' ' && --c)
884 ++cp;
885 c = *cp;
886 *cp = '\0';
887 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
888 str->vid);
889 *cp = c;
890 while (*cp && *cp != ' ')
891 ++cp;
892 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700893 while (*cp == ' ')
894 ++cp;
895 /* last six chars reserved for vol type */
896 c = 0;
897 if (strlen(cp) > sizeof(str->pid)) {
898 c = cp[sizeof(str->pid)];
899 cp[sizeof(str->pid)] = '\0';
900 }
901 inqstrcpy (cp, str->pid);
902 if (c)
903 cp[sizeof(str->pid)] = c;
904 } else {
905 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700906
907 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700908 /* last six chars reserved for vol type */
909 inqstrcpy (mp->model, str->pid);
910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Tobias Klauser6391a112006-06-08 22:23:48 -0700912 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 char *findit = str->pid;
914
915 for ( ; *findit != ' '; findit++); /* walk till we find a space */
916 /* RAID is superfluous in the context of a RAID device */
917 if (memcmp(findit-4, "RAID", 4) == 0)
918 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700919 if (((findit - str->pid) + strlen(container_types[tindex]))
920 < (sizeof(str->pid) + sizeof(str->prl)))
921 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
923 inqstrcpy ("V1.0", str->prl);
924}
925
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400926static void get_container_serial_callback(void *context, struct fib * fibptr)
927{
928 struct aac_get_serial_resp * get_serial_reply;
929 struct scsi_cmnd * scsicmd;
930
931 BUG_ON(fibptr == NULL);
932
933 scsicmd = (struct scsi_cmnd *) context;
934 if (!aac_valid_context(scsicmd, fibptr))
935 return;
936
937 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
938 /* Failure is irrelevant, using default value instead */
939 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400940 /*Check to see if it's for VPD 0x83 or 0x80 */
941 if (scsicmd->cmnd[2] == 0x83) {
942 /* vpd page 0x83 - Device Identification Page */
943 int i;
944 TVPD_Page83 VPDPage83Data;
945
946 memset(((u8 *)&VPDPage83Data), 0,
947 sizeof(VPDPage83Data));
948
949 /* DIRECT_ACCESS_DEVIC */
950 VPDPage83Data.DeviceType = 0;
951 /* DEVICE_CONNECTED */
952 VPDPage83Data.DeviceTypeQualifier = 0;
953 /* VPD_DEVICE_IDENTIFIERS */
954 VPDPage83Data.PageCode = 0x83;
955 VPDPage83Data.Reserved = 0;
956 VPDPage83Data.PageLength =
957 sizeof(VPDPage83Data.IdDescriptorType1) +
958 sizeof(VPDPage83Data.IdDescriptorType2);
959
960 /* T10 Vendor Identifier Field Format */
961 /* VpdCodeSetAscii */
962 VPDPage83Data.IdDescriptorType1.CodeSet = 2;
963 /* VpdIdentifierTypeVendorId */
964 VPDPage83Data.IdDescriptorType1.IdentifierType = 1;
965 VPDPage83Data.IdDescriptorType1.IdentifierLength =
966 sizeof(VPDPage83Data.IdDescriptorType1) - 4;
967
968 /* "ADAPTEC " for adaptec */
969 memcpy(VPDPage83Data.IdDescriptorType1.VendId,
970 "ADAPTEC ",
971 sizeof(VPDPage83Data.IdDescriptorType1.VendId));
972 memcpy(VPDPage83Data.IdDescriptorType1.ProductId,
973 "ARRAY ",
974 sizeof(
975 VPDPage83Data.IdDescriptorType1.ProductId));
976
977 /* Convert to ascii based serial number.
978 * The LSB is the the end.
979 */
980 for (i = 0; i < 8; i++) {
981 u8 temp =
982 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
983 if (temp > 0x9) {
984 VPDPage83Data.IdDescriptorType1.SerialNumber[i] =
985 'A' + (temp - 0xA);
986 } else {
987 VPDPage83Data.IdDescriptorType1.SerialNumber[i] =
988 '0' + temp;
989 }
990 }
991
992 /* VpdCodeSetBinary */
993 VPDPage83Data.IdDescriptorType2.CodeSet = 1;
994 /* VpdIdentifierTypeEUI64 */
995 VPDPage83Data.IdDescriptorType2.IdentifierType = 2;
996 VPDPage83Data.IdDescriptorType2.IdentifierLength =
997 sizeof(VPDPage83Data.IdDescriptorType2) - 4;
998
999 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[0] = 0xD0;
1000 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[1] = 0;
1001 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[2] = 0;
1002
1003 VPDPage83Data.IdDescriptorType2.EU64Id.Serial =
1004 get_serial_reply->uid;
1005 VPDPage83Data.IdDescriptorType2.EU64Id.Reserved = 0;
1006
1007 /* Move the inquiry data to the response buffer. */
1008 scsi_sg_copy_from_buffer(scsicmd, &VPDPage83Data,
1009 sizeof(VPDPage83Data));
1010 } else {
1011 /* It must be for VPD 0x80 */
1012 char sp[13];
1013 /* EVPD bit set */
1014 sp[0] = INQD_PDT_DA;
1015 sp[1] = scsicmd->cmnd[2];
1016 sp[2] = 0;
1017 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1018 le32_to_cpu(get_serial_reply->uid));
1019 scsi_sg_copy_from_buffer(scsicmd, sp,
1020 sizeof(sp));
1021 }
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001022 }
1023
1024 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1025
1026 aac_fib_complete(fibptr);
1027 aac_fib_free(fibptr);
1028 scsicmd->scsi_done(scsicmd);
1029}
1030
1031/**
1032 * aac_get_container_serial - get container serial, none blocking.
1033 */
1034static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1035{
1036 int status;
1037 struct aac_get_serial *dinfo;
1038 struct fib * cmd_fibcontext;
1039 struct aac_dev * dev;
1040
1041 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1042
1043 if (!(cmd_fibcontext = aac_fib_alloc(dev)))
1044 return -ENOMEM;
1045
1046 aac_fib_init(cmd_fibcontext);
1047 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1048
1049 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1050 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1051 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1052
1053 status = aac_fib_send(ContainerCommand,
1054 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -04001055 sizeof(struct aac_get_serial_resp),
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001056 FsaNormal,
1057 0, 1,
1058 (fib_callback) get_container_serial_callback,
1059 (void *) scsicmd);
1060
1061 /*
1062 * Check that the command queued to the controller
1063 */
1064 if (status == -EINPROGRESS) {
1065 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1066 return 0;
1067 }
1068
1069 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1070 aac_fib_complete(cmd_fibcontext);
1071 aac_fib_free(cmd_fibcontext);
1072 return -1;
1073}
1074
1075/* Function: setinqserial
1076 *
1077 * Arguments: [1] pointer to void [1] int
1078 *
1079 * Purpose: Sets SCSI Unit Serial number.
1080 * This is a fake. We should read a proper
1081 * serial number from the container. <SuSE>But
1082 * without docs it's quite hard to do it :-)
1083 * So this will have to do in the meantime.</SuSE>
1084 */
1085
1086static int setinqserial(struct aac_dev *dev, void *data, int cid)
1087{
1088 /*
1089 * This breaks array migration.
1090 */
1091 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1092 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1093}
1094
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001095static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1096 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001098 u8 *sense_buf = (u8 *)sense_data;
1099 /* Sense data valid, err code 70h */
1100 sense_buf[0] = 0x70; /* No info field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 sense_buf[1] = 0; /* Segment number, always zero */
1102
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001103 sense_buf[2] = sense_key; /* Sense key */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
1105 sense_buf[12] = sense_code; /* Additional sense code */
1106 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 if (sense_key == ILLEGAL_REQUEST) {
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001109 sense_buf[7] = 10; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001111 sense_buf[15] = bit_pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 /* Illegal parameter is in the parameter block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 if (sense_code == SENCODE_INVALID_CDB_FIELD)
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001114 sense_buf[15] |= 0xc0;/* Std sense key specific field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 /* Illegal parameter is in the CDB block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 sense_buf[16] = field_pointer >> 8; /* MSB */
1117 sense_buf[17] = field_pointer; /* LSB */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001118 } else
1119 sense_buf[7] = 6; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001122static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1123{
1124 if (lba & 0xffffffff00000000LL) {
1125 int cid = scmd_id(cmd);
1126 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1127 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1128 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001129 set_sense(&dev->fsa_dev[cid].sense_data,
1130 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1131 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001132 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001133 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1134 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001135 cmd->scsi_done(cmd);
1136 return 1;
1137 }
1138 return 0;
1139}
1140
1141static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1142{
1143 return 0;
1144}
1145
1146static void io_callback(void *context, struct fib * fibptr);
1147
1148static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1149{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301150 struct aac_dev *dev = fib->dev;
1151 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301152 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001153
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301154 aac_fib_init(fib);
1155 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1156 struct aac_raw_io2 *readcmd2;
1157 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1158 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1159 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1160 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001161 readcmd2->byteCount = cpu_to_le32(count *
1162 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301163 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1164 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301165 ret = aac_build_sgraw2(cmd, readcmd2,
1166 dev->scsi_host_ptr->sg_tablesize);
1167 if (ret < 0)
1168 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301169 command = ContainerRawIo2;
1170 fibsize = sizeof(struct aac_raw_io2) +
1171 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1172 } else {
1173 struct aac_raw_io *readcmd;
1174 readcmd = (struct aac_raw_io *) fib_data(fib);
1175 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1176 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001177 readcmd->count = cpu_to_le32(count *
1178 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301179 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1180 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1181 readcmd->bpTotal = 0;
1182 readcmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301183 ret = aac_build_sgraw(cmd, &readcmd->sg);
1184 if (ret < 0)
1185 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301186 command = ContainerRawIo;
1187 fibsize = sizeof(struct aac_raw_io) +
1188 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1189 }
1190
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001191 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1192 /*
1193 * Now send the Fib to the adapter
1194 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301195 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001196 fib,
1197 fibsize,
1198 FsaNormal,
1199 0, 1,
1200 (fib_callback) io_callback,
1201 (void *) cmd);
1202}
1203
1204static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1205{
1206 u16 fibsize;
1207 struct aac_read64 *readcmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301208 long ret;
1209
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001210 aac_fib_init(fib);
1211 readcmd = (struct aac_read64 *) fib_data(fib);
1212 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1213 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1214 readcmd->sector_count = cpu_to_le16(count);
1215 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1216 readcmd->pad = 0;
1217 readcmd->flags = 0;
1218
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301219 ret = aac_build_sg64(cmd, &readcmd->sg);
1220 if (ret < 0)
1221 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001222 fibsize = sizeof(struct aac_read64) +
1223 ((le32_to_cpu(readcmd->sg.count) - 1) *
1224 sizeof (struct sgentry64));
1225 BUG_ON (fibsize > (fib->dev->max_fib_size -
1226 sizeof(struct aac_fibhdr)));
1227 /*
1228 * Now send the Fib to the adapter
1229 */
1230 return aac_fib_send(ContainerCommand64,
1231 fib,
1232 fibsize,
1233 FsaNormal,
1234 0, 1,
1235 (fib_callback) io_callback,
1236 (void *) cmd);
1237}
1238
1239static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1240{
1241 u16 fibsize;
1242 struct aac_read *readcmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001243 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301244 long ret;
1245
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001246 aac_fib_init(fib);
1247 readcmd = (struct aac_read *) fib_data(fib);
1248 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001249 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001250 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001251 readcmd->count = cpu_to_le32(count *
1252 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001253
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301254 ret = aac_build_sg(cmd, &readcmd->sg);
1255 if (ret < 0)
1256 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001257 fibsize = sizeof(struct aac_read) +
1258 ((le32_to_cpu(readcmd->sg.count) - 1) *
1259 sizeof (struct sgentry));
1260 BUG_ON (fibsize > (fib->dev->max_fib_size -
1261 sizeof(struct aac_fibhdr)));
1262 /*
1263 * Now send the Fib to the adapter
1264 */
1265 return aac_fib_send(ContainerCommand,
1266 fib,
1267 fibsize,
1268 FsaNormal,
1269 0, 1,
1270 (fib_callback) io_callback,
1271 (void *) cmd);
1272}
1273
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001274static 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 -08001275{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301276 struct aac_dev *dev = fib->dev;
1277 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301278 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001279
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301280 aac_fib_init(fib);
1281 if (dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 && !dev->sync_mode) {
1282 struct aac_raw_io2 *writecmd2;
1283 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1284 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1285 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1286 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001287 writecmd2->byteCount = cpu_to_le32(count *
1288 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301289 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1290 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1291 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1292 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1293 cpu_to_le16(RIO2_IO_TYPE_WRITE);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301294 ret = aac_build_sgraw2(cmd, writecmd2,
1295 dev->scsi_host_ptr->sg_tablesize);
1296 if (ret < 0)
1297 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301298 command = ContainerRawIo2;
1299 fibsize = sizeof(struct aac_raw_io2) +
1300 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1301 } else {
1302 struct aac_raw_io *writecmd;
1303 writecmd = (struct aac_raw_io *) fib_data(fib);
1304 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1305 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001306 writecmd->count = cpu_to_le32(count *
1307 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301308 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1309 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1310 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1311 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1312 cpu_to_le16(RIO_TYPE_WRITE);
1313 writecmd->bpTotal = 0;
1314 writecmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301315 ret = aac_build_sgraw(cmd, &writecmd->sg);
1316 if (ret < 0)
1317 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301318 command = ContainerRawIo;
1319 fibsize = sizeof(struct aac_raw_io) +
1320 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1321 }
1322
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001323 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1324 /*
1325 * Now send the Fib to the adapter
1326 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301327 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001328 fib,
1329 fibsize,
1330 FsaNormal,
1331 0, 1,
1332 (fib_callback) io_callback,
1333 (void *) cmd);
1334}
1335
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001336static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001337{
1338 u16 fibsize;
1339 struct aac_write64 *writecmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301340 long ret;
1341
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001342 aac_fib_init(fib);
1343 writecmd = (struct aac_write64 *) fib_data(fib);
1344 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1345 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1346 writecmd->sector_count = cpu_to_le16(count);
1347 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1348 writecmd->pad = 0;
1349 writecmd->flags = 0;
1350
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301351 ret = aac_build_sg64(cmd, &writecmd->sg);
1352 if (ret < 0)
1353 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001354 fibsize = sizeof(struct aac_write64) +
1355 ((le32_to_cpu(writecmd->sg.count) - 1) *
1356 sizeof (struct sgentry64));
1357 BUG_ON (fibsize > (fib->dev->max_fib_size -
1358 sizeof(struct aac_fibhdr)));
1359 /*
1360 * Now send the Fib to the adapter
1361 */
1362 return aac_fib_send(ContainerCommand64,
1363 fib,
1364 fibsize,
1365 FsaNormal,
1366 0, 1,
1367 (fib_callback) io_callback,
1368 (void *) cmd);
1369}
1370
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001371static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001372{
1373 u16 fibsize;
1374 struct aac_write *writecmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001375 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301376 long ret;
1377
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001378 aac_fib_init(fib);
1379 writecmd = (struct aac_write *) fib_data(fib);
1380 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001381 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001382 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001383 writecmd->count = cpu_to_le32(count *
1384 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001385 writecmd->sg.count = cpu_to_le32(1);
1386 /* ->stable is not used - it did mean which type of write */
1387
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301388 ret = aac_build_sg(cmd, &writecmd->sg);
1389 if (ret < 0)
1390 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001391 fibsize = sizeof(struct aac_write) +
1392 ((le32_to_cpu(writecmd->sg.count) - 1) *
1393 sizeof (struct sgentry));
1394 BUG_ON (fibsize > (fib->dev->max_fib_size -
1395 sizeof(struct aac_fibhdr)));
1396 /*
1397 * Now send the Fib to the adapter
1398 */
1399 return aac_fib_send(ContainerCommand,
1400 fib,
1401 fibsize,
1402 FsaNormal,
1403 0, 1,
1404 (fib_callback) io_callback,
1405 (void *) cmd);
1406}
1407
1408static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1409{
1410 struct aac_srb * srbcmd;
1411 u32 flag;
1412 u32 timeout;
1413
1414 aac_fib_init(fib);
1415 switch(cmd->sc_data_direction){
1416 case DMA_TO_DEVICE:
1417 flag = SRB_DataOut;
1418 break;
1419 case DMA_BIDIRECTIONAL:
1420 flag = SRB_DataIn | SRB_DataOut;
1421 break;
1422 case DMA_FROM_DEVICE:
1423 flag = SRB_DataIn;
1424 break;
1425 case DMA_NONE:
1426 default: /* shuts up some versions of gcc */
1427 flag = SRB_NoDataXfer;
1428 break;
1429 }
1430
1431 srbcmd = (struct aac_srb*) fib_data(fib);
1432 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1433 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1434 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1435 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1436 srbcmd->flags = cpu_to_le32(flag);
Jens Axboe242f9dc2008-09-14 05:55:09 -07001437 timeout = cmd->request->timeout/HZ;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001438 if (timeout == 0)
1439 timeout = 1;
1440 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1441 srbcmd->retry_limit = 0; /* Obsolete parameter */
1442 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1443 return srbcmd;
1444}
1445
1446static void aac_srb_callback(void *context, struct fib * fibptr);
1447
1448static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1449{
1450 u16 fibsize;
1451 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301452 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001453
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301454 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1455 if (ret < 0)
1456 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001457 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001458
1459 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1460 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1461 /*
1462 * Build Scatter/Gather list
1463 */
1464 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1465 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1466 sizeof (struct sgentry64));
1467 BUG_ON (fibsize > (fib->dev->max_fib_size -
1468 sizeof(struct aac_fibhdr)));
1469
1470 /*
1471 * Now send the Fib to the adapter
1472 */
1473 return aac_fib_send(ScsiPortCommand64, fib,
1474 fibsize, FsaNormal, 0, 1,
1475 (fib_callback) aac_srb_callback,
1476 (void *) cmd);
1477}
1478
1479static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1480{
1481 u16 fibsize;
1482 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301483 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001484
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301485 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1486 if (ret < 0)
1487 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001488 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001489
1490 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1491 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1492 /*
1493 * Build Scatter/Gather list
1494 */
1495 fibsize = sizeof (struct aac_srb) +
1496 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1497 sizeof (struct sgentry));
1498 BUG_ON (fibsize > (fib->dev->max_fib_size -
1499 sizeof(struct aac_fibhdr)));
1500
1501 /*
1502 * Now send the Fib to the adapter
1503 */
1504 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1505 (fib_callback) aac_srb_callback, (void *) cmd);
1506}
1507
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001508static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1509{
Leubner, Achimd8e965072009-04-01 07:16:08 -07001510 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1511 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001512 return FAILED;
1513 return aac_scsi_32(fib, cmd);
1514}
1515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516int aac_get_adapter_info(struct aac_dev* dev)
1517{
1518 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 int rcode;
1520 u32 tmp;
Mark Haverkamp84971732005-06-20 11:55:24 -07001521 struct aac_adapter_info *info;
1522 struct aac_bus_info *command;
1523 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001524
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001525 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return -ENOMEM;
1527
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001528 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001529 info = (struct aac_adapter_info *) fib_data(fibptr);
1530 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001532 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001533 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001534 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001535 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07001536 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001537 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001538 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001540 if (rcode < 0) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301541 /* FIB should be freed only after
1542 * getting the response from the F/W */
1543 if (rcode != -ERESTARTSYS) {
1544 aac_fib_complete(fibptr);
1545 aac_fib_free(fibptr);
1546 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001547 return rcode;
1548 }
1549 memcpy(&dev->adapter_info, info, sizeof(*info));
1550
1551 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001552 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001553
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001554 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001555
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001556 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001557
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001558 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001559
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001560 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001561 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001562 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001563 FsaNormal,
1564 1, 1,
1565 NULL,
1566 NULL);
1567
1568 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001569 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301570 if (rcode == -ERESTARTSYS) {
1571 fibptr = aac_fib_alloc(dev);
1572 if (!fibptr)
1573 return -ENOMEM;
1574 }
1575
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Mark Haverkamp84971732005-06-20 11:55:24 -07001578
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001579 /*
1580 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07001581 */
1582
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001583 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07001584
1585 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1586
1587 memset(bus_info, 0, sizeof(*bus_info));
1588
1589 command = (struct aac_bus_info *)bus_info;
1590
1591 command->Command = cpu_to_le32(VM_Ioctl);
1592 command->ObjType = cpu_to_le32(FT_DRIVE);
1593 command->MethodId = cpu_to_le32(1);
1594 command->CtlCmd = cpu_to_le32(GetBusInfo);
1595
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001596 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07001597 fibptr,
1598 sizeof (*bus_info),
1599 FsaNormal,
1600 1, 1,
1601 NULL, NULL);
1602
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001603 /* reasoned default */
1604 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07001605 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1606 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1607 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1608 }
1609
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001610 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001611 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001612 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1613 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001614 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 dev->id,
1616 tmp>>24,
1617 (tmp>>16)&0xff,
1618 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001619 le32_to_cpu(dev->adapter_info.kernelbuild),
1620 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1621 dev->supplement_adapter_info.BuildDate);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001622 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1623 printk(KERN_INFO "%s%d: monitor %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.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001627 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1628 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 dev->name, dev->id,
1630 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1631 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001632 buffer[0] = '\0';
Tony Jonesee959b02008-02-22 00:13:36 +01001633 if (aac_get_serial_number(
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001634 shost_to_class(dev->scsi_host_ptr), buffer))
1635 printk(KERN_INFO "%s%d: serial %s",
1636 dev->name, dev->id, buffer);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04001637 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1638 printk(KERN_INFO "%s%d: TSID %.*s\n",
1639 dev->name, dev->id,
1640 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1641 dev->supplement_adapter_info.VpdInfo.Tsid);
1642 }
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001643 if (!aac_check_reset || ((aac_check_reset == 1) &&
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001644 (dev->supplement_adapter_info.SupportedOptions2 &
1645 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001646 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1647 dev->name, dev->id);
1648 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001651 dev->cache_protected = 0;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001652 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1653 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 dev->nondasd_support = 0;
1655 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001656 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 /*
1660 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1661 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1662 * force nondasd support on. If we decide to allow the non-dasd flag
1663 * additional changes changes will have to be made to support
1664 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1665 * changed to support the new dev->raid_scsi_mode flag instead of
1666 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1667 * function aac_detect will have to be modified where it sets up the
1668 * max number of channels based on the aac->nondasd_support flag only.
1669 */
1670 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1671 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1672 dev->nondasd_support = 1;
1673 dev->raid_scsi_mode = 1;
1674 }
1675 if (dev->raid_scsi_mode != 0)
1676 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1677 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001678
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001679 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001681 if (dev->nondasd_support && !dev->in_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Yang Hongyange9304382009-04-13 14:40:14 -07001684 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
Leubner, Achimd8e965072009-04-01 07:16:08 -07001685 dev->needs_dac = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 dev->dac_support = 0;
Leubner, Achimd8e965072009-04-01 07:16:08 -07001687 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
1688 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001689 if (!dev->in_reset)
1690 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
1691 dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 dev->dac_support = 1;
1693 }
1694
1695 if(dacmode != -1) {
1696 dev->dac_support = (dacmode!=0);
1697 }
Leubner, Achimd8e965072009-04-01 07:16:08 -07001698
1699 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1700 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
1701 & AAC_QUIRK_SCSI_32)) {
1702 dev->nondasd_support = 0;
1703 dev->jbod = 0;
1704 expose_physicals = 0;
1705 }
1706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 if(dev->dac_support != 0) {
Yang Hongyang6a355282009-04-06 19:01:13 -07001708 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64)) &&
1709 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001710 if (!dev->in_reset)
1711 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1712 dev->name, dev->id);
Yang Hongyang284901a2009-04-06 19:01:15 -07001713 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32)) &&
1714 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1716 dev->name, dev->id);
1717 dev->dac_support = 0;
1718 } else {
1719 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1720 dev->name, dev->id);
1721 rcode = -ENOMEM;
1722 }
1723 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001724 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001725 * Deal with configuring for the individualized limits of each packet
1726 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001727 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001728 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001729 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1730 ? aac_scsi_32_64
1731 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001732 : aac_scsi_32;
1733 if (dev->raw_io_interface) {
1734 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1735 ? aac_bounds_64
1736 : aac_bounds_32;
1737 dev->a_ops.adapter_read = aac_read_raw_io;
1738 dev->a_ops.adapter_write = aac_write_raw_io;
1739 } else {
1740 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001741 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001742 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001743 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1744 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001745 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001746 dev->a_ops.adapter_read = aac_read_block64;
1747 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001748 /*
1749 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001750 */
1751 dev->scsi_host_ptr->sg_tablesize =
1752 (dev->max_fib_size -
1753 sizeof(struct aac_fibhdr) -
1754 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001755 sizeof(struct sgentry64)) /
1756 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001757 } else {
1758 dev->a_ops.adapter_read = aac_read_block;
1759 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001760 }
1761 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07001762 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001763 /*
1764 * Worst case size that could cause sg overflow when
1765 * we break up SG elements that are larger than 64KB.
1766 * Would be nice if we could tell the SCSI layer what
1767 * the maximum SG element size can be. Worst case is
1768 * (sg_tablesize-1) 4KB elements with one 64KB
1769 * element.
1770 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1771 */
1772 dev->scsi_host_ptr->max_sectors =
1773 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1774 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001775 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301776 /* FIB should be freed only after getting the response from the F/W */
1777 if (rcode != -ERESTARTSYS) {
1778 aac_fib_complete(fibptr);
1779 aac_fib_free(fibptr);
1780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
1782 return rcode;
1783}
1784
1785
Mark Haverkampe53cb352005-08-03 15:39:09 -07001786static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787{
1788 struct aac_dev *dev;
1789 struct aac_read_reply *readreply;
1790 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 u32 cid;
1792
1793 scsicmd = (struct scsi_cmnd *) context;
1794
Mark Haverkamp03d44332007-03-15 10:27:45 -07001795 if (!aac_valid_context(scsicmd, fibptr))
1796 return;
1797
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001798 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001799 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001801 if (nblank(dprintk(x))) {
1802 u64 lba;
1803 switch (scsicmd->cmnd[0]) {
1804 case WRITE_6:
1805 case READ_6:
1806 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1807 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1808 break;
1809 case WRITE_16:
1810 case READ_16:
1811 lba = ((u64)scsicmd->cmnd[2] << 56) |
1812 ((u64)scsicmd->cmnd[3] << 48) |
1813 ((u64)scsicmd->cmnd[4] << 40) |
1814 ((u64)scsicmd->cmnd[5] << 32) |
1815 ((u64)scsicmd->cmnd[6] << 24) |
1816 (scsicmd->cmnd[7] << 16) |
1817 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1818 break;
1819 case WRITE_12:
1820 case READ_12:
1821 lba = ((u64)scsicmd->cmnd[2] << 24) |
1822 (scsicmd->cmnd[3] << 16) |
1823 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1824 break;
1825 default:
1826 lba = ((u64)scsicmd->cmnd[2] << 24) |
1827 (scsicmd->cmnd[3] << 16) |
1828 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1829 break;
1830 }
1831 printk(KERN_DEBUG
1832 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1833 smp_processor_id(), (unsigned long long)lba, jiffies);
1834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Eric Sesterhenn125e1872006-06-23 02:06:06 -07001836 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001837
1838 scsi_dma_unmap(scsicmd);
1839
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 readreply = (struct aac_read_reply *)fib_data(fibptr);
Mark Salyzyn655d7222008-04-30 16:03:42 -04001841 switch (le32_to_cpu(readreply->status)) {
1842 case ST_OK:
1843 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1844 SAM_STAT_GOOD;
1845 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
1846 break;
1847 case ST_NOT_READY:
1848 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1849 SAM_STAT_CHECK_CONDITION;
1850 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
1851 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
1852 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1853 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1854 SCSI_SENSE_BUFFERSIZE));
1855 break;
1856 default:
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001857#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07001858 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001859 le32_to_cpu(readreply->status));
1860#endif
Mark Salyzyn655d7222008-04-30 16:03:42 -04001861 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1862 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001863 set_sense(&dev->fsa_dev[cid].sense_data,
1864 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1865 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001867 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1868 SCSI_SENSE_BUFFERSIZE));
Mark Salyzyn655d7222008-04-30 16:03:42 -04001869 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001871 aac_fib_complete(fibptr);
1872 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001874 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875}
1876
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001877static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001879 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 u32 count;
1881 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 struct aac_dev *dev;
1883 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001884 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1887 /*
1888 * Get block address and transfer length
1889 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001890 switch (scsicmd->cmnd[0]) {
1891 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001892 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001894 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001895 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 count = scsicmd->cmnd[4];
1897
1898 if (count == 0)
1899 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001900 break;
1901 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001902 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001903
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001904 lba = ((u64)scsicmd->cmnd[2] << 56) |
1905 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001906 ((u64)scsicmd->cmnd[4] << 40) |
1907 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001908 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001909 (scsicmd->cmnd[7] << 16) |
1910 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001911 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001912 (scsicmd->cmnd[11] << 16) |
1913 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1914 break;
1915 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001916 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001917
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001918 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001919 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001920 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1921 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001922 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001923 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001924 break;
1925 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001926 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001928 lba = ((u64)scsicmd->cmnd[2] << 24) |
1929 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001930 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001932 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001934
1935 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1936 cid = scmd_id(scsicmd);
1937 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1938 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1939 SAM_STAT_CHECK_CONDITION;
1940 set_sense(&dev->fsa_dev[cid].sense_data,
1941 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1942 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1943 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1944 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1945 SCSI_SENSE_BUFFERSIZE));
1946 scsicmd->scsi_done(scsicmd);
1947 return 1;
1948 }
1949
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001950 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001951 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001952 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001953 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 /*
1955 * Alocate and initialize a Fib
1956 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001957 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301958 printk(KERN_WARNING "aac_read: fib allocation failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 return -1;
1960 }
1961
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001962 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
1964 /*
1965 * Check that the command queued to the controller
1966 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001967 if (status == -EINPROGRESS) {
1968 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001970 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001971
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001972 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 /*
1974 * For some reason, the Fib didn't queue, return QUEUE_FULL
1975 */
1976 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001977 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001978 aac_fib_complete(cmd_fibcontext);
1979 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 return 0;
1981}
1982
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001983static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001985 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001987 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 struct aac_dev *dev;
1990 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001991 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
1993 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1994 /*
1995 * Get block address and transfer length
1996 */
1997 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1998 {
1999 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2000 count = scsicmd->cmnd[4];
2001 if (count == 0)
2002 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002003 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002004 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002005 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002006
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002007 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002008 ((u64)scsicmd->cmnd[3] << 48) |
2009 ((u64)scsicmd->cmnd[4] << 40) |
2010 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002011 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002012 (scsicmd->cmnd[7] << 16) |
2013 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2014 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2015 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002016 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002017 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002018 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002019
2020 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2021 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2022 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2023 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002024 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002026 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002027 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002029 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002031
2032 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2033 cid = scmd_id(scsicmd);
2034 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2035 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2036 SAM_STAT_CHECK_CONDITION;
2037 set_sense(&dev->fsa_dev[cid].sense_data,
2038 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2039 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2040 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2041 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2042 SCSI_SENSE_BUFFERSIZE));
2043 scsicmd->scsi_done(scsicmd);
2044 return 1;
2045 }
2046
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002047 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002049 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002050 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 /*
2052 * Allocate and initialize a Fib then setup a BlockWrite command
2053 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002054 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302055 /* FIB temporarily unavailable,not catastrophic failure */
2056
2057 /* scsicmd->result = DID_ERROR << 16;
2058 * scsicmd->scsi_done(scsicmd);
2059 * return 0;
2060 */
2061 printk(KERN_WARNING "aac_write: fib allocation failed\n");
2062 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002065 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
2067 /*
2068 * Check that the command queued to the controller
2069 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002070 if (status == -EINPROGRESS) {
2071 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 return 0;
2073 }
2074
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002075 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 /*
2077 * For some reason, the Fib didn't queue, return QUEUE_FULL
2078 */
2079 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002080 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002082 aac_fib_complete(cmd_fibcontext);
2083 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 return 0;
2085}
2086
2087static void synchronize_callback(void *context, struct fib *fibptr)
2088{
2089 struct aac_synchronize_reply *synchronizereply;
2090 struct scsi_cmnd *cmd;
2091
2092 cmd = context;
2093
Mark Haverkamp03d44332007-03-15 10:27:45 -07002094 if (!aac_valid_context(cmd, fibptr))
2095 return;
2096
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002097 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 smp_processor_id(), jiffies));
2099 BUG_ON(fibptr == NULL);
2100
2101
2102 synchronizereply = fib_data(fibptr);
2103 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002104 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2106 else {
2107 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002108 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002109 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002110 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 "synchronize_callback: synchronize failed, status = %d\n",
2112 le32_to_cpu(synchronizereply->status));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002113 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002115 set_sense(&dev->fsa_dev[cid].sense_data,
2116 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2117 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002119 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2120 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 }
2122
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002123 aac_fib_complete(fibptr);
2124 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002125 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002128static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 int status;
2131 struct fib *cmd_fibcontext;
2132 struct aac_synchronize *synchronizecmd;
2133 struct scsi_cmnd *cmd;
2134 struct scsi_device *sdev = scsicmd->device;
2135 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002136 struct aac_dev *aac;
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002137 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2138 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2139 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 unsigned long flags;
2141
2142 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002143 * Wait for all outstanding queued commands to complete to this
2144 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 */
2146 spin_lock_irqsave(&sdev->list_lock, flags);
2147 list_for_each_entry(cmd, &sdev->cmd_list, list)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002148 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2149 u64 cmnd_lba;
2150 u32 cmnd_count;
2151
2152 if (cmd->cmnd[0] == WRITE_6) {
2153 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2154 (cmd->cmnd[2] << 8) |
2155 cmd->cmnd[3];
2156 cmnd_count = cmd->cmnd[4];
2157 if (cmnd_count == 0)
2158 cmnd_count = 256;
2159 } else if (cmd->cmnd[0] == WRITE_16) {
2160 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2161 ((u64)cmd->cmnd[3] << 48) |
2162 ((u64)cmd->cmnd[4] << 40) |
2163 ((u64)cmd->cmnd[5] << 32) |
2164 ((u64)cmd->cmnd[6] << 24) |
2165 (cmd->cmnd[7] << 16) |
2166 (cmd->cmnd[8] << 8) |
2167 cmd->cmnd[9];
2168 cmnd_count = (cmd->cmnd[10] << 24) |
2169 (cmd->cmnd[11] << 16) |
2170 (cmd->cmnd[12] << 8) |
2171 cmd->cmnd[13];
2172 } else if (cmd->cmnd[0] == WRITE_12) {
2173 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2174 (cmd->cmnd[3] << 16) |
2175 (cmd->cmnd[4] << 8) |
2176 cmd->cmnd[5];
2177 cmnd_count = (cmd->cmnd[6] << 24) |
2178 (cmd->cmnd[7] << 16) |
2179 (cmd->cmnd[8] << 8) |
2180 cmd->cmnd[9];
2181 } else if (cmd->cmnd[0] == WRITE_10) {
2182 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2183 (cmd->cmnd[3] << 16) |
2184 (cmd->cmnd[4] << 8) |
2185 cmd->cmnd[5];
2186 cmnd_count = (cmd->cmnd[7] << 8) |
2187 cmd->cmnd[8];
2188 } else
2189 continue;
2190 if (((cmnd_lba + cmnd_count) < lba) ||
2191 (count && ((lba + count) < cmnd_lba)))
2192 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 ++active;
2194 break;
2195 }
2196
2197 spin_unlock_irqrestore(&sdev->list_lock, flags);
2198
2199 /*
2200 * Yield the processor (requeue for later)
2201 */
2202 if (active)
2203 return SCSI_MLQUEUE_DEVICE_BUSY;
2204
Salyzyn, Markf8583172007-10-30 15:50:49 -04002205 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002206 if (aac->in_reset)
2207 return SCSI_MLQUEUE_HOST_BUSY;
2208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002210 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002212 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 return SCSI_MLQUEUE_HOST_BUSY;
2214
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002215 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217 synchronizecmd = fib_data(cmd_fibcontext);
2218 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2219 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002220 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002221 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2223
2224 /*
2225 * Now send the Fib to the adapter
2226 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002227 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 cmd_fibcontext,
2229 sizeof(struct aac_synchronize),
2230 FsaNormal,
2231 0, 1,
2232 (fib_callback)synchronize_callback,
2233 (void *)scsicmd);
2234
2235 /*
2236 * Check that the command queued to the controller
2237 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002238 if (status == -EINPROGRESS) {
2239 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002243 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002244 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2245 aac_fib_complete(cmd_fibcontext);
2246 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 return SCSI_MLQUEUE_HOST_BUSY;
2248}
2249
Mark Salyzyn655d7222008-04-30 16:03:42 -04002250static void aac_start_stop_callback(void *context, struct fib *fibptr)
2251{
2252 struct scsi_cmnd *scsicmd = context;
2253
2254 if (!aac_valid_context(scsicmd, fibptr))
2255 return;
2256
2257 BUG_ON(fibptr == NULL);
2258
2259 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2260
2261 aac_fib_complete(fibptr);
2262 aac_fib_free(fibptr);
2263 scsicmd->scsi_done(scsicmd);
2264}
2265
2266static int aac_start_stop(struct scsi_cmnd *scsicmd)
2267{
2268 int status;
2269 struct fib *cmd_fibcontext;
2270 struct aac_power_management *pmcmd;
2271 struct scsi_device *sdev = scsicmd->device;
2272 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2273
2274 if (!(aac->supplement_adapter_info.SupportedOptions2 &
2275 AAC_OPTION_POWER_MANAGEMENT)) {
2276 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2277 SAM_STAT_GOOD;
2278 scsicmd->scsi_done(scsicmd);
2279 return 0;
2280 }
2281
2282 if (aac->in_reset)
2283 return SCSI_MLQUEUE_HOST_BUSY;
2284
2285 /*
2286 * Allocate and initialize a Fib
2287 */
2288 cmd_fibcontext = aac_fib_alloc(aac);
2289 if (!cmd_fibcontext)
2290 return SCSI_MLQUEUE_HOST_BUSY;
2291
2292 aac_fib_init(cmd_fibcontext);
2293
2294 pmcmd = fib_data(cmd_fibcontext);
2295 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2296 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2297 /* Eject bit ignored, not relevant */
2298 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2299 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2300 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2301 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2302 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2303
2304 /*
2305 * Now send the Fib to the adapter
2306 */
2307 status = aac_fib_send(ContainerCommand,
2308 cmd_fibcontext,
2309 sizeof(struct aac_power_management),
2310 FsaNormal,
2311 0, 1,
2312 (fib_callback)aac_start_stop_callback,
2313 (void *)scsicmd);
2314
2315 /*
2316 * Check that the command queued to the controller
2317 */
2318 if (status == -EINPROGRESS) {
2319 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2320 return 0;
2321 }
2322
2323 aac_fib_complete(cmd_fibcontext);
2324 aac_fib_free(cmd_fibcontext);
2325 return SCSI_MLQUEUE_HOST_BUSY;
2326}
2327
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328/**
2329 * aac_scsi_cmd() - Process SCSI command
2330 * @scsicmd: SCSI command block
2331 *
2332 * Emulate a SCSI command and queue the required request for the
2333 * aacraid firmware.
2334 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002335
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2337{
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002338 u32 cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 struct Scsi_Host *host = scsicmd->device->host;
2340 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2341 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002342
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002343 if (fsa_dev_ptr == NULL)
2344 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 /*
2346 * If the bus, id or lun is out of range, return fail
2347 * Test does not apply to ID 16, the pseudo id for the controller
2348 * itself.
2349 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002350 cid = scmd_id(scsicmd);
2351 if (cid != host->this_id) {
2352 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2353 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08002354 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 scsicmd->result = DID_NO_CONNECT << 16;
2356 scsicmd->scsi_done(scsicmd);
2357 return 0;
2358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
2360 /*
2361 * If the target container doesn't exist, it may have
2362 * been newly created
2363 */
Mark Salyzyn655d7222008-04-30 16:03:42 -04002364 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2365 (fsa_dev_ptr[cid].sense_data.sense_key ==
2366 NOT_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 switch (scsicmd->cmnd[0]) {
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002368 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002369 if (!(dev->raw_io_interface) ||
2370 !(dev->raw_io_64) ||
2371 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2372 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 case INQUIRY:
2374 case READ_CAPACITY:
2375 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002376 if (dev->in_reset)
2377 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07002378 return _aac_probe_container(scsicmd,
2379 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 default:
2381 break;
2382 }
2383 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 } else { /* check for physical non-dasd devices */
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08002385 if (dev->nondasd_support || expose_physicals ||
2386 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002387 if (dev->in_reset)
2388 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 return aac_send_srb_fib(scsicmd);
2390 } else {
2391 scsicmd->result = DID_NO_CONNECT << 16;
2392 scsicmd->scsi_done(scsicmd);
2393 return 0;
2394 }
2395 }
2396 }
2397 /*
2398 * else Command for the controller itself
2399 */
2400 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002401 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 {
2403 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2404 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002405 set_sense(&dev->fsa_dev[cid].sense_data,
2406 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2407 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002409 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2410 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 scsicmd->scsi_done(scsicmd);
2412 return 0;
2413 }
2414
2415
2416 /* Handle commands here that don't really require going out to the adapter */
2417 switch (scsicmd->cmnd[0]) {
2418 case INQUIRY:
2419 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002420 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002422 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002423 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
Leubner, Achimd8e965072009-04-01 07:16:08 -07002425 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002426 char *arr = (char *)&inq_data;
2427
2428 /* EVPD bit set */
2429 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2430 INQD_PDT_PROC : INQD_PDT_DA;
2431 if (scsicmd->cmnd[2] == 0) {
2432 /* supported vital product data pages */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002433 arr[3] = 3;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002434 arr[4] = 0x0;
2435 arr[5] = 0x80;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002436 arr[6] = 0x83;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002437 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002438 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2439 sizeof(inq_data));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002440 scsicmd->result = DID_OK << 16 |
2441 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2442 } else if (scsicmd->cmnd[2] == 0x80) {
2443 /* unit serial number page */
2444 arr[3] = setinqserial(dev, &arr[4],
2445 scmd_id(scsicmd));
2446 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002447 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2448 sizeof(inq_data));
Leubner, Achimd8e965072009-04-01 07:16:08 -07002449 if (aac_wwn != 2)
2450 return aac_get_container_serial(
2451 scsicmd);
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002452 scsicmd->result = DID_OK << 16 |
2453 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2454 } else if (scsicmd->cmnd[2] == 0x83) {
2455 /* vpd page 0x83 - Device Identification Page */
2456 char *sno = (char *)&inq_data;
2457 sno[3] = setinqserial(dev, &sno[4],
2458 scmd_id(scsicmd));
2459 if (aac_wwn != 2)
2460 return aac_get_container_serial(
2461 scsicmd);
Leubner, Achimd8e965072009-04-01 07:16:08 -07002462 scsicmd->result = DID_OK << 16 |
2463 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002464 } else {
2465 /* vpd page not implemented */
2466 scsicmd->result = DID_OK << 16 |
2467 COMMAND_COMPLETE << 8 |
2468 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002469 set_sense(&dev->fsa_dev[cid].sense_data,
2470 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2471 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002472 memcpy(scsicmd->sense_buffer,
2473 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002474 min_t(size_t,
2475 sizeof(dev->fsa_dev[cid].sense_data),
2476 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002477 }
2478 scsicmd->scsi_done(scsicmd);
2479 return 0;
2480 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002481 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002482 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 */
2483 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002485 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 /*
2487 * Set the Vendor, Product, and Revision Level
2488 * see: <vendor>.c i.e. aac.c
2489 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002490 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07002491 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002492 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002493 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2494 sizeof(inq_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2496 scsicmd->scsi_done(scsicmd);
2497 return 0;
2498 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002499 if (dev->in_reset)
2500 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07002501 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002502 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002503 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002504 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 }
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002506 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002507 if (!(dev->raw_io_interface) ||
2508 !(dev->raw_io_64) ||
2509 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2510 break;
2511 {
2512 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002513 char cp[13];
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002514 unsigned int alloc_len;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002515
2516 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2517 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002518 cp[0] = (capacity >> 56) & 0xff;
2519 cp[1] = (capacity >> 48) & 0xff;
2520 cp[2] = (capacity >> 40) & 0xff;
2521 cp[3] = (capacity >> 32) & 0xff;
2522 cp[4] = (capacity >> 24) & 0xff;
2523 cp[5] = (capacity >> 16) & 0xff;
2524 cp[6] = (capacity >> 8) & 0xff;
2525 cp[7] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002526 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2527 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2528 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2529 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002530 cp[12] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002531
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002532 alloc_len = ((scsicmd->cmnd[10] << 24)
2533 + (scsicmd->cmnd[11] << 16)
2534 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2535
2536 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002537 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002538 if (alloc_len < scsi_bufflen(scsicmd))
2539 scsi_set_resid(scsicmd,
2540 scsi_bufflen(scsicmd) - alloc_len);
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002541
2542 /* Do not cache partition table for arrays */
2543 scsicmd->device->removable = 1;
2544
2545 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2546 scsicmd->scsi_done(scsicmd);
2547
2548 return 0;
2549 }
2550
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 case READ_CAPACITY:
2552 {
2553 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002554 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
2556 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002557 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 capacity = fsa_dev_ptr[cid].size - 1;
2559 else
2560 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002561
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 cp[0] = (capacity >> 24) & 0xff;
2563 cp[1] = (capacity >> 16) & 0xff;
2564 cp[2] = (capacity >> 8) & 0xff;
2565 cp[3] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002566 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2567 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2568 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2569 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002570 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002571 /* Do not cache partition table for arrays */
2572 scsicmd->device->removable = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002573 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2574 SAM_STAT_GOOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 scsicmd->scsi_done(scsicmd);
2576
2577 return 0;
2578 }
2579
2580 case MODE_SENSE:
2581 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002582 int mode_buf_length = 4;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002583 u32 capacity;
2584 aac_modep_data mpd;
2585
2586 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2587 capacity = fsa_dev_ptr[cid].size - 1;
2588 else
2589 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
2591 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002592 memset((char *)&mpd, 0, sizeof(aac_modep_data));
2593
2594 /* Mode data length */
2595 mpd.hd.data_length = sizeof(mpd.hd) - 1;
2596 /* Medium type - default */
2597 mpd.hd.med_type = 0;
2598 /* Device-specific param,
2599 bit 8: 0/1 = write enabled/protected
2600 bit 4: 0/1 = FUA enabled */
2601 mpd.hd.dev_par = 0;
2602
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002603 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002604 mpd.hd.dev_par = 0x10;
2605 if (scsicmd->cmnd[1] & 0x8)
2606 mpd.hd.bd_length = 0; /* Block descriptor length */
2607 else {
2608 mpd.hd.bd_length = sizeof(mpd.bd);
2609 mpd.hd.data_length += mpd.hd.bd_length;
2610 mpd.bd.block_length[0] =
2611 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2612 mpd.bd.block_length[1] =
2613 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2614 mpd.bd.block_length[2] =
2615 fsa_dev_ptr[cid].block_size & 0xff;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002616
2617 mpd.mpc_buf[0] = scsicmd->cmnd[2];
2618 if (scsicmd->cmnd[2] == 0x1C) {
2619 /* page length */
2620 mpd.mpc_buf[1] = 0xa;
2621 /* Mode data length */
2622 mpd.hd.data_length = 23;
2623 } else {
2624 /* Mode data length */
2625 mpd.hd.data_length = 15;
2626 }
2627
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002628 if (capacity > 0xffffff) {
2629 mpd.bd.block_count[0] = 0xff;
2630 mpd.bd.block_count[1] = 0xff;
2631 mpd.bd.block_count[2] = 0xff;
2632 } else {
2633 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
2634 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
2635 mpd.bd.block_count[2] = capacity & 0xff;
2636 }
2637 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002638 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2639 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002640 mpd.hd.data_length += 3;
2641 mpd.mpc_buf[0] = 8;
2642 mpd.mpc_buf[1] = 1;
2643 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002644 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002645 mode_buf_length = sizeof(mpd);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002646 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002647
2648 if (mode_buf_length > scsicmd->cmnd[4])
2649 mode_buf_length = scsicmd->cmnd[4];
2650 else
2651 mode_buf_length = sizeof(mpd);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002652 scsi_sg_copy_from_buffer(scsicmd,
2653 (char *)&mpd,
2654 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2656 scsicmd->scsi_done(scsicmd);
2657
2658 return 0;
2659 }
2660 case MODE_SENSE_10:
2661 {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002662 u32 capacity;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002663 int mode_buf_length = 8;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002664 aac_modep10_data mpd10;
2665
2666 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2667 capacity = fsa_dev_ptr[cid].size - 1;
2668 else
2669 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670
2671 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002672 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
2673 /* Mode data length (MSB) */
2674 mpd10.hd.data_length[0] = 0;
2675 /* Mode data length (LSB) */
2676 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
2677 /* Medium type - default */
2678 mpd10.hd.med_type = 0;
2679 /* Device-specific param,
2680 bit 8: 0/1 = write enabled/protected
2681 bit 4: 0/1 = FUA enabled */
2682 mpd10.hd.dev_par = 0;
2683
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002684 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002685 mpd10.hd.dev_par = 0x10;
2686 mpd10.hd.rsrvd[0] = 0; /* reserved */
2687 mpd10.hd.rsrvd[1] = 0; /* reserved */
2688 if (scsicmd->cmnd[1] & 0x8) {
2689 /* Block descriptor length (MSB) */
2690 mpd10.hd.bd_length[0] = 0;
2691 /* Block descriptor length (LSB) */
2692 mpd10.hd.bd_length[1] = 0;
2693 } else {
2694 mpd10.hd.bd_length[0] = 0;
2695 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
2696
2697 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
2698
2699 mpd10.bd.block_length[0] =
2700 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2701 mpd10.bd.block_length[1] =
2702 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2703 mpd10.bd.block_length[2] =
2704 fsa_dev_ptr[cid].block_size & 0xff;
2705
2706 if (capacity > 0xffffff) {
2707 mpd10.bd.block_count[0] = 0xff;
2708 mpd10.bd.block_count[1] = 0xff;
2709 mpd10.bd.block_count[2] = 0xff;
2710 } else {
2711 mpd10.bd.block_count[0] =
2712 (capacity >> 16) & 0xff;
2713 mpd10.bd.block_count[1] =
2714 (capacity >> 8) & 0xff;
2715 mpd10.bd.block_count[2] =
2716 capacity & 0xff;
2717 }
2718 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002719 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2720 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002721 mpd10.hd.data_length[1] += 3;
2722 mpd10.mpc_buf[0] = 8;
2723 mpd10.mpc_buf[1] = 1;
2724 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002725 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002726 mode_buf_length = sizeof(mpd10);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002727 if (mode_buf_length > scsicmd->cmnd[8])
2728 mode_buf_length = scsicmd->cmnd[8];
2729 }
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002730 scsi_sg_copy_from_buffer(scsicmd,
2731 (char *)&mpd10,
2732 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733
2734 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2735 scsicmd->scsi_done(scsicmd);
2736
2737 return 0;
2738 }
2739 case REQUEST_SENSE:
2740 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2741 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2742 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2743 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2744 scsicmd->scsi_done(scsicmd);
2745 return 0;
2746
2747 case ALLOW_MEDIUM_REMOVAL:
2748 dprintk((KERN_DEBUG "LOCK command.\n"));
2749 if (scsicmd->cmnd[4])
2750 fsa_dev_ptr[cid].locked = 1;
2751 else
2752 fsa_dev_ptr[cid].locked = 0;
2753
2754 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2755 scsicmd->scsi_done(scsicmd);
2756 return 0;
2757 /*
2758 * These commands are all No-Ops
2759 */
2760 case TEST_UNIT_READY:
Mark Salyzyn655d7222008-04-30 16:03:42 -04002761 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
2762 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2763 SAM_STAT_CHECK_CONDITION;
2764 set_sense(&dev->fsa_dev[cid].sense_data,
2765 NOT_READY, SENCODE_BECOMING_READY,
2766 ASENCODE_BECOMING_READY, 0, 0);
2767 memcpy(scsicmd->sense_buffer,
2768 &dev->fsa_dev[cid].sense_data,
2769 min_t(size_t,
2770 sizeof(dev->fsa_dev[cid].sense_data),
2771 SCSI_SENSE_BUFFERSIZE));
2772 scsicmd->scsi_done(scsicmd);
2773 return 0;
2774 }
2775 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 case RESERVE:
2777 case RELEASE:
2778 case REZERO_UNIT:
2779 case REASSIGN_BLOCKS:
2780 case SEEK_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2782 scsicmd->scsi_done(scsicmd);
2783 return 0;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002784
2785 case START_STOP:
2786 return aac_start_stop(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 }
2788
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002789 switch (scsicmd->cmnd[0])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 {
2791 case READ_6:
2792 case READ_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002793 case READ_12:
2794 case READ_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002795 if (dev->in_reset)
2796 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 /*
2798 * Hack to keep track of ordinal number of the device that
2799 * corresponds to a container. Needed to convert
2800 * containers to /dev/sd device names
2801 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002802
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002803 if (scsicmd->request->rq_disk)
2804 strlcpy(fsa_dev_ptr[cid].devname,
2805 scsicmd->request->rq_disk->disk_name,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002806 min(sizeof(fsa_dev_ptr[cid].devname),
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002807 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002808
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002809 return aac_read(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810
2811 case WRITE_6:
2812 case WRITE_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002813 case WRITE_12:
2814 case WRITE_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002815 if (dev->in_reset)
2816 return -1;
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002817 return aac_write(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
2819 case SYNCHRONIZE_CACHE:
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002820 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2821 scsicmd->result = DID_OK << 16 |
2822 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2823 scsicmd->scsi_done(scsicmd);
2824 return 0;
2825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 /* Issue FIB to tell Firmware to flush it's cache */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002827 if ((aac_cache & 6) != 2)
2828 return aac_synchronize(scsicmd);
2829 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 default:
2831 /*
2832 * Unhandled commands
2833 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002834 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002836 set_sense(&dev->fsa_dev[cid].sense_data,
2837 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2838 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002840 min_t(size_t,
2841 sizeof(dev->fsa_dev[cid].sense_data),
2842 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 scsicmd->scsi_done(scsicmd);
2844 return 0;
2845 }
2846}
2847
2848static int query_disk(struct aac_dev *dev, void __user *arg)
2849{
2850 struct aac_query_disk qd;
2851 struct fsa_dev_info *fsa_dev_ptr;
2852
2853 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002854 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07002855 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2857 return -EFAULT;
2858 if (qd.cnum == -1)
Mark Haverkampe5718772006-03-27 09:43:25 -08002859 qd.cnum = qd.id;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002860 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 {
2862 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2863 return -EINVAL;
2864 qd.instance = dev->scsi_host_ptr->host_no;
2865 qd.bus = 0;
2866 qd.id = CONTAINER_TO_ID(qd.cnum);
2867 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2868 }
2869 else return -EINVAL;
2870
Salyzyn, Markfd622b12007-07-17 10:59:19 -04002871 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2873 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2874
2875 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2876 qd.unmapped = 1;
2877 else
2878 qd.unmapped = 0;
2879
2880 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2881 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2882
2883 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2884 return -EFAULT;
2885 return 0;
2886}
2887
2888static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2889{
2890 struct aac_delete_disk dd;
2891 struct fsa_dev_info *fsa_dev_ptr;
2892
2893 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp65101352006-09-19 08:59:23 -07002894 if (!fsa_dev_ptr)
2895 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
2897 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2898 return -EFAULT;
2899
2900 if (dd.cnum >= dev->maximum_num_containers)
2901 return -EINVAL;
2902 /*
2903 * Mark this container as being deleted.
2904 */
2905 fsa_dev_ptr[dd.cnum].deleted = 1;
2906 /*
2907 * Mark the container as no longer valid
2908 */
2909 fsa_dev_ptr[dd.cnum].valid = 0;
2910 return 0;
2911}
2912
2913static int delete_disk(struct aac_dev *dev, void __user *arg)
2914{
2915 struct aac_delete_disk dd;
2916 struct fsa_dev_info *fsa_dev_ptr;
2917
2918 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002919 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07002920 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
2922 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2923 return -EFAULT;
2924
2925 if (dd.cnum >= dev->maximum_num_containers)
2926 return -EINVAL;
2927 /*
2928 * If the container is locked, it can not be deleted by the API.
2929 */
2930 if (fsa_dev_ptr[dd.cnum].locked)
2931 return -EBUSY;
2932 else {
2933 /*
2934 * Mark the container as no longer being valid.
2935 */
2936 fsa_dev_ptr[dd.cnum].valid = 0;
2937 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2938 return 0;
2939 }
2940}
2941
2942int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2943{
2944 switch (cmd) {
2945 case FSACTL_QUERY_DISK:
2946 return query_disk(dev, arg);
2947 case FSACTL_DELETE_DISK:
2948 return delete_disk(dev, arg);
2949 case FSACTL_FORCE_DELETE_DISK:
2950 return force_delete_disk(dev, arg);
2951 case FSACTL_GET_CONTAINERS:
2952 return aac_get_containers(dev);
2953 default:
2954 return -ENOTTY;
2955 }
2956}
2957
2958/**
2959 *
2960 * aac_srb_callback
2961 * @context: the context set in the fib - here it is scsi cmd
2962 * @fibptr: pointer to the fib
2963 *
2964 * Handles the completion of a scsi command to a non dasd device
2965 *
2966 */
2967
2968static void aac_srb_callback(void *context, struct fib * fibptr)
2969{
2970 struct aac_dev *dev;
2971 struct aac_srb_reply *srbreply;
2972 struct scsi_cmnd *scsicmd;
2973
2974 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07002975
2976 if (!aac_valid_context(scsicmd, fibptr))
2977 return;
2978
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002979 BUG_ON(fibptr == NULL);
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002980 dev = fibptr->dev;
2981
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04002982 scsi_dma_unmap(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04002984 /* expose physical device if expose_physicald flag is on */
2985 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
2986 && expose_physicals > 0)
2987 aac_expose_phy_device(scsicmd);
2988
2989 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05302992 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
2993 /* fast response */
2994 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
2995 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
2996 } else {
2997 /*
2998 * Calculate resid for sg
2999 */
3000 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
3001 - le32_to_cpu(srbreply->data_xfer_length));
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003002 /*
3003 * First check the fib status
3004 */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003005
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003006 if (le32_to_cpu(srbreply->status) != ST_OK) {
3007 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003009 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
3010 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3011 SCSI_SENSE_BUFFERSIZE);
3012 scsicmd->result = DID_ERROR << 16
3013 | COMMAND_COMPLETE << 8
3014 | SAM_STAT_CHECK_CONDITION;
3015 memcpy(scsicmd->sense_buffer,
3016 srbreply->sense_data, len);
3017 }
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -07003018
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003019 /*
3020 * Next check the srb status
3021 */
3022 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3023 case SRB_STATUS_ERROR_RECOVERY:
3024 case SRB_STATUS_PENDING:
3025 case SRB_STATUS_SUCCESS:
Mark Haverkampbb08f922006-02-01 09:30:44 -08003026 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003028 case SRB_STATUS_DATA_OVERRUN:
3029 switch (scsicmd->cmnd[0]) {
3030 case READ_6:
3031 case WRITE_6:
3032 case READ_10:
3033 case WRITE_10:
3034 case READ_12:
3035 case WRITE_12:
3036 case READ_16:
3037 case WRITE_16:
3038 if (le32_to_cpu(srbreply->data_xfer_length)
3039 < scsicmd->underflow)
3040 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
3041 else
3042 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
3043 scsicmd->result = DID_ERROR << 16
3044 | COMMAND_COMPLETE << 8;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003045 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003046 case INQUIRY: {
3047 scsicmd->result = DID_OK << 16
3048 | COMMAND_COMPLETE << 8;
3049 break;
3050 }
3051 default:
3052 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3053 break;
3054 }
3055 break;
3056 case SRB_STATUS_ABORTED:
3057 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3058 break;
3059 case SRB_STATUS_ABORT_FAILED:
3060 /*
3061 * Not sure about this one - but assuming the
3062 * hba was trying to abort for some reason
3063 */
3064 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3065 break;
3066 case SRB_STATUS_PARITY_ERROR:
3067 scsicmd->result = DID_PARITY << 16
3068 | MSG_PARITY_ERROR << 8;
3069 break;
3070 case SRB_STATUS_NO_DEVICE:
3071 case SRB_STATUS_INVALID_PATH_ID:
3072 case SRB_STATUS_INVALID_TARGET_ID:
3073 case SRB_STATUS_INVALID_LUN:
3074 case SRB_STATUS_SELECTION_TIMEOUT:
3075 scsicmd->result = DID_NO_CONNECT << 16
3076 | COMMAND_COMPLETE << 8;
3077 break;
3078
3079 case SRB_STATUS_COMMAND_TIMEOUT:
3080 case SRB_STATUS_TIMEOUT:
3081 scsicmd->result = DID_TIME_OUT << 16
3082 | COMMAND_COMPLETE << 8;
3083 break;
3084
3085 case SRB_STATUS_BUSY:
3086 scsicmd->result = DID_BUS_BUSY << 16
3087 | COMMAND_COMPLETE << 8;
3088 break;
3089
3090 case SRB_STATUS_BUS_RESET:
3091 scsicmd->result = DID_RESET << 16
3092 | COMMAND_COMPLETE << 8;
3093 break;
3094
3095 case SRB_STATUS_MESSAGE_REJECTED:
3096 scsicmd->result = DID_ERROR << 16
3097 | MESSAGE_REJECT << 8;
3098 break;
3099 case SRB_STATUS_REQUEST_FLUSHED:
3100 case SRB_STATUS_ERROR:
3101 case SRB_STATUS_INVALID_REQUEST:
3102 case SRB_STATUS_REQUEST_SENSE_FAILED:
3103 case SRB_STATUS_NO_HBA:
3104 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3105 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3106 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3107 case SRB_STATUS_DELAYED_RETRY:
3108 case SRB_STATUS_BAD_FUNCTION:
3109 case SRB_STATUS_NOT_STARTED:
3110 case SRB_STATUS_NOT_IN_USE:
3111 case SRB_STATUS_FORCE_ABORT:
3112 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3113 default:
3114#ifdef AAC_DETAILED_STATUS_INFO
3115 printk(KERN_INFO "aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
3116 le32_to_cpu(srbreply->srb_status) & 0x3F,
3117 aac_get_status_string(
3118 le32_to_cpu(srbreply->srb_status) & 0x3F),
3119 scsicmd->cmnd[0],
3120 le32_to_cpu(srbreply->scsi_status));
3121#endif
3122 if ((scsicmd->cmnd[0] == ATA_12)
3123 || (scsicmd->cmnd[0] == ATA_16)) {
3124 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3125 scsicmd->result = DID_OK << 16
3126 | COMMAND_COMPLETE << 8;
3127 break;
3128 } else {
3129 scsicmd->result = DID_ERROR << 16
3130 | COMMAND_COMPLETE << 8;
3131 break;
3132 }
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003133 } else {
3134 scsicmd->result = DID_ERROR << 16
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003135 | COMMAND_COMPLETE << 8;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003136 break;
3137 }
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003138 }
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003139 if (le32_to_cpu(srbreply->scsi_status)
3140 == SAM_STAT_CHECK_CONDITION) {
3141 int len;
3142
3143 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3144 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3145 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146#ifdef AAC_DETAILED_STATUS_INFO
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003147 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
3148 le32_to_cpu(srbreply->status), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149#endif
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003150 memcpy(scsicmd->sense_buffer,
3151 srbreply->sense_data, len);
3152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 }
3154 /*
3155 * OR in the scsi status (already shifted up a bit)
3156 */
3157 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3158
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003159 aac_fib_complete(fibptr);
3160 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07003161 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162}
3163
3164/**
3165 *
3166 * aac_send_scb_fib
3167 * @scsicmd: the scsi command block
3168 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003169 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 * scsicmd passed in.
3171 */
3172
3173static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3174{
3175 struct fib* cmd_fibcontext;
3176 struct aac_dev* dev;
3177 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
Mark Haverkamp84971732005-06-20 11:55:24 -07003179 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08003180 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07003181 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 scsicmd->result = DID_NO_CONNECT << 16;
3183 scsicmd->scsi_done(scsicmd);
3184 return 0;
3185 }
3186
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 /*
3188 * Allocate and initialize a Fib then setup a BlockWrite command
3189 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003190 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 return -1;
3192 }
Mark Haverkampe8f32de2007-01-23 15:00:30 -08003193 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 /*
3196 * Check that the command queued to the controller
3197 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08003198 if (status == -EINPROGRESS) {
3199 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 return 0;
3201 }
3202
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003203 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3204 aac_fib_complete(cmd_fibcontext);
3205 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
3207 return -1;
3208}
3209
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303210static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211{
3212 struct aac_dev *dev;
3213 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003214 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
3216 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3217 // Get rid of old data
3218 psg->count = 0;
3219 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003220 psg->sg[0].count = 0;
3221
3222 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303223 if (nseg < 0)
3224 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003225 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 struct scatterlist *sg;
3227 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003229 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003231 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3233 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3234 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 }
3236 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003237 if (byte_count > scsi_bufflen(scsicmd)) {
3238 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3239 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003240 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003241 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 }
3243 /* Check for command underflow */
3244 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3245 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3246 byte_count, scsicmd->underflow);
3247 }
3248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 return byte_count;
3250}
3251
3252
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303253static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254{
3255 struct aac_dev *dev;
3256 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003257 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003258 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259
3260 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3261 // Get rid of old data
3262 psg->count = 0;
3263 psg->sg[0].addr[0] = 0;
3264 psg->sg[0].addr[1] = 0;
3265 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003266
3267 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303268 if (nseg < 0)
3269 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003270 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 struct scatterlist *sg;
3272 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003274 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp1241f352006-03-27 09:44:23 -08003275 int count = sg_dma_len(sg);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003276 addr = sg_dma_address(sg);
3277 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3278 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
Mark Haverkamp1241f352006-03-27 09:44:23 -08003279 psg->sg[i].count = cpu_to_le32(count);
3280 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003282 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003284 if (byte_count > scsi_bufflen(scsicmd)) {
3285 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3286 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003287 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003288 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 }
3290 /* Check for command underflow */
3291 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3292 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3293 byte_count, scsicmd->underflow);
3294 }
3295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 return byte_count;
3297}
3298
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303299static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003300{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003301 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003302 int nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003303
3304 // Get rid of old data
3305 psg->count = 0;
3306 psg->sg[0].next = 0;
3307 psg->sg[0].prev = 0;
3308 psg->sg[0].addr[0] = 0;
3309 psg->sg[0].addr[1] = 0;
3310 psg->sg[0].count = 0;
3311 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003312
3313 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303314 if (nseg < 0)
3315 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003316 if (nseg) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003317 struct scatterlist *sg;
3318 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003319
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003320 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003321 int count = sg_dma_len(sg);
3322 u64 addr = sg_dma_address(sg);
3323 psg->sg[i].next = 0;
3324 psg->sg[i].prev = 0;
3325 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
3326 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
3327 psg->sg[i].count = cpu_to_le32(count);
3328 psg->sg[i].flags = 0;
3329 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003330 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003331 psg->count = cpu_to_le32(nseg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003332 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003333 if (byte_count > scsi_bufflen(scsicmd)) {
3334 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3335 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003336 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003337 byte_count = scsi_bufflen(scsicmd);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003338 }
3339 /* Check for command underflow */
3340 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3341 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3342 byte_count, scsicmd->underflow);
3343 }
3344 }
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003345 return byte_count;
3346}
3347
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303348static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
3349 struct aac_raw_io2 *rio2, int sg_max)
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303350{
3351 unsigned long byte_count = 0;
3352 int nseg;
3353
3354 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303355 if (nseg < 0)
3356 return nseg;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303357 if (nseg) {
3358 struct scatterlist *sg;
3359 int i, conformable = 0;
3360 u32 min_size = PAGE_SIZE, cur_size;
3361
3362 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3363 int count = sg_dma_len(sg);
3364 u64 addr = sg_dma_address(sg);
3365
3366 BUG_ON(i >= sg_max);
3367 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3368 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3369 cur_size = cpu_to_le32(count);
3370 rio2->sge[i].length = cur_size;
3371 rio2->sge[i].flags = 0;
3372 if (i == 0) {
3373 conformable = 1;
3374 rio2->sgeFirstSize = cur_size;
3375 } else if (i == 1) {
3376 rio2->sgeNominalSize = cur_size;
3377 min_size = cur_size;
3378 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3379 conformable = 0;
3380 if (cur_size < min_size)
3381 min_size = cur_size;
3382 }
3383 byte_count += count;
3384 }
3385
3386 /* hba wants the size to be exact */
3387 if (byte_count > scsi_bufflen(scsicmd)) {
3388 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3389 (byte_count - scsi_bufflen(scsicmd));
3390 rio2->sge[i-1].length = cpu_to_le32(temp);
3391 byte_count = scsi_bufflen(scsicmd);
3392 }
3393
3394 rio2->sgeCnt = cpu_to_le32(nseg);
3395 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3396 /* not conformable: evaluate required sg elements */
3397 if (!conformable) {
3398 int j, nseg_new = nseg, err_found;
3399 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3400 err_found = 0;
3401 nseg_new = 2;
3402 for (j = 1; j < nseg - 1; ++j) {
3403 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3404 err_found = 1;
3405 break;
3406 }
3407 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3408 }
3409 if (!err_found)
3410 break;
3411 }
3412 if (i > 0 && nseg_new <= sg_max)
3413 aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3414 } else
3415 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3416
3417 /* Check for command underflow */
3418 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3419 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3420 byte_count, scsicmd->underflow);
3421 }
3422 }
3423
3424 return byte_count;
3425}
3426
3427static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3428{
3429 struct sge_ieee1212 *sge;
3430 int i, j, pos;
3431 u32 addr_low;
3432
3433 if (aac_convert_sgl == 0)
3434 return 0;
3435
3436 sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
3437 if (sge == NULL)
3438 return -1;
3439
3440 for (i = 1, pos = 1; i < nseg-1; ++i) {
3441 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
3442 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
3443 sge[pos].addrLow = addr_low;
3444 sge[pos].addrHigh = rio2->sge[i].addrHigh;
3445 if (addr_low < rio2->sge[i].addrLow)
3446 sge[pos].addrHigh++;
3447 sge[pos].length = pages * PAGE_SIZE;
3448 sge[pos].flags = 0;
3449 pos++;
3450 }
3451 }
3452 sge[pos] = rio2->sge[nseg-1];
3453 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
3454
3455 kfree(sge);
3456 rio2->sgeCnt = cpu_to_le32(nseg_new);
3457 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3458 rio2->sgeNominalSize = pages * PAGE_SIZE;
3459 return 0;
3460}
3461
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462#ifdef AAC_DETAILED_STATUS_INFO
3463
3464struct aac_srb_status_info {
3465 u32 status;
3466 char *str;
3467};
3468
3469
3470static struct aac_srb_status_info srb_status_info[] = {
3471 { SRB_STATUS_PENDING, "Pending Status"},
3472 { SRB_STATUS_SUCCESS, "Success"},
3473 { SRB_STATUS_ABORTED, "Aborted Command"},
3474 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07003475 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 { SRB_STATUS_BUSY, "Device Busy"},
3477 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
3478 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
3479 { SRB_STATUS_NO_DEVICE, "No Device"},
3480 { SRB_STATUS_TIMEOUT, "Timeout"},
3481 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
3482 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
3483 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
3484 { SRB_STATUS_BUS_RESET, "Bus Reset"},
3485 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
3486 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
3487 { SRB_STATUS_NO_HBA, "No HBA"},
3488 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
3489 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
3490 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
3491 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
3492 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
3493 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07003494 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
3496 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
3497 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
3498 { SRB_STATUS_NOT_STARTED, "Not Started"},
3499 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003500 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
3502 { 0xff, "Unknown Error"}
3503};
3504
3505char *aac_get_status_string(u32 status)
3506{
3507 int i;
3508
Tobias Klauser6391a112006-06-08 22:23:48 -07003509 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
3510 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512
3513 return "Bad Status Code";
3514}
3515
3516#endif