blob: 98d4ffd798c507f6af3e72ce11b670564e8a2a74 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
Alan Coxfa195af2008-10-27 15:16:36 +00003 * (c) Copyright 2001 Red Hat Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07008 * Copyright (c) 2000-2010 Adaptec, Inc.
Raghava Aditya Renukuntaf4babba2017-02-02 15:53:36 -08009 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
10 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
Raghava Aditya Renukuntaf4babba2017-02-02 15:53:36 -080026 * Module Name:
27 * aachba.c
28 *
29 * Abstract: Contains Interfaces to manage IOs.
30 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 */
32
33#include <linux/kernel.h>
34#include <linux/init.h>
35#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/pci.h>
37#include <linux/spinlock.h>
38#include <linux/slab.h>
39#include <linux/completion.h>
40#include <linux/blkdev.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080041#include <linux/uaccess.h>
Salyzyn, Mark3a0086a82008-01-11 11:46:44 -080042#include <linux/highmem.h> /* For flush_kernel_dcache_page */
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040043#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#include <scsi/scsi.h>
46#include <scsi/scsi_cmnd.h>
47#include <scsi/scsi_device.h>
48#include <scsi/scsi_host.h>
49
50#include "aacraid.h"
51
52/* values for inqd_pdt: Peripheral device type in plain English */
53#define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
54#define INQD_PDT_PROC 0x03 /* Processor device */
55#define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
56#define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
57#define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
58#define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
59
60#define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
61#define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*
64 * Sense codes
65 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080066
67#define SENCODE_NO_SENSE 0x00
68#define SENCODE_END_OF_DATA 0x00
69#define SENCODE_BECOMING_READY 0x04
70#define SENCODE_INIT_CMD_REQUIRED 0x04
Raghava Aditya Renukuntaf956a662017-02-02 15:53:23 -080071#define SENCODE_UNRECOVERED_READ_ERROR 0x11
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080072#define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
73#define SENCODE_INVALID_COMMAND 0x20
74#define SENCODE_LBA_OUT_OF_RANGE 0x21
75#define SENCODE_INVALID_CDB_FIELD 0x24
76#define SENCODE_LUN_NOT_SUPPORTED 0x25
77#define SENCODE_INVALID_PARAM_FIELD 0x26
78#define SENCODE_PARAM_NOT_SUPPORTED 0x26
79#define SENCODE_PARAM_VALUE_INVALID 0x26
80#define SENCODE_RESET_OCCURRED 0x29
81#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
82#define SENCODE_INQUIRY_DATA_CHANGED 0x3F
83#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
84#define SENCODE_DIAGNOSTIC_FAILURE 0x40
85#define SENCODE_INTERNAL_TARGET_FAILURE 0x44
86#define SENCODE_INVALID_MESSAGE_ERROR 0x49
87#define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
88#define SENCODE_OVERLAPPED_COMMAND 0x4E
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90/*
91 * Additional sense codes
92 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -080093
94#define ASENCODE_NO_SENSE 0x00
95#define ASENCODE_END_OF_DATA 0x05
96#define ASENCODE_BECOMING_READY 0x01
97#define ASENCODE_INIT_CMD_REQUIRED 0x02
98#define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
99#define ASENCODE_INVALID_COMMAND 0x00
100#define ASENCODE_LBA_OUT_OF_RANGE 0x00
101#define ASENCODE_INVALID_CDB_FIELD 0x00
102#define ASENCODE_LUN_NOT_SUPPORTED 0x00
103#define ASENCODE_INVALID_PARAM_FIELD 0x00
104#define ASENCODE_PARAM_NOT_SUPPORTED 0x01
105#define ASENCODE_PARAM_VALUE_INVALID 0x02
106#define ASENCODE_RESET_OCCURRED 0x00
107#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
108#define ASENCODE_INQUIRY_DATA_CHANGED 0x03
109#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
110#define ASENCODE_DIAGNOSTIC_FAILURE 0x80
111#define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
112#define ASENCODE_INVALID_MESSAGE_ERROR 0x00
113#define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
114#define ASENCODE_OVERLAPPED_COMMAND 0x00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -0800116#define AAC_STAT_GOOD (DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD)
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define BYTE0(x) (unsigned char)(x)
119#define BYTE1(x) (unsigned char)((x) >> 8)
120#define BYTE2(x) (unsigned char)((x) >> 16)
121#define BYTE3(x) (unsigned char)((x) >> 24)
122
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400123/* MODE_SENSE data format */
124typedef struct {
125 struct {
126 u8 data_length;
127 u8 med_type;
128 u8 dev_par;
129 u8 bd_length;
130 } __attribute__((packed)) hd;
131 struct {
132 u8 dens_code;
133 u8 block_count[3];
134 u8 reserved;
135 u8 block_length[3];
136 } __attribute__((packed)) bd;
137 u8 mpc_buf[3];
138} __attribute__((packed)) aac_modep_data;
139
140/* MODE_SENSE_10 data format */
141typedef struct {
142 struct {
143 u8 data_length[2];
144 u8 med_type;
145 u8 dev_par;
146 u8 rsrvd[2];
147 u8 bd_length[2];
148 } __attribute__((packed)) hd;
149 struct {
150 u8 dens_code;
151 u8 block_count[3];
152 u8 reserved;
153 u8 block_length[3];
154 } __attribute__((packed)) bd;
155 u8 mpc_buf[3];
156} __attribute__((packed)) aac_modep10_data;
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/*------------------------------------------------------------------------------
159 * S T R U C T S / T Y P E D E F S
160 *----------------------------------------------------------------------------*/
161/* SCSI inquiry data */
162struct inquiry_data {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800163 u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
164 u8 inqd_dtq; /* RMB | Device Type Qualifier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
166 u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
167 u8 inqd_len; /* Additional length (n-4) */
168 u8 inqd_pad1[2];/* Reserved - must be zero */
169 u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
170 u8 inqd_vid[8]; /* Vendor ID */
171 u8 inqd_pid[16];/* Product ID */
172 u8 inqd_prl[4]; /* Product Revision Level */
173};
174
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400175/* Added for VPD 0x83 */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800176struct tvpd_id_descriptor_type_1 {
177 u8 codeset:4; /* VPD_CODE_SET */
178 u8 reserved:4;
179 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
180 u8 reserved2:4;
181 u8 reserved3;
182 u8 identifierlength;
183 u8 venid[8];
184 u8 productid[16];
185 u8 serialnumber[8]; /* SN in ASCII */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400186
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800187};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400188
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800189struct tvpd_id_descriptor_type_2 {
190 u8 codeset:4; /* VPD_CODE_SET */
191 u8 reserved:4;
192 u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
193 u8 reserved2:4;
194 u8 reserved3;
195 u8 identifierlength;
196 struct teu64id {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400197 u32 Serial;
198 /* The serial number supposed to be 40 bits,
199 * bit we only support 32, so make the last byte zero. */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800200 u8 reserved;
201 u8 venid[3];
202 } eu64id;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400203
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800204};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400205
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800206struct tvpd_id_descriptor_type_3 {
207 u8 codeset : 4; /* VPD_CODE_SET */
208 u8 reserved : 4;
209 u8 identifiertype : 4; /* VPD_IDENTIFIER_TYPE */
210 u8 reserved2 : 4;
211 u8 reserved3;
212 u8 identifierlength;
213 u8 Identifier[16];
214};
215
216struct tvpd_page83 {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400217 u8 DeviceType:5;
218 u8 DeviceTypeQualifier:3;
219 u8 PageCode;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800220 u8 reserved;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400221 u8 PageLength;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800222 struct tvpd_id_descriptor_type_1 type1;
223 struct tvpd_id_descriptor_type_2 type2;
224 struct tvpd_id_descriptor_type_3 type3;
225};
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/*
228 * M O D U L E G L O B A L S
229 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800230
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +0530231static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
232static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
233static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
234static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
235 struct aac_raw_io2 *rio2, int sg_max);
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -0800236static long aac_build_sghba(struct scsi_cmnd *scsicmd,
237 struct aac_hba_cmd_req *hbacmd,
238 int sg_max, u64 sg_address);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +0530239static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
240 int pages, int nseg, int nseg_new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -0800242static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#ifdef AAC_DETAILED_STATUS_INFO
244static char *aac_get_status_string(u32 status);
245#endif
246
247/*
248 * Non dasd selection is handled entirely in aachba now
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800249 */
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251static int nondasd = -1;
Leubner, Achimd8e965072009-04-01 07:16:08 -0700252static int aac_cache = 2; /* WCE=0 to avoid performance problems */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static int dacmode = -1;
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800254int aac_msi;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400255int aac_commit = -1;
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700256int startup_timeout = 180;
257int aif_timeout = 120;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800258int aac_sync_mode; /* Only Sync. transfer - disabled */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530259int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800261module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
262MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
263 " 0=off, 1=on");
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +0530264module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
265MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
266 " 0=off, 1=on");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800267module_param(nondasd, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800268MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
269 " 0=off, 1=on");
Salyzyn, Mark95e852e2008-01-08 12:01:07 -0800270module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800271MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
272 "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
273 "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
Leubner, Achimd8e965072009-04-01 07:16:08 -0700274 "\tbit 2 - Disable only if Battery is protecting Cache");
Mark Haverkamp9a72f972006-03-27 09:44:37 -0800275module_param(dacmode, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800276MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
277 " 0=off, 1=on");
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400278module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800279MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
280 " adapter for foreign arrays.\n"
281 "This is typically needed in systems that do not have a BIOS."
282 " 0=off, 1=on");
283module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
284MODULE_PARM_DESC(msi, "IRQ handling."
Mahesh Rajashekhara9022d372015-08-28 06:38:35 -0400285 " 0=PIC(default), 1=MSI, 2=MSI-X)");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700286module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800287MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
288 " adapter to have it's kernel up and\n"
289 "running. This is typically adjusted for large systems that do not"
290 " have a BIOS.");
Mark Haverkamp404d9a92006-05-10 09:12:48 -0700291module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800292MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
293 " applications to pick up AIFs before\n"
294 "deregistering them. This is typically adjusted for heavily burdened"
295 " systems.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700297int numacb = -1;
298module_param(numacb, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800299MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
300 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
301 " to use suggestion from Firmware.");
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700302
303int acbsize = -1;
304module_param(acbsize, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800305MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
306 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
307 " suggestion from Firmware.");
Mark Haverkamp653ba582006-09-19 08:59:43 -0700308
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400309int update_interval = 30 * 60;
310module_param(update_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800311MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
312 " updates issued to adapter.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400313
314int check_interval = 24 * 60 * 60;
315module_param(check_interval, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800316MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
317 " checks.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400318
Andrew Morton87f3bda2007-08-10 14:50:30 -0700319int aac_check_reset = 1;
320module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
Paul Bolle95e7a8e2008-04-16 14:43:00 +0200321MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800322 " adapter. a value of -1 forces the reset to adapters programmed to"
323 " ignore it.");
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400324
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800325int expose_physicals = -1;
Mark Haverkamp653ba582006-09-19 08:59:43 -0700326module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800327MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
328 " -1=protect 0=off, 1=on");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700329
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800330int aac_reset_devices;
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400331module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
332MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
Mark Haverkamp03d44332007-03-15 10:27:45 -0700333
Leubner, Achimd8e965072009-04-01 07:16:08 -0700334int aac_wwn = 1;
335module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
336MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
337 "\t0 - Disable\n"
338 "\t1 - Array Meta Data Signature (default)\n"
339 "\t2 - Adapter Serial Number");
340
341
Mark Haverkamp03d44332007-03-15 10:27:45 -0700342static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
343 struct fib *fibptr) {
344 struct scsi_device *device;
345
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800346 if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
Salyzyn, Markc835e372007-07-26 14:20:02 -0400347 dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800348 aac_fib_complete(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800349 return 0;
350 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700351 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
352 device = scsicmd->device;
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800353 if (unlikely(!device)) {
Mark Haverkamp03d44332007-03-15 10:27:45 -0700354 dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
355 aac_fib_complete(fibptr);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700356 return 0;
357 }
358 return 1;
359}
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361/**
362 * aac_get_config_status - check the adapter configuration
363 * @common: adapter to query
364 *
365 * Query config status, and commit the configuration if needed.
366 */
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700367int aac_get_config_status(struct aac_dev *dev, int commit_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369 int status = 0;
370 struct fib * fibptr;
371
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800372 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 return -ENOMEM;
374
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800375 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 {
377 struct aac_get_config_status *dinfo;
378 dinfo = (struct aac_get_config_status *) fib_data(fibptr);
379
380 dinfo->command = cpu_to_le32(VM_ContainerConfig);
381 dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
382 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
383 }
384
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800385 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 fibptr,
387 sizeof (struct aac_get_config_status),
388 FsaNormal,
389 1, 1,
390 NULL, NULL);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800391 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
393 } else {
394 struct aac_get_config_status_resp *reply
395 = (struct aac_get_config_status_resp *) fib_data(fibptr);
396 dprintk((KERN_WARNING
397 "aac_get_config_status: response=%d status=%d action=%d\n",
398 le32_to_cpu(reply->response),
399 le32_to_cpu(reply->status),
400 le32_to_cpu(reply->data.action)));
401 if ((le32_to_cpu(reply->response) != ST_OK) ||
402 (le32_to_cpu(reply->status) != CT_OK) ||
403 (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
404 printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
405 status = -EINVAL;
406 }
407 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530408 /* Do not set XferState to zero unless receives a response from F/W */
409 if (status >= 0)
410 aac_fib_complete(fibptr);
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
413 if (status >= 0) {
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400414 if ((aac_commit == 1) || commit_flag) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 struct aac_commit_config * dinfo;
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800416 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 dinfo = (struct aac_commit_config *) fib_data(fibptr);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 dinfo->command = cpu_to_le32(VM_ContainerConfig);
420 dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800421
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800422 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 fibptr,
424 sizeof (struct aac_commit_config),
425 FsaNormal,
426 1, 1,
427 NULL, NULL);
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530428 /* Do not set XferState to zero unless
429 * receives a response from F/W */
430 if (status >= 0)
431 aac_fib_complete(fibptr);
Salyzyn, Mark1208bab2007-05-22 09:32:29 -0400432 } else if (aac_commit == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 printk(KERN_WARNING
434 "aac_get_config_status: Foreign device configurations are being ignored\n");
435 }
436 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530437 /* FIB should be freed only after getting the response from the F/W */
438 if (status != -ERESTARTSYS)
439 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return status;
441}
442
Rajashekhara, Maheshe3cc2682010-05-10 04:12:28 -0700443static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
444{
445 char inq_data;
446 scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
447 if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
448 inq_data &= 0xdf;
449 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
450 }
451}
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453/**
454 * aac_get_containers - list containers
455 * @common: adapter to probe
456 *
457 * Make a list of all containers on this controller
458 */
459int aac_get_containers(struct aac_dev *dev)
460{
461 struct fsa_dev_info *fsa_dev_ptr;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800462 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 int status = 0;
464 struct fib * fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 struct aac_get_container_count *dinfo;
466 struct aac_get_container_count_resp *dresp;
467 int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
468
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800469 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return -ENOMEM;
471
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800472 aac_fib_init(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 dinfo = (struct aac_get_container_count *) fib_data(fibptr);
474 dinfo->command = cpu_to_le32(VM_ContainerConfig);
475 dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
476
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800477 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 fibptr,
479 sizeof (struct aac_get_container_count),
480 FsaNormal,
481 1, 1,
482 NULL, NULL);
483 if (status >= 0) {
484 dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
485 maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800486 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharaa7129a52015-03-26 10:41:27 -0400487 AAC_OPTION_SUPPORTED_240_VOLUMES) {
488 maximum_num_containers =
489 le32_to_cpu(dresp->MaxSimpleVolumes);
490 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800491 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 }
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +0530493 /* FIB should be freed only after getting the response from the F/W */
494 if (status != -ERESTARTSYS)
495 aac_fib_free(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
498 maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800499 if (dev->fsa_dev == NULL ||
500 dev->maximum_num_containers != maximum_num_containers) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800502 fsa_dev_ptr = dev->fsa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Raghava Aditya Renukunta3ffd6c52017-02-02 15:53:22 -0800504 dev->fsa_dev = kcalloc(maximum_num_containers,
505 sizeof(*fsa_dev_ptr), GFP_KERNEL);
506
507 kfree(fsa_dev_ptr);
508 fsa_dev_ptr = NULL;
509
510
511 if (!dev->fsa_dev)
512 return -ENOMEM;
513
514 dev->maximum_num_containers = maximum_num_containers;
515 }
516 for (index = 0; index < dev->maximum_num_containers; index++) {
517 dev->fsa_dev[index].devname[0] = '\0';
518 dev->fsa_dev[index].valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Mark Haverkampfe76df42007-03-15 12:55:07 -0700520 status = aac_probe_container(dev, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Mark Haverkampfe76df42007-03-15 12:55:07 -0700522 if (status < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
524 break;
525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return status;
528}
529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530static void get_container_name_callback(void *context, struct fib * fibptr)
531{
532 struct aac_get_name_resp * get_name_reply;
533 struct scsi_cmnd * scsicmd;
534
535 scsicmd = (struct scsi_cmnd *) context;
536
Mark Haverkamp03d44332007-03-15 10:27:45 -0700537 if (!aac_valid_context(scsicmd, fibptr))
538 return;
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700541 BUG_ON(fibptr == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
544 /* Failure is irrelevant, using default value instead */
545 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
546 && (get_name_reply->data[0] != '\0')) {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700547 char *sp = get_name_reply->data;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400548 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 while (*sp == ' ')
550 ++sp;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700551 if (*sp) {
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900552 struct inquiry_data inq;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700553 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
554 int count = sizeof(d);
555 char *dp = d;
556 do {
557 *dp++ = (*sp) ? *sp++ : ' ';
558 } while (--count > 0);
FUJITA Tomonorid4345022008-03-09 13:44:34 +0900559
560 scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
561 memcpy(inq.inqd_pid, d, sizeof(d));
562 scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -0700565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
567
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800568 aac_fib_complete(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -0700569 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
572/**
573 * aac_get_container_name - get container name, none blocking.
574 */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700575static int aac_get_container_name(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 int status;
578 struct aac_get_name *dinfo;
579 struct fib * cmd_fibcontext;
580 struct aac_dev * dev;
581
582 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
583
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800584 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800586 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
588
589 dinfo->command = cpu_to_le32(VM_ContainerConfig);
590 dinfo->type = cpu_to_le32(CT_READ_NAME);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -0700591 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data));
593
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800594 status = aac_fib_send(ContainerCommand,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800595 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -0400596 sizeof(struct aac_get_name_resp),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800597 FsaNormal,
598 0, 1,
599 (fib_callback)get_container_name_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 (void *) scsicmd);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /*
603 * Check that the command queued to the controller
604 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800605 if (status == -EINPROGRESS) {
606 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800608 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800609
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800610 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
611 aac_fib_complete(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 return -1;
613}
614
Mark Haverkampfe76df42007-03-15 12:55:07 -0700615static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
616{
617 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
618
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400619 if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
Mark Haverkampfe76df42007-03-15 12:55:07 -0700620 return aac_scsi_cmd(scsicmd);
621
622 scsicmd->result = DID_NO_CONNECT << 16;
623 scsicmd->scsi_done(scsicmd);
624 return 0;
625}
626
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400627static void _aac_probe_container2(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700628{
Mark Haverkamp03d44332007-03-15 10:27:45 -0700629 struct fsa_dev_info *fsa_dev_ptr;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700630 int (*callback)(struct scsi_cmnd *);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700631 struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800632 int i;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700633
Mark Haverkamp03d44332007-03-15 10:27:45 -0700634
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400635 if (!aac_valid_context(scsicmd, fibptr))
636 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700637
638 scsicmd->SCp.Status = 0;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400639 fsa_dev_ptr = fibptr->dev->fsa_dev;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700640 if (fsa_dev_ptr) {
641 struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800642 __le32 sup_options2;
643
Mark Haverkampfe76df42007-03-15 12:55:07 -0700644 fsa_dev_ptr += scmd_id(scsicmd);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800645 sup_options2 =
646 fibptr->dev->supplement_adapter_info.supported_options2;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700647
648 if ((le32_to_cpu(dresp->status) == ST_OK) &&
649 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
650 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800651 if (!(sup_options2 & AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400652 dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
653 fsa_dev_ptr->block_size = 0x200;
654 } else {
655 fsa_dev_ptr->block_size =
656 le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
657 }
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800658 for (i = 0; i < 16; i++)
659 fsa_dev_ptr->identifier[i] =
660 dresp->mnt[0].fileinfo.bdevinfo
661 .identifier[i];
Mark Haverkampfe76df42007-03-15 12:55:07 -0700662 fsa_dev_ptr->valid = 1;
Mark Salyzyn655d7222008-04-30 16:03:42 -0400663 /* sense_key holds the current state of the spin-up */
664 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
665 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
666 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
667 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700668 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
669 fsa_dev_ptr->size
670 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
671 (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
672 fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
673 }
674 if ((fsa_dev_ptr->valid & 1) == 0)
675 fsa_dev_ptr->valid = 0;
676 scsicmd->SCp.Status = le32_to_cpu(dresp->count);
677 }
678 aac_fib_complete(fibptr);
679 aac_fib_free(fibptr);
680 callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
681 scsicmd->SCp.ptr = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400682 (*callback)(scsicmd);
683 return;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700684}
685
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400686static void _aac_probe_container1(void * context, struct fib * fibptr)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700687{
688 struct scsi_cmnd * scsicmd;
689 struct aac_mount * dresp;
690 struct aac_query_mount *dinfo;
691 int status;
692
693 dresp = (struct aac_mount *) fib_data(fibptr);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800694 if (!(fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400695 AAC_OPTION_VARIABLE_BLOCK_SIZE))
696 dresp->mnt[0].capacityhigh = 0;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700697 if ((le32_to_cpu(dresp->status) != ST_OK) ||
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400698 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
699 _aac_probe_container2(context, fibptr);
700 return;
701 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700702 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkampfe76df42007-03-15 12:55:07 -0700703
Mark Haverkamp03d44332007-03-15 10:27:45 -0700704 if (!aac_valid_context(scsicmd, fibptr))
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400705 return;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700706
Mark Haverkampfe76df42007-03-15 12:55:07 -0700707 aac_fib_init(fibptr);
708
709 dinfo = (struct aac_query_mount *)fib_data(fibptr);
710
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800711 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400712 AAC_OPTION_VARIABLE_BLOCK_SIZE)
713 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
714 else
715 dinfo->command = cpu_to_le32(VM_NameServe64);
716
Mark Haverkampfe76df42007-03-15 12:55:07 -0700717 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
718 dinfo->type = cpu_to_le32(FT_FILESYS);
719
720 status = aac_fib_send(ContainerCommand,
721 fibptr,
722 sizeof(struct aac_query_mount),
723 FsaNormal,
724 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400725 _aac_probe_container2,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700726 (void *) scsicmd);
727 /*
728 * Check that the command queued to the controller
729 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400730 if (status == -EINPROGRESS)
Mark Haverkampfe76df42007-03-15 12:55:07 -0700731 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400732 else if (status < 0) {
Mark Haverkampfe76df42007-03-15 12:55:07 -0700733 /* Inherit results from VM_NameServe, if any */
734 dresp->status = cpu_to_le32(ST_OK);
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400735 _aac_probe_container2(context, fibptr);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700736 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700737}
738
739static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
740{
741 struct fib * fibptr;
742 int status = -ENOMEM;
743
744 if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
745 struct aac_query_mount *dinfo;
746
747 aac_fib_init(fibptr);
748
749 dinfo = (struct aac_query_mount *)fib_data(fibptr);
750
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800751 if (fibptr->dev->supplement_adapter_info.supported_options2 &
Mahesh Rajashekharab8364392015-03-26 10:41:24 -0400752 AAC_OPTION_VARIABLE_BLOCK_SIZE)
753 dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
754 else
755 dinfo->command = cpu_to_le32(VM_NameServe);
756
Mark Haverkampfe76df42007-03-15 12:55:07 -0700757 dinfo->count = cpu_to_le32(scmd_id(scsicmd));
758 dinfo->type = cpu_to_le32(FT_FILESYS);
759 scsicmd->SCp.ptr = (char *)callback;
760
761 status = aac_fib_send(ContainerCommand,
762 fibptr,
763 sizeof(struct aac_query_mount),
764 FsaNormal,
765 0, 1,
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400766 _aac_probe_container1,
Mark Haverkampfe76df42007-03-15 12:55:07 -0700767 (void *) scsicmd);
768 /*
769 * Check that the command queued to the controller
770 */
771 if (status == -EINPROGRESS) {
772 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
773 return 0;
774 }
775 if (status < 0) {
776 scsicmd->SCp.ptr = NULL;
777 aac_fib_complete(fibptr);
778 aac_fib_free(fibptr);
779 }
780 }
781 if (status < 0) {
782 struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
783 if (fsa_dev_ptr) {
784 fsa_dev_ptr += scmd_id(scsicmd);
785 if ((fsa_dev_ptr->valid & 1) == 0) {
786 fsa_dev_ptr->valid = 0;
787 return (*callback)(scsicmd);
788 }
789 }
790 }
791 return status;
792}
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794/**
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800795 * aac_probe_container - query a logical volume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 * @dev: device to query
797 * @cid: container identifier
798 *
799 * Queries the controller about the given volume. The volume information
800 * is updated in the struct fsa_dev_info structure rather than returned.
801 */
Mark Haverkampfe76df42007-03-15 12:55:07 -0700802static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
803{
804 scsicmd->device = NULL;
805 return 0;
806}
807
Mark Haverkampbfb35aa82006-02-01 09:30:55 -0800808int aac_probe_container(struct aac_dev *dev, int cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
Mark Haverkampfe76df42007-03-15 12:55:07 -0700810 struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
811 struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Mark Haverkampfe76df42007-03-15 12:55:07 -0700814 if (!scsicmd || !scsidev) {
815 kfree(scsicmd);
816 kfree(scsidev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -0700817 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 }
Mark Haverkampfe76df42007-03-15 12:55:07 -0700819 scsicmd->list.next = NULL;
Salyzyn, Mark1a655042007-06-11 16:17:55 -0400820 scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Mark Haverkampfe76df42007-03-15 12:55:07 -0700822 scsicmd->device = scsidev;
823 scsidev->sdev_state = 0;
824 scsidev->id = cid;
825 scsidev->host = dev->scsi_host_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Mark Haverkampfe76df42007-03-15 12:55:07 -0700827 if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
828 while (scsicmd->device == scsidev)
829 schedule();
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400830 kfree(scsidev);
Mark Haverkampfe76df42007-03-15 12:55:07 -0700831 status = scsicmd->SCp.Status;
832 kfree(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 return status;
834}
835
836/* Local Structure to set SCSI inquiry data strings */
837struct scsi_inq {
838 char vid[8]; /* Vendor ID */
839 char pid[16]; /* Product ID */
840 char prl[4]; /* Product Revision Level */
841};
842
843/**
844 * InqStrCopy - string merge
845 * @a: string to copy from
846 * @b: string to copy to
847 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800848 * Copy a String from one location to another
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 * without copying \0
850 */
851
852static void inqstrcpy(char *a, char *b)
853{
854
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800855 while (*a != (char)0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 *b++ = *a++;
857}
858
859static char *container_types[] = {
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800860 "None",
861 "Volume",
862 "Mirror",
863 "Stripe",
864 "RAID5",
865 "SSRW",
866 "SSRO",
867 "Morph",
868 "Legacy",
869 "RAID4",
870 "RAID10",
871 "RAID00",
872 "V-MIRRORS",
873 "PSEUDO R4",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 "RAID50",
Mark Haverkamp84971732005-06-20 11:55:24 -0700875 "RAID5D",
876 "RAID5D0",
877 "RAID1E",
878 "RAID6",
879 "RAID60",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800880 "Unknown"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881};
882
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800883char * get_container_type(unsigned tindex)
884{
885 if (tindex >= ARRAY_SIZE(container_types))
886 tindex = ARRAY_SIZE(container_types) - 1;
887 return container_types[tindex];
888}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890/* Function: setinqstr
891 *
892 * Arguments: [1] pointer to void [1] int
893 *
894 * Purpose: Sets SCSI inquiry data strings for vendor, product
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300895 * and revision level. Allows strings to be set in platform dependent
896 * files instead of in OS dependent driver source.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 */
898
Mark Haverkamp794d0602005-10-24 10:51:53 -0700899static void setinqstr(struct aac_dev *dev, void *data, int tindex)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
901 struct scsi_inq *str;
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800902 struct aac_supplement_adapter_info *sup_adap_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800904 sup_adap_info = &dev->supplement_adapter_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
Mark Haverkamp794d0602005-10-24 10:51:53 -0700906 memset(str, ' ', sizeof(*str));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800908 if (sup_adap_info->adapter_type_text[0]) {
909 char *cp = sup_adap_info->adapter_type_text;
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800910 int c;
911 if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
912 inqstrcpy("SMC", str->vid);
913 else {
914 c = sizeof(str->vid);
915 while (*cp && *cp != ' ' && --c)
916 ++cp;
917 c = *cp;
918 *cp = '\0';
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -0800919 inqstrcpy(sup_adap_info->adapter_type_text, str->vid);
Salyzyn, Mark3bc80702008-01-11 13:46:24 -0800920 *cp = c;
921 while (*cp && *cp != ' ')
922 ++cp;
923 }
Mark Haverkamp794d0602005-10-24 10:51:53 -0700924 while (*cp == ' ')
925 ++cp;
926 /* last six chars reserved for vol type */
927 c = 0;
928 if (strlen(cp) > sizeof(str->pid)) {
929 c = cp[sizeof(str->pid)];
930 cp[sizeof(str->pid)] = '\0';
931 }
932 inqstrcpy (cp, str->pid);
933 if (c)
934 cp[sizeof(str->pid)] = c;
935 } else {
936 struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
Tobias Klauser6391a112006-06-08 22:23:48 -0700937
938 inqstrcpy (mp->vname, str->vid);
Mark Haverkamp794d0602005-10-24 10:51:53 -0700939 /* last six chars reserved for vol type */
940 inqstrcpy (mp->model, str->pid);
941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Tobias Klauser6391a112006-06-08 22:23:48 -0700943 if (tindex < ARRAY_SIZE(container_types)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 char *findit = str->pid;
945
946 for ( ; *findit != ' '; findit++); /* walk till we find a space */
947 /* RAID is superfluous in the context of a RAID device */
948 if (memcmp(findit-4, "RAID", 4) == 0)
949 *(findit -= 4) = ' ';
Mark Haverkamp794d0602005-10-24 10:51:53 -0700950 if (((findit - str->pid) + strlen(container_types[tindex]))
951 < (sizeof(str->pid) + sizeof(str->prl)))
952 inqstrcpy (container_types[tindex], findit + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 }
954 inqstrcpy ("V1.0", str->prl);
955}
956
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800957static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
958 struct aac_dev *dev, struct scsi_cmnd *scsicmd)
959{
960 int container;
961
962 vpdpage83data->type3.codeset = 1;
963 vpdpage83data->type3.identifiertype = 3;
964 vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
965 - 4;
966
967 for (container = 0; container < dev->maximum_num_containers;
968 container++) {
969
970 if (scmd_id(scsicmd) == container) {
971 memcpy(vpdpage83data->type3.Identifier,
972 dev->fsa_dev[container].identifier,
973 16);
974 break;
975 }
976 }
977}
978
Salyzyn, Mark88e2f982007-07-17 14:01:28 -0400979static void get_container_serial_callback(void *context, struct fib * fibptr)
980{
981 struct aac_get_serial_resp * get_serial_reply;
982 struct scsi_cmnd * scsicmd;
983
984 BUG_ON(fibptr == NULL);
985
986 scsicmd = (struct scsi_cmnd *) context;
987 if (!aac_valid_context(scsicmd, fibptr))
988 return;
989
990 get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
991 /* Failure is irrelevant, using default value instead */
992 if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400993 /*Check to see if it's for VPD 0x83 or 0x80 */
994 if (scsicmd->cmnd[2] == 0x83) {
995 /* vpd page 0x83 - Device Identification Page */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800996 struct aac_dev *dev;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400997 int i;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -0800998 struct tvpd_page83 vpdpage83data;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -0400999
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001000 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1001
1002 memset(((u8 *)&vpdpage83data), 0,
1003 sizeof(vpdpage83data));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001004
1005 /* DIRECT_ACCESS_DEVIC */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001006 vpdpage83data.DeviceType = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001007 /* DEVICE_CONNECTED */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001008 vpdpage83data.DeviceTypeQualifier = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001009 /* VPD_DEVICE_IDENTIFIERS */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001010 vpdpage83data.PageCode = 0x83;
1011 vpdpage83data.reserved = 0;
1012 vpdpage83data.PageLength =
1013 sizeof(vpdpage83data.type1) +
1014 sizeof(vpdpage83data.type2);
1015
1016 /* VPD 83 Type 3 is not supported for ARC */
1017 if (dev->sa_firmware)
1018 vpdpage83data.PageLength +=
1019 sizeof(vpdpage83data.type3);
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001020
1021 /* T10 Vendor Identifier Field Format */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001022 /* VpdcodesetAscii */
1023 vpdpage83data.type1.codeset = 2;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001024 /* VpdIdentifierTypeVendorId */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001025 vpdpage83data.type1.identifiertype = 1;
1026 vpdpage83data.type1.identifierlength =
1027 sizeof(vpdpage83data.type1) - 4;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001028
1029 /* "ADAPTEC " for adaptec */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001030 memcpy(vpdpage83data.type1.venid,
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001031 "ADAPTEC ",
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001032 sizeof(vpdpage83data.type1.venid));
1033 memcpy(vpdpage83data.type1.productid,
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001034 "ARRAY ",
1035 sizeof(
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001036 vpdpage83data.type1.productid));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001037
1038 /* Convert to ascii based serial number.
1039 * The LSB is the the end.
1040 */
1041 for (i = 0; i < 8; i++) {
1042 u8 temp =
1043 (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
1044 if (temp > 0x9) {
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001045 vpdpage83data.type1.serialnumber[i] =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001046 'A' + (temp - 0xA);
1047 } else {
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001048 vpdpage83data.type1.serialnumber[i] =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001049 '0' + temp;
1050 }
1051 }
1052
1053 /* VpdCodeSetBinary */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001054 vpdpage83data.type2.codeset = 1;
1055 /* VpdidentifiertypeEUI64 */
1056 vpdpage83data.type2.identifiertype = 2;
1057 vpdpage83data.type2.identifierlength =
1058 sizeof(vpdpage83data.type2) - 4;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001059
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001060 vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1061 vpdpage83data.type2.eu64id.venid[1] = 0;
1062 vpdpage83data.type2.eu64id.venid[2] = 0;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001063
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001064 vpdpage83data.type2.eu64id.Serial =
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001065 get_serial_reply->uid;
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001066 vpdpage83data.type2.eu64id.reserved = 0;
1067
1068 /*
1069 * VpdIdentifierTypeFCPHName
1070 * VPD 0x83 Type 3 not supported for ARC
1071 */
1072 if (dev->sa_firmware) {
1073 build_vpd83_type3(&vpdpage83data,
1074 dev, scsicmd);
1075 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001076
1077 /* Move the inquiry data to the response buffer. */
Raghava Aditya Renukunta999b3ff2017-02-02 15:53:32 -08001078 scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1079 sizeof(vpdpage83data));
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04001080 } else {
1081 /* It must be for VPD 0x80 */
1082 char sp[13];
1083 /* EVPD bit set */
1084 sp[0] = INQD_PDT_DA;
1085 sp[1] = scsicmd->cmnd[2];
1086 sp[2] = 0;
1087 sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1088 le32_to_cpu(get_serial_reply->uid));
1089 scsi_sg_copy_from_buffer(scsicmd, sp,
1090 sizeof(sp));
1091 }
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001092 }
1093
1094 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1095
1096 aac_fib_complete(fibptr);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001097 scsicmd->scsi_done(scsicmd);
1098}
1099
1100/**
1101 * aac_get_container_serial - get container serial, none blocking.
1102 */
1103static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1104{
1105 int status;
1106 struct aac_get_serial *dinfo;
1107 struct fib * cmd_fibcontext;
1108 struct aac_dev * dev;
1109
1110 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1111
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08001112 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001113
1114 aac_fib_init(cmd_fibcontext);
1115 dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1116
1117 dinfo->command = cpu_to_le32(VM_ContainerConfig);
1118 dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1119 dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1120
1121 status = aac_fib_send(ContainerCommand,
1122 cmd_fibcontext,
Mahesh Rajashekharafb5d40d2015-08-28 06:38:33 -04001123 sizeof(struct aac_get_serial_resp),
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04001124 FsaNormal,
1125 0, 1,
1126 (fib_callback) get_container_serial_callback,
1127 (void *) scsicmd);
1128
1129 /*
1130 * Check that the command queued to the controller
1131 */
1132 if (status == -EINPROGRESS) {
1133 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1134 return 0;
1135 }
1136
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"));
1194 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1195 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08001196 set_sense(&dev->fsa_dev[cid].sense_data,
1197 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1198 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001199 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08001200 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1201 SCSI_SENSE_BUFFERSIZE));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001202 cmd->scsi_done(cmd);
1203 return 1;
1204 }
1205 return 0;
1206}
1207
1208static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1209{
1210 return 0;
1211}
1212
1213static void io_callback(void *context, struct fib * fibptr);
1214
1215static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1216{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301217 struct aac_dev *dev = fib->dev;
1218 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301219 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001220
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301221 aac_fib_init(fib);
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -08001222 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1223 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1224 !dev->sync_mode) {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301225 struct aac_raw_io2 *readcmd2;
1226 readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1227 memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1228 readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1229 readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001230 readcmd2->byteCount = cpu_to_le32(count *
1231 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301232 readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1233 readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301234 ret = aac_build_sgraw2(cmd, readcmd2,
1235 dev->scsi_host_ptr->sg_tablesize);
1236 if (ret < 0)
1237 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301238 command = ContainerRawIo2;
1239 fibsize = sizeof(struct aac_raw_io2) +
1240 ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1241 } else {
1242 struct aac_raw_io *readcmd;
1243 readcmd = (struct aac_raw_io *) fib_data(fib);
1244 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1245 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001246 readcmd->count = cpu_to_le32(count *
1247 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301248 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1249 readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1250 readcmd->bpTotal = 0;
1251 readcmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301252 ret = aac_build_sgraw(cmd, &readcmd->sg);
1253 if (ret < 0)
1254 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301255 command = ContainerRawIo;
1256 fibsize = sizeof(struct aac_raw_io) +
1257 ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1258 }
1259
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001260 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1261 /*
1262 * Now send the Fib to the adapter
1263 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301264 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001265 fib,
1266 fibsize,
1267 FsaNormal,
1268 0, 1,
1269 (fib_callback) io_callback,
1270 (void *) cmd);
1271}
1272
1273static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1274{
1275 u16 fibsize;
1276 struct aac_read64 *readcmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301277 long ret;
1278
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001279 aac_fib_init(fib);
1280 readcmd = (struct aac_read64 *) fib_data(fib);
1281 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1282 readcmd->cid = cpu_to_le16(scmd_id(cmd));
1283 readcmd->sector_count = cpu_to_le16(count);
1284 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1285 readcmd->pad = 0;
1286 readcmd->flags = 0;
1287
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301288 ret = aac_build_sg64(cmd, &readcmd->sg);
1289 if (ret < 0)
1290 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001291 fibsize = sizeof(struct aac_read64) +
1292 ((le32_to_cpu(readcmd->sg.count) - 1) *
1293 sizeof (struct sgentry64));
1294 BUG_ON (fibsize > (fib->dev->max_fib_size -
1295 sizeof(struct aac_fibhdr)));
1296 /*
1297 * Now send the Fib to the adapter
1298 */
1299 return aac_fib_send(ContainerCommand64,
1300 fib,
1301 fibsize,
1302 FsaNormal,
1303 0, 1,
1304 (fib_callback) io_callback,
1305 (void *) cmd);
1306}
1307
1308static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1309{
1310 u16 fibsize;
1311 struct aac_read *readcmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001312 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301313 long ret;
1314
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001315 aac_fib_init(fib);
1316 readcmd = (struct aac_read *) fib_data(fib);
1317 readcmd->command = cpu_to_le32(VM_CtBlockRead);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001318 readcmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001319 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001320 readcmd->count = cpu_to_le32(count *
1321 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001322
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301323 ret = aac_build_sg(cmd, &readcmd->sg);
1324 if (ret < 0)
1325 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001326 fibsize = sizeof(struct aac_read) +
1327 ((le32_to_cpu(readcmd->sg.count) - 1) *
1328 sizeof (struct sgentry));
1329 BUG_ON (fibsize > (fib->dev->max_fib_size -
1330 sizeof(struct aac_fibhdr)));
1331 /*
1332 * Now send the Fib to the adapter
1333 */
1334 return aac_fib_send(ContainerCommand,
1335 fib,
1336 fibsize,
1337 FsaNormal,
1338 0, 1,
1339 (fib_callback) io_callback,
1340 (void *) cmd);
1341}
1342
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001343static 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 -08001344{
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301345 struct aac_dev *dev = fib->dev;
1346 u16 fibsize, command;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301347 long ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001348
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301349 aac_fib_init(fib);
Raghava Aditya Renukuntad1ef4da2017-02-02 15:53:17 -08001350 if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1351 dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1352 !dev->sync_mode) {
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301353 struct aac_raw_io2 *writecmd2;
1354 writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1355 memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1356 writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1357 writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001358 writecmd2->byteCount = cpu_to_le32(count *
1359 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301360 writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1361 writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1362 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1363 cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1364 cpu_to_le16(RIO2_IO_TYPE_WRITE);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301365 ret = aac_build_sgraw2(cmd, writecmd2,
1366 dev->scsi_host_ptr->sg_tablesize);
1367 if (ret < 0)
1368 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301369 command = ContainerRawIo2;
1370 fibsize = sizeof(struct aac_raw_io2) +
1371 ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1372 } else {
1373 struct aac_raw_io *writecmd;
1374 writecmd = (struct aac_raw_io *) fib_data(fib);
1375 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1376 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001377 writecmd->count = cpu_to_le32(count *
1378 dev->fsa_dev[scmd_id(cmd)].block_size);
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301379 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1380 writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1381 (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1382 cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1383 cpu_to_le16(RIO_TYPE_WRITE);
1384 writecmd->bpTotal = 0;
1385 writecmd->bpComplete = 0;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301386 ret = aac_build_sgraw(cmd, &writecmd->sg);
1387 if (ret < 0)
1388 return ret;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301389 command = ContainerRawIo;
1390 fibsize = sizeof(struct aac_raw_io) +
1391 ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1392 }
1393
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001394 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1395 /*
1396 * Now send the Fib to the adapter
1397 */
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301398 return aac_fib_send(command,
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001399 fib,
1400 fibsize,
1401 FsaNormal,
1402 0, 1,
1403 (fib_callback) io_callback,
1404 (void *) cmd);
1405}
1406
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001407static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001408{
1409 u16 fibsize;
1410 struct aac_write64 *writecmd;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301411 long ret;
1412
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001413 aac_fib_init(fib);
1414 writecmd = (struct aac_write64 *) fib_data(fib);
1415 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1416 writecmd->cid = cpu_to_le16(scmd_id(cmd));
1417 writecmd->sector_count = cpu_to_le16(count);
1418 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1419 writecmd->pad = 0;
1420 writecmd->flags = 0;
1421
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301422 ret = aac_build_sg64(cmd, &writecmd->sg);
1423 if (ret < 0)
1424 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001425 fibsize = sizeof(struct aac_write64) +
1426 ((le32_to_cpu(writecmd->sg.count) - 1) *
1427 sizeof (struct sgentry64));
1428 BUG_ON (fibsize > (fib->dev->max_fib_size -
1429 sizeof(struct aac_fibhdr)));
1430 /*
1431 * Now send the Fib to the adapter
1432 */
1433 return aac_fib_send(ContainerCommand64,
1434 fib,
1435 fibsize,
1436 FsaNormal,
1437 0, 1,
1438 (fib_callback) io_callback,
1439 (void *) cmd);
1440}
1441
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04001442static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001443{
1444 u16 fibsize;
1445 struct aac_write *writecmd;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001446 struct aac_dev *dev = fib->dev;
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301447 long ret;
1448
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001449 aac_fib_init(fib);
1450 writecmd = (struct aac_write *) fib_data(fib);
1451 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
Christoph Hellwigf3307f72007-11-08 17:27:47 +00001452 writecmd->cid = cpu_to_le32(scmd_id(cmd));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001453 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04001454 writecmd->count = cpu_to_le32(count *
1455 dev->fsa_dev[scmd_id(cmd)].block_size);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001456 writecmd->sg.count = cpu_to_le32(1);
1457 /* ->stable is not used - it did mean which type of write */
1458
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05301459 ret = aac_build_sg(cmd, &writecmd->sg);
1460 if (ret < 0)
1461 return ret;
Mark Haverkampe8f32de2007-01-23 15:00:30 -08001462 fibsize = sizeof(struct aac_write) +
1463 ((le32_to_cpu(writecmd->sg.count) - 1) *
1464 sizeof (struct sgentry));
1465 BUG_ON (fibsize > (fib->dev->max_fib_size -
1466 sizeof(struct aac_fibhdr)));
1467 /*
1468 * Now send the Fib to the adapter
1469 */
1470 return aac_fib_send(ContainerCommand,
1471 fib,
1472 fibsize,
1473 FsaNormal,
1474 0, 1,
1475 (fib_callback) io_callback,
1476 (void *) cmd);
1477}
1478
1479static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1480{
1481 struct aac_srb * srbcmd;
1482 u32 flag;
1483 u32 timeout;
1484
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)
1510 timeout = 1;
1511 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 Renukunta71a91ca2017-02-02 15:53:26 -08001657int aac_issue_bmic_identify(struct aac_dev *dev, u32 bus, u32 target)
1658{
1659 struct fib *fibptr;
1660 struct aac_srb *srbcmd;
1661 struct sgmap64 *sg64;
1662 struct aac_ciss_identify_pd *identify_resp;
1663 dma_addr_t addr;
1664 u32 vbus, vid;
1665 u16 fibsize, datasize;
1666 int rcode = -ENOMEM;
1667
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08001668
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001669 fibptr = aac_fib_alloc(dev);
1670 if (!fibptr)
1671 goto out;
1672
1673 fibsize = sizeof(struct aac_srb) -
1674 sizeof(struct sgentry) + sizeof(struct sgentry64);
1675 datasize = sizeof(struct aac_ciss_identify_pd);
1676
1677 identify_resp = pci_alloc_consistent(dev->pdev, datasize, &addr);
1678
1679 if (!identify_resp)
1680 goto fib_free_ptr;
1681
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08001682 vbus = (u32)le16_to_cpu(dev->supplement_adapter_info.virt_device_bus);
1683 vid = (u32)le16_to_cpu(dev->supplement_adapter_info.virt_device_target);
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001684
1685 aac_fib_init(fibptr);
1686
1687 srbcmd = (struct aac_srb *) fib_data(fibptr);
1688 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1689 srbcmd->channel = cpu_to_le32(vbus);
1690 srbcmd->id = cpu_to_le32(vid);
1691 srbcmd->lun = 0;
1692 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1693 srbcmd->timeout = cpu_to_le32(10);
1694 srbcmd->retry_limit = 0;
1695 srbcmd->cdb_size = cpu_to_le32(12);
1696 srbcmd->count = cpu_to_le32(datasize);
1697
1698 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1699 srbcmd->cdb[0] = 0x26;
1700 srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
1701 srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
1702
1703 sg64 = (struct sgmap64 *)&srbcmd->sg;
1704 sg64->count = cpu_to_le32(1);
1705 sg64->sg[0].addr[1] = cpu_to_le32((u32)(((addr) >> 16) >> 16));
1706 sg64->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
1707 sg64->sg[0].count = cpu_to_le32(datasize);
1708
1709 rcode = aac_fib_send(ScsiPortCommand64,
1710 fibptr, fibsize, FsaNormal, 1, 1, NULL, NULL);
1711
1712 if (identify_resp->current_queue_depth_limit <= 0 ||
1713 identify_resp->current_queue_depth_limit > 32)
1714 dev->hba_map[bus][target].qd_limit = 32;
1715 else
1716 dev->hba_map[bus][target].qd_limit =
1717 identify_resp->current_queue_depth_limit;
1718
1719 pci_free_consistent(dev->pdev, datasize, (void *)identify_resp, addr);
1720
1721 aac_fib_complete(fibptr);
1722
1723fib_free_ptr:
1724 aac_fib_free(fibptr);
1725out:
1726 return rcode;
1727}
1728
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001729/**
1730 * aac_update hba_map()- update current hba map with data from FW
1731 * @dev: aac_dev structure
1732 * @phys_luns: FW information from report phys luns
1733 *
1734 * Update our hba map with the information gathered from the FW
1735 */
1736void aac_update_hba_map(struct aac_dev *dev,
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001737 struct aac_ciss_phys_luns_resp *phys_luns, int rescan)
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001738{
1739 /* ok and extended reporting */
1740 u32 lun_count, nexus;
1741 u32 i, bus, target;
1742 u8 expose_flag, attribs;
1743 u8 devtype;
1744
1745 lun_count = ((phys_luns->list_length[0] << 24)
1746 + (phys_luns->list_length[1] << 16)
1747 + (phys_luns->list_length[2] << 8)
1748 + (phys_luns->list_length[3])) / 24;
1749
1750 for (i = 0; i < lun_count; ++i) {
1751
1752 bus = phys_luns->lun[i].level2[1] & 0x3f;
1753 target = phys_luns->lun[i].level2[0];
1754 expose_flag = phys_luns->lun[i].bus >> 6;
1755 attribs = phys_luns->lun[i].node_ident[9];
1756 nexus = *((u32 *) &phys_luns->lun[i].node_ident[12]);
1757
1758 if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
1759 continue;
1760
1761 dev->hba_map[bus][target].expose = expose_flag;
1762
1763 if (expose_flag != 0) {
1764 devtype = AAC_DEVTYPE_RAID_MEMBER;
1765 goto update_devtype;
1766 }
1767
1768 if (nexus != 0 && (attribs & 8)) {
1769 devtype = AAC_DEVTYPE_NATIVE_RAW;
1770 dev->hba_map[bus][target].rmw_nexus =
1771 nexus;
1772 } else
1773 devtype = AAC_DEVTYPE_ARC_RAW;
1774
1775 if (devtype != AAC_DEVTYPE_NATIVE_RAW)
1776 goto update_devtype;
1777
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001778 if (aac_issue_bmic_identify(dev, bus, target) < 0)
1779 dev->hba_map[bus][target].qd_limit = 32;
1780
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001781update_devtype:
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001782 if (rescan == AAC_INIT)
1783 dev->hba_map[bus][target].devtype = devtype;
1784 else
1785 dev->hba_map[bus][target].new_devtype = devtype;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001786 }
1787}
1788
1789/**
1790 * aac_report_phys_luns() Process topology change
1791 * @dev: aac_dev structure
1792 * @fibptr: fib pointer
1793 *
1794 * Execute a CISS REPORT PHYS LUNS and process the results into
1795 * the current hba_map.
1796 */
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001797int aac_report_phys_luns(struct aac_dev *dev, struct fib *fibptr, int rescan)
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001798{
1799 int fibsize, datasize;
1800 struct aac_ciss_phys_luns_resp *phys_luns;
1801 struct aac_srb *srbcmd;
1802 struct sgmap64 *sg64;
1803 dma_addr_t addr;
1804 u32 vbus, vid;
Colin Ian King76291462017-02-07 11:51:29 +00001805 int rcode = 0;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001806
1807 /* Thor SA Firmware -> CISS_REPORT_PHYSICAL_LUNS */
1808 fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry)
1809 + sizeof(struct sgentry64);
1810 datasize = sizeof(struct aac_ciss_phys_luns_resp)
1811 + (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
1812
1813 phys_luns = (struct aac_ciss_phys_luns_resp *) pci_alloc_consistent(
1814 dev->pdev, datasize, &addr);
1815
1816 if (phys_luns == NULL) {
1817 rcode = -ENOMEM;
1818 goto err_out;
1819 }
1820
1821 vbus = (u32) le16_to_cpu(
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08001822 dev->supplement_adapter_info.virt_device_bus);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001823 vid = (u32) le16_to_cpu(
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08001824 dev->supplement_adapter_info.virt_device_target);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001825
1826 aac_fib_init(fibptr);
1827
1828 srbcmd = (struct aac_srb *) fib_data(fibptr);
1829 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1830 srbcmd->channel = cpu_to_le32(vbus);
1831 srbcmd->id = cpu_to_le32(vid);
1832 srbcmd->lun = 0;
1833 srbcmd->flags = cpu_to_le32(SRB_DataIn);
1834 srbcmd->timeout = cpu_to_le32(10);
1835 srbcmd->retry_limit = 0;
1836 srbcmd->cdb_size = cpu_to_le32(12);
1837 srbcmd->count = cpu_to_le32(datasize);
1838
1839 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1840 srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
1841 srbcmd->cdb[1] = 2; /* extended reporting */
1842 srbcmd->cdb[8] = (u8)(datasize >> 8);
1843 srbcmd->cdb[9] = (u8)(datasize);
1844
1845 sg64 = (struct sgmap64 *) &srbcmd->sg;
1846 sg64->count = cpu_to_le32(1);
1847 sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
1848 sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
1849 sg64->sg[0].count = cpu_to_le32(datasize);
1850
1851 rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize,
1852 FsaNormal, 1, 1, NULL, NULL);
1853
1854 /* analyse data */
1855 if (rcode >= 0 && phys_luns->resp_flag == 2) {
1856 /* ok and extended reporting */
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001857 aac_update_hba_map(dev, phys_luns, rescan);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001858 }
1859
1860 pci_free_consistent(dev->pdev, datasize, (void *) phys_luns, addr);
1861err_out:
1862 return rcode;
1863}
1864
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865int aac_get_adapter_info(struct aac_dev* dev)
1866{
1867 struct fib* fibptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 int rcode;
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001869 u32 tmp, bus, target;
Mark Haverkamp84971732005-06-20 11:55:24 -07001870 struct aac_adapter_info *info;
1871 struct aac_bus_info *command;
1872 struct aac_bus_info_response *bus_info;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001873
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001874 if (!(fibptr = aac_fib_alloc(dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 return -ENOMEM;
1876
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001877 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001878 info = (struct aac_adapter_info *) fib_data(fibptr);
1879 memset(info,0,sizeof(*info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001881 rcode = aac_fib_send(RequestAdapterInfo,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001882 fibptr,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001883 sizeof(*info),
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001884 FsaNormal,
Mark Haverkamp92033442005-09-20 12:56:50 -07001885 -1, 1, /* First `interrupt' command uses special wait */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001886 NULL,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001887 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001889 if (rcode < 0) {
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301890 /* FIB should be freed only after
1891 * getting the response from the F/W */
1892 if (rcode != -ERESTARTSYS) {
1893 aac_fib_complete(fibptr);
1894 aac_fib_free(fibptr);
1895 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001896 return rcode;
1897 }
1898 memcpy(&dev->adapter_info, info, sizeof(*info));
1899
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08001900 dev->supplement_adapter_info.virt_device_bus = 0xffff;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001901 if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001902 struct aac_supplement_adapter_info * sinfo;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001903
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001904 aac_fib_init(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001905
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001906 sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001907
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001908 memset(sinfo,0,sizeof(*sinfo));
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001909
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001910 rcode = aac_fib_send(RequestSupplementAdapterInfo,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001911 fibptr,
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001912 sizeof(*sinfo),
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001913 FsaNormal,
1914 1, 1,
1915 NULL,
1916 NULL);
1917
1918 if (rcode >= 0)
Salyzyn, Mark06a43d12008-01-08 12:32:00 -08001919 memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05301920 if (rcode == -ERESTARTSYS) {
1921 fibptr = aac_fib_alloc(dev);
1922 if (!fibptr)
1923 return -ENOMEM;
1924 }
1925
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001928 /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
1929 for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001930 for (target = 0; target < AAC_MAX_TARGETS; target++) {
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001931 dev->hba_map[bus][target].devtype = 0;
Raghava Aditya Renukunta71a91ca2017-02-02 15:53:26 -08001932 dev->hba_map[bus][target].qd_limit = 0;
1933 }
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001934 }
Mark Haverkamp84971732005-06-20 11:55:24 -07001935
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001936 /*
1937 * GetBusInfo
Mark Haverkamp84971732005-06-20 11:55:24 -07001938 */
1939
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001940 aac_fib_init(fibptr);
Mark Haverkamp84971732005-06-20 11:55:24 -07001941
1942 bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
1943
1944 memset(bus_info, 0, sizeof(*bus_info));
1945
1946 command = (struct aac_bus_info *)bus_info;
1947
1948 command->Command = cpu_to_le32(VM_Ioctl);
1949 command->ObjType = cpu_to_le32(FT_DRIVE);
1950 command->MethodId = cpu_to_le32(1);
1951 command->CtlCmd = cpu_to_le32(GetBusInfo);
1952
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001953 rcode = aac_fib_send(ContainerCommand,
Mark Haverkamp84971732005-06-20 11:55:24 -07001954 fibptr,
1955 sizeof (*bus_info),
1956 FsaNormal,
1957 1, 1,
1958 NULL, NULL);
1959
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08001960 /* reasoned default */
1961 dev->maximum_num_physicals = 16;
Mark Haverkamp84971732005-06-20 11:55:24 -07001962 if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
1963 dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
1964 dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
1965 }
1966
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001967 if (!dev->sync_mode && dev->sa_firmware &&
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08001968 dev->supplement_adapter_info.virt_device_bus != 0xffff) {
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001969 /* Thor SA Firmware -> CISS_REPORT_PHYSICAL_LUNS */
Raghava Aditya Renukunta6223a392017-02-02 15:53:28 -08001970 rcode = aac_report_phys_luns(dev, fibptr, AAC_INIT);
Raghava Aditya Renukuntac83b11e2017-02-02 15:53:19 -08001971 }
1972
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001973 if (!dev->in_reset) {
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001974 char buffer[16];
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001975 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
1976 printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001977 dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 dev->id,
1979 tmp>>24,
1980 (tmp>>16)&0xff,
1981 tmp&0xff,
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001982 le32_to_cpu(dev->adapter_info.kernelbuild),
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08001983 (int)sizeof(dev->supplement_adapter_info.build_date),
1984 dev->supplement_adapter_info.build_date);
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001985 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
1986 printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 dev->name, dev->id,
1988 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1989 le32_to_cpu(dev->adapter_info.monitorbuild));
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001990 tmp = le32_to_cpu(dev->adapter_info.biosrev);
1991 printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 dev->name, dev->id,
1993 tmp>>24,(tmp>>16)&0xff,tmp&0xff,
1994 le32_to_cpu(dev->adapter_info.biosbuild));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001995 buffer[0] = '\0';
Tony Jonesee959b02008-02-22 00:13:36 +01001996 if (aac_get_serial_number(
Salyzyn, Mark24f02e12007-06-19 16:29:24 -04001997 shost_to_class(dev->scsi_host_ptr), buffer))
1998 printk(KERN_INFO "%s%d: serial %s",
1999 dev->name, dev->id, buffer);
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002000 if (dev->supplement_adapter_info.vpd_info.tsid[0]) {
Salyzyn, Marka45c8632007-03-28 13:44:54 -04002001 printk(KERN_INFO "%s%d: TSID %.*s\n",
2002 dev->name, dev->id,
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002003 (int)sizeof(dev->supplement_adapter_info
2004 .vpd_info.tsid),
2005 dev->supplement_adapter_info.vpd_info.tsid);
Salyzyn, Marka45c8632007-03-28 13:44:54 -04002006 }
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002007 if (!aac_check_reset || ((aac_check_reset == 1) &&
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002008 (dev->supplement_adapter_info.supported_options2 &
Salyzyn, Marka3940da2008-01-08 12:48:25 -08002009 AAC_OPTION_IGNORE_RESET))) {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04002010 printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
2011 dev->name, dev->id);
2012 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002015 dev->cache_protected = 0;
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002016 dev->jbod = ((dev->supplement_adapter_info.feature_bits &
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08002017 AAC_FEATURE_JBOD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 dev->nondasd_support = 0;
2019 dev->raid_scsi_mode = 0;
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002020 if(dev->adapter_info.options & AAC_OPT_NONDASD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 dev->nondasd_support = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
2023 /*
2024 * If the firmware supports ROMB RAID/SCSI mode and we are currently
2025 * in RAID/SCSI mode, set the flag. For now if in this mode we will
2026 * force nondasd support on. If we decide to allow the non-dasd flag
2027 * additional changes changes will have to be made to support
2028 * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
2029 * changed to support the new dev->raid_scsi_mode flag instead of
2030 * leaching off of the dev->nondasd_support flag. Also in linit.c the
2031 * function aac_detect will have to be modified where it sets up the
2032 * max number of channels based on the aac->nondasd_support flag only.
2033 */
2034 if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
2035 (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
2036 dev->nondasd_support = 1;
2037 dev->raid_scsi_mode = 1;
2038 }
2039 if (dev->raid_scsi_mode != 0)
2040 printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
2041 dev->name, dev->id);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002042
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002043 if (nondasd != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 dev->nondasd_support = (nondasd!=0);
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002045 if (dev->nondasd_support && !dev->in_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
Yang Hongyange9304382009-04-13 14:40:14 -07002048 if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
Leubner, Achimd8e965072009-04-01 07:16:08 -07002049 dev->needs_dac = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 dev->dac_support = 0;
Leubner, Achimd8e965072009-04-01 07:16:08 -07002051 if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
2052 (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002053 if (!dev->in_reset)
2054 printk(KERN_INFO "%s%d: 64bit support enabled.\n",
2055 dev->name, dev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 dev->dac_support = 1;
2057 }
2058
2059 if(dacmode != -1) {
2060 dev->dac_support = (dacmode!=0);
2061 }
Leubner, Achimd8e965072009-04-01 07:16:08 -07002062
2063 /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
2064 if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
2065 & AAC_QUIRK_SCSI_32)) {
2066 dev->nondasd_support = 0;
2067 dev->jbod = 0;
2068 expose_physicals = 0;
2069 }
2070
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 if(dev->dac_support != 0) {
Yang Hongyang6a355282009-04-06 19:01:13 -07002072 if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64)) &&
2073 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -08002074 if (!dev->in_reset)
2075 printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n",
2076 dev->name, dev->id);
Yang Hongyang284901a2009-04-06 19:01:15 -07002077 } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32)) &&
2078 !pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n",
2080 dev->name, dev->id);
2081 dev->dac_support = 0;
2082 } else {
2083 printk(KERN_WARNING"%s%d: No suitable DMA available.\n",
2084 dev->name, dev->id);
2085 rcode = -ENOMEM;
2086 }
2087 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002088 /*
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002089 * Deal with configuring for the individualized limits of each packet
2090 * interface.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002091 */
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002092 dev->a_ops.adapter_scsi = (dev->dac_support)
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -08002093 ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
2094 ? aac_scsi_32_64
2095 : aac_scsi_64)
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002096 : aac_scsi_32;
2097 if (dev->raw_io_interface) {
2098 dev->a_ops.adapter_bounds = (dev->raw_io_64)
2099 ? aac_bounds_64
2100 : aac_bounds_32;
2101 dev->a_ops.adapter_read = aac_read_raw_io;
2102 dev->a_ops.adapter_write = aac_write_raw_io;
2103 } else {
2104 dev->a_ops.adapter_bounds = aac_bounds_32;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002105 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002106 sizeof(struct aac_fibhdr) -
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07002107 sizeof(struct aac_write) + sizeof(struct sgentry)) /
2108 sizeof(struct sgentry);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002109 if (dev->dac_support) {
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002110 dev->a_ops.adapter_read = aac_read_block64;
2111 dev->a_ops.adapter_write = aac_write_block64;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002112 /*
2113 * 38 scatter gather elements
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002114 */
2115 dev->scsi_host_ptr->sg_tablesize =
2116 (dev->max_fib_size -
2117 sizeof(struct aac_fibhdr) -
2118 sizeof(struct aac_write64) +
Mark Haverkamp63a70ee2005-09-20 12:57:04 -07002119 sizeof(struct sgentry64)) /
2120 sizeof(struct sgentry64);
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002121 } else {
2122 dev->a_ops.adapter_read = aac_read_block;
2123 dev->a_ops.adapter_write = aac_write_block;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002124 }
2125 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07002126 if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07002127 /*
2128 * Worst case size that could cause sg overflow when
2129 * we break up SG elements that are larger than 64KB.
2130 * Would be nice if we could tell the SCSI layer what
2131 * the maximum SG element size can be. Worst case is
2132 * (sg_tablesize-1) 4KB elements with one 64KB
2133 * element.
2134 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
2135 */
2136 dev->scsi_host_ptr->max_sectors =
2137 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
2138 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002139 }
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002140 if (!dev->sync_mode && dev->sa_firmware &&
2141 dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
2142 dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
2143 HBA_MAX_SG_SEPARATE;
2144
Penchala Narasimha Reddy Chilakala, ERS-HCLTechcacb6dc2009-12-21 18:39:27 +05302145 /* FIB should be freed only after getting the response from the F/W */
2146 if (rcode != -ERESTARTSYS) {
2147 aac_fib_complete(fibptr);
2148 aac_fib_free(fibptr);
2149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
2151 return rcode;
2152}
2153
2154
Mark Haverkampe53cb352005-08-03 15:39:09 -07002155static void io_callback(void *context, struct fib * fibptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
2157 struct aac_dev *dev;
2158 struct aac_read_reply *readreply;
2159 struct scsi_cmnd *scsicmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 u32 cid;
2161
2162 scsicmd = (struct scsi_cmnd *) context;
2163
Mark Haverkamp03d44332007-03-15 10:27:45 -07002164 if (!aac_valid_context(scsicmd, fibptr))
2165 return;
2166
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002167 dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002168 cid = scmd_id(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002170 if (nblank(dprintk(x))) {
2171 u64 lba;
2172 switch (scsicmd->cmnd[0]) {
2173 case WRITE_6:
2174 case READ_6:
2175 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
2176 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2177 break;
2178 case WRITE_16:
2179 case READ_16:
2180 lba = ((u64)scsicmd->cmnd[2] << 56) |
2181 ((u64)scsicmd->cmnd[3] << 48) |
2182 ((u64)scsicmd->cmnd[4] << 40) |
2183 ((u64)scsicmd->cmnd[5] << 32) |
2184 ((u64)scsicmd->cmnd[6] << 24) |
2185 (scsicmd->cmnd[7] << 16) |
2186 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2187 break;
2188 case WRITE_12:
2189 case READ_12:
2190 lba = ((u64)scsicmd->cmnd[2] << 24) |
2191 (scsicmd->cmnd[3] << 16) |
2192 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2193 break;
2194 default:
2195 lba = ((u64)scsicmd->cmnd[2] << 24) |
2196 (scsicmd->cmnd[3] << 16) |
2197 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2198 break;
2199 }
2200 printk(KERN_DEBUG
2201 "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
2202 smp_processor_id(), (unsigned long long)lba, jiffies);
2203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
Eric Sesterhenn125e1872006-06-23 02:06:06 -07002205 BUG_ON(fibptr == NULL);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09002206
2207 scsi_dma_unmap(scsicmd);
2208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 readreply = (struct aac_read_reply *)fib_data(fibptr);
Mark Salyzyn655d7222008-04-30 16:03:42 -04002210 switch (le32_to_cpu(readreply->status)) {
2211 case ST_OK:
2212 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2213 SAM_STAT_GOOD;
2214 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
2215 break;
2216 case ST_NOT_READY:
2217 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2218 SAM_STAT_CHECK_CONDITION;
2219 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
2220 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
2221 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2222 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2223 SCSI_SENSE_BUFFERSIZE));
2224 break;
Raghava Aditya Renukuntaf956a662017-02-02 15:53:23 -08002225 case ST_MEDERR:
2226 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2227 SAM_STAT_CHECK_CONDITION;
2228 set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
2229 SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
2230 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2231 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2232 SCSI_SENSE_BUFFERSIZE));
2233 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04002234 default:
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002235#ifdef AAC_DETAILED_STATUS_INFO
Mark Haverkampe53cb352005-08-03 15:39:09 -07002236 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002237 le32_to_cpu(readreply->status));
2238#endif
Mark Salyzyn655d7222008-04-30 16:03:42 -04002239 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2240 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002241 set_sense(&dev->fsa_dev[cid].sense_data,
2242 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2243 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002245 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2246 SCSI_SENSE_BUFFERSIZE));
Mark Salyzyn655d7222008-04-30 16:03:42 -04002247 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 }
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002249 aac_fib_complete(fibptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002251 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252}
2253
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002254static int aac_read(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002256 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 u32 count;
2258 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 struct aac_dev *dev;
2260 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002261 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
2263 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2264 /*
2265 * Get block address and transfer length
2266 */
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002267 switch (scsicmd->cmnd[0]) {
2268 case READ_6:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002269 dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002271 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002272 (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 count = scsicmd->cmnd[4];
2274
2275 if (count == 0)
2276 count = 256;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002277 break;
2278 case READ_16:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002279 dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002280
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002281 lba = ((u64)scsicmd->cmnd[2] << 56) |
2282 ((u64)scsicmd->cmnd[3] << 48) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002283 ((u64)scsicmd->cmnd[4] << 40) |
2284 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002285 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002286 (scsicmd->cmnd[7] << 16) |
2287 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002288 count = (scsicmd->cmnd[10] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002289 (scsicmd->cmnd[11] << 16) |
2290 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
2291 break;
2292 case READ_12:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002293 dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002294
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002295 lba = ((u64)scsicmd->cmnd[2] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002296 (scsicmd->cmnd[3] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002297 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2298 count = (scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002299 (scsicmd->cmnd[7] << 16) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002300 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002301 break;
2302 default:
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002303 dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002305 lba = ((u64)scsicmd->cmnd[2] << 24) |
2306 (scsicmd->cmnd[3] << 16) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002307 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002309 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002311
2312 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2313 cid = scmd_id(scsicmd);
2314 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2315 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2316 SAM_STAT_CHECK_CONDITION;
2317 set_sense(&dev->fsa_dev[cid].sense_data,
2318 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2319 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2320 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2321 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2322 SCSI_SENSE_BUFFERSIZE));
2323 scsicmd->scsi_done(scsicmd);
2324 return 1;
2325 }
2326
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002327 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002328 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002329 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002330 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 /*
2332 * Alocate and initialize a Fib
2333 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002334 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002336 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
2338 /*
2339 * Check that the command queued to the controller
2340 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002341 if (status == -EINPROGRESS) {
2342 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002344 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002345
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002346 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 /*
2348 * For some reason, the Fib didn't queue, return QUEUE_FULL
2349 */
2350 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002351 scsicmd->scsi_done(scsicmd);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002352 aac_fib_complete(cmd_fibcontext);
2353 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 return 0;
2355}
2356
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002357static int aac_write(struct scsi_cmnd * scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002359 u64 lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 u32 count;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002361 int fua;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 struct aac_dev *dev;
2364 struct fib * cmd_fibcontext;
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002365 int cid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
2367 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2368 /*
2369 * Get block address and transfer length
2370 */
2371 if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
2372 {
2373 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
2374 count = scsicmd->cmnd[4];
2375 if (count == 0)
2376 count = 256;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002377 fua = 0;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002378 } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002379 dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002380
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002381 lba = ((u64)scsicmd->cmnd[2] << 56) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002382 ((u64)scsicmd->cmnd[3] << 48) |
2383 ((u64)scsicmd->cmnd[4] << 40) |
2384 ((u64)scsicmd->cmnd[5] << 32) |
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002385 ((u64)scsicmd->cmnd[6] << 24) |
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002386 (scsicmd->cmnd[7] << 16) |
2387 (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
2388 count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
2389 (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002390 fua = scsicmd->cmnd[1] & 0x8;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002391 } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002392 dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002393
2394 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
2395 | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2396 count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
2397 | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002398 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 } else {
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002400 dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002401 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002403 fua = scsicmd->cmnd[1] & 0x8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 }
Rajashekhara, Maheshda3cc672010-05-10 04:24:01 -07002405
2406 if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
2407 cid = scmd_id(scsicmd);
2408 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
2409 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2410 SAM_STAT_CHECK_CONDITION;
2411 set_sense(&dev->fsa_dev[cid].sense_data,
2412 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2413 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
2414 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
2415 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2416 SCSI_SENSE_BUFFERSIZE));
2417 scsicmd->scsi_done(scsicmd);
2418 return 1;
2419 }
2420
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002421 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 smp_processor_id(), (unsigned long long)lba, jiffies));
Mark Haverkampe8f32de2007-01-23 15:00:30 -08002423 if (aac_adapter_bounds(dev,scsicmd,lba))
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002424 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 /*
2426 * Allocate and initialize a Fib then setup a BlockWrite command
2427 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002428 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002430 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
2432 /*
2433 * Check that the command queued to the controller
2434 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002435 if (status == -EINPROGRESS) {
2436 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 return 0;
2438 }
2439
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002440 printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 /*
2442 * For some reason, the Fib didn't queue, return QUEUE_FULL
2443 */
2444 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002445 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002447 aac_fib_complete(cmd_fibcontext);
2448 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 return 0;
2450}
2451
2452static void synchronize_callback(void *context, struct fib *fibptr)
2453{
2454 struct aac_synchronize_reply *synchronizereply;
2455 struct scsi_cmnd *cmd;
2456
2457 cmd = context;
2458
Mark Haverkamp03d44332007-03-15 10:27:45 -07002459 if (!aac_valid_context(cmd, fibptr))
2460 return;
2461
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002462 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 smp_processor_id(), jiffies));
2464 BUG_ON(fibptr == NULL);
2465
2466
2467 synchronizereply = fib_data(fibptr);
2468 if (le32_to_cpu(synchronizereply->status) == CT_OK)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002469 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2471 else {
2472 struct scsi_device *sdev = cmd->device;
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002473 struct aac_dev *dev = fibptr->dev;
Mark Haverkampe5718772006-03-27 09:43:25 -08002474 u32 cid = sdev_id(sdev);
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002475 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 "synchronize_callback: synchronize failed, status = %d\n",
2477 le32_to_cpu(synchronizereply->status));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002478 cmd->result = DID_OK << 16 |
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002480 set_sense(&dev->fsa_dev[cid].sense_data,
2481 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
2482 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +09002484 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2485 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 }
2487
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002488 aac_fib_complete(fibptr);
2489 aac_fib_free(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07002490 cmd->scsi_done(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491}
2492
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002493static int aac_synchronize(struct scsi_cmnd *scsicmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494{
2495 int status;
2496 struct fib *cmd_fibcontext;
2497 struct aac_synchronize *synchronizecmd;
2498 struct scsi_cmnd *cmd;
2499 struct scsi_device *sdev = scsicmd->device;
2500 int active = 0;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002501 struct aac_dev *aac;
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002502 u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2503 (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2504 u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 unsigned long flags;
2506
2507 /*
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002508 * Wait for all outstanding queued commands to complete to this
2509 * specific target (block).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 */
2511 spin_lock_irqsave(&sdev->list_lock, flags);
2512 list_for_each_entry(cmd, &sdev->cmd_list, list)
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002513 if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2514 u64 cmnd_lba;
2515 u32 cmnd_count;
2516
2517 if (cmd->cmnd[0] == WRITE_6) {
2518 cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2519 (cmd->cmnd[2] << 8) |
2520 cmd->cmnd[3];
2521 cmnd_count = cmd->cmnd[4];
2522 if (cmnd_count == 0)
2523 cmnd_count = 256;
2524 } else if (cmd->cmnd[0] == WRITE_16) {
2525 cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2526 ((u64)cmd->cmnd[3] << 48) |
2527 ((u64)cmd->cmnd[4] << 40) |
2528 ((u64)cmd->cmnd[5] << 32) |
2529 ((u64)cmd->cmnd[6] << 24) |
2530 (cmd->cmnd[7] << 16) |
2531 (cmd->cmnd[8] << 8) |
2532 cmd->cmnd[9];
2533 cmnd_count = (cmd->cmnd[10] << 24) |
2534 (cmd->cmnd[11] << 16) |
2535 (cmd->cmnd[12] << 8) |
2536 cmd->cmnd[13];
2537 } else if (cmd->cmnd[0] == WRITE_12) {
2538 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2539 (cmd->cmnd[3] << 16) |
2540 (cmd->cmnd[4] << 8) |
2541 cmd->cmnd[5];
2542 cmnd_count = (cmd->cmnd[6] << 24) |
2543 (cmd->cmnd[7] << 16) |
2544 (cmd->cmnd[8] << 8) |
2545 cmd->cmnd[9];
2546 } else if (cmd->cmnd[0] == WRITE_10) {
2547 cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2548 (cmd->cmnd[3] << 16) |
2549 (cmd->cmnd[4] << 8) |
2550 cmd->cmnd[5];
2551 cmnd_count = (cmd->cmnd[7] << 8) |
2552 cmd->cmnd[8];
2553 } else
2554 continue;
2555 if (((cmnd_lba + cmnd_count) < lba) ||
2556 (count && ((lba + count) < cmnd_lba)))
2557 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 ++active;
2559 break;
2560 }
2561
2562 spin_unlock_irqrestore(&sdev->list_lock, flags);
2563
2564 /*
2565 * Yield the processor (requeue for later)
2566 */
2567 if (active)
2568 return SCSI_MLQUEUE_DEVICE_BUSY;
2569
Salyzyn, Markf8583172007-10-30 15:50:49 -04002570 aac = (struct aac_dev *)sdev->host->hostdata;
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002571 if (aac->in_reset)
2572 return SCSI_MLQUEUE_HOST_BUSY;
2573
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 /*
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07002575 * Allocate and initialize a Fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 */
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002577 if (!(cmd_fibcontext = aac_fib_alloc(aac)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 return SCSI_MLQUEUE_HOST_BUSY;
2579
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002580 aac_fib_init(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
2582 synchronizecmd = fib_data(cmd_fibcontext);
2583 synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
2584 synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002585 synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002586 synchronizecmd->count =
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
2588
2589 /*
2590 * Now send the Fib to the adapter
2591 */
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002592 status = aac_fib_send(ContainerCommand,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 cmd_fibcontext,
2594 sizeof(struct aac_synchronize),
2595 FsaNormal,
2596 0, 1,
2597 (fib_callback)synchronize_callback,
2598 (void *)scsicmd);
2599
2600 /*
2601 * Check that the command queued to the controller
2602 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002603 if (status == -EINPROGRESS) {
2604 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 return 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -08002606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Salyzyn, Markb90f90d2007-07-27 09:48:49 -04002608 printk(KERN_WARNING
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08002609 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
2610 aac_fib_complete(cmd_fibcontext);
2611 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 return SCSI_MLQUEUE_HOST_BUSY;
2613}
2614
Mark Salyzyn655d7222008-04-30 16:03:42 -04002615static void aac_start_stop_callback(void *context, struct fib *fibptr)
2616{
2617 struct scsi_cmnd *scsicmd = context;
2618
2619 if (!aac_valid_context(scsicmd, fibptr))
2620 return;
2621
2622 BUG_ON(fibptr == NULL);
2623
2624 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2625
2626 aac_fib_complete(fibptr);
2627 aac_fib_free(fibptr);
2628 scsicmd->scsi_done(scsicmd);
2629}
2630
2631static int aac_start_stop(struct scsi_cmnd *scsicmd)
2632{
2633 int status;
2634 struct fib *cmd_fibcontext;
2635 struct aac_power_management *pmcmd;
2636 struct scsi_device *sdev = scsicmd->device;
2637 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
2638
Raghava Aditya Renukunta1c688562017-02-16 12:51:10 -08002639 if (!(aac->supplement_adapter_info.supported_options2 &
Mark Salyzyn655d7222008-04-30 16:03:42 -04002640 AAC_OPTION_POWER_MANAGEMENT)) {
2641 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2642 SAM_STAT_GOOD;
2643 scsicmd->scsi_done(scsicmd);
2644 return 0;
2645 }
2646
2647 if (aac->in_reset)
2648 return SCSI_MLQUEUE_HOST_BUSY;
2649
2650 /*
2651 * Allocate and initialize a Fib
2652 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08002653 cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
Mark Salyzyn655d7222008-04-30 16:03:42 -04002654
2655 aac_fib_init(cmd_fibcontext);
2656
2657 pmcmd = fib_data(cmd_fibcontext);
2658 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
2659 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
2660 /* Eject bit ignored, not relevant */
2661 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
2662 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
2663 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
2664 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
2665 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
2666
2667 /*
2668 * Now send the Fib to the adapter
2669 */
2670 status = aac_fib_send(ContainerCommand,
2671 cmd_fibcontext,
2672 sizeof(struct aac_power_management),
2673 FsaNormal,
2674 0, 1,
2675 (fib_callback)aac_start_stop_callback,
2676 (void *)scsicmd);
2677
2678 /*
2679 * Check that the command queued to the controller
2680 */
2681 if (status == -EINPROGRESS) {
2682 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2683 return 0;
2684 }
2685
2686 aac_fib_complete(cmd_fibcontext);
2687 aac_fib_free(cmd_fibcontext);
2688 return SCSI_MLQUEUE_HOST_BUSY;
2689}
2690
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691/**
2692 * aac_scsi_cmd() - Process SCSI command
2693 * @scsicmd: SCSI command block
2694 *
2695 * Emulate a SCSI command and queue the required request for the
2696 * aacraid firmware.
2697 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002698
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2700{
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002701 u32 cid, bus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 struct Scsi_Host *host = scsicmd->device->host;
2703 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2704 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002705
Mark Haverkamp90ee3462006-08-03 08:03:07 -07002706 if (fsa_dev_ptr == NULL)
2707 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 /*
2709 * If the bus, id or lun is out of range, return fail
2710 * Test does not apply to ID 16, the pseudo id for the controller
2711 * itself.
2712 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002713 cid = scmd_id(scsicmd);
2714 if (cid != host->this_id) {
2715 if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
2716 if((cid >= dev->maximum_num_containers) ||
Mark Haverkampe5718772006-03-27 09:43:25 -08002717 (scsicmd->device->lun != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002719 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
2722 /*
2723 * If the target container doesn't exist, it may have
2724 * been newly created
2725 */
Mark Salyzyn655d7222008-04-30 16:03:42 -04002726 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2727 (fsa_dev_ptr[cid].sense_data.sense_key ==
2728 NOT_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 switch (scsicmd->cmnd[0]) {
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002730 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002731 if (!(dev->raw_io_interface) ||
2732 !(dev->raw_io_64) ||
2733 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2734 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 case INQUIRY:
2736 case READ_CAPACITY:
2737 case TEST_UNIT_READY:
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002738 if (dev->in_reset)
2739 return -1;
Mark Haverkampfe76df42007-03-15 12:55:07 -07002740 return _aac_probe_container(scsicmd,
2741 aac_probe_container_callback2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 default:
2743 break;
2744 }
2745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 } else { /* check for physical non-dasd devices */
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08002747 bus = aac_logical_to_phys(scmd_channel(scsicmd));
2748 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2749 (dev->hba_map[bus][cid].expose
2750 == AAC_HIDE_DISK)){
2751 if (scsicmd->cmnd[0] == INQUIRY) {
2752 scsicmd->result = DID_NO_CONNECT << 16;
2753 goto scsi_done_ret;
2754 }
2755 }
2756
2757 if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
2758 dev->hba_map[bus][cid].devtype
2759 == AAC_DEVTYPE_NATIVE_RAW) {
2760 if (dev->in_reset)
2761 return -1;
2762 return aac_send_hba_fib(scsicmd);
2763 } else if (dev->nondasd_support || expose_physicals ||
2764 dev->jbod) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002765 if (dev->in_reset)
2766 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 return aac_send_srb_fib(scsicmd);
2768 } else {
2769 scsicmd->result = DID_NO_CONNECT << 16;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002770 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 }
2772 }
2773 }
2774 /*
2775 * else Command for the controller itself
2776 */
2777 else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08002778 (scsicmd->cmnd[0] != TEST_UNIT_READY))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 {
2780 dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
2781 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002782 set_sense(&dev->fsa_dev[cid].sense_data,
2783 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
2784 ASENCODE_INVALID_COMMAND, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002786 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
2787 SCSI_SENSE_BUFFERSIZE));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002788 goto scsi_done_ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 }
2790
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 switch (scsicmd->cmnd[0]) {
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002792 case READ_6:
2793 case READ_10:
2794 case READ_12:
2795 case READ_16:
2796 if (dev->in_reset)
2797 return -1;
2798 return aac_read(scsicmd);
2799
2800 case WRITE_6:
2801 case WRITE_10:
2802 case WRITE_12:
2803 case WRITE_16:
2804 if (dev->in_reset)
2805 return -1;
2806 return aac_write(scsicmd);
2807
2808 case SYNCHRONIZE_CACHE:
2809 if (((aac_cache & 6) == 6) && dev->cache_protected) {
2810 scsicmd->result = AAC_STAT_GOOD;
2811 break;
2812 }
2813 /* Issue FIB to tell Firmware to flush it's cache */
2814 if ((aac_cache & 6) != 2)
2815 return aac_synchronize(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 case INQUIRY:
2817 {
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002818 struct inquiry_data inq_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002820 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002821 memset(&inq_data, 0, sizeof (struct inquiry_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
Leubner, Achimd8e965072009-04-01 07:16:08 -07002823 if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002824 char *arr = (char *)&inq_data;
2825
2826 /* EVPD bit set */
2827 arr[0] = (scmd_id(scsicmd) == host->this_id) ?
2828 INQD_PDT_PROC : INQD_PDT_DA;
2829 if (scsicmd->cmnd[2] == 0) {
2830 /* supported vital product data pages */
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002831 arr[3] = 3;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002832 arr[4] = 0x0;
2833 arr[5] = 0x80;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002834 arr[6] = 0x83;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002835 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002836 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2837 sizeof(inq_data));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002838 scsicmd->result = AAC_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002839 } else if (scsicmd->cmnd[2] == 0x80) {
2840 /* unit serial number page */
2841 arr[3] = setinqserial(dev, &arr[4],
2842 scmd_id(scsicmd));
2843 arr[1] = scsicmd->cmnd[2];
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002844 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2845 sizeof(inq_data));
Leubner, Achimd8e965072009-04-01 07:16:08 -07002846 if (aac_wwn != 2)
2847 return aac_get_container_serial(
2848 scsicmd);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002849 scsicmd->result = AAC_STAT_GOOD;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04002850 } else if (scsicmd->cmnd[2] == 0x83) {
2851 /* vpd page 0x83 - Device Identification Page */
2852 char *sno = (char *)&inq_data;
2853 sno[3] = setinqserial(dev, &sno[4],
2854 scmd_id(scsicmd));
2855 if (aac_wwn != 2)
2856 return aac_get_container_serial(
2857 scsicmd);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002858 scsicmd->result = AAC_STAT_GOOD;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002859 } else {
2860 /* vpd page not implemented */
2861 scsicmd->result = DID_OK << 16 |
2862 COMMAND_COMPLETE << 8 |
2863 SAM_STAT_CHECK_CONDITION;
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08002864 set_sense(&dev->fsa_dev[cid].sense_data,
2865 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
2866 ASENCODE_NO_SENSE, 7, 2);
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002867 memcpy(scsicmd->sense_buffer,
2868 &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08002869 min_t(size_t,
2870 sizeof(dev->fsa_dev[cid].sense_data),
2871 SCSI_SENSE_BUFFERSIZE));
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002872 }
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002873 break;
Salyzyn, Mark88e2f982007-07-17 14:01:28 -04002874 }
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002875 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002876 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 */
2877 inq_data.inqd_len = 31;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002879 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 /*
2881 * Set the Vendor, Product, and Revision Level
2882 * see: <vendor>.c i.e. aac.c
2883 */
Salyzyn, Mark1a655042007-06-11 16:17:55 -04002884 if (cid == host->this_id) {
Tobias Klauser6391a112006-06-08 22:23:48 -07002885 setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002886 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002887 scsi_sg_copy_from_buffer(scsicmd, &inq_data,
2888 sizeof(inq_data));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002889 scsicmd->result = AAC_STAT_GOOD;
2890 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 }
Mark Haverkamp8c867b22006-08-03 08:03:30 -07002892 if (dev->in_reset)
2893 return -1;
Mark Haverkamp794d0602005-10-24 10:51:53 -07002894 setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002895 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002896 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
Mark Haverkamp9e7c3492007-03-15 10:26:55 -07002897 return aac_get_container_name(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 }
Hannes Reineckeeb846d92014-11-17 14:25:19 +01002899 case SERVICE_ACTION_IN_16:
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002900 if (!(dev->raw_io_interface) ||
2901 !(dev->raw_io_64) ||
2902 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
2903 break;
2904 {
2905 u64 capacity;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002906 char cp[13];
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002907 unsigned int alloc_len;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002908
2909 dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
2910 capacity = fsa_dev_ptr[cid].size - 1;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002911 cp[0] = (capacity >> 56) & 0xff;
2912 cp[1] = (capacity >> 48) & 0xff;
2913 cp[2] = (capacity >> 40) & 0xff;
2914 cp[3] = (capacity >> 32) & 0xff;
2915 cp[4] = (capacity >> 24) & 0xff;
2916 cp[5] = (capacity >> 16) & 0xff;
2917 cp[6] = (capacity >> 8) & 0xff;
2918 cp[7] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002919 cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2920 cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2921 cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2922 cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002923 cp[12] = 0;
Mark Haverkamp07ce5eb2005-11-08 14:26:33 -08002924
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002925 alloc_len = ((scsicmd->cmnd[10] << 24)
2926 + (scsicmd->cmnd[11] << 16)
2927 + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
2928
2929 alloc_len = min_t(size_t, alloc_len, sizeof(cp));
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002930 scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
FUJITA Tomonorib271f1c2008-02-24 15:25:23 -08002931 if (alloc_len < scsi_bufflen(scsicmd))
2932 scsi_set_resid(scsicmd,
2933 scsi_bufflen(scsicmd) - alloc_len);
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002934
2935 /* Do not cache partition table for arrays */
2936 scsicmd->device->removable = 1;
2937
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002938 scsicmd->result = AAC_STAT_GOOD;
2939 break;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002940 }
2941
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 case READ_CAPACITY:
2943 {
2944 u32 capacity;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002945 char cp[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946
2947 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002948 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 capacity = fsa_dev_ptr[cid].size - 1;
2950 else
2951 capacity = (u32)-1;
Mark Haverkamp3b2946c2005-08-15 10:50:24 -07002952
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 cp[0] = (capacity >> 24) & 0xff;
2954 cp[1] = (capacity >> 16) & 0xff;
2955 cp[2] = (capacity >> 8) & 0xff;
2956 cp[3] = (capacity >> 0) & 0xff;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002957 cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
2958 cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
2959 cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
2960 cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
FUJITA Tomonorid4345022008-03-09 13:44:34 +09002961 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07002962 /* Do not cache partition table for arrays */
2963 scsicmd->device->removable = 1;
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08002964 scsicmd->result = AAC_STAT_GOOD;
2965 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 }
2967
2968 case MODE_SENSE:
2969 {
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04002970 int mode_buf_length = 4;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002971 u32 capacity;
2972 aac_modep_data mpd;
2973
2974 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
2975 capacity = fsa_dev_ptr[cid].size - 1;
2976 else
2977 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
2979 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002980 memset((char *)&mpd, 0, sizeof(aac_modep_data));
2981
2982 /* Mode data length */
2983 mpd.hd.data_length = sizeof(mpd.hd) - 1;
2984 /* Medium type - default */
2985 mpd.hd.med_type = 0;
2986 /* Device-specific param,
2987 bit 8: 0/1 = write enabled/protected
2988 bit 4: 0/1 = FUA enabled */
2989 mpd.hd.dev_par = 0;
2990
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08002991 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04002992 mpd.hd.dev_par = 0x10;
2993 if (scsicmd->cmnd[1] & 0x8)
2994 mpd.hd.bd_length = 0; /* Block descriptor length */
2995 else {
2996 mpd.hd.bd_length = sizeof(mpd.bd);
2997 mpd.hd.data_length += mpd.hd.bd_length;
2998 mpd.bd.block_length[0] =
2999 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3000 mpd.bd.block_length[1] =
3001 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3002 mpd.bd.block_length[2] =
3003 fsa_dev_ptr[cid].block_size & 0xff;
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04003004
3005 mpd.mpc_buf[0] = scsicmd->cmnd[2];
3006 if (scsicmd->cmnd[2] == 0x1C) {
3007 /* page length */
3008 mpd.mpc_buf[1] = 0xa;
3009 /* Mode data length */
3010 mpd.hd.data_length = 23;
3011 } else {
3012 /* Mode data length */
3013 mpd.hd.data_length = 15;
3014 }
3015
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003016 if (capacity > 0xffffff) {
3017 mpd.bd.block_count[0] = 0xff;
3018 mpd.bd.block_count[1] = 0xff;
3019 mpd.bd.block_count[2] = 0xff;
3020 } else {
3021 mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
3022 mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
3023 mpd.bd.block_count[2] = capacity & 0xff;
3024 }
3025 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003026 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3027 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003028 mpd.hd.data_length += 3;
3029 mpd.mpc_buf[0] = 8;
3030 mpd.mpc_buf[1] = 1;
3031 mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003032 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003033 mode_buf_length = sizeof(mpd);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003034 }
Mahesh Rajashekhara5d910642015-03-26 10:41:26 -04003035
3036 if (mode_buf_length > scsicmd->cmnd[4])
3037 mode_buf_length = scsicmd->cmnd[4];
3038 else
3039 mode_buf_length = sizeof(mpd);
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003040 scsi_sg_copy_from_buffer(scsicmd,
3041 (char *)&mpd,
3042 mode_buf_length);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003043 scsicmd->result = AAC_STAT_GOOD;
3044 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 }
3046 case MODE_SENSE_10:
3047 {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003048 u32 capacity;
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003049 int mode_buf_length = 8;
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003050 aac_modep10_data mpd10;
3051
3052 if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
3053 capacity = fsa_dev_ptr[cid].size - 1;
3054 else
3055 capacity = (u32)-1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056
3057 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003058 memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
3059 /* Mode data length (MSB) */
3060 mpd10.hd.data_length[0] = 0;
3061 /* Mode data length (LSB) */
3062 mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
3063 /* Medium type - default */
3064 mpd10.hd.med_type = 0;
3065 /* Device-specific param,
3066 bit 8: 0/1 = write enabled/protected
3067 bit 4: 0/1 = FUA enabled */
3068 mpd10.hd.dev_par = 0;
3069
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003070 if (dev->raw_io_interface && ((aac_cache & 5) != 1))
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003071 mpd10.hd.dev_par = 0x10;
3072 mpd10.hd.rsrvd[0] = 0; /* reserved */
3073 mpd10.hd.rsrvd[1] = 0; /* reserved */
3074 if (scsicmd->cmnd[1] & 0x8) {
3075 /* Block descriptor length (MSB) */
3076 mpd10.hd.bd_length[0] = 0;
3077 /* Block descriptor length (LSB) */
3078 mpd10.hd.bd_length[1] = 0;
3079 } else {
3080 mpd10.hd.bd_length[0] = 0;
3081 mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
3082
3083 mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
3084
3085 mpd10.bd.block_length[0] =
3086 (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
3087 mpd10.bd.block_length[1] =
3088 (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
3089 mpd10.bd.block_length[2] =
3090 fsa_dev_ptr[cid].block_size & 0xff;
3091
3092 if (capacity > 0xffffff) {
3093 mpd10.bd.block_count[0] = 0xff;
3094 mpd10.bd.block_count[1] = 0xff;
3095 mpd10.bd.block_count[2] = 0xff;
3096 } else {
3097 mpd10.bd.block_count[0] =
3098 (capacity >> 16) & 0xff;
3099 mpd10.bd.block_count[1] =
3100 (capacity >> 8) & 0xff;
3101 mpd10.bd.block_count[2] =
3102 capacity & 0xff;
3103 }
3104 }
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003105 if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
3106 ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003107 mpd10.hd.data_length[1] += 3;
3108 mpd10.mpc_buf[0] = 8;
3109 mpd10.mpc_buf[1] = 1;
3110 mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
Salyzyn, Mark95e852e2008-01-08 12:01:07 -08003111 ? 0 : 0x04; /* WCE */
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003112 mode_buf_length = sizeof(mpd10);
Salyzyn, Mark9d399cc2007-05-18 14:51:34 -04003113 if (mode_buf_length > scsicmd->cmnd[8])
3114 mode_buf_length = scsicmd->cmnd[8];
3115 }
Mahesh Rajashekharab8364392015-03-26 10:41:24 -04003116 scsi_sg_copy_from_buffer(scsicmd,
3117 (char *)&mpd10,
3118 mode_buf_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003120 scsicmd->result = AAC_STAT_GOOD;
3121 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 }
3123 case REQUEST_SENSE:
3124 dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003125 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
3126 sizeof(struct sense_data));
3127 memset(&dev->fsa_dev[cid].sense_data, 0,
3128 sizeof(struct sense_data));
3129 scsicmd->result = AAC_STAT_GOOD;
3130 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
3132 case ALLOW_MEDIUM_REMOVAL:
3133 dprintk((KERN_DEBUG "LOCK command.\n"));
3134 if (scsicmd->cmnd[4])
3135 fsa_dev_ptr[cid].locked = 1;
3136 else
3137 fsa_dev_ptr[cid].locked = 0;
3138
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003139 scsicmd->result = AAC_STAT_GOOD;
3140 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 /*
3142 * These commands are all No-Ops
3143 */
3144 case TEST_UNIT_READY:
Mark Salyzyn655d7222008-04-30 16:03:42 -04003145 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
3146 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3147 SAM_STAT_CHECK_CONDITION;
3148 set_sense(&dev->fsa_dev[cid].sense_data,
3149 NOT_READY, SENCODE_BECOMING_READY,
3150 ASENCODE_BECOMING_READY, 0, 0);
3151 memcpy(scsicmd->sense_buffer,
3152 &dev->fsa_dev[cid].sense_data,
3153 min_t(size_t,
3154 sizeof(dev->fsa_dev[cid].sense_data),
3155 SCSI_SENSE_BUFFERSIZE));
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003156 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04003157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 case RESERVE:
3159 case RELEASE:
3160 case REZERO_UNIT:
3161 case REASSIGN_BLOCKS:
3162 case SEEK_10:
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003163 scsicmd->result = AAC_STAT_GOOD;
3164 break;
Mark Salyzyn655d7222008-04-30 16:03:42 -04003165
3166 case START_STOP:
3167 return aac_start_stop(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003169 /* FALLTHRU */
3170 default:
3171 /*
3172 * Unhandled commands
3173 */
3174 dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
3175 scsicmd->cmnd[0]));
3176 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
3177 SAM_STAT_CHECK_CONDITION;
3178 set_sense(&dev->fsa_dev[cid].sense_data,
Salyzyn, Mark8e31e602008-02-06 13:54:12 -08003179 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
3180 ASENCODE_INVALID_COMMAND, 0, 0);
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003181 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
Salyzyn, Mark3ace4262008-01-14 07:25:33 -08003182 min_t(size_t,
3183 sizeof(dev->fsa_dev[cid].sense_data),
3184 SCSI_SENSE_BUFFERSIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 }
Raghava Aditya Renukuntac4e2fbc2017-02-02 15:53:20 -08003186
3187scsi_done_ret:
3188
3189 scsicmd->scsi_done(scsicmd);
3190 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191}
3192
3193static int query_disk(struct aac_dev *dev, void __user *arg)
3194{
3195 struct aac_query_disk qd;
3196 struct fsa_dev_info *fsa_dev_ptr;
3197
3198 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07003199 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07003200 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
3202 return -EFAULT;
3203 if (qd.cnum == -1)
Mark Haverkampe5718772006-03-27 09:43:25 -08003204 qd.cnum = qd.id;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003205 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 {
3207 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
3208 return -EINVAL;
3209 qd.instance = dev->scsi_host_ptr->host_no;
3210 qd.bus = 0;
3211 qd.id = CONTAINER_TO_ID(qd.cnum);
3212 qd.lun = CONTAINER_TO_LUN(qd.cnum);
3213 }
3214 else return -EINVAL;
3215
Salyzyn, Markfd622b12007-07-17 10:59:19 -04003216 qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 qd.locked = fsa_dev_ptr[qd.cnum].locked;
3218 qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
3219
3220 if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
3221 qd.unmapped = 1;
3222 else
3223 qd.unmapped = 0;
3224
3225 strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
3226 min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
3227
3228 if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
3229 return -EFAULT;
3230 return 0;
3231}
3232
3233static int force_delete_disk(struct aac_dev *dev, void __user *arg)
3234{
3235 struct aac_delete_disk dd;
3236 struct fsa_dev_info *fsa_dev_ptr;
3237
3238 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp65101352006-09-19 08:59:23 -07003239 if (!fsa_dev_ptr)
3240 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
3242 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3243 return -EFAULT;
3244
3245 if (dd.cnum >= dev->maximum_num_containers)
3246 return -EINVAL;
3247 /*
3248 * Mark this container as being deleted.
3249 */
3250 fsa_dev_ptr[dd.cnum].deleted = 1;
3251 /*
3252 * Mark the container as no longer valid
3253 */
3254 fsa_dev_ptr[dd.cnum].valid = 0;
3255 return 0;
3256}
3257
3258static int delete_disk(struct aac_dev *dev, void __user *arg)
3259{
3260 struct aac_delete_disk dd;
3261 struct fsa_dev_info *fsa_dev_ptr;
3262
3263 fsa_dev_ptr = dev->fsa_dev;
Mark Haverkamp90ee3462006-08-03 08:03:07 -07003264 if (!fsa_dev_ptr)
Mark Haverkamp65101352006-09-19 08:59:23 -07003265 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266
3267 if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
3268 return -EFAULT;
3269
3270 if (dd.cnum >= dev->maximum_num_containers)
3271 return -EINVAL;
3272 /*
3273 * If the container is locked, it can not be deleted by the API.
3274 */
3275 if (fsa_dev_ptr[dd.cnum].locked)
3276 return -EBUSY;
3277 else {
3278 /*
3279 * Mark the container as no longer being valid.
3280 */
3281 fsa_dev_ptr[dd.cnum].valid = 0;
3282 fsa_dev_ptr[dd.cnum].devname[0] = '\0';
3283 return 0;
3284 }
3285}
3286
3287int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
3288{
3289 switch (cmd) {
3290 case FSACTL_QUERY_DISK:
3291 return query_disk(dev, arg);
3292 case FSACTL_DELETE_DISK:
3293 return delete_disk(dev, arg);
3294 case FSACTL_FORCE_DELETE_DISK:
3295 return force_delete_disk(dev, arg);
3296 case FSACTL_GET_CONTAINERS:
3297 return aac_get_containers(dev);
3298 default:
3299 return -ENOTTY;
3300 }
3301}
3302
3303/**
3304 *
3305 * aac_srb_callback
3306 * @context: the context set in the fib - here it is scsi cmd
3307 * @fibptr: pointer to the fib
3308 *
3309 * Handles the completion of a scsi command to a non dasd device
3310 *
3311 */
3312
3313static void aac_srb_callback(void *context, struct fib * fibptr)
3314{
3315 struct aac_dev *dev;
3316 struct aac_srb_reply *srbreply;
3317 struct scsi_cmnd *scsicmd;
3318
3319 scsicmd = (struct scsi_cmnd *) context;
Mark Haverkamp03d44332007-03-15 10:27:45 -07003320
3321 if (!aac_valid_context(scsicmd, fibptr))
3322 return;
3323
Eric Sesterhenn125e1872006-06-23 02:06:06 -07003324 BUG_ON(fibptr == NULL);
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003325
Salyzyn, Mark1a655042007-06-11 16:17:55 -04003326 dev = fibptr->dev;
3327
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003328 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003329
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303332 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3333 /* fast response */
3334 srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
3335 srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
3336 } else {
3337 /*
3338 * Calculate resid for sg
3339 */
3340 scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
3341 - le32_to_cpu(srbreply->data_xfer_length));
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003342 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003343
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003345 scsi_dma_unmap(scsicmd);
3346
3347 /* expose physical device if expose_physicald flag is on */
3348 if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
3349 && expose_physicals > 0)
3350 aac_expose_phy_device(scsicmd);
3351
3352 /*
3353 * First check the fib status
3354 */
3355
3356 if (le32_to_cpu(srbreply->status) != ST_OK) {
3357 int len;
3358
3359 pr_warn("aac_srb_callback: srb failed, status = %d\n",
3360 le32_to_cpu(srbreply->status));
3361 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3362 SCSI_SENSE_BUFFERSIZE);
3363 scsicmd->result = DID_ERROR << 16
3364 | COMMAND_COMPLETE << 8
3365 | SAM_STAT_CHECK_CONDITION;
3366 memcpy(scsicmd->sense_buffer,
3367 srbreply->sense_data, len);
3368 }
3369
3370 /*
3371 * Next check the srb status
3372 */
3373 switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
3374 case SRB_STATUS_ERROR_RECOVERY:
3375 case SRB_STATUS_PENDING:
3376 case SRB_STATUS_SUCCESS:
3377 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3378 break;
3379 case SRB_STATUS_DATA_OVERRUN:
3380 switch (scsicmd->cmnd[0]) {
3381 case READ_6:
3382 case WRITE_6:
3383 case READ_10:
3384 case WRITE_10:
3385 case READ_12:
3386 case WRITE_12:
3387 case READ_16:
3388 case WRITE_16:
3389 if (le32_to_cpu(srbreply->data_xfer_length)
3390 < scsicmd->underflow)
3391 pr_warn("aacraid: SCSI CMD underflow\n");
3392 else
3393 pr_warn("aacraid: SCSI CMD Data Overrun\n");
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003394 scsicmd->result = DID_ERROR << 16
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003395 | COMMAND_COMPLETE << 8;
3396 break;
3397 case INQUIRY:
3398 scsicmd->result = DID_OK << 16
3399 | COMMAND_COMPLETE << 8;
3400 break;
3401 default:
Mark Haverkampbb08f922006-02-01 09:30:44 -08003402 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 break;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003404 }
3405 break;
3406 case SRB_STATUS_ABORTED:
3407 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3408 break;
3409 case SRB_STATUS_ABORT_FAILED:
3410 /*
3411 * Not sure about this one - but assuming the
3412 * hba was trying to abort for some reason
3413 */
3414 scsicmd->result = DID_ERROR << 16 | ABORT << 8;
3415 break;
3416 case SRB_STATUS_PARITY_ERROR:
3417 scsicmd->result = DID_PARITY << 16
3418 | MSG_PARITY_ERROR << 8;
3419 break;
3420 case SRB_STATUS_NO_DEVICE:
3421 case SRB_STATUS_INVALID_PATH_ID:
3422 case SRB_STATUS_INVALID_TARGET_ID:
3423 case SRB_STATUS_INVALID_LUN:
3424 case SRB_STATUS_SELECTION_TIMEOUT:
3425 scsicmd->result = DID_NO_CONNECT << 16
3426 | COMMAND_COMPLETE << 8;
3427 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003428
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003429 case SRB_STATUS_COMMAND_TIMEOUT:
3430 case SRB_STATUS_TIMEOUT:
3431 scsicmd->result = DID_TIME_OUT << 16
3432 | COMMAND_COMPLETE << 8;
3433 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003434
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003435 case SRB_STATUS_BUSY:
3436 scsicmd->result = DID_BUS_BUSY << 16
3437 | COMMAND_COMPLETE << 8;
3438 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003439
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003440 case SRB_STATUS_BUS_RESET:
3441 scsicmd->result = DID_RESET << 16
3442 | COMMAND_COMPLETE << 8;
3443 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003444
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003445 case SRB_STATUS_MESSAGE_REJECTED:
3446 scsicmd->result = DID_ERROR << 16
3447 | MESSAGE_REJECT << 8;
3448 break;
3449 case SRB_STATUS_REQUEST_FLUSHED:
3450 case SRB_STATUS_ERROR:
3451 case SRB_STATUS_INVALID_REQUEST:
3452 case SRB_STATUS_REQUEST_SENSE_FAILED:
3453 case SRB_STATUS_NO_HBA:
3454 case SRB_STATUS_UNEXPECTED_BUS_FREE:
3455 case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
3456 case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
3457 case SRB_STATUS_DELAYED_RETRY:
3458 case SRB_STATUS_BAD_FUNCTION:
3459 case SRB_STATUS_NOT_STARTED:
3460 case SRB_STATUS_NOT_IN_USE:
3461 case SRB_STATUS_FORCE_ABORT:
3462 case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
3463 default:
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003464#ifdef AAC_DETAILED_STATUS_INFO
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003465 pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
3466 le32_to_cpu(srbreply->srb_status) & 0x3F,
3467 aac_get_status_string(
3468 le32_to_cpu(srbreply->srb_status) & 0x3F),
3469 scsicmd->cmnd[0],
3470 le32_to_cpu(srbreply->scsi_status));
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003471#endif
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003472 /*
3473 * When the CC bit is SET by the host in ATA pass thru CDB,
3474 * driver is supposed to return DID_OK
3475 *
3476 * When the CC bit is RESET by the host, driver should
3477 * return DID_ERROR
3478 */
3479 if ((scsicmd->cmnd[0] == ATA_12)
3480 || (scsicmd->cmnd[0] == ATA_16)) {
3481
3482 if (scsicmd->cmnd[2] & (0x01 << 5)) {
3483 scsicmd->result = DID_OK << 16
3484 | COMMAND_COMPLETE << 8;
3485 break;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003486 } else {
3487 scsicmd->result = DID_ERROR << 16
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003488 | COMMAND_COMPLETE << 8;
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003489 break;
Rajashekhara, Mahesh1fc80102010-05-10 04:17:57 -07003490 }
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003491 } else {
3492 scsicmd->result = DID_ERROR << 16
3493 | COMMAND_COMPLETE << 8;
3494 break;
Mahesh Rajashekhara55b87602015-08-28 06:38:37 -04003495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 }
Raghava Aditya Renukunta4ec57fb2017-02-02 15:53:21 -08003497 if (le32_to_cpu(srbreply->scsi_status)
3498 == SAM_STAT_CHECK_CONDITION) {
3499 int len;
3500
3501 scsicmd->result |= SAM_STAT_CHECK_CONDITION;
3502 len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
3503 SCSI_SENSE_BUFFERSIZE);
3504#ifdef AAC_DETAILED_STATUS_INFO
3505 pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
3506 le32_to_cpu(srbreply->status), len);
3507#endif
3508 memcpy(scsicmd->sense_buffer,
3509 srbreply->sense_data, len);
3510 }
3511
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 /*
3513 * OR in the scsi status (already shifted up a bit)
3514 */
3515 scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
3516
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003517 aac_fib_complete(fibptr);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07003518 scsicmd->scsi_done(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519}
3520
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003521static void hba_resp_task_complete(struct aac_dev *dev,
3522 struct scsi_cmnd *scsicmd,
3523 struct aac_hba_resp *err) {
3524
3525 scsicmd->result = err->status;
3526 /* set residual count */
3527 scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
3528
3529 switch (err->status) {
3530 case SAM_STAT_GOOD:
3531 scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3532 break;
3533 case SAM_STAT_CHECK_CONDITION:
3534 {
3535 int len;
3536
3537 len = min_t(u8, err->sense_response_data_len,
3538 SCSI_SENSE_BUFFERSIZE);
3539 if (len)
3540 memcpy(scsicmd->sense_buffer,
3541 err->sense_response_buf, len);
3542 scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
3543 break;
3544 }
3545 case SAM_STAT_BUSY:
3546 scsicmd->result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
3547 break;
3548 case SAM_STAT_TASK_ABORTED:
3549 scsicmd->result |= DID_ABORT << 16 | ABORT << 8;
3550 break;
3551 case SAM_STAT_RESERVATION_CONFLICT:
3552 case SAM_STAT_TASK_SET_FULL:
3553 default:
3554 scsicmd->result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3555 break;
3556 }
3557}
3558
3559static void hba_resp_task_failure(struct aac_dev *dev,
3560 struct scsi_cmnd *scsicmd,
3561 struct aac_hba_resp *err)
3562{
3563 switch (err->status) {
3564 case HBA_RESP_STAT_HBAMODE_DISABLED:
3565 {
3566 u32 bus, cid;
3567
3568 bus = aac_logical_to_phys(scmd_channel(scsicmd));
3569 cid = scmd_id(scsicmd);
3570 if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
3571 dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
3572 dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
3573 }
3574 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3575 break;
3576 }
3577 case HBA_RESP_STAT_IO_ERROR:
3578 case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
3579 scsicmd->result = DID_OK << 16 |
3580 COMMAND_COMPLETE << 8 | SAM_STAT_BUSY;
3581 break;
3582 case HBA_RESP_STAT_IO_ABORTED:
3583 scsicmd->result = DID_ABORT << 16 | ABORT << 8;
3584 break;
3585 case HBA_RESP_STAT_INVALID_DEVICE:
3586 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3587 break;
3588 case HBA_RESP_STAT_UNDERRUN:
3589 /* UNDERRUN is OK */
3590 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3591 break;
3592 case HBA_RESP_STAT_OVERRUN:
3593 default:
3594 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3595 break;
3596 }
3597}
3598
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599/**
3600 *
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003601 * aac_hba_callback
3602 * @context: the context set in the fib - here it is scsi cmd
3603 * @fibptr: pointer to the fib
3604 *
3605 * Handles the completion of a native HBA scsi command
3606 *
3607 */
3608void aac_hba_callback(void *context, struct fib *fibptr)
3609{
3610 struct aac_dev *dev;
3611 struct scsi_cmnd *scsicmd;
3612
3613 struct aac_hba_resp *err =
3614 &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
3615
3616 scsicmd = (struct scsi_cmnd *) context;
3617
3618 if (!aac_valid_context(scsicmd, fibptr))
3619 return;
3620
3621 WARN_ON(fibptr == NULL);
3622 dev = fibptr->dev;
3623
3624 if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
3625 scsi_dma_unmap(scsicmd);
3626
3627 if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
3628 /* fast response */
3629 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3630 goto out;
3631 }
3632
3633 switch (err->service_response) {
3634 case HBA_RESP_SVCRES_TASK_COMPLETE:
3635 hba_resp_task_complete(dev, scsicmd, err);
3636 break;
3637 case HBA_RESP_SVCRES_FAILURE:
3638 hba_resp_task_failure(dev, scsicmd, err);
3639 break;
3640 case HBA_RESP_SVCRES_TMF_REJECTED:
3641 scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
3642 break;
3643 case HBA_RESP_SVCRES_TMF_LUN_INVALID:
3644 scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
3645 break;
3646 case HBA_RESP_SVCRES_TMF_COMPLETE:
3647 case HBA_RESP_SVCRES_TMF_SUCCEEDED:
3648 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
3649 break;
3650 default:
3651 scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
3652 break;
3653 }
3654
3655out:
3656 aac_fib_complete(fibptr);
3657
3658 if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
3659 scsicmd->SCp.sent_command = 1;
3660 else
3661 scsicmd->scsi_done(scsicmd);
3662}
3663
3664/**
3665 *
3666 * aac_send_srb_fib
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 * @scsicmd: the scsi command block
3668 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08003669 * This routine will form a FIB and fill in the aac_srb from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 * scsicmd passed in.
3671 */
3672
3673static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
3674{
3675 struct fib* cmd_fibcontext;
3676 struct aac_dev* dev;
3677 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678
Mark Haverkamp84971732005-06-20 11:55:24 -07003679 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
Mark Haverkampe5718772006-03-27 09:43:25 -08003680 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
Mark Haverkamp84971732005-06-20 11:55:24 -07003681 scsicmd->device->lun > 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 scsicmd->result = DID_NO_CONNECT << 16;
3683 scsicmd->scsi_done(scsicmd);
3684 return 0;
3685 }
3686
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 /*
3688 * Allocate and initialize a Fib then setup a BlockWrite command
3689 */
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08003690 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -08003691
Mark Haverkampe8f32de2007-01-23 15:00:30 -08003692 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 /*
3695 * Check that the command queued to the controller
3696 */
Mark Haverkamp77d644d2006-03-27 09:43:40 -08003697 if (status == -EINPROGRESS) {
3698 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 return 0;
3700 }
3701
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08003702 printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
3703 aac_fib_complete(cmd_fibcontext);
3704 aac_fib_free(cmd_fibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705
3706 return -1;
3707}
3708
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08003709/**
3710 *
3711 * aac_send_hba_fib
3712 * @scsicmd: the scsi command block
3713 *
3714 * This routine will form a FIB and fill in the aac_hba_cmd_req from the
3715 * scsicmd passed in.
3716 */
3717static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
3718{
3719 struct fib *cmd_fibcontext;
3720 struct aac_dev *dev;
3721 int status;
3722
3723 dev = shost_priv(scsicmd->device->host);
3724 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
3725 scsicmd->device->lun > AAC_MAX_LUN - 1) {
3726 scsicmd->result = DID_NO_CONNECT << 16;
3727 scsicmd->scsi_done(scsicmd);
3728 return 0;
3729 }
3730
3731 /*
3732 * Allocate and initialize a Fib then setup a BlockWrite command
3733 */
3734 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
3735 if (!cmd_fibcontext)
3736 return -1;
3737
3738 status = aac_adapter_hba(cmd_fibcontext, scsicmd);
3739
3740 /*
3741 * Check that the command queued to the controller
3742 */
3743 if (status == -EINPROGRESS) {
3744 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
3745 return 0;
3746 }
3747
3748 pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
3749 status);
3750 aac_fib_complete(cmd_fibcontext);
3751 aac_fib_free(cmd_fibcontext);
3752
3753 return -1;
3754}
3755
3756
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303757static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758{
3759 struct aac_dev *dev;
3760 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003761 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762
3763 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3764 // Get rid of old data
3765 psg->count = 0;
3766 psg->sg[0].addr = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003767 psg->sg[0].count = 0;
3768
3769 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303770 if (nseg < 0)
3771 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003772 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 struct scatterlist *sg;
3774 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003776 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003778 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
3780 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
3781 byte_count += sg_dma_len(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 }
3783 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003784 if (byte_count > scsi_bufflen(scsicmd)) {
3785 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3786 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003787 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003788 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 }
3790 /* Check for command underflow */
3791 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3792 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3793 byte_count, scsicmd->underflow);
3794 }
3795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 return byte_count;
3797}
3798
3799
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303800static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801{
3802 struct aac_dev *dev;
3803 unsigned long byte_count = 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003804 u64 addr;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003805 int nseg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
3807 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
3808 // Get rid of old data
3809 psg->count = 0;
3810 psg->sg[0].addr[0] = 0;
3811 psg->sg[0].addr[1] = 0;
3812 psg->sg[0].count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003813
3814 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303815 if (nseg < 0)
3816 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003817 if (nseg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 struct scatterlist *sg;
3819 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003821 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp1241f352006-03-27 09:44:23 -08003822 int count = sg_dma_len(sg);
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003823 addr = sg_dma_address(sg);
3824 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
3825 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
Mark Haverkamp1241f352006-03-27 09:44:23 -08003826 psg->sg[i].count = cpu_to_le32(count);
3827 byte_count += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003829 psg->count = cpu_to_le32(nseg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003831 if (byte_count > scsi_bufflen(scsicmd)) {
3832 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3833 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp 56b58712005-04-27 06:05:51 -07003834 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003835 byte_count = scsi_bufflen(scsicmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 }
3837 /* Check for command underflow */
3838 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3839 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3840 byte_count, scsicmd->underflow);
3841 }
3842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 return byte_count;
3844}
3845
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303846static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003847{
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003848 unsigned long byte_count = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003849 int nseg;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003850
3851 // Get rid of old data
3852 psg->count = 0;
3853 psg->sg[0].next = 0;
3854 psg->sg[0].prev = 0;
3855 psg->sg[0].addr[0] = 0;
3856 psg->sg[0].addr[1] = 0;
3857 psg->sg[0].count = 0;
3858 psg->sg[0].flags = 0;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003859
3860 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303861 if (nseg < 0)
3862 return nseg;
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003863 if (nseg) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003864 struct scatterlist *sg;
3865 int i;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003866
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003867 scsi_for_each_sg(scsicmd, sg, nseg, i) {
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003868 int count = sg_dma_len(sg);
3869 u64 addr = sg_dma_address(sg);
3870 psg->sg[i].next = 0;
3871 psg->sg[i].prev = 0;
3872 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
3873 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
3874 psg->sg[i].count = cpu_to_le32(count);
3875 psg->sg[i].flags = 0;
3876 byte_count += count;
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003877 }
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003878 psg->count = cpu_to_le32(nseg);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003879 /* hba wants the size to be exact */
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003880 if (byte_count > scsi_bufflen(scsicmd)) {
3881 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
3882 (byte_count - scsi_bufflen(scsicmd));
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003883 psg->sg[i-1].count = cpu_to_le32(temp);
FUJITA Tomonori727eead2007-05-26 02:00:42 +09003884 byte_count = scsi_bufflen(scsicmd);
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003885 }
3886 /* Check for command underflow */
3887 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
3888 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3889 byte_count, scsicmd->underflow);
3890 }
3891 }
Mark Haverkamp0e68c002005-08-03 15:39:49 -07003892 return byte_count;
3893}
3894
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303895static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
3896 struct aac_raw_io2 *rio2, int sg_max)
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303897{
3898 unsigned long byte_count = 0;
3899 int nseg;
3900
3901 nseg = scsi_dma_map(scsicmd);
Mahesh Rajashekhara0b433442012-10-19 19:21:07 +05303902 if (nseg < 0)
3903 return nseg;
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05303904 if (nseg) {
3905 struct scatterlist *sg;
3906 int i, conformable = 0;
3907 u32 min_size = PAGE_SIZE, cur_size;
3908
3909 scsi_for_each_sg(scsicmd, sg, nseg, i) {
3910 int count = sg_dma_len(sg);
3911 u64 addr = sg_dma_address(sg);
3912
3913 BUG_ON(i >= sg_max);
3914 rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
3915 rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
3916 cur_size = cpu_to_le32(count);
3917 rio2->sge[i].length = cur_size;
3918 rio2->sge[i].flags = 0;
3919 if (i == 0) {
3920 conformable = 1;
3921 rio2->sgeFirstSize = cur_size;
3922 } else if (i == 1) {
3923 rio2->sgeNominalSize = cur_size;
3924 min_size = cur_size;
3925 } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
3926 conformable = 0;
3927 if (cur_size < min_size)
3928 min_size = cur_size;
3929 }
3930 byte_count += count;
3931 }
3932
3933 /* hba wants the size to be exact */
3934 if (byte_count > scsi_bufflen(scsicmd)) {
3935 u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
3936 (byte_count - scsi_bufflen(scsicmd));
3937 rio2->sge[i-1].length = cpu_to_le32(temp);
3938 byte_count = scsi_bufflen(scsicmd);
3939 }
3940
3941 rio2->sgeCnt = cpu_to_le32(nseg);
3942 rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
3943 /* not conformable: evaluate required sg elements */
3944 if (!conformable) {
3945 int j, nseg_new = nseg, err_found;
3946 for (i = min_size / PAGE_SIZE; i >= 1; --i) {
3947 err_found = 0;
3948 nseg_new = 2;
3949 for (j = 1; j < nseg - 1; ++j) {
3950 if (rio2->sge[j].length % (i*PAGE_SIZE)) {
3951 err_found = 1;
3952 break;
3953 }
3954 nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
3955 }
3956 if (!err_found)
3957 break;
3958 }
3959 if (i > 0 && nseg_new <= sg_max)
3960 aac_convert_sgraw2(rio2, i, nseg, nseg_new);
3961 } else
3962 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
3963
3964 /* Check for command underflow */
3965 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
3966 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
3967 byte_count, scsicmd->underflow);
3968 }
3969 }
3970
3971 return byte_count;
3972}
3973
3974static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
3975{
3976 struct sge_ieee1212 *sge;
3977 int i, j, pos;
3978 u32 addr_low;
3979
3980 if (aac_convert_sgl == 0)
3981 return 0;
3982
3983 sge = kmalloc(nseg_new * sizeof(struct sge_ieee1212), GFP_ATOMIC);
3984 if (sge == NULL)
3985 return -1;
3986
3987 for (i = 1, pos = 1; i < nseg-1; ++i) {
3988 for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
3989 addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
3990 sge[pos].addrLow = addr_low;
3991 sge[pos].addrHigh = rio2->sge[i].addrHigh;
3992 if (addr_low < rio2->sge[i].addrLow)
3993 sge[pos].addrHigh++;
3994 sge[pos].length = pages * PAGE_SIZE;
3995 sge[pos].flags = 0;
3996 pos++;
3997 }
3998 }
3999 sge[pos] = rio2->sge[nseg-1];
4000 memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
4001
4002 kfree(sge);
4003 rio2->sgeCnt = cpu_to_le32(nseg_new);
4004 rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
4005 rio2->sgeNominalSize = pages * PAGE_SIZE;
4006 return 0;
4007}
4008
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08004009static long aac_build_sghba(struct scsi_cmnd *scsicmd,
4010 struct aac_hba_cmd_req *hbacmd,
4011 int sg_max,
4012 u64 sg_address)
4013{
4014 unsigned long byte_count = 0;
4015 int nseg;
4016 struct scatterlist *sg;
4017 int i;
4018 u32 cur_size;
4019 struct aac_hba_sgl *sge;
4020
Raghava Aditya Renukuntaab5d1292017-02-02 15:53:30 -08004021 nseg = scsi_dma_map(scsicmd);
4022 if (nseg <= 0) {
4023 byte_count = nseg;
4024 goto out;
4025 }
4026
4027 if (nseg > HBA_MAX_SG_EMBEDDED)
4028 sge = &hbacmd->sge[2];
4029 else
4030 sge = &hbacmd->sge[0];
4031
4032 scsi_for_each_sg(scsicmd, sg, nseg, i) {
4033 int count = sg_dma_len(sg);
4034 u64 addr = sg_dma_address(sg);
4035
4036 WARN_ON(i >= sg_max);
4037 sge->addr_hi = cpu_to_le32((u32)(addr>>32));
4038 sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
4039 cur_size = cpu_to_le32(count);
4040 sge->len = cur_size;
4041 sge->flags = 0;
4042 byte_count += count;
4043 sge++;
4044 }
4045
4046 sge--;
4047 /* hba wants the size to be exact */
4048 if (byte_count > scsi_bufflen(scsicmd)) {
4049 u32 temp;
4050
4051 temp = le32_to_cpu(sge->len) - byte_count
4052 - scsi_bufflen(scsicmd);
4053 sge->len = cpu_to_le32(temp);
4054 byte_count = scsi_bufflen(scsicmd);
4055 }
4056
4057 if (nseg <= HBA_MAX_SG_EMBEDDED) {
4058 hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
4059 sge->flags = cpu_to_le32(0x40000000);
4060 } else {
4061 /* not embedded */
4062 hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
4063 hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
4064 hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
4065 hbacmd->sge[0].addr_lo =
4066 cpu_to_le32((u32)(sg_address & 0xffffffff));
4067 }
4068
4069 /* Check for command underflow */
4070 if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
4071 pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
4072 byte_count, scsicmd->underflow);
4073 }
4074out:
4075 return byte_count;
4076}
4077
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078#ifdef AAC_DETAILED_STATUS_INFO
4079
4080struct aac_srb_status_info {
4081 u32 status;
4082 char *str;
4083};
4084
4085
4086static struct aac_srb_status_info srb_status_info[] = {
4087 { SRB_STATUS_PENDING, "Pending Status"},
4088 { SRB_STATUS_SUCCESS, "Success"},
4089 { SRB_STATUS_ABORTED, "Aborted Command"},
4090 { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
Tobias Klauser6391a112006-06-08 22:23:48 -07004091 { SRB_STATUS_ERROR, "Error Event"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 { SRB_STATUS_BUSY, "Device Busy"},
4093 { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
4094 { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
4095 { SRB_STATUS_NO_DEVICE, "No Device"},
4096 { SRB_STATUS_TIMEOUT, "Timeout"},
4097 { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
4098 { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
4099 { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
4100 { SRB_STATUS_BUS_RESET, "Bus Reset"},
4101 { SRB_STATUS_PARITY_ERROR, "Parity Error"},
4102 { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
4103 { SRB_STATUS_NO_HBA, "No HBA"},
4104 { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
4105 { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
4106 { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
4107 { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
4108 { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
4109 { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
Tobias Klauser6391a112006-06-08 22:23:48 -07004110 { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
4112 { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
4113 { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
4114 { SRB_STATUS_NOT_STARTED, "Not Started"},
4115 { SRB_STATUS_NOT_IN_USE, "Not In Use"},
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08004116 { SRB_STATUS_FORCE_ABORT, "Force Abort"},
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
4118 { 0xff, "Unknown Error"}
4119};
4120
4121char *aac_get_status_string(u32 status)
4122{
4123 int i;
4124
Tobias Klauser6391a112006-06-08 22:23:48 -07004125 for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
4126 if (srb_status_info[i].status == status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 return srb_status_info[i].str;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128
4129 return "Bad Status Code";
4130}
4131
4132#endif