blob: a9831bd37a73d52462489d025c1631a576ca2fbc [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.
Raghava Aditya Renukuntaf4babba2017-02-02 15:53:36 -08009 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
Raghava Aditya Renukuntaf4babba2017-02-02 15:53:36 -080026 * Module Name:
27 * aachba.c
28 *
29 * Abstract: Contains Interfaces to manage IOs.
30 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 */
32
33#include <linux/kernel.h>
34#include <linux/init.h>
35#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/pci.h>
37#include <linux/spinlock.h>
38#include <linux/slab.h>
39#include <linux/completion.h>
40#include <linux/blkdev.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080041#include <linux/uaccess.h>
Salyzyn, Mark3a0086a82008-01-11 11:46:44 -080042#include <linux/highmem.h> /* For flush_kernel_dcache_page */
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040043#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -080045#include <asm/unaligned.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <scsi/scsi.h>
48#include <scsi/scsi_cmnd.h>
49#include <scsi/scsi_device.h>
50#include <scsi/scsi_host.h>
51
52#include "aacraid.h"
53
54/* values for inqd_pdt: Peripheral device type in plain English */
55#define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
56#define INQD_PDT_PROC 0x03 /* Processor device */
57#define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
58#define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
59#define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
60#define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
61
62#define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
63#define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/*
66 * Sense codes
67 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080068
69#define SENCODE_NO_SENSE 0x00
70#define SENCODE_END_OF_DATA 0x00
71#define SENCODE_BECOMING_READY 0x04
72#define SENCODE_INIT_CMD_REQUIRED 0x04
Raghava Aditya Renukuntaf956a662017-02-02 15:53:23 -080073#define SENCODE_UNRECOVERED_READ_ERROR 0x11
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080074#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
75#define SENCODE_INVALID_COMMAND 0x20
76#define SENCODE_LBA_OUT_OF_RANGE 0x21
77#define SENCODE_INVALID_CDB_FIELD 0x24
78#define SENCODE_LUN_NOT_SUPPORTED 0x25
79#define SENCODE_INVALID_PARAM_FIELD 0x26
80#define SENCODE_PARAM_NOT_SUPPORTED 0x26
81#define SENCODE_PARAM_VALUE_INVALID 0x26
82#define SENCODE_RESET_OCCURRED 0x29
83#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
84#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
85#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
86#define SENCODE_DIAGNOSTIC_FAILURE 0x40
87#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
88#define SENCODE_INVALID_MESSAGE_ERROR 0x49
89#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
90#define SENCODE_OVERLAPPED_COMMAND 0x4E
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/*
93 * Additional sense codes
94 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080095
96#define ASENCODE_NO_SENSE 0x00
97#define ASENCODE_END_OF_DATA 0x05
98#define ASENCODE_BECOMING_READY 0x01
99#define ASENCODE_INIT_CMD_REQUIRED 0x02
100#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
101#define ASENCODE_INVALID_COMMAND 0x00
102#define ASENCODE_LBA_OUT_OF_RANGE 0x00
103#define ASENCODE_INVALID_CDB_FIELD 0x00
104#define ASENCODE_LUN_NOT_SUPPORTED 0x00
105#define ASENCODE_INVALID_PARAM_FIELD 0x00
106#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
107#define ASENCODE_PARAM_VALUE_INVALID 0x02
108#define ASENCODE_RESET_OCCURRED 0x00
109#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
110#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
111#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
112#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
113#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
114#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
115#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
116#define ASENCODE_OVERLAPPED_COMMAND 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -0800118#define AAC_STAT_GOOD (DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD)
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#define BYTE0(x) (unsigned char)(x)
121#define BYTE1(x) (unsigned char)((x) >> 8)
122#define BYTE2(x) (unsigned char)((x) >> 16)
123#define BYTE3(x) (unsigned char)((x) >> 24)
124
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400125/* MODE_SENSE data format */
126typedef struct {
127 struct {
128 u8 data_length;
129 u8 med_type;
130 u8 dev_par;
131 u8 bd_length;
132 } __attribute__((packed)) hd;
133 struct {
134 u8 dens_code;
135 u8 block_count[3];
136 u8 reserved;
137 u8 block_length[3];
138 } __attribute__((packed)) bd;
139 u8 mpc_buf[3];
140} __attribute__((packed)) aac_modep_data;
141
142/* MODE_SENSE_10 data format */
143typedef struct {
144 struct {
145 u8 data_length[2];
146 u8 med_type;
147 u8 dev_par;
148 u8 rsrvd[2];
149 u8 bd_length[2];
150 } __attribute__((packed)) hd;
151 struct {
152 u8 dens_code;
153 u8 block_count[3];
154 u8 reserved;
155 u8 block_length[3];
156 } __attribute__((packed)) bd;
157 u8 mpc_buf[3];
158} __attribute__((packed)) aac_modep10_data;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160/*------------------------------------------------------------------------------
161 * S T R U C T S / T Y P E D E F S
162 *----------------------------------------------------------------------------*/
163/* SCSI inquiry data */
164struct inquiry_data {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800165 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
166 u8 inqd_dtq; /* RMB | Device Type Qualifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
168 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
169 u8 inqd_len; /* Additional length (n-4) */
170 u8 inqd_pad1[2];/* Reserved - must be zero */
171 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
172 u8 inqd_vid[8]; /* Vendor ID */
173 u8 inqd_pid[16];/* Product ID */
174 u8 inqd_prl[4]; /* Product Revision Level */
175};
176
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400177/* Added for VPD 0x83 */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800178struct tvpd_id_descriptor_type_1 {
179 u8 codeset:4; /* VPD_CODE_SET */
180 u8 reserved:4;
181 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
182 u8 reserved2:4;
183 u8 reserved3;
184 u8 identifierlength;
185 u8 venid[8];
186 u8 productid[16];
187 u8 serialnumber[8]; /* SN in ASCII */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400188
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800189};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400190
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800191struct tvpd_id_descriptor_type_2 {
192 u8 codeset:4; /* VPD_CODE_SET */
193 u8 reserved:4;
194 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
195 u8 reserved2:4;
196 u8 reserved3;
197 u8 identifierlength;
198 struct teu64id {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400199 u32 Serial;
200 /* The serial number supposed to be 40 bits,
201 * bit we only support 32, so make the last byte zero. */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800202 u8 reserved;
203 u8 venid[3];
204 } eu64id;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400205
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800206};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400207
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800208struct tvpd_id_descriptor_type_3 {
209 u8 codeset : 4; /* VPD_CODE_SET */
210 u8 reserved : 4;
211 u8 identifiertype : 4; /* VPD_IDENTIFIER_TYPE */
212 u8 reserved2 : 4;
213 u8 reserved3;
214 u8 identifierlength;
215 u8 Identifier[16];
216};
217
218struct tvpd_page83 {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400219 u8 DeviceType:5;
220 u8 DeviceTypeQualifier:3;
221 u8 PageCode;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800222 u8 reserved;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400223 u8 PageLength;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800224 struct tvpd_id_descriptor_type_1 type1;
225 struct tvpd_id_descriptor_type_2 type2;
226 struct tvpd_id_descriptor_type_3 type3;
227};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/*
230 * M O D U L E G L O B A L S
231 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800232
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +0530233static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
234static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
235static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
236static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
237 struct aac_raw_io2 *rio2, int sg_max);
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -0800238static long aac_build_sghba(struct scsi_cmnd *scsicmd,
239 struct aac_hba_cmd_req *hbacmd,
240 int sg_max, u64 sg_address);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +0530241static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
242 int pages, int nseg, int nseg_new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -0800244static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#ifdef AAC_DETAILED_STATUS_INFO
246static char *aac_get_status_string(u32 status);
247#endif
248
249/*
250 * Non dasd selection is handled entirely in aachba now
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800251 */
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static int nondasd = -1;
Leubner, Achimd8e965072009-04-01 07:16:08 -0700254static int aac_cache = 2; /* WCE=0 to avoid performance problems */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255static int dacmode = -1;
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800256int aac_msi;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400257int aac_commit = -1;
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700258int startup_timeout = 180;
259int aif_timeout = 120;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800260int aac_sync_mode; /* Only Sync. transfer - disabled */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530261int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800263module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
264MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
265 " 0=off, 1=on");
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530266module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
267MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
268 " 0=off, 1=on");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800269module_param(nondasd, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800270MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
271 " 0=off, 1=on");
Salyzyn, Mark95e852e2008-01-08 12:01:07 -0800272module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800273MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
274 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
275 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
Leubner, Achimd8e965072009-04-01 07:16:08 -0700276 "\tbit 2 - Disable only if Battery is protecting Cache");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800277module_param(dacmode, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800278MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
279 " 0=off, 1=on");
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400280module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800281MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
282 " adapter for foreign arrays.\n"
283 "This is typically needed in systems that do not have a BIOS."
284 " 0=off, 1=on");
285module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
286MODULE_PARM_DESC(msi, "IRQ handling."
Mahesh Rajashekhara9022d372015-08-28 06:38:35 -0400287 " 0=PIC(default), 1=MSI, 2=MSI-X)");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700288module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800289MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
290 " adapter to have it's kernel up and\n"
291 "running. This is typically adjusted for large systems that do not"
292 " have a BIOS.");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700293module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800294MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
295 " applications to pick up AIFs before\n"
296 "deregistering them. This is typically adjusted for heavily burdened"
297 " systems.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Raghava Aditya Renukunta09624642017-02-16 12:51:22 -0800299int aac_fib_dump;
300module_param(aac_fib_dump, int, 0644);
301MODULE_PARM_DESC(aac_fib_dump, "Dump controller fibs prior to IOP_RESET 0=off, 1=on");
302
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700303int numacb = -1;
304module_param(numacb, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800305MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
306 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
307 " to use suggestion from Firmware.");
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700308
309int acbsize = -1;
310module_param(acbsize, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800311MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
312 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
313 " suggestion from Firmware.");
Mark Haverkamp653ba582006-09-19 08:59:43 -0700314
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400315int update_interval = 30 * 60;
316module_param(update_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800317MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
318 " updates issued to adapter.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400319
Raghava Aditya Renukunta11da1b72017-02-16 12:51:19 -0800320int check_interval = 60;
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400321module_param(check_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800322MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
323 " checks.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400324
Andrew Morton87f3bda2007-08-10 14:50:30 -0700325int aac_check_reset = 1;
326module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
Paul Bolle95e7a8e2008-04-16 14:43:00 +0200327MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800328 " adapter. a value of -1 forces the reset to adapters programmed to"
329 " ignore it.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400330
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800331int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700332module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800333MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
334 " -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700335
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800336int aac_reset_devices;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400337module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
338MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700339
Leubner, Achimd8e965072009-04-01 07:16:08 -0700340int aac_wwn = 1;
341module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
342MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
343 "\t0 - Disable\n"
344 "\t1 - Array Meta Data Signature (default)\n"
345 "\t2 - Adapter Serial Number");
346
347
Mark Haverkamp03d44332007-03-15 10:27:45 -0700348static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
349 struct fib *fibptr) {
350 struct scsi_device *device;
351
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800352 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
Salyzyn, Markc835e372007-07-26 14:20:02 -0400353 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800354 aac_fib_complete(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800355 return 0;
356 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700357 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
358 device = scsicmd->device;
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800359 if (unlikely(!device)) {
Mark Haverkamp03d44332007-03-15 10:27:45 -0700360 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
361 aac_fib_complete(fibptr);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700362 return 0;
363 }
364 return 1;
365}
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367/**
368 * aac_get_config_status - check the adapter configuration
369 * @common: adapter to query
370 *
371 * Query config status, and commit the configuration if needed.
372 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700373int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
375 int status = 0;
376 struct fib * fibptr;
377
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800378 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return -ENOMEM;
380
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800381 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 {
383 struct aac_get_config_status *dinfo;
384 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
385
386 dinfo->command = cpu_to_le32(VM_ContainerConfig);
387 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
388 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
389 }
390
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800391 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 fibptr,
393 sizeof (struct aac_get_config_status),
394 FsaNormal,
395 1, 1,
396 NULL, NULL);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800397 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
399 } else {
400 struct aac_get_config_status_resp *reply
401 = (struct aac_get_config_status_resp *) fib_data(fibptr);
402 dprintk((KERN_WARNING
403 "aac_get_config_status: response=%d status=%d action=%d\n",
404 le32_to_cpu(reply->response),
405 le32_to_cpu(reply->status),
406 le32_to_cpu(reply->data.action)));
407 if ((le32_to_cpu(reply->response) != ST_OK) ||
408 (le32_to_cpu(reply->status) != CT_OK) ||
409 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
410 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
411 status = -EINVAL;
412 }
413 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530414 /* Do not set XferState to zero unless receives a response from F/W */
415 if (status >= 0)
416 aac_fib_complete(fibptr);
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
419 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400420 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800422 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 dinfo = (struct aac_commit_config *) fib_data(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 dinfo->command = cpu_to_le32(VM_ContainerConfig);
426 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800427
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800428 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 fibptr,
430 sizeof (struct aac_commit_config),
431 FsaNormal,
432 1, 1,
433 NULL, NULL);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530434 /* Do not set XferState to zero unless
435 * receives a response from F/W */
436 if (status >= 0)
437 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400438 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 printk(KERN_WARNING
440 "aac_get_config_status: Foreign device configurations are being ignored\n");
441 }
442 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530443 /* FIB should be freed only after getting the response from the F/W */
444 if (status != -ERESTARTSYS)
445 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return status;
447}
448
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -0700449static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
450{
451 char inq_data;
452 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
453 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
454 inq_data &= 0xdf;
455 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
456 }
457}
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459/**
460 * aac_get_containers - list containers
461 * @common: adapter to probe
462 *
463 * Make a list of all containers on this controller
464 */
465int aac_get_containers(struct aac_dev *dev)
466{
467 struct fsa_dev_info *fsa_dev_ptr;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800468 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 int status = 0;
470 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 struct aac_get_container_count *dinfo;
472 struct aac_get_container_count_resp *dresp;
473 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
474
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800475 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return -ENOMEM;
477
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800478 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
480 dinfo->command = cpu_to_le32(VM_ContainerConfig);
481 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
482
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800483 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 fibptr,
485 sizeof (struct aac_get_container_count),
486 FsaNormal,
487 1, 1,
488 NULL, NULL);
489 if (status >= 0) {
490 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
491 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800492 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharaa7129a52015-03-26 10:41:27 -0400493 AAC_OPTION_SUPPORTED_240_VOLUMES) {
494 maximum_num_containers =
495 le32_to_cpu(dresp->MaxSimpleVolumes);
496 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800497 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530499 /* FIB should be freed only after getting the response from the F/W */
500 if (status != -ERESTARTSYS)
501 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
504 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800505 if (dev->fsa_dev == NULL ||
506 dev->maximum_num_containers != maximum_num_containers) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800508 fsa_dev_ptr = dev->fsa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800510 dev->fsa_dev = kcalloc(maximum_num_containers,
511 sizeof(*fsa_dev_ptr), GFP_KERNEL);
512
513 kfree(fsa_dev_ptr);
514 fsa_dev_ptr = NULL;
515
516
517 if (!dev->fsa_dev)
518 return -ENOMEM;
519
520 dev->maximum_num_containers = maximum_num_containers;
521 }
522 for (index = 0; index < dev->maximum_num_containers; index++) {
523 dev->fsa_dev[index].devname[0] = '\0';
524 dev->fsa_dev[index].valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Mark Haverkampfe76df42007-03-15 12:55:07 -0700526 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Mark Haverkampfe76df42007-03-15 12:55:07 -0700528 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
530 break;
531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 return status;
534}
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536static void get_container_name_callback(void *context, struct fib * fibptr)
537{
538 struct aac_get_name_resp * get_name_reply;
539 struct scsi_cmnd * scsicmd;
540
541 scsicmd = (struct scsi_cmnd *) context;
542
Mark Haverkamp03d44332007-03-15 10:27:45 -0700543 if (!aac_valid_context(scsicmd, fibptr))
544 return;
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700547 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
550 /* Failure is irrelevant, using default value instead */
551 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
552 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700553 char *sp = get_name_reply->data;
Raghava Aditya Renukuntac8026732017-08-04 03:51:41 -0700554 int data_size = FIELD_SIZEOF(struct aac_get_name_resp, data);
555
556 sp[data_size - 1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 while (*sp == ' ')
558 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700559 if (*sp) {
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900560 struct inquiry_data inq;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700561 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
562 int count = sizeof(d);
563 char *dp = d;
564 do {
565 *dp++ = (*sp) ? *sp++ : ' ';
566 } while (--count > 0);
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900567
568 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
569 memcpy(inq.inqd_pid, d, sizeof(d));
570 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
575
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800576 aac_fib_complete(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700577 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
580/**
581 * aac_get_container_name - get container name, none blocking.
582 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700583static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
585 int status;
Raghava Aditya Renukuntac8026732017-08-04 03:51:41 -0700586 int data_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 struct aac_get_name *dinfo;
588 struct fib * cmd_fibcontext;
589 struct aac_dev * dev;
590
591 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
592
Raghava Aditya Renukuntac8026732017-08-04 03:51:41 -0700593 data_size = FIELD_SIZEOF(struct aac_get_name_resp, data);
594
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800595 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800597 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
Brian King1ae948f2017-08-29 10:00:29 -0500599 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 dinfo->command = cpu_to_le32(VM_ContainerConfig);
602 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700603 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Raghava Aditya Renukuntac8026732017-08-04 03:51:41 -0700604 dinfo->count = cpu_to_le32(data_size - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800606 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800607 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -0400608 sizeof(struct aac_get_name_resp),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800609 FsaNormal,
610 0, 1,
611 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 /*
615 * Check that the command queued to the controller
616 */
Brian King1ae948f2017-08-29 10:00:29 -0500617 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 return 0;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800619
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800620 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
621 aac_fib_complete(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 return -1;
623}
624
Mark Haverkampfe76df42007-03-15 12:55:07 -0700625static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
626{
627 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
628
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400629 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700630 return aac_scsi_cmd(scsicmd);
631
632 scsicmd->result = DID_NO_CONNECT << 16;
633 scsicmd->scsi_done(scsicmd);
634 return 0;
635}
636
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400637static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700638{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700639 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700640 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700641 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800642 int i;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700643
Mark Haverkamp03d44332007-03-15 10:27:45 -0700644
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400645 if (!aac_valid_context(scsicmd, fibptr))
646 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700647
648 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400649 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700650 if (fsa_dev_ptr) {
651 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800652 __le32 sup_options2;
653
Mark Haverkampfe76df42007-03-15 12:55:07 -0700654 fsa_dev_ptr += scmd_id(scsicmd);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800655 sup_options2 =
656 fibptr->dev->supplement_adapter_info.supported_options2;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700657
658 if ((le32_to_cpu(dresp->status) == ST_OK) &&
659 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
660 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800661 if (!(sup_options2 & AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400662 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
663 fsa_dev_ptr->block_size = 0x200;
664 } else {
665 fsa_dev_ptr->block_size =
666 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
667 }
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800668 for (i = 0; i < 16; i++)
669 fsa_dev_ptr->identifier[i] =
670 dresp->mnt[0].fileinfo.bdevinfo
671 .identifier[i];
Mark Haverkampfe76df42007-03-15 12:55:07 -0700672 fsa_dev_ptr->valid = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -0400673 /* sense_key holds the current state of the spin-up */
674 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
675 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
676 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
677 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700678 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
679 fsa_dev_ptr->size
680 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
681 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
682 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
683 }
684 if ((fsa_dev_ptr->valid & 1) == 0)
685 fsa_dev_ptr->valid = 0;
686 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
687 }
688 aac_fib_complete(fibptr);
689 aac_fib_free(fibptr);
690 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
691 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400692 (*callback)(scsicmd);
693 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700694}
695
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400696static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700697{
698 struct scsi_cmnd * scsicmd;
699 struct aac_mount * dresp;
700 struct aac_query_mount *dinfo;
701 int status;
702
703 dresp = (struct aac_mount *) fib_data(fibptr);
Dave Carroll6c92f7d2017-09-15 11:04:28 -0600704 if (!aac_supports_2T(fibptr->dev)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400705 dresp->mnt[0].capacityhigh = 0;
Dave Carroll6c92f7d2017-09-15 11:04:28 -0600706 if ((le32_to_cpu(dresp->status) == ST_OK) &&
707 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
708 _aac_probe_container2(context, fibptr);
709 return;
710 }
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400711 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700712 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700713
Mark Haverkamp03d44332007-03-15 10:27:45 -0700714 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400715 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700716
Mark Haverkampfe76df42007-03-15 12:55:07 -0700717 aac_fib_init(fibptr);
718
719 dinfo = (struct aac_query_mount *)fib_data(fibptr);
720
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800721 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400722 AAC_OPTION_VARIABLE_BLOCK_SIZE)
723 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
724 else
725 dinfo->command = cpu_to_le32(VM_NameServe64);
726
Mark Haverkampfe76df42007-03-15 12:55:07 -0700727 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
728 dinfo->type = cpu_to_le32(FT_FILESYS);
Brian King1ae948f2017-08-29 10:00:29 -0500729 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700730
731 status = aac_fib_send(ContainerCommand,
732 fibptr,
733 sizeof(struct aac_query_mount),
734 FsaNormal,
735 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400736 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700737 (void *) scsicmd);
738 /*
739 * Check that the command queued to the controller
740 */
Brian King1ae948f2017-08-29 10:00:29 -0500741 if (status < 0 && status != -EINPROGRESS) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700742 /* Inherit results from VM_NameServe, if any */
743 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400744 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700745 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700746}
747
748static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
749{
750 struct fib * fibptr;
751 int status = -ENOMEM;
752
753 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
754 struct aac_query_mount *dinfo;
755
756 aac_fib_init(fibptr);
757
758 dinfo = (struct aac_query_mount *)fib_data(fibptr);
759
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800760 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400761 AAC_OPTION_VARIABLE_BLOCK_SIZE)
762 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
763 else
764 dinfo->command = cpu_to_le32(VM_NameServe);
765
Mark Haverkampfe76df42007-03-15 12:55:07 -0700766 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
767 dinfo->type = cpu_to_le32(FT_FILESYS);
768 scsicmd->SCp.ptr = (char *)callback;
Brian King1ae948f2017-08-29 10:00:29 -0500769 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700770
771 status = aac_fib_send(ContainerCommand,
772 fibptr,
773 sizeof(struct aac_query_mount),
774 FsaNormal,
775 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400776 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700777 (void *) scsicmd);
778 /*
779 * Check that the command queued to the controller
780 */
Brian King1ae948f2017-08-29 10:00:29 -0500781 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700782 return 0;
Brian King1ae948f2017-08-29 10:00:29 -0500783
Mark Haverkampfe76df42007-03-15 12:55:07 -0700784 if (status < 0) {
785 scsicmd->SCp.ptr = NULL;
786 aac_fib_complete(fibptr);
787 aac_fib_free(fibptr);
788 }
789 }
790 if (status < 0) {
791 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
792 if (fsa_dev_ptr) {
793 fsa_dev_ptr += scmd_id(scsicmd);
794 if ((fsa_dev_ptr->valid & 1) == 0) {
795 fsa_dev_ptr->valid = 0;
796 return (*callback)(scsicmd);
797 }
798 }
799 }
800 return status;
801}
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800804 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 * @dev: device to query
806 * @cid: container identifier
807 *
808 * Queries the controller about the given volume. The volume information
809 * is updated in the struct fsa_dev_info structure rather than returned.
810 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700811static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
812{
813 scsicmd->device = NULL;
814 return 0;
815}
816
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800817int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700819 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
820 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Mark Haverkampfe76df42007-03-15 12:55:07 -0700823 if (!scsicmd || !scsidev) {
824 kfree(scsicmd);
825 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700826 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700828 scsicmd->list.next = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400829 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Mark Haverkampfe76df42007-03-15 12:55:07 -0700831 scsicmd->device = scsidev;
832 scsidev->sdev_state = 0;
833 scsidev->id = cid;
834 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Mark Haverkampfe76df42007-03-15 12:55:07 -0700836 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
837 while (scsicmd->device == scsidev)
838 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400839 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700840 status = scsicmd->SCp.Status;
841 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 return status;
843}
844
845/* Local Structure to set SCSI inquiry data strings */
846struct scsi_inq {
847 char vid[8]; /* Vendor ID */
848 char pid[16]; /* Product ID */
849 char prl[4]; /* Product Revision Level */
850};
851
852/**
853 * InqStrCopy - string merge
854 * @a: string to copy from
855 * @b: string to copy to
856 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800857 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 * without copying \0
859 */
860
861static void inqstrcpy(char *a, char *b)
862{
863
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800864 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 *b++ = *a++;
866}
867
868static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800869 "None",
870 "Volume",
871 "Mirror",
872 "Stripe",
873 "RAID5",
874 "SSRW",
875 "SSRO",
876 "Morph",
877 "Legacy",
878 "RAID4",
879 "RAID10",
880 "RAID00",
881 "V-MIRRORS",
882 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700884 "RAID5D",
885 "RAID5D0",
886 "RAID1E",
887 "RAID6",
888 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800889 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890};
891
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800892char * get_container_type(unsigned tindex)
893{
894 if (tindex >= ARRAY_SIZE(container_types))
895 tindex = ARRAY_SIZE(container_types) - 1;
896 return container_types[tindex];
897}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899/* Function: setinqstr
900 *
901 * Arguments: [1] pointer to void [1] int
902 *
903 * Purpose: Sets SCSI inquiry data strings for vendor, product
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300904 * and revision level. Allows strings to be set in platform dependent
905 * files instead of in OS dependent driver source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 */
907
Mark Haverkamp794d0602005-10-24 10:51:53 -0700908static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
910 struct scsi_inq *str;
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800911 struct aac_supplement_adapter_info *sup_adap_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800913 sup_adap_info = &dev->supplement_adapter_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700915 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800917 if (sup_adap_info->adapter_type_text[0]) {
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800918 int c;
Raghava Aditya Renukuntaf4e87082017-12-26 20:34:22 -0800919 char *cp;
920 char *cname = kmemdup(sup_adap_info->adapter_type_text,
921 sizeof(sup_adap_info->adapter_type_text),
922 GFP_ATOMIC);
Raghava Aditya Renukuntaf4e87082017-12-26 20:34:22 -0800923 if (!cname)
924 return;
925
926 cp = cname;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800927 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
928 inqstrcpy("SMC", str->vid);
929 else {
930 c = sizeof(str->vid);
931 while (*cp && *cp != ' ' && --c)
932 ++cp;
933 c = *cp;
934 *cp = '\0';
Raghava Aditya Renukuntaf4e87082017-12-26 20:34:22 -0800935 inqstrcpy(cname, str->vid);
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800936 *cp = c;
937 while (*cp && *cp != ' ')
938 ++cp;
939 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700940 while (*cp == ' ')
941 ++cp;
942 /* last six chars reserved for vol type */
Colin Ian King91814742018-01-05 15:31:06 +0000943 if (strlen(cp) > sizeof(str->pid))
Mark Haverkamp794d0602005-10-24 10:51:53 -0700944 cp[sizeof(str->pid)] = '\0';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700945 inqstrcpy (cp, str->pid);
Raghava Aditya Renukuntaf4e87082017-12-26 20:34:22 -0800946
947 kfree(cname);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700948 } else {
949 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700950
951 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700952 /* last six chars reserved for vol type */
953 inqstrcpy (mp->model, str->pid);
954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Tobias Klauser6391a112006-06-08 22:23:48 -0700956 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 char *findit = str->pid;
958
959 for ( ; *findit != ' '; findit++); /* walk till we find a space */
960 /* RAID is superfluous in the context of a RAID device */
961 if (memcmp(findit-4, "RAID", 4) == 0)
962 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700963 if (((findit - str->pid) + strlen(container_types[tindex]))
964 < (sizeof(str->pid) + sizeof(str->prl)))
965 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 }
967 inqstrcpy ("V1.0", str->prl);
968}
969
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800970static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
971 struct aac_dev *dev, struct scsi_cmnd *scsicmd)
972{
973 int container;
974
975 vpdpage83data->type3.codeset = 1;
976 vpdpage83data->type3.identifiertype = 3;
977 vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
978 - 4;
979
980 for (container = 0; container < dev->maximum_num_containers;
981 container++) {
982
983 if (scmd_id(scsicmd) == container) {
984 memcpy(vpdpage83data->type3.Identifier,
985 dev->fsa_dev[container].identifier,
986 16);
987 break;
988 }
989 }
990}
991
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400992static void get_container_serial_callback(void *context, struct fib * fibptr)
993{
994 struct aac_get_serial_resp * get_serial_reply;
995 struct scsi_cmnd * scsicmd;
996
997 BUG_ON(fibptr == NULL);
998
999 scsicmd = (struct scsi_cmnd *) context;
1000 if (!aac_valid_context(scsicmd, fibptr))
1001 return;
1002
1003 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
1004 /* Failure is irrelevant, using default value instead */
1005 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001006 /*Check to see if it's for VPD 0x83 or 0x80 */
1007 if (scsicmd->cmnd[2] == 0x83) {
1008 /* vpd page 0x83 - Device Identification Page */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001009 struct aac_dev *dev;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001010 int i;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001011 struct tvpd_page83 vpdpage83data;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001012
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001013 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1014
1015 memset(((u8 *)&vpdpage83data), 0,
1016 sizeof(vpdpage83data));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001017
1018 /* DIRECT_ACCESS_DEVIC */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001019 vpdpage83data.DeviceType = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001020 /* DEVICE_CONNECTED */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001021 vpdpage83data.DeviceTypeQualifier = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001022 /* VPD_DEVICE_IDENTIFIERS */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001023 vpdpage83data.PageCode = 0x83;
1024 vpdpage83data.reserved = 0;
1025 vpdpage83data.PageLength =
1026 sizeof(vpdpage83data.type1) +
1027 sizeof(vpdpage83data.type2);
1028
1029 /* VPD 83 Type 3 is not supported for ARC */
1030 if (dev->sa_firmware)
1031 vpdpage83data.PageLength +=
1032 sizeof(vpdpage83data.type3);
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001033
1034 /* T10 Vendor Identifier Field Format */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001035 /* VpdcodesetAscii */
1036 vpdpage83data.type1.codeset = 2;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001037 /* VpdIdentifierTypeVendorId */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001038 vpdpage83data.type1.identifiertype = 1;
1039 vpdpage83data.type1.identifierlength =
1040 sizeof(vpdpage83data.type1) - 4;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001041
1042 /* "ADAPTEC " for adaptec */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001043 memcpy(vpdpage83data.type1.venid,
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001044 "ADAPTEC ",
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001045 sizeof(vpdpage83data.type1.venid));
1046 memcpy(vpdpage83data.type1.productid,
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001047 "ARRAY ",
1048 sizeof(
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001049 vpdpage83data.type1.productid));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001050
1051 /* Convert to ascii based serial number.
1052 * The LSB is the the end.
1053 */
1054 for (i = 0; i < 8; i++) {
1055 u8 temp =
1056 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
1057 if (temp > 0x9) {
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001058 vpdpage83data.type1.serialnumber[i] =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001059 'A' + (temp - 0xA);
1060 } else {
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001061 vpdpage83data.type1.serialnumber[i] =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001062 '0' + temp;
1063 }
1064 }
1065
1066 /* VpdCodeSetBinary */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001067 vpdpage83data.type2.codeset = 1;
1068 /* VpdidentifiertypeEUI64 */
1069 vpdpage83data.type2.identifiertype = 2;
1070 vpdpage83data.type2.identifierlength =
1071 sizeof(vpdpage83data.type2) - 4;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001072
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001073 vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1074 vpdpage83data.type2.eu64id.venid[1] = 0;
1075 vpdpage83data.type2.eu64id.venid[2] = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001076
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001077 vpdpage83data.type2.eu64id.Serial =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001078 get_serial_reply->uid;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001079 vpdpage83data.type2.eu64id.reserved = 0;
1080
1081 /*
1082 * VpdIdentifierTypeFCPHName
1083 * VPD 0x83 Type 3 not supported for ARC
1084 */
1085 if (dev->sa_firmware) {
1086 build_vpd83_type3(&vpdpage83data,
1087 dev, scsicmd);
1088 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001089
1090 /* Move the inquiry data to the response buffer. */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001091 scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1092 sizeof(vpdpage83data));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001093 } else {
1094 /* It must be for VPD 0x80 */
1095 char sp[13];
1096 /* EVPD bit set */
1097 sp[0] = INQD_PDT_DA;
1098 sp[1] = scsicmd->cmnd[2];
1099 sp[2] = 0;
1100 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1101 le32_to_cpu(get_serial_reply->uid));
1102 scsi_sg_copy_from_buffer(scsicmd, sp,
1103 sizeof(sp));
1104 }
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001105 }
1106
1107 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1108
1109 aac_fib_complete(fibptr);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001110 scsicmd->scsi_done(scsicmd);
1111}
1112
1113/**
1114 * aac_get_container_serial - get container serial, none blocking.
1115 */
1116static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1117{
1118 int status;
1119 struct aac_get_serial *dinfo;
1120 struct fib * cmd_fibcontext;
1121 struct aac_dev * dev;
1122
1123 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1124
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08001125 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001126
1127 aac_fib_init(cmd_fibcontext);
1128 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1129
1130 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1131 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1132 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Brian King1ae948f2017-08-29 10:00:29 -05001133 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001134
1135 status = aac_fib_send(ContainerCommand,
1136 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -04001137 sizeof(struct aac_get_serial_resp),
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001138 FsaNormal,
1139 0, 1,
1140 (fib_callback) get_container_serial_callback,
1141 (void *) scsicmd);
1142
1143 /*
1144 * Check that the command queued to the controller
1145 */
Brian King1ae948f2017-08-29 10:00:29 -05001146 if (status == -EINPROGRESS)
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001147 return 0;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001148
1149 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1150 aac_fib_complete(cmd_fibcontext);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001151 return -1;
1152}
1153
1154/* Function: setinqserial
1155 *
1156 * Arguments: [1] pointer to void [1] int
1157 *
1158 * Purpose: Sets SCSI Unit Serial number.
1159 * This is a fake. We should read a proper
1160 * serial number from the container. <SuSE>But
1161 * without docs it's quite hard to do it :-)
1162 * So this will have to do in the meantime.</SuSE>
1163 */
1164
1165static int setinqserial(struct aac_dev *dev, void *data, int cid)
1166{
1167 /*
1168 * This breaks array migration.
1169 */
1170 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1171 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1172}
1173
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001174static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1175 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001177 u8 *sense_buf = (u8 *)sense_data;
1178 /* Sense data valid, err code 70h */
1179 sense_buf[0] = 0x70; /* No info field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 sense_buf[1] = 0; /* Segment number, always zero */
1181
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001182 sense_buf[2] = sense_key; /* Sense key */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 sense_buf[12] = sense_code; /* Additional sense code */
1185 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001186
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 if (sense_key == ILLEGAL_REQUEST) {
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001188 sense_buf[7] = 10; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001190 sense_buf[15] = bit_pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 /* Illegal parameter is in the parameter block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 if (sense_code == SENCODE_INVALID_CDB_FIELD)
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001193 sense_buf[15] |= 0xc0;/* Std sense key specific field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 /* Illegal parameter is in the CDB block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 sense_buf[16] = field_pointer >> 8; /* MSB */
1196 sense_buf[17] = field_pointer; /* LSB */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001197 } else
1198 sense_buf[7] = 6; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001201static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1202{
1203 if (lba & 0xffffffff00000000LL) {
1204 int cid = scmd_id(cmd);
1205 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1206 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1207 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001208 set_sense(&dev->fsa_dev[cid].sense_data,
1209 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1210 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001211 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001212 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1213 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001214 cmd->scsi_done(cmd);
1215 return 1;
1216 }
1217 return 0;
1218}
1219
1220static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1221{
1222 return 0;
1223}
1224
1225static void io_callback(void *context, struct fib * fibptr);
1226
1227static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1228{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301229 struct aac_dev *dev = fib->dev;
1230 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301231 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001232
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301233 aac_fib_init(fib);
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -08001234 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1235 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1236 !dev->sync_mode) {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301237 struct aac_raw_io2 *readcmd2;
1238 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1239 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1240 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1241 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001242 readcmd2->byteCount = cpu_to_le32(count *
1243 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301244 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1245 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301246 ret = aac_build_sgraw2(cmd, readcmd2,
1247 dev->scsi_host_ptr->sg_tablesize);
1248 if (ret < 0)
1249 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301250 command = ContainerRawIo2;
1251 fibsize = sizeof(struct aac_raw_io2) +
1252 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1253 } else {
1254 struct aac_raw_io *readcmd;
1255 readcmd = (struct aac_raw_io *) fib_data(fib);
1256 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1257 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001258 readcmd->count = cpu_to_le32(count *
1259 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301260 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1261 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1262 readcmd->bpTotal = 0;
1263 readcmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301264 ret = aac_build_sgraw(cmd, &readcmd->sg);
1265 if (ret < 0)
1266 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301267 command = ContainerRawIo;
1268 fibsize = sizeof(struct aac_raw_io) +
1269 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1270 }
1271
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001272 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1273 /*
1274 * Now send the Fib to the adapter
1275 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301276 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001277 fib,
1278 fibsize,
1279 FsaNormal,
1280 0, 1,
1281 (fib_callback) io_callback,
1282 (void *) cmd);
1283}
1284
1285static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1286{
1287 u16 fibsize;
1288 struct aac_read64 *readcmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301289 long ret;
1290
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001291 aac_fib_init(fib);
1292 readcmd = (struct aac_read64 *) fib_data(fib);
1293 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1294 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1295 readcmd->sector_count = cpu_to_le16(count);
1296 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1297 readcmd->pad = 0;
1298 readcmd->flags = 0;
1299
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301300 ret = aac_build_sg64(cmd, &readcmd->sg);
1301 if (ret < 0)
1302 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001303 fibsize = sizeof(struct aac_read64) +
1304 ((le32_to_cpu(readcmd->sg.count) - 1) *
1305 sizeof (struct sgentry64));
1306 BUG_ON (fibsize > (fib->dev->max_fib_size -
1307 sizeof(struct aac_fibhdr)));
1308 /*
1309 * Now send the Fib to the adapter
1310 */
1311 return aac_fib_send(ContainerCommand64,
1312 fib,
1313 fibsize,
1314 FsaNormal,
1315 0, 1,
1316 (fib_callback) io_callback,
1317 (void *) cmd);
1318}
1319
1320static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1321{
1322 u16 fibsize;
1323 struct aac_read *readcmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001324 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301325 long ret;
1326
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001327 aac_fib_init(fib);
1328 readcmd = (struct aac_read *) fib_data(fib);
1329 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001330 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001331 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001332 readcmd->count = cpu_to_le32(count *
1333 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001334
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301335 ret = aac_build_sg(cmd, &readcmd->sg);
1336 if (ret < 0)
1337 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001338 fibsize = sizeof(struct aac_read) +
1339 ((le32_to_cpu(readcmd->sg.count) - 1) *
1340 sizeof (struct sgentry));
1341 BUG_ON (fibsize > (fib->dev->max_fib_size -
1342 sizeof(struct aac_fibhdr)));
1343 /*
1344 * Now send the Fib to the adapter
1345 */
1346 return aac_fib_send(ContainerCommand,
1347 fib,
1348 fibsize,
1349 FsaNormal,
1350 0, 1,
1351 (fib_callback) io_callback,
1352 (void *) cmd);
1353}
1354
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001355static 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 -08001356{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301357 struct aac_dev *dev = fib->dev;
1358 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301359 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001360
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301361 aac_fib_init(fib);
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -08001362 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1363 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1364 !dev->sync_mode) {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301365 struct aac_raw_io2 *writecmd2;
1366 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1367 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1368 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1369 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001370 writecmd2->byteCount = cpu_to_le32(count *
1371 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301372 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1373 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1374 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1375 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1376 cpu_to_le16(RIO2_IO_TYPE_WRITE);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301377 ret = aac_build_sgraw2(cmd, writecmd2,
1378 dev->scsi_host_ptr->sg_tablesize);
1379 if (ret < 0)
1380 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301381 command = ContainerRawIo2;
1382 fibsize = sizeof(struct aac_raw_io2) +
1383 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1384 } else {
1385 struct aac_raw_io *writecmd;
1386 writecmd = (struct aac_raw_io *) fib_data(fib);
1387 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1388 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001389 writecmd->count = cpu_to_le32(count *
1390 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301391 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1392 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1393 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1394 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1395 cpu_to_le16(RIO_TYPE_WRITE);
1396 writecmd->bpTotal = 0;
1397 writecmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301398 ret = aac_build_sgraw(cmd, &writecmd->sg);
1399 if (ret < 0)
1400 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301401 command = ContainerRawIo;
1402 fibsize = sizeof(struct aac_raw_io) +
1403 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1404 }
1405
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001406 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1407 /*
1408 * Now send the Fib to the adapter
1409 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301410 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001411 fib,
1412 fibsize,
1413 FsaNormal,
1414 0, 1,
1415 (fib_callback) io_callback,
1416 (void *) cmd);
1417}
1418
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001419static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001420{
1421 u16 fibsize;
1422 struct aac_write64 *writecmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301423 long ret;
1424
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001425 aac_fib_init(fib);
1426 writecmd = (struct aac_write64 *) fib_data(fib);
1427 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1428 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1429 writecmd->sector_count = cpu_to_le16(count);
1430 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1431 writecmd->pad = 0;
1432 writecmd->flags = 0;
1433
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301434 ret = aac_build_sg64(cmd, &writecmd->sg);
1435 if (ret < 0)
1436 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001437 fibsize = sizeof(struct aac_write64) +
1438 ((le32_to_cpu(writecmd->sg.count) - 1) *
1439 sizeof (struct sgentry64));
1440 BUG_ON (fibsize > (fib->dev->max_fib_size -
1441 sizeof(struct aac_fibhdr)));
1442 /*
1443 * Now send the Fib to the adapter
1444 */
1445 return aac_fib_send(ContainerCommand64,
1446 fib,
1447 fibsize,
1448 FsaNormal,
1449 0, 1,
1450 (fib_callback) io_callback,
1451 (void *) cmd);
1452}
1453
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001454static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001455{
1456 u16 fibsize;
1457 struct aac_write *writecmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001458 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301459 long ret;
1460
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001461 aac_fib_init(fib);
1462 writecmd = (struct aac_write *) fib_data(fib);
1463 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001464 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001465 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001466 writecmd->count = cpu_to_le32(count *
1467 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001468 writecmd->sg.count = cpu_to_le32(1);
1469 /* ->stable is not used - it did mean which type of write */
1470
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301471 ret = aac_build_sg(cmd, &writecmd->sg);
1472 if (ret < 0)
1473 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001474 fibsize = sizeof(struct aac_write) +
1475 ((le32_to_cpu(writecmd->sg.count) - 1) *
1476 sizeof (struct sgentry));
1477 BUG_ON (fibsize > (fib->dev->max_fib_size -
1478 sizeof(struct aac_fibhdr)));
1479 /*
1480 * Now send the Fib to the adapter
1481 */
1482 return aac_fib_send(ContainerCommand,
1483 fib,
1484 fibsize,
1485 FsaNormal,
1486 0, 1,
1487 (fib_callback) io_callback,
1488 (void *) cmd);
1489}
1490
1491static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1492{
1493 struct aac_srb * srbcmd;
1494 u32 flag;
1495 u32 timeout;
1496
1497 aac_fib_init(fib);
1498 switch(cmd->sc_data_direction){
1499 case DMA_TO_DEVICE:
1500 flag = SRB_DataOut;
1501 break;
1502 case DMA_BIDIRECTIONAL:
1503 flag = SRB_DataIn | SRB_DataOut;
1504 break;
1505 case DMA_FROM_DEVICE:
1506 flag = SRB_DataIn;
1507 break;
1508 case DMA_NONE:
1509 default: /* shuts up some versions of gcc */
1510 flag = SRB_NoDataXfer;
1511 break;
1512 }
1513
1514 srbcmd = (struct aac_srb*) fib_data(fib);
1515 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1516 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1517 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1518 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1519 srbcmd->flags = cpu_to_le32(flag);
Jens Axboe242f9dc2008-09-14 05:55:09 -07001520 timeout = cmd->request->timeout/HZ;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001521 if (timeout == 0)
1522 timeout = 1;
1523 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1524 srbcmd->retry_limit = 0; /* Obsolete parameter */
1525 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1526 return srbcmd;
1527}
1528
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08001529static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
1530 struct scsi_cmnd *cmd)
1531{
1532 struct aac_hba_cmd_req *hbacmd;
1533 struct aac_dev *dev;
1534 int bus, target;
1535 u64 address;
1536
1537 dev = (struct aac_dev *)cmd->device->host->hostdata;
1538
1539 hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
1540 memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
1541 /* iu_type is a parameter of aac_hba_send */
1542 switch (cmd->sc_data_direction) {
1543 case DMA_TO_DEVICE:
1544 hbacmd->byte1 = 2;
1545 break;
1546 case DMA_FROM_DEVICE:
1547 case DMA_BIDIRECTIONAL:
1548 hbacmd->byte1 = 1;
1549 break;
1550 case DMA_NONE:
1551 default:
1552 break;
1553 }
1554 hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
1555
1556 bus = aac_logical_to_phys(scmd_channel(cmd));
1557 target = scmd_id(cmd);
1558 hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
1559
1560 /* we fill in reply_qid later in aac_src_deliver_message */
1561 /* we fill in iu_type, request_id later in aac_hba_send */
1562 /* we fill in emb_data_desc_count later in aac_build_sghba */
1563
1564 memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
1565 hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
1566
1567 address = (u64)fib->hw_error_pa;
1568 hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
1569 hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
1570 hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
1571
1572 return hbacmd;
1573}
1574
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001575static void aac_srb_callback(void *context, struct fib * fibptr);
1576
1577static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1578{
1579 u16 fibsize;
1580 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301581 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001582
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301583 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1584 if (ret < 0)
1585 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001586 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001587
1588 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1589 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1590 /*
1591 * Build Scatter/Gather list
1592 */
1593 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1594 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1595 sizeof (struct sgentry64));
1596 BUG_ON (fibsize > (fib->dev->max_fib_size -
1597 sizeof(struct aac_fibhdr)));
1598
1599 /*
1600 * Now send the Fib to the adapter
1601 */
1602 return aac_fib_send(ScsiPortCommand64, fib,
1603 fibsize, FsaNormal, 0, 1,
1604 (fib_callback) aac_srb_callback,
1605 (void *) cmd);
1606}
1607
1608static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1609{
1610 u16 fibsize;
1611 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301612 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001613
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301614 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1615 if (ret < 0)
1616 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001617 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001618
1619 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1620 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1621 /*
1622 * Build Scatter/Gather list
1623 */
1624 fibsize = sizeof (struct aac_srb) +
1625 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1626 sizeof (struct sgentry));
1627 BUG_ON (fibsize > (fib->dev->max_fib_size -
1628 sizeof(struct aac_fibhdr)));
1629
1630 /*
1631 * Now send the Fib to the adapter
1632 */
1633 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1634 (fib_callback) aac_srb_callback, (void *) cmd);
1635}
1636
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001637static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1638{
Leubner, Achimd8e965072009-04-01 07:16:08 -07001639 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1640 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001641 return FAILED;
1642 return aac_scsi_32(fib, cmd);
1643}
1644
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08001645static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
1646{
1647 struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
1648 struct aac_dev *dev;
1649 long ret;
1650
1651 dev = (struct aac_dev *)cmd->device->host->hostdata;
1652
1653 ret = aac_build_sghba(cmd, hbacmd,
1654 dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
1655 if (ret < 0)
1656 return ret;
1657
1658 /*
1659 * Now send the HBA command to the adapter
1660 */
1661 fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
1662 sizeof(struct aac_hba_sgl);
1663
1664 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
1665 (fib_callback) aac_hba_callback,
1666 (void *) cmd);
1667}
1668
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001669static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
1670 struct aac_srb_unit *srbu, void *xfer_buf, int xfer_len)
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001671{
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001672 struct fib *fibptr;
1673 dma_addr_t addr;
1674 int rcode;
1675 int fibsize;
1676 struct aac_srb *srb;
1677 struct aac_srb_reply *srb_reply;
1678 struct sgmap64 *sg64;
1679 u32 vbus;
1680 u32 vid;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001681
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001682 if (!dev->sa_firmware)
1683 return 0;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08001684
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001685 /* allocate FIB */
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001686 fibptr = aac_fib_alloc(dev);
1687 if (!fibptr)
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001688 return -ENOMEM;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001689
1690 aac_fib_init(fibptr);
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001691 fibptr->hw_fib_va->header.XferState &=
1692 ~cpu_to_le32(FastResponseCapable);
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001693
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001694 fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
1695 sizeof(struct sgentry64);
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001696
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001697 /* allocate DMA buffer for response */
1698 addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
1699 DMA_BIDIRECTIONAL);
1700 if (dma_mapping_error(&dev->pdev->dev, addr)) {
1701 rcode = -ENOMEM;
1702 goto fib_error;
1703 }
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001704
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001705 srb = fib_data(fibptr);
1706 memcpy(srb, &srbu->srb, sizeof(struct aac_srb));
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001707
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001708 vbus = (u32)le16_to_cpu(
1709 dev->supplement_adapter_info.virt_device_bus);
1710 vid = (u32)le16_to_cpu(
1711 dev->supplement_adapter_info.virt_device_target);
1712
1713 /* set the common request fields */
1714 srb->channel = cpu_to_le32(vbus);
1715 srb->id = cpu_to_le32(vid);
1716 srb->lun = 0;
1717 srb->function = cpu_to_le32(SRBF_ExecuteScsi);
1718 srb->timeout = 0;
1719 srb->retry_limit = 0;
1720 srb->cdb_size = cpu_to_le32(16);
1721 srb->count = cpu_to_le32(xfer_len);
1722
1723 sg64 = (struct sgmap64 *)&srb->sg;
1724 sg64->count = cpu_to_le32(1);
1725 sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
1726 sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
1727 sg64->sg[0].count = cpu_to_le32(xfer_len);
1728
1729 /*
1730 * Copy the updated data for other dumping or other usage if needed
1731 */
1732 memcpy(&srbu->srb, srb, sizeof(struct aac_srb));
1733
1734 /* issue request to the controller */
1735 rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize, FsaNormal,
1736 1, 1, NULL, NULL);
1737
1738 if (rcode == -ERESTARTSYS)
1739 rcode = -ERESTART;
1740
1741 if (unlikely(rcode < 0))
1742 goto bmic_error;
1743
1744 srb_reply = (struct aac_srb_reply *)fib_data(fibptr);
1745 memcpy(&srbu->srb_reply, srb_reply, sizeof(struct aac_srb_reply));
1746
1747bmic_error:
1748 dma_unmap_single(&dev->pdev->dev, addr, xfer_len, DMA_BIDIRECTIONAL);
1749fib_error:
1750 aac_fib_complete(fibptr);
1751 aac_fib_free(fibptr);
1752 return rcode;
1753}
1754
Raghava Aditya Renukunta0bcb45f2017-12-26 20:34:38 -08001755static void aac_set_safw_target_qd(struct aac_dev *dev, int bus, int target)
1756{
1757
1758 struct aac_ciss_identify_pd *identify_resp;
1759
1760 if (dev->hba_map[bus][target].devtype != AAC_DEVTYPE_NATIVE_RAW)
1761 return;
1762
1763 identify_resp = dev->hba_map[bus][target].safw_identify_resp;
1764 if (identify_resp == NULL) {
1765 dev->hba_map[bus][target].qd_limit = 32;
1766 return;
1767 }
1768
1769 if (identify_resp->current_queue_depth_limit <= 0 ||
1770 identify_resp->current_queue_depth_limit > 255)
1771 dev->hba_map[bus][target].qd_limit = 32;
1772 else
1773 dev->hba_map[bus][target].qd_limit =
1774 identify_resp->current_queue_depth_limit;
1775}
1776
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001777static int aac_issue_safw_bmic_identify(struct aac_dev *dev,
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001778 struct aac_ciss_identify_pd **identify_resp, u32 bus, u32 target)
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001779{
1780 int rcode = -ENOMEM;
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001781 int datasize;
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001782 struct aac_srb_unit srbu;
1783 struct aac_srb *srbcmd;
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001784 struct aac_ciss_identify_pd *identify_reply;
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001785
1786 datasize = sizeof(struct aac_ciss_identify_pd);
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001787 identify_reply = kmalloc(datasize, GFP_KERNEL);
1788 if (!identify_reply)
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001789 goto out;
1790
1791 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1792
1793 srbcmd = &srbu.srb;
1794 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1795 srbcmd->cdb[0] = 0x26;
1796 srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
1797 srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
1798
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001799 rcode = aac_send_safw_bmic_cmd(dev, &srbu, identify_reply, datasize);
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001800 if (unlikely(rcode < 0))
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001801 goto mem_free_all;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001802
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001803 *identify_resp = identify_reply;
1804
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001805out:
1806 return rcode;
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001807mem_free_all:
1808 kfree(identify_reply);
1809 goto out;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001810}
1811
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001812static inline void aac_free_safw_ciss_luns(struct aac_dev *dev)
1813{
1814 kfree(dev->safw_phys_luns);
1815 dev->safw_phys_luns = NULL;
1816}
1817
1818/**
1819 * aac_get_safw_ciss_luns() Process topology change
1820 * @dev: aac_dev structure
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001821 *
1822 * Execute a CISS REPORT PHYS LUNS and process the results into
1823 * the current hba_map.
1824 */
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08001825static int aac_get_safw_ciss_luns(struct aac_dev *dev)
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001826{
1827 int rcode = -ENOMEM;
1828 int datasize;
1829 struct aac_srb *srbcmd;
1830 struct aac_srb_unit srbu;
1831 struct aac_ciss_phys_luns_resp *phys_luns;
1832
1833 datasize = sizeof(struct aac_ciss_phys_luns_resp) +
1834 (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
1835 phys_luns = kmalloc(datasize, GFP_KERNEL);
1836 if (phys_luns == NULL)
1837 goto out;
1838
1839 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1840
1841 srbcmd = &srbu.srb;
1842 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1843 srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
1844 srbcmd->cdb[1] = 2; /* extended reporting */
1845 srbcmd->cdb[8] = (u8)(datasize >> 8);
1846 srbcmd->cdb[9] = (u8)(datasize);
1847
1848 rcode = aac_send_safw_bmic_cmd(dev, &srbu, phys_luns, datasize);
1849 if (unlikely(rcode < 0))
1850 goto mem_free_all;
1851
1852 if (phys_luns->resp_flag != 2) {
1853 rcode = -ENOMSG;
1854 goto mem_free_all;
1855 }
1856
1857 dev->safw_phys_luns = phys_luns;
1858
1859out:
1860 return rcode;
1861mem_free_all:
1862 kfree(phys_luns);
1863 goto out;
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001864}
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001865
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001866static inline u32 aac_get_safw_phys_lun_count(struct aac_dev *dev)
1867{
Raghava Aditya Renukuntabbd16d92018-01-10 13:13:09 -08001868 return get_unaligned_be32(&dev->safw_phys_luns->list_length[0])/24;
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001869}
1870
1871static inline u32 aac_get_safw_phys_bus(struct aac_dev *dev, int lun)
1872{
1873 return dev->safw_phys_luns->lun[lun].level2[1] & 0x3f;
1874}
1875
1876static inline u32 aac_get_safw_phys_target(struct aac_dev *dev, int lun)
1877{
1878 return dev->safw_phys_luns->lun[lun].level2[0];
1879}
1880
1881static inline u32 aac_get_safw_phys_expose_flag(struct aac_dev *dev, int lun)
1882{
1883 return dev->safw_phys_luns->lun[lun].bus >> 6;
1884}
1885
1886static inline u32 aac_get_safw_phys_attribs(struct aac_dev *dev, int lun)
1887{
1888 return dev->safw_phys_luns->lun[lun].node_ident[9];
1889}
1890
1891static inline u32 aac_get_safw_phys_nexus(struct aac_dev *dev, int lun)
1892{
1893 return *((u32 *)&dev->safw_phys_luns->lun[lun].node_ident[12]);
1894}
1895
1896static inline u32 aac_get_safw_phys_device_type(struct aac_dev *dev, int lun)
1897{
1898 return dev->safw_phys_luns->lun[lun].node_ident[8];
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001899}
1900
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001901static inline void aac_free_safw_identify_resp(struct aac_dev *dev,
1902 int bus, int target)
1903{
1904 kfree(dev->hba_map[bus][target].safw_identify_resp);
1905 dev->hba_map[bus][target].safw_identify_resp = NULL;
1906}
1907
1908static inline void aac_free_safw_all_identify_resp(struct aac_dev *dev,
1909 int lun_count)
1910{
1911 int luns;
1912 int i;
1913 u32 bus;
1914 u32 target;
1915
1916 luns = aac_get_safw_phys_lun_count(dev);
1917
1918 if (luns < lun_count)
1919 lun_count = luns;
1920 else if (lun_count < 0)
1921 lun_count = luns;
1922
1923 for (i = 0; i < lun_count; i++) {
1924 bus = aac_get_safw_phys_bus(dev, i);
1925 target = aac_get_safw_phys_target(dev, i);
1926
1927 aac_free_safw_identify_resp(dev, bus, target);
1928 }
1929}
1930
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08001931static int aac_get_safw_attr_all_targets(struct aac_dev *dev)
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001932{
1933 int i;
1934 int rcode = 0;
1935 u32 lun_count;
1936 u32 bus;
1937 u32 target;
1938 struct aac_ciss_identify_pd *identify_resp = NULL;
1939
1940 lun_count = aac_get_safw_phys_lun_count(dev);
1941
1942 for (i = 0; i < lun_count; ++i) {
1943
1944 bus = aac_get_safw_phys_bus(dev, i);
1945 target = aac_get_safw_phys_target(dev, i);
1946
1947 rcode = aac_issue_safw_bmic_identify(dev,
1948 &identify_resp, bus, target);
1949
Raghava Aditya Renukunta0bcb45f2017-12-26 20:34:38 -08001950 if (unlikely(rcode < 0))
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001951 goto free_identify_resp;
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001952
1953 dev->hba_map[bus][target].safw_identify_resp = identify_resp;
1954 }
1955
1956out:
1957 return rcode;
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001958free_identify_resp:
1959 aac_free_safw_all_identify_resp(dev, i);
1960 goto out;
1961}
1962
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001963/**
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001964 * aac_set_safw_attr_all_targets- update current hba map with data from FW
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001965 * @dev: aac_dev structure
1966 * @phys_luns: FW information from report phys luns
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001967 * @rescan: Indicates scan type
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001968 *
1969 * Update our hba map with the information gathered from the FW
1970 */
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08001971static void aac_set_safw_attr_all_targets(struct aac_dev *dev)
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001972{
1973 /* ok and extended reporting */
1974 u32 lun_count, nexus;
1975 u32 i, bus, target;
1976 u8 expose_flag, attribs;
1977 u8 devtype;
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08001978
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001979 lun_count = aac_get_safw_phys_lun_count(dev);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001980
Raghava Aditya Renukuntaf2d2cab2017-12-26 20:34:40 -08001981 dev->scan_counter++;
1982
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001983 for (i = 0; i < lun_count; ++i) {
1984
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001985 bus = aac_get_safw_phys_bus(dev, i);
1986 target = aac_get_safw_phys_target(dev, i);
1987 expose_flag = aac_get_safw_phys_expose_flag(dev, i);
1988 attribs = aac_get_safw_phys_attribs(dev, i);
1989 nexus = aac_get_safw_phys_nexus(dev, i);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001990
1991 if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
1992 continue;
1993
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001994 if (expose_flag != 0) {
1995 devtype = AAC_DEVTYPE_RAID_MEMBER;
1996 goto update_devtype;
1997 }
1998
1999 if (nexus != 0 && (attribs & 8)) {
2000 devtype = AAC_DEVTYPE_NATIVE_RAW;
2001 dev->hba_map[bus][target].rmw_nexus =
2002 nexus;
2003 } else
2004 devtype = AAC_DEVTYPE_ARC_RAW;
2005
Raghava Aditya Renukuntaf2d2cab2017-12-26 20:34:40 -08002006 dev->hba_map[bus][target].scan_counter = dev->scan_counter;
2007
Raghava Aditya Renukunta0bcb45f2017-12-26 20:34:38 -08002008 aac_set_safw_target_qd(dev, bus, target);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002009
2010update_devtype:
Raghava Aditya Renukuntaf2d2cab2017-12-26 20:34:40 -08002011 dev->hba_map[bus][target].devtype = devtype;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002012 }
2013}
2014
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002015static int aac_setup_safw_targets(struct aac_dev *dev)
Raghava Aditya Renukuntafc0fdd92017-12-26 20:34:33 -08002016{
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08002017 int rcode = 0;
2018
Raghava Aditya Renukunta1d1fec52017-12-26 20:34:39 -08002019 rcode = aac_get_containers(dev);
2020 if (unlikely(rcode < 0))
2021 goto out;
2022
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002023 rcode = aac_get_safw_ciss_luns(dev);
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08002024 if (unlikely(rcode < 0))
2025 goto out;
2026
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002027 rcode = aac_get_safw_attr_all_targets(dev);
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08002028 if (unlikely(rcode < 0))
2029 goto free_ciss_luns;
2030
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002031 aac_set_safw_attr_all_targets(dev);
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08002032
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08002033 aac_free_safw_all_identify_resp(dev, -1);
2034free_ciss_luns:
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08002035 aac_free_safw_ciss_luns(dev);
2036out:
2037 return rcode;
Raghava Aditya Renukuntafc0fdd92017-12-26 20:34:33 -08002038}
2039
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002040int aac_setup_safw_adapter(struct aac_dev *dev)
Raghava Aditya Renukuntafc0fdd92017-12-26 20:34:33 -08002041{
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002042 return aac_setup_safw_targets(dev);
Raghava Aditya Renukuntafc0fdd92017-12-26 20:34:33 -08002043}
2044
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045int aac_get_adapter_info(struct aac_dev* dev)
2046{
2047 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 int rcode;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002049 u32 tmp, bus, target;
Mark Haverkamp84971732005-06-20 11:55:24 -07002050 struct aac_adapter_info *info;
2051 struct aac_bus_info *command;
2052 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002053
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002054 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 return -ENOMEM;
2056
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002057 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002058 info = (struct aac_adapter_info *) fib_data(fibptr);
2059 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002061 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002062 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002063 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002064 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07002065 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002066 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002067 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002069 if (rcode < 0) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302070 /* FIB should be freed only after
2071 * getting the response from the F/W */
2072 if (rcode != -ERESTARTSYS) {
2073 aac_fib_complete(fibptr);
2074 aac_fib_free(fibptr);
2075 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002076 return rcode;
2077 }
2078 memcpy(&dev->adapter_info, info, sizeof(*info));
2079
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002080 dev->supplement_adapter_info.virt_device_bus = 0xffff;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002081 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002082 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002083
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002084 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002085
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002086 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002087
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002088 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002089
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002090 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002091 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002092 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002093 FsaNormal,
2094 1, 1,
2095 NULL,
2096 NULL);
2097
2098 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002099 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302100 if (rcode == -ERESTARTSYS) {
2101 fibptr = aac_fib_alloc(dev);
2102 if (!fibptr)
2103 return -ENOMEM;
2104 }
2105
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002108 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
2109 for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08002110 for (target = 0; target < AAC_MAX_TARGETS; target++) {
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002111 dev->hba_map[bus][target].devtype = 0;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08002112 dev->hba_map[bus][target].qd_limit = 0;
2113 }
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002114 }
Mark Haverkamp84971732005-06-20 11:55:24 -07002115
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002116 /*
2117 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07002118 */
2119
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002120 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07002121
2122 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
2123
2124 memset(bus_info, 0, sizeof(*bus_info));
2125
2126 command = (struct aac_bus_info *)bus_info;
2127
2128 command->Command = cpu_to_le32(VM_Ioctl);
2129 command->ObjType = cpu_to_le32(FT_DRIVE);
2130 command->MethodId = cpu_to_le32(1);
2131 command->CtlCmd = cpu_to_le32(GetBusInfo);
2132
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002133 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07002134 fibptr,
2135 sizeof (*bus_info),
2136 FsaNormal,
2137 1, 1,
2138 NULL, NULL);
2139
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08002140 /* reasoned default */
2141 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07002142 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
2143 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
2144 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
2145 }
2146
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002147 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04002148 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002149 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
2150 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002151 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 dev->id,
2153 tmp>>24,
2154 (tmp>>16)&0xff,
2155 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002156 le32_to_cpu(dev->adapter_info.kernelbuild),
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002157 (int)sizeof(dev->supplement_adapter_info.build_date),
2158 dev->supplement_adapter_info.build_date);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002159 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
2160 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 dev->name, dev->id,
2162 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2163 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002164 tmp = le32_to_cpu(dev->adapter_info.biosrev);
2165 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 dev->name, dev->id,
2167 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2168 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04002169 buffer[0] = '\0';
Tony Jonesee959b02008-02-22 00:13:36 +01002170 if (aac_get_serial_number(
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04002171 shost_to_class(dev->scsi_host_ptr), buffer))
2172 printk(KERN_INFO "%s%d: serial %s",
2173 dev->name, dev->id, buffer);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002174 if (dev->supplement_adapter_info.vpd_info.tsid[0]) {
Salyzyn, Marka45c8632007-03-28 13:44:54 -04002175 printk(KERN_INFO "%s%d: TSID %.*s\n",
2176 dev->name, dev->id,
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002177 (int)sizeof(dev->supplement_adapter_info
2178 .vpd_info.tsid),
2179 dev->supplement_adapter_info.vpd_info.tsid);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04002180 }
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002181 if (!aac_check_reset || ((aac_check_reset == 1) &&
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002182 (dev->supplement_adapter_info.supported_options2 &
Salyzyn, Marka3940da2008-01-08 12:48:25 -08002183 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002184 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
2185 dev->name, dev->id);
2186 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002189 dev->cache_protected = 0;
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002190 dev->jbod = ((dev->supplement_adapter_info.feature_bits &
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08002191 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 dev->nondasd_support = 0;
2193 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002194 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
2197 /*
2198 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2199 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2200 * force nondasd support on. If we decide to allow the non-dasd flag
2201 * additional changes changes will have to be made to support
2202 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2203 * changed to support the new dev->raid_scsi_mode flag instead of
2204 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2205 * function aac_detect will have to be modified where it sets up the
2206 * max number of channels based on the aac->nondasd_support flag only.
2207 */
2208 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
2209 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
2210 dev->nondasd_support = 1;
2211 dev->raid_scsi_mode = 1;
2212 }
2213 if (dev->raid_scsi_mode != 0)
2214 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
2215 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002216
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002217 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002219 if (dev->nondasd_support && !dev->in_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Yang Hongyange9304382009-04-13 14:40:14 -07002222 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
Leubner, Achimd8e965072009-04-01 07:16:08 -07002223 dev->needs_dac = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 dev->dac_support = 0;
Leubner, Achimd8e965072009-04-01 07:16:08 -07002225 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
2226 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002227 if (!dev->in_reset)
2228 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
2229 dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 dev->dac_support = 1;
2231 }
2232
2233 if(dacmode != -1) {
2234 dev->dac_support = (dacmode!=0);
2235 }
Leubner, Achimd8e965072009-04-01 07:16:08 -07002236
2237 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2238 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
2239 & AAC_QUIRK_SCSI_32)) {
2240 dev->nondasd_support = 0;
2241 dev->jbod = 0;
2242 expose_physicals = 0;
2243 }
2244
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07002245 if (dev->dac_support) {
2246 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002247 if (!dev->in_reset)
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07002248 dev_info(&dev->pdev->dev, "64 Bit DAC enabled\n");
2249 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
2250 dev_info(&dev->pdev->dev, "DMA mask set failed, 64 Bit DAC disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 dev->dac_support = 0;
2252 } else {
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07002253 dev_info(&dev->pdev->dev, "No suitable DMA available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 rcode = -ENOMEM;
2255 }
2256 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002257 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002258 * Deal with configuring for the individualized limits of each packet
2259 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002260 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002261 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08002262 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
2263 ? aac_scsi_32_64
2264 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002265 : aac_scsi_32;
2266 if (dev->raw_io_interface) {
2267 dev->a_ops.adapter_bounds = (dev->raw_io_64)
2268 ? aac_bounds_64
2269 : aac_bounds_32;
2270 dev->a_ops.adapter_read = aac_read_raw_io;
2271 dev->a_ops.adapter_write = aac_write_raw_io;
2272 } else {
2273 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002274 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002275 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07002276 sizeof(struct aac_write) + sizeof(struct sgentry)) /
2277 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002278 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002279 dev->a_ops.adapter_read = aac_read_block64;
2280 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002281 /*
2282 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002283 */
2284 dev->scsi_host_ptr->sg_tablesize =
2285 (dev->max_fib_size -
2286 sizeof(struct aac_fibhdr) -
2287 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07002288 sizeof(struct sgentry64)) /
2289 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002290 } else {
2291 dev->a_ops.adapter_read = aac_read_block;
2292 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002293 }
2294 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07002295 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002296 /*
2297 * Worst case size that could cause sg overflow when
2298 * we break up SG elements that are larger than 64KB.
2299 * Would be nice if we could tell the SCSI layer what
2300 * the maximum SG element size can be. Worst case is
2301 * (sg_tablesize-1) 4KB elements with one 64KB
2302 * element.
2303 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2304 */
2305 dev->scsi_host_ptr->max_sectors =
2306 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
2307 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002308 }
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002309 if (!dev->sync_mode && dev->sa_firmware &&
2310 dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
2311 dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
2312 HBA_MAX_SG_SEPARATE;
2313
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302314 /* FIB should be freed only after getting the response from the F/W */
2315 if (rcode != -ERESTARTSYS) {
2316 aac_fib_complete(fibptr);
2317 aac_fib_free(fibptr);
2318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
2320 return rcode;
2321}
2322
2323
Mark Haverkampe53cb352005-08-03 15:39:09 -07002324static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325{
2326 struct aac_dev *dev;
2327 struct aac_read_reply *readreply;
2328 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 u32 cid;
2330
2331 scsicmd = (struct scsi_cmnd *) context;
2332
Mark Haverkamp03d44332007-03-15 10:27:45 -07002333 if (!aac_valid_context(scsicmd, fibptr))
2334 return;
2335
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002336 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002337 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002339 if (nblank(dprintk(x))) {
2340 u64 lba;
2341 switch (scsicmd->cmnd[0]) {
2342 case WRITE_6:
2343 case READ_6:
2344 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2345 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2346 break;
2347 case WRITE_16:
2348 case READ_16:
2349 lba = ((u64)scsicmd->cmnd[2] << 56) |
2350 ((u64)scsicmd->cmnd[3] << 48) |
2351 ((u64)scsicmd->cmnd[4] << 40) |
2352 ((u64)scsicmd->cmnd[5] << 32) |
2353 ((u64)scsicmd->cmnd[6] << 24) |
2354 (scsicmd->cmnd[7] << 16) |
2355 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2356 break;
2357 case WRITE_12:
2358 case READ_12:
2359 lba = ((u64)scsicmd->cmnd[2] << 24) |
2360 (scsicmd->cmnd[3] << 16) |
2361 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2362 break;
2363 default:
2364 lba = ((u64)scsicmd->cmnd[2] << 24) |
2365 (scsicmd->cmnd[3] << 16) |
2366 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2367 break;
2368 }
2369 printk(KERN_DEBUG
2370 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2371 smp_processor_id(), (unsigned long long)lba, jiffies);
2372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002374 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002375
2376 scsi_dma_unmap(scsicmd);
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 readreply = (struct aac_read_reply *)fib_data(fibptr);
Mark Salyzyn655d7222008-04-30 16:03:42 -04002379 switch (le32_to_cpu(readreply->status)) {
2380 case ST_OK:
2381 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2382 SAM_STAT_GOOD;
2383 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
2384 break;
2385 case ST_NOT_READY:
2386 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2387 SAM_STAT_CHECK_CONDITION;
2388 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
2389 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
2390 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2391 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2392 SCSI_SENSE_BUFFERSIZE));
2393 break;
Raghava Aditya Renukuntaf956a662017-02-02 15:53:23 -08002394 case ST_MEDERR:
2395 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2396 SAM_STAT_CHECK_CONDITION;
2397 set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
2398 SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
2399 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2400 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2401 SCSI_SENSE_BUFFERSIZE));
2402 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002403 default:
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002404#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07002405 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002406 le32_to_cpu(readreply->status));
2407#endif
Mark Salyzyn655d7222008-04-30 16:03:42 -04002408 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2409 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002410 set_sense(&dev->fsa_dev[cid].sense_data,
2411 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2412 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002414 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2415 SCSI_SENSE_BUFFERSIZE));
Mark Salyzyn655d7222008-04-30 16:03:42 -04002416 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002418 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002420 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421}
2422
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002423static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002425 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 u32 count;
2427 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 struct aac_dev *dev;
2429 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002430 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
2432 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2433 /*
2434 * Get block address and transfer length
2435 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002436 switch (scsicmd->cmnd[0]) {
2437 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002438 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002440 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002441 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 count = scsicmd->cmnd[4];
2443
2444 if (count == 0)
2445 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002446 break;
2447 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002448 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002449
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002450 lba = ((u64)scsicmd->cmnd[2] << 56) |
2451 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002452 ((u64)scsicmd->cmnd[4] << 40) |
2453 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002454 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002455 (scsicmd->cmnd[7] << 16) |
2456 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002457 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002458 (scsicmd->cmnd[11] << 16) |
2459 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2460 break;
2461 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002462 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002463
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002464 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002465 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002466 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2467 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002468 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002469 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002470 break;
2471 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002472 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002474 lba = ((u64)scsicmd->cmnd[2] << 24) |
2475 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002476 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002478 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002480
2481 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2482 cid = scmd_id(scsicmd);
2483 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2484 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2485 SAM_STAT_CHECK_CONDITION;
2486 set_sense(&dev->fsa_dev[cid].sense_data,
2487 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2488 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2489 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2490 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2491 SCSI_SENSE_BUFFERSIZE));
2492 scsicmd->scsi_done(scsicmd);
2493 return 1;
2494 }
2495
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002496 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002497 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002498 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002499 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 /*
2501 * Alocate and initialize a Fib
2502 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002503 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Brian King1ae948f2017-08-29 10:00:29 -05002504 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002505 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506
2507 /*
2508 * Check that the command queued to the controller
2509 */
Brian King1ae948f2017-08-29 10:00:29 -05002510 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 return 0;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002512
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002513 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 /*
2515 * For some reason, the Fib didn't queue, return QUEUE_FULL
2516 */
2517 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002518 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002519 aac_fib_complete(cmd_fibcontext);
2520 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 return 0;
2522}
2523
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002524static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002526 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002528 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 struct aac_dev *dev;
2531 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002532 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
2534 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2535 /*
2536 * Get block address and transfer length
2537 */
2538 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
2539 {
2540 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2541 count = scsicmd->cmnd[4];
2542 if (count == 0)
2543 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002544 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002545 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002546 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002547
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002548 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002549 ((u64)scsicmd->cmnd[3] << 48) |
2550 ((u64)scsicmd->cmnd[4] << 40) |
2551 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002552 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002553 (scsicmd->cmnd[7] << 16) |
2554 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2555 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2556 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002557 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002558 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002559 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002560
2561 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2562 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2563 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2564 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002565 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002567 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002568 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002570 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002572
2573 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2574 cid = scmd_id(scsicmd);
2575 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2576 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2577 SAM_STAT_CHECK_CONDITION;
2578 set_sense(&dev->fsa_dev[cid].sense_data,
2579 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2580 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2581 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2582 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2583 SCSI_SENSE_BUFFERSIZE));
2584 scsicmd->scsi_done(scsicmd);
2585 return 1;
2586 }
2587
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002588 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002590 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002591 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 /*
2593 * Allocate and initialize a Fib then setup a BlockWrite command
2594 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002595 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Brian King1ae948f2017-08-29 10:00:29 -05002596 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002597 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
2599 /*
2600 * Check that the command queued to the controller
2601 */
Brian King1ae948f2017-08-29 10:00:29 -05002602 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002605 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 /*
2607 * For some reason, the Fib didn't queue, return QUEUE_FULL
2608 */
2609 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002610 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002612 aac_fib_complete(cmd_fibcontext);
2613 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 return 0;
2615}
2616
2617static void synchronize_callback(void *context, struct fib *fibptr)
2618{
2619 struct aac_synchronize_reply *synchronizereply;
2620 struct scsi_cmnd *cmd;
2621
2622 cmd = context;
2623
Mark Haverkamp03d44332007-03-15 10:27:45 -07002624 if (!aac_valid_context(cmd, fibptr))
2625 return;
2626
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002627 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 smp_processor_id(), jiffies));
2629 BUG_ON(fibptr == NULL);
2630
2631
2632 synchronizereply = fib_data(fibptr);
2633 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002634 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2636 else {
2637 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002638 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002639 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002640 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 "synchronize_callback: synchronize failed, status = %d\n",
2642 le32_to_cpu(synchronizereply->status));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002643 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002645 set_sense(&dev->fsa_dev[cid].sense_data,
2646 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2647 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002649 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2650 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 }
2652
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002653 aac_fib_complete(fibptr);
2654 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002655 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656}
2657
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002658static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659{
2660 int status;
2661 struct fib *cmd_fibcontext;
2662 struct aac_synchronize *synchronizecmd;
2663 struct scsi_cmnd *cmd;
2664 struct scsi_device *sdev = scsicmd->device;
2665 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002666 struct aac_dev *aac;
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002667 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2668 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2669 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 unsigned long flags;
2671
2672 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002673 * Wait for all outstanding queued commands to complete to this
2674 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 */
2676 spin_lock_irqsave(&sdev->list_lock, flags);
2677 list_for_each_entry(cmd, &sdev->cmd_list, list)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002678 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2679 u64 cmnd_lba;
2680 u32 cmnd_count;
2681
2682 if (cmd->cmnd[0] == WRITE_6) {
2683 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2684 (cmd->cmnd[2] << 8) |
2685 cmd->cmnd[3];
2686 cmnd_count = cmd->cmnd[4];
2687 if (cmnd_count == 0)
2688 cmnd_count = 256;
2689 } else if (cmd->cmnd[0] == WRITE_16) {
2690 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2691 ((u64)cmd->cmnd[3] << 48) |
2692 ((u64)cmd->cmnd[4] << 40) |
2693 ((u64)cmd->cmnd[5] << 32) |
2694 ((u64)cmd->cmnd[6] << 24) |
2695 (cmd->cmnd[7] << 16) |
2696 (cmd->cmnd[8] << 8) |
2697 cmd->cmnd[9];
2698 cmnd_count = (cmd->cmnd[10] << 24) |
2699 (cmd->cmnd[11] << 16) |
2700 (cmd->cmnd[12] << 8) |
2701 cmd->cmnd[13];
2702 } else if (cmd->cmnd[0] == WRITE_12) {
2703 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2704 (cmd->cmnd[3] << 16) |
2705 (cmd->cmnd[4] << 8) |
2706 cmd->cmnd[5];
2707 cmnd_count = (cmd->cmnd[6] << 24) |
2708 (cmd->cmnd[7] << 16) |
2709 (cmd->cmnd[8] << 8) |
2710 cmd->cmnd[9];
2711 } else if (cmd->cmnd[0] == WRITE_10) {
2712 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2713 (cmd->cmnd[3] << 16) |
2714 (cmd->cmnd[4] << 8) |
2715 cmd->cmnd[5];
2716 cmnd_count = (cmd->cmnd[7] << 8) |
2717 cmd->cmnd[8];
2718 } else
2719 continue;
2720 if (((cmnd_lba + cmnd_count) < lba) ||
2721 (count && ((lba + count) < cmnd_lba)))
2722 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 ++active;
2724 break;
2725 }
2726
2727 spin_unlock_irqrestore(&sdev->list_lock, flags);
2728
2729 /*
2730 * Yield the processor (requeue for later)
2731 */
2732 if (active)
2733 return SCSI_MLQUEUE_DEVICE_BUSY;
2734
Salyzyn, Markf8583172007-10-30 15:50:49 -04002735 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002736 if (aac->in_reset)
2737 return SCSI_MLQUEUE_HOST_BUSY;
2738
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002740 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002742 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 return SCSI_MLQUEUE_HOST_BUSY;
2744
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002745 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
2747 synchronizecmd = fib_data(cmd_fibcontext);
2748 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2749 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002750 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002751 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
Brian King1ae948f2017-08-29 10:00:29 -05002753 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754
2755 /*
2756 * Now send the Fib to the adapter
2757 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002758 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 cmd_fibcontext,
2760 sizeof(struct aac_synchronize),
2761 FsaNormal,
2762 0, 1,
2763 (fib_callback)synchronize_callback,
2764 (void *)scsicmd);
2765
2766 /*
2767 * Check that the command queued to the controller
2768 */
Brian King1ae948f2017-08-29 10:00:29 -05002769 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 return 0;
2771
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002772 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002773 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2774 aac_fib_complete(cmd_fibcontext);
2775 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 return SCSI_MLQUEUE_HOST_BUSY;
2777}
2778
Mark Salyzyn655d7222008-04-30 16:03:42 -04002779static void aac_start_stop_callback(void *context, struct fib *fibptr)
2780{
2781 struct scsi_cmnd *scsicmd = context;
2782
2783 if (!aac_valid_context(scsicmd, fibptr))
2784 return;
2785
2786 BUG_ON(fibptr == NULL);
2787
2788 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2789
2790 aac_fib_complete(fibptr);
2791 aac_fib_free(fibptr);
2792 scsicmd->scsi_done(scsicmd);
2793}
2794
2795static int aac_start_stop(struct scsi_cmnd *scsicmd)
2796{
2797 int status;
2798 struct fib *cmd_fibcontext;
2799 struct aac_power_management *pmcmd;
2800 struct scsi_device *sdev = scsicmd->device;
2801 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2802
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002803 if (!(aac->supplement_adapter_info.supported_options2 &
Mark Salyzyn655d7222008-04-30 16:03:42 -04002804 AAC_OPTION_POWER_MANAGEMENT)) {
2805 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2806 SAM_STAT_GOOD;
2807 scsicmd->scsi_done(scsicmd);
2808 return 0;
2809 }
2810
2811 if (aac->in_reset)
2812 return SCSI_MLQUEUE_HOST_BUSY;
2813
2814 /*
2815 * Allocate and initialize a Fib
2816 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002817 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
Mark Salyzyn655d7222008-04-30 16:03:42 -04002818
2819 aac_fib_init(cmd_fibcontext);
2820
2821 pmcmd = fib_data(cmd_fibcontext);
2822 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2823 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2824 /* Eject bit ignored, not relevant */
2825 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2826 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2827 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2828 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2829 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
Brian King1ae948f2017-08-29 10:00:29 -05002830 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002831
2832 /*
2833 * Now send the Fib to the adapter
2834 */
2835 status = aac_fib_send(ContainerCommand,
2836 cmd_fibcontext,
2837 sizeof(struct aac_power_management),
2838 FsaNormal,
2839 0, 1,
2840 (fib_callback)aac_start_stop_callback,
2841 (void *)scsicmd);
2842
2843 /*
2844 * Check that the command queued to the controller
2845 */
Brian King1ae948f2017-08-29 10:00:29 -05002846 if (status == -EINPROGRESS)
Mark Salyzyn655d7222008-04-30 16:03:42 -04002847 return 0;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002848
2849 aac_fib_complete(cmd_fibcontext);
2850 aac_fib_free(cmd_fibcontext);
2851 return SCSI_MLQUEUE_HOST_BUSY;
2852}
2853
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854/**
2855 * aac_scsi_cmd() - Process SCSI command
2856 * @scsicmd: SCSI command block
2857 *
2858 * Emulate a SCSI command and queue the required request for the
2859 * aacraid firmware.
2860 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002861
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2863{
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002864 u32 cid, bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 struct Scsi_Host *host = scsicmd->device->host;
2866 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2867 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002868
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002869 if (fsa_dev_ptr == NULL)
2870 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 /*
2872 * If the bus, id or lun is out of range, return fail
2873 * Test does not apply to ID 16, the pseudo id for the controller
2874 * itself.
2875 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002876 cid = scmd_id(scsicmd);
2877 if (cid != host->this_id) {
2878 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2879 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08002880 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002882 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
2885 /*
2886 * If the target container doesn't exist, it may have
2887 * been newly created
2888 */
Mark Salyzyn655d7222008-04-30 16:03:42 -04002889 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2890 (fsa_dev_ptr[cid].sense_data.sense_key ==
2891 NOT_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 switch (scsicmd->cmnd[0]) {
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002893 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002894 if (!(dev->raw_io_interface) ||
2895 !(dev->raw_io_64) ||
2896 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2897 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 case INQUIRY:
2899 case READ_CAPACITY:
2900 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002901 if (dev->in_reset)
2902 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07002903 return _aac_probe_container(scsicmd,
2904 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 default:
2906 break;
2907 }
2908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 } else { /* check for physical non-dasd devices */
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002910 bus = aac_logical_to_phys(scmd_channel(scsicmd));
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002911
2912 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2913 dev->hba_map[bus][cid].devtype
2914 == AAC_DEVTYPE_NATIVE_RAW) {
2915 if (dev->in_reset)
2916 return -1;
2917 return aac_send_hba_fib(scsicmd);
2918 } else if (dev->nondasd_support || expose_physicals ||
2919 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002920 if (dev->in_reset)
2921 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 return aac_send_srb_fib(scsicmd);
2923 } else {
2924 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002925 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 }
2927 }
2928 }
2929 /*
2930 * else Command for the controller itself
2931 */
2932 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002933 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 {
2935 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2936 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002937 set_sense(&dev->fsa_dev[cid].sense_data,
2938 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2939 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002941 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2942 SCSI_SENSE_BUFFERSIZE));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002943 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 }
2945
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 switch (scsicmd->cmnd[0]) {
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002947 case READ_6:
2948 case READ_10:
2949 case READ_12:
2950 case READ_16:
2951 if (dev->in_reset)
2952 return -1;
2953 return aac_read(scsicmd);
2954
2955 case WRITE_6:
2956 case WRITE_10:
2957 case WRITE_12:
2958 case WRITE_16:
2959 if (dev->in_reset)
2960 return -1;
2961 return aac_write(scsicmd);
2962
2963 case SYNCHRONIZE_CACHE:
2964 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2965 scsicmd->result = AAC_STAT_GOOD;
2966 break;
2967 }
2968 /* Issue FIB to tell Firmware to flush it's cache */
2969 if ((aac_cache & 6) != 2)
2970 return aac_synchronize(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 case INQUIRY:
2972 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002973 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002975 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002976 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977
Leubner, Achimd8e965072009-04-01 07:16:08 -07002978 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002979 char *arr = (char *)&inq_data;
2980
2981 /* EVPD bit set */
2982 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2983 INQD_PDT_PROC : INQD_PDT_DA;
2984 if (scsicmd->cmnd[2] == 0) {
2985 /* supported vital product data pages */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002986 arr[3] = 3;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002987 arr[4] = 0x0;
2988 arr[5] = 0x80;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002989 arr[6] = 0x83;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002990 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002991 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2992 sizeof(inq_data));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002993 scsicmd->result = AAC_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002994 } else if (scsicmd->cmnd[2] == 0x80) {
2995 /* unit serial number page */
2996 arr[3] = setinqserial(dev, &arr[4],
2997 scmd_id(scsicmd));
2998 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002999 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
3000 sizeof(inq_data));
Leubner, Achimd8e965072009-04-01 07:16:08 -07003001 if (aac_wwn != 2)
3002 return aac_get_container_serial(
3003 scsicmd);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003004 scsicmd->result = AAC_STAT_GOOD;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04003005 } else if (scsicmd->cmnd[2] == 0x83) {
3006 /* vpd page 0x83 - Device Identification Page */
3007 char *sno = (char *)&inq_data;
3008 sno[3] = setinqserial(dev, &sno[4],
3009 scmd_id(scsicmd));
3010 if (aac_wwn != 2)
3011 return aac_get_container_serial(
3012 scsicmd);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003013 scsicmd->result = AAC_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04003014 } else {
3015 /* vpd page not implemented */
3016 scsicmd->result = DID_OK << 16 |
3017 COMMAND_COMPLETE << 8 |
3018 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08003019 set_sense(&dev->fsa_dev[cid].sense_data,
3020 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
3021 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04003022 memcpy(scsicmd->sense_buffer,
3023 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08003024 min_t(size_t,
3025 sizeof(dev->fsa_dev[cid].sense_data),
3026 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04003027 }
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003028 break;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04003029 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07003030 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07003031 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 */
3032 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07003034 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 /*
3036 * Set the Vendor, Product, and Revision Level
3037 * see: <vendor>.c i.e. aac.c
3038 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04003039 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07003040 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07003041 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09003042 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
3043 sizeof(inq_data));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003044 scsicmd->result = AAC_STAT_GOOD;
3045 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07003047 if (dev->in_reset)
3048 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07003049 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07003050 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09003051 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07003052 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 }
Hannes Reineckeeb846d92014-11-17 14:25:19 +01003054 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003055 if (!(dev->raw_io_interface) ||
3056 !(dev->raw_io_64) ||
3057 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
3058 break;
3059 {
3060 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08003061 char cp[13];
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08003062 unsigned int alloc_len;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003063
3064 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
3065 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003066 cp[0] = (capacity >> 56) & 0xff;
3067 cp[1] = (capacity >> 48) & 0xff;
3068 cp[2] = (capacity >> 40) & 0xff;
3069 cp[3] = (capacity >> 32) & 0xff;
3070 cp[4] = (capacity >> 24) & 0xff;
3071 cp[5] = (capacity >> 16) & 0xff;
3072 cp[6] = (capacity >> 8) & 0xff;
3073 cp[7] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003074 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3075 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3076 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3077 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08003078 cp[12] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08003079
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08003080 alloc_len = ((scsicmd->cmnd[10] << 24)
3081 + (scsicmd->cmnd[11] << 16)
3082 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
3083
3084 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
FUJITA Tomonorid4345022008-03-09 13:44:34 +09003085 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08003086 if (alloc_len < scsi_bufflen(scsicmd))
3087 scsi_set_resid(scsicmd,
3088 scsi_bufflen(scsicmd) - alloc_len);
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003089
3090 /* Do not cache partition table for arrays */
3091 scsicmd->device->removable = 1;
3092
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003093 scsicmd->result = AAC_STAT_GOOD;
3094 break;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003095 }
3096
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 case READ_CAPACITY:
3098 {
3099 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07003100 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101
3102 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003103 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 capacity = fsa_dev_ptr[cid].size - 1;
3105 else
3106 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07003107
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 cp[0] = (capacity >> 24) & 0xff;
3109 cp[1] = (capacity >> 16) & 0xff;
3110 cp[2] = (capacity >> 8) & 0xff;
3111 cp[3] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003112 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3113 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3114 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3115 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
FUJITA Tomonorid4345022008-03-09 13:44:34 +09003116 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003117 /* Do not cache partition table for arrays */
3118 scsicmd->device->removable = 1;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003119 scsicmd->result = AAC_STAT_GOOD;
3120 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 }
3122
3123 case MODE_SENSE:
3124 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003125 int mode_buf_length = 4;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003126 u32 capacity;
3127 aac_modep_data mpd;
3128
3129 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3130 capacity = fsa_dev_ptr[cid].size - 1;
3131 else
3132 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
3134 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003135 memset((char *)&mpd, 0, sizeof(aac_modep_data));
3136
3137 /* Mode data length */
3138 mpd.hd.data_length = sizeof(mpd.hd) - 1;
3139 /* Medium type - default */
3140 mpd.hd.med_type = 0;
3141 /* Device-specific param,
3142 bit 8: 0/1 = write enabled/protected
3143 bit 4: 0/1 = FUA enabled */
3144 mpd.hd.dev_par = 0;
3145
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003146 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003147 mpd.hd.dev_par = 0x10;
3148 if (scsicmd->cmnd[1] & 0x8)
3149 mpd.hd.bd_length = 0; /* Block descriptor length */
3150 else {
3151 mpd.hd.bd_length = sizeof(mpd.bd);
3152 mpd.hd.data_length += mpd.hd.bd_length;
3153 mpd.bd.block_length[0] =
3154 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3155 mpd.bd.block_length[1] =
3156 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3157 mpd.bd.block_length[2] =
3158 fsa_dev_ptr[cid].block_size & 0xff;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04003159
3160 mpd.mpc_buf[0] = scsicmd->cmnd[2];
3161 if (scsicmd->cmnd[2] == 0x1C) {
3162 /* page length */
3163 mpd.mpc_buf[1] = 0xa;
3164 /* Mode data length */
3165 mpd.hd.data_length = 23;
3166 } else {
3167 /* Mode data length */
3168 mpd.hd.data_length = 15;
3169 }
3170
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003171 if (capacity > 0xffffff) {
3172 mpd.bd.block_count[0] = 0xff;
3173 mpd.bd.block_count[1] = 0xff;
3174 mpd.bd.block_count[2] = 0xff;
3175 } else {
3176 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
3177 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
3178 mpd.bd.block_count[2] = capacity & 0xff;
3179 }
3180 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003181 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3182 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003183 mpd.hd.data_length += 3;
3184 mpd.mpc_buf[0] = 8;
3185 mpd.mpc_buf[1] = 1;
3186 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003187 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003188 mode_buf_length = sizeof(mpd);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003189 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04003190
3191 if (mode_buf_length > scsicmd->cmnd[4])
3192 mode_buf_length = scsicmd->cmnd[4];
3193 else
3194 mode_buf_length = sizeof(mpd);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003195 scsi_sg_copy_from_buffer(scsicmd,
3196 (char *)&mpd,
3197 mode_buf_length);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003198 scsicmd->result = AAC_STAT_GOOD;
3199 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 }
3201 case MODE_SENSE_10:
3202 {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003203 u32 capacity;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003204 int mode_buf_length = 8;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003205 aac_modep10_data mpd10;
3206
3207 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3208 capacity = fsa_dev_ptr[cid].size - 1;
3209 else
3210 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
3212 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003213 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
3214 /* Mode data length (MSB) */
3215 mpd10.hd.data_length[0] = 0;
3216 /* Mode data length (LSB) */
3217 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
3218 /* Medium type - default */
3219 mpd10.hd.med_type = 0;
3220 /* Device-specific param,
3221 bit 8: 0/1 = write enabled/protected
3222 bit 4: 0/1 = FUA enabled */
3223 mpd10.hd.dev_par = 0;
3224
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003225 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003226 mpd10.hd.dev_par = 0x10;
3227 mpd10.hd.rsrvd[0] = 0; /* reserved */
3228 mpd10.hd.rsrvd[1] = 0; /* reserved */
3229 if (scsicmd->cmnd[1] & 0x8) {
3230 /* Block descriptor length (MSB) */
3231 mpd10.hd.bd_length[0] = 0;
3232 /* Block descriptor length (LSB) */
3233 mpd10.hd.bd_length[1] = 0;
3234 } else {
3235 mpd10.hd.bd_length[0] = 0;
3236 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
3237
3238 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
3239
3240 mpd10.bd.block_length[0] =
3241 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3242 mpd10.bd.block_length[1] =
3243 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3244 mpd10.bd.block_length[2] =
3245 fsa_dev_ptr[cid].block_size & 0xff;
3246
3247 if (capacity > 0xffffff) {
3248 mpd10.bd.block_count[0] = 0xff;
3249 mpd10.bd.block_count[1] = 0xff;
3250 mpd10.bd.block_count[2] = 0xff;
3251 } else {
3252 mpd10.bd.block_count[0] =
3253 (capacity >> 16) & 0xff;
3254 mpd10.bd.block_count[1] =
3255 (capacity >> 8) & 0xff;
3256 mpd10.bd.block_count[2] =
3257 capacity & 0xff;
3258 }
3259 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003260 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3261 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003262 mpd10.hd.data_length[1] += 3;
3263 mpd10.mpc_buf[0] = 8;
3264 mpd10.mpc_buf[1] = 1;
3265 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003266 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003267 mode_buf_length = sizeof(mpd10);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003268 if (mode_buf_length > scsicmd->cmnd[8])
3269 mode_buf_length = scsicmd->cmnd[8];
3270 }
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003271 scsi_sg_copy_from_buffer(scsicmd,
3272 (char *)&mpd10,
3273 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003275 scsicmd->result = AAC_STAT_GOOD;
3276 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 }
3278 case REQUEST_SENSE:
3279 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003280 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3281 sizeof(struct sense_data));
3282 memset(&dev->fsa_dev[cid].sense_data, 0,
3283 sizeof(struct sense_data));
3284 scsicmd->result = AAC_STAT_GOOD;
3285 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
3287 case ALLOW_MEDIUM_REMOVAL:
3288 dprintk((KERN_DEBUG "LOCK command.\n"));
3289 if (scsicmd->cmnd[4])
3290 fsa_dev_ptr[cid].locked = 1;
3291 else
3292 fsa_dev_ptr[cid].locked = 0;
3293
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003294 scsicmd->result = AAC_STAT_GOOD;
3295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 /*
3297 * These commands are all No-Ops
3298 */
3299 case TEST_UNIT_READY:
Mark Salyzyn655d7222008-04-30 16:03:42 -04003300 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
3301 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3302 SAM_STAT_CHECK_CONDITION;
3303 set_sense(&dev->fsa_dev[cid].sense_data,
3304 NOT_READY, SENCODE_BECOMING_READY,
3305 ASENCODE_BECOMING_READY, 0, 0);
3306 memcpy(scsicmd->sense_buffer,
3307 &dev->fsa_dev[cid].sense_data,
3308 min_t(size_t,
3309 sizeof(dev->fsa_dev[cid].sense_data),
3310 SCSI_SENSE_BUFFERSIZE));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003311 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04003312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 case RESERVE:
3314 case RELEASE:
3315 case REZERO_UNIT:
3316 case REASSIGN_BLOCKS:
3317 case SEEK_10:
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003318 scsicmd->result = AAC_STAT_GOOD;
3319 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04003320
3321 case START_STOP:
3322 return aac_start_stop(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003324 /* FALLTHRU */
3325 default:
3326 /*
3327 * Unhandled commands
3328 */
3329 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
3330 scsicmd->cmnd[0]));
3331 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3332 SAM_STAT_CHECK_CONDITION;
3333 set_sense(&dev->fsa_dev[cid].sense_data,
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08003334 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
3335 ASENCODE_INVALID_COMMAND, 0, 0);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003336 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08003337 min_t(size_t,
3338 sizeof(dev->fsa_dev[cid].sense_data),
3339 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 }
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003341
3342scsi_done_ret:
3343
3344 scsicmd->scsi_done(scsicmd);
3345 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346}
3347
3348static int query_disk(struct aac_dev *dev, void __user *arg)
3349{
3350 struct aac_query_disk qd;
3351 struct fsa_dev_info *fsa_dev_ptr;
3352
3353 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07003354 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07003355 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
3357 return -EFAULT;
Dan Carpentere6fd9162017-07-25 22:49:55 +03003358 if (qd.cnum == -1) {
3359 if (qd.id < 0 || qd.id >= dev->maximum_num_containers)
3360 return -EINVAL;
Mark Haverkampe5718772006-03-27 09:43:25 -08003361 qd.cnum = qd.id;
Dan Carpentere6fd9162017-07-25 22:49:55 +03003362 } else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
3364 return -EINVAL;
3365 qd.instance = dev->scsi_host_ptr->host_no;
3366 qd.bus = 0;
3367 qd.id = CONTAINER_TO_ID(qd.cnum);
3368 qd.lun = CONTAINER_TO_LUN(qd.cnum);
3369 }
3370 else return -EINVAL;
3371
Salyzyn, Markfd622b12007-07-17 10:59:19 -04003372 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 qd.locked = fsa_dev_ptr[qd.cnum].locked;
3374 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
3375
3376 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
3377 qd.unmapped = 1;
3378 else
3379 qd.unmapped = 0;
3380
3381 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
3382 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
3383
3384 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
3385 return -EFAULT;
3386 return 0;
3387}
3388
3389static int force_delete_disk(struct aac_dev *dev, void __user *arg)
3390{
3391 struct aac_delete_disk dd;
3392 struct fsa_dev_info *fsa_dev_ptr;
3393
3394 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp65101352006-09-19 08:59:23 -07003395 if (!fsa_dev_ptr)
3396 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397
3398 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3399 return -EFAULT;
3400
3401 if (dd.cnum >= dev->maximum_num_containers)
3402 return -EINVAL;
3403 /*
3404 * Mark this container as being deleted.
3405 */
3406 fsa_dev_ptr[dd.cnum].deleted = 1;
3407 /*
3408 * Mark the container as no longer valid
3409 */
3410 fsa_dev_ptr[dd.cnum].valid = 0;
3411 return 0;
3412}
3413
3414static int delete_disk(struct aac_dev *dev, void __user *arg)
3415{
3416 struct aac_delete_disk dd;
3417 struct fsa_dev_info *fsa_dev_ptr;
3418
3419 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07003420 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07003421 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422
3423 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3424 return -EFAULT;
3425
3426 if (dd.cnum >= dev->maximum_num_containers)
3427 return -EINVAL;
3428 /*
3429 * If the container is locked, it can not be deleted by the API.
3430 */
3431 if (fsa_dev_ptr[dd.cnum].locked)
3432 return -EBUSY;
3433 else {
3434 /*
3435 * Mark the container as no longer being valid.
3436 */
3437 fsa_dev_ptr[dd.cnum].valid = 0;
3438 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
3439 return 0;
3440 }
3441}
3442
3443int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
3444{
3445 switch (cmd) {
3446 case FSACTL_QUERY_DISK:
3447 return query_disk(dev, arg);
3448 case FSACTL_DELETE_DISK:
3449 return delete_disk(dev, arg);
3450 case FSACTL_FORCE_DELETE_DISK:
3451 return force_delete_disk(dev, arg);
3452 case FSACTL_GET_CONTAINERS:
3453 return aac_get_containers(dev);
3454 default:
3455 return -ENOTTY;
3456 }
3457}
3458
3459/**
3460 *
3461 * aac_srb_callback
3462 * @context: the context set in the fib - here it is scsi cmd
3463 * @fibptr: pointer to the fib
3464 *
3465 * Handles the completion of a scsi command to a non dasd device
3466 *
3467 */
3468
3469static void aac_srb_callback(void *context, struct fib * fibptr)
3470{
3471 struct aac_dev *dev;
3472 struct aac_srb_reply *srbreply;
3473 struct scsi_cmnd *scsicmd;
3474
3475 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07003476
3477 if (!aac_valid_context(scsicmd, fibptr))
3478 return;
3479
Eric Sesterhenn125e1872006-06-23 02:06:06 -07003480 BUG_ON(fibptr == NULL);
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003481
Salyzyn, Mark1a655042007-06-11 16:17:55 -04003482 dev = fibptr->dev;
3483
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003484 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003485
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303488 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3489 /* fast response */
3490 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
3491 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
3492 } else {
3493 /*
3494 * Calculate resid for sg
3495 */
3496 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
3497 - le32_to_cpu(srbreply->data_xfer_length));
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003498 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003499
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003501 scsi_dma_unmap(scsicmd);
3502
3503 /* expose physical device if expose_physicald flag is on */
3504 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
3505 && expose_physicals > 0)
3506 aac_expose_phy_device(scsicmd);
3507
3508 /*
3509 * First check the fib status
3510 */
3511
3512 if (le32_to_cpu(srbreply->status) != ST_OK) {
3513 int len;
3514
3515 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3516 le32_to_cpu(srbreply->status));
3517 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3518 SCSI_SENSE_BUFFERSIZE);
3519 scsicmd->result = DID_ERROR << 16
3520 | COMMAND_COMPLETE << 8
3521 | SAM_STAT_CHECK_CONDITION;
3522 memcpy(scsicmd->sense_buffer,
3523 srbreply->sense_data, len);
3524 }
3525
3526 /*
3527 * Next check the srb status
3528 */
3529 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3530 case SRB_STATUS_ERROR_RECOVERY:
3531 case SRB_STATUS_PENDING:
3532 case SRB_STATUS_SUCCESS:
3533 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3534 break;
3535 case SRB_STATUS_DATA_OVERRUN:
3536 switch (scsicmd->cmnd[0]) {
3537 case READ_6:
3538 case WRITE_6:
3539 case READ_10:
3540 case WRITE_10:
3541 case READ_12:
3542 case WRITE_12:
3543 case READ_16:
3544 case WRITE_16:
3545 if (le32_to_cpu(srbreply->data_xfer_length)
3546 < scsicmd->underflow)
3547 pr_warn("aacraid: SCSI CMD underflow\n");
3548 else
3549 pr_warn("aacraid: SCSI CMD Data Overrun\n");
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003550 scsicmd->result = DID_ERROR << 16
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003551 | COMMAND_COMPLETE << 8;
3552 break;
3553 case INQUIRY:
3554 scsicmd->result = DID_OK << 16
3555 | COMMAND_COMPLETE << 8;
3556 break;
3557 default:
Mark Haverkampbb08f922006-02-01 09:30:44 -08003558 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 break;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003560 }
3561 break;
3562 case SRB_STATUS_ABORTED:
3563 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3564 break;
3565 case SRB_STATUS_ABORT_FAILED:
3566 /*
3567 * Not sure about this one - but assuming the
3568 * hba was trying to abort for some reason
3569 */
3570 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3571 break;
3572 case SRB_STATUS_PARITY_ERROR:
3573 scsicmd->result = DID_PARITY << 16
3574 | MSG_PARITY_ERROR << 8;
3575 break;
3576 case SRB_STATUS_NO_DEVICE:
3577 case SRB_STATUS_INVALID_PATH_ID:
3578 case SRB_STATUS_INVALID_TARGET_ID:
3579 case SRB_STATUS_INVALID_LUN:
3580 case SRB_STATUS_SELECTION_TIMEOUT:
3581 scsicmd->result = DID_NO_CONNECT << 16
3582 | COMMAND_COMPLETE << 8;
3583 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003584
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003585 case SRB_STATUS_COMMAND_TIMEOUT:
3586 case SRB_STATUS_TIMEOUT:
3587 scsicmd->result = DID_TIME_OUT << 16
3588 | COMMAND_COMPLETE << 8;
3589 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003590
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003591 case SRB_STATUS_BUSY:
3592 scsicmd->result = DID_BUS_BUSY << 16
3593 | COMMAND_COMPLETE << 8;
3594 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003595
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003596 case SRB_STATUS_BUS_RESET:
3597 scsicmd->result = DID_RESET << 16
3598 | COMMAND_COMPLETE << 8;
3599 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003600
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003601 case SRB_STATUS_MESSAGE_REJECTED:
3602 scsicmd->result = DID_ERROR << 16
3603 | MESSAGE_REJECT << 8;
3604 break;
3605 case SRB_STATUS_REQUEST_FLUSHED:
3606 case SRB_STATUS_ERROR:
3607 case SRB_STATUS_INVALID_REQUEST:
3608 case SRB_STATUS_REQUEST_SENSE_FAILED:
3609 case SRB_STATUS_NO_HBA:
3610 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3611 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3612 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3613 case SRB_STATUS_DELAYED_RETRY:
3614 case SRB_STATUS_BAD_FUNCTION:
3615 case SRB_STATUS_NOT_STARTED:
3616 case SRB_STATUS_NOT_IN_USE:
3617 case SRB_STATUS_FORCE_ABORT:
3618 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3619 default:
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003620#ifdef AAC_DETAILED_STATUS_INFO
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003621 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3622 le32_to_cpu(srbreply->srb_status) & 0x3F,
3623 aac_get_status_string(
3624 le32_to_cpu(srbreply->srb_status) & 0x3F),
3625 scsicmd->cmnd[0],
3626 le32_to_cpu(srbreply->scsi_status));
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003627#endif
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003628 /*
3629 * When the CC bit is SET by the host in ATA pass thru CDB,
3630 * driver is supposed to return DID_OK
3631 *
3632 * When the CC bit is RESET by the host, driver should
3633 * return DID_ERROR
3634 */
3635 if ((scsicmd->cmnd[0] == ATA_12)
3636 || (scsicmd->cmnd[0] == ATA_16)) {
3637
3638 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3639 scsicmd->result = DID_OK << 16
3640 | COMMAND_COMPLETE << 8;
3641 break;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003642 } else {
3643 scsicmd->result = DID_ERROR << 16
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003644 | COMMAND_COMPLETE << 8;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003645 break;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003646 }
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003647 } else {
3648 scsicmd->result = DID_ERROR << 16
3649 | COMMAND_COMPLETE << 8;
3650 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003651 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 }
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003653 if (le32_to_cpu(srbreply->scsi_status)
3654 == SAM_STAT_CHECK_CONDITION) {
3655 int len;
3656
3657 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3658 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3659 SCSI_SENSE_BUFFERSIZE);
3660#ifdef AAC_DETAILED_STATUS_INFO
3661 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3662 le32_to_cpu(srbreply->status), len);
3663#endif
3664 memcpy(scsicmd->sense_buffer,
3665 srbreply->sense_data, len);
3666 }
3667
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 /*
3669 * OR in the scsi status (already shifted up a bit)
3670 */
3671 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3672
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003673 aac_fib_complete(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07003674 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675}
3676
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003677static void hba_resp_task_complete(struct aac_dev *dev,
3678 struct scsi_cmnd *scsicmd,
3679 struct aac_hba_resp *err) {
3680
3681 scsicmd->result = err->status;
3682 /* set residual count */
3683 scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
3684
3685 switch (err->status) {
3686 case SAM_STAT_GOOD:
3687 scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3688 break;
3689 case SAM_STAT_CHECK_CONDITION:
3690 {
3691 int len;
3692
3693 len = min_t(u8, err->sense_response_data_len,
3694 SCSI_SENSE_BUFFERSIZE);
3695 if (len)
3696 memcpy(scsicmd->sense_buffer,
3697 err->sense_response_buf, len);
3698 scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3699 break;
3700 }
3701 case SAM_STAT_BUSY:
3702 scsicmd->result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
3703 break;
3704 case SAM_STAT_TASK_ABORTED:
3705 scsicmd->result |= DID_ABORT << 16 | ABORT << 8;
3706 break;
3707 case SAM_STAT_RESERVATION_CONFLICT:
3708 case SAM_STAT_TASK_SET_FULL:
3709 default:
3710 scsicmd->result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3711 break;
3712 }
3713}
3714
3715static void hba_resp_task_failure(struct aac_dev *dev,
3716 struct scsi_cmnd *scsicmd,
3717 struct aac_hba_resp *err)
3718{
3719 switch (err->status) {
3720 case HBA_RESP_STAT_HBAMODE_DISABLED:
3721 {
3722 u32 bus, cid;
3723
3724 bus = aac_logical_to_phys(scmd_channel(scsicmd));
3725 cid = scmd_id(scsicmd);
3726 if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
3727 dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
3728 dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
3729 }
3730 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3731 break;
3732 }
3733 case HBA_RESP_STAT_IO_ERROR:
3734 case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
3735 scsicmd->result = DID_OK << 16 |
3736 COMMAND_COMPLETE << 8 | SAM_STAT_BUSY;
3737 break;
3738 case HBA_RESP_STAT_IO_ABORTED:
3739 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3740 break;
3741 case HBA_RESP_STAT_INVALID_DEVICE:
3742 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3743 break;
3744 case HBA_RESP_STAT_UNDERRUN:
3745 /* UNDERRUN is OK */
3746 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3747 break;
3748 case HBA_RESP_STAT_OVERRUN:
3749 default:
3750 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3751 break;
3752 }
3753}
3754
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755/**
3756 *
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003757 * aac_hba_callback
3758 * @context: the context set in the fib - here it is scsi cmd
3759 * @fibptr: pointer to the fib
3760 *
3761 * Handles the completion of a native HBA scsi command
3762 *
3763 */
3764void aac_hba_callback(void *context, struct fib *fibptr)
3765{
3766 struct aac_dev *dev;
3767 struct scsi_cmnd *scsicmd;
3768
3769 struct aac_hba_resp *err =
3770 &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
3771
3772 scsicmd = (struct scsi_cmnd *) context;
3773
3774 if (!aac_valid_context(scsicmd, fibptr))
3775 return;
3776
3777 WARN_ON(fibptr == NULL);
3778 dev = fibptr->dev;
3779
3780 if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
3781 scsi_dma_unmap(scsicmd);
3782
3783 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3784 /* fast response */
3785 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3786 goto out;
3787 }
3788
3789 switch (err->service_response) {
3790 case HBA_RESP_SVCRES_TASK_COMPLETE:
3791 hba_resp_task_complete(dev, scsicmd, err);
3792 break;
3793 case HBA_RESP_SVCRES_FAILURE:
3794 hba_resp_task_failure(dev, scsicmd, err);
3795 break;
3796 case HBA_RESP_SVCRES_TMF_REJECTED:
3797 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
3798 break;
3799 case HBA_RESP_SVCRES_TMF_LUN_INVALID:
3800 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3801 break;
3802 case HBA_RESP_SVCRES_TMF_COMPLETE:
3803 case HBA_RESP_SVCRES_TMF_SUCCEEDED:
3804 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3805 break;
3806 default:
3807 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3808 break;
3809 }
3810
3811out:
3812 aac_fib_complete(fibptr);
3813
3814 if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
3815 scsicmd->SCp.sent_command = 1;
3816 else
3817 scsicmd->scsi_done(scsicmd);
3818}
3819
3820/**
3821 *
3822 * aac_send_srb_fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 * @scsicmd: the scsi command block
3824 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003825 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 * scsicmd passed in.
3827 */
3828
3829static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3830{
3831 struct fib* cmd_fibcontext;
3832 struct aac_dev* dev;
3833 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834
Mark Haverkamp84971732005-06-20 11:55:24 -07003835 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08003836 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07003837 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 scsicmd->result = DID_NO_CONNECT << 16;
3839 scsicmd->scsi_done(scsicmd);
3840 return 0;
3841 }
3842
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 /*
3844 * Allocate and initialize a Fib then setup a BlockWrite command
3845 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08003846 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Brian King1ae948f2017-08-29 10:00:29 -05003847 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08003848 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 /*
3851 * Check that the command queued to the controller
3852 */
Brian King1ae948f2017-08-29 10:00:29 -05003853 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003856 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3857 aac_fib_complete(cmd_fibcontext);
3858 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859
3860 return -1;
3861}
3862
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003863/**
3864 *
3865 * aac_send_hba_fib
3866 * @scsicmd: the scsi command block
3867 *
3868 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3869 * scsicmd passed in.
3870 */
3871static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
3872{
3873 struct fib *cmd_fibcontext;
3874 struct aac_dev *dev;
3875 int status;
3876
3877 dev = shost_priv(scsicmd->device->host);
3878 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3879 scsicmd->device->lun > AAC_MAX_LUN - 1) {
3880 scsicmd->result = DID_NO_CONNECT << 16;
3881 scsicmd->scsi_done(scsicmd);
3882 return 0;
3883 }
3884
3885 /*
3886 * Allocate and initialize a Fib then setup a BlockWrite command
3887 */
3888 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3889 if (!cmd_fibcontext)
3890 return -1;
3891
Brian King1ae948f2017-08-29 10:00:29 -05003892 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003893 status = aac_adapter_hba(cmd_fibcontext, scsicmd);
3894
3895 /*
3896 * Check that the command queued to the controller
3897 */
Brian King1ae948f2017-08-29 10:00:29 -05003898 if (status == -EINPROGRESS)
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003899 return 0;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003900
3901 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3902 status);
3903 aac_fib_complete(cmd_fibcontext);
3904 aac_fib_free(cmd_fibcontext);
3905
3906 return -1;
3907}
3908
3909
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303910static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911{
3912 struct aac_dev *dev;
3913 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003914 int nseg;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003915 struct scatterlist *sg;
3916 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
3918 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3919 // Get rid of old data
3920 psg->count = 0;
3921 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003922 psg->sg[0].count = 0;
3923
3924 nseg = scsi_dma_map(scsicmd);
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003925 if (nseg <= 0)
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303926 return nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003928 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003930 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3931 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3932 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3933 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003935 /* hba wants the size to be exact */
3936 if (byte_count > scsi_bufflen(scsicmd)) {
3937 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3938 (byte_count - scsi_bufflen(scsicmd));
3939 psg->sg[i-1].count = cpu_to_le32(temp);
3940 byte_count = scsi_bufflen(scsicmd);
3941 }
3942 /* Check for command underflow */
3943 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3944 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3945 byte_count, scsicmd->underflow);
3946 }
3947
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 return byte_count;
3949}
3950
3951
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303952static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953{
3954 struct aac_dev *dev;
3955 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003956 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003957 int nseg;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003958 struct scatterlist *sg;
3959 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960
3961 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3962 // Get rid of old data
3963 psg->count = 0;
3964 psg->sg[0].addr[0] = 0;
3965 psg->sg[0].addr[1] = 0;
3966 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003967
3968 nseg = scsi_dma_map(scsicmd);
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003969 if (nseg <= 0)
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303970 return nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003972 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3973 int count = sg_dma_len(sg);
3974 addr = sg_dma_address(sg);
3975 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3976 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
3977 psg->sg[i].count = cpu_to_le32(count);
3978 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003980 psg->count = cpu_to_le32(nseg);
3981 /* hba wants the size to be exact */
3982 if (byte_count > scsi_bufflen(scsicmd)) {
3983 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3984 (byte_count - scsi_bufflen(scsicmd));
3985 psg->sg[i-1].count = cpu_to_le32(temp);
3986 byte_count = scsi_bufflen(scsicmd);
3987 }
3988 /* Check for command underflow */
3989 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3990 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3991 byte_count, scsicmd->underflow);
3992 }
3993
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 return byte_count;
3995}
3996
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303997static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003998{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003999 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09004000 int nseg;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004001 struct scatterlist *sg;
4002 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07004003
4004 // Get rid of old data
4005 psg->count = 0;
4006 psg->sg[0].next = 0;
4007 psg->sg[0].prev = 0;
4008 psg->sg[0].addr[0] = 0;
4009 psg->sg[0].addr[1] = 0;
4010 psg->sg[0].count = 0;
4011 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09004012
4013 nseg = scsi_dma_map(scsicmd);
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004014 if (nseg <= 0)
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05304015 return nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07004016
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004017 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4018 int count = sg_dma_len(sg);
4019 u64 addr = sg_dma_address(sg);
4020 psg->sg[i].next = 0;
4021 psg->sg[i].prev = 0;
4022 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
4023 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
4024 psg->sg[i].count = cpu_to_le32(count);
4025 psg->sg[i].flags = 0;
4026 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07004027 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004028 psg->count = cpu_to_le32(nseg);
4029 /* hba wants the size to be exact */
4030 if (byte_count > scsi_bufflen(scsicmd)) {
4031 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
4032 (byte_count - scsi_bufflen(scsicmd));
4033 psg->sg[i-1].count = cpu_to_le32(temp);
4034 byte_count = scsi_bufflen(scsicmd);
4035 }
4036 /* Check for command underflow */
4037 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4038 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
4039 byte_count, scsicmd->underflow);
4040 }
4041
Mark Haverkamp0e68c002005-08-03 15:39:49 -07004042 return byte_count;
4043}
4044
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05304045static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
4046 struct aac_raw_io2 *rio2, int sg_max)
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304047{
4048 unsigned long byte_count = 0;
4049 int nseg;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004050 struct scatterlist *sg;
4051 int i, conformable = 0;
4052 u32 min_size = PAGE_SIZE, cur_size;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304053
4054 nseg = scsi_dma_map(scsicmd);
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004055 if (nseg <= 0)
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05304056 return nseg;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304057
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004058 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4059 int count = sg_dma_len(sg);
4060 u64 addr = sg_dma_address(sg);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304061
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004062 BUG_ON(i >= sg_max);
4063 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
4064 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
4065 cur_size = cpu_to_le32(count);
4066 rio2->sge[i].length = cur_size;
4067 rio2->sge[i].flags = 0;
4068 if (i == 0) {
4069 conformable = 1;
4070 rio2->sgeFirstSize = cur_size;
4071 } else if (i == 1) {
4072 rio2->sgeNominalSize = cur_size;
4073 min_size = cur_size;
4074 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
4075 conformable = 0;
4076 if (cur_size < min_size)
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304077 min_size = cur_size;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304078 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004079 byte_count += count;
4080 }
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304081
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004082 /* hba wants the size to be exact */
4083 if (byte_count > scsi_bufflen(scsicmd)) {
4084 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
4085 (byte_count - scsi_bufflen(scsicmd));
4086 rio2->sge[i-1].length = cpu_to_le32(temp);
4087 byte_count = scsi_bufflen(scsicmd);
4088 }
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304089
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004090 rio2->sgeCnt = cpu_to_le32(nseg);
4091 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
4092 /* not conformable: evaluate required sg elements */
4093 if (!conformable) {
4094 int j, nseg_new = nseg, err_found;
4095 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
4096 err_found = 0;
4097 nseg_new = 2;
4098 for (j = 1; j < nseg - 1; ++j) {
4099 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
4100 err_found = 1;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304101 break;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004102 }
4103 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304104 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004105 if (!err_found)
4106 break;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304107 }
Nikola Pajkovsky96676242017-08-29 13:59:04 +02004108 if (i > 0 && nseg_new <= sg_max) {
4109 int ret = aac_convert_sgraw2(rio2, i, nseg, nseg_new);
4110
4111 if (ret < 0)
4112 return ret;
4113 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02004114 } else
4115 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4116
4117 /* Check for command underflow */
4118 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4119 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
4120 byte_count, scsicmd->underflow);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304121 }
4122
4123 return byte_count;
4124}
4125
4126static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
4127{
4128 struct sge_ieee1212 *sge;
4129 int i, j, pos;
4130 u32 addr_low;
4131
4132 if (aac_convert_sgl == 0)
4133 return 0;
4134
Kees Cook6da2ec52018-06-12 13:55:00 -07004135 sge = kmalloc_array(nseg_new, sizeof(struct sge_ieee1212), GFP_ATOMIC);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304136 if (sge == NULL)
Nikola Pajkovsky96676242017-08-29 13:59:04 +02004137 return -ENOMEM;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304138
4139 for (i = 1, pos = 1; i < nseg-1; ++i) {
4140 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
4141 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
4142 sge[pos].addrLow = addr_low;
4143 sge[pos].addrHigh = rio2->sge[i].addrHigh;
4144 if (addr_low < rio2->sge[i].addrLow)
4145 sge[pos].addrHigh++;
4146 sge[pos].length = pages * PAGE_SIZE;
4147 sge[pos].flags = 0;
4148 pos++;
4149 }
4150 }
4151 sge[pos] = rio2->sge[nseg-1];
4152 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
4153
4154 kfree(sge);
4155 rio2->sgeCnt = cpu_to_le32(nseg_new);
4156 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4157 rio2->sgeNominalSize = pages * PAGE_SIZE;
4158 return 0;
4159}
4160
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08004161static long aac_build_sghba(struct scsi_cmnd *scsicmd,
4162 struct aac_hba_cmd_req *hbacmd,
4163 int sg_max,
4164 u64 sg_address)
4165{
4166 unsigned long byte_count = 0;
4167 int nseg;
4168 struct scatterlist *sg;
4169 int i;
4170 u32 cur_size;
4171 struct aac_hba_sgl *sge;
4172
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08004173 nseg = scsi_dma_map(scsicmd);
4174 if (nseg <= 0) {
4175 byte_count = nseg;
4176 goto out;
4177 }
4178
4179 if (nseg > HBA_MAX_SG_EMBEDDED)
4180 sge = &hbacmd->sge[2];
4181 else
4182 sge = &hbacmd->sge[0];
4183
4184 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4185 int count = sg_dma_len(sg);
4186 u64 addr = sg_dma_address(sg);
4187
4188 WARN_ON(i >= sg_max);
4189 sge->addr_hi = cpu_to_le32((u32)(addr>>32));
4190 sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
4191 cur_size = cpu_to_le32(count);
4192 sge->len = cur_size;
4193 sge->flags = 0;
4194 byte_count += count;
4195 sge++;
4196 }
4197
4198 sge--;
4199 /* hba wants the size to be exact */
4200 if (byte_count > scsi_bufflen(scsicmd)) {
4201 u32 temp;
4202
4203 temp = le32_to_cpu(sge->len) - byte_count
4204 - scsi_bufflen(scsicmd);
4205 sge->len = cpu_to_le32(temp);
4206 byte_count = scsi_bufflen(scsicmd);
4207 }
4208
4209 if (nseg <= HBA_MAX_SG_EMBEDDED) {
4210 hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
4211 sge->flags = cpu_to_le32(0x40000000);
4212 } else {
4213 /* not embedded */
4214 hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
4215 hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
4216 hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
4217 hbacmd->sge[0].addr_lo =
4218 cpu_to_le32((u32)(sg_address & 0xffffffff));
4219 }
4220
4221 /* Check for command underflow */
4222 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4223 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4224 byte_count, scsicmd->underflow);
4225 }
4226out:
4227 return byte_count;
4228}
4229
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230#ifdef AAC_DETAILED_STATUS_INFO
4231
4232struct aac_srb_status_info {
4233 u32 status;
4234 char *str;
4235};
4236
4237
4238static struct aac_srb_status_info srb_status_info[] = {
4239 { SRB_STATUS_PENDING, "Pending Status"},
4240 { SRB_STATUS_SUCCESS, "Success"},
4241 { SRB_STATUS_ABORTED, "Aborted Command"},
4242 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07004243 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244 { SRB_STATUS_BUSY, "Device Busy"},
4245 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
4246 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
4247 { SRB_STATUS_NO_DEVICE, "No Device"},
4248 { SRB_STATUS_TIMEOUT, "Timeout"},
4249 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
4250 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
4251 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
4252 { SRB_STATUS_BUS_RESET, "Bus Reset"},
4253 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
4254 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
4255 { SRB_STATUS_NO_HBA, "No HBA"},
4256 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
4257 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
4258 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
4259 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
4260 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
4261 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07004262 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
4264 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
4265 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
4266 { SRB_STATUS_NOT_STARTED, "Not Started"},
4267 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08004268 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
4270 { 0xff, "Unknown Error"}
4271};
4272
4273char *aac_get_status_string(u32 status)
4274{
4275 int i;
4276
Tobias Klauser6391a112006-06-08 22:23:48 -07004277 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
4278 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280
4281 return "Bad Status Code";
4282}
4283
4284#endif