blob: 2ad7aeacd092dd1a54e4d4a0e0babe11274ef36c [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 Torvalds7c0f6ba2016-12-24 11:46:01 -080035#include <linux/uaccess.h>
Salyzyn, Mark3a0086a82008-01-11 11:46:44 -080036#include <linux/highmem.h> /* For flush_kernel_dcache_page */
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040037#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#include <scsi/scsi.h>
40#include <scsi/scsi_cmnd.h>
41#include <scsi/scsi_device.h>
42#include <scsi/scsi_host.h>
43
44#include "aacraid.h"
45
46/* values for inqd_pdt: Peripheral device type in plain English */
47#define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
48#define INQD_PDT_PROC 0x03 /* Processor device */
49#define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
50#define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
51#define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
52#define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
53
54#define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
55#define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
58 * Sense codes
59 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080060
61#define SENCODE_NO_SENSE 0x00
62#define SENCODE_END_OF_DATA 0x00
63#define SENCODE_BECOMING_READY 0x04
64#define SENCODE_INIT_CMD_REQUIRED 0x04
65#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
66#define SENCODE_INVALID_COMMAND 0x20
67#define SENCODE_LBA_OUT_OF_RANGE 0x21
68#define SENCODE_INVALID_CDB_FIELD 0x24
69#define SENCODE_LUN_NOT_SUPPORTED 0x25
70#define SENCODE_INVALID_PARAM_FIELD 0x26
71#define SENCODE_PARAM_NOT_SUPPORTED 0x26
72#define SENCODE_PARAM_VALUE_INVALID 0x26
73#define SENCODE_RESET_OCCURRED 0x29
74#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
75#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
76#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
77#define SENCODE_DIAGNOSTIC_FAILURE 0x40
78#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
79#define SENCODE_INVALID_MESSAGE_ERROR 0x49
80#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
81#define SENCODE_OVERLAPPED_COMMAND 0x4E
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83/*
84 * Additional sense codes
85 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080086
87#define ASENCODE_NO_SENSE 0x00
88#define ASENCODE_END_OF_DATA 0x05
89#define ASENCODE_BECOMING_READY 0x01
90#define ASENCODE_INIT_CMD_REQUIRED 0x02
91#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
92#define ASENCODE_INVALID_COMMAND 0x00
93#define ASENCODE_LBA_OUT_OF_RANGE 0x00
94#define ASENCODE_INVALID_CDB_FIELD 0x00
95#define ASENCODE_LUN_NOT_SUPPORTED 0x00
96#define ASENCODE_INVALID_PARAM_FIELD 0x00
97#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
98#define ASENCODE_PARAM_VALUE_INVALID 0x02
99#define ASENCODE_RESET_OCCURRED 0x00
100#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
101#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
102#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
103#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
104#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
105#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
106#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
107#define ASENCODE_OVERLAPPED_COMMAND 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109#define BYTE0(x) (unsigned char)(x)
110#define BYTE1(x) (unsigned char)((x) >> 8)
111#define BYTE2(x) (unsigned char)((x) >> 16)
112#define BYTE3(x) (unsigned char)((x) >> 24)
113
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 Haverkampe37ee4b2007-01-26 09:23:32 -0800302int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700303module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800304MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
305 " -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700306
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800307int aac_reset_devices;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400308module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
309MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700310
Leubner, Achimd8e965072009-04-01 07:16:08 -0700311int aac_wwn = 1;
312module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
313MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
314 "\t0 - Disable\n"
315 "\t1 - Array Meta Data Signature (default)\n"
316 "\t2 - Adapter Serial Number");
317
318
Mark Haverkamp03d44332007-03-15 10:27:45 -0700319static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
320 struct fib *fibptr) {
321 struct scsi_device *device;
322
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800323 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
Salyzyn, Markc835e372007-07-26 14:20:02 -0400324 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800325 aac_fib_complete(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800326 return 0;
327 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700328 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
329 device = scsicmd->device;
330 if (unlikely(!device || !scsi_device_online(device))) {
331 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
332 aac_fib_complete(fibptr);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700333 return 0;
334 }
335 return 1;
336}
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338/**
339 * aac_get_config_status - check the adapter configuration
340 * @common: adapter to query
341 *
342 * Query config status, and commit the configuration if needed.
343 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700344int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
346 int status = 0;
347 struct fib * fibptr;
348
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800349 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return -ENOMEM;
351
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800352 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 {
354 struct aac_get_config_status *dinfo;
355 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
356
357 dinfo->command = cpu_to_le32(VM_ContainerConfig);
358 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
359 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
360 }
361
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800362 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 fibptr,
364 sizeof (struct aac_get_config_status),
365 FsaNormal,
366 1, 1,
367 NULL, NULL);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800368 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
370 } else {
371 struct aac_get_config_status_resp *reply
372 = (struct aac_get_config_status_resp *) fib_data(fibptr);
373 dprintk((KERN_WARNING
374 "aac_get_config_status: response=%d status=%d action=%d\n",
375 le32_to_cpu(reply->response),
376 le32_to_cpu(reply->status),
377 le32_to_cpu(reply->data.action)));
378 if ((le32_to_cpu(reply->response) != ST_OK) ||
379 (le32_to_cpu(reply->status) != CT_OK) ||
380 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
381 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
382 status = -EINVAL;
383 }
384 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530385 /* Do not set XferState to zero unless receives a response from F/W */
386 if (status >= 0)
387 aac_fib_complete(fibptr);
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
390 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400391 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800393 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 dinfo = (struct aac_commit_config *) fib_data(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 dinfo->command = cpu_to_le32(VM_ContainerConfig);
397 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800398
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800399 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 fibptr,
401 sizeof (struct aac_commit_config),
402 FsaNormal,
403 1, 1,
404 NULL, NULL);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530405 /* Do not set XferState to zero unless
406 * receives a response from F/W */
407 if (status >= 0)
408 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400409 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 printk(KERN_WARNING
411 "aac_get_config_status: Foreign device configurations are being ignored\n");
412 }
413 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530414 /* FIB should be freed only after getting the response from the F/W */
415 if (status != -ERESTARTSYS)
416 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 return status;
418}
419
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -0700420static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
421{
422 char inq_data;
423 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
424 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
425 inq_data &= 0xdf;
426 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
427 }
428}
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430/**
431 * aac_get_containers - list containers
432 * @common: adapter to probe
433 *
434 * Make a list of all containers on this controller
435 */
436int aac_get_containers(struct aac_dev *dev)
437{
438 struct fsa_dev_info *fsa_dev_ptr;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800439 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 int status = 0;
441 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 struct aac_get_container_count *dinfo;
443 struct aac_get_container_count_resp *dresp;
444 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
445
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800446 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 return -ENOMEM;
448
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800449 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
451 dinfo->command = cpu_to_le32(VM_ContainerConfig);
452 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
453
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800454 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 fibptr,
456 sizeof (struct aac_get_container_count),
457 FsaNormal,
458 1, 1,
459 NULL, NULL);
460 if (status >= 0) {
461 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
462 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Mahesh Rajashekharaa7129a52015-03-26 10:41:27 -0400463 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
464 AAC_OPTION_SUPPORTED_240_VOLUMES) {
465 maximum_num_containers =
466 le32_to_cpu(dresp->MaxSimpleVolumes);
467 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800468 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530470 /* FIB should be freed only after getting the response from the F/W */
471 if (status != -ERESTARTSYS)
472 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
475 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400476 fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700477 GFP_KERNEL);
478 if (!fsa_dev_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 dev->fsa_dev = fsa_dev_ptr;
482 dev->maximum_num_containers = maximum_num_containers;
483
Mark Haverkampfe76df42007-03-15 12:55:07 -0700484 for (index = 0; index < dev->maximum_num_containers; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 fsa_dev_ptr[index].devname[0] = '\0';
486
Mark Haverkampfe76df42007-03-15 12:55:07 -0700487 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Mark Haverkampfe76df42007-03-15 12:55:07 -0700489 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
491 break;
492 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 /*
495 * If there are no more containers, then stop asking.
496 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700497 if (++index >= status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 return status;
501}
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503static void get_container_name_callback(void *context, struct fib * fibptr)
504{
505 struct aac_get_name_resp * get_name_reply;
506 struct scsi_cmnd * scsicmd;
507
508 scsicmd = (struct scsi_cmnd *) context;
509
Mark Haverkamp03d44332007-03-15 10:27:45 -0700510 if (!aac_valid_context(scsicmd, fibptr))
511 return;
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700514 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
517 /* Failure is irrelevant, using default value instead */
518 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
519 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700520 char *sp = get_name_reply->data;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400521 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 while (*sp == ' ')
523 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700524 if (*sp) {
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900525 struct inquiry_data inq;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700526 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
527 int count = sizeof(d);
528 char *dp = d;
529 do {
530 *dp++ = (*sp) ? *sp++ : ' ';
531 } while (--count > 0);
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900532
533 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
534 memcpy(inq.inqd_pid, d, sizeof(d));
535 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
540
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800541 aac_fib_complete(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700542 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
545/**
546 * aac_get_container_name - get container name, none blocking.
547 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700548static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
550 int status;
551 struct aac_get_name *dinfo;
552 struct fib * cmd_fibcontext;
553 struct aac_dev * dev;
554
555 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
556
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800557 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800559 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
561
562 dinfo->command = cpu_to_le32(VM_ContainerConfig);
563 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700564 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
566
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800567 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800568 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -0400569 sizeof(struct aac_get_name_resp),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800570 FsaNormal,
571 0, 1,
572 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 /*
576 * Check that the command queued to the controller
577 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800578 if (status == -EINPROGRESS) {
579 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800581 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800582
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800583 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
584 aac_fib_complete(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 return -1;
586}
587
Mark Haverkampfe76df42007-03-15 12:55:07 -0700588static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
589{
590 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
591
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400592 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700593 return aac_scsi_cmd(scsicmd);
594
595 scsicmd->result = DID_NO_CONNECT << 16;
596 scsicmd->scsi_done(scsicmd);
597 return 0;
598}
599
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400600static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700601{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700602 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700603 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700604 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
605
Mark Haverkamp03d44332007-03-15 10:27:45 -0700606
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400607 if (!aac_valid_context(scsicmd, fibptr))
608 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700609
610 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400611 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700612 if (fsa_dev_ptr) {
613 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
614 fsa_dev_ptr += scmd_id(scsicmd);
615
616 if ((le32_to_cpu(dresp->status) == ST_OK) &&
617 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
618 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400619 if (!(fibptr->dev->supplement_adapter_info.SupportedOptions2 &
620 AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
621 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
622 fsa_dev_ptr->block_size = 0x200;
623 } else {
624 fsa_dev_ptr->block_size =
625 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
626 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700627 fsa_dev_ptr->valid = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -0400628 /* sense_key holds the current state of the spin-up */
629 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
630 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
631 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
632 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700633 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
634 fsa_dev_ptr->size
635 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
636 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
637 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
638 }
639 if ((fsa_dev_ptr->valid & 1) == 0)
640 fsa_dev_ptr->valid = 0;
641 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
642 }
643 aac_fib_complete(fibptr);
644 aac_fib_free(fibptr);
645 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
646 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400647 (*callback)(scsicmd);
648 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700649}
650
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400651static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700652{
653 struct scsi_cmnd * scsicmd;
654 struct aac_mount * dresp;
655 struct aac_query_mount *dinfo;
656 int status;
657
658 dresp = (struct aac_mount *) fib_data(fibptr);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400659 if (!(fibptr->dev->supplement_adapter_info.SupportedOptions2 &
660 AAC_OPTION_VARIABLE_BLOCK_SIZE))
661 dresp->mnt[0].capacityhigh = 0;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700662 if ((le32_to_cpu(dresp->status) != ST_OK) ||
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400663 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
664 _aac_probe_container2(context, fibptr);
665 return;
666 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700667 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700668
Mark Haverkamp03d44332007-03-15 10:27:45 -0700669 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400670 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700671
Mark Haverkampfe76df42007-03-15 12:55:07 -0700672 aac_fib_init(fibptr);
673
674 dinfo = (struct aac_query_mount *)fib_data(fibptr);
675
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400676 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
677 AAC_OPTION_VARIABLE_BLOCK_SIZE)
678 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
679 else
680 dinfo->command = cpu_to_le32(VM_NameServe64);
681
Mark Haverkampfe76df42007-03-15 12:55:07 -0700682 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
683 dinfo->type = cpu_to_le32(FT_FILESYS);
684
685 status = aac_fib_send(ContainerCommand,
686 fibptr,
687 sizeof(struct aac_query_mount),
688 FsaNormal,
689 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400690 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700691 (void *) scsicmd);
692 /*
693 * Check that the command queued to the controller
694 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400695 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700696 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400697 else if (status < 0) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700698 /* Inherit results from VM_NameServe, if any */
699 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400700 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700701 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700702}
703
704static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
705{
706 struct fib * fibptr;
707 int status = -ENOMEM;
708
709 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
710 struct aac_query_mount *dinfo;
711
712 aac_fib_init(fibptr);
713
714 dinfo = (struct aac_query_mount *)fib_data(fibptr);
715
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400716 if (fibptr->dev->supplement_adapter_info.SupportedOptions2 &
717 AAC_OPTION_VARIABLE_BLOCK_SIZE)
718 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
719 else
720 dinfo->command = cpu_to_le32(VM_NameServe);
721
Mark Haverkampfe76df42007-03-15 12:55:07 -0700722 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
723 dinfo->type = cpu_to_le32(FT_FILESYS);
724 scsicmd->SCp.ptr = (char *)callback;
725
726 status = aac_fib_send(ContainerCommand,
727 fibptr,
728 sizeof(struct aac_query_mount),
729 FsaNormal,
730 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400731 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700732 (void *) scsicmd);
733 /*
734 * Check that the command queued to the controller
735 */
736 if (status == -EINPROGRESS) {
737 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
738 return 0;
739 }
740 if (status < 0) {
741 scsicmd->SCp.ptr = NULL;
742 aac_fib_complete(fibptr);
743 aac_fib_free(fibptr);
744 }
745 }
746 if (status < 0) {
747 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
748 if (fsa_dev_ptr) {
749 fsa_dev_ptr += scmd_id(scsicmd);
750 if ((fsa_dev_ptr->valid & 1) == 0) {
751 fsa_dev_ptr->valid = 0;
752 return (*callback)(scsicmd);
753 }
754 }
755 }
756 return status;
757}
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800760 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 * @dev: device to query
762 * @cid: container identifier
763 *
764 * Queries the controller about the given volume. The volume information
765 * is updated in the struct fsa_dev_info structure rather than returned.
766 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700767static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
768{
769 scsicmd->device = NULL;
770 return 0;
771}
772
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800773int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700775 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
776 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Mark Haverkampfe76df42007-03-15 12:55:07 -0700779 if (!scsicmd || !scsidev) {
780 kfree(scsicmd);
781 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700782 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700784 scsicmd->list.next = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400785 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Mark Haverkampfe76df42007-03-15 12:55:07 -0700787 scsicmd->device = scsidev;
788 scsidev->sdev_state = 0;
789 scsidev->id = cid;
790 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Mark Haverkampfe76df42007-03-15 12:55:07 -0700792 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
793 while (scsicmd->device == scsidev)
794 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400795 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700796 status = scsicmd->SCp.Status;
797 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 return status;
799}
800
801/* Local Structure to set SCSI inquiry data strings */
802struct scsi_inq {
803 char vid[8]; /* Vendor ID */
804 char pid[16]; /* Product ID */
805 char prl[4]; /* Product Revision Level */
806};
807
808/**
809 * InqStrCopy - string merge
810 * @a: string to copy from
811 * @b: string to copy to
812 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800813 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 * without copying \0
815 */
816
817static void inqstrcpy(char *a, char *b)
818{
819
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800820 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 *b++ = *a++;
822}
823
824static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800825 "None",
826 "Volume",
827 "Mirror",
828 "Stripe",
829 "RAID5",
830 "SSRW",
831 "SSRO",
832 "Morph",
833 "Legacy",
834 "RAID4",
835 "RAID10",
836 "RAID00",
837 "V-MIRRORS",
838 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700840 "RAID5D",
841 "RAID5D0",
842 "RAID1E",
843 "RAID6",
844 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800845 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846};
847
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800848char * get_container_type(unsigned tindex)
849{
850 if (tindex >= ARRAY_SIZE(container_types))
851 tindex = ARRAY_SIZE(container_types) - 1;
852 return container_types[tindex];
853}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855/* Function: setinqstr
856 *
857 * Arguments: [1] pointer to void [1] int
858 *
859 * Purpose: Sets SCSI inquiry data strings for vendor, product
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300860 * and revision level. Allows strings to be set in platform dependent
861 * files instead of in OS dependent driver source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 */
863
Mark Haverkamp794d0602005-10-24 10:51:53 -0700864static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
866 struct scsi_inq *str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700869 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Mark Haverkamp794d0602005-10-24 10:51:53 -0700871 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
872 char * cp = dev->supplement_adapter_info.AdapterTypeText;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800873 int c;
874 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
875 inqstrcpy("SMC", str->vid);
876 else {
877 c = sizeof(str->vid);
878 while (*cp && *cp != ' ' && --c)
879 ++cp;
880 c = *cp;
881 *cp = '\0';
882 inqstrcpy (dev->supplement_adapter_info.AdapterTypeText,
883 str->vid);
884 *cp = c;
885 while (*cp && *cp != ' ')
886 ++cp;
887 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700888 while (*cp == ' ')
889 ++cp;
890 /* last six chars reserved for vol type */
891 c = 0;
892 if (strlen(cp) > sizeof(str->pid)) {
893 c = cp[sizeof(str->pid)];
894 cp[sizeof(str->pid)] = '\0';
895 }
896 inqstrcpy (cp, str->pid);
897 if (c)
898 cp[sizeof(str->pid)] = c;
899 } else {
900 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700901
902 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700903 /* last six chars reserved for vol type */
904 inqstrcpy (mp->model, str->pid);
905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Tobias Klauser6391a112006-06-08 22:23:48 -0700907 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 char *findit = str->pid;
909
910 for ( ; *findit != ' '; findit++); /* walk till we find a space */
911 /* RAID is superfluous in the context of a RAID device */
912 if (memcmp(findit-4, "RAID", 4) == 0)
913 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700914 if (((findit - str->pid) + strlen(container_types[tindex]))
915 < (sizeof(str->pid) + sizeof(str->prl)))
916 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918 inqstrcpy ("V1.0", str->prl);
919}
920
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400921static void get_container_serial_callback(void *context, struct fib * fibptr)
922{
923 struct aac_get_serial_resp * get_serial_reply;
924 struct scsi_cmnd * scsicmd;
925
926 BUG_ON(fibptr == NULL);
927
928 scsicmd = (struct scsi_cmnd *) context;
929 if (!aac_valid_context(scsicmd, fibptr))
930 return;
931
932 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
933 /* Failure is irrelevant, using default value instead */
934 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400935 /*Check to see if it's for VPD 0x83 or 0x80 */
936 if (scsicmd->cmnd[2] == 0x83) {
937 /* vpd page 0x83 - Device Identification Page */
938 int i;
939 TVPD_Page83 VPDPage83Data;
940
941 memset(((u8 *)&VPDPage83Data), 0,
942 sizeof(VPDPage83Data));
943
944 /* DIRECT_ACCESS_DEVIC */
945 VPDPage83Data.DeviceType = 0;
946 /* DEVICE_CONNECTED */
947 VPDPage83Data.DeviceTypeQualifier = 0;
948 /* VPD_DEVICE_IDENTIFIERS */
949 VPDPage83Data.PageCode = 0x83;
950 VPDPage83Data.Reserved = 0;
951 VPDPage83Data.PageLength =
952 sizeof(VPDPage83Data.IdDescriptorType1) +
953 sizeof(VPDPage83Data.IdDescriptorType2);
954
955 /* T10 Vendor Identifier Field Format */
956 /* VpdCodeSetAscii */
957 VPDPage83Data.IdDescriptorType1.CodeSet = 2;
958 /* VpdIdentifierTypeVendorId */
959 VPDPage83Data.IdDescriptorType1.IdentifierType = 1;
960 VPDPage83Data.IdDescriptorType1.IdentifierLength =
961 sizeof(VPDPage83Data.IdDescriptorType1) - 4;
962
963 /* "ADAPTEC " for adaptec */
964 memcpy(VPDPage83Data.IdDescriptorType1.VendId,
965 "ADAPTEC ",
966 sizeof(VPDPage83Data.IdDescriptorType1.VendId));
967 memcpy(VPDPage83Data.IdDescriptorType1.ProductId,
968 "ARRAY ",
969 sizeof(
970 VPDPage83Data.IdDescriptorType1.ProductId));
971
972 /* Convert to ascii based serial number.
973 * The LSB is the the end.
974 */
975 for (i = 0; i < 8; i++) {
976 u8 temp =
977 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
978 if (temp > 0x9) {
979 VPDPage83Data.IdDescriptorType1.SerialNumber[i] =
980 'A' + (temp - 0xA);
981 } else {
982 VPDPage83Data.IdDescriptorType1.SerialNumber[i] =
983 '0' + temp;
984 }
985 }
986
987 /* VpdCodeSetBinary */
988 VPDPage83Data.IdDescriptorType2.CodeSet = 1;
989 /* VpdIdentifierTypeEUI64 */
990 VPDPage83Data.IdDescriptorType2.IdentifierType = 2;
991 VPDPage83Data.IdDescriptorType2.IdentifierLength =
992 sizeof(VPDPage83Data.IdDescriptorType2) - 4;
993
994 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[0] = 0xD0;
995 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[1] = 0;
996 VPDPage83Data.IdDescriptorType2.EU64Id.VendId[2] = 0;
997
998 VPDPage83Data.IdDescriptorType2.EU64Id.Serial =
999 get_serial_reply->uid;
1000 VPDPage83Data.IdDescriptorType2.EU64Id.Reserved = 0;
1001
1002 /* Move the inquiry data to the response buffer. */
1003 scsi_sg_copy_from_buffer(scsicmd, &VPDPage83Data,
1004 sizeof(VPDPage83Data));
1005 } else {
1006 /* It must be for VPD 0x80 */
1007 char sp[13];
1008 /* EVPD bit set */
1009 sp[0] = INQD_PDT_DA;
1010 sp[1] = scsicmd->cmnd[2];
1011 sp[2] = 0;
1012 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1013 le32_to_cpu(get_serial_reply->uid));
1014 scsi_sg_copy_from_buffer(scsicmd, sp,
1015 sizeof(sp));
1016 }
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001017 }
1018
1019 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1020
1021 aac_fib_complete(fibptr);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001022 scsicmd->scsi_done(scsicmd);
1023}
1024
1025/**
1026 * aac_get_container_serial - get container serial, none blocking.
1027 */
1028static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1029{
1030 int status;
1031 struct aac_get_serial *dinfo;
1032 struct fib * cmd_fibcontext;
1033 struct aac_dev * dev;
1034
1035 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1036
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08001037 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001038
1039 aac_fib_init(cmd_fibcontext);
1040 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1041
1042 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1043 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1044 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1045
1046 status = aac_fib_send(ContainerCommand,
1047 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -04001048 sizeof(struct aac_get_serial_resp),
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001049 FsaNormal,
1050 0, 1,
1051 (fib_callback) get_container_serial_callback,
1052 (void *) scsicmd);
1053
1054 /*
1055 * Check that the command queued to the controller
1056 */
1057 if (status == -EINPROGRESS) {
1058 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1059 return 0;
1060 }
1061
1062 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1063 aac_fib_complete(cmd_fibcontext);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001064 return -1;
1065}
1066
1067/* Function: setinqserial
1068 *
1069 * Arguments: [1] pointer to void [1] int
1070 *
1071 * Purpose: Sets SCSI Unit Serial number.
1072 * This is a fake. We should read a proper
1073 * serial number from the container. <SuSE>But
1074 * without docs it's quite hard to do it :-)
1075 * So this will have to do in the meantime.</SuSE>
1076 */
1077
1078static int setinqserial(struct aac_dev *dev, void *data, int cid)
1079{
1080 /*
1081 * This breaks array migration.
1082 */
1083 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1084 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1085}
1086
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001087static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1088 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089{
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001090 u8 *sense_buf = (u8 *)sense_data;
1091 /* Sense data valid, err code 70h */
1092 sense_buf[0] = 0x70; /* No info field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 sense_buf[1] = 0; /* Segment number, always zero */
1094
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001095 sense_buf[2] = sense_key; /* Sense key */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 sense_buf[12] = sense_code; /* Additional sense code */
1098 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001099
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 if (sense_key == ILLEGAL_REQUEST) {
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001101 sense_buf[7] = 10; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001103 sense_buf[15] = bit_pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 /* Illegal parameter is in the parameter block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 if (sense_code == SENCODE_INVALID_CDB_FIELD)
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001106 sense_buf[15] |= 0xc0;/* Std sense key specific field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 /* Illegal parameter is in the CDB block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 sense_buf[16] = field_pointer >> 8; /* MSB */
1109 sense_buf[17] = field_pointer; /* LSB */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001110 } else
1111 sense_buf[7] = 6; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112}
1113
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001114static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1115{
1116 if (lba & 0xffffffff00000000LL) {
1117 int cid = scmd_id(cmd);
1118 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1119 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1120 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001121 set_sense(&dev->fsa_dev[cid].sense_data,
1122 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1123 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001124 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001125 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1126 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001127 cmd->scsi_done(cmd);
1128 return 1;
1129 }
1130 return 0;
1131}
1132
1133static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1134{
1135 return 0;
1136}
1137
1138static void io_callback(void *context, struct fib * fibptr);
1139
1140static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1141{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301142 struct aac_dev *dev = fib->dev;
1143 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301144 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001145
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301146 aac_fib_init(fib);
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -08001147 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1148 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1149 !dev->sync_mode) {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301150 struct aac_raw_io2 *readcmd2;
1151 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1152 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1153 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1154 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001155 readcmd2->byteCount = cpu_to_le32(count *
1156 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301157 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1158 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301159 ret = aac_build_sgraw2(cmd, readcmd2,
1160 dev->scsi_host_ptr->sg_tablesize);
1161 if (ret < 0)
1162 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301163 command = ContainerRawIo2;
1164 fibsize = sizeof(struct aac_raw_io2) +
1165 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1166 } else {
1167 struct aac_raw_io *readcmd;
1168 readcmd = (struct aac_raw_io *) fib_data(fib);
1169 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1170 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001171 readcmd->count = cpu_to_le32(count *
1172 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301173 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1174 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1175 readcmd->bpTotal = 0;
1176 readcmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301177 ret = aac_build_sgraw(cmd, &readcmd->sg);
1178 if (ret < 0)
1179 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301180 command = ContainerRawIo;
1181 fibsize = sizeof(struct aac_raw_io) +
1182 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1183 }
1184
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001185 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1186 /*
1187 * Now send the Fib to the adapter
1188 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301189 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001190 fib,
1191 fibsize,
1192 FsaNormal,
1193 0, 1,
1194 (fib_callback) io_callback,
1195 (void *) cmd);
1196}
1197
1198static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1199{
1200 u16 fibsize;
1201 struct aac_read64 *readcmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301202 long ret;
1203
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001204 aac_fib_init(fib);
1205 readcmd = (struct aac_read64 *) fib_data(fib);
1206 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1207 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1208 readcmd->sector_count = cpu_to_le16(count);
1209 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1210 readcmd->pad = 0;
1211 readcmd->flags = 0;
1212
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301213 ret = aac_build_sg64(cmd, &readcmd->sg);
1214 if (ret < 0)
1215 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001216 fibsize = sizeof(struct aac_read64) +
1217 ((le32_to_cpu(readcmd->sg.count) - 1) *
1218 sizeof (struct sgentry64));
1219 BUG_ON (fibsize > (fib->dev->max_fib_size -
1220 sizeof(struct aac_fibhdr)));
1221 /*
1222 * Now send the Fib to the adapter
1223 */
1224 return aac_fib_send(ContainerCommand64,
1225 fib,
1226 fibsize,
1227 FsaNormal,
1228 0, 1,
1229 (fib_callback) io_callback,
1230 (void *) cmd);
1231}
1232
1233static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1234{
1235 u16 fibsize;
1236 struct aac_read *readcmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001237 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301238 long ret;
1239
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001240 aac_fib_init(fib);
1241 readcmd = (struct aac_read *) fib_data(fib);
1242 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001243 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001244 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001245 readcmd->count = cpu_to_le32(count *
1246 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001247
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301248 ret = aac_build_sg(cmd, &readcmd->sg);
1249 if (ret < 0)
1250 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001251 fibsize = sizeof(struct aac_read) +
1252 ((le32_to_cpu(readcmd->sg.count) - 1) *
1253 sizeof (struct sgentry));
1254 BUG_ON (fibsize > (fib->dev->max_fib_size -
1255 sizeof(struct aac_fibhdr)));
1256 /*
1257 * Now send the Fib to the adapter
1258 */
1259 return aac_fib_send(ContainerCommand,
1260 fib,
1261 fibsize,
1262 FsaNormal,
1263 0, 1,
1264 (fib_callback) io_callback,
1265 (void *) cmd);
1266}
1267
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001268static 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 -08001269{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301270 struct aac_dev *dev = fib->dev;
1271 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301272 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001273
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301274 aac_fib_init(fib);
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -08001275 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1276 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1277 !dev->sync_mode) {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301278 struct aac_raw_io2 *writecmd2;
1279 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1280 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1281 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1282 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001283 writecmd2->byteCount = cpu_to_le32(count *
1284 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301285 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1286 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1287 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1288 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1289 cpu_to_le16(RIO2_IO_TYPE_WRITE);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301290 ret = aac_build_sgraw2(cmd, writecmd2,
1291 dev->scsi_host_ptr->sg_tablesize);
1292 if (ret < 0)
1293 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301294 command = ContainerRawIo2;
1295 fibsize = sizeof(struct aac_raw_io2) +
1296 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1297 } else {
1298 struct aac_raw_io *writecmd;
1299 writecmd = (struct aac_raw_io *) fib_data(fib);
1300 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1301 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001302 writecmd->count = cpu_to_le32(count *
1303 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301304 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1305 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1306 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1307 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1308 cpu_to_le16(RIO_TYPE_WRITE);
1309 writecmd->bpTotal = 0;
1310 writecmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301311 ret = aac_build_sgraw(cmd, &writecmd->sg);
1312 if (ret < 0)
1313 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301314 command = ContainerRawIo;
1315 fibsize = sizeof(struct aac_raw_io) +
1316 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1317 }
1318
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001319 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1320 /*
1321 * Now send the Fib to the adapter
1322 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301323 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001324 fib,
1325 fibsize,
1326 FsaNormal,
1327 0, 1,
1328 (fib_callback) io_callback,
1329 (void *) cmd);
1330}
1331
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001332static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001333{
1334 u16 fibsize;
1335 struct aac_write64 *writecmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301336 long ret;
1337
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001338 aac_fib_init(fib);
1339 writecmd = (struct aac_write64 *) fib_data(fib);
1340 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1341 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1342 writecmd->sector_count = cpu_to_le16(count);
1343 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1344 writecmd->pad = 0;
1345 writecmd->flags = 0;
1346
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301347 ret = aac_build_sg64(cmd, &writecmd->sg);
1348 if (ret < 0)
1349 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001350 fibsize = sizeof(struct aac_write64) +
1351 ((le32_to_cpu(writecmd->sg.count) - 1) *
1352 sizeof (struct sgentry64));
1353 BUG_ON (fibsize > (fib->dev->max_fib_size -
1354 sizeof(struct aac_fibhdr)));
1355 /*
1356 * Now send the Fib to the adapter
1357 */
1358 return aac_fib_send(ContainerCommand64,
1359 fib,
1360 fibsize,
1361 FsaNormal,
1362 0, 1,
1363 (fib_callback) io_callback,
1364 (void *) cmd);
1365}
1366
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001367static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001368{
1369 u16 fibsize;
1370 struct aac_write *writecmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001371 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301372 long ret;
1373
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001374 aac_fib_init(fib);
1375 writecmd = (struct aac_write *) fib_data(fib);
1376 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001377 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001378 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001379 writecmd->count = cpu_to_le32(count *
1380 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001381 writecmd->sg.count = cpu_to_le32(1);
1382 /* ->stable is not used - it did mean which type of write */
1383
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301384 ret = aac_build_sg(cmd, &writecmd->sg);
1385 if (ret < 0)
1386 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001387 fibsize = sizeof(struct aac_write) +
1388 ((le32_to_cpu(writecmd->sg.count) - 1) *
1389 sizeof (struct sgentry));
1390 BUG_ON (fibsize > (fib->dev->max_fib_size -
1391 sizeof(struct aac_fibhdr)));
1392 /*
1393 * Now send the Fib to the adapter
1394 */
1395 return aac_fib_send(ContainerCommand,
1396 fib,
1397 fibsize,
1398 FsaNormal,
1399 0, 1,
1400 (fib_callback) io_callback,
1401 (void *) cmd);
1402}
1403
1404static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1405{
1406 struct aac_srb * srbcmd;
1407 u32 flag;
1408 u32 timeout;
1409
1410 aac_fib_init(fib);
1411 switch(cmd->sc_data_direction){
1412 case DMA_TO_DEVICE:
1413 flag = SRB_DataOut;
1414 break;
1415 case DMA_BIDIRECTIONAL:
1416 flag = SRB_DataIn | SRB_DataOut;
1417 break;
1418 case DMA_FROM_DEVICE:
1419 flag = SRB_DataIn;
1420 break;
1421 case DMA_NONE:
1422 default: /* shuts up some versions of gcc */
1423 flag = SRB_NoDataXfer;
1424 break;
1425 }
1426
1427 srbcmd = (struct aac_srb*) fib_data(fib);
1428 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1429 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1430 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1431 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1432 srbcmd->flags = cpu_to_le32(flag);
Jens Axboe242f9dc2008-09-14 05:55:09 -07001433 timeout = cmd->request->timeout/HZ;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001434 if (timeout == 0)
1435 timeout = 1;
1436 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1437 srbcmd->retry_limit = 0; /* Obsolete parameter */
1438 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1439 return srbcmd;
1440}
1441
1442static void aac_srb_callback(void *context, struct fib * fibptr);
1443
1444static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1445{
1446 u16 fibsize;
1447 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301448 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001449
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301450 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1451 if (ret < 0)
1452 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001453 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001454
1455 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1456 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1457 /*
1458 * Build Scatter/Gather list
1459 */
1460 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1461 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1462 sizeof (struct sgentry64));
1463 BUG_ON (fibsize > (fib->dev->max_fib_size -
1464 sizeof(struct aac_fibhdr)));
1465
1466 /*
1467 * Now send the Fib to the adapter
1468 */
1469 return aac_fib_send(ScsiPortCommand64, fib,
1470 fibsize, FsaNormal, 0, 1,
1471 (fib_callback) aac_srb_callback,
1472 (void *) cmd);
1473}
1474
1475static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1476{
1477 u16 fibsize;
1478 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301479 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001480
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301481 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1482 if (ret < 0)
1483 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001484 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001485
1486 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1487 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1488 /*
1489 * Build Scatter/Gather list
1490 */
1491 fibsize = sizeof (struct aac_srb) +
1492 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1493 sizeof (struct sgentry));
1494 BUG_ON (fibsize > (fib->dev->max_fib_size -
1495 sizeof(struct aac_fibhdr)));
1496
1497 /*
1498 * Now send the Fib to the adapter
1499 */
1500 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1501 (fib_callback) aac_srb_callback, (void *) cmd);
1502}
1503
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001504static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1505{
Leubner, Achimd8e965072009-04-01 07:16:08 -07001506 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1507 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001508 return FAILED;
1509 return aac_scsi_32(fib, cmd);
1510}
1511
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512int aac_get_adapter_info(struct aac_dev* dev)
1513{
1514 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 int rcode;
1516 u32 tmp;
Mark Haverkamp84971732005-06-20 11:55:24 -07001517 struct aac_adapter_info *info;
1518 struct aac_bus_info *command;
1519 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001520
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001521 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 return -ENOMEM;
1523
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001524 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001525 info = (struct aac_adapter_info *) fib_data(fibptr);
1526 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001528 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001529 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001530 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001531 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07001532 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001533 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001534 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001536 if (rcode < 0) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301537 /* FIB should be freed only after
1538 * getting the response from the F/W */
1539 if (rcode != -ERESTARTSYS) {
1540 aac_fib_complete(fibptr);
1541 aac_fib_free(fibptr);
1542 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001543 return rcode;
1544 }
1545 memcpy(&dev->adapter_info, info, sizeof(*info));
1546
1547 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001548 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001549
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001550 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001551
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001552 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001553
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001554 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001555
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001556 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001557 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001558 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001559 FsaNormal,
1560 1, 1,
1561 NULL,
1562 NULL);
1563
1564 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001565 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301566 if (rcode == -ERESTARTSYS) {
1567 fibptr = aac_fib_alloc(dev);
1568 if (!fibptr)
1569 return -ENOMEM;
1570 }
1571
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Mark Haverkamp84971732005-06-20 11:55:24 -07001574
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001575 /*
1576 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07001577 */
1578
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001579 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07001580
1581 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1582
1583 memset(bus_info, 0, sizeof(*bus_info));
1584
1585 command = (struct aac_bus_info *)bus_info;
1586
1587 command->Command = cpu_to_le32(VM_Ioctl);
1588 command->ObjType = cpu_to_le32(FT_DRIVE);
1589 command->MethodId = cpu_to_le32(1);
1590 command->CtlCmd = cpu_to_le32(GetBusInfo);
1591
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001592 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07001593 fibptr,
1594 sizeof (*bus_info),
1595 FsaNormal,
1596 1, 1,
1597 NULL, NULL);
1598
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001599 /* reasoned default */
1600 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07001601 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1602 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1603 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1604 }
1605
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001606 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001607 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001608 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1609 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001610 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 dev->id,
1612 tmp>>24,
1613 (tmp>>16)&0xff,
1614 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001615 le32_to_cpu(dev->adapter_info.kernelbuild),
1616 (int)sizeof(dev->supplement_adapter_info.BuildDate),
1617 dev->supplement_adapter_info.BuildDate);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001618 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1619 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 dev->name, dev->id,
1621 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1622 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001623 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1624 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 dev->name, dev->id,
1626 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1627 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001628 buffer[0] = '\0';
Tony Jonesee959b02008-02-22 00:13:36 +01001629 if (aac_get_serial_number(
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001630 shost_to_class(dev->scsi_host_ptr), buffer))
1631 printk(KERN_INFO "%s%d: serial %s",
1632 dev->name, dev->id, buffer);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04001633 if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) {
1634 printk(KERN_INFO "%s%d: TSID %.*s\n",
1635 dev->name, dev->id,
1636 (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid),
1637 dev->supplement_adapter_info.VpdInfo.Tsid);
1638 }
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001639 if (!aac_check_reset || ((aac_check_reset == 1) &&
Salyzyn, Marka3940da2008-01-08 12:48:25 -08001640 (dev->supplement_adapter_info.SupportedOptions2 &
1641 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001642 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
1643 dev->name, dev->id);
1644 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001647 dev->cache_protected = 0;
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001648 dev->jbod = ((dev->supplement_adapter_info.FeatureBits &
1649 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 dev->nondasd_support = 0;
1651 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001652 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655 /*
1656 * If the firmware supports ROMB RAID/SCSI mode and we are currently
1657 * in RAID/SCSI mode, set the flag. For now if in this mode we will
1658 * force nondasd support on. If we decide to allow the non-dasd flag
1659 * additional changes changes will have to be made to support
1660 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
1661 * changed to support the new dev->raid_scsi_mode flag instead of
1662 * leaching off of the dev->nondasd_support flag. Also in linit.c the
1663 * function aac_detect will have to be modified where it sets up the
1664 * max number of channels based on the aac->nondasd_support flag only.
1665 */
1666 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
1667 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
1668 dev->nondasd_support = 1;
1669 dev->raid_scsi_mode = 1;
1670 }
1671 if (dev->raid_scsi_mode != 0)
1672 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
1673 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001674
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08001675 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001677 if (dev->nondasd_support && !dev->in_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Yang Hongyange9304382009-04-13 14:40:14 -07001680 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
Leubner, Achimd8e965072009-04-01 07:16:08 -07001681 dev->needs_dac = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 dev->dac_support = 0;
Leubner, Achimd8e965072009-04-01 07:16:08 -07001683 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
1684 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001685 if (!dev->in_reset)
1686 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
1687 dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 dev->dac_support = 1;
1689 }
1690
1691 if(dacmode != -1) {
1692 dev->dac_support = (dacmode!=0);
1693 }
Leubner, Achimd8e965072009-04-01 07:16:08 -07001694
1695 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
1696 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
1697 & AAC_QUIRK_SCSI_32)) {
1698 dev->nondasd_support = 0;
1699 dev->jbod = 0;
1700 expose_physicals = 0;
1701 }
1702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 if(dev->dac_support != 0) {
Yang Hongyang6a355282009-04-06 19:01:13 -07001704 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64)) &&
1705 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08001706 if (!dev->in_reset)
1707 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
1708 dev->name, dev->id);
Yang Hongyang284901a2009-04-06 19:01:15 -07001709 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32)) &&
1710 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
1712 dev->name, dev->id);
1713 dev->dac_support = 0;
1714 } else {
1715 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
1716 dev->name, dev->id);
1717 rcode = -ENOMEM;
1718 }
1719 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001720 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001721 * Deal with configuring for the individualized limits of each packet
1722 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001723 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001724 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001725 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
1726 ? aac_scsi_32_64
1727 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001728 : aac_scsi_32;
1729 if (dev->raw_io_interface) {
1730 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1731 ? aac_bounds_64
1732 : aac_bounds_32;
1733 dev->a_ops.adapter_read = aac_read_raw_io;
1734 dev->a_ops.adapter_write = aac_write_raw_io;
1735 } else {
1736 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001737 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001738 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001739 sizeof(struct aac_write) + sizeof(struct sgentry)) /
1740 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001741 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001742 dev->a_ops.adapter_read = aac_read_block64;
1743 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001744 /*
1745 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001746 */
1747 dev->scsi_host_ptr->sg_tablesize =
1748 (dev->max_fib_size -
1749 sizeof(struct aac_fibhdr) -
1750 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07001751 sizeof(struct sgentry64)) /
1752 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001753 } else {
1754 dev->a_ops.adapter_read = aac_read_block;
1755 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001756 }
1757 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07001758 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07001759 /*
1760 * Worst case size that could cause sg overflow when
1761 * we break up SG elements that are larger than 64KB.
1762 * Would be nice if we could tell the SCSI layer what
1763 * the maximum SG element size can be. Worst case is
1764 * (sg_tablesize-1) 4KB elements with one 64KB
1765 * element.
1766 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
1767 */
1768 dev->scsi_host_ptr->max_sectors =
1769 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
1770 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001771 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301772 /* FIB should be freed only after getting the response from the F/W */
1773 if (rcode != -ERESTARTSYS) {
1774 aac_fib_complete(fibptr);
1775 aac_fib_free(fibptr);
1776 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
1778 return rcode;
1779}
1780
1781
Mark Haverkampe53cb352005-08-03 15:39:09 -07001782static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783{
1784 struct aac_dev *dev;
1785 struct aac_read_reply *readreply;
1786 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 u32 cid;
1788
1789 scsicmd = (struct scsi_cmnd *) context;
1790
Mark Haverkamp03d44332007-03-15 10:27:45 -07001791 if (!aac_valid_context(scsicmd, fibptr))
1792 return;
1793
Salyzyn, Mark1a655042007-06-11 16:17:55 -04001794 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08001795 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001797 if (nblank(dprintk(x))) {
1798 u64 lba;
1799 switch (scsicmd->cmnd[0]) {
1800 case WRITE_6:
1801 case READ_6:
1802 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
1803 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1804 break;
1805 case WRITE_16:
1806 case READ_16:
1807 lba = ((u64)scsicmd->cmnd[2] << 56) |
1808 ((u64)scsicmd->cmnd[3] << 48) |
1809 ((u64)scsicmd->cmnd[4] << 40) |
1810 ((u64)scsicmd->cmnd[5] << 32) |
1811 ((u64)scsicmd->cmnd[6] << 24) |
1812 (scsicmd->cmnd[7] << 16) |
1813 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
1814 break;
1815 case WRITE_12:
1816 case READ_12:
1817 lba = ((u64)scsicmd->cmnd[2] << 24) |
1818 (scsicmd->cmnd[3] << 16) |
1819 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1820 break;
1821 default:
1822 lba = ((u64)scsicmd->cmnd[2] << 24) |
1823 (scsicmd->cmnd[3] << 16) |
1824 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1825 break;
1826 }
1827 printk(KERN_DEBUG
1828 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
1829 smp_processor_id(), (unsigned long long)lba, jiffies);
1830 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Eric Sesterhenn125e1872006-06-23 02:06:06 -07001832 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001833
1834 scsi_dma_unmap(scsicmd);
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 readreply = (struct aac_read_reply *)fib_data(fibptr);
Mark Salyzyn655d7222008-04-30 16:03:42 -04001837 switch (le32_to_cpu(readreply->status)) {
1838 case ST_OK:
1839 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1840 SAM_STAT_GOOD;
1841 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
1842 break;
1843 case ST_NOT_READY:
1844 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1845 SAM_STAT_CHECK_CONDITION;
1846 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
1847 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
1848 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1849 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1850 SCSI_SENSE_BUFFERSIZE));
1851 break;
1852 default:
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001853#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07001854 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001855 le32_to_cpu(readreply->status));
1856#endif
Mark Salyzyn655d7222008-04-30 16:03:42 -04001857 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1858 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001859 set_sense(&dev->fsa_dev[cid].sense_data,
1860 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1861 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001863 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1864 SCSI_SENSE_BUFFERSIZE));
Mark Salyzyn655d7222008-04-30 16:03:42 -04001865 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001867 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001869 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870}
1871
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001872static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001874 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 u32 count;
1876 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 struct aac_dev *dev;
1878 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001879 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
1881 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1882 /*
1883 * Get block address and transfer length
1884 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001885 switch (scsicmd->cmnd[0]) {
1886 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001887 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001889 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001890 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 count = scsicmd->cmnd[4];
1892
1893 if (count == 0)
1894 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001895 break;
1896 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001897 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001898
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001899 lba = ((u64)scsicmd->cmnd[2] << 56) |
1900 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001901 ((u64)scsicmd->cmnd[4] << 40) |
1902 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001903 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001904 (scsicmd->cmnd[7] << 16) |
1905 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001906 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001907 (scsicmd->cmnd[11] << 16) |
1908 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
1909 break;
1910 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001911 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001912
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001913 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001914 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001915 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
1916 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001917 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001918 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001919 break;
1920 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001921 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001923 lba = ((u64)scsicmd->cmnd[2] << 24) |
1924 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001925 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001927 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001929
1930 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
1931 cid = scmd_id(scsicmd);
1932 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1933 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1934 SAM_STAT_CHECK_CONDITION;
1935 set_sense(&dev->fsa_dev[cid].sense_data,
1936 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1937 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1938 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1939 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1940 SCSI_SENSE_BUFFERSIZE));
1941 scsicmd->scsi_done(scsicmd);
1942 return 1;
1943 }
1944
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001945 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001946 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001947 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001948 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 /*
1950 * Alocate and initialize a Fib
1951 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08001952 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001954 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
1956 /*
1957 * Check that the command queued to the controller
1958 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001959 if (status == -EINPROGRESS) {
1960 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08001962 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001963
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001964 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 /*
1966 * For some reason, the Fib didn't queue, return QUEUE_FULL
1967 */
1968 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001969 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001970 aac_fib_complete(cmd_fibcontext);
1971 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 return 0;
1973}
1974
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001975static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001977 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001979 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 struct aac_dev *dev;
1982 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07001983 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
1985 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1986 /*
1987 * Get block address and transfer length
1988 */
1989 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
1990 {
1991 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
1992 count = scsicmd->cmnd[4];
1993 if (count == 0)
1994 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001995 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001996 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07001997 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001998
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001999 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002000 ((u64)scsicmd->cmnd[3] << 48) |
2001 ((u64)scsicmd->cmnd[4] << 40) |
2002 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002003 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002004 (scsicmd->cmnd[7] << 16) |
2005 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2006 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2007 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002008 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002009 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002010 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002011
2012 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2013 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2014 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2015 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002016 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002018 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002019 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002021 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002023
2024 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2025 cid = scmd_id(scsicmd);
2026 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2027 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2028 SAM_STAT_CHECK_CONDITION;
2029 set_sense(&dev->fsa_dev[cid].sense_data,
2030 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2031 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2032 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2033 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2034 SCSI_SENSE_BUFFERSIZE));
2035 scsicmd->scsi_done(scsicmd);
2036 return 1;
2037 }
2038
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002039 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002041 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002042 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 /*
2044 * Allocate and initialize a Fib then setup a BlockWrite command
2045 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002046 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002048 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 /*
2051 * Check that the command queued to the controller
2052 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002053 if (status == -EINPROGRESS) {
2054 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 return 0;
2056 }
2057
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002058 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 /*
2060 * For some reason, the Fib didn't queue, return QUEUE_FULL
2061 */
2062 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002063 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002065 aac_fib_complete(cmd_fibcontext);
2066 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 return 0;
2068}
2069
2070static void synchronize_callback(void *context, struct fib *fibptr)
2071{
2072 struct aac_synchronize_reply *synchronizereply;
2073 struct scsi_cmnd *cmd;
2074
2075 cmd = context;
2076
Mark Haverkamp03d44332007-03-15 10:27:45 -07002077 if (!aac_valid_context(cmd, fibptr))
2078 return;
2079
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002080 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 smp_processor_id(), jiffies));
2082 BUG_ON(fibptr == NULL);
2083
2084
2085 synchronizereply = fib_data(fibptr);
2086 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002087 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2089 else {
2090 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002091 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002092 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002093 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 "synchronize_callback: synchronize failed, status = %d\n",
2095 le32_to_cpu(synchronizereply->status));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002096 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002098 set_sense(&dev->fsa_dev[cid].sense_data,
2099 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2100 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002102 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2103 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 }
2105
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002106 aac_fib_complete(fibptr);
2107 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002108 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109}
2110
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002111static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
2113 int status;
2114 struct fib *cmd_fibcontext;
2115 struct aac_synchronize *synchronizecmd;
2116 struct scsi_cmnd *cmd;
2117 struct scsi_device *sdev = scsicmd->device;
2118 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002119 struct aac_dev *aac;
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002120 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2121 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2122 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 unsigned long flags;
2124
2125 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002126 * Wait for all outstanding queued commands to complete to this
2127 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 */
2129 spin_lock_irqsave(&sdev->list_lock, flags);
2130 list_for_each_entry(cmd, &sdev->cmd_list, list)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002131 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2132 u64 cmnd_lba;
2133 u32 cmnd_count;
2134
2135 if (cmd->cmnd[0] == WRITE_6) {
2136 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2137 (cmd->cmnd[2] << 8) |
2138 cmd->cmnd[3];
2139 cmnd_count = cmd->cmnd[4];
2140 if (cmnd_count == 0)
2141 cmnd_count = 256;
2142 } else if (cmd->cmnd[0] == WRITE_16) {
2143 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2144 ((u64)cmd->cmnd[3] << 48) |
2145 ((u64)cmd->cmnd[4] << 40) |
2146 ((u64)cmd->cmnd[5] << 32) |
2147 ((u64)cmd->cmnd[6] << 24) |
2148 (cmd->cmnd[7] << 16) |
2149 (cmd->cmnd[8] << 8) |
2150 cmd->cmnd[9];
2151 cmnd_count = (cmd->cmnd[10] << 24) |
2152 (cmd->cmnd[11] << 16) |
2153 (cmd->cmnd[12] << 8) |
2154 cmd->cmnd[13];
2155 } else if (cmd->cmnd[0] == WRITE_12) {
2156 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2157 (cmd->cmnd[3] << 16) |
2158 (cmd->cmnd[4] << 8) |
2159 cmd->cmnd[5];
2160 cmnd_count = (cmd->cmnd[6] << 24) |
2161 (cmd->cmnd[7] << 16) |
2162 (cmd->cmnd[8] << 8) |
2163 cmd->cmnd[9];
2164 } else if (cmd->cmnd[0] == WRITE_10) {
2165 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2166 (cmd->cmnd[3] << 16) |
2167 (cmd->cmnd[4] << 8) |
2168 cmd->cmnd[5];
2169 cmnd_count = (cmd->cmnd[7] << 8) |
2170 cmd->cmnd[8];
2171 } else
2172 continue;
2173 if (((cmnd_lba + cmnd_count) < lba) ||
2174 (count && ((lba + count) < cmnd_lba)))
2175 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 ++active;
2177 break;
2178 }
2179
2180 spin_unlock_irqrestore(&sdev->list_lock, flags);
2181
2182 /*
2183 * Yield the processor (requeue for later)
2184 */
2185 if (active)
2186 return SCSI_MLQUEUE_DEVICE_BUSY;
2187
Salyzyn, Markf8583172007-10-30 15:50:49 -04002188 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002189 if (aac->in_reset)
2190 return SCSI_MLQUEUE_HOST_BUSY;
2191
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002193 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002195 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 return SCSI_MLQUEUE_HOST_BUSY;
2197
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002198 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
2200 synchronizecmd = fib_data(cmd_fibcontext);
2201 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2202 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002203 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002204 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2206
2207 /*
2208 * Now send the Fib to the adapter
2209 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002210 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 cmd_fibcontext,
2212 sizeof(struct aac_synchronize),
2213 FsaNormal,
2214 0, 1,
2215 (fib_callback)synchronize_callback,
2216 (void *)scsicmd);
2217
2218 /*
2219 * Check that the command queued to the controller
2220 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002221 if (status == -EINPROGRESS) {
2222 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002226 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002227 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2228 aac_fib_complete(cmd_fibcontext);
2229 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 return SCSI_MLQUEUE_HOST_BUSY;
2231}
2232
Mark Salyzyn655d7222008-04-30 16:03:42 -04002233static void aac_start_stop_callback(void *context, struct fib *fibptr)
2234{
2235 struct scsi_cmnd *scsicmd = context;
2236
2237 if (!aac_valid_context(scsicmd, fibptr))
2238 return;
2239
2240 BUG_ON(fibptr == NULL);
2241
2242 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2243
2244 aac_fib_complete(fibptr);
2245 aac_fib_free(fibptr);
2246 scsicmd->scsi_done(scsicmd);
2247}
2248
2249static int aac_start_stop(struct scsi_cmnd *scsicmd)
2250{
2251 int status;
2252 struct fib *cmd_fibcontext;
2253 struct aac_power_management *pmcmd;
2254 struct scsi_device *sdev = scsicmd->device;
2255 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2256
2257 if (!(aac->supplement_adapter_info.SupportedOptions2 &
2258 AAC_OPTION_POWER_MANAGEMENT)) {
2259 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2260 SAM_STAT_GOOD;
2261 scsicmd->scsi_done(scsicmd);
2262 return 0;
2263 }
2264
2265 if (aac->in_reset)
2266 return SCSI_MLQUEUE_HOST_BUSY;
2267
2268 /*
2269 * Allocate and initialize a Fib
2270 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002271 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
Mark Salyzyn655d7222008-04-30 16:03:42 -04002272
2273 aac_fib_init(cmd_fibcontext);
2274
2275 pmcmd = fib_data(cmd_fibcontext);
2276 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2277 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2278 /* Eject bit ignored, not relevant */
2279 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2280 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2281 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2282 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2283 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2284
2285 /*
2286 * Now send the Fib to the adapter
2287 */
2288 status = aac_fib_send(ContainerCommand,
2289 cmd_fibcontext,
2290 sizeof(struct aac_power_management),
2291 FsaNormal,
2292 0, 1,
2293 (fib_callback)aac_start_stop_callback,
2294 (void *)scsicmd);
2295
2296 /*
2297 * Check that the command queued to the controller
2298 */
2299 if (status == -EINPROGRESS) {
2300 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2301 return 0;
2302 }
2303
2304 aac_fib_complete(cmd_fibcontext);
2305 aac_fib_free(cmd_fibcontext);
2306 return SCSI_MLQUEUE_HOST_BUSY;
2307}
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309/**
2310 * aac_scsi_cmd() - Process SCSI command
2311 * @scsicmd: SCSI command block
2312 *
2313 * Emulate a SCSI command and queue the required request for the
2314 * aacraid firmware.
2315 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002316
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2318{
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002319 u32 cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 struct Scsi_Host *host = scsicmd->device->host;
2321 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2322 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002323
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002324 if (fsa_dev_ptr == NULL)
2325 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 /*
2327 * If the bus, id or lun is out of range, return fail
2328 * Test does not apply to ID 16, the pseudo id for the controller
2329 * itself.
2330 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002331 cid = scmd_id(scsicmd);
2332 if (cid != host->this_id) {
2333 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2334 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08002335 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 scsicmd->result = DID_NO_CONNECT << 16;
2337 scsicmd->scsi_done(scsicmd);
2338 return 0;
2339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
2341 /*
2342 * If the target container doesn't exist, it may have
2343 * been newly created
2344 */
Mark Salyzyn655d7222008-04-30 16:03:42 -04002345 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2346 (fsa_dev_ptr[cid].sense_data.sense_key ==
2347 NOT_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 switch (scsicmd->cmnd[0]) {
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002349 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002350 if (!(dev->raw_io_interface) ||
2351 !(dev->raw_io_64) ||
2352 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2353 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 case INQUIRY:
2355 case READ_CAPACITY:
2356 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002357 if (dev->in_reset)
2358 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07002359 return _aac_probe_container(scsicmd,
2360 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 default:
2362 break;
2363 }
2364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 } else { /* check for physical non-dasd devices */
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08002366 if (dev->nondasd_support || expose_physicals ||
2367 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002368 if (dev->in_reset)
2369 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 return aac_send_srb_fib(scsicmd);
2371 } else {
2372 scsicmd->result = DID_NO_CONNECT << 16;
2373 scsicmd->scsi_done(scsicmd);
2374 return 0;
2375 }
2376 }
2377 }
2378 /*
2379 * else Command for the controller itself
2380 */
2381 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002382 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 {
2384 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2385 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002386 set_sense(&dev->fsa_dev[cid].sense_data,
2387 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2388 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002390 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2391 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 scsicmd->scsi_done(scsicmd);
2393 return 0;
2394 }
2395
2396
2397 /* Handle commands here that don't really require going out to the adapter */
2398 switch (scsicmd->cmnd[0]) {
2399 case INQUIRY:
2400 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002401 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002403 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002404 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Leubner, Achimd8e965072009-04-01 07:16:08 -07002406 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002407 char *arr = (char *)&inq_data;
2408
2409 /* EVPD bit set */
2410 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2411 INQD_PDT_PROC : INQD_PDT_DA;
2412 if (scsicmd->cmnd[2] == 0) {
2413 /* supported vital product data pages */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002414 arr[3] = 3;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002415 arr[4] = 0x0;
2416 arr[5] = 0x80;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002417 arr[6] = 0x83;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002418 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002419 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2420 sizeof(inq_data));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002421 scsicmd->result = DID_OK << 16 |
2422 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2423 } else if (scsicmd->cmnd[2] == 0x80) {
2424 /* unit serial number page */
2425 arr[3] = setinqserial(dev, &arr[4],
2426 scmd_id(scsicmd));
2427 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002428 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2429 sizeof(inq_data));
Leubner, Achimd8e965072009-04-01 07:16:08 -07002430 if (aac_wwn != 2)
2431 return aac_get_container_serial(
2432 scsicmd);
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002433 scsicmd->result = DID_OK << 16 |
2434 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2435 } else if (scsicmd->cmnd[2] == 0x83) {
2436 /* vpd page 0x83 - Device Identification Page */
2437 char *sno = (char *)&inq_data;
2438 sno[3] = setinqserial(dev, &sno[4],
2439 scmd_id(scsicmd));
2440 if (aac_wwn != 2)
2441 return aac_get_container_serial(
2442 scsicmd);
Leubner, Achimd8e965072009-04-01 07:16:08 -07002443 scsicmd->result = DID_OK << 16 |
2444 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002445 } else {
2446 /* vpd page not implemented */
2447 scsicmd->result = DID_OK << 16 |
2448 COMMAND_COMPLETE << 8 |
2449 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002450 set_sense(&dev->fsa_dev[cid].sense_data,
2451 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2452 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002453 memcpy(scsicmd->sense_buffer,
2454 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002455 min_t(size_t,
2456 sizeof(dev->fsa_dev[cid].sense_data),
2457 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002458 }
2459 scsicmd->scsi_done(scsicmd);
2460 return 0;
2461 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002462 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002463 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 */
2464 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002466 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 /*
2468 * Set the Vendor, Product, and Revision Level
2469 * see: <vendor>.c i.e. aac.c
2470 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002471 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07002472 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002473 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002474 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2475 sizeof(inq_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2477 scsicmd->scsi_done(scsicmd);
2478 return 0;
2479 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002480 if (dev->in_reset)
2481 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07002482 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002483 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002484 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002485 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 }
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002487 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002488 if (!(dev->raw_io_interface) ||
2489 !(dev->raw_io_64) ||
2490 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2491 break;
2492 {
2493 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002494 char cp[13];
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002495 unsigned int alloc_len;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002496
2497 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2498 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002499 cp[0] = (capacity >> 56) & 0xff;
2500 cp[1] = (capacity >> 48) & 0xff;
2501 cp[2] = (capacity >> 40) & 0xff;
2502 cp[3] = (capacity >> 32) & 0xff;
2503 cp[4] = (capacity >> 24) & 0xff;
2504 cp[5] = (capacity >> 16) & 0xff;
2505 cp[6] = (capacity >> 8) & 0xff;
2506 cp[7] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002507 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2508 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2509 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2510 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002511 cp[12] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002512
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002513 alloc_len = ((scsicmd->cmnd[10] << 24)
2514 + (scsicmd->cmnd[11] << 16)
2515 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2516
2517 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002518 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002519 if (alloc_len < scsi_bufflen(scsicmd))
2520 scsi_set_resid(scsicmd,
2521 scsi_bufflen(scsicmd) - alloc_len);
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002522
2523 /* Do not cache partition table for arrays */
2524 scsicmd->device->removable = 1;
2525
2526 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2527 scsicmd->scsi_done(scsicmd);
2528
2529 return 0;
2530 }
2531
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 case READ_CAPACITY:
2533 {
2534 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002535 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002538 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 capacity = fsa_dev_ptr[cid].size - 1;
2540 else
2541 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002542
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 cp[0] = (capacity >> 24) & 0xff;
2544 cp[1] = (capacity >> 16) & 0xff;
2545 cp[2] = (capacity >> 8) & 0xff;
2546 cp[3] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002547 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2548 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2549 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2550 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002551 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002552 /* Do not cache partition table for arrays */
2553 scsicmd->device->removable = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002554 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2555 SAM_STAT_GOOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 scsicmd->scsi_done(scsicmd);
2557
2558 return 0;
2559 }
2560
2561 case MODE_SENSE:
2562 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002563 int mode_buf_length = 4;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002564 u32 capacity;
2565 aac_modep_data mpd;
2566
2567 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2568 capacity = fsa_dev_ptr[cid].size - 1;
2569 else
2570 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571
2572 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002573 memset((char *)&mpd, 0, sizeof(aac_modep_data));
2574
2575 /* Mode data length */
2576 mpd.hd.data_length = sizeof(mpd.hd) - 1;
2577 /* Medium type - default */
2578 mpd.hd.med_type = 0;
2579 /* Device-specific param,
2580 bit 8: 0/1 = write enabled/protected
2581 bit 4: 0/1 = FUA enabled */
2582 mpd.hd.dev_par = 0;
2583
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002584 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002585 mpd.hd.dev_par = 0x10;
2586 if (scsicmd->cmnd[1] & 0x8)
2587 mpd.hd.bd_length = 0; /* Block descriptor length */
2588 else {
2589 mpd.hd.bd_length = sizeof(mpd.bd);
2590 mpd.hd.data_length += mpd.hd.bd_length;
2591 mpd.bd.block_length[0] =
2592 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2593 mpd.bd.block_length[1] =
2594 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2595 mpd.bd.block_length[2] =
2596 fsa_dev_ptr[cid].block_size & 0xff;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002597
2598 mpd.mpc_buf[0] = scsicmd->cmnd[2];
2599 if (scsicmd->cmnd[2] == 0x1C) {
2600 /* page length */
2601 mpd.mpc_buf[1] = 0xa;
2602 /* Mode data length */
2603 mpd.hd.data_length = 23;
2604 } else {
2605 /* Mode data length */
2606 mpd.hd.data_length = 15;
2607 }
2608
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002609 if (capacity > 0xffffff) {
2610 mpd.bd.block_count[0] = 0xff;
2611 mpd.bd.block_count[1] = 0xff;
2612 mpd.bd.block_count[2] = 0xff;
2613 } else {
2614 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
2615 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
2616 mpd.bd.block_count[2] = capacity & 0xff;
2617 }
2618 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002619 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2620 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002621 mpd.hd.data_length += 3;
2622 mpd.mpc_buf[0] = 8;
2623 mpd.mpc_buf[1] = 1;
2624 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002625 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002626 mode_buf_length = sizeof(mpd);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002627 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002628
2629 if (mode_buf_length > scsicmd->cmnd[4])
2630 mode_buf_length = scsicmd->cmnd[4];
2631 else
2632 mode_buf_length = sizeof(mpd);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002633 scsi_sg_copy_from_buffer(scsicmd,
2634 (char *)&mpd,
2635 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2637 scsicmd->scsi_done(scsicmd);
2638
2639 return 0;
2640 }
2641 case MODE_SENSE_10:
2642 {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002643 u32 capacity;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002644 int mode_buf_length = 8;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002645 aac_modep10_data mpd10;
2646
2647 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2648 capacity = fsa_dev_ptr[cid].size - 1;
2649 else
2650 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
2652 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002653 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
2654 /* Mode data length (MSB) */
2655 mpd10.hd.data_length[0] = 0;
2656 /* Mode data length (LSB) */
2657 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
2658 /* Medium type - default */
2659 mpd10.hd.med_type = 0;
2660 /* Device-specific param,
2661 bit 8: 0/1 = write enabled/protected
2662 bit 4: 0/1 = FUA enabled */
2663 mpd10.hd.dev_par = 0;
2664
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002665 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002666 mpd10.hd.dev_par = 0x10;
2667 mpd10.hd.rsrvd[0] = 0; /* reserved */
2668 mpd10.hd.rsrvd[1] = 0; /* reserved */
2669 if (scsicmd->cmnd[1] & 0x8) {
2670 /* Block descriptor length (MSB) */
2671 mpd10.hd.bd_length[0] = 0;
2672 /* Block descriptor length (LSB) */
2673 mpd10.hd.bd_length[1] = 0;
2674 } else {
2675 mpd10.hd.bd_length[0] = 0;
2676 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
2677
2678 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
2679
2680 mpd10.bd.block_length[0] =
2681 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2682 mpd10.bd.block_length[1] =
2683 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2684 mpd10.bd.block_length[2] =
2685 fsa_dev_ptr[cid].block_size & 0xff;
2686
2687 if (capacity > 0xffffff) {
2688 mpd10.bd.block_count[0] = 0xff;
2689 mpd10.bd.block_count[1] = 0xff;
2690 mpd10.bd.block_count[2] = 0xff;
2691 } else {
2692 mpd10.bd.block_count[0] =
2693 (capacity >> 16) & 0xff;
2694 mpd10.bd.block_count[1] =
2695 (capacity >> 8) & 0xff;
2696 mpd10.bd.block_count[2] =
2697 capacity & 0xff;
2698 }
2699 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002700 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
2701 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002702 mpd10.hd.data_length[1] += 3;
2703 mpd10.mpc_buf[0] = 8;
2704 mpd10.mpc_buf[1] = 1;
2705 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002706 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002707 mode_buf_length = sizeof(mpd10);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002708 if (mode_buf_length > scsicmd->cmnd[8])
2709 mode_buf_length = scsicmd->cmnd[8];
2710 }
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002711 scsi_sg_copy_from_buffer(scsicmd,
2712 (char *)&mpd10,
2713 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
2715 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2716 scsicmd->scsi_done(scsicmd);
2717
2718 return 0;
2719 }
2720 case REQUEST_SENSE:
2721 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
2722 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data));
2723 memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data));
2724 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2725 scsicmd->scsi_done(scsicmd);
2726 return 0;
2727
2728 case ALLOW_MEDIUM_REMOVAL:
2729 dprintk((KERN_DEBUG "LOCK command.\n"));
2730 if (scsicmd->cmnd[4])
2731 fsa_dev_ptr[cid].locked = 1;
2732 else
2733 fsa_dev_ptr[cid].locked = 0;
2734
2735 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2736 scsicmd->scsi_done(scsicmd);
2737 return 0;
2738 /*
2739 * These commands are all No-Ops
2740 */
2741 case TEST_UNIT_READY:
Mark Salyzyn655d7222008-04-30 16:03:42 -04002742 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
2743 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2744 SAM_STAT_CHECK_CONDITION;
2745 set_sense(&dev->fsa_dev[cid].sense_data,
2746 NOT_READY, SENCODE_BECOMING_READY,
2747 ASENCODE_BECOMING_READY, 0, 0);
2748 memcpy(scsicmd->sense_buffer,
2749 &dev->fsa_dev[cid].sense_data,
2750 min_t(size_t,
2751 sizeof(dev->fsa_dev[cid].sense_data),
2752 SCSI_SENSE_BUFFERSIZE));
2753 scsicmd->scsi_done(scsicmd);
2754 return 0;
2755 }
2756 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 case RESERVE:
2758 case RELEASE:
2759 case REZERO_UNIT:
2760 case REASSIGN_BLOCKS:
2761 case SEEK_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2763 scsicmd->scsi_done(scsicmd);
2764 return 0;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002765
2766 case START_STOP:
2767 return aac_start_stop(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 }
2769
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002770 switch (scsicmd->cmnd[0])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 {
2772 case READ_6:
2773 case READ_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002774 case READ_12:
2775 case READ_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002776 if (dev->in_reset)
2777 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 /*
2779 * Hack to keep track of ordinal number of the device that
2780 * corresponds to a container. Needed to convert
2781 * containers to /dev/sd device names
2782 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002783
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002784 if (scsicmd->request->rq_disk)
2785 strlcpy(fsa_dev_ptr[cid].devname,
2786 scsicmd->request->rq_disk->disk_name,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002787 min(sizeof(fsa_dev_ptr[cid].devname),
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002788 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002789
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002790 return aac_read(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791
2792 case WRITE_6:
2793 case WRITE_10:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002794 case WRITE_12:
2795 case WRITE_16:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002796 if (dev->in_reset)
2797 return -1;
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002798 return aac_write(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799
2800 case SYNCHRONIZE_CACHE:
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002801 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2802 scsicmd->result = DID_OK << 16 |
2803 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2804 scsicmd->scsi_done(scsicmd);
2805 return 0;
2806 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 /* Issue FIB to tell Firmware to flush it's cache */
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002808 if ((aac_cache & 6) != 2)
2809 return aac_synchronize(scsicmd);
2810 /* FALLTHRU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 default:
2812 /*
2813 * Unhandled commands
2814 */
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002815 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002817 set_sense(&dev->fsa_dev[cid].sense_data,
2818 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2819 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002821 min_t(size_t,
2822 sizeof(dev->fsa_dev[cid].sense_data),
2823 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 scsicmd->scsi_done(scsicmd);
2825 return 0;
2826 }
2827}
2828
2829static int query_disk(struct aac_dev *dev, void __user *arg)
2830{
2831 struct aac_query_disk qd;
2832 struct fsa_dev_info *fsa_dev_ptr;
2833
2834 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002835 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07002836 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
2838 return -EFAULT;
2839 if (qd.cnum == -1)
Mark Haverkampe5718772006-03-27 09:43:25 -08002840 qd.cnum = qd.id;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002841 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 {
2843 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
2844 return -EINVAL;
2845 qd.instance = dev->scsi_host_ptr->host_no;
2846 qd.bus = 0;
2847 qd.id = CONTAINER_TO_ID(qd.cnum);
2848 qd.lun = CONTAINER_TO_LUN(qd.cnum);
2849 }
2850 else return -EINVAL;
2851
Salyzyn, Markfd622b12007-07-17 10:59:19 -04002852 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 qd.locked = fsa_dev_ptr[qd.cnum].locked;
2854 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
2855
2856 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
2857 qd.unmapped = 1;
2858 else
2859 qd.unmapped = 0;
2860
2861 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
2862 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
2863
2864 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
2865 return -EFAULT;
2866 return 0;
2867}
2868
2869static int force_delete_disk(struct aac_dev *dev, void __user *arg)
2870{
2871 struct aac_delete_disk dd;
2872 struct fsa_dev_info *fsa_dev_ptr;
2873
2874 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp65101352006-09-19 08:59:23 -07002875 if (!fsa_dev_ptr)
2876 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877
2878 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2879 return -EFAULT;
2880
2881 if (dd.cnum >= dev->maximum_num_containers)
2882 return -EINVAL;
2883 /*
2884 * Mark this container as being deleted.
2885 */
2886 fsa_dev_ptr[dd.cnum].deleted = 1;
2887 /*
2888 * Mark the container as no longer valid
2889 */
2890 fsa_dev_ptr[dd.cnum].valid = 0;
2891 return 0;
2892}
2893
2894static int delete_disk(struct aac_dev *dev, void __user *arg)
2895{
2896 struct aac_delete_disk dd;
2897 struct fsa_dev_info *fsa_dev_ptr;
2898
2899 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002900 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07002901 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
2903 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
2904 return -EFAULT;
2905
2906 if (dd.cnum >= dev->maximum_num_containers)
2907 return -EINVAL;
2908 /*
2909 * If the container is locked, it can not be deleted by the API.
2910 */
2911 if (fsa_dev_ptr[dd.cnum].locked)
2912 return -EBUSY;
2913 else {
2914 /*
2915 * Mark the container as no longer being valid.
2916 */
2917 fsa_dev_ptr[dd.cnum].valid = 0;
2918 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
2919 return 0;
2920 }
2921}
2922
2923int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
2924{
2925 switch (cmd) {
2926 case FSACTL_QUERY_DISK:
2927 return query_disk(dev, arg);
2928 case FSACTL_DELETE_DISK:
2929 return delete_disk(dev, arg);
2930 case FSACTL_FORCE_DELETE_DISK:
2931 return force_delete_disk(dev, arg);
2932 case FSACTL_GET_CONTAINERS:
2933 return aac_get_containers(dev);
2934 default:
2935 return -ENOTTY;
2936 }
2937}
2938
2939/**
2940 *
2941 * aac_srb_callback
2942 * @context: the context set in the fib - here it is scsi cmd
2943 * @fibptr: pointer to the fib
2944 *
2945 * Handles the completion of a scsi command to a non dasd device
2946 *
2947 */
2948
2949static void aac_srb_callback(void *context, struct fib * fibptr)
2950{
2951 struct aac_dev *dev;
2952 struct aac_srb_reply *srbreply;
2953 struct scsi_cmnd *scsicmd;
2954
2955 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07002956
2957 if (!aac_valid_context(scsicmd, fibptr))
2958 return;
2959
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002960 BUG_ON(fibptr == NULL);
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002961 dev = fibptr->dev;
2962
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04002963 scsi_dma_unmap(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04002965 /* expose physical device if expose_physicald flag is on */
2966 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
2967 && expose_physicals > 0)
2968 aac_expose_phy_device(scsicmd);
2969
2970 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05302973 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
2974 /* fast response */
2975 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
2976 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
2977 } else {
2978 /*
2979 * Calculate resid for sg
2980 */
2981 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
2982 - le32_to_cpu(srbreply->data_xfer_length));
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04002983 /*
2984 * First check the fib status
2985 */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002986
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04002987 if (le32_to_cpu(srbreply->status) != ST_OK) {
2988 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04002990 printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status));
2991 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
2992 SCSI_SENSE_BUFFERSIZE);
2993 scsicmd->result = DID_ERROR << 16
2994 | COMMAND_COMPLETE << 8
2995 | SAM_STAT_CHECK_CONDITION;
2996 memcpy(scsicmd->sense_buffer,
2997 srbreply->sense_data, len);
2998 }
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -07002999
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003000 /*
3001 * Next check the srb status
3002 */
3003 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3004 case SRB_STATUS_ERROR_RECOVERY:
3005 case SRB_STATUS_PENDING:
3006 case SRB_STATUS_SUCCESS:
Mark Haverkampbb08f922006-02-01 09:30:44 -08003007 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003009 case SRB_STATUS_DATA_OVERRUN:
3010 switch (scsicmd->cmnd[0]) {
3011 case READ_6:
3012 case WRITE_6:
3013 case READ_10:
3014 case WRITE_10:
3015 case READ_12:
3016 case WRITE_12:
3017 case READ_16:
3018 case WRITE_16:
3019 if (le32_to_cpu(srbreply->data_xfer_length)
3020 < scsicmd->underflow)
3021 printk(KERN_WARNING"aacraid: SCSI CMD underflow\n");
3022 else
3023 printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n");
3024 scsicmd->result = DID_ERROR << 16
3025 | COMMAND_COMPLETE << 8;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003026 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003027 case INQUIRY: {
3028 scsicmd->result = DID_OK << 16
3029 | COMMAND_COMPLETE << 8;
3030 break;
3031 }
3032 default:
3033 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3034 break;
3035 }
3036 break;
3037 case SRB_STATUS_ABORTED:
3038 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3039 break;
3040 case SRB_STATUS_ABORT_FAILED:
3041 /*
3042 * Not sure about this one - but assuming the
3043 * hba was trying to abort for some reason
3044 */
3045 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3046 break;
3047 case SRB_STATUS_PARITY_ERROR:
3048 scsicmd->result = DID_PARITY << 16
3049 | MSG_PARITY_ERROR << 8;
3050 break;
3051 case SRB_STATUS_NO_DEVICE:
3052 case SRB_STATUS_INVALID_PATH_ID:
3053 case SRB_STATUS_INVALID_TARGET_ID:
3054 case SRB_STATUS_INVALID_LUN:
3055 case SRB_STATUS_SELECTION_TIMEOUT:
3056 scsicmd->result = DID_NO_CONNECT << 16
3057 | COMMAND_COMPLETE << 8;
3058 break;
3059
3060 case SRB_STATUS_COMMAND_TIMEOUT:
3061 case SRB_STATUS_TIMEOUT:
3062 scsicmd->result = DID_TIME_OUT << 16
3063 | COMMAND_COMPLETE << 8;
3064 break;
3065
3066 case SRB_STATUS_BUSY:
3067 scsicmd->result = DID_BUS_BUSY << 16
3068 | COMMAND_COMPLETE << 8;
3069 break;
3070
3071 case SRB_STATUS_BUS_RESET:
3072 scsicmd->result = DID_RESET << 16
3073 | COMMAND_COMPLETE << 8;
3074 break;
3075
3076 case SRB_STATUS_MESSAGE_REJECTED:
3077 scsicmd->result = DID_ERROR << 16
3078 | MESSAGE_REJECT << 8;
3079 break;
3080 case SRB_STATUS_REQUEST_FLUSHED:
3081 case SRB_STATUS_ERROR:
3082 case SRB_STATUS_INVALID_REQUEST:
3083 case SRB_STATUS_REQUEST_SENSE_FAILED:
3084 case SRB_STATUS_NO_HBA:
3085 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3086 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3087 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3088 case SRB_STATUS_DELAYED_RETRY:
3089 case SRB_STATUS_BAD_FUNCTION:
3090 case SRB_STATUS_NOT_STARTED:
3091 case SRB_STATUS_NOT_IN_USE:
3092 case SRB_STATUS_FORCE_ABORT:
3093 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3094 default:
3095#ifdef AAC_DETAILED_STATUS_INFO
3096 printk(KERN_INFO "aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n",
3097 le32_to_cpu(srbreply->srb_status) & 0x3F,
3098 aac_get_status_string(
3099 le32_to_cpu(srbreply->srb_status) & 0x3F),
3100 scsicmd->cmnd[0],
3101 le32_to_cpu(srbreply->scsi_status));
3102#endif
3103 if ((scsicmd->cmnd[0] == ATA_12)
3104 || (scsicmd->cmnd[0] == ATA_16)) {
3105 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3106 scsicmd->result = DID_OK << 16
3107 | COMMAND_COMPLETE << 8;
3108 break;
3109 } else {
3110 scsicmd->result = DID_ERROR << 16
3111 | COMMAND_COMPLETE << 8;
3112 break;
3113 }
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003114 } else {
3115 scsicmd->result = DID_ERROR << 16
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003116 | COMMAND_COMPLETE << 8;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003117 break;
3118 }
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003119 }
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003120 if (le32_to_cpu(srbreply->scsi_status)
3121 == SAM_STAT_CHECK_CONDITION) {
3122 int len;
3123
3124 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3125 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3126 SCSI_SENSE_BUFFERSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127#ifdef AAC_DETAILED_STATUS_INFO
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003128 printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n",
3129 le32_to_cpu(srbreply->status), len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130#endif
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003131 memcpy(scsicmd->sense_buffer,
3132 srbreply->sense_data, len);
3133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 }
3135 /*
3136 * OR in the scsi status (already shifted up a bit)
3137 */
3138 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3139
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003140 aac_fib_complete(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07003141 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142}
3143
3144/**
3145 *
3146 * aac_send_scb_fib
3147 * @scsicmd: the scsi command block
3148 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003149 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 * scsicmd passed in.
3151 */
3152
3153static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3154{
3155 struct fib* cmd_fibcontext;
3156 struct aac_dev* dev;
3157 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158
Mark Haverkamp84971732005-06-20 11:55:24 -07003159 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08003160 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07003161 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 scsicmd->result = DID_NO_CONNECT << 16;
3163 scsicmd->scsi_done(scsicmd);
3164 return 0;
3165 }
3166
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 /*
3168 * Allocate and initialize a Fib then setup a BlockWrite command
3169 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08003170 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08003171
Mark Haverkampe8f32de2007-01-23 15:00:30 -08003172 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 /*
3175 * Check that the command queued to the controller
3176 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08003177 if (status == -EINPROGRESS) {
3178 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return 0;
3180 }
3181
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003182 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3183 aac_fib_complete(cmd_fibcontext);
3184 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
3186 return -1;
3187}
3188
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303189static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190{
3191 struct aac_dev *dev;
3192 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003193 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3196 // Get rid of old data
3197 psg->count = 0;
3198 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003199 psg->sg[0].count = 0;
3200
3201 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303202 if (nseg < 0)
3203 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003204 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 struct scatterlist *sg;
3206 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003208 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003210 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3212 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3213 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 }
3215 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003216 if (byte_count > scsi_bufflen(scsicmd)) {
3217 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3218 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003219 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003220 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 }
3222 /* Check for command underflow */
3223 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3224 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3225 byte_count, scsicmd->underflow);
3226 }
3227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 return byte_count;
3229}
3230
3231
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303232static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233{
3234 struct aac_dev *dev;
3235 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003236 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003237 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
3239 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3240 // Get rid of old data
3241 psg->count = 0;
3242 psg->sg[0].addr[0] = 0;
3243 psg->sg[0].addr[1] = 0;
3244 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003245
3246 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303247 if (nseg < 0)
3248 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003249 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 struct scatterlist *sg;
3251 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003253 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp1241f352006-03-27 09:44:23 -08003254 int count = sg_dma_len(sg);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003255 addr = sg_dma_address(sg);
3256 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3257 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
Mark Haverkamp1241f352006-03-27 09:44:23 -08003258 psg->sg[i].count = cpu_to_le32(count);
3259 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003261 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003263 if (byte_count > scsi_bufflen(scsicmd)) {
3264 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3265 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003266 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003267 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 }
3269 /* Check for command underflow */
3270 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3271 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3272 byte_count, scsicmd->underflow);
3273 }
3274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 return byte_count;
3276}
3277
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303278static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003279{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003280 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003281 int nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003282
3283 // Get rid of old data
3284 psg->count = 0;
3285 psg->sg[0].next = 0;
3286 psg->sg[0].prev = 0;
3287 psg->sg[0].addr[0] = 0;
3288 psg->sg[0].addr[1] = 0;
3289 psg->sg[0].count = 0;
3290 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003291
3292 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303293 if (nseg < 0)
3294 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003295 if (nseg) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003296 struct scatterlist *sg;
3297 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003298
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003299 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003300 int count = sg_dma_len(sg);
3301 u64 addr = sg_dma_address(sg);
3302 psg->sg[i].next = 0;
3303 psg->sg[i].prev = 0;
3304 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
3305 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
3306 psg->sg[i].count = cpu_to_le32(count);
3307 psg->sg[i].flags = 0;
3308 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003309 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003310 psg->count = cpu_to_le32(nseg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003311 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003312 if (byte_count > scsi_bufflen(scsicmd)) {
3313 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3314 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003315 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003316 byte_count = scsi_bufflen(scsicmd);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003317 }
3318 /* Check for command underflow */
3319 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3320 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3321 byte_count, scsicmd->underflow);
3322 }
3323 }
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003324 return byte_count;
3325}
3326
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303327static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
3328 struct aac_raw_io2 *rio2, int sg_max)
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303329{
3330 unsigned long byte_count = 0;
3331 int nseg;
3332
3333 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303334 if (nseg < 0)
3335 return nseg;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303336 if (nseg) {
3337 struct scatterlist *sg;
3338 int i, conformable = 0;
3339 u32 min_size = PAGE_SIZE, cur_size;
3340
3341 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3342 int count = sg_dma_len(sg);
3343 u64 addr = sg_dma_address(sg);
3344
3345 BUG_ON(i >= sg_max);
3346 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3347 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3348 cur_size = cpu_to_le32(count);
3349 rio2->sge[i].length = cur_size;
3350 rio2->sge[i].flags = 0;
3351 if (i == 0) {
3352 conformable = 1;
3353 rio2->sgeFirstSize = cur_size;
3354 } else if (i == 1) {
3355 rio2->sgeNominalSize = cur_size;
3356 min_size = cur_size;
3357 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3358 conformable = 0;
3359 if (cur_size < min_size)
3360 min_size = cur_size;
3361 }
3362 byte_count += count;
3363 }
3364
3365 /* hba wants the size to be exact */
3366 if (byte_count > scsi_bufflen(scsicmd)) {
3367 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3368 (byte_count - scsi_bufflen(scsicmd));
3369 rio2->sge[i-1].length = cpu_to_le32(temp);
3370 byte_count = scsi_bufflen(scsicmd);
3371 }
3372
3373 rio2->sgeCnt = cpu_to_le32(nseg);
3374 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3375 /* not conformable: evaluate required sg elements */
3376 if (!conformable) {
3377 int j, nseg_new = nseg, err_found;
3378 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3379 err_found = 0;
3380 nseg_new = 2;
3381 for (j = 1; j < nseg - 1; ++j) {
3382 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3383 err_found = 1;
3384 break;
3385 }
3386 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3387 }
3388 if (!err_found)
3389 break;
3390 }
3391 if (i > 0 && nseg_new <= sg_max)
3392 aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3393 } else
3394 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3395
3396 /* Check for command underflow */
3397 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3398 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3399 byte_count, scsicmd->underflow);
3400 }
3401 }
3402
3403 return byte_count;
3404}
3405
3406static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3407{
3408 struct sge_ieee1212 *sge;
3409 int i, j, pos;
3410 u32 addr_low;
3411
3412 if (aac_convert_sgl == 0)
3413 return 0;
3414
3415 sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
3416 if (sge == NULL)
3417 return -1;
3418
3419 for (i = 1, pos = 1; i < nseg-1; ++i) {
3420 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
3421 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
3422 sge[pos].addrLow = addr_low;
3423 sge[pos].addrHigh = rio2->sge[i].addrHigh;
3424 if (addr_low < rio2->sge[i].addrLow)
3425 sge[pos].addrHigh++;
3426 sge[pos].length = pages * PAGE_SIZE;
3427 sge[pos].flags = 0;
3428 pos++;
3429 }
3430 }
3431 sge[pos] = rio2->sge[nseg-1];
3432 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
3433
3434 kfree(sge);
3435 rio2->sgeCnt = cpu_to_le32(nseg_new);
3436 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3437 rio2->sgeNominalSize = pages * PAGE_SIZE;
3438 return 0;
3439}
3440
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441#ifdef AAC_DETAILED_STATUS_INFO
3442
3443struct aac_srb_status_info {
3444 u32 status;
3445 char *str;
3446};
3447
3448
3449static struct aac_srb_status_info srb_status_info[] = {
3450 { SRB_STATUS_PENDING, "Pending Status"},
3451 { SRB_STATUS_SUCCESS, "Success"},
3452 { SRB_STATUS_ABORTED, "Aborted Command"},
3453 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07003454 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 { SRB_STATUS_BUSY, "Device Busy"},
3456 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
3457 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
3458 { SRB_STATUS_NO_DEVICE, "No Device"},
3459 { SRB_STATUS_TIMEOUT, "Timeout"},
3460 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
3461 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
3462 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
3463 { SRB_STATUS_BUS_RESET, "Bus Reset"},
3464 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
3465 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
3466 { SRB_STATUS_NO_HBA, "No HBA"},
3467 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
3468 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
3469 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
3470 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
3471 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
3472 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07003473 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
3475 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
3476 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
3477 { SRB_STATUS_NOT_STARTED, "Not Started"},
3478 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003479 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
3481 { 0xff, "Unknown Error"}
3482};
3483
3484char *aac_get_status_string(u32 status)
3485{
3486 int i;
3487
Tobias Klauser6391a112006-06-08 22:23:48 -07003488 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
3489 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491
3492 return "Bad Status Code";
3493}
3494
3495#endif