blob: f1f62b5da8b70992e45fec773d84549031a79fa4 [file] [log] [blame]
Thomas Gleixnerc82ee6d2019-05-19 15:51:48 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Adaptec AAC series RAID controller driver
Alan Coxfa195af2008-10-27 15:16:36 +00004 * (c) Copyright 2001 Red Hat Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * based on the old aacraid driver that is..
7 * Adaptec aacraid device driver for Linux.
8 *
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07009 * Copyright (c) 2000-2010 Adaptec, Inc.
Raghava Aditya Renukuntaf4babba2017-02-02 15:53:36 -080010 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
11 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
Raghava Aditya Renukuntaf4babba2017-02-02 15:53:36 -080013 * Module Name:
14 * aachba.c
15 *
16 * Abstract: Contains Interfaces to manage IOs.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/pci.h>
23#include <linux/spinlock.h>
24#include <linux/slab.h>
25#include <linux/completion.h>
26#include <linux/blkdev.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080027#include <linux/uaccess.h>
Salyzyn, Mark3a0086a82008-01-11 11:46:44 -080028#include <linux/highmem.h> /* For flush_kernel_dcache_page */
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040029#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -080031#include <asm/unaligned.h>
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <scsi/scsi.h>
34#include <scsi/scsi_cmnd.h>
35#include <scsi/scsi_device.h>
36#include <scsi/scsi_host.h>
37
38#include "aacraid.h"
39
40/* values for inqd_pdt: Peripheral device type in plain English */
41#define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
42#define INQD_PDT_PROC 0x03 /* Processor device */
43#define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
44#define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
45#define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
46#define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
47
48#define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
49#define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/*
52 * Sense codes
53 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080054
55#define SENCODE_NO_SENSE 0x00
56#define SENCODE_END_OF_DATA 0x00
57#define SENCODE_BECOMING_READY 0x04
58#define SENCODE_INIT_CMD_REQUIRED 0x04
Raghava Aditya Renukuntaf956a662017-02-02 15:53:23 -080059#define SENCODE_UNRECOVERED_READ_ERROR 0x11
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080060#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
61#define SENCODE_INVALID_COMMAND 0x20
62#define SENCODE_LBA_OUT_OF_RANGE 0x21
63#define SENCODE_INVALID_CDB_FIELD 0x24
64#define SENCODE_LUN_NOT_SUPPORTED 0x25
65#define SENCODE_INVALID_PARAM_FIELD 0x26
66#define SENCODE_PARAM_NOT_SUPPORTED 0x26
67#define SENCODE_PARAM_VALUE_INVALID 0x26
68#define SENCODE_RESET_OCCURRED 0x29
69#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
70#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
71#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
72#define SENCODE_DIAGNOSTIC_FAILURE 0x40
73#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
74#define SENCODE_INVALID_MESSAGE_ERROR 0x49
75#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
76#define SENCODE_OVERLAPPED_COMMAND 0x4E
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78/*
79 * Additional sense codes
80 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080081
82#define ASENCODE_NO_SENSE 0x00
83#define ASENCODE_END_OF_DATA 0x05
84#define ASENCODE_BECOMING_READY 0x01
85#define ASENCODE_INIT_CMD_REQUIRED 0x02
86#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
87#define ASENCODE_INVALID_COMMAND 0x00
88#define ASENCODE_LBA_OUT_OF_RANGE 0x00
89#define ASENCODE_INVALID_CDB_FIELD 0x00
90#define ASENCODE_LUN_NOT_SUPPORTED 0x00
91#define ASENCODE_INVALID_PARAM_FIELD 0x00
92#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
93#define ASENCODE_PARAM_VALUE_INVALID 0x02
94#define ASENCODE_RESET_OCCURRED 0x00
95#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
96#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
97#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
98#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
99#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
100#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
101#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
102#define ASENCODE_OVERLAPPED_COMMAND 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104#define BYTE0(x) (unsigned char)(x)
105#define BYTE1(x) (unsigned char)((x) >> 8)
106#define BYTE2(x) (unsigned char)((x) >> 16)
107#define BYTE3(x) (unsigned char)((x) >> 24)
108
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400109/* MODE_SENSE data format */
110typedef struct {
111 struct {
112 u8 data_length;
113 u8 med_type;
114 u8 dev_par;
115 u8 bd_length;
116 } __attribute__((packed)) hd;
117 struct {
118 u8 dens_code;
119 u8 block_count[3];
120 u8 reserved;
121 u8 block_length[3];
122 } __attribute__((packed)) bd;
123 u8 mpc_buf[3];
124} __attribute__((packed)) aac_modep_data;
125
126/* MODE_SENSE_10 data format */
127typedef struct {
128 struct {
129 u8 data_length[2];
130 u8 med_type;
131 u8 dev_par;
132 u8 rsrvd[2];
133 u8 bd_length[2];
134 } __attribute__((packed)) hd;
135 struct {
136 u8 dens_code;
137 u8 block_count[3];
138 u8 reserved;
139 u8 block_length[3];
140 } __attribute__((packed)) bd;
141 u8 mpc_buf[3];
142} __attribute__((packed)) aac_modep10_data;
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/*------------------------------------------------------------------------------
145 * S T R U C T S / T Y P E D E F S
146 *----------------------------------------------------------------------------*/
147/* SCSI inquiry data */
148struct inquiry_data {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800149 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
150 u8 inqd_dtq; /* RMB | Device Type Qualifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
152 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
153 u8 inqd_len; /* Additional length (n-4) */
154 u8 inqd_pad1[2];/* Reserved - must be zero */
155 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
156 u8 inqd_vid[8]; /* Vendor ID */
157 u8 inqd_pid[16];/* Product ID */
158 u8 inqd_prl[4]; /* Product Revision Level */
159};
160
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400161/* Added for VPD 0x83 */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800162struct tvpd_id_descriptor_type_1 {
163 u8 codeset:4; /* VPD_CODE_SET */
164 u8 reserved:4;
165 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
166 u8 reserved2:4;
167 u8 reserved3;
168 u8 identifierlength;
169 u8 venid[8];
170 u8 productid[16];
171 u8 serialnumber[8]; /* SN in ASCII */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400172
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800173};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400174
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800175struct tvpd_id_descriptor_type_2 {
176 u8 codeset:4; /* VPD_CODE_SET */
177 u8 reserved:4;
178 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
179 u8 reserved2:4;
180 u8 reserved3;
181 u8 identifierlength;
182 struct teu64id {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400183 u32 Serial;
184 /* The serial number supposed to be 40 bits,
185 * bit we only support 32, so make the last byte zero. */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800186 u8 reserved;
187 u8 venid[3];
188 } eu64id;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400189
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800190};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400191
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800192struct tvpd_id_descriptor_type_3 {
193 u8 codeset : 4; /* VPD_CODE_SET */
194 u8 reserved : 4;
195 u8 identifiertype : 4; /* VPD_IDENTIFIER_TYPE */
196 u8 reserved2 : 4;
197 u8 reserved3;
198 u8 identifierlength;
199 u8 Identifier[16];
200};
201
202struct tvpd_page83 {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400203 u8 DeviceType:5;
204 u8 DeviceTypeQualifier:3;
205 u8 PageCode;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800206 u8 reserved;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400207 u8 PageLength;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800208 struct tvpd_id_descriptor_type_1 type1;
209 struct tvpd_id_descriptor_type_2 type2;
210 struct tvpd_id_descriptor_type_3 type3;
211};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213/*
214 * M O D U L E G L O B A L S
215 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800216
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +0530217static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
218static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
219static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
220static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
221 struct aac_raw_io2 *rio2, int sg_max);
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -0800222static long aac_build_sghba(struct scsi_cmnd *scsicmd,
223 struct aac_hba_cmd_req *hbacmd,
224 int sg_max, u64 sg_address);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +0530225static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
226 int pages, int nseg, int nseg_new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -0800228static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#ifdef AAC_DETAILED_STATUS_INFO
230static char *aac_get_status_string(u32 status);
231#endif
232
233/*
234 * Non dasd selection is handled entirely in aachba now
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800235 */
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237static int nondasd = -1;
Leubner, Achimd8e965072009-04-01 07:16:08 -0700238static int aac_cache = 2; /* WCE=0 to avoid performance problems */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239static int dacmode = -1;
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800240int aac_msi;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400241int aac_commit = -1;
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700242int startup_timeout = 180;
243int aif_timeout = 120;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800244int aac_sync_mode; /* Only Sync. transfer - disabled */
Jason Yan571e1562020-09-12 11:37:49 +0800245static int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800247module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
248MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
249 " 0=off, 1=on");
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530250module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
251MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
252 " 0=off, 1=on");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800253module_param(nondasd, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800254MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
255 " 0=off, 1=on");
Salyzyn, Mark95e852e2008-01-08 12:01:07 -0800256module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800257MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
258 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
259 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
Leubner, Achimd8e965072009-04-01 07:16:08 -0700260 "\tbit 2 - Disable only if Battery is protecting Cache");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800261module_param(dacmode, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800262MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
263 " 0=off, 1=on");
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400264module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800265MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
266 " adapter for foreign arrays.\n"
267 "This is typically needed in systems that do not have a BIOS."
268 " 0=off, 1=on");
269module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
270MODULE_PARM_DESC(msi, "IRQ handling."
Mahesh Rajashekhara9022d372015-08-28 06:38:35 -0400271 " 0=PIC(default), 1=MSI, 2=MSI-X)");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700272module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800273MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
274 " adapter to have it's kernel up and\n"
275 "running. This is typically adjusted for large systems that do not"
276 " have a BIOS.");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700277module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800278MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
279 " applications to pick up AIFs before\n"
280 "deregistering them. This is typically adjusted for heavily burdened"
281 " systems.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Raghava Aditya Renukunta09624642017-02-16 12:51:22 -0800283int aac_fib_dump;
284module_param(aac_fib_dump, int, 0644);
285MODULE_PARM_DESC(aac_fib_dump, "Dump controller fibs prior to IOP_RESET 0=off, 1=on");
286
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700287int numacb = -1;
288module_param(numacb, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800289MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
290 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
291 " to use suggestion from Firmware.");
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700292
Jason Yan571e1562020-09-12 11:37:49 +0800293static int acbsize = -1;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700294module_param(acbsize, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800295MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
296 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
297 " suggestion from Firmware.");
Mark Haverkamp653ba582006-09-19 08:59:43 -0700298
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400299int update_interval = 30 * 60;
300module_param(update_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800301MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
302 " updates issued to adapter.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400303
Raghava Aditya Renukunta11da1b72017-02-16 12:51:19 -0800304int check_interval = 60;
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400305module_param(check_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800306MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
307 " checks.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400308
Andrew Morton87f3bda2007-08-10 14:50:30 -0700309int aac_check_reset = 1;
310module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
Paul Bolle95e7a8e2008-04-16 14:43:00 +0200311MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800312 " adapter. a value of -1 forces the reset to adapters programmed to"
313 " ignore it.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400314
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800315int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700316module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800317MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
318 " -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700319
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800320int aac_reset_devices;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400321module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
322MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700323
Jason Yan571e1562020-09-12 11:37:49 +0800324static int aac_wwn = 1;
Leubner, Achimd8e965072009-04-01 07:16:08 -0700325module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
326MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
327 "\t0 - Disable\n"
328 "\t1 - Array Meta Data Signature (default)\n"
329 "\t2 - Adapter Serial Number");
330
331
Mark Haverkamp03d44332007-03-15 10:27:45 -0700332static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
333 struct fib *fibptr) {
334 struct scsi_device *device;
335
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800336 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
Salyzyn, Markc835e372007-07-26 14:20:02 -0400337 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800338 aac_fib_complete(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800339 return 0;
340 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700341 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
342 device = scsicmd->device;
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800343 if (unlikely(!device)) {
Mark Haverkamp03d44332007-03-15 10:27:45 -0700344 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
345 aac_fib_complete(fibptr);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700346 return 0;
347 }
348 return 1;
349}
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/**
352 * aac_get_config_status - check the adapter configuration
Lee Jonesb1159582020-07-13 08:59:38 +0100353 * @dev: aac driver data
354 * @commit_flag: force sending CT_COMMIT_CONFIG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 *
356 * Query config status, and commit the configuration if needed.
357 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700358int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
360 int status = 0;
361 struct fib * fibptr;
362
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800363 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 return -ENOMEM;
365
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800366 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 {
368 struct aac_get_config_status *dinfo;
369 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
370
371 dinfo->command = cpu_to_le32(VM_ContainerConfig);
372 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
373 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
374 }
375
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800376 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 fibptr,
378 sizeof (struct aac_get_config_status),
379 FsaNormal,
380 1, 1,
381 NULL, NULL);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800382 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
384 } else {
385 struct aac_get_config_status_resp *reply
386 = (struct aac_get_config_status_resp *) fib_data(fibptr);
387 dprintk((KERN_WARNING
388 "aac_get_config_status: response=%d status=%d action=%d\n",
389 le32_to_cpu(reply->response),
390 le32_to_cpu(reply->status),
391 le32_to_cpu(reply->data.action)));
392 if ((le32_to_cpu(reply->response) != ST_OK) ||
393 (le32_to_cpu(reply->status) != CT_OK) ||
394 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
395 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
396 status = -EINVAL;
397 }
398 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530399 /* Do not set XferState to zero unless receives a response from F/W */
400 if (status >= 0)
401 aac_fib_complete(fibptr);
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
404 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400405 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800407 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 dinfo = (struct aac_commit_config *) fib_data(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 dinfo->command = cpu_to_le32(VM_ContainerConfig);
411 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800412
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800413 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 fibptr,
415 sizeof (struct aac_commit_config),
416 FsaNormal,
417 1, 1,
418 NULL, NULL);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530419 /* Do not set XferState to zero unless
420 * receives a response from F/W */
421 if (status >= 0)
422 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400423 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 printk(KERN_WARNING
425 "aac_get_config_status: Foreign device configurations are being ignored\n");
426 }
427 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530428 /* FIB should be freed only after getting the response from the F/W */
429 if (status != -ERESTARTSYS)
430 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 return status;
432}
433
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -0700434static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
435{
436 char inq_data;
437 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
438 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
439 inq_data &= 0xdf;
440 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
441 }
442}
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444/**
445 * aac_get_containers - list containers
Lee Jonesb1159582020-07-13 08:59:38 +0100446 * @dev: aac driver data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 *
448 * Make a list of all containers on this controller
449 */
450int aac_get_containers(struct aac_dev *dev)
451{
452 struct fsa_dev_info *fsa_dev_ptr;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800453 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 int status = 0;
455 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 struct aac_get_container_count *dinfo;
457 struct aac_get_container_count_resp *dresp;
458 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
459
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800460 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return -ENOMEM;
462
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800463 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
465 dinfo->command = cpu_to_le32(VM_ContainerConfig);
466 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
467
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800468 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 fibptr,
470 sizeof (struct aac_get_container_count),
471 FsaNormal,
472 1, 1,
473 NULL, NULL);
474 if (status >= 0) {
475 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
476 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800477 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharaa7129a52015-03-26 10:41:27 -0400478 AAC_OPTION_SUPPORTED_240_VOLUMES) {
479 maximum_num_containers =
480 le32_to_cpu(dresp->MaxSimpleVolumes);
481 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800482 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530484 /* FIB should be freed only after getting the response from the F/W */
485 if (status != -ERESTARTSYS)
486 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
489 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800490 if (dev->fsa_dev == NULL ||
491 dev->maximum_num_containers != maximum_num_containers) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800493 fsa_dev_ptr = dev->fsa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800495 dev->fsa_dev = kcalloc(maximum_num_containers,
496 sizeof(*fsa_dev_ptr), GFP_KERNEL);
497
498 kfree(fsa_dev_ptr);
499 fsa_dev_ptr = NULL;
500
501
502 if (!dev->fsa_dev)
503 return -ENOMEM;
504
505 dev->maximum_num_containers = maximum_num_containers;
506 }
507 for (index = 0; index < dev->maximum_num_containers; index++) {
508 dev->fsa_dev[index].devname[0] = '\0';
509 dev->fsa_dev[index].valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Mark Haverkampfe76df42007-03-15 12:55:07 -0700511 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Mark Haverkampfe76df42007-03-15 12:55:07 -0700513 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
515 break;
516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return status;
519}
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521static void get_container_name_callback(void *context, struct fib * fibptr)
522{
523 struct aac_get_name_resp * get_name_reply;
524 struct scsi_cmnd * scsicmd;
525
526 scsicmd = (struct scsi_cmnd *) context;
527
Mark Haverkamp03d44332007-03-15 10:27:45 -0700528 if (!aac_valid_context(scsicmd, fibptr))
529 return;
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700532 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
535 /* Failure is irrelevant, using default value instead */
536 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
537 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700538 char *sp = get_name_reply->data;
Pankaj Bharadiyac5936422019-12-09 10:31:43 -0800539 int data_size = sizeof_field(struct aac_get_name_resp, data);
Raghava Aditya Renukuntac8026732017-08-04 03:51:41 -0700540
541 sp[data_size - 1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 while (*sp == ' ')
543 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700544 if (*sp) {
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900545 struct inquiry_data inq;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700546 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
547 int count = sizeof(d);
548 char *dp = d;
549 do {
550 *dp++ = (*sp) ? *sp++ : ' ';
551 } while (--count > 0);
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900552
553 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
554 memcpy(inq.inqd_pid, d, sizeof(d));
555 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700558
Hannes Reineckecdec16c2021-01-13 10:04:40 +0100559 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800561 aac_fib_complete(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700562 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
Lee Jonese7eb4142020-07-13 08:46:44 +0100565/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 * aac_get_container_name - get container name, none blocking.
567 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700568static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
570 int status;
Raghava Aditya Renukuntac8026732017-08-04 03:51:41 -0700571 int data_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 struct aac_get_name *dinfo;
573 struct fib * cmd_fibcontext;
574 struct aac_dev * dev;
575
576 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
577
Pankaj Bharadiyac5936422019-12-09 10:31:43 -0800578 data_size = sizeof_field(struct aac_get_name_resp, data);
Raghava Aditya Renukuntac8026732017-08-04 03:51:41 -0700579
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800580 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800582 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
Brian King1ae948f2017-08-29 10:00:29 -0500584 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 dinfo->command = cpu_to_le32(VM_ContainerConfig);
587 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700588 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Raghava Aditya Renukuntac8026732017-08-04 03:51:41 -0700589 dinfo->count = cpu_to_le32(data_size - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800591 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800592 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -0400593 sizeof(struct aac_get_name_resp),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800594 FsaNormal,
595 0, 1,
596 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 /*
600 * Check that the command queued to the controller
601 */
Brian King1ae948f2017-08-29 10:00:29 -0500602 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 return 0;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800604
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800605 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
606 aac_fib_complete(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 return -1;
608}
609
Mark Haverkampfe76df42007-03-15 12:55:07 -0700610static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
611{
612 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
613
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400614 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700615 return aac_scsi_cmd(scsicmd);
616
617 scsicmd->result = DID_NO_CONNECT << 16;
618 scsicmd->scsi_done(scsicmd);
619 return 0;
620}
621
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400622static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700623{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700624 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700625 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700626 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800627 int i;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700628
Mark Haverkamp03d44332007-03-15 10:27:45 -0700629
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400630 if (!aac_valid_context(scsicmd, fibptr))
631 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700632
633 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400634 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700635 if (fsa_dev_ptr) {
636 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800637 __le32 sup_options2;
638
Mark Haverkampfe76df42007-03-15 12:55:07 -0700639 fsa_dev_ptr += scmd_id(scsicmd);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800640 sup_options2 =
641 fibptr->dev->supplement_adapter_info.supported_options2;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700642
643 if ((le32_to_cpu(dresp->status) == ST_OK) &&
644 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
645 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800646 if (!(sup_options2 & AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400647 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
648 fsa_dev_ptr->block_size = 0x200;
649 } else {
650 fsa_dev_ptr->block_size =
651 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
652 }
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800653 for (i = 0; i < 16; i++)
654 fsa_dev_ptr->identifier[i] =
655 dresp->mnt[0].fileinfo.bdevinfo
656 .identifier[i];
Mark Haverkampfe76df42007-03-15 12:55:07 -0700657 fsa_dev_ptr->valid = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -0400658 /* sense_key holds the current state of the spin-up */
659 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
660 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
661 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
662 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700663 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
664 fsa_dev_ptr->size
665 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
666 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
667 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
668 }
669 if ((fsa_dev_ptr->valid & 1) == 0)
670 fsa_dev_ptr->valid = 0;
671 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
672 }
673 aac_fib_complete(fibptr);
674 aac_fib_free(fibptr);
675 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
676 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400677 (*callback)(scsicmd);
678 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700679}
680
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400681static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700682{
683 struct scsi_cmnd * scsicmd;
684 struct aac_mount * dresp;
685 struct aac_query_mount *dinfo;
686 int status;
687
688 dresp = (struct aac_mount *) fib_data(fibptr);
Dave Carroll6c92f7d2017-09-15 11:04:28 -0600689 if (!aac_supports_2T(fibptr->dev)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400690 dresp->mnt[0].capacityhigh = 0;
Dave Carroll6c92f7d2017-09-15 11:04:28 -0600691 if ((le32_to_cpu(dresp->status) == ST_OK) &&
692 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
693 _aac_probe_container2(context, fibptr);
694 return;
695 }
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400696 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700697 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700698
Mark Haverkamp03d44332007-03-15 10:27:45 -0700699 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400700 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700701
Mark Haverkampfe76df42007-03-15 12:55:07 -0700702 aac_fib_init(fibptr);
703
704 dinfo = (struct aac_query_mount *)fib_data(fibptr);
705
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800706 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400707 AAC_OPTION_VARIABLE_BLOCK_SIZE)
708 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
709 else
710 dinfo->command = cpu_to_le32(VM_NameServe64);
711
Mark Haverkampfe76df42007-03-15 12:55:07 -0700712 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
713 dinfo->type = cpu_to_le32(FT_FILESYS);
Brian King1ae948f2017-08-29 10:00:29 -0500714 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700715
716 status = aac_fib_send(ContainerCommand,
717 fibptr,
718 sizeof(struct aac_query_mount),
719 FsaNormal,
720 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400721 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700722 (void *) scsicmd);
723 /*
724 * Check that the command queued to the controller
725 */
Brian King1ae948f2017-08-29 10:00:29 -0500726 if (status < 0 && status != -EINPROGRESS) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700727 /* Inherit results from VM_NameServe, if any */
728 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400729 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700730 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700731}
732
733static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
734{
735 struct fib * fibptr;
736 int status = -ENOMEM;
737
738 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
739 struct aac_query_mount *dinfo;
740
741 aac_fib_init(fibptr);
742
743 dinfo = (struct aac_query_mount *)fib_data(fibptr);
744
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800745 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400746 AAC_OPTION_VARIABLE_BLOCK_SIZE)
747 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
748 else
749 dinfo->command = cpu_to_le32(VM_NameServe);
750
Mark Haverkampfe76df42007-03-15 12:55:07 -0700751 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
752 dinfo->type = cpu_to_le32(FT_FILESYS);
753 scsicmd->SCp.ptr = (char *)callback;
Brian King1ae948f2017-08-29 10:00:29 -0500754 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700755
756 status = aac_fib_send(ContainerCommand,
757 fibptr,
758 sizeof(struct aac_query_mount),
759 FsaNormal,
760 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400761 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700762 (void *) scsicmd);
763 /*
764 * Check that the command queued to the controller
765 */
Brian King1ae948f2017-08-29 10:00:29 -0500766 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700767 return 0;
Brian King1ae948f2017-08-29 10:00:29 -0500768
Mark Haverkampfe76df42007-03-15 12:55:07 -0700769 if (status < 0) {
770 scsicmd->SCp.ptr = NULL;
771 aac_fib_complete(fibptr);
772 aac_fib_free(fibptr);
773 }
774 }
775 if (status < 0) {
776 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
777 if (fsa_dev_ptr) {
778 fsa_dev_ptr += scmd_id(scsicmd);
779 if ((fsa_dev_ptr->valid & 1) == 0) {
780 fsa_dev_ptr->valid = 0;
781 return (*callback)(scsicmd);
782 }
783 }
784 }
785 return status;
786}
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788/**
Lee Jonesa80218c2021-03-03 14:46:08 +0000789 * aac_probe_container_callback1 - query a logical volume
790 * @scsicmd: the scsi command block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 *
792 * Queries the controller about the given volume. The volume information
793 * is updated in the struct fsa_dev_info structure rather than returned.
794 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700795static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
796{
797 scsicmd->device = NULL;
798 return 0;
799}
800
Phong Tran779dfcf2020-03-09 22:53:19 +0700801static void aac_probe_container_scsi_done(struct scsi_cmnd *scsi_cmnd)
802{
803 aac_probe_container_callback1(scsi_cmnd);
804}
805
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800806int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700808 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
809 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Mark Haverkampfe76df42007-03-15 12:55:07 -0700812 if (!scsicmd || !scsidev) {
813 kfree(scsicmd);
814 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700815 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
Phong Tran779dfcf2020-03-09 22:53:19 +0700817 scsicmd->scsi_done = aac_probe_container_scsi_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Mark Haverkampfe76df42007-03-15 12:55:07 -0700819 scsicmd->device = scsidev;
820 scsidev->sdev_state = 0;
821 scsidev->id = cid;
822 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Mark Haverkampfe76df42007-03-15 12:55:07 -0700824 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
825 while (scsicmd->device == scsidev)
826 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400827 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700828 status = scsicmd->SCp.Status;
829 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 return status;
831}
832
833/* Local Structure to set SCSI inquiry data strings */
834struct scsi_inq {
835 char vid[8]; /* Vendor ID */
836 char pid[16]; /* Product ID */
837 char prl[4]; /* Product Revision Level */
838};
839
840/**
Lee Jonesa80218c2021-03-03 14:46:08 +0000841 * inqstrcpy - string merge
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 * @a: string to copy from
843 * @b: string to copy to
844 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800845 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 * without copying \0
847 */
848
849static void inqstrcpy(char *a, char *b)
850{
851
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800852 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 *b++ = *a++;
854}
855
856static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800857 "None",
858 "Volume",
859 "Mirror",
860 "Stripe",
861 "RAID5",
862 "SSRW",
863 "SSRO",
864 "Morph",
865 "Legacy",
866 "RAID4",
867 "RAID10",
868 "RAID00",
869 "V-MIRRORS",
870 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700872 "RAID5D",
873 "RAID5D0",
874 "RAID1E",
875 "RAID6",
876 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800877 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878};
879
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800880char * get_container_type(unsigned tindex)
881{
882 if (tindex >= ARRAY_SIZE(container_types))
883 tindex = ARRAY_SIZE(container_types) - 1;
884 return container_types[tindex];
885}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887/* Function: setinqstr
888 *
889 * Arguments: [1] pointer to void [1] int
890 *
891 * Purpose: Sets SCSI inquiry data strings for vendor, product
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300892 * and revision level. Allows strings to be set in platform dependent
893 * files instead of in OS dependent driver source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 */
895
Mark Haverkamp794d0602005-10-24 10:51:53 -0700896static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
898 struct scsi_inq *str;
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800899 struct aac_supplement_adapter_info *sup_adap_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800901 sup_adap_info = &dev->supplement_adapter_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700903 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800905 if (sup_adap_info->adapter_type_text[0]) {
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800906 int c;
Raghava Aditya Renukuntaf4e87082017-12-26 20:34:22 -0800907 char *cp;
908 char *cname = kmemdup(sup_adap_info->adapter_type_text,
909 sizeof(sup_adap_info->adapter_type_text),
910 GFP_ATOMIC);
Raghava Aditya Renukuntaf4e87082017-12-26 20:34:22 -0800911 if (!cname)
912 return;
913
914 cp = cname;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800915 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
916 inqstrcpy("SMC", str->vid);
917 else {
918 c = sizeof(str->vid);
919 while (*cp && *cp != ' ' && --c)
920 ++cp;
921 c = *cp;
922 *cp = '\0';
Raghava Aditya Renukuntaf4e87082017-12-26 20:34:22 -0800923 inqstrcpy(cname, str->vid);
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800924 *cp = c;
925 while (*cp && *cp != ' ')
926 ++cp;
927 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700928 while (*cp == ' ')
929 ++cp;
930 /* last six chars reserved for vol type */
Colin Ian King91814742018-01-05 15:31:06 +0000931 if (strlen(cp) > sizeof(str->pid))
Mark Haverkamp794d0602005-10-24 10:51:53 -0700932 cp[sizeof(str->pid)] = '\0';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700933 inqstrcpy (cp, str->pid);
Raghava Aditya Renukuntaf4e87082017-12-26 20:34:22 -0800934
935 kfree(cname);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700936 } else {
937 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700938
939 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700940 /* last six chars reserved for vol type */
941 inqstrcpy (mp->model, str->pid);
942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Tobias Klauser6391a112006-06-08 22:23:48 -0700944 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 char *findit = str->pid;
946
947 for ( ; *findit != ' '; findit++); /* walk till we find a space */
948 /* RAID is superfluous in the context of a RAID device */
949 if (memcmp(findit-4, "RAID", 4) == 0)
950 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700951 if (((findit - str->pid) + strlen(container_types[tindex]))
952 < (sizeof(str->pid) + sizeof(str->prl)))
953 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
955 inqstrcpy ("V1.0", str->prl);
956}
957
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800958static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
959 struct aac_dev *dev, struct scsi_cmnd *scsicmd)
960{
961 int container;
962
963 vpdpage83data->type3.codeset = 1;
964 vpdpage83data->type3.identifiertype = 3;
965 vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
966 - 4;
967
968 for (container = 0; container < dev->maximum_num_containers;
969 container++) {
970
971 if (scmd_id(scsicmd) == container) {
972 memcpy(vpdpage83data->type3.Identifier,
973 dev->fsa_dev[container].identifier,
974 16);
975 break;
976 }
977 }
978}
979
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400980static void get_container_serial_callback(void *context, struct fib * fibptr)
981{
982 struct aac_get_serial_resp * get_serial_reply;
983 struct scsi_cmnd * scsicmd;
984
985 BUG_ON(fibptr == NULL);
986
987 scsicmd = (struct scsi_cmnd *) context;
988 if (!aac_valid_context(scsicmd, fibptr))
989 return;
990
991 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
992 /* Failure is irrelevant, using default value instead */
993 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400994 /*Check to see if it's for VPD 0x83 or 0x80 */
995 if (scsicmd->cmnd[2] == 0x83) {
996 /* vpd page 0x83 - Device Identification Page */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800997 struct aac_dev *dev;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400998 int i;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800999 struct tvpd_page83 vpdpage83data;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001000
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001001 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1002
1003 memset(((u8 *)&vpdpage83data), 0,
1004 sizeof(vpdpage83data));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001005
1006 /* DIRECT_ACCESS_DEVIC */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001007 vpdpage83data.DeviceType = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001008 /* DEVICE_CONNECTED */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001009 vpdpage83data.DeviceTypeQualifier = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001010 /* VPD_DEVICE_IDENTIFIERS */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001011 vpdpage83data.PageCode = 0x83;
1012 vpdpage83data.reserved = 0;
1013 vpdpage83data.PageLength =
1014 sizeof(vpdpage83data.type1) +
1015 sizeof(vpdpage83data.type2);
1016
1017 /* VPD 83 Type 3 is not supported for ARC */
1018 if (dev->sa_firmware)
1019 vpdpage83data.PageLength +=
1020 sizeof(vpdpage83data.type3);
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001021
1022 /* T10 Vendor Identifier Field Format */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001023 /* VpdcodesetAscii */
1024 vpdpage83data.type1.codeset = 2;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001025 /* VpdIdentifierTypeVendorId */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001026 vpdpage83data.type1.identifiertype = 1;
1027 vpdpage83data.type1.identifierlength =
1028 sizeof(vpdpage83data.type1) - 4;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001029
1030 /* "ADAPTEC " for adaptec */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001031 memcpy(vpdpage83data.type1.venid,
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001032 "ADAPTEC ",
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001033 sizeof(vpdpage83data.type1.venid));
1034 memcpy(vpdpage83data.type1.productid,
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001035 "ARRAY ",
1036 sizeof(
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001037 vpdpage83data.type1.productid));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001038
1039 /* Convert to ascii based serial number.
1040 * The LSB is the the end.
1041 */
1042 for (i = 0; i < 8; i++) {
1043 u8 temp =
1044 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
1045 if (temp > 0x9) {
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001046 vpdpage83data.type1.serialnumber[i] =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001047 'A' + (temp - 0xA);
1048 } else {
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001049 vpdpage83data.type1.serialnumber[i] =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001050 '0' + temp;
1051 }
1052 }
1053
1054 /* VpdCodeSetBinary */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001055 vpdpage83data.type2.codeset = 1;
1056 /* VpdidentifiertypeEUI64 */
1057 vpdpage83data.type2.identifiertype = 2;
1058 vpdpage83data.type2.identifierlength =
1059 sizeof(vpdpage83data.type2) - 4;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001060
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001061 vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1062 vpdpage83data.type2.eu64id.venid[1] = 0;
1063 vpdpage83data.type2.eu64id.venid[2] = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001064
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001065 vpdpage83data.type2.eu64id.Serial =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001066 get_serial_reply->uid;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001067 vpdpage83data.type2.eu64id.reserved = 0;
1068
1069 /*
1070 * VpdIdentifierTypeFCPHName
1071 * VPD 0x83 Type 3 not supported for ARC
1072 */
1073 if (dev->sa_firmware) {
1074 build_vpd83_type3(&vpdpage83data,
1075 dev, scsicmd);
1076 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001077
1078 /* Move the inquiry data to the response buffer. */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001079 scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1080 sizeof(vpdpage83data));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001081 } else {
1082 /* It must be for VPD 0x80 */
1083 char sp[13];
1084 /* EVPD bit set */
1085 sp[0] = INQD_PDT_DA;
1086 sp[1] = scsicmd->cmnd[2];
1087 sp[2] = 0;
1088 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1089 le32_to_cpu(get_serial_reply->uid));
1090 scsi_sg_copy_from_buffer(scsicmd, sp,
1091 sizeof(sp));
1092 }
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001093 }
1094
Hannes Reineckecdec16c2021-01-13 10:04:40 +01001095 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001096
1097 aac_fib_complete(fibptr);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001098 scsicmd->scsi_done(scsicmd);
1099}
1100
Lee Jonese7eb4142020-07-13 08:46:44 +01001101/*
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001102 * aac_get_container_serial - get container serial, none blocking.
1103 */
1104static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1105{
1106 int status;
1107 struct aac_get_serial *dinfo;
1108 struct fib * cmd_fibcontext;
1109 struct aac_dev * dev;
1110
1111 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1112
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08001113 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001114
1115 aac_fib_init(cmd_fibcontext);
1116 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1117
1118 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1119 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1120 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Brian King1ae948f2017-08-29 10:00:29 -05001121 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001122
1123 status = aac_fib_send(ContainerCommand,
1124 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -04001125 sizeof(struct aac_get_serial_resp),
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001126 FsaNormal,
1127 0, 1,
1128 (fib_callback) get_container_serial_callback,
1129 (void *) scsicmd);
1130
1131 /*
1132 * Check that the command queued to the controller
1133 */
Brian King1ae948f2017-08-29 10:00:29 -05001134 if (status == -EINPROGRESS)
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001135 return 0;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001136
1137 printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1138 aac_fib_complete(cmd_fibcontext);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001139 return -1;
1140}
1141
1142/* Function: setinqserial
1143 *
1144 * Arguments: [1] pointer to void [1] int
1145 *
1146 * Purpose: Sets SCSI Unit Serial number.
1147 * This is a fake. We should read a proper
1148 * serial number from the container. <SuSE>But
1149 * without docs it's quite hard to do it :-)
1150 * So this will have to do in the meantime.</SuSE>
1151 */
1152
1153static int setinqserial(struct aac_dev *dev, void *data, int cid)
1154{
1155 /*
1156 * This breaks array migration.
1157 */
1158 return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1159 le32_to_cpu(dev->adapter_info.serial[0]), cid);
1160}
1161
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001162static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1163 u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164{
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001165 u8 *sense_buf = (u8 *)sense_data;
1166 /* Sense data valid, err code 70h */
1167 sense_buf[0] = 0x70; /* No info field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 sense_buf[1] = 0; /* Segment number, always zero */
1169
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001170 sense_buf[2] = sense_key; /* Sense key */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 sense_buf[12] = sense_code; /* Additional sense code */
1173 sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001174
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 if (sense_key == ILLEGAL_REQUEST) {
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001176 sense_buf[7] = 10; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001178 sense_buf[15] = bit_pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 /* Illegal parameter is in the parameter block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 if (sense_code == SENCODE_INVALID_CDB_FIELD)
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001181 sense_buf[15] |= 0xc0;/* Std sense key specific field */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 /* Illegal parameter is in the CDB block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 sense_buf[16] = field_pointer >> 8; /* MSB */
1184 sense_buf[17] = field_pointer; /* LSB */
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001185 } else
1186 sense_buf[7] = 6; /* Additional sense length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001189static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1190{
1191 if (lba & 0xffffffff00000000LL) {
1192 int cid = scmd_id(cmd);
1193 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01001194 cmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001195 set_sense(&dev->fsa_dev[cid].sense_data,
1196 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1197 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001198 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001199 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1200 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001201 cmd->scsi_done(cmd);
1202 return 1;
1203 }
1204 return 0;
1205}
1206
1207static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1208{
1209 return 0;
1210}
1211
1212static void io_callback(void *context, struct fib * fibptr);
1213
1214static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1215{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301216 struct aac_dev *dev = fib->dev;
1217 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301218 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001219
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301220 aac_fib_init(fib);
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -08001221 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1222 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1223 !dev->sync_mode) {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301224 struct aac_raw_io2 *readcmd2;
1225 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1226 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1227 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1228 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001229 readcmd2->byteCount = cpu_to_le32(count *
1230 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301231 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1232 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301233 ret = aac_build_sgraw2(cmd, readcmd2,
1234 dev->scsi_host_ptr->sg_tablesize);
1235 if (ret < 0)
1236 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301237 command = ContainerRawIo2;
1238 fibsize = sizeof(struct aac_raw_io2) +
1239 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1240 } else {
1241 struct aac_raw_io *readcmd;
1242 readcmd = (struct aac_raw_io *) fib_data(fib);
1243 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1244 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001245 readcmd->count = cpu_to_le32(count *
1246 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301247 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1248 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1249 readcmd->bpTotal = 0;
1250 readcmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301251 ret = aac_build_sgraw(cmd, &readcmd->sg);
1252 if (ret < 0)
1253 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301254 command = ContainerRawIo;
1255 fibsize = sizeof(struct aac_raw_io) +
1256 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1257 }
1258
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001259 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1260 /*
1261 * Now send the Fib to the adapter
1262 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301263 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001264 fib,
1265 fibsize,
1266 FsaNormal,
1267 0, 1,
1268 (fib_callback) io_callback,
1269 (void *) cmd);
1270}
1271
1272static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1273{
1274 u16 fibsize;
1275 struct aac_read64 *readcmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301276 long ret;
1277
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001278 aac_fib_init(fib);
1279 readcmd = (struct aac_read64 *) fib_data(fib);
1280 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1281 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1282 readcmd->sector_count = cpu_to_le16(count);
1283 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1284 readcmd->pad = 0;
1285 readcmd->flags = 0;
1286
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301287 ret = aac_build_sg64(cmd, &readcmd->sg);
1288 if (ret < 0)
1289 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001290 fibsize = sizeof(struct aac_read64) +
1291 ((le32_to_cpu(readcmd->sg.count) - 1) *
1292 sizeof (struct sgentry64));
1293 BUG_ON (fibsize > (fib->dev->max_fib_size -
1294 sizeof(struct aac_fibhdr)));
1295 /*
1296 * Now send the Fib to the adapter
1297 */
1298 return aac_fib_send(ContainerCommand64,
1299 fib,
1300 fibsize,
1301 FsaNormal,
1302 0, 1,
1303 (fib_callback) io_callback,
1304 (void *) cmd);
1305}
1306
1307static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1308{
1309 u16 fibsize;
1310 struct aac_read *readcmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001311 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301312 long ret;
1313
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001314 aac_fib_init(fib);
1315 readcmd = (struct aac_read *) fib_data(fib);
1316 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001317 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001318 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001319 readcmd->count = cpu_to_le32(count *
1320 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001321
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301322 ret = aac_build_sg(cmd, &readcmd->sg);
1323 if (ret < 0)
1324 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001325 fibsize = sizeof(struct aac_read) +
1326 ((le32_to_cpu(readcmd->sg.count) - 1) *
1327 sizeof (struct sgentry));
1328 BUG_ON (fibsize > (fib->dev->max_fib_size -
1329 sizeof(struct aac_fibhdr)));
1330 /*
1331 * Now send the Fib to the adapter
1332 */
1333 return aac_fib_send(ContainerCommand,
1334 fib,
1335 fibsize,
1336 FsaNormal,
1337 0, 1,
1338 (fib_callback) io_callback,
1339 (void *) cmd);
1340}
1341
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001342static 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 -08001343{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301344 struct aac_dev *dev = fib->dev;
1345 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301346 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001347
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301348 aac_fib_init(fib);
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -08001349 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1350 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1351 !dev->sync_mode) {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301352 struct aac_raw_io2 *writecmd2;
1353 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1354 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1355 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1356 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001357 writecmd2->byteCount = cpu_to_le32(count *
1358 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301359 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1360 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1361 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1362 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1363 cpu_to_le16(RIO2_IO_TYPE_WRITE);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301364 ret = aac_build_sgraw2(cmd, writecmd2,
1365 dev->scsi_host_ptr->sg_tablesize);
1366 if (ret < 0)
1367 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301368 command = ContainerRawIo2;
1369 fibsize = sizeof(struct aac_raw_io2) +
1370 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1371 } else {
1372 struct aac_raw_io *writecmd;
1373 writecmd = (struct aac_raw_io *) fib_data(fib);
1374 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1375 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001376 writecmd->count = cpu_to_le32(count *
1377 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301378 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1379 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1380 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1381 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1382 cpu_to_le16(RIO_TYPE_WRITE);
1383 writecmd->bpTotal = 0;
1384 writecmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301385 ret = aac_build_sgraw(cmd, &writecmd->sg);
1386 if (ret < 0)
1387 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301388 command = ContainerRawIo;
1389 fibsize = sizeof(struct aac_raw_io) +
1390 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1391 }
1392
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001393 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1394 /*
1395 * Now send the Fib to the adapter
1396 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301397 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001398 fib,
1399 fibsize,
1400 FsaNormal,
1401 0, 1,
1402 (fib_callback) io_callback,
1403 (void *) cmd);
1404}
1405
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001406static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001407{
1408 u16 fibsize;
1409 struct aac_write64 *writecmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301410 long ret;
1411
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001412 aac_fib_init(fib);
1413 writecmd = (struct aac_write64 *) fib_data(fib);
1414 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1415 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1416 writecmd->sector_count = cpu_to_le16(count);
1417 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1418 writecmd->pad = 0;
1419 writecmd->flags = 0;
1420
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301421 ret = aac_build_sg64(cmd, &writecmd->sg);
1422 if (ret < 0)
1423 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001424 fibsize = sizeof(struct aac_write64) +
1425 ((le32_to_cpu(writecmd->sg.count) - 1) *
1426 sizeof (struct sgentry64));
1427 BUG_ON (fibsize > (fib->dev->max_fib_size -
1428 sizeof(struct aac_fibhdr)));
1429 /*
1430 * Now send the Fib to the adapter
1431 */
1432 return aac_fib_send(ContainerCommand64,
1433 fib,
1434 fibsize,
1435 FsaNormal,
1436 0, 1,
1437 (fib_callback) io_callback,
1438 (void *) cmd);
1439}
1440
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001441static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001442{
1443 u16 fibsize;
1444 struct aac_write *writecmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001445 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301446 long ret;
1447
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001448 aac_fib_init(fib);
1449 writecmd = (struct aac_write *) fib_data(fib);
1450 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001451 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001452 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001453 writecmd->count = cpu_to_le32(count *
1454 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001455 writecmd->sg.count = cpu_to_le32(1);
1456 /* ->stable is not used - it did mean which type of write */
1457
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301458 ret = aac_build_sg(cmd, &writecmd->sg);
1459 if (ret < 0)
1460 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001461 fibsize = sizeof(struct aac_write) +
1462 ((le32_to_cpu(writecmd->sg.count) - 1) *
1463 sizeof (struct sgentry));
1464 BUG_ON (fibsize > (fib->dev->max_fib_size -
1465 sizeof(struct aac_fibhdr)));
1466 /*
1467 * Now send the Fib to the adapter
1468 */
1469 return aac_fib_send(ContainerCommand,
1470 fib,
1471 fibsize,
1472 FsaNormal,
1473 0, 1,
1474 (fib_callback) io_callback,
1475 (void *) cmd);
1476}
1477
1478static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1479{
1480 struct aac_srb * srbcmd;
1481 u32 flag;
1482 u32 timeout;
Balsundar Pe2fd90d2019-10-15 11:52:01 +05301483 struct aac_dev *dev = fib->dev;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001484
1485 aac_fib_init(fib);
1486 switch(cmd->sc_data_direction){
1487 case DMA_TO_DEVICE:
1488 flag = SRB_DataOut;
1489 break;
1490 case DMA_BIDIRECTIONAL:
1491 flag = SRB_DataIn | SRB_DataOut;
1492 break;
1493 case DMA_FROM_DEVICE:
1494 flag = SRB_DataIn;
1495 break;
1496 case DMA_NONE:
1497 default: /* shuts up some versions of gcc */
1498 flag = SRB_NoDataXfer;
1499 break;
1500 }
1501
1502 srbcmd = (struct aac_srb*) fib_data(fib);
1503 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1504 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1505 srbcmd->id = cpu_to_le32(scmd_id(cmd));
1506 srbcmd->lun = cpu_to_le32(cmd->device->lun);
1507 srbcmd->flags = cpu_to_le32(flag);
Jens Axboe242f9dc2008-09-14 05:55:09 -07001508 timeout = cmd->request->timeout/HZ;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001509 if (timeout == 0)
Balsundar Pe2fd90d2019-10-15 11:52:01 +05301510 timeout = (dev->sa_firmware ? AAC_SA_TIMEOUT : AAC_ARC_TIMEOUT);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001511 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
1512 srbcmd->retry_limit = 0; /* Obsolete parameter */
1513 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1514 return srbcmd;
1515}
1516
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08001517static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
1518 struct scsi_cmnd *cmd)
1519{
1520 struct aac_hba_cmd_req *hbacmd;
1521 struct aac_dev *dev;
1522 int bus, target;
1523 u64 address;
1524
1525 dev = (struct aac_dev *)cmd->device->host->hostdata;
1526
1527 hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
1528 memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
1529 /* iu_type is a parameter of aac_hba_send */
1530 switch (cmd->sc_data_direction) {
1531 case DMA_TO_DEVICE:
1532 hbacmd->byte1 = 2;
1533 break;
1534 case DMA_FROM_DEVICE:
1535 case DMA_BIDIRECTIONAL:
1536 hbacmd->byte1 = 1;
1537 break;
1538 case DMA_NONE:
1539 default:
1540 break;
1541 }
1542 hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
1543
1544 bus = aac_logical_to_phys(scmd_channel(cmd));
1545 target = scmd_id(cmd);
1546 hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
1547
1548 /* we fill in reply_qid later in aac_src_deliver_message */
1549 /* we fill in iu_type, request_id later in aac_hba_send */
1550 /* we fill in emb_data_desc_count later in aac_build_sghba */
1551
1552 memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
1553 hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
1554
1555 address = (u64)fib->hw_error_pa;
1556 hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
1557 hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
1558 hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
1559
1560 return hbacmd;
1561}
1562
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001563static void aac_srb_callback(void *context, struct fib * fibptr);
1564
1565static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1566{
1567 u16 fibsize;
1568 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301569 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001570
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301571 ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1572 if (ret < 0)
1573 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001574 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001575
1576 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1577 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1578 /*
1579 * Build Scatter/Gather list
1580 */
1581 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1582 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1583 sizeof (struct sgentry64));
1584 BUG_ON (fibsize > (fib->dev->max_fib_size -
1585 sizeof(struct aac_fibhdr)));
1586
1587 /*
1588 * Now send the Fib to the adapter
1589 */
1590 return aac_fib_send(ScsiPortCommand64, fib,
1591 fibsize, FsaNormal, 0, 1,
1592 (fib_callback) aac_srb_callback,
1593 (void *) cmd);
1594}
1595
1596static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1597{
1598 u16 fibsize;
1599 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301600 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001601
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301602 ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1603 if (ret < 0)
1604 return ret;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09001605 srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001606
1607 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1608 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1609 /*
1610 * Build Scatter/Gather list
1611 */
1612 fibsize = sizeof (struct aac_srb) +
1613 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1614 sizeof (struct sgentry));
1615 BUG_ON (fibsize > (fib->dev->max_fib_size -
1616 sizeof(struct aac_fibhdr)));
1617
1618 /*
1619 * Now send the Fib to the adapter
1620 */
1621 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1622 (fib_callback) aac_srb_callback, (void *) cmd);
1623}
1624
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001625static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1626{
Leubner, Achimd8e965072009-04-01 07:16:08 -07001627 if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1628 (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001629 return FAILED;
1630 return aac_scsi_32(fib, cmd);
1631}
1632
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08001633static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
1634{
1635 struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
1636 struct aac_dev *dev;
1637 long ret;
1638
1639 dev = (struct aac_dev *)cmd->device->host->hostdata;
1640
1641 ret = aac_build_sghba(cmd, hbacmd,
1642 dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
1643 if (ret < 0)
1644 return ret;
1645
1646 /*
1647 * Now send the HBA command to the adapter
1648 */
1649 fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
1650 sizeof(struct aac_hba_sgl);
1651
1652 return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
1653 (fib_callback) aac_hba_callback,
1654 (void *) cmd);
1655}
1656
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001657static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
1658 struct aac_srb_unit *srbu, void *xfer_buf, int xfer_len)
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001659{
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001660 struct fib *fibptr;
1661 dma_addr_t addr;
1662 int rcode;
1663 int fibsize;
1664 struct aac_srb *srb;
1665 struct aac_srb_reply *srb_reply;
1666 struct sgmap64 *sg64;
1667 u32 vbus;
1668 u32 vid;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001669
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001670 if (!dev->sa_firmware)
1671 return 0;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08001672
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001673 /* allocate FIB */
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001674 fibptr = aac_fib_alloc(dev);
1675 if (!fibptr)
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001676 return -ENOMEM;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001677
1678 aac_fib_init(fibptr);
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001679 fibptr->hw_fib_va->header.XferState &=
1680 ~cpu_to_le32(FastResponseCapable);
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001681
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001682 fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
1683 sizeof(struct sgentry64);
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001684
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001685 /* allocate DMA buffer for response */
1686 addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
1687 DMA_BIDIRECTIONAL);
1688 if (dma_mapping_error(&dev->pdev->dev, addr)) {
1689 rcode = -ENOMEM;
1690 goto fib_error;
1691 }
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001692
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001693 srb = fib_data(fibptr);
1694 memcpy(srb, &srbu->srb, sizeof(struct aac_srb));
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001695
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001696 vbus = (u32)le16_to_cpu(
1697 dev->supplement_adapter_info.virt_device_bus);
1698 vid = (u32)le16_to_cpu(
1699 dev->supplement_adapter_info.virt_device_target);
1700
1701 /* set the common request fields */
1702 srb->channel = cpu_to_le32(vbus);
1703 srb->id = cpu_to_le32(vid);
1704 srb->lun = 0;
1705 srb->function = cpu_to_le32(SRBF_ExecuteScsi);
1706 srb->timeout = 0;
1707 srb->retry_limit = 0;
1708 srb->cdb_size = cpu_to_le32(16);
1709 srb->count = cpu_to_le32(xfer_len);
1710
1711 sg64 = (struct sgmap64 *)&srb->sg;
1712 sg64->count = cpu_to_le32(1);
1713 sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
1714 sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
1715 sg64->sg[0].count = cpu_to_le32(xfer_len);
1716
1717 /*
1718 * Copy the updated data for other dumping or other usage if needed
1719 */
1720 memcpy(&srbu->srb, srb, sizeof(struct aac_srb));
1721
1722 /* issue request to the controller */
1723 rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize, FsaNormal,
1724 1, 1, NULL, NULL);
1725
1726 if (rcode == -ERESTARTSYS)
1727 rcode = -ERESTART;
1728
1729 if (unlikely(rcode < 0))
1730 goto bmic_error;
1731
1732 srb_reply = (struct aac_srb_reply *)fib_data(fibptr);
1733 memcpy(&srbu->srb_reply, srb_reply, sizeof(struct aac_srb_reply));
1734
1735bmic_error:
1736 dma_unmap_single(&dev->pdev->dev, addr, xfer_len, DMA_BIDIRECTIONAL);
1737fib_error:
1738 aac_fib_complete(fibptr);
1739 aac_fib_free(fibptr);
1740 return rcode;
1741}
1742
Raghava Aditya Renukunta0bcb45f2017-12-26 20:34:38 -08001743static void aac_set_safw_target_qd(struct aac_dev *dev, int bus, int target)
1744{
1745
1746 struct aac_ciss_identify_pd *identify_resp;
1747
1748 if (dev->hba_map[bus][target].devtype != AAC_DEVTYPE_NATIVE_RAW)
1749 return;
1750
1751 identify_resp = dev->hba_map[bus][target].safw_identify_resp;
1752 if (identify_resp == NULL) {
1753 dev->hba_map[bus][target].qd_limit = 32;
1754 return;
1755 }
1756
1757 if (identify_resp->current_queue_depth_limit <= 0 ||
1758 identify_resp->current_queue_depth_limit > 255)
1759 dev->hba_map[bus][target].qd_limit = 32;
1760 else
1761 dev->hba_map[bus][target].qd_limit =
1762 identify_resp->current_queue_depth_limit;
1763}
1764
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001765static int aac_issue_safw_bmic_identify(struct aac_dev *dev,
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001766 struct aac_ciss_identify_pd **identify_resp, u32 bus, u32 target)
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001767{
1768 int rcode = -ENOMEM;
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001769 int datasize;
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001770 struct aac_srb_unit srbu;
1771 struct aac_srb *srbcmd;
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001772 struct aac_ciss_identify_pd *identify_reply;
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001773
1774 datasize = sizeof(struct aac_ciss_identify_pd);
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001775 identify_reply = kmalloc(datasize, GFP_KERNEL);
1776 if (!identify_reply)
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001777 goto out;
1778
1779 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1780
1781 srbcmd = &srbu.srb;
1782 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1783 srbcmd->cdb[0] = 0x26;
1784 srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
1785 srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
1786
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001787 rcode = aac_send_safw_bmic_cmd(dev, &srbu, identify_reply, datasize);
Raghava Aditya Renukunta8fb39182017-12-26 20:34:30 -08001788 if (unlikely(rcode < 0))
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001789 goto mem_free_all;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001790
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001791 *identify_resp = identify_reply;
1792
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001793out:
1794 return rcode;
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001795mem_free_all:
1796 kfree(identify_reply);
1797 goto out;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001798}
1799
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001800static inline void aac_free_safw_ciss_luns(struct aac_dev *dev)
1801{
1802 kfree(dev->safw_phys_luns);
1803 dev->safw_phys_luns = NULL;
1804}
1805
1806/**
Lee Jonesa80218c2021-03-03 14:46:08 +00001807 * aac_get_safw_ciss_luns() - Process topology change
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001808 * @dev: aac_dev structure
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001809 *
1810 * Execute a CISS REPORT PHYS LUNS and process the results into
1811 * the current hba_map.
1812 */
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08001813static int aac_get_safw_ciss_luns(struct aac_dev *dev)
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001814{
1815 int rcode = -ENOMEM;
1816 int datasize;
1817 struct aac_srb *srbcmd;
1818 struct aac_srb_unit srbu;
1819 struct aac_ciss_phys_luns_resp *phys_luns;
1820
1821 datasize = sizeof(struct aac_ciss_phys_luns_resp) +
1822 (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
1823 phys_luns = kmalloc(datasize, GFP_KERNEL);
1824 if (phys_luns == NULL)
1825 goto out;
1826
1827 memset(&srbu, 0, sizeof(struct aac_srb_unit));
1828
1829 srbcmd = &srbu.srb;
1830 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1831 srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
1832 srbcmd->cdb[1] = 2; /* extended reporting */
1833 srbcmd->cdb[8] = (u8)(datasize >> 8);
1834 srbcmd->cdb[9] = (u8)(datasize);
1835
1836 rcode = aac_send_safw_bmic_cmd(dev, &srbu, phys_luns, datasize);
1837 if (unlikely(rcode < 0))
1838 goto mem_free_all;
1839
1840 if (phys_luns->resp_flag != 2) {
1841 rcode = -ENOMSG;
1842 goto mem_free_all;
1843 }
1844
1845 dev->safw_phys_luns = phys_luns;
1846
1847out:
1848 return rcode;
1849mem_free_all:
1850 kfree(phys_luns);
1851 goto out;
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001852}
Raghava Aditya Renukuntaa25b6ca2017-12-26 20:34:35 -08001853
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001854static inline u32 aac_get_safw_phys_lun_count(struct aac_dev *dev)
1855{
Raghava Aditya Renukuntabbd16d92018-01-10 13:13:09 -08001856 return get_unaligned_be32(&dev->safw_phys_luns->list_length[0])/24;
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001857}
1858
1859static inline u32 aac_get_safw_phys_bus(struct aac_dev *dev, int lun)
1860{
1861 return dev->safw_phys_luns->lun[lun].level2[1] & 0x3f;
1862}
1863
1864static inline u32 aac_get_safw_phys_target(struct aac_dev *dev, int lun)
1865{
1866 return dev->safw_phys_luns->lun[lun].level2[0];
1867}
1868
1869static inline u32 aac_get_safw_phys_expose_flag(struct aac_dev *dev, int lun)
1870{
1871 return dev->safw_phys_luns->lun[lun].bus >> 6;
1872}
1873
1874static inline u32 aac_get_safw_phys_attribs(struct aac_dev *dev, int lun)
1875{
1876 return dev->safw_phys_luns->lun[lun].node_ident[9];
1877}
1878
1879static inline u32 aac_get_safw_phys_nexus(struct aac_dev *dev, int lun)
1880{
1881 return *((u32 *)&dev->safw_phys_luns->lun[lun].node_ident[12]);
1882}
1883
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001884static inline void aac_free_safw_identify_resp(struct aac_dev *dev,
1885 int bus, int target)
1886{
1887 kfree(dev->hba_map[bus][target].safw_identify_resp);
1888 dev->hba_map[bus][target].safw_identify_resp = NULL;
1889}
1890
1891static inline void aac_free_safw_all_identify_resp(struct aac_dev *dev,
1892 int lun_count)
1893{
1894 int luns;
1895 int i;
1896 u32 bus;
1897 u32 target;
1898
1899 luns = aac_get_safw_phys_lun_count(dev);
1900
1901 if (luns < lun_count)
1902 lun_count = luns;
1903 else if (lun_count < 0)
1904 lun_count = luns;
1905
1906 for (i = 0; i < lun_count; i++) {
1907 bus = aac_get_safw_phys_bus(dev, i);
1908 target = aac_get_safw_phys_target(dev, i);
1909
1910 aac_free_safw_identify_resp(dev, bus, target);
1911 }
1912}
1913
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08001914static int aac_get_safw_attr_all_targets(struct aac_dev *dev)
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001915{
1916 int i;
1917 int rcode = 0;
1918 u32 lun_count;
1919 u32 bus;
1920 u32 target;
1921 struct aac_ciss_identify_pd *identify_resp = NULL;
1922
1923 lun_count = aac_get_safw_phys_lun_count(dev);
1924
1925 for (i = 0; i < lun_count; ++i) {
1926
1927 bus = aac_get_safw_phys_bus(dev, i);
1928 target = aac_get_safw_phys_target(dev, i);
1929
1930 rcode = aac_issue_safw_bmic_identify(dev,
1931 &identify_resp, bus, target);
1932
Raghava Aditya Renukunta0bcb45f2017-12-26 20:34:38 -08001933 if (unlikely(rcode < 0))
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001934 goto free_identify_resp;
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001935
1936 dev->hba_map[bus][target].safw_identify_resp = identify_resp;
1937 }
1938
1939out:
1940 return rcode;
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08001941free_identify_resp:
1942 aac_free_safw_all_identify_resp(dev, i);
1943 goto out;
1944}
1945
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001946/**
Raghava Aditya Renukuntab5a475e2017-12-26 20:34:32 -08001947 * aac_set_safw_attr_all_targets- update current hba map with data from FW
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001948 * @dev: aac_dev structure
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001949 *
1950 * Update our hba map with the information gathered from the FW
1951 */
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08001952static void aac_set_safw_attr_all_targets(struct aac_dev *dev)
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001953{
1954 /* ok and extended reporting */
1955 u32 lun_count, nexus;
1956 u32 i, bus, target;
1957 u8 expose_flag, attribs;
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08001958
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001959 lun_count = aac_get_safw_phys_lun_count(dev);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001960
Raghava Aditya Renukuntaf2d2cab2017-12-26 20:34:40 -08001961 dev->scan_counter++;
1962
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001963 for (i = 0; i < lun_count; ++i) {
1964
Raghava Aditya Renukunta4b000222017-12-26 20:34:36 -08001965 bus = aac_get_safw_phys_bus(dev, i);
1966 target = aac_get_safw_phys_target(dev, i);
1967 expose_flag = aac_get_safw_phys_expose_flag(dev, i);
1968 attribs = aac_get_safw_phys_attribs(dev, i);
1969 nexus = aac_get_safw_phys_nexus(dev, i);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001970
1971 if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
1972 continue;
1973
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001974 if (expose_flag != 0) {
Raghava Aditya Renukunta59b433c2018-06-22 06:55:47 -07001975 dev->hba_map[bus][target].devtype =
1976 AAC_DEVTYPE_RAID_MEMBER;
1977 continue;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001978 }
1979
1980 if (nexus != 0 && (attribs & 8)) {
Raghava Aditya Renukunta59b433c2018-06-22 06:55:47 -07001981 dev->hba_map[bus][target].devtype =
1982 AAC_DEVTYPE_NATIVE_RAW;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001983 dev->hba_map[bus][target].rmw_nexus =
1984 nexus;
1985 } else
Raghava Aditya Renukunta59b433c2018-06-22 06:55:47 -07001986 dev->hba_map[bus][target].devtype =
1987 AAC_DEVTYPE_ARC_RAW;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001988
Raghava Aditya Renukuntaf2d2cab2017-12-26 20:34:40 -08001989 dev->hba_map[bus][target].scan_counter = dev->scan_counter;
1990
Raghava Aditya Renukunta0bcb45f2017-12-26 20:34:38 -08001991 aac_set_safw_target_qd(dev, bus, target);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001992 }
1993}
1994
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08001995static int aac_setup_safw_targets(struct aac_dev *dev)
Raghava Aditya Renukuntafc0fdd92017-12-26 20:34:33 -08001996{
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08001997 int rcode = 0;
1998
Raghava Aditya Renukunta1d1fec52017-12-26 20:34:39 -08001999 rcode = aac_get_containers(dev);
2000 if (unlikely(rcode < 0))
2001 goto out;
2002
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002003 rcode = aac_get_safw_ciss_luns(dev);
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08002004 if (unlikely(rcode < 0))
2005 goto out;
2006
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002007 rcode = aac_get_safw_attr_all_targets(dev);
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08002008 if (unlikely(rcode < 0))
2009 goto free_ciss_luns;
2010
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002011 aac_set_safw_attr_all_targets(dev);
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08002012
Raghava Aditya Renukuntae2ee8c92017-12-26 20:34:37 -08002013 aac_free_safw_all_identify_resp(dev, -1);
2014free_ciss_luns:
Raghava Aditya Renukunta3edfb8b2017-12-26 20:34:34 -08002015 aac_free_safw_ciss_luns(dev);
2016out:
2017 return rcode;
Raghava Aditya Renukuntafc0fdd92017-12-26 20:34:33 -08002018}
2019
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002020int aac_setup_safw_adapter(struct aac_dev *dev)
Raghava Aditya Renukuntafc0fdd92017-12-26 20:34:33 -08002021{
Raghava Aditya Renukunta75be67c2017-12-26 20:34:49 -08002022 return aac_setup_safw_targets(dev);
Raghava Aditya Renukuntafc0fdd92017-12-26 20:34:33 -08002023}
2024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025int aac_get_adapter_info(struct aac_dev* dev)
2026{
2027 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 int rcode;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002029 u32 tmp, bus, target;
Mark Haverkamp84971732005-06-20 11:55:24 -07002030 struct aac_adapter_info *info;
2031 struct aac_bus_info *command;
2032 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002033
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002034 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 return -ENOMEM;
2036
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002037 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002038 info = (struct aac_adapter_info *) fib_data(fibptr);
2039 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002041 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002042 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002043 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002044 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07002045 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002046 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002047 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002049 if (rcode < 0) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302050 /* FIB should be freed only after
2051 * getting the response from the F/W */
2052 if (rcode != -ERESTARTSYS) {
2053 aac_fib_complete(fibptr);
2054 aac_fib_free(fibptr);
2055 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002056 return rcode;
2057 }
2058 memcpy(&dev->adapter_info, info, sizeof(*info));
2059
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002060 dev->supplement_adapter_info.virt_device_bus = 0xffff;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002061 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002062 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002063
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002064 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002065
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002066 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002067
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002068 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002069
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002070 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002071 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002072 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002073 FsaNormal,
2074 1, 1,
2075 NULL,
2076 NULL);
2077
2078 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08002079 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302080 if (rcode == -ERESTARTSYS) {
2081 fibptr = aac_fib_alloc(dev);
2082 if (!fibptr)
2083 return -ENOMEM;
2084 }
2085
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002086 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002088 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
2089 for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08002090 for (target = 0; target < AAC_MAX_TARGETS; target++) {
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002091 dev->hba_map[bus][target].devtype = 0;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08002092 dev->hba_map[bus][target].qd_limit = 0;
2093 }
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08002094 }
Mark Haverkamp84971732005-06-20 11:55:24 -07002095
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002096 /*
2097 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07002098 */
2099
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002100 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07002101
2102 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
2103
2104 memset(bus_info, 0, sizeof(*bus_info));
2105
2106 command = (struct aac_bus_info *)bus_info;
2107
2108 command->Command = cpu_to_le32(VM_Ioctl);
2109 command->ObjType = cpu_to_le32(FT_DRIVE);
2110 command->MethodId = cpu_to_le32(1);
2111 command->CtlCmd = cpu_to_le32(GetBusInfo);
2112
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002113 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07002114 fibptr,
2115 sizeof (*bus_info),
2116 FsaNormal,
2117 1, 1,
2118 NULL, NULL);
2119
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08002120 /* reasoned default */
2121 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07002122 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
2123 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
2124 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
2125 }
2126
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002127 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04002128 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002129 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
2130 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002131 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 dev->id,
2133 tmp>>24,
2134 (tmp>>16)&0xff,
2135 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002136 le32_to_cpu(dev->adapter_info.kernelbuild),
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002137 (int)sizeof(dev->supplement_adapter_info.build_date),
2138 dev->supplement_adapter_info.build_date);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002139 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
2140 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 dev->name, dev->id,
2142 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2143 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002144 tmp = le32_to_cpu(dev->adapter_info.biosrev);
2145 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 dev->name, dev->id,
2147 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
2148 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04002149 buffer[0] = '\0';
Tony Jonesee959b02008-02-22 00:13:36 +01002150 if (aac_get_serial_number(
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04002151 shost_to_class(dev->scsi_host_ptr), buffer))
2152 printk(KERN_INFO "%s%d: serial %s",
2153 dev->name, dev->id, buffer);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002154 if (dev->supplement_adapter_info.vpd_info.tsid[0]) {
Salyzyn, Marka45c8632007-03-28 13:44:54 -04002155 printk(KERN_INFO "%s%d: TSID %.*s\n",
2156 dev->name, dev->id,
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002157 (int)sizeof(dev->supplement_adapter_info
2158 .vpd_info.tsid),
2159 dev->supplement_adapter_info.vpd_info.tsid);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04002160 }
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002161 if (!aac_check_reset || ((aac_check_reset == 1) &&
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002162 (dev->supplement_adapter_info.supported_options2 &
Salyzyn, Marka3940da2008-01-08 12:48:25 -08002163 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002164 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
2165 dev->name, dev->id);
2166 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002169 dev->cache_protected = 0;
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002170 dev->jbod = ((dev->supplement_adapter_info.feature_bits &
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08002171 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 dev->nondasd_support = 0;
2173 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002174 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
2177 /*
2178 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2179 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2180 * force nondasd support on. If we decide to allow the non-dasd flag
2181 * additional changes changes will have to be made to support
2182 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2183 * changed to support the new dev->raid_scsi_mode flag instead of
2184 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2185 * function aac_detect will have to be modified where it sets up the
2186 * max number of channels based on the aac->nondasd_support flag only.
2187 */
2188 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
2189 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
2190 dev->nondasd_support = 1;
2191 dev->raid_scsi_mode = 1;
2192 }
2193 if (dev->raid_scsi_mode != 0)
2194 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
2195 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002196
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002197 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002199 if (dev->nondasd_support && !dev->in_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Yang Hongyange9304382009-04-13 14:40:14 -07002202 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
Leubner, Achimd8e965072009-04-01 07:16:08 -07002203 dev->needs_dac = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 dev->dac_support = 0;
Leubner, Achimd8e965072009-04-01 07:16:08 -07002205 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
2206 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002207 if (!dev->in_reset)
2208 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
2209 dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 dev->dac_support = 1;
2211 }
2212
2213 if(dacmode != -1) {
2214 dev->dac_support = (dacmode!=0);
2215 }
Leubner, Achimd8e965072009-04-01 07:16:08 -07002216
2217 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2218 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
2219 & AAC_QUIRK_SCSI_32)) {
2220 dev->nondasd_support = 0;
2221 dev->jbod = 0;
2222 expose_physicals = 0;
2223 }
2224
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07002225 if (dev->dac_support) {
Suraj Upadhyaye555cd52020-07-29 23:36:27 +05302226 if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(64))) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002227 if (!dev->in_reset)
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07002228 dev_info(&dev->pdev->dev, "64 Bit DAC enabled\n");
Suraj Upadhyaye555cd52020-07-29 23:36:27 +05302229 } else if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(32))) {
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07002230 dev_info(&dev->pdev->dev, "DMA mask set failed, 64 Bit DAC disabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 dev->dac_support = 0;
2232 } else {
Raghava Aditya Renukunta8105d392017-05-10 09:39:36 -07002233 dev_info(&dev->pdev->dev, "No suitable DMA available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 rcode = -ENOMEM;
2235 }
2236 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002237 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002238 * Deal with configuring for the individualized limits of each packet
2239 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002240 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002241 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08002242 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
2243 ? aac_scsi_32_64
2244 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002245 : aac_scsi_32;
2246 if (dev->raw_io_interface) {
2247 dev->a_ops.adapter_bounds = (dev->raw_io_64)
2248 ? aac_bounds_64
2249 : aac_bounds_32;
2250 dev->a_ops.adapter_read = aac_read_raw_io;
2251 dev->a_ops.adapter_write = aac_write_raw_io;
2252 } else {
2253 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002254 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002255 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07002256 sizeof(struct aac_write) + sizeof(struct sgentry)) /
2257 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002258 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002259 dev->a_ops.adapter_read = aac_read_block64;
2260 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002261 /*
2262 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002263 */
2264 dev->scsi_host_ptr->sg_tablesize =
2265 (dev->max_fib_size -
2266 sizeof(struct aac_fibhdr) -
2267 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07002268 sizeof(struct sgentry64)) /
2269 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002270 } else {
2271 dev->a_ops.adapter_read = aac_read_block;
2272 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002273 }
2274 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07002275 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002276 /*
2277 * Worst case size that could cause sg overflow when
2278 * we break up SG elements that are larger than 64KB.
2279 * Would be nice if we could tell the SCSI layer what
2280 * the maximum SG element size can be. Worst case is
2281 * (sg_tablesize-1) 4KB elements with one 64KB
2282 * element.
2283 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2284 */
2285 dev->scsi_host_ptr->max_sectors =
2286 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
2287 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002288 }
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002289 if (!dev->sync_mode && dev->sa_firmware &&
2290 dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
2291 dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
2292 HBA_MAX_SG_SEPARATE;
2293
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302294 /* FIB should be freed only after getting the response from the F/W */
2295 if (rcode != -ERESTARTSYS) {
2296 aac_fib_complete(fibptr);
2297 aac_fib_free(fibptr);
2298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
2300 return rcode;
2301}
2302
2303
Mark Haverkampe53cb352005-08-03 15:39:09 -07002304static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305{
2306 struct aac_dev *dev;
2307 struct aac_read_reply *readreply;
2308 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 u32 cid;
2310
2311 scsicmd = (struct scsi_cmnd *) context;
2312
Mark Haverkamp03d44332007-03-15 10:27:45 -07002313 if (!aac_valid_context(scsicmd, fibptr))
2314 return;
2315
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002316 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002317 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002319 if (nblank(dprintk(x))) {
2320 u64 lba;
2321 switch (scsicmd->cmnd[0]) {
2322 case WRITE_6:
2323 case READ_6:
2324 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2325 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2326 break;
2327 case WRITE_16:
2328 case READ_16:
2329 lba = ((u64)scsicmd->cmnd[2] << 56) |
2330 ((u64)scsicmd->cmnd[3] << 48) |
2331 ((u64)scsicmd->cmnd[4] << 40) |
2332 ((u64)scsicmd->cmnd[5] << 32) |
2333 ((u64)scsicmd->cmnd[6] << 24) |
2334 (scsicmd->cmnd[7] << 16) |
2335 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2336 break;
2337 case WRITE_12:
2338 case READ_12:
2339 lba = ((u64)scsicmd->cmnd[2] << 24) |
2340 (scsicmd->cmnd[3] << 16) |
2341 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2342 break;
2343 default:
2344 lba = ((u64)scsicmd->cmnd[2] << 24) |
2345 (scsicmd->cmnd[3] << 16) |
2346 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2347 break;
2348 }
2349 printk(KERN_DEBUG
2350 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2351 smp_processor_id(), (unsigned long long)lba, jiffies);
2352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002354 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002355
2356 scsi_dma_unmap(scsicmd);
2357
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 readreply = (struct aac_read_reply *)fib_data(fibptr);
Mark Salyzyn655d7222008-04-30 16:03:42 -04002359 switch (le32_to_cpu(readreply->status)) {
2360 case ST_OK:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002361 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002362 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
2363 break;
2364 case ST_NOT_READY:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002365 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002366 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
2367 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
2368 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2369 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2370 SCSI_SENSE_BUFFERSIZE));
2371 break;
Raghava Aditya Renukuntaf956a662017-02-02 15:53:23 -08002372 case ST_MEDERR:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002373 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Raghava Aditya Renukuntaf956a662017-02-02 15:53:23 -08002374 set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
2375 SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
2376 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2377 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2378 SCSI_SENSE_BUFFERSIZE));
2379 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002380 default:
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002381#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07002382 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002383 le32_to_cpu(readreply->status));
2384#endif
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002385 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002386 set_sense(&dev->fsa_dev[cid].sense_data,
2387 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2388 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002390 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2391 SCSI_SENSE_BUFFERSIZE));
Mark Salyzyn655d7222008-04-30 16:03:42 -04002392 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002394 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002396 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397}
2398
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002399static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002401 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 u32 count;
2403 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 struct aac_dev *dev;
2405 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002406 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
2408 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2409 /*
2410 * Get block address and transfer length
2411 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002412 switch (scsicmd->cmnd[0]) {
2413 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002414 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002416 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002417 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 count = scsicmd->cmnd[4];
2419
2420 if (count == 0)
2421 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002422 break;
2423 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002424 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002425
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002426 lba = ((u64)scsicmd->cmnd[2] << 56) |
2427 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002428 ((u64)scsicmd->cmnd[4] << 40) |
2429 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002430 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002431 (scsicmd->cmnd[7] << 16) |
2432 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002433 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002434 (scsicmd->cmnd[11] << 16) |
2435 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2436 break;
2437 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002438 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002439
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002440 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002441 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002442 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2443 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002444 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002445 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002446 break;
2447 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002448 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002450 lba = ((u64)scsicmd->cmnd[2] << 24) |
2451 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002452 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002454 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002456
2457 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2458 cid = scmd_id(scsicmd);
2459 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002460 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002461 set_sense(&dev->fsa_dev[cid].sense_data,
Balsundar Pc86fbe42019-10-15 11:51:58 +05302462 ILLEGAL_REQUEST, SENCODE_LBA_OUT_OF_RANGE,
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002463 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2464 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2465 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2466 SCSI_SENSE_BUFFERSIZE));
2467 scsicmd->scsi_done(scsicmd);
Balsundar Pc86fbe42019-10-15 11:51:58 +05302468 return 0;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002469 }
2470
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002471 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002472 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002473 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002474 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 /*
2476 * Alocate and initialize a Fib
2477 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002478 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Brian King1ae948f2017-08-29 10:00:29 -05002479 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002480 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481
2482 /*
2483 * Check that the command queued to the controller
2484 */
Brian King1ae948f2017-08-29 10:00:29 -05002485 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 return 0;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002487
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002488 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 /*
2490 * For some reason, the Fib didn't queue, return QUEUE_FULL
2491 */
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002492 scsicmd->result = DID_OK << 16 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002493 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002494 aac_fib_complete(cmd_fibcontext);
2495 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 return 0;
2497}
2498
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002499static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002501 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002503 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 struct aac_dev *dev;
2506 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002507 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
2509 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2510 /*
2511 * Get block address and transfer length
2512 */
2513 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
2514 {
2515 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2516 count = scsicmd->cmnd[4];
2517 if (count == 0)
2518 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002519 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002520 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002521 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002522
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002523 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002524 ((u64)scsicmd->cmnd[3] << 48) |
2525 ((u64)scsicmd->cmnd[4] << 40) |
2526 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002527 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002528 (scsicmd->cmnd[7] << 16) |
2529 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2530 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2531 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002532 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002533 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002534 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002535
2536 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2537 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2538 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2539 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002540 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002542 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002543 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002545 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002547
2548 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2549 cid = scmd_id(scsicmd);
2550 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002551 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002552 set_sense(&dev->fsa_dev[cid].sense_data,
Balsundar Pc86fbe42019-10-15 11:51:58 +05302553 ILLEGAL_REQUEST, SENCODE_LBA_OUT_OF_RANGE,
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002554 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2555 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2556 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2557 SCSI_SENSE_BUFFERSIZE));
2558 scsicmd->scsi_done(scsicmd);
Balsundar Pc86fbe42019-10-15 11:51:58 +05302559 return 0;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002560 }
2561
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002562 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002564 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002565 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 /*
2567 * Allocate and initialize a Fib then setup a BlockWrite command
2568 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002569 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Brian King1ae948f2017-08-29 10:00:29 -05002570 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002571 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572
2573 /*
2574 * Check that the command queued to the controller
2575 */
Brian King1ae948f2017-08-29 10:00:29 -05002576 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002579 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 /*
2581 * For some reason, the Fib didn't queue, return QUEUE_FULL
2582 */
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002583 scsicmd->result = DID_OK << 16 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002584 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002586 aac_fib_complete(cmd_fibcontext);
2587 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 return 0;
2589}
2590
2591static void synchronize_callback(void *context, struct fib *fibptr)
2592{
2593 struct aac_synchronize_reply *synchronizereply;
Hannes Reinecke2c644b12020-02-28 08:53:09 +01002594 struct scsi_cmnd *cmd = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Mark Haverkamp03d44332007-03-15 10:27:45 -07002596 if (!aac_valid_context(cmd, fibptr))
2597 return;
2598
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002599 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 smp_processor_id(), jiffies));
2601 BUG_ON(fibptr == NULL);
2602
2603
2604 synchronizereply = fib_data(fibptr);
2605 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002606 cmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 else {
2608 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002609 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002610 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002611 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 "synchronize_callback: synchronize failed, status = %d\n",
2613 le32_to_cpu(synchronizereply->status));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002614 cmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002615 set_sense(&dev->fsa_dev[cid].sense_data,
2616 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2617 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002619 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2620 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 }
2622
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002623 aac_fib_complete(fibptr);
2624 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002625 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626}
2627
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002628static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629{
2630 int status;
2631 struct fib *cmd_fibcontext;
2632 struct aac_synchronize *synchronizecmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 struct scsi_device *sdev = scsicmd->device;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002634 struct aac_dev *aac;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
Salyzyn, Markf8583172007-10-30 15:50:49 -04002636 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002637 if (aac->in_reset)
2638 return SCSI_MLQUEUE_HOST_BUSY;
2639
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002641 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 */
Hannes Reinecke2c644b12020-02-28 08:53:09 +01002643 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002645 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
2647 synchronizecmd = fib_data(cmd_fibcontext);
2648 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2649 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002650 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002651 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
Brian King1ae948f2017-08-29 10:00:29 -05002653 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
2655 /*
2656 * Now send the Fib to the adapter
2657 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002658 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 cmd_fibcontext,
2660 sizeof(struct aac_synchronize),
2661 FsaNormal,
2662 0, 1,
2663 (fib_callback)synchronize_callback,
2664 (void *)scsicmd);
2665
2666 /*
2667 * Check that the command queued to the controller
2668 */
Brian King1ae948f2017-08-29 10:00:29 -05002669 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 return 0;
2671
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002672 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002673 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2674 aac_fib_complete(cmd_fibcontext);
2675 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 return SCSI_MLQUEUE_HOST_BUSY;
2677}
2678
Mark Salyzyn655d7222008-04-30 16:03:42 -04002679static void aac_start_stop_callback(void *context, struct fib *fibptr)
2680{
2681 struct scsi_cmnd *scsicmd = context;
2682
2683 if (!aac_valid_context(scsicmd, fibptr))
2684 return;
2685
2686 BUG_ON(fibptr == NULL);
2687
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002688 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002689
2690 aac_fib_complete(fibptr);
2691 aac_fib_free(fibptr);
2692 scsicmd->scsi_done(scsicmd);
2693}
2694
2695static int aac_start_stop(struct scsi_cmnd *scsicmd)
2696{
2697 int status;
2698 struct fib *cmd_fibcontext;
2699 struct aac_power_management *pmcmd;
2700 struct scsi_device *sdev = scsicmd->device;
2701 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2702
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002703 if (!(aac->supplement_adapter_info.supported_options2 &
Mark Salyzyn655d7222008-04-30 16:03:42 -04002704 AAC_OPTION_POWER_MANAGEMENT)) {
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002705 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002706 scsicmd->scsi_done(scsicmd);
2707 return 0;
2708 }
2709
2710 if (aac->in_reset)
2711 return SCSI_MLQUEUE_HOST_BUSY;
2712
2713 /*
2714 * Allocate and initialize a Fib
2715 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002716 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
Mark Salyzyn655d7222008-04-30 16:03:42 -04002717
2718 aac_fib_init(cmd_fibcontext);
2719
2720 pmcmd = fib_data(cmd_fibcontext);
2721 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2722 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2723 /* Eject bit ignored, not relevant */
2724 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2725 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2726 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2727 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2728 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
Brian King1ae948f2017-08-29 10:00:29 -05002729 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002730
2731 /*
2732 * Now send the Fib to the adapter
2733 */
2734 status = aac_fib_send(ContainerCommand,
2735 cmd_fibcontext,
2736 sizeof(struct aac_power_management),
2737 FsaNormal,
2738 0, 1,
2739 (fib_callback)aac_start_stop_callback,
2740 (void *)scsicmd);
2741
2742 /*
2743 * Check that the command queued to the controller
2744 */
Brian King1ae948f2017-08-29 10:00:29 -05002745 if (status == -EINPROGRESS)
Mark Salyzyn655d7222008-04-30 16:03:42 -04002746 return 0;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002747
2748 aac_fib_complete(cmd_fibcontext);
2749 aac_fib_free(cmd_fibcontext);
2750 return SCSI_MLQUEUE_HOST_BUSY;
2751}
2752
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753/**
2754 * aac_scsi_cmd() - Process SCSI command
2755 * @scsicmd: SCSI command block
2756 *
2757 * Emulate a SCSI command and queue the required request for the
2758 * aacraid firmware.
2759 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002760
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2762{
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002763 u32 cid, bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 struct Scsi_Host *host = scsicmd->device->host;
2765 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2766 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002767
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002768 if (fsa_dev_ptr == NULL)
2769 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 /*
2771 * If the bus, id or lun is out of range, return fail
2772 * Test does not apply to ID 16, the pseudo id for the controller
2773 * itself.
2774 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002775 cid = scmd_id(scsicmd);
2776 if (cid != host->this_id) {
2777 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2778 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08002779 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002781 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
2784 /*
2785 * If the target container doesn't exist, it may have
2786 * been newly created
2787 */
Mark Salyzyn655d7222008-04-30 16:03:42 -04002788 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2789 (fsa_dev_ptr[cid].sense_data.sense_key ==
2790 NOT_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 switch (scsicmd->cmnd[0]) {
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002792 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002793 if (!(dev->raw_io_interface) ||
2794 !(dev->raw_io_64) ||
2795 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2796 break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002797 fallthrough;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 case INQUIRY:
2799 case READ_CAPACITY:
2800 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002801 if (dev->in_reset)
2802 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07002803 return _aac_probe_container(scsicmd,
2804 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 default:
2806 break;
2807 }
2808 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 } else { /* check for physical non-dasd devices */
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002810 bus = aac_logical_to_phys(scmd_channel(scsicmd));
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002811
2812 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2813 dev->hba_map[bus][cid].devtype
2814 == AAC_DEVTYPE_NATIVE_RAW) {
2815 if (dev->in_reset)
2816 return -1;
2817 return aac_send_hba_fib(scsicmd);
2818 } else if (dev->nondasd_support || expose_physicals ||
2819 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002820 if (dev->in_reset)
2821 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 return aac_send_srb_fib(scsicmd);
2823 } else {
2824 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002825 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 }
2827 }
2828 }
2829 /*
2830 * else Command for the controller itself
2831 */
2832 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002833 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 {
2835 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002836 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002837 set_sense(&dev->fsa_dev[cid].sense_data,
2838 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2839 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002841 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2842 SCSI_SENSE_BUFFERSIZE));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002843 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 }
2845
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 switch (scsicmd->cmnd[0]) {
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002847 case READ_6:
2848 case READ_10:
2849 case READ_12:
2850 case READ_16:
2851 if (dev->in_reset)
2852 return -1;
2853 return aac_read(scsicmd);
2854
2855 case WRITE_6:
2856 case WRITE_10:
2857 case WRITE_12:
2858 case WRITE_16:
2859 if (dev->in_reset)
2860 return -1;
2861 return aac_write(scsicmd);
2862
2863 case SYNCHRONIZE_CACHE:
2864 if (((aac_cache & 6) == 6) && dev->cache_protected) {
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002865 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002866 break;
2867 }
2868 /* Issue FIB to tell Firmware to flush it's cache */
2869 if ((aac_cache & 6) != 2)
2870 return aac_synchronize(scsicmd);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002871 fallthrough;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 case INQUIRY:
2873 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002874 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002876 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002877 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
Leubner, Achimd8e965072009-04-01 07:16:08 -07002879 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002880 char *arr = (char *)&inq_data;
2881
2882 /* EVPD bit set */
2883 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2884 INQD_PDT_PROC : INQD_PDT_DA;
2885 if (scsicmd->cmnd[2] == 0) {
2886 /* supported vital product data pages */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002887 arr[3] = 3;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002888 arr[4] = 0x0;
2889 arr[5] = 0x80;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002890 arr[6] = 0x83;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002891 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002892 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2893 sizeof(inq_data));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002894 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002895 } else if (scsicmd->cmnd[2] == 0x80) {
2896 /* unit serial number page */
2897 arr[3] = setinqserial(dev, &arr[4],
2898 scmd_id(scsicmd));
2899 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002900 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2901 sizeof(inq_data));
Leubner, Achimd8e965072009-04-01 07:16:08 -07002902 if (aac_wwn != 2)
2903 return aac_get_container_serial(
2904 scsicmd);
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002905 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002906 } else if (scsicmd->cmnd[2] == 0x83) {
2907 /* vpd page 0x83 - Device Identification Page */
2908 char *sno = (char *)&inq_data;
2909 sno[3] = setinqserial(dev, &sno[4],
2910 scmd_id(scsicmd));
2911 if (aac_wwn != 2)
2912 return aac_get_container_serial(
2913 scsicmd);
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002914 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002915 } else {
2916 /* vpd page not implemented */
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002917 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002918 set_sense(&dev->fsa_dev[cid].sense_data,
2919 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2920 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002921 memcpy(scsicmd->sense_buffer,
2922 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002923 min_t(size_t,
2924 sizeof(dev->fsa_dev[cid].sense_data),
2925 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002926 }
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002927 break;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002928 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002929 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002930 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 */
2931 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002933 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 /*
2935 * Set the Vendor, Product, and Revision Level
2936 * see: <vendor>.c i.e. aac.c
2937 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002938 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07002939 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002940 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002941 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2942 sizeof(inq_data));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002943 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002944 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002946 if (dev->in_reset)
2947 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07002948 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002949 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002950 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002951 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 }
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002953 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002954 if (!(dev->raw_io_interface) ||
2955 !(dev->raw_io_64) ||
2956 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2957 break;
2958 {
2959 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002960 char cp[13];
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002961 unsigned int alloc_len;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002962
2963 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2964 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002965 cp[0] = (capacity >> 56) & 0xff;
2966 cp[1] = (capacity >> 48) & 0xff;
2967 cp[2] = (capacity >> 40) & 0xff;
2968 cp[3] = (capacity >> 32) & 0xff;
2969 cp[4] = (capacity >> 24) & 0xff;
2970 cp[5] = (capacity >> 16) & 0xff;
2971 cp[6] = (capacity >> 8) & 0xff;
2972 cp[7] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002973 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2974 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2975 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2976 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002977 cp[12] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002978
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002979 alloc_len = ((scsicmd->cmnd[10] << 24)
2980 + (scsicmd->cmnd[11] << 16)
2981 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2982
2983 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002984 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002985 if (alloc_len < scsi_bufflen(scsicmd))
2986 scsi_set_resid(scsicmd,
2987 scsi_bufflen(scsicmd) - alloc_len);
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002988
2989 /* Do not cache partition table for arrays */
2990 scsicmd->device->removable = 1;
2991
Hannes Reineckecdec16c2021-01-13 10:04:40 +01002992 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002993 break;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002994 }
2995
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 case READ_CAPACITY:
2997 {
2998 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002999 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000
3001 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003002 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 capacity = fsa_dev_ptr[cid].size - 1;
3004 else
3005 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07003006
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 cp[0] = (capacity >> 24) & 0xff;
3008 cp[1] = (capacity >> 16) & 0xff;
3009 cp[2] = (capacity >> 8) & 0xff;
3010 cp[3] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003011 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
3012 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3013 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3014 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
FUJITA Tomonorid4345022008-03-09 13:44:34 +09003015 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07003016 /* Do not cache partition table for arrays */
3017 scsicmd->device->removable = 1;
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003018 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003019 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 }
3021
3022 case MODE_SENSE:
3023 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003024 int mode_buf_length = 4;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003025 u32 capacity;
3026 aac_modep_data mpd;
3027
3028 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3029 capacity = fsa_dev_ptr[cid].size - 1;
3030 else
3031 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032
3033 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003034 memset((char *)&mpd, 0, sizeof(aac_modep_data));
3035
3036 /* Mode data length */
3037 mpd.hd.data_length = sizeof(mpd.hd) - 1;
3038 /* Medium type - default */
3039 mpd.hd.med_type = 0;
3040 /* Device-specific param,
3041 bit 8: 0/1 = write enabled/protected
3042 bit 4: 0/1 = FUA enabled */
3043 mpd.hd.dev_par = 0;
3044
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003045 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003046 mpd.hd.dev_par = 0x10;
3047 if (scsicmd->cmnd[1] & 0x8)
3048 mpd.hd.bd_length = 0; /* Block descriptor length */
3049 else {
3050 mpd.hd.bd_length = sizeof(mpd.bd);
3051 mpd.hd.data_length += mpd.hd.bd_length;
3052 mpd.bd.block_length[0] =
3053 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3054 mpd.bd.block_length[1] =
3055 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3056 mpd.bd.block_length[2] =
3057 fsa_dev_ptr[cid].block_size & 0xff;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04003058
3059 mpd.mpc_buf[0] = scsicmd->cmnd[2];
3060 if (scsicmd->cmnd[2] == 0x1C) {
3061 /* page length */
3062 mpd.mpc_buf[1] = 0xa;
3063 /* Mode data length */
3064 mpd.hd.data_length = 23;
3065 } else {
3066 /* Mode data length */
3067 mpd.hd.data_length = 15;
3068 }
3069
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003070 if (capacity > 0xffffff) {
3071 mpd.bd.block_count[0] = 0xff;
3072 mpd.bd.block_count[1] = 0xff;
3073 mpd.bd.block_count[2] = 0xff;
3074 } else {
3075 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
3076 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
3077 mpd.bd.block_count[2] = capacity & 0xff;
3078 }
3079 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003080 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3081 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003082 mpd.hd.data_length += 3;
3083 mpd.mpc_buf[0] = 8;
3084 mpd.mpc_buf[1] = 1;
3085 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003086 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003087 mode_buf_length = sizeof(mpd);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003088 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04003089
3090 if (mode_buf_length > scsicmd->cmnd[4])
3091 mode_buf_length = scsicmd->cmnd[4];
3092 else
3093 mode_buf_length = sizeof(mpd);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003094 scsi_sg_copy_from_buffer(scsicmd,
3095 (char *)&mpd,
3096 mode_buf_length);
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003097 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003098 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
3100 case MODE_SENSE_10:
3101 {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003102 u32 capacity;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003103 int mode_buf_length = 8;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003104 aac_modep10_data mpd10;
3105
3106 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3107 capacity = fsa_dev_ptr[cid].size - 1;
3108 else
3109 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
3111 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003112 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
3113 /* Mode data length (MSB) */
3114 mpd10.hd.data_length[0] = 0;
3115 /* Mode data length (LSB) */
3116 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
3117 /* Medium type - default */
3118 mpd10.hd.med_type = 0;
3119 /* Device-specific param,
3120 bit 8: 0/1 = write enabled/protected
3121 bit 4: 0/1 = FUA enabled */
3122 mpd10.hd.dev_par = 0;
3123
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003124 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003125 mpd10.hd.dev_par = 0x10;
3126 mpd10.hd.rsrvd[0] = 0; /* reserved */
3127 mpd10.hd.rsrvd[1] = 0; /* reserved */
3128 if (scsicmd->cmnd[1] & 0x8) {
3129 /* Block descriptor length (MSB) */
3130 mpd10.hd.bd_length[0] = 0;
3131 /* Block descriptor length (LSB) */
3132 mpd10.hd.bd_length[1] = 0;
3133 } else {
3134 mpd10.hd.bd_length[0] = 0;
3135 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
3136
3137 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
3138
3139 mpd10.bd.block_length[0] =
3140 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3141 mpd10.bd.block_length[1] =
3142 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3143 mpd10.bd.block_length[2] =
3144 fsa_dev_ptr[cid].block_size & 0xff;
3145
3146 if (capacity > 0xffffff) {
3147 mpd10.bd.block_count[0] = 0xff;
3148 mpd10.bd.block_count[1] = 0xff;
3149 mpd10.bd.block_count[2] = 0xff;
3150 } else {
3151 mpd10.bd.block_count[0] =
3152 (capacity >> 16) & 0xff;
3153 mpd10.bd.block_count[1] =
3154 (capacity >> 8) & 0xff;
3155 mpd10.bd.block_count[2] =
3156 capacity & 0xff;
3157 }
3158 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003159 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3160 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003161 mpd10.hd.data_length[1] += 3;
3162 mpd10.mpc_buf[0] = 8;
3163 mpd10.mpc_buf[1] = 1;
3164 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003165 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003166 mode_buf_length = sizeof(mpd10);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003167 if (mode_buf_length > scsicmd->cmnd[8])
3168 mode_buf_length = scsicmd->cmnd[8];
3169 }
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003170 scsi_sg_copy_from_buffer(scsicmd,
3171 (char *)&mpd10,
3172 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003174 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003175 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 }
3177 case REQUEST_SENSE:
3178 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003179 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3180 sizeof(struct sense_data));
3181 memset(&dev->fsa_dev[cid].sense_data, 0,
3182 sizeof(struct sense_data));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003183 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003184 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
3186 case ALLOW_MEDIUM_REMOVAL:
3187 dprintk((KERN_DEBUG "LOCK command.\n"));
3188 if (scsicmd->cmnd[4])
3189 fsa_dev_ptr[cid].locked = 1;
3190 else
3191 fsa_dev_ptr[cid].locked = 0;
3192
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003193 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003194 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 /*
3196 * These commands are all No-Ops
3197 */
3198 case TEST_UNIT_READY:
Mark Salyzyn655d7222008-04-30 16:03:42 -04003199 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003200 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Mark Salyzyn655d7222008-04-30 16:03:42 -04003201 set_sense(&dev->fsa_dev[cid].sense_data,
3202 NOT_READY, SENCODE_BECOMING_READY,
3203 ASENCODE_BECOMING_READY, 0, 0);
3204 memcpy(scsicmd->sense_buffer,
3205 &dev->fsa_dev[cid].sense_data,
3206 min_t(size_t,
3207 sizeof(dev->fsa_dev[cid].sense_data),
3208 SCSI_SENSE_BUFFERSIZE));
Gustavo A. R. Silva8d4d5b32018-11-27 22:25:41 -06003209 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04003210 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05003211 fallthrough;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 case RESERVE:
3213 case RELEASE:
3214 case REZERO_UNIT:
3215 case REASSIGN_BLOCKS:
3216 case SEEK_10:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003217 scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003218 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04003219
3220 case START_STOP:
3221 return aac_start_stop(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003223 default:
3224 /*
3225 * Unhandled commands
3226 */
3227 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
3228 scsicmd->cmnd[0]));
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003229 scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003230 set_sense(&dev->fsa_dev[cid].sense_data,
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08003231 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
3232 ASENCODE_INVALID_COMMAND, 0, 0);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003233 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08003234 min_t(size_t,
3235 sizeof(dev->fsa_dev[cid].sense_data),
3236 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 }
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003238
3239scsi_done_ret:
3240
3241 scsicmd->scsi_done(scsicmd);
3242 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243}
3244
3245static int query_disk(struct aac_dev *dev, void __user *arg)
3246{
3247 struct aac_query_disk qd;
3248 struct fsa_dev_info *fsa_dev_ptr;
3249
3250 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07003251 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07003252 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
3254 return -EFAULT;
Dan Carpentere6fd9162017-07-25 22:49:55 +03003255 if (qd.cnum == -1) {
3256 if (qd.id < 0 || qd.id >= dev->maximum_num_containers)
3257 return -EINVAL;
Mark Haverkampe5718772006-03-27 09:43:25 -08003258 qd.cnum = qd.id;
Dan Carpentere6fd9162017-07-25 22:49:55 +03003259 } else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
3261 return -EINVAL;
3262 qd.instance = dev->scsi_host_ptr->host_no;
3263 qd.bus = 0;
3264 qd.id = CONTAINER_TO_ID(qd.cnum);
3265 qd.lun = CONTAINER_TO_LUN(qd.cnum);
3266 }
3267 else return -EINVAL;
3268
Salyzyn, Markfd622b12007-07-17 10:59:19 -04003269 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 qd.locked = fsa_dev_ptr[qd.cnum].locked;
3271 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
3272
3273 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
3274 qd.unmapped = 1;
3275 else
3276 qd.unmapped = 0;
3277
3278 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
3279 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
3280
3281 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
3282 return -EFAULT;
3283 return 0;
3284}
3285
3286static int force_delete_disk(struct aac_dev *dev, void __user *arg)
3287{
3288 struct aac_delete_disk dd;
3289 struct fsa_dev_info *fsa_dev_ptr;
3290
3291 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp65101352006-09-19 08:59:23 -07003292 if (!fsa_dev_ptr)
3293 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294
3295 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3296 return -EFAULT;
3297
3298 if (dd.cnum >= dev->maximum_num_containers)
3299 return -EINVAL;
3300 /*
3301 * Mark this container as being deleted.
3302 */
3303 fsa_dev_ptr[dd.cnum].deleted = 1;
3304 /*
3305 * Mark the container as no longer valid
3306 */
3307 fsa_dev_ptr[dd.cnum].valid = 0;
3308 return 0;
3309}
3310
3311static int delete_disk(struct aac_dev *dev, void __user *arg)
3312{
3313 struct aac_delete_disk dd;
3314 struct fsa_dev_info *fsa_dev_ptr;
3315
3316 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07003317 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07003318 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
3320 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3321 return -EFAULT;
3322
3323 if (dd.cnum >= dev->maximum_num_containers)
3324 return -EINVAL;
3325 /*
3326 * If the container is locked, it can not be deleted by the API.
3327 */
3328 if (fsa_dev_ptr[dd.cnum].locked)
3329 return -EBUSY;
3330 else {
3331 /*
3332 * Mark the container as no longer being valid.
3333 */
3334 fsa_dev_ptr[dd.cnum].valid = 0;
3335 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
3336 return 0;
3337 }
3338}
3339
Nathan Chancellor6f4e6262019-02-07 09:07:20 -07003340int aac_dev_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341{
3342 switch (cmd) {
3343 case FSACTL_QUERY_DISK:
3344 return query_disk(dev, arg);
3345 case FSACTL_DELETE_DISK:
3346 return delete_disk(dev, arg);
3347 case FSACTL_FORCE_DELETE_DISK:
3348 return force_delete_disk(dev, arg);
3349 case FSACTL_GET_CONTAINERS:
3350 return aac_get_containers(dev);
3351 default:
3352 return -ENOTTY;
3353 }
3354}
3355
3356/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 * aac_srb_callback
3358 * @context: the context set in the fib - here it is scsi cmd
3359 * @fibptr: pointer to the fib
3360 *
3361 * Handles the completion of a scsi command to a non dasd device
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363static void aac_srb_callback(void *context, struct fib * fibptr)
3364{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 struct aac_srb_reply *srbreply;
3366 struct scsi_cmnd *scsicmd;
3367
3368 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07003369
3370 if (!aac_valid_context(scsicmd, fibptr))
3371 return;
3372
Eric Sesterhenn125e1872006-06-23 02:06:06 -07003373 BUG_ON(fibptr == NULL);
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003374
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003375 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003376
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303379 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3380 /* fast response */
3381 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
3382 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
3383 } else {
3384 /*
3385 * Calculate resid for sg
3386 */
3387 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
3388 - le32_to_cpu(srbreply->data_xfer_length));
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003389 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003390
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003392 scsi_dma_unmap(scsicmd);
3393
3394 /* expose physical device if expose_physicald flag is on */
3395 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
3396 && expose_physicals > 0)
3397 aac_expose_phy_device(scsicmd);
3398
3399 /*
3400 * First check the fib status
3401 */
3402
3403 if (le32_to_cpu(srbreply->status) != ST_OK) {
3404 int len;
3405
3406 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3407 le32_to_cpu(srbreply->status));
3408 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3409 SCSI_SENSE_BUFFERSIZE);
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003410 scsicmd->result = DID_ERROR << 16 | SAM_STAT_CHECK_CONDITION;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003411 memcpy(scsicmd->sense_buffer,
3412 srbreply->sense_data, len);
3413 }
3414
3415 /*
3416 * Next check the srb status
3417 */
3418 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3419 case SRB_STATUS_ERROR_RECOVERY:
3420 case SRB_STATUS_PENDING:
3421 case SRB_STATUS_SUCCESS:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003422 scsicmd->result = DID_OK << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003423 break;
3424 case SRB_STATUS_DATA_OVERRUN:
3425 switch (scsicmd->cmnd[0]) {
3426 case READ_6:
3427 case WRITE_6:
3428 case READ_10:
3429 case WRITE_10:
3430 case READ_12:
3431 case WRITE_12:
3432 case READ_16:
3433 case WRITE_16:
3434 if (le32_to_cpu(srbreply->data_xfer_length)
3435 < scsicmd->underflow)
3436 pr_warn("aacraid: SCSI CMD underflow\n");
3437 else
3438 pr_warn("aacraid: SCSI CMD Data Overrun\n");
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003439 scsicmd->result = DID_ERROR << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003440 break;
3441 case INQUIRY:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003442 scsicmd->result = DID_OK << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003443 break;
3444 default:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003445 scsicmd->result = DID_OK << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 break;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003447 }
3448 break;
3449 case SRB_STATUS_ABORTED:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003450 scsicmd->result = DID_ABORT << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003451 break;
3452 case SRB_STATUS_ABORT_FAILED:
3453 /*
3454 * Not sure about this one - but assuming the
3455 * hba was trying to abort for some reason
3456 */
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003457 scsicmd->result = DID_ERROR << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003458 break;
3459 case SRB_STATUS_PARITY_ERROR:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003460 scsicmd->result = DID_PARITY << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003461 break;
3462 case SRB_STATUS_NO_DEVICE:
3463 case SRB_STATUS_INVALID_PATH_ID:
3464 case SRB_STATUS_INVALID_TARGET_ID:
3465 case SRB_STATUS_INVALID_LUN:
3466 case SRB_STATUS_SELECTION_TIMEOUT:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003467 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003468 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003469
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003470 case SRB_STATUS_COMMAND_TIMEOUT:
3471 case SRB_STATUS_TIMEOUT:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003472 scsicmd->result = DID_TIME_OUT << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003473 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003474
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003475 case SRB_STATUS_BUSY:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003476 scsicmd->result = DID_BUS_BUSY << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003477 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003478
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003479 case SRB_STATUS_BUS_RESET:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003480 scsicmd->result = DID_RESET << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003481 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003482
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003483 case SRB_STATUS_MESSAGE_REJECTED:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003484 scsicmd->result = DID_ERROR << 16;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003485 break;
3486 case SRB_STATUS_REQUEST_FLUSHED:
3487 case SRB_STATUS_ERROR:
3488 case SRB_STATUS_INVALID_REQUEST:
3489 case SRB_STATUS_REQUEST_SENSE_FAILED:
3490 case SRB_STATUS_NO_HBA:
3491 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3492 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3493 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3494 case SRB_STATUS_DELAYED_RETRY:
3495 case SRB_STATUS_BAD_FUNCTION:
3496 case SRB_STATUS_NOT_STARTED:
3497 case SRB_STATUS_NOT_IN_USE:
3498 case SRB_STATUS_FORCE_ABORT:
3499 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3500 default:
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003501#ifdef AAC_DETAILED_STATUS_INFO
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003502 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3503 le32_to_cpu(srbreply->srb_status) & 0x3F,
3504 aac_get_status_string(
3505 le32_to_cpu(srbreply->srb_status) & 0x3F),
3506 scsicmd->cmnd[0],
3507 le32_to_cpu(srbreply->scsi_status));
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003508#endif
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003509 /*
3510 * When the CC bit is SET by the host in ATA pass thru CDB,
3511 * driver is supposed to return DID_OK
3512 *
3513 * When the CC bit is RESET by the host, driver should
3514 * return DID_ERROR
3515 */
3516 if ((scsicmd->cmnd[0] == ATA_12)
3517 || (scsicmd->cmnd[0] == ATA_16)) {
3518
3519 if (scsicmd->cmnd[2] & (0x01 << 5)) {
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003520 scsicmd->result = DID_OK << 16;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003521 } else {
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003522 scsicmd->result = DID_ERROR << 16;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003523 }
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003524 } else {
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003525 scsicmd->result = DID_ERROR << 16;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003526 }
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003527 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 }
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003529 if (le32_to_cpu(srbreply->scsi_status)
3530 == SAM_STAT_CHECK_CONDITION) {
3531 int len;
3532
3533 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3534 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3535 SCSI_SENSE_BUFFERSIZE);
3536#ifdef AAC_DETAILED_STATUS_INFO
3537 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3538 le32_to_cpu(srbreply->status), len);
3539#endif
3540 memcpy(scsicmd->sense_buffer,
3541 srbreply->sense_data, len);
3542 }
3543
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 /*
3545 * OR in the scsi status (already shifted up a bit)
3546 */
3547 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3548
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003549 aac_fib_complete(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07003550 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551}
3552
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003553static void hba_resp_task_complete(struct aac_dev *dev,
3554 struct scsi_cmnd *scsicmd,
3555 struct aac_hba_resp *err) {
3556
3557 scsicmd->result = err->status;
3558 /* set residual count */
3559 scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
3560
3561 switch (err->status) {
3562 case SAM_STAT_GOOD:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003563 scsicmd->result |= DID_OK << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003564 break;
3565 case SAM_STAT_CHECK_CONDITION:
3566 {
3567 int len;
3568
3569 len = min_t(u8, err->sense_response_data_len,
3570 SCSI_SENSE_BUFFERSIZE);
3571 if (len)
3572 memcpy(scsicmd->sense_buffer,
3573 err->sense_response_buf, len);
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003574 scsicmd->result |= DID_OK << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003575 break;
3576 }
3577 case SAM_STAT_BUSY:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003578 scsicmd->result |= DID_BUS_BUSY << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003579 break;
3580 case SAM_STAT_TASK_ABORTED:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003581 scsicmd->result |= DID_ABORT << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003582 break;
3583 case SAM_STAT_RESERVATION_CONFLICT:
3584 case SAM_STAT_TASK_SET_FULL:
3585 default:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003586 scsicmd->result |= DID_ERROR << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003587 break;
3588 }
3589}
3590
3591static void hba_resp_task_failure(struct aac_dev *dev,
3592 struct scsi_cmnd *scsicmd,
3593 struct aac_hba_resp *err)
3594{
3595 switch (err->status) {
3596 case HBA_RESP_STAT_HBAMODE_DISABLED:
3597 {
3598 u32 bus, cid;
3599
3600 bus = aac_logical_to_phys(scmd_channel(scsicmd));
3601 cid = scmd_id(scsicmd);
3602 if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
3603 dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
3604 dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
3605 }
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003606 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003607 break;
3608 }
3609 case HBA_RESP_STAT_IO_ERROR:
3610 case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003611 scsicmd->result = DID_OK << 16 | SAM_STAT_BUSY;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003612 break;
3613 case HBA_RESP_STAT_IO_ABORTED:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003614 scsicmd->result = DID_ABORT << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003615 break;
3616 case HBA_RESP_STAT_INVALID_DEVICE:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003617 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003618 break;
3619 case HBA_RESP_STAT_UNDERRUN:
3620 /* UNDERRUN is OK */
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003621 scsicmd->result = DID_OK << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003622 break;
3623 case HBA_RESP_STAT_OVERRUN:
3624 default:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003625 scsicmd->result = DID_ERROR << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003626 break;
3627 }
3628}
3629
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630/**
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003631 * aac_hba_callback
3632 * @context: the context set in the fib - here it is scsi cmd
3633 * @fibptr: pointer to the fib
3634 *
3635 * Handles the completion of a native HBA scsi command
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003636 */
3637void aac_hba_callback(void *context, struct fib *fibptr)
3638{
3639 struct aac_dev *dev;
3640 struct scsi_cmnd *scsicmd;
3641
3642 struct aac_hba_resp *err =
3643 &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
3644
3645 scsicmd = (struct scsi_cmnd *) context;
3646
3647 if (!aac_valid_context(scsicmd, fibptr))
3648 return;
3649
3650 WARN_ON(fibptr == NULL);
3651 dev = fibptr->dev;
3652
3653 if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
3654 scsi_dma_unmap(scsicmd);
3655
3656 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3657 /* fast response */
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003658 scsicmd->result = DID_OK << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003659 goto out;
3660 }
3661
3662 switch (err->service_response) {
3663 case HBA_RESP_SVCRES_TASK_COMPLETE:
3664 hba_resp_task_complete(dev, scsicmd, err);
3665 break;
3666 case HBA_RESP_SVCRES_FAILURE:
3667 hba_resp_task_failure(dev, scsicmd, err);
3668 break;
3669 case HBA_RESP_SVCRES_TMF_REJECTED:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003670 scsicmd->result = DID_ERROR << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003671 break;
3672 case HBA_RESP_SVCRES_TMF_LUN_INVALID:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003673 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003674 break;
3675 case HBA_RESP_SVCRES_TMF_COMPLETE:
3676 case HBA_RESP_SVCRES_TMF_SUCCEEDED:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003677 scsicmd->result = DID_OK << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003678 break;
3679 default:
Hannes Reineckecdec16c2021-01-13 10:04:40 +01003680 scsicmd->result = DID_ERROR << 16;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003681 break;
3682 }
3683
3684out:
3685 aac_fib_complete(fibptr);
3686
3687 if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
3688 scsicmd->SCp.sent_command = 1;
3689 else
3690 scsicmd->scsi_done(scsicmd);
3691}
3692
3693/**
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003694 * aac_send_srb_fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 * @scsicmd: the scsi command block
3696 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003697 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 * scsicmd passed in.
3699 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3701{
3702 struct fib* cmd_fibcontext;
3703 struct aac_dev* dev;
3704 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705
Mark Haverkamp84971732005-06-20 11:55:24 -07003706 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08003707 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07003708 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 scsicmd->result = DID_NO_CONNECT << 16;
3710 scsicmd->scsi_done(scsicmd);
3711 return 0;
3712 }
3713
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 /*
3715 * Allocate and initialize a Fib then setup a BlockWrite command
3716 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08003717 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Brian King1ae948f2017-08-29 10:00:29 -05003718 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08003719 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 /*
3722 * Check that the command queued to the controller
3723 */
Brian King1ae948f2017-08-29 10:00:29 -05003724 if (status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003727 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3728 aac_fib_complete(cmd_fibcontext);
3729 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730
3731 return -1;
3732}
3733
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003734/**
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003735 * aac_send_hba_fib
3736 * @scsicmd: the scsi command block
3737 *
3738 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3739 * scsicmd passed in.
3740 */
3741static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
3742{
3743 struct fib *cmd_fibcontext;
3744 struct aac_dev *dev;
3745 int status;
3746
3747 dev = shost_priv(scsicmd->device->host);
3748 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3749 scsicmd->device->lun > AAC_MAX_LUN - 1) {
3750 scsicmd->result = DID_NO_CONNECT << 16;
3751 scsicmd->scsi_done(scsicmd);
3752 return 0;
3753 }
3754
3755 /*
3756 * Allocate and initialize a Fib then setup a BlockWrite command
3757 */
3758 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3759 if (!cmd_fibcontext)
3760 return -1;
3761
Brian King1ae948f2017-08-29 10:00:29 -05003762 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003763 status = aac_adapter_hba(cmd_fibcontext, scsicmd);
3764
3765 /*
3766 * Check that the command queued to the controller
3767 */
Brian King1ae948f2017-08-29 10:00:29 -05003768 if (status == -EINPROGRESS)
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003769 return 0;
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003770
3771 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3772 status);
3773 aac_fib_complete(cmd_fibcontext);
3774 aac_fib_free(cmd_fibcontext);
3775
3776 return -1;
3777}
3778
3779
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303780static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003783 int nseg;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003784 struct scatterlist *sg;
3785 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 // Get rid of old data
3788 psg->count = 0;
3789 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003790 psg->sg[0].count = 0;
3791
3792 nseg = scsi_dma_map(scsicmd);
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003793 if (nseg <= 0)
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303794 return nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003796 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003798 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3799 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3800 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3801 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003803 /* hba wants the size to be exact */
3804 if (byte_count > scsi_bufflen(scsicmd)) {
3805 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3806 (byte_count - scsi_bufflen(scsicmd));
3807 psg->sg[i-1].count = cpu_to_le32(temp);
3808 byte_count = scsi_bufflen(scsicmd);
3809 }
3810 /* Check for command underflow */
3811 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3812 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3813 byte_count, scsicmd->underflow);
3814 }
3815
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 return byte_count;
3817}
3818
3819
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303820static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003823 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003824 int nseg;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003825 struct scatterlist *sg;
3826 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 // Get rid of old data
3829 psg->count = 0;
3830 psg->sg[0].addr[0] = 0;
3831 psg->sg[0].addr[1] = 0;
3832 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003833
3834 nseg = scsi_dma_map(scsicmd);
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003835 if (nseg <= 0)
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303836 return nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003838 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3839 int count = sg_dma_len(sg);
3840 addr = sg_dma_address(sg);
3841 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3842 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
3843 psg->sg[i].count = cpu_to_le32(count);
3844 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003846 psg->count = cpu_to_le32(nseg);
3847 /* hba wants the size to be exact */
3848 if (byte_count > scsi_bufflen(scsicmd)) {
3849 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3850 (byte_count - scsi_bufflen(scsicmd));
3851 psg->sg[i-1].count = cpu_to_le32(temp);
3852 byte_count = scsi_bufflen(scsicmd);
3853 }
3854 /* Check for command underflow */
3855 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3856 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3857 byte_count, scsicmd->underflow);
3858 }
3859
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 return byte_count;
3861}
3862
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303863static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003864{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003865 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003866 int nseg;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003867 struct scatterlist *sg;
3868 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003869
3870 // Get rid of old data
3871 psg->count = 0;
3872 psg->sg[0].next = 0;
3873 psg->sg[0].prev = 0;
3874 psg->sg[0].addr[0] = 0;
3875 psg->sg[0].addr[1] = 0;
3876 psg->sg[0].count = 0;
3877 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003878
3879 nseg = scsi_dma_map(scsicmd);
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003880 if (nseg <= 0)
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303881 return nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003882
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003883 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3884 int count = sg_dma_len(sg);
3885 u64 addr = sg_dma_address(sg);
3886 psg->sg[i].next = 0;
3887 psg->sg[i].prev = 0;
3888 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
3889 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
3890 psg->sg[i].count = cpu_to_le32(count);
3891 psg->sg[i].flags = 0;
3892 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003893 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003894 psg->count = cpu_to_le32(nseg);
3895 /* hba wants the size to be exact */
3896 if (byte_count > scsi_bufflen(scsicmd)) {
3897 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3898 (byte_count - scsi_bufflen(scsicmd));
3899 psg->sg[i-1].count = cpu_to_le32(temp);
3900 byte_count = scsi_bufflen(scsicmd);
3901 }
3902 /* Check for command underflow */
3903 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3904 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3905 byte_count, scsicmd->underflow);
3906 }
3907
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003908 return byte_count;
3909}
3910
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303911static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
3912 struct aac_raw_io2 *rio2, int sg_max)
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303913{
3914 unsigned long byte_count = 0;
3915 int nseg;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003916 struct scatterlist *sg;
3917 int i, conformable = 0;
3918 u32 min_size = PAGE_SIZE, cur_size;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303919
3920 nseg = scsi_dma_map(scsicmd);
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003921 if (nseg <= 0)
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303922 return nseg;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303923
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003924 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3925 int count = sg_dma_len(sg);
3926 u64 addr = sg_dma_address(sg);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303927
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003928 BUG_ON(i >= sg_max);
3929 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3930 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3931 cur_size = cpu_to_le32(count);
3932 rio2->sge[i].length = cur_size;
3933 rio2->sge[i].flags = 0;
3934 if (i == 0) {
3935 conformable = 1;
3936 rio2->sgeFirstSize = cur_size;
3937 } else if (i == 1) {
3938 rio2->sgeNominalSize = cur_size;
3939 min_size = cur_size;
3940 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3941 conformable = 0;
3942 if (cur_size < min_size)
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303943 min_size = cur_size;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303944 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003945 byte_count += count;
3946 }
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303947
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003948 /* hba wants the size to be exact */
3949 if (byte_count > scsi_bufflen(scsicmd)) {
3950 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3951 (byte_count - scsi_bufflen(scsicmd));
3952 rio2->sge[i-1].length = cpu_to_le32(temp);
3953 byte_count = scsi_bufflen(scsicmd);
3954 }
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303955
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003956 rio2->sgeCnt = cpu_to_le32(nseg);
3957 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3958 /* not conformable: evaluate required sg elements */
3959 if (!conformable) {
3960 int j, nseg_new = nseg, err_found;
3961 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3962 err_found = 0;
3963 nseg_new = 2;
3964 for (j = 1; j < nseg - 1; ++j) {
3965 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3966 err_found = 1;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303967 break;
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003968 }
3969 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303970 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003971 if (!err_found)
3972 break;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303973 }
Nikola Pajkovsky96676242017-08-29 13:59:04 +02003974 if (i > 0 && nseg_new <= sg_max) {
3975 int ret = aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3976
3977 if (ret < 0)
3978 return ret;
3979 }
Nikola Pajkovskya2260322017-08-29 13:59:03 +02003980 } else
3981 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3982
3983 /* Check for command underflow */
3984 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3985 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3986 byte_count, scsicmd->underflow);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303987 }
3988
3989 return byte_count;
3990}
3991
3992static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3993{
3994 struct sge_ieee1212 *sge;
3995 int i, j, pos;
3996 u32 addr_low;
3997
3998 if (aac_convert_sgl == 0)
3999 return 0;
4000
Kees Cook6da2ec52018-06-12 13:55:00 -07004001 sge = kmalloc_array(nseg_new, sizeof(struct sge_ieee1212), GFP_ATOMIC);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304002 if (sge == NULL)
Nikola Pajkovsky96676242017-08-29 13:59:04 +02004003 return -ENOMEM;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05304004
4005 for (i = 1, pos = 1; i < nseg-1; ++i) {
4006 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
4007 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
4008 sge[pos].addrLow = addr_low;
4009 sge[pos].addrHigh = rio2->sge[i].addrHigh;
4010 if (addr_low < rio2->sge[i].addrLow)
4011 sge[pos].addrHigh++;
4012 sge[pos].length = pages * PAGE_SIZE;
4013 sge[pos].flags = 0;
4014 pos++;
4015 }
4016 }
4017 sge[pos] = rio2->sge[nseg-1];
4018 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
4019
4020 kfree(sge);
4021 rio2->sgeCnt = cpu_to_le32(nseg_new);
4022 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4023 rio2->sgeNominalSize = pages * PAGE_SIZE;
4024 return 0;
4025}
4026
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08004027static long aac_build_sghba(struct scsi_cmnd *scsicmd,
4028 struct aac_hba_cmd_req *hbacmd,
4029 int sg_max,
4030 u64 sg_address)
4031{
4032 unsigned long byte_count = 0;
4033 int nseg;
4034 struct scatterlist *sg;
4035 int i;
4036 u32 cur_size;
4037 struct aac_hba_sgl *sge;
4038
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08004039 nseg = scsi_dma_map(scsicmd);
4040 if (nseg <= 0) {
4041 byte_count = nseg;
4042 goto out;
4043 }
4044
4045 if (nseg > HBA_MAX_SG_EMBEDDED)
4046 sge = &hbacmd->sge[2];
4047 else
4048 sge = &hbacmd->sge[0];
4049
4050 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4051 int count = sg_dma_len(sg);
4052 u64 addr = sg_dma_address(sg);
4053
4054 WARN_ON(i >= sg_max);
4055 sge->addr_hi = cpu_to_le32((u32)(addr>>32));
4056 sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
4057 cur_size = cpu_to_le32(count);
4058 sge->len = cur_size;
4059 sge->flags = 0;
4060 byte_count += count;
4061 sge++;
4062 }
4063
4064 sge--;
4065 /* hba wants the size to be exact */
4066 if (byte_count > scsi_bufflen(scsicmd)) {
4067 u32 temp;
4068
4069 temp = le32_to_cpu(sge->len) - byte_count
4070 - scsi_bufflen(scsicmd);
4071 sge->len = cpu_to_le32(temp);
4072 byte_count = scsi_bufflen(scsicmd);
4073 }
4074
4075 if (nseg <= HBA_MAX_SG_EMBEDDED) {
4076 hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
4077 sge->flags = cpu_to_le32(0x40000000);
4078 } else {
4079 /* not embedded */
4080 hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
4081 hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
4082 hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
4083 hbacmd->sge[0].addr_lo =
4084 cpu_to_le32((u32)(sg_address & 0xffffffff));
4085 }
4086
4087 /* Check for command underflow */
4088 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4089 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4090 byte_count, scsicmd->underflow);
4091 }
4092out:
4093 return byte_count;
4094}
4095
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096#ifdef AAC_DETAILED_STATUS_INFO
4097
4098struct aac_srb_status_info {
4099 u32 status;
4100 char *str;
4101};
4102
4103
4104static struct aac_srb_status_info srb_status_info[] = {
4105 { SRB_STATUS_PENDING, "Pending Status"},
4106 { SRB_STATUS_SUCCESS, "Success"},
4107 { SRB_STATUS_ABORTED, "Aborted Command"},
4108 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07004109 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110 { SRB_STATUS_BUSY, "Device Busy"},
4111 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
4112 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
4113 { SRB_STATUS_NO_DEVICE, "No Device"},
4114 { SRB_STATUS_TIMEOUT, "Timeout"},
4115 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
4116 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
4117 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
4118 { SRB_STATUS_BUS_RESET, "Bus Reset"},
4119 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
4120 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
4121 { SRB_STATUS_NO_HBA, "No HBA"},
4122 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
4123 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
4124 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
4125 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
4126 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
4127 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07004128 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
4130 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
4131 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
4132 { SRB_STATUS_NOT_STARTED, "Not Started"},
4133 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08004134 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
4136 { 0xff, "Unknown Error"}
4137};
4138
4139char *aac_get_status_string(u32 status)
4140{
4141 int i;
4142
Tobias Klauser6391a112006-06-08 22:23:48 -07004143 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
4144 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146
4147 return "Bad Status Code";
4148}
4149
4150#endif