blob: 789030c9dd26ac74f5f9e12a3122bf56682f4d5a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/moduleparam.h>
10#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/delay.h>
Christoph Hellwig39a11242006-02-14 18:46:22 +010012#include <linux/kthread.h>
Daniel Walkere1e82b62008-05-12 22:21:10 -070013#include <linux/mutex.h>
Andrew Vasquez3420d362009-10-13 15:16:45 -070014#include <linux/kobject.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Michael Hernandez56012362016-12-12 14:40:08 -080016#include <linux/blk-mq-pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <scsi/scsi_tcq.h>
18#include <scsi/scsicam.h>
19#include <scsi/scsi_transport.h>
20#include <scsi/scsi_transport_fc.h>
21
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040022#include "qla_target.h"
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/*
25 * Driver version
26 */
27char qla2x00_version_str[40];
28
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -070029static int apidev_major;
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031/*
32 * SRB allocation cache
33 */
Michael Hernandezd7459522016-12-12 14:40:07 -080034struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Giridhar Malavalia9083012010-04-12 17:59:55 -070036/*
37 * CT6 CTX allocation cache
38 */
39static struct kmem_cache *ctx_cachep;
Saurav Kashyap3ce88662011-07-14 12:00:12 -070040/*
41 * error level for logging
42 */
43int ql_errlev = ql_log_all;
Giridhar Malavalia9083012010-04-12 17:59:55 -070044
Saurav Kashyapfa492632012-11-21 02:40:29 -050045static int ql2xenableclass2;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040046module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
47MODULE_PARM_DESC(ql2xenableclass2,
48 "Specify if Class 2 operations are supported from the very "
49 "beginning. Default is 0 - class 2 not supported.");
50
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052int ql2xlogintimeout = 20;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080053module_param(ql2xlogintimeout, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054MODULE_PARM_DESC(ql2xlogintimeout,
55 "Login timeout value in seconds.");
56
Andrew Vasqueza7b61842007-05-07 07:42:59 -070057int qlport_down_retry;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080058module_param(qlport_down_retry, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070060 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 "a PORT-DOWN status.");
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063int ql2xplogiabsentdevice;
64module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
65MODULE_PARM_DESC(ql2xplogiabsentdevice,
66 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070067 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070int ql2xloginretrycount = 0;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080071module_param(ql2xloginretrycount, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072MODULE_PARM_DESC(ql2xloginretrycount,
73 "Specify an alternate value for the NVRAM login retry count.");
74
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070075int ql2xallocfwdump = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080076module_param(ql2xallocfwdump, int, S_IRUGO);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070077MODULE_PARM_DESC(ql2xallocfwdump,
78 "Option to enable allocation of memory for a firmware dump "
79 "during HBA initialization. Memory allocation requirements "
80 "vary by ISP type. Default is 1 - allocate memory.");
81
Andrew Vasquez11010fe2006-10-06 09:54:59 -070082int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070083module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -040084module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070085MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070086 "Option to enable extended error logging,\n"
87 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
88 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
89 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
90 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
91 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
92 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
93 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
94 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
Chad Dupuis29f9f902012-11-21 02:40:41 -050095 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
96 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070097 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -080098 "\t\t0x1e400000 - Preferred value for capturing essential "
99 "debug information (equivalent to old "
100 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -0700101 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -0700102
Giridhar Malavalia9083012010-04-12 17:59:55 -0700103int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800104module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700105MODULE_PARM_DESC(ql2xshiftctondsd,
106 "Set to control shifting of command type processing "
107 "based on total number of SG elements.");
108
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700109int ql2xfdmienable=1;
Himanshu Madhanide187df2014-09-25 05:16:50 -0400110module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400111module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700112MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100113 "Enables FDMI registrations. "
114 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700115
Michael Hernandezd213a4b2017-08-23 15:05:20 -0700116#define MAX_Q_DEPTH 64
Chad Dupuis50280c02013-10-30 03:38:14 -0400117static int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700118module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
119MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400120 "Maximum queue depth to set for each LUN. "
Michael Hernandezd213a4b2017-08-23 15:05:20 -0700121 "Default is 64.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700122
Duane Grigsbye84067d2017-06-21 13:48:43 -0700123#if (IS_ENABLED(CONFIG_NVME_FC))
124int ql2xenabledif;
125#else
Arun Easi9e522cd2012-08-22 14:21:31 -0400126int ql2xenabledif = 2;
Duane Grigsbye84067d2017-06-21 13:48:43 -0700127#endif
Arun Easi9e522cd2012-08-22 14:21:31 -0400128module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700129MODULE_PARM_DESC(ql2xenabledif,
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600130 " Enable T10-CRC-DIF:\n"
131 " Default is 2.\n"
132 " 0 -- No DIF Support\n"
133 " 1 -- Enable DIF for all types\n"
134 " 2 -- Enable DIF for all types, except Type 0.\n");
Arun Easibad75002010-05-04 15:01:30 -0700135
Duane Grigsbye84067d2017-06-21 13:48:43 -0700136#if (IS_ENABLED(CONFIG_NVME_FC))
137int ql2xnvmeenable = 1;
138#else
139int ql2xnvmeenable;
140#endif
141module_param(ql2xnvmeenable, int, 0644);
142MODULE_PARM_DESC(ql2xnvmeenable,
143 "Enables NVME support. "
144 "0 - no NVMe. Default is Y");
145
Arun Easi8cb20492011-08-16 11:29:22 -0700146int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700147module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
148MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700149 " Enable T10-CRC-DIF Error isolation by HBA:\n"
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600150 " Default is 2.\n"
Arun Easi8cb20492011-08-16 11:29:22 -0700151 " 0 -- Error isolation disabled\n"
152 " 1 -- Error isolation enabled only for DIX Type 0\n"
153 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700154
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700155int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800156module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700157MODULE_PARM_DESC(ql2xiidmaenable,
158 "Enables iIDMA settings "
159 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
160
Michael Hernandezd7459522016-12-12 14:40:07 -0800161int ql2xmqsupport = 1;
162module_param(ql2xmqsupport, int, S_IRUGO);
163MODULE_PARM_DESC(ql2xmqsupport,
164 "Enable on demand multiple queue pairs support "
165 "Default is 1 for supported. "
166 "Set it to 0 to turn off mq qpair support.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700167
168int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700169module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400170module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700171MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700172 "Option to specify location from which to load ISP firmware:.\n"
173 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700174 " interface.\n"
175 " 1 -- load firmware from flash.\n"
176 " 0 -- use default semantics.\n");
177
Andrew Vasquezae97c912010-02-18 10:07:28 -0800178int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800179module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800180MODULE_PARM_DESC(ql2xetsenable,
181 "Enables firmware ETS burst."
182 "Default is 0 - skip ETS enablement.");
183
Giridhar Malavali69078692010-05-28 15:08:28 -0700184int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700185module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700186MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700187 "Option to specify scheme for request queue posting.\n"
188 " 0 -- Regular doorbell.\n"
189 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700190
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700191int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800192module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700193MODULE_PARM_DESC(ql2xtargetreset,
194 "Enable target reset."
195 "Default is 1 - use hw defaults.");
196
Chad Dupuis4da26e12010-10-15 11:27:40 -0700197int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800198module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700199MODULE_PARM_DESC(ql2xgffidenable,
200 "Enables GFF_ID checks of port type. "
201 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700202
himanshu.madhani@cavium.com043dc1d2017-08-23 15:05:19 -0700203int ql2xasynctmfenable = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800204module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700205MODULE_PARM_DESC(ql2xasynctmfenable,
206 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
207 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700208
209int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700210module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700211MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700212 "Option to specify reset behaviour.\n"
213 " 0 (Default) -- Reset on failure.\n"
214 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700215
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200216uint64_t ql2xmaxlun = MAX_LUNS;
217module_param(ql2xmaxlun, ullong, S_IRUGO);
Andrew Vasquez82515922011-05-10 11:30:13 -0700218MODULE_PARM_DESC(ql2xmaxlun,
219 "Defines the maximum LU number to register with the SCSI "
220 "midlayer. Default is 65535.");
221
Giridhar Malavali08de2842011-08-16 11:31:44 -0700222int ql2xmdcapmask = 0x1F;
223module_param(ql2xmdcapmask, int, S_IRUGO);
224MODULE_PARM_DESC(ql2xmdcapmask,
225 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800226 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700227
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800228int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700229module_param(ql2xmdenable, int, S_IRUGO);
230MODULE_PARM_DESC(ql2xmdenable,
231 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800232 "0 - MiniDump disabled. "
233 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700234
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500235int ql2xexlogins = 0;
236module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
237MODULE_PARM_DESC(ql2xexlogins,
238 "Number of extended Logins. "
239 "0 (Default)- Disabled.");
240
Quinn Tran99e1b682017-06-02 09:12:03 -0700241int ql2xexchoffld = 1024;
242module_param(ql2xexchoffld, uint, 0644);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500243MODULE_PARM_DESC(ql2xexchoffld,
Quinn Tran99e1b682017-06-02 09:12:03 -0700244 "Number of target exchanges.");
245
246int ql2xiniexchg = 1024;
247module_param(ql2xiniexchg, uint, 0644);
248MODULE_PARM_DESC(ql2xiniexchg,
249 "Number of initiator exchanges.");
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500250
Himanshu Madhanif198caf2016-01-27 12:03:30 -0500251int ql2xfwholdabts = 0;
252module_param(ql2xfwholdabts, int, S_IRUGO);
253MODULE_PARM_DESC(ql2xfwholdabts,
254 "Allow FW to hold status IOCB until ABTS rsp received. "
255 "0 (Default) Do not set fw option. "
256 "1 - Set fw option to hold ABTS.");
257
Quinn Tran41dc5292017-01-19 22:28:03 -0800258int ql2xmvasynctoatio = 1;
259module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
260MODULE_PARM_DESC(ql2xmvasynctoatio,
261 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
262 "0 (Default). Do not move IOCBs"
263 "1 - Move IOCBs.");
264
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700265int ql2xautodetectsfp = 1;
266module_param(ql2xautodetectsfp, int, 0444);
267MODULE_PARM_DESC(ql2xautodetectsfp,
268 "Detect SFP range and set appropriate distance.\n"
269 "1 (Default): Enable\n");
270
Himanshu Madhanie7240af2017-10-13 09:34:03 -0700271int ql2xenablemsix = 1;
272module_param(ql2xenablemsix, int, 0444);
273MODULE_PARM_DESC(ql2xenablemsix,
274 "Set to enable MSI or MSI-X interrupt mechanism.\n"
275 " Default is 1, enable MSI-X interrupt mechanism.\n"
276 " 0 -- enable traditional pin-based mechanism.\n"
277 " 1 -- enable MSI-X interrupt mechanism.\n"
278 " 2 -- enable MSI interrupt mechanism.\n");
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700281 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 */
283static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500284static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800285static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
286static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500287static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500288static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289static int qla2xxx_eh_abort(struct scsi_cmnd *);
290static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700291static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
293static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400295static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400296static void qla2x00_free_device(scsi_qla_host_t *);
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -0400297static void qla83xx_disable_laser(scsi_qla_host_t *vha);
Michael Hernandez56012362016-12-12 14:40:08 -0800298static int qla2xxx_map_queues(struct Scsi_Host *shost);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700299static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700300
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700301struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700303 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700304 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700305
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100306 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700307 .eh_abort_handler = qla2xxx_eh_abort,
308 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700309 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700310 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
311 .eh_host_reset_handler = qla2xxx_eh_host_reset,
312
313 .slave_configure = qla2xxx_slave_configure,
314
315 .slave_alloc = qla2xxx_slave_alloc,
316 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700317 .scan_finished = qla2xxx_scan_finished,
318 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100319 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800320 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700321 .this_id = -1,
322 .cmd_per_lun = 3,
323 .use_clustering = ENABLE_CLUSTERING,
324 .sg_tablesize = SG_ALL,
325
326 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700327 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400328
329 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100330 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700331};
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700334struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336/* TODO Convert to inlines
337 *
338 * Timer routines
339 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700341__inline__ void
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700342qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700344 timer_setup(&vha->timer, qla2x00_timer, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800345 vha->timer.expires = jiffies + interval * HZ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800346 add_timer(&vha->timer);
347 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348}
349
350static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800351qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700353 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700354 if (vha->device_flags & DFLG_DEV_FAILED) {
355 ql_dbg(ql_dbg_timer, vha, 0x600d,
356 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700357 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700358 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700359
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800360 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
Adrian Bunka824ebb2008-01-17 09:02:15 -0800363static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800364qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800366 del_timer_sync(&vha->timer);
367 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370static int qla2x00_do_dpc(void *data);
371
372static void qla2x00_rst_aen(scsi_qla_host_t *);
373
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800374static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
375 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700376static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800377static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800378int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
379 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700382static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
383 struct rsp_que *rsp)
384{
385 struct qla_hw_data *ha = vha->hw;
386 rsp->qpair = ha->base_qpair;
387 rsp->req = req;
388 ha->base_qpair->req = req;
389 ha->base_qpair->rsp = rsp;
390 ha->base_qpair->vha = vha;
391 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
392 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
393 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
394 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
Duane Grigsbycf19c452017-08-23 15:04:58 -0700395 INIT_LIST_HEAD(&ha->base_qpair->nvme_done_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700396 ha->base_qpair->enable_class_2 = ql2xenableclass2;
397 /* init qpair to this cpu. Will adjust at run time. */
Bart Van Assche86531882017-11-06 11:59:05 -0800398 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700399 ha->base_qpair->pdev = ha->pdev;
400
401 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
402 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
403}
404
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400405static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
406 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800407{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700408 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700409 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800410 GFP_KERNEL);
411 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700412 ql_log(ql_log_fatal, vha, 0x003b,
413 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800414 goto fail_req_map;
415 }
416
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700417 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800418 GFP_KERNEL);
419 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700420 ql_log(ql_log_fatal, vha, 0x003c,
421 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800422 goto fail_rsp_map;
423 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800424
Quinn Trane326d222017-06-13 20:47:18 -0700425 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
426 if (ha->base_qpair == NULL) {
427 ql_log(ql_log_warn, vha, 0x00e0,
428 "Failed to allocate base queue pair memory.\n");
429 goto fail_base_qpair;
430 }
431
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700432 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700433
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -0700434 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -0800435 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
436 GFP_KERNEL);
437 if (!ha->queue_pair_map) {
438 ql_log(ql_log_fatal, vha, 0x0180,
439 "Unable to allocate memory for queue pair ptrs.\n");
440 goto fail_qpair_map;
441 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800442 }
443
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400444 /*
445 * Make sure we record at least the request and response queue zero in
446 * case we need to free them if part of the probe fails.
447 */
448 ha->rsp_q_map[0] = rsp;
449 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800450 set_bit(0, ha->rsp_qid_map);
451 set_bit(0, ha->req_qid_map);
452 return 1;
453
Michael Hernandezd7459522016-12-12 14:40:07 -0800454fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700455 kfree(ha->base_qpair);
456 ha->base_qpair = NULL;
457fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800458 kfree(ha->rsp_q_map);
459 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800460fail_rsp_map:
461 kfree(ha->req_q_map);
462 ha->req_q_map = NULL;
463fail_req_map:
464 return -ENOMEM;
465}
466
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700467static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800468{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400469 if (IS_QLAFX00(ha)) {
470 if (req && req->ring_fx00)
471 dma_free_coherent(&ha->pdev->dev,
472 (req->length_fx00 + 1) * sizeof(request_t),
473 req->ring_fx00, req->dma_fx00);
474 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800475 dma_free_coherent(&ha->pdev->dev,
476 (req->length + 1) * sizeof(request_t),
477 req->ring, req->dma);
478
Chad Dupuis8d93f552013-01-30 03:34:37 -0500479 if (req)
480 kfree(req->outstanding_cmds);
481
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800482 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800483}
484
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700485static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
486{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400487 if (IS_QLAFX00(ha)) {
488 if (rsp && rsp->ring)
489 dma_free_coherent(&ha->pdev->dev,
490 (rsp->length_fx00 + 1) * sizeof(request_t),
491 rsp->ring_fx00, rsp->dma_fx00);
492 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700493 dma_free_coherent(&ha->pdev->dev,
494 (rsp->length + 1) * sizeof(response_t),
495 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400496 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700497 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700498}
499
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800500static void qla2x00_free_queues(struct qla_hw_data *ha)
501{
502 struct req_que *req;
503 struct rsp_que *rsp;
504 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800505 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800506
Quinn Tran82de8022017-06-13 20:47:17 -0700507 if (ha->queue_pair_map) {
508 kfree(ha->queue_pair_map);
509 ha->queue_pair_map = NULL;
510 }
511 if (ha->base_qpair) {
512 kfree(ha->base_qpair);
513 ha->base_qpair = NULL;
514 }
515
Quinn Tran093df732016-12-12 14:40:09 -0800516 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700517 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500518 if (!test_bit(cnt, ha->req_qid_map))
519 continue;
520
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800521 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800522 clear_bit(cnt, ha->req_qid_map);
523 ha->req_q_map[cnt] = NULL;
524
525 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700526 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800527 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700528 }
Quinn Tran093df732016-12-12 14:40:09 -0800529 spin_unlock_irqrestore(&ha->hardware_lock, flags);
530
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700531 kfree(ha->req_q_map);
532 ha->req_q_map = NULL;
533
Quinn Tran093df732016-12-12 14:40:09 -0800534
535 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700536 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500537 if (!test_bit(cnt, ha->rsp_qid_map))
538 continue;
539
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700540 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c42392016-12-27 13:13:21 -0500541 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800542 ha->rsp_q_map[cnt] = NULL;
543 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700544 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800545 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800546 }
Quinn Tran093df732016-12-12 14:40:09 -0800547 spin_unlock_irqrestore(&ha->hardware_lock, flags);
548
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800549 kfree(ha->rsp_q_map);
550 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800551}
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800556 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 static char *pci_bus_modes[] = {
558 "33", "66", "100", "133",
559 };
560 uint16_t pci_bus;
561
562 strcpy(str, "PCI");
563 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
564 if (pci_bus) {
565 strcat(str, "-X (");
566 strcat(str, pci_bus_modes[pci_bus]);
567 } else {
568 pci_bus = (ha->pci_attr & BIT_8) >> 8;
569 strcat(str, " (");
570 strcat(str, pci_bus_modes[pci_bus]);
571 }
572 strcat(str, " MHz)");
573
574 return (str);
575}
576
Andrew Vasquezfca29702005-07-06 10:31:47 -0700577static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800578qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700579{
580 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800581 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700582 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700583
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600584 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700585 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600586 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700587
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600588 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
589 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
590 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700591
592 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500593 switch (lspeed) {
594 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700595 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500596 break;
597 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700598 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500599 break;
600 case 3:
601 strcat(str, "8.0GT/s ");
602 break;
603 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700604 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500605 break;
606 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700607 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
608 strcat(str, lwstr);
609
610 return str;
611 }
612
613 strcpy(str, "PCI");
614 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
615 if (pci_bus == 0 || pci_bus == 8) {
616 strcat(str, " (");
617 strcat(str, pci_bus_modes[pci_bus >> 3]);
618 } else {
619 strcat(str, "-X ");
620 if (pci_bus & BIT_2)
621 strcat(str, "Mode 2");
622 else
623 strcat(str, "Mode 1");
624 strcat(str, " (");
625 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
626 }
627 strcat(str, " MHz)");
628
629 return str;
630}
631
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800632static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400633qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
635 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800636 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700637
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400638 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
639 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 if (ha->fw_attributes & BIT_9) {
642 strcat(str, "FLX");
643 return (str);
644 }
645
646 switch (ha->fw_attributes & 0xFF) {
647 case 0x7:
648 strcat(str, "EF");
649 break;
650 case 0x17:
651 strcat(str, "TP");
652 break;
653 case 0x37:
654 strcat(str, "IP");
655 break;
656 case 0x77:
657 strcat(str, "VI");
658 break;
659 default:
660 sprintf(un_str, "(%x)", ha->fw_attributes);
661 strcat(str, un_str);
662 break;
663 }
664 if (ha->fw_attributes & 0x100)
665 strcat(str, "X");
666
667 return (str);
668}
669
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800670static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400671qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700672{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800673 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700674
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400675 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800676 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700677 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700678}
679
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800680void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800681qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700682{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800683 srb_t *sp = ptr;
684 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800685 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800686 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700687
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800688 if (sp->flags & SRB_DMA_VALID) {
689 scsi_dma_unmap(cmd);
690 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700692
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800693 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
694 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
695 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
696 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
697 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700698
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700699 if (!ctx)
700 goto end;
701
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800702 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
703 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700704 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800705 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
706 }
707
708 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700709 struct crc_context *ctx0 = ctx;
710
711 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800712 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
713 }
714
715 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700716 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800717
718 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700719 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800720 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
721 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
722 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
723 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800724 }
725
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700726end:
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -0700727 if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) {
Duane Grigsby7401bc12017-06-21 13:48:42 -0700728 CMD_SP(cmd) = NULL;
729 qla2x00_rel_sp(sp);
730 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800731}
732
Michael Hernandezd7459522016-12-12 14:40:07 -0800733void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800734qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800735{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800736 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800737 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
738
739 cmd->result = res;
740
741 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800742 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800743 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
744 sp, GET_CMD_SP(sp));
745 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400746 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800747 return;
748 }
749 if (!atomic_dec_and_test(&sp->ref_count))
750 return;
751
Joe Carnucciof3caa992017-08-23 15:05:09 -0700752 sp->free(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800753 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700754}
755
Michael Hernandezd7459522016-12-12 14:40:07 -0800756void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800757qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800758{
759 srb_t *sp = (srb_t *)ptr;
760 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
761 struct qla_hw_data *ha = sp->fcport->vha->hw;
762 void *ctx = GET_CMD_CTX_SP(sp);
763
764 if (sp->flags & SRB_DMA_VALID) {
765 scsi_dma_unmap(cmd);
766 sp->flags &= ~SRB_DMA_VALID;
767 }
768
769 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
770 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
771 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
772 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
773 }
774
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700775 if (!ctx)
776 goto end;
777
Michael Hernandezd7459522016-12-12 14:40:07 -0800778 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
779 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700780 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800781 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
782 }
783
784 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700785 struct crc_context *ctx0 = ctx;
786
787 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800788 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
789 }
790
791 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700792 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800793 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
794 ctx1->fcp_cmnd_dma);
795 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
796 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
797 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
798 mempool_free(ctx1, ha->ctx_mempool);
799 }
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700800end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800801 CMD_SP(cmd) = NULL;
802 qla2xxx_rel_qpair_sp(sp->qpair, sp);
803}
804
805void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800806qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800807{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800808 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800809 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
810
811 cmd->result = res;
812
813 if (atomic_read(&sp->ref_count) == 0) {
814 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
815 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
816 sp, GET_CMD_SP(sp));
817 if (ql2xextended_error_logging & ql_dbg_io)
818 WARN_ON(atomic_read(&sp->ref_count) == 0);
819 return;
820 }
821 if (!atomic_dec_and_test(&sp->ref_count))
822 return;
823
Joe Carnucciof3caa992017-08-23 15:05:09 -0700824 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800825 cmd->scsi_done(cmd);
826}
827
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400828/* If we are SP1 here, we need to still take and release the host_lock as SP1
829 * does not have the changes necessary to avoid taking host->host_lock.
830 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800832qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700833{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700834 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700835 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400836 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800837 struct qla_hw_data *ha = vha->hw;
838 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700839 srb_t *sp;
840 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800841 struct qla_qpair *qpair = NULL;
842 uint32_t tag;
843 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700844
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200845 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
846 cmd->result = DID_NO_CONNECT << 16;
847 goto qc24_fail_command;
848 }
849
Michael Hernandez56012362016-12-12 14:40:08 -0800850 if (ha->mqenable) {
851 if (shost_use_blk_mq(vha->host)) {
852 tag = blk_mq_unique_tag(cmd->request);
853 hwq = blk_mq_unique_tag_to_hwq(tag);
854 qpair = ha->queue_pair_map[hwq];
855 } else if (vha->vp_idx && vha->qpair) {
856 qpair = vha->qpair;
857 }
858
859 if (qpair)
860 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800861 }
862
Andrew Vasquez85880802009-12-15 21:29:46 -0800863 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700864 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400865 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700866 "PCI Channel IO permanent failure, exiting "
867 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700868 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700869 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400870 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700871 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800872 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700873 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700874 goto qc24_fail_command;
875 }
876
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400877 rval = fc_remote_port_chkready(rport);
878 if (rval) {
879 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400880 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700881 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
882 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700883 goto qc24_fail_command;
884 }
885
Arun Easibad75002010-05-04 15:01:30 -0700886 if (!vha->flags.difdix_supported &&
887 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700888 ql_dbg(ql_dbg_io, vha, 0x3004,
889 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
890 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700891 cmd->result = DID_NO_CONNECT << 16;
892 goto qc24_fail_command;
893 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800894
895 if (!fcport) {
896 cmd->result = DID_NO_CONNECT << 16;
897 goto qc24_fail_command;
898 }
899
Andrew Vasquezfca29702005-07-06 10:31:47 -0700900 if (atomic_read(&fcport->state) != FCS_ONLINE) {
901 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700902 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700903 ql_dbg(ql_dbg_io, vha, 0x3005,
904 "Returning DNC, fcport_state=%d loop_state=%d.\n",
905 atomic_read(&fcport->state),
906 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700907 cmd->result = DID_NO_CONNECT << 16;
908 goto qc24_fail_command;
909 }
Mike Christie7b594132008-08-17 15:24:40 -0500910 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700911 }
912
Chad Dupuise05fe292014-09-25 05:16:59 -0400913 /*
914 * Return target busy if we've received a non-zero retry_delay_timer
915 * in a FCP_RSP.
916 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100917 if (fcport->retry_delay_timestamp == 0) {
918 /* retry delay not set */
919 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400920 fcport->retry_delay_timestamp = 0;
921 else
922 goto qc24_target_busy;
923
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500924 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400925 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800926 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700927
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800928 sp->u.scmd.cmd = cmd;
929 sp->type = SRB_SCSI_CMD;
930 atomic_set(&sp->ref_count, 1);
931 CMD_SP(cmd) = (void *)sp;
932 sp->free = qla2x00_sp_free_dma;
933 sp->done = qla2x00_sp_compl;
934
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800935 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700936 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500937 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700938 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700939 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700940 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700941
Andrew Vasquezfca29702005-07-06 10:31:47 -0700942 return 0;
943
944qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700945 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700946
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800947qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700948 return SCSI_MLQUEUE_HOST_BUSY;
949
Mike Christie7b594132008-08-17 15:24:40 -0500950qc24_target_busy:
951 return SCSI_MLQUEUE_TARGET_BUSY;
952
Andrew Vasquezfca29702005-07-06 10:31:47 -0700953qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800954 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700955
956 return 0;
957}
958
Michael Hernandezd7459522016-12-12 14:40:07 -0800959/* For MQ supported I/O */
960int
961qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
962 struct qla_qpair *qpair)
963{
964 scsi_qla_host_t *vha = shost_priv(host);
965 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
966 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
967 struct qla_hw_data *ha = vha->hw;
968 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
969 srb_t *sp;
970 int rval;
971
972 rval = fc_remote_port_chkready(rport);
973 if (rval) {
974 cmd->result = rval;
975 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
976 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
977 cmd, rval);
978 goto qc24_fail_command;
979 }
980
981 if (!fcport) {
982 cmd->result = DID_NO_CONNECT << 16;
983 goto qc24_fail_command;
984 }
985
986 if (atomic_read(&fcport->state) != FCS_ONLINE) {
987 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
988 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
989 ql_dbg(ql_dbg_io, vha, 0x3077,
990 "Returning DNC, fcport_state=%d loop_state=%d.\n",
991 atomic_read(&fcport->state),
992 atomic_read(&base_vha->loop_state));
993 cmd->result = DID_NO_CONNECT << 16;
994 goto qc24_fail_command;
995 }
996 goto qc24_target_busy;
997 }
998
999 /*
1000 * Return target busy if we've received a non-zero retry_delay_timer
1001 * in a FCP_RSP.
1002 */
1003 if (fcport->retry_delay_timestamp == 0) {
1004 /* retry delay not set */
1005 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1006 fcport->retry_delay_timestamp = 0;
1007 else
1008 goto qc24_target_busy;
1009
1010 sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
1011 if (!sp)
1012 goto qc24_host_busy;
1013
1014 sp->u.scmd.cmd = cmd;
1015 sp->type = SRB_SCSI_CMD;
1016 atomic_set(&sp->ref_count, 1);
1017 CMD_SP(cmd) = (void *)sp;
1018 sp->free = qla2xxx_qpair_sp_free_dma;
1019 sp->done = qla2xxx_qpair_sp_compl;
1020 sp->qpair = qpair;
1021
1022 rval = ha->isp_ops->start_scsi_mq(sp);
1023 if (rval != QLA_SUCCESS) {
1024 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1025 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1026 if (rval == QLA_INTERFACE_ERROR)
1027 goto qc24_fail_command;
1028 goto qc24_host_busy_free_sp;
1029 }
1030
1031 return 0;
1032
1033qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001034 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001035
1036qc24_host_busy:
1037 return SCSI_MLQUEUE_HOST_BUSY;
1038
1039qc24_target_busy:
1040 return SCSI_MLQUEUE_TARGET_BUSY;
1041
1042qc24_fail_command:
1043 cmd->scsi_done(cmd);
1044
1045 return 0;
1046}
1047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048/*
1049 * qla2x00_eh_wait_on_command
1050 * Waits for the command to be returned by the Firmware for some
1051 * max time.
1052 *
1053 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 *
1056 * Return:
1057 * Not Found : 0
1058 * Found : 1
1059 */
1060static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001061qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001063#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001064#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001065 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001066 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1067 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001068 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Andrew Vasquez85880802009-12-15 21:29:46 -08001070 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001071 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1072 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001073 return ret;
1074 }
1075
Lalit Chandivaded9704322009-08-25 11:36:18 -07001076 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001077 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001078 }
1079 if (CMD_SP(cmd))
1080 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
f4f051e2005-04-17 15:02:26 -05001082 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
1085/*
1086 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001087 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 * <= MAX_RETRIES_OF_ISP_ABORT or
1089 * finally HBA is disabled ie marked offline
1090 *
1091 * Input:
1092 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001093 *
1094 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 * Does context switching-Release SPIN_LOCK
1096 * (if any) before calling this routine.
1097 *
1098 * Return:
1099 * Success (Adapter is online) : 0
1100 * Failed (Adapter is offline/disabled) : 1
1101 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001102int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001103qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001105 int return_status;
1106 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001107 struct qla_hw_data *ha = vha->hw;
1108 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001110 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001111 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1112 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1113 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1114 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116 msleep(1000);
1117 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001118 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001119 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 else
1121 return_status = QLA_FUNCTION_FAILED;
1122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 return (return_status);
1124}
1125
Quinn Tran726b8542017-01-19 22:28:00 -08001126static inline int test_fcport_count(scsi_qla_host_t *vha)
1127{
1128 struct qla_hw_data *ha = vha->hw;
1129 unsigned long flags;
1130 int res;
1131
1132 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001133 ql_dbg(ql_dbg_init, vha, 0x00ec,
1134 "tgt %p, fcport_count=%d\n",
1135 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001136 res = (vha->fcport_count == 0);
1137 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1138
1139 return res;
1140}
1141
1142/*
1143 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1144 * it has dependency on UNLOADING flag to stop device discovery
1145 */
1146static void
1147qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1148{
1149 qla2x00_mark_all_devices_lost(vha, 0);
1150
Joe Carnucciob85e0952017-08-23 15:05:11 -07001151 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001152}
1153
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001154/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001155 * qla2x00_wait_for_hba_ready
1156 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001157 *
1158 * Input:
1159 * ha - pointer to host adapter structure
1160 *
1161 * Note:
1162 * Does context switching-Release SPIN_LOCK
1163 * (if any) before calling this routine.
1164 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001165 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001166static void
1167qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001168{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001169 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001170 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001171
Dan Carpenter1d483902016-08-03 21:42:32 +03001172 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1173 ha->flags.mbox_busy) ||
1174 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1175 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1176 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1177 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001178 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001179 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001180}
1181
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001182int
1183qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1184{
1185 int return_status;
1186 unsigned long wait_reset;
1187 struct qla_hw_data *ha = vha->hw;
1188 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1189
1190 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1191 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1192 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1193 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1194 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1195
1196 msleep(1000);
1197
1198 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1199 ha->flags.chip_reset_done)
1200 break;
1201 }
1202 if (ha->flags.chip_reset_done)
1203 return_status = QLA_SUCCESS;
1204 else
1205 return_status = QLA_FUNCTION_FAILED;
1206
1207 return return_status;
1208}
1209
Giridhar Malavali083a4692010-05-28 15:08:18 -07001210static void
1211sp_get(struct srb *sp)
1212{
1213 atomic_inc(&sp->ref_count);
1214}
1215
Sawan Chandaka4655372016-07-06 11:14:32 -04001216#define ISP_REG_DISCONNECT 0xffffffffU
1217/**************************************************************************
1218* qla2x00_isp_reg_stat
1219*
1220* Description:
1221* Read the host status register of ISP before aborting the command.
1222*
1223* Input:
1224* ha = pointer to host adapter structure.
1225*
1226*
1227* Returns:
1228* Either true or false.
1229*
1230* Note: Return true if there is register disconnect.
1231**************************************************************************/
1232static inline
1233uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1234{
1235 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001236 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001237
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001238 if (IS_P3P_TYPE(ha))
1239 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1240 else
1241 return ((RD_REG_DWORD(&reg->host_status)) ==
1242 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001243}
1244
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245/**************************************************************************
1246* qla2xxx_eh_abort
1247*
1248* Description:
1249* The abort function will abort the specified command.
1250*
1251* Input:
1252* cmd = Linux SCSI command packet to be aborted.
1253*
1254* Returns:
1255* Either SUCCESS or FAILED.
1256*
1257* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001258* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001260static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1262{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001263 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001264 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001265 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001266 unsigned int id;
1267 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001268 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001269 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001270 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Sawan Chandaka4655372016-07-06 11:14:32 -04001272 if (qla2x00_isp_reg_stat(ha)) {
1273 ql_log(ql_log_info, vha, 0x8042,
1274 "PCI/Register disconnect, exiting.\n");
1275 return FAILED;
1276 }
f4f051e2005-04-17 15:02:26 -05001277 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -07001278 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001280 ret = fc_block_scsi_eh(cmd);
1281 if (ret != 0)
1282 return ret;
1283 ret = SUCCESS;
1284
f4f051e2005-04-17 15:02:26 -05001285 id = cmd->device->id;
1286 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001287
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001289 sp = (srb_t *) CMD_SP(cmd);
1290 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001291 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001292 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001293 }
Mike Christie170babc2010-10-15 11:27:47 -07001294
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001295 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001296 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1297 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001298
1299 /* Get a reference to the sp and drop the lock.*/
1300 sp_get(sp);
1301
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001302 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001303 rval = ha->isp_ops->abort_command(sp);
1304 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001305 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001306 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001307 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001308 ret = FAILED;
1309
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001310 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001311 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001312 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001313 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001314 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001315 wait = 1;
1316 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001317
1318 spin_lock_irqsave(&ha->hardware_lock, flags);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001319 sp->done(sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -07001320 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -05001321
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001322 /* Did the command return during mailbox execution? */
1323 if (ret == FAILED && !CMD_SP(cmd))
1324 ret = SUCCESS;
1325
f4f051e2005-04-17 15:02:26 -05001326 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001327 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001328 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001329 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001330 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001331 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001335 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001336 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001337 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
f4f051e2005-04-17 15:02:26 -05001339 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001342int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001343qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001344 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001346 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001347 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001349 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001350 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001351 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Andrew Vasquez523ec772008-04-03 13:13:24 -07001353 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001354
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001355 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001356 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001357 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001358 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001359 sp = req->outstanding_cmds[cnt];
1360 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001361 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001362 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001363 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001364 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001365 continue;
1366 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001367 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001368 switch (type) {
1369 case WAIT_HOST:
1370 match = 1;
1371 break;
1372 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001373 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001374 break;
1375 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001376 match = (cmd->device->id == t &&
1377 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001378 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001380 if (!match)
1381 continue;
1382
1383 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001384 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001385 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001387 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001388
1389 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390}
1391
Andrew Vasquez523ec772008-04-03 13:13:24 -07001392static char *reset_errors[] = {
1393 "HBA not online",
1394 "HBA not ready",
1395 "Task management failed",
1396 "Waiting for command completions",
1397};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Andrew Vasquez523ec772008-04-03 13:13:24 -07001399static int
1400__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001401 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001402{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001403 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001404 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1405 int err;
1406
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001407 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001408 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001409 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001410
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001411 err = fc_block_scsi_eh(cmd);
1412 if (err != 0)
1413 return err;
1414
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001415 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001416 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001417 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001418
1419 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001420 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1421 ql_log(ql_log_warn, vha, 0x800a,
1422 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001423 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001424 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001425 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001426 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001427 != QLA_SUCCESS) {
1428 ql_log(ql_log_warn, vha, 0x800c,
1429 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001430 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001431 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001432 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001433 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001434 cmd->device->lun, type) != QLA_SUCCESS) {
1435 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001436 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001437 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001438 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001439
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001440 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001441 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001442 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001443
1444 return SUCCESS;
1445
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001446eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001447 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001448 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001449 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1450 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001451 return FAILED;
1452}
1453
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001454static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1456{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1458 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Sawan Chandaka4655372016-07-06 11:14:32 -04001460 if (qla2x00_isp_reg_stat(ha)) {
1461 ql_log(ql_log_info, vha, 0x803e,
1462 "PCI/Register disconnect, exiting.\n");
1463 return FAILED;
1464 }
1465
Andrew Vasquez523ec772008-04-03 13:13:24 -07001466 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1467 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468}
1469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001471qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001473 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1474 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Sawan Chandaka4655372016-07-06 11:14:32 -04001476 if (qla2x00_isp_reg_stat(ha)) {
1477 ql_log(ql_log_info, vha, 0x803f,
1478 "PCI/Register disconnect, exiting.\n");
1479 return FAILED;
1480 }
1481
Andrew Vasquez523ec772008-04-03 13:13:24 -07001482 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1483 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484}
1485
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486/**************************************************************************
1487* qla2xxx_eh_bus_reset
1488*
1489* Description:
1490* The bus reset function will reset the bus and abort any executing
1491* commands.
1492*
1493* Input:
1494* cmd = Linux SCSI command packet of the command that cause the
1495* bus reset.
1496*
1497* Returns:
1498* SUCCESS/FAILURE (defined as macro in scsi.h).
1499*
1500**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001501static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1503{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001504 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001505 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001506 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001507 unsigned int id;
1508 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001509 struct qla_hw_data *ha = vha->hw;
1510
1511 if (qla2x00_isp_reg_stat(ha)) {
1512 ql_log(ql_log_info, vha, 0x8040,
1513 "PCI/Register disconnect, exiting.\n");
1514 return FAILED;
1515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
f4f051e2005-04-17 15:02:26 -05001517 id = cmd->device->id;
1518 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001519
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001520 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001521 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001524 ret = fc_block_scsi_eh(cmd);
1525 if (ret != 0)
1526 return ret;
1527 ret = FAILED;
1528
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001529 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001530 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001533 ql_log(ql_log_fatal, vha, 0x8013,
1534 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001535 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 }
1537
Saurav Kashyapad5376892011-11-18 09:02:09 -08001538 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1539 ret = SUCCESS;
1540
f4f051e2005-04-17 15:02:26 -05001541 if (ret == FAILED)
1542 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001544 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001545 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001546 QLA_SUCCESS) {
1547 ql_log(ql_log_warn, vha, 0x8014,
1548 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001549 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
f4f051e2005-04-17 15:02:26 -05001552eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001553 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001554 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001555 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
f4f051e2005-04-17 15:02:26 -05001557 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
1560/**************************************************************************
1561* qla2xxx_eh_host_reset
1562*
1563* Description:
1564* The reset function will reset the Adapter.
1565*
1566* Input:
1567* cmd = Linux SCSI command packet of the command that cause the
1568* adapter reset.
1569*
1570* Returns:
1571* Either SUCCESS or FAILED.
1572*
1573* Note:
1574**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001575static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1577{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001578 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001579 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001580 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001581 unsigned int id;
1582 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001583 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Sawan Chandaka4655372016-07-06 11:14:32 -04001585 if (qla2x00_isp_reg_stat(ha)) {
1586 ql_log(ql_log_info, vha, 0x8041,
1587 "PCI/Register disconnect, exiting.\n");
1588 schedule_work(&ha->board_disable);
1589 return SUCCESS;
1590 }
1591
f4f051e2005-04-17 15:02:26 -05001592 id = cmd->device->id;
1593 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001594
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001595 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001596 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Chad Dupuis63ee7072014-04-11 16:54:46 -04001598 /*
1599 * No point in issuing another reset if one is active. Also do not
1600 * attempt a reset if we are updating flash.
1601 */
1602 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001603 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001605 if (vha != base_vha) {
1606 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001607 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001608 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001609 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001610 if (!qla82xx_fcoe_ctx_reset(vha)) {
1611 /* Ctx reset success */
1612 ret = SUCCESS;
1613 goto eh_host_reset_lock;
1614 }
1615 /* fall thru if ctx reset failed */
1616 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001617 if (ha->wq)
1618 flush_workqueue(ha->wq);
1619
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001620 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001621 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001622 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1623 /* failed. schedule dpc to try */
1624 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1625
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001626 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1627 ql_log(ql_log_warn, vha, 0x802a,
1628 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001629 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001630 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001631 }
1632 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001635 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001636 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001637 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001638 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
f4f051e2005-04-17 15:02:26 -05001640eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001641 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001642 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001643 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
f4f051e2005-04-17 15:02:26 -05001645 return ret;
1646}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648/*
1649* qla2x00_loop_reset
1650* Issue loop reset.
1651*
1652* Input:
1653* ha = adapter block pointer.
1654*
1655* Returns:
1656* 0 = success
1657*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001658int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001659qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001661 int ret;
bdf79622005-04-17 15:06:53 -05001662 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Armen Baloyan58547712013-08-27 01:37:33 -04001665 if (IS_QLAFX00(ha)) {
1666 return qlafx00_loop_reset(vha);
1667 }
1668
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001669 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001670 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1671 if (fcport->port_type != FCT_TARGET)
1672 continue;
1673
1674 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1675 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001676 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001677 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001678 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001679 }
1680 }
1681 }
1682
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001683
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001684 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001685 atomic_set(&vha->loop_state, LOOP_DOWN);
1686 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1687 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001688 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001689 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001690 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1691 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 }
1694
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001695 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001697 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001698 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1699 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001700 }
1701
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001703 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001705 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001708void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001709qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001710{
Bill Kuzeja4cd3b6e2017-05-25 15:26:31 -04001711 int que, cnt, status;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001712 unsigned long flags;
1713 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001714 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001715 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001716 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1717 struct qla_tgt_cmd *cmd;
1718 uint8_t trace = 0;
Arun Easic0cb4492014-09-25 06:14:51 -04001719
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001720 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001721 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001722 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001723 if (!req)
1724 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001725 if (!req->outstanding_cmds)
1726 continue;
1727 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001728 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001729 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001730 req->outstanding_cmds[cnt] = NULL;
Quinn Tranc5419e22017-06-13 20:47:16 -07001731 if (sp->cmd_type == TYPE_SRB) {
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -07001732 if (sp->type == SRB_NVME_CMD ||
1733 sp->type == SRB_NVME_LS) {
Duane Grigsbye84067d2017-06-21 13:48:43 -07001734 sp_get(sp);
1735 spin_unlock_irqrestore(
1736 &ha->hardware_lock, flags);
1737 qla_nvme_abort(ha, sp);
1738 spin_lock_irqsave(
1739 &ha->hardware_lock, flags);
1740 } else if (GET_CMD_SP(sp) &&
Quinn Tranc5419e22017-06-13 20:47:16 -07001741 !ha->flags.eeh_busy &&
Sawan Chandakd61cca62017-08-23 15:05:24 -07001742 (!test_bit(ABORT_ISP_ACTIVE,
1743 &vha->dpc_flags)) &&
Quinn Tranc5419e22017-06-13 20:47:16 -07001744 (sp->type == SRB_SCSI_CMD)) {
1745 /*
Duane Grigsbye84067d2017-06-21 13:48:43 -07001746 * Don't abort commands in
1747 * adapter during EEH
1748 * recovery as it's not
1749 * accessible/responding.
1750 *
Quinn Tranc5419e22017-06-13 20:47:16 -07001751 * Get a reference to the sp
1752 * and drop the lock. The
1753 * reference ensures this
1754 * sp->done() call and not the
1755 * call in qla2xxx_eh_abort()
1756 * ends the SCSI command (with
1757 * result 'res').
1758 */
1759 sp_get(sp);
1760 spin_unlock_irqrestore(
1761 &ha->hardware_lock, flags);
1762 status = qla2xxx_eh_abort(
1763 GET_CMD_SP(sp));
1764 spin_lock_irqsave(
1765 &ha->hardware_lock, flags);
1766 /*
1767 * Get rid of extra reference
1768 * if immediate exit from
1769 * ql2xxx_eh_abort
1770 */
1771 if (status == FAILED &&
1772 (qla2x00_isp_reg_stat(ha)))
1773 atomic_dec(
1774 &sp->ref_count);
1775 }
1776 sp->done(sp, res);
1777 } else {
1778 if (!vha->hw->tgt.tgt_ops || !tgt ||
1779 qla_ini_mode_enabled(vha)) {
1780 if (!trace)
1781 ql_dbg(ql_dbg_tgt_mgt,
1782 vha, 0xf003,
1783 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1784 vha->dpc_flags);
1785 continue;
1786 }
1787 cmd = (struct qla_tgt_cmd *)sp;
1788 qlt_abort_cmd_on_host_reset(cmd->vha,
1789 cmd);
1790 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001791 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001792 }
1793 }
1794 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1795}
1796
f4f051e2005-04-17 15:02:26 -05001797static int
1798qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799{
bdf79622005-04-17 15:06:53 -05001800 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001802 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001803 return -ENXIO;
1804
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001805 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001806
1807 return 0;
1808}
1809
1810static int
1811qla2xxx_slave_configure(struct scsi_device *sdev)
1812{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001813 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001814 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001815
Arun Easi9e522cd2012-08-22 14:21:31 -04001816 if (IS_T10_PI_CAPABLE(vha->hw))
1817 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1818
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001819 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001820 return 0;
1821}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
f4f051e2005-04-17 15:02:26 -05001823static void
1824qla2xxx_slave_destroy(struct scsi_device *sdev)
1825{
1826 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827}
1828
1829/**
1830 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1831 * @ha: HA context
1832 *
1833 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1834 * supported addressing method.
1835 */
1836static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001837qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001839 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
Yang Hongyang6a355282009-04-06 19:01:13 -07001842 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001843 /* Any upper-dword bits set? */
1844 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001845 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001846 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001848 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1849 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001850 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001853
Yang Hongyang284901a2009-04-06 19:01:15 -07001854 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1855 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856}
1857
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001858static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001859qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001860{
1861 unsigned long flags = 0;
1862 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1863
1864 spin_lock_irqsave(&ha->hardware_lock, flags);
1865 ha->interrupts_on = 1;
1866 /* enable risc and host interrupts */
1867 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1868 RD_REG_WORD(&reg->ictrl);
1869 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1870
1871}
1872
1873static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001875{
1876 unsigned long flags = 0;
1877 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1878
1879 spin_lock_irqsave(&ha->hardware_lock, flags);
1880 ha->interrupts_on = 0;
1881 /* disable risc and host interrupts */
1882 WRT_REG_WORD(&reg->ictrl, 0);
1883 RD_REG_WORD(&reg->ictrl);
1884 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1885}
1886
1887static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001888qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001889{
1890 unsigned long flags = 0;
1891 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1892
1893 spin_lock_irqsave(&ha->hardware_lock, flags);
1894 ha->interrupts_on = 1;
1895 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1896 RD_REG_DWORD(&reg->ictrl);
1897 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1898}
1899
1900static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001901qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001902{
1903 unsigned long flags = 0;
1904 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1905
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001906 if (IS_NOPOLLING_TYPE(ha))
1907 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001908 spin_lock_irqsave(&ha->hardware_lock, flags);
1909 ha->interrupts_on = 0;
1910 WRT_REG_DWORD(&reg->ictrl, 0);
1911 RD_REG_DWORD(&reg->ictrl);
1912 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1913}
1914
Giridhar Malavali706f4572011-11-18 09:03:16 -08001915static int
1916qla2x00_iospace_config(struct qla_hw_data *ha)
1917{
1918 resource_size_t pio;
1919 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001920
Giridhar Malavali706f4572011-11-18 09:03:16 -08001921 if (pci_request_selected_regions(ha->pdev, ha->bars,
1922 QLA2XXX_DRIVER_NAME)) {
1923 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1924 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1925 pci_name(ha->pdev));
1926 goto iospace_error_exit;
1927 }
1928 if (!(ha->bars & 1))
1929 goto skip_pio;
1930
1931 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1932 pio = pci_resource_start(ha->pdev, 0);
1933 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1934 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1935 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1936 "Invalid pci I/O region size (%s).\n",
1937 pci_name(ha->pdev));
1938 pio = 0;
1939 }
1940 } else {
1941 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1942 "Region #0 no a PIO resource (%s).\n",
1943 pci_name(ha->pdev));
1944 pio = 0;
1945 }
1946 ha->pio_address = pio;
1947 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1948 "PIO address=%llu.\n",
1949 (unsigned long long)ha->pio_address);
1950
1951skip_pio:
1952 /* Use MMIO operations for all accesses. */
1953 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1954 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1955 "Region #1 not an MMIO resource (%s), aborting.\n",
1956 pci_name(ha->pdev));
1957 goto iospace_error_exit;
1958 }
1959 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1960 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1961 "Invalid PCI mem region size (%s), aborting.\n",
1962 pci_name(ha->pdev));
1963 goto iospace_error_exit;
1964 }
1965
1966 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1967 if (!ha->iobase) {
1968 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1969 "Cannot remap MMIO (%s), aborting.\n",
1970 pci_name(ha->pdev));
1971 goto iospace_error_exit;
1972 }
1973
1974 /* Determine queue resources */
1975 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08001976 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07001977 if (!ql2xmqsupport || !ql2xnvmeenable ||
1978 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08001979 goto mqiobase_exit;
1980
1981 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1982 pci_resource_len(ha->pdev, 3));
1983 if (ha->mqiobase) {
1984 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1985 "MQIO Base=%p.\n", ha->mqiobase);
1986 /* Read MSIX vector size of the board */
1987 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08001988 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001989 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08001990 /* MB interrupt uses 1 vector */
1991 ha->max_req_queues = ha->msix_count - 1;
1992 ha->max_rsp_queues = ha->max_req_queues;
1993 /* Queue pairs is the max value minus the base queue pair */
1994 ha->max_qpairs = ha->max_rsp_queues - 1;
1995 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
1996 "Max no of queues pairs: %d.\n", ha->max_qpairs);
1997
Giridhar Malavali706f4572011-11-18 09:03:16 -08001998 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08001999 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002000 } else
2001 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2002 "BAR 3 not enabled.\n");
2003
2004mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002005 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002006 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002007 return (0);
2008
2009iospace_error_exit:
2010 return (-ENOMEM);
2011}
2012
2013
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002014static int
2015qla83xx_iospace_config(struct qla_hw_data *ha)
2016{
2017 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002018
2019 if (pci_request_selected_regions(ha->pdev, ha->bars,
2020 QLA2XXX_DRIVER_NAME)) {
2021 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2022 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2023 pci_name(ha->pdev));
2024
2025 goto iospace_error_exit;
2026 }
2027
2028 /* Use MMIO operations for all accesses. */
2029 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2030 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2031 "Invalid pci I/O region size (%s).\n",
2032 pci_name(ha->pdev));
2033 goto iospace_error_exit;
2034 }
2035 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2036 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2037 "Invalid PCI mem region size (%s), aborting\n",
2038 pci_name(ha->pdev));
2039 goto iospace_error_exit;
2040 }
2041
2042 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2043 if (!ha->iobase) {
2044 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2045 "Cannot remap MMIO (%s), aborting.\n",
2046 pci_name(ha->pdev));
2047 goto iospace_error_exit;
2048 }
2049
2050 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2051 /* 83XX 26XX always use MQ type access for queues
2052 * - mbar 2, a.k.a region 4 */
2053 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002054 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002055 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2056 pci_resource_len(ha->pdev, 4));
2057
2058 if (!ha->mqiobase) {
2059 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2060 "BAR2/region4 not enabled\n");
2061 goto mqiobase_exit;
2062 }
2063
2064 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2065 pci_resource_len(ha->pdev, 2));
2066 if (ha->msixbase) {
2067 /* Read MSIX vector size of the board */
2068 pci_read_config_word(ha->pdev,
2069 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002070 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002071 /*
2072 * By default, driver uses at least two msix vectors
2073 * (default & rspq)
2074 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002075 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002076 /* MB interrupt uses 1 vector */
2077 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002078
2079 /* ATIOQ needs 1 vector. That's 1 less QPair */
2080 if (QLA_TGT_MODE_ENABLED())
2081 ha->max_req_queues--;
2082
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002083 ha->max_rsp_queues = ha->max_req_queues;
2084
Michael Hernandezd7459522016-12-12 14:40:07 -08002085 /* Queue pairs is the max value minus
2086 * the base queue pair */
2087 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002088 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002089 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002090 }
2091 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002092 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002093 } else
2094 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2095 "BAR 1 not enabled.\n");
2096
2097mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002098 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002099 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002100 return 0;
2101
2102iospace_error_exit:
2103 return -ENOMEM;
2104}
2105
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002106static struct isp_operations qla2100_isp_ops = {
2107 .pci_config = qla2100_pci_config,
2108 .reset_chip = qla2x00_reset_chip,
2109 .chip_diag = qla2x00_chip_diag,
2110 .config_rings = qla2x00_config_rings,
2111 .reset_adapter = qla2x00_reset_adapter,
2112 .nvram_config = qla2x00_nvram_config,
2113 .update_fw_options = qla2x00_update_fw_options,
2114 .load_risc = qla2x00_load_risc,
2115 .pci_info_str = qla2x00_pci_info_str,
2116 .fw_version_str = qla2x00_fw_version_str,
2117 .intr_handler = qla2100_intr_handler,
2118 .enable_intrs = qla2x00_enable_intrs,
2119 .disable_intrs = qla2x00_disable_intrs,
2120 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002121 .target_reset = qla2x00_abort_target,
2122 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002123 .fabric_login = qla2x00_login_fabric,
2124 .fabric_logout = qla2x00_fabric_logout,
2125 .calc_req_entries = qla2x00_calc_iocbs_32,
2126 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2127 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2128 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2129 .read_nvram = qla2x00_read_nvram_data,
2130 .write_nvram = qla2x00_write_nvram_data,
2131 .fw_dump = qla2100_fw_dump,
2132 .beacon_on = NULL,
2133 .beacon_off = NULL,
2134 .beacon_blink = NULL,
2135 .read_optrom = qla2x00_read_optrom_data,
2136 .write_optrom = qla2x00_write_optrom_data,
2137 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002138 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002139 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002140 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002141 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002142 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002143};
2144
2145static struct isp_operations qla2300_isp_ops = {
2146 .pci_config = qla2300_pci_config,
2147 .reset_chip = qla2x00_reset_chip,
2148 .chip_diag = qla2x00_chip_diag,
2149 .config_rings = qla2x00_config_rings,
2150 .reset_adapter = qla2x00_reset_adapter,
2151 .nvram_config = qla2x00_nvram_config,
2152 .update_fw_options = qla2x00_update_fw_options,
2153 .load_risc = qla2x00_load_risc,
2154 .pci_info_str = qla2x00_pci_info_str,
2155 .fw_version_str = qla2x00_fw_version_str,
2156 .intr_handler = qla2300_intr_handler,
2157 .enable_intrs = qla2x00_enable_intrs,
2158 .disable_intrs = qla2x00_disable_intrs,
2159 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002160 .target_reset = qla2x00_abort_target,
2161 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002162 .fabric_login = qla2x00_login_fabric,
2163 .fabric_logout = qla2x00_fabric_logout,
2164 .calc_req_entries = qla2x00_calc_iocbs_32,
2165 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2166 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2167 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2168 .read_nvram = qla2x00_read_nvram_data,
2169 .write_nvram = qla2x00_write_nvram_data,
2170 .fw_dump = qla2300_fw_dump,
2171 .beacon_on = qla2x00_beacon_on,
2172 .beacon_off = qla2x00_beacon_off,
2173 .beacon_blink = qla2x00_beacon_blink,
2174 .read_optrom = qla2x00_read_optrom_data,
2175 .write_optrom = qla2x00_write_optrom_data,
2176 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002177 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002178 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002179 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002180 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002181 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002182};
2183
2184static struct isp_operations qla24xx_isp_ops = {
2185 .pci_config = qla24xx_pci_config,
2186 .reset_chip = qla24xx_reset_chip,
2187 .chip_diag = qla24xx_chip_diag,
2188 .config_rings = qla24xx_config_rings,
2189 .reset_adapter = qla24xx_reset_adapter,
2190 .nvram_config = qla24xx_nvram_config,
2191 .update_fw_options = qla24xx_update_fw_options,
2192 .load_risc = qla24xx_load_risc,
2193 .pci_info_str = qla24xx_pci_info_str,
2194 .fw_version_str = qla24xx_fw_version_str,
2195 .intr_handler = qla24xx_intr_handler,
2196 .enable_intrs = qla24xx_enable_intrs,
2197 .disable_intrs = qla24xx_disable_intrs,
2198 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002199 .target_reset = qla24xx_abort_target,
2200 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002201 .fabric_login = qla24xx_login_fabric,
2202 .fabric_logout = qla24xx_fabric_logout,
2203 .calc_req_entries = NULL,
2204 .build_iocbs = NULL,
2205 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2206 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2207 .read_nvram = qla24xx_read_nvram_data,
2208 .write_nvram = qla24xx_write_nvram_data,
2209 .fw_dump = qla24xx_fw_dump,
2210 .beacon_on = qla24xx_beacon_on,
2211 .beacon_off = qla24xx_beacon_off,
2212 .beacon_blink = qla24xx_beacon_blink,
2213 .read_optrom = qla24xx_read_optrom_data,
2214 .write_optrom = qla24xx_write_optrom_data,
2215 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002216 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002217 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002218 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002219 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002220 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002221};
2222
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002223static struct isp_operations qla25xx_isp_ops = {
2224 .pci_config = qla25xx_pci_config,
2225 .reset_chip = qla24xx_reset_chip,
2226 .chip_diag = qla24xx_chip_diag,
2227 .config_rings = qla24xx_config_rings,
2228 .reset_adapter = qla24xx_reset_adapter,
2229 .nvram_config = qla24xx_nvram_config,
2230 .update_fw_options = qla24xx_update_fw_options,
2231 .load_risc = qla24xx_load_risc,
2232 .pci_info_str = qla24xx_pci_info_str,
2233 .fw_version_str = qla24xx_fw_version_str,
2234 .intr_handler = qla24xx_intr_handler,
2235 .enable_intrs = qla24xx_enable_intrs,
2236 .disable_intrs = qla24xx_disable_intrs,
2237 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002238 .target_reset = qla24xx_abort_target,
2239 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002240 .fabric_login = qla24xx_login_fabric,
2241 .fabric_logout = qla24xx_fabric_logout,
2242 .calc_req_entries = NULL,
2243 .build_iocbs = NULL,
2244 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2245 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2246 .read_nvram = qla25xx_read_nvram_data,
2247 .write_nvram = qla25xx_write_nvram_data,
2248 .fw_dump = qla25xx_fw_dump,
2249 .beacon_on = qla24xx_beacon_on,
2250 .beacon_off = qla24xx_beacon_off,
2251 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002252 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002253 .write_optrom = qla24xx_write_optrom_data,
2254 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002255 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002256 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002257 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002258 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002259 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002260};
2261
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002262static struct isp_operations qla81xx_isp_ops = {
2263 .pci_config = qla25xx_pci_config,
2264 .reset_chip = qla24xx_reset_chip,
2265 .chip_diag = qla24xx_chip_diag,
2266 .config_rings = qla24xx_config_rings,
2267 .reset_adapter = qla24xx_reset_adapter,
2268 .nvram_config = qla81xx_nvram_config,
2269 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002270 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002271 .pci_info_str = qla24xx_pci_info_str,
2272 .fw_version_str = qla24xx_fw_version_str,
2273 .intr_handler = qla24xx_intr_handler,
2274 .enable_intrs = qla24xx_enable_intrs,
2275 .disable_intrs = qla24xx_disable_intrs,
2276 .abort_command = qla24xx_abort_command,
2277 .target_reset = qla24xx_abort_target,
2278 .lun_reset = qla24xx_lun_reset,
2279 .fabric_login = qla24xx_login_fabric,
2280 .fabric_logout = qla24xx_fabric_logout,
2281 .calc_req_entries = NULL,
2282 .build_iocbs = NULL,
2283 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2284 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002285 .read_nvram = NULL,
2286 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002287 .fw_dump = qla81xx_fw_dump,
2288 .beacon_on = qla24xx_beacon_on,
2289 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002290 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002291 .read_optrom = qla25xx_read_optrom_data,
2292 .write_optrom = qla24xx_write_optrom_data,
2293 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002294 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002295 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002296 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002297 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002298 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002299};
2300
2301static struct isp_operations qla82xx_isp_ops = {
2302 .pci_config = qla82xx_pci_config,
2303 .reset_chip = qla82xx_reset_chip,
2304 .chip_diag = qla24xx_chip_diag,
2305 .config_rings = qla82xx_config_rings,
2306 .reset_adapter = qla24xx_reset_adapter,
2307 .nvram_config = qla81xx_nvram_config,
2308 .update_fw_options = qla24xx_update_fw_options,
2309 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002310 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002311 .fw_version_str = qla24xx_fw_version_str,
2312 .intr_handler = qla82xx_intr_handler,
2313 .enable_intrs = qla82xx_enable_intrs,
2314 .disable_intrs = qla82xx_disable_intrs,
2315 .abort_command = qla24xx_abort_command,
2316 .target_reset = qla24xx_abort_target,
2317 .lun_reset = qla24xx_lun_reset,
2318 .fabric_login = qla24xx_login_fabric,
2319 .fabric_logout = qla24xx_fabric_logout,
2320 .calc_req_entries = NULL,
2321 .build_iocbs = NULL,
2322 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2323 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2324 .read_nvram = qla24xx_read_nvram_data,
2325 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002326 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002327 .beacon_on = qla82xx_beacon_on,
2328 .beacon_off = qla82xx_beacon_off,
2329 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002330 .read_optrom = qla82xx_read_optrom_data,
2331 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002332 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002333 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002334 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002335 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002336 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002337 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002338};
2339
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002340static struct isp_operations qla8044_isp_ops = {
2341 .pci_config = qla82xx_pci_config,
2342 .reset_chip = qla82xx_reset_chip,
2343 .chip_diag = qla24xx_chip_diag,
2344 .config_rings = qla82xx_config_rings,
2345 .reset_adapter = qla24xx_reset_adapter,
2346 .nvram_config = qla81xx_nvram_config,
2347 .update_fw_options = qla24xx_update_fw_options,
2348 .load_risc = qla82xx_load_risc,
2349 .pci_info_str = qla24xx_pci_info_str,
2350 .fw_version_str = qla24xx_fw_version_str,
2351 .intr_handler = qla8044_intr_handler,
2352 .enable_intrs = qla82xx_enable_intrs,
2353 .disable_intrs = qla82xx_disable_intrs,
2354 .abort_command = qla24xx_abort_command,
2355 .target_reset = qla24xx_abort_target,
2356 .lun_reset = qla24xx_lun_reset,
2357 .fabric_login = qla24xx_login_fabric,
2358 .fabric_logout = qla24xx_fabric_logout,
2359 .calc_req_entries = NULL,
2360 .build_iocbs = NULL,
2361 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2362 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2363 .read_nvram = NULL,
2364 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002365 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002366 .beacon_on = qla82xx_beacon_on,
2367 .beacon_off = qla82xx_beacon_off,
2368 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002369 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002370 .write_optrom = qla8044_write_optrom_data,
2371 .get_flash_version = qla82xx_get_flash_version,
2372 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002373 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002374 .abort_isp = qla8044_abort_isp,
2375 .iospace_config = qla82xx_iospace_config,
2376 .initialize_adapter = qla2x00_initialize_adapter,
2377};
2378
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002379static struct isp_operations qla83xx_isp_ops = {
2380 .pci_config = qla25xx_pci_config,
2381 .reset_chip = qla24xx_reset_chip,
2382 .chip_diag = qla24xx_chip_diag,
2383 .config_rings = qla24xx_config_rings,
2384 .reset_adapter = qla24xx_reset_adapter,
2385 .nvram_config = qla81xx_nvram_config,
2386 .update_fw_options = qla81xx_update_fw_options,
2387 .load_risc = qla81xx_load_risc,
2388 .pci_info_str = qla24xx_pci_info_str,
2389 .fw_version_str = qla24xx_fw_version_str,
2390 .intr_handler = qla24xx_intr_handler,
2391 .enable_intrs = qla24xx_enable_intrs,
2392 .disable_intrs = qla24xx_disable_intrs,
2393 .abort_command = qla24xx_abort_command,
2394 .target_reset = qla24xx_abort_target,
2395 .lun_reset = qla24xx_lun_reset,
2396 .fabric_login = qla24xx_login_fabric,
2397 .fabric_logout = qla24xx_fabric_logout,
2398 .calc_req_entries = NULL,
2399 .build_iocbs = NULL,
2400 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2401 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2402 .read_nvram = NULL,
2403 .write_nvram = NULL,
2404 .fw_dump = qla83xx_fw_dump,
2405 .beacon_on = qla24xx_beacon_on,
2406 .beacon_off = qla24xx_beacon_off,
2407 .beacon_blink = qla83xx_beacon_blink,
2408 .read_optrom = qla25xx_read_optrom_data,
2409 .write_optrom = qla24xx_write_optrom_data,
2410 .get_flash_version = qla24xx_get_flash_version,
2411 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002412 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002413 .abort_isp = qla2x00_abort_isp,
2414 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002415 .initialize_adapter = qla2x00_initialize_adapter,
2416};
2417
2418static struct isp_operations qlafx00_isp_ops = {
2419 .pci_config = qlafx00_pci_config,
2420 .reset_chip = qlafx00_soft_reset,
2421 .chip_diag = qlafx00_chip_diag,
2422 .config_rings = qlafx00_config_rings,
2423 .reset_adapter = qlafx00_soft_reset,
2424 .nvram_config = NULL,
2425 .update_fw_options = NULL,
2426 .load_risc = NULL,
2427 .pci_info_str = qlafx00_pci_info_str,
2428 .fw_version_str = qlafx00_fw_version_str,
2429 .intr_handler = qlafx00_intr_handler,
2430 .enable_intrs = qlafx00_enable_intrs,
2431 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002432 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002433 .target_reset = qlafx00_abort_target,
2434 .lun_reset = qlafx00_lun_reset,
2435 .fabric_login = NULL,
2436 .fabric_logout = NULL,
2437 .calc_req_entries = NULL,
2438 .build_iocbs = NULL,
2439 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2440 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2441 .read_nvram = qla24xx_read_nvram_data,
2442 .write_nvram = qla24xx_write_nvram_data,
2443 .fw_dump = NULL,
2444 .beacon_on = qla24xx_beacon_on,
2445 .beacon_off = qla24xx_beacon_off,
2446 .beacon_blink = NULL,
2447 .read_optrom = qla24xx_read_optrom_data,
2448 .write_optrom = qla24xx_write_optrom_data,
2449 .get_flash_version = qla24xx_get_flash_version,
2450 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002451 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002452 .abort_isp = qlafx00_abort_isp,
2453 .iospace_config = qlafx00_iospace_config,
2454 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002455};
2456
Chad Dupuisf73cb692014-02-26 04:15:06 -05002457static struct isp_operations qla27xx_isp_ops = {
2458 .pci_config = qla25xx_pci_config,
2459 .reset_chip = qla24xx_reset_chip,
2460 .chip_diag = qla24xx_chip_diag,
2461 .config_rings = qla24xx_config_rings,
2462 .reset_adapter = qla24xx_reset_adapter,
2463 .nvram_config = qla81xx_nvram_config,
2464 .update_fw_options = qla81xx_update_fw_options,
2465 .load_risc = qla81xx_load_risc,
2466 .pci_info_str = qla24xx_pci_info_str,
2467 .fw_version_str = qla24xx_fw_version_str,
2468 .intr_handler = qla24xx_intr_handler,
2469 .enable_intrs = qla24xx_enable_intrs,
2470 .disable_intrs = qla24xx_disable_intrs,
2471 .abort_command = qla24xx_abort_command,
2472 .target_reset = qla24xx_abort_target,
2473 .lun_reset = qla24xx_lun_reset,
2474 .fabric_login = qla24xx_login_fabric,
2475 .fabric_logout = qla24xx_fabric_logout,
2476 .calc_req_entries = NULL,
2477 .build_iocbs = NULL,
2478 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2479 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2480 .read_nvram = NULL,
2481 .write_nvram = NULL,
2482 .fw_dump = qla27xx_fwdump,
2483 .beacon_on = qla24xx_beacon_on,
2484 .beacon_off = qla24xx_beacon_off,
2485 .beacon_blink = qla83xx_beacon_blink,
2486 .read_optrom = qla25xx_read_optrom_data,
2487 .write_optrom = qla24xx_write_optrom_data,
2488 .get_flash_version = qla24xx_get_flash_version,
2489 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002490 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002491 .abort_isp = qla2x00_abort_isp,
2492 .iospace_config = qla83xx_iospace_config,
2493 .initialize_adapter = qla2x00_initialize_adapter,
2494};
2495
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002496static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002498{
2499 ha->device_type = DT_EXTENDED_IDS;
2500 switch (ha->pdev->device) {
2501 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002502 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002503 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002504 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002505 break;
2506 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002507 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002508 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002509 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002510 break;
2511 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002512 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002513 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002514 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002515 break;
2516 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002517 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002518 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002519 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002520 break;
2521 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002522 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002523 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002524 if (ha->pdev->subsystem_vendor == 0x1028 &&
2525 ha->pdev->subsystem_device == 0x0170)
2526 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002527 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002528 break;
2529 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002530 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002531 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002532 break;
2533 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002534 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002535 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002536 break;
2537 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002538 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002539 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002540 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002541 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002542 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002543 break;
2544 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002545 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002546 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002547 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002548 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002549 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002550 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002551 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002552 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002553 ha->device_type |= DT_ZIO_SUPPORTED;
2554 ha->device_type |= DT_FWI2;
2555 ha->device_type |= DT_IIDMA;
2556 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2557 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002558 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002559 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002560 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002561 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002562 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002563 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002564 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002565 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002566 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002567 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002568 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002569 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002570 ha->device_type |= DT_ZIO_SUPPORTED;
2571 ha->device_type |= DT_FWI2;
2572 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002573 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2574 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002575 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002576 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002577 ha->device_type |= DT_ZIO_SUPPORTED;
2578 ha->device_type |= DT_FWI2;
2579 ha->device_type |= DT_IIDMA;
2580 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2581 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002582 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002583 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002584 ha->device_type |= DT_ZIO_SUPPORTED;
2585 ha->device_type |= DT_FWI2;
2586 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2587 /* Initialize 82XX ISP flags */
2588 qla82xx_init_flags(ha);
2589 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002590 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002591 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002592 ha->device_type |= DT_ZIO_SUPPORTED;
2593 ha->device_type |= DT_FWI2;
2594 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2595 /* Initialize 82XX ISP flags */
2596 qla82xx_init_flags(ha);
2597 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002598 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002599 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002600 ha->device_type |= DT_ZIO_SUPPORTED;
2601 ha->device_type |= DT_FWI2;
2602 ha->device_type |= DT_IIDMA;
2603 ha->device_type |= DT_T10_PI;
2604 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2605 break;
2606 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002607 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002608 ha->device_type |= DT_ZIO_SUPPORTED;
2609 ha->device_type |= DT_FWI2;
2610 ha->device_type |= DT_IIDMA;
2611 ha->device_type |= DT_T10_PI;
2612 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2613 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002614 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002615 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002616 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002617 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002618 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002619 ha->device_type |= DT_ZIO_SUPPORTED;
2620 ha->device_type |= DT_FWI2;
2621 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002622 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002623 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2624 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002625 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002626 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002627 ha->device_type |= DT_ZIO_SUPPORTED;
2628 ha->device_type |= DT_FWI2;
2629 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002630 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002631 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2632 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002633 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002634 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002635 ha->device_type |= DT_ZIO_SUPPORTED;
2636 ha->device_type |= DT_FWI2;
2637 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002638 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002639 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2640 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002641 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002642
Giridhar Malavalia9083012010-04-12 17:59:55 -07002643 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002644 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002645 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002646 /* Get adapter physical port no from interrupt pin register. */
2647 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002648 if (IS_QLA27XX(ha))
2649 ha->port_no--;
2650 else
2651 ha->port_no = !(ha->port_no & 1);
2652 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002653
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002654 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002655 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002656 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002657}
2658
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002659static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002660qla2xxx_scan_start(struct Scsi_Host *shost)
2661{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002663
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002664 if (vha->hw->flags.running_gold_fw)
2665 return;
2666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2668 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2669 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2670 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002671}
2672
2673static int
2674qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2675{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002677
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002678 if (test_bit(UNLOADING, &vha->dpc_flags))
2679 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002681 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002683 return 1;
2684
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002686}
2687
Quinn Tranec7193e2017-03-15 09:48:55 -07002688static void qla2x00_iocb_work_fn(struct work_struct *work)
2689{
2690 struct scsi_qla_host *vha = container_of(work,
2691 struct scsi_qla_host, iocb_work);
2692 int cnt = 0;
2693
2694 while (!list_empty(&vha->work_list)) {
2695 qla2x00_do_work(vha);
2696 cnt++;
2697 if (cnt > 10)
2698 break;
2699 }
2700}
2701
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702/*
2703 * PCI driver interface
2704 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002705static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002706qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002708 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002710 scsi_qla_host_t *base_vha = NULL;
2711 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002712 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002713 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002714 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002715 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002717 struct req_que *req = NULL;
2718 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002719 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002720
Andrew Vasquez285d0322007-10-19 15:59:17 -07002721 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002722 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002723 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2724 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002725 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002726 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2727 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002728 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002729 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002730 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2731 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002732 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002733 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002734 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002735 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002736 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2737 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002738 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002739 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002740 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2741 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002742 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002743 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2744 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002745
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002746 if (mem_only) {
2747 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002748 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002749 } else {
2750 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002751 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
Jesse Barnes09276782008-10-18 17:33:19 -07002754 /* This may fail but that's ok */
2755 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002756
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2758 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002759 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2760 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002761 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002763 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2764 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002765 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002766 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2767 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002768 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002769 spin_lock_init(&ha->tgt.atio_lock);
2770
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002771 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
2773 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002774 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002775 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002776 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002777 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002778 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002779 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002781 /* Set ISP-type information. */
2782 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002783
2784 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002785 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002786 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002787 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002788
Chad Dupuiscba1e472011-11-18 09:03:21 -08002789 ha->prev_topology = 0;
2790 ha->init_cb_size = sizeof(init_cb_t);
2791 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2792 ha->optrom_size = OPTROM_SIZE_2300;
2793
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002794 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002796 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 req_length = REQUEST_ENTRY_CNT_2100;
2799 rsp_length = RESPONSE_ENTRY_CNT_2100;
2800 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002801 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002802 ha->flash_conf_off = ~0;
2803 ha->flash_data_off = ~0;
2804 ha->nvram_conf_off = ~0;
2805 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002806 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002808 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002809 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002810 req_length = REQUEST_ENTRY_CNT_2200;
2811 rsp_length = RESPONSE_ENTRY_CNT_2100;
2812 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002813 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002814 ha->flash_conf_off = ~0;
2815 ha->flash_data_off = ~0;
2816 ha->nvram_conf_off = ~0;
2817 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002818 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002819 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002820 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822 req_length = REQUEST_ENTRY_CNT_2200;
2823 rsp_length = RESPONSE_ENTRY_CNT_2300;
2824 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002825 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002826 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2827 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002828 ha->flash_conf_off = ~0;
2829 ha->flash_data_off = ~0;
2830 ha->nvram_conf_off = ~0;
2831 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002832 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002833 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002834 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002835 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002836 req_length = REQUEST_ENTRY_CNT_24XX;
2837 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002838 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002839 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002840 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002841 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002842 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002843 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002844 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002845 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2846 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2847 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2848 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002849 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002850 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002851 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 req_length = REQUEST_ENTRY_CNT_24XX;
2853 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002854 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002855 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002856 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002857 ha->gid_list_info_size = 8;
2858 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002859 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002860 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002861 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2862 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2863 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2864 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2865 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002866 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002867 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2868 req_length = REQUEST_ENTRY_CNT_24XX;
2869 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002870 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002871 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2872 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2873 ha->gid_list_info_size = 8;
2874 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002875 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002876 ha->isp_ops = &qla81xx_isp_ops;
2877 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2878 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2879 ha->nvram_conf_off = ~0;
2880 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002881 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002882 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002883 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2884 req_length = REQUEST_ENTRY_CNT_82XX;
2885 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2886 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2887 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2888 ha->gid_list_info_size = 8;
2889 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002890 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002891 ha->isp_ops = &qla82xx_isp_ops;
2892 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2893 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2894 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2895 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002896 } else if (IS_QLA8044(ha)) {
2897 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2898 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2899 req_length = REQUEST_ENTRY_CNT_82XX;
2900 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2901 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2902 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2903 ha->gid_list_info_size = 8;
2904 ha->optrom_size = OPTROM_SIZE_83XX;
2905 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2906 ha->isp_ops = &qla8044_isp_ops;
2907 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2908 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2909 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2910 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002911 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002912 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002913 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002914 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002915 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002916 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002917 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002918 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2919 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2920 ha->gid_list_info_size = 8;
2921 ha->optrom_size = OPTROM_SIZE_83XX;
2922 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2923 ha->isp_ops = &qla83xx_isp_ops;
2924 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2925 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2926 ha->nvram_conf_off = ~0;
2927 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002928 } else if (IS_QLAFX00(ha)) {
2929 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2930 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2931 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2932 req_length = REQUEST_ENTRY_CNT_FX00;
2933 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002934 ha->isp_ops = &qlafx00_isp_ops;
2935 ha->port_down_retry_count = 30; /* default value */
2936 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2937 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002938 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002939 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002940 ha->mr.host_info_resend = false;
2941 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002942 } else if (IS_QLA27XX(ha)) {
2943 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2944 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2945 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05002946 req_length = REQUEST_ENTRY_CNT_83XX;
2947 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002948 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002949 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2950 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2951 ha->gid_list_info_size = 8;
2952 ha->optrom_size = OPTROM_SIZE_83XX;
2953 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2954 ha->isp_ops = &qla27xx_isp_ops;
2955 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2956 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2957 ha->nvram_conf_off = ~0;
2958 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002960
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002961 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2962 "mbx_count=%d, req_length=%d, "
2963 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002964 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2965 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002966 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2967 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002968 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002969 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2970 "isp_ops=%p, flash_conf_off=%d, "
2971 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2972 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2973 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002974
2975 /* Configure PCI I/O space */
2976 ret = ha->isp_ops->iospace_config(ha);
2977 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05002978 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002979
2980 ql_log_pci(ql_log_info, pdev, 0x001d,
2981 "Found an ISP%04X irq %d iobase 0x%p.\n",
2982 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002983 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08002984 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08002985 init_completion(&ha->mbx_cmd_comp);
2986 complete(&ha->mbx_cmd_comp);
2987 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07002988 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05002989 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002991 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
Andrew Vasquez53303c42009-01-22 09:45:37 -08002993 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002994 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2995 "64 Bit addressing is %s.\n",
2996 ha->flags.enable_64bit_addressing ? "enable" :
2997 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002998 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03002999 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003000 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3001 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 goto probe_hw_failed;
3004 }
3005
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003006 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003008 req->max_q_depth = ql2xmaxqdepth;
3009
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003010
3011 base_vha = qla2x00_create_host(sht, ha);
3012 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003013 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003014 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003015 qla2x00_free_req_que(ha, req);
3016 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 }
3019
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003021 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003024 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003025 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003027 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3029 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003030
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003031 /* Setup fcport template structure. */
3032 ha->mr.fcport.vha = base_vha;
3033 ha->mr.fcport.port_type = FCT_UNKNOWN;
3034 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3035 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3036 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3037 ha->mr.fcport.scan_state = 1;
3038
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003039 /* Set the SG table size based on ISP type */
3040 if (!IS_FWI2_CAPABLE(ha)) {
3041 if (IS_QLA2100(ha))
3042 host->sg_tablesize = 32;
3043 } else {
3044 if (!IS_QLA82XX(ha))
3045 host->sg_tablesize = QLA_SG_ALL;
3046 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003047 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003048 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003049 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003050 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003051 host->max_cmd_len = 32;
3052 else
3053 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003054 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003055 /* Older HBAs support only 16-bit LUNs */
3056 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3057 ql2xmaxlun > 0xffff)
3058 host->max_lun = 0xffff;
3059 else
3060 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003061 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003062 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003063
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003064 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3065 "max_id=%d this_id=%d "
3066 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003067 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003068 host->this_id, host->cmd_per_lun, host->unique_id,
3069 host->max_cmd_len, host->max_channel, host->max_lun,
3070 host->transportt, sht->vendor_id);
3071
Himanshu Madhani1010f212017-10-16 11:26:05 -07003072 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3073
Michael Hernandezd7459522016-12-12 14:40:07 -08003074 /* Set up the irqs */
3075 ret = qla2x00_request_irqs(ha, rsp);
3076 if (ret)
3077 goto probe_init_failed;
3078
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003079 /* Alloc arrays of request and response ring ptrs */
3080 if (!qla2x00_alloc_queues(ha, req, rsp)) {
3081 ql_log(ql_log_fatal, base_vha, 0x003d,
3082 "Failed to allocate memory for queue pointers..."
3083 "aborting.\n");
3084 goto probe_init_failed;
3085 }
3086
Michael Hernandez56012362016-12-12 14:40:08 -08003087 if (ha->mqenable && shost_use_blk_mq(host)) {
3088 /* number of hardware queues supported by blk/scsi-mq*/
3089 host->nr_hw_queues = ha->max_qpairs;
3090
3091 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3092 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003093 } else {
3094 if (ql2xnvmeenable) {
3095 host->nr_hw_queues = ha->max_qpairs;
3096 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3097 "FC-NVMe support is enabled, HW queues=%d\n",
3098 host->nr_hw_queues);
3099 } else {
3100 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3101 "blk/scsi-mq disabled.\n");
3102 }
3103 }
Michael Hernandez56012362016-12-12 14:40:08 -08003104
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003105 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003106
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003107 pci_save_state(pdev);
3108
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003109 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003110 rsp->req = req;
3111 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003112
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003113 if (IS_QLAFX00(ha)) {
3114 ha->rsp_q_map[0] = rsp;
3115 ha->req_q_map[0] = req;
3116 set_bit(0, ha->req_qid_map);
3117 set_bit(0, ha->rsp_qid_map);
3118 }
3119
Andrew Vasquez08029992009-03-24 09:07:55 -07003120 /* FWI2-capable only. */
3121 req->req_q_in = &ha->iobase->isp24.req_q_in;
3122 req->req_q_out = &ha->iobase->isp24.req_q_out;
3123 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3124 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003125 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003126 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3127 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3128 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3129 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003130 }
3131
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003132 if (IS_QLAFX00(ha)) {
3133 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3134 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3135 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3136 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3137 }
3138
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003139 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003140 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3141 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3142 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3143 }
3144
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003145 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3146 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3147 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3148 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3149 "req->req_q_in=%p req->req_q_out=%p "
3150 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3151 req->req_q_in, req->req_q_out,
3152 rsp->rsp_q_in, rsp->rsp_q_out);
3153 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3154 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3155 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3156 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3157 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3158 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003160 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003161 ql_log(ql_log_fatal, base_vha, 0x00d6,
3162 "Failed to initialize adapter - Adapter flags %x.\n",
3163 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164
Giridhar Malavalia9083012010-04-12 17:59:55 -07003165 if (IS_QLA82XX(ha)) {
3166 qla82xx_idc_lock(ha);
3167 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003168 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003169 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003170 ql_log(ql_log_fatal, base_vha, 0x00d7,
3171 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003172 } else if (IS_QLA8044(ha)) {
3173 qla8044_idc_lock(ha);
3174 qla8044_wr_direct(base_vha,
3175 QLA8044_CRB_DEV_STATE_INDEX,
3176 QLA8XXX_DEV_FAILED);
3177 qla8044_idc_unlock(ha);
3178 ql_log(ql_log_fatal, base_vha, 0x0150,
3179 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003180 }
3181
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182 ret = -ENODEV;
3183 goto probe_failed;
3184 }
3185
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003186 if (IS_QLAFX00(ha))
3187 host->can_queue = QLAFX00_MAX_CANQUEUE;
3188 else
3189 host->can_queue = req->num_outstanding_cmds - 10;
3190
3191 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3192 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3193 host->can_queue, base_vha->req,
3194 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3195
Quinn Trana01c77d2017-12-04 14:44:58 -08003196 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0);
3197
Quinn Trane326d222017-06-13 20:47:18 -07003198 if (ha->mqenable) {
3199 bool mq = false;
3200 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003201
3202 if (QLA_TGT_MODE_ENABLED()) {
3203 mq = true;
3204 startit = false;
3205 }
3206
3207 if ((ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) &&
3208 shost_use_blk_mq(host)) {
3209 mq = true;
3210 startit = true;
3211 }
3212
3213 if (mq) {
3214 /* Create start of day qpairs for Block MQ */
Michael Hernandez56012362016-12-12 14:40:08 -08003215 for (i = 0; i < ha->max_qpairs; i++)
Quinn Trane326d222017-06-13 20:47:18 -07003216 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003217 }
3218 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003219
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003220 if (ha->flags.running_gold_fw)
3221 goto skip_dpc;
3222
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003223 /*
3224 * Startup the kernel thread for this host adapter
3225 */
3226 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003227 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003229 ql_log(ql_log_fatal, base_vha, 0x00ed,
3230 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003232 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233 goto probe_failed;
3234 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003235 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3236 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003238 /*
3239 * If we're not coming up in initiator mode, we might sit for
3240 * a while without waking up the dpc thread, which leads to a
3241 * stuck process warning. So just kick the dpc once here and
3242 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3243 */
3244 qla2xxx_wake_dpc(base_vha);
3245
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003246 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3247
Saurav Kashyap81178772012-08-22 14:21:04 -04003248 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3249 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3250 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3251 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3252
3253 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3254 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3255 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3256 INIT_WORK(&ha->idc_state_handler,
3257 qla83xx_idc_state_handler_work);
3258 INIT_WORK(&ha->nic_core_unrecoverable,
3259 qla83xx_nic_core_unrecoverable_work);
3260 }
3261
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003262skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263 list_add_tail(&base_vha->list, &ha->vp_list);
3264 base_vha->host->irq = ha->pdev->irq;
3265
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003267 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003268 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3269 "Started qla2x00_timer with "
3270 "interval=%d.\n", WATCH_INTERVAL);
3271 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3272 "Detected hba at address=%p.\n",
3273 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Arun Easie02587d2011-08-16 11:29:23 -07003275 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003276 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003277 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003278 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003279 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3280 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003281 if (ql2xenabledif == 1)
3282 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07003283 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07003284 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003285 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003286 | SHOST_DIF_TYPE3_PROTECTION
3287 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003288 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003289 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003290
3291 guard = SHOST_DIX_GUARD_CRC;
3292
3293 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3294 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3295 guard |= SHOST_DIX_GUARD_IP;
3296
3297 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003298 } else
3299 base_vha->flags.difdix_supported = 0;
3300 }
3301
Giridhar Malavalia9083012010-04-12 17:59:55 -07003302 ha->isp_ops->enable_intrs(ha);
3303
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003304 if (IS_QLAFX00(ha)) {
3305 ret = qlafx00_fx_disc(base_vha,
3306 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3307 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3308 QLA_SG_ALL : 128;
3309 }
3310
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003311 ret = scsi_add_host(host, &pdev->dev);
3312 if (ret)
3313 goto probe_failed;
3314
Michael Reed14864002009-12-02 09:11:16 -06003315 base_vha->flags.init_done = 1;
3316 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003317 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003318
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003319 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3320 "Init done and hba is online.\n");
3321
Quinn Tran726b8542017-01-19 22:28:00 -08003322 if (qla_ini_mode_enabled(base_vha) ||
3323 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003324 scsi_scan_host(host);
3325 else
3326 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3327 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003328
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003329 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003330
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003331 if (IS_QLAFX00(ha)) {
3332 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003333 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3334
3335 /* Register system information */
3336 ret = qlafx00_fx_disc(base_vha,
3337 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3338 }
3339
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003341
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003342 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003343
Armen Baloyan03eb9122013-10-30 03:38:22 -04003344 ql_log(ql_log_info, base_vha, 0x00fb,
3345 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003346 ql_log(ql_log_info, base_vha, 0x00fc,
3347 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3348 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3349 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3350 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003351 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003353 qlt_add_target(ha, base_vha);
3354
Joe Lawrence6b383972014-08-26 17:12:29 -04003355 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003356
3357 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3358 return -ENODEV;
3359
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003360 if (ha->flags.detected_lr_sfp) {
3361 ql_log(ql_log_info, base_vha, 0xffff,
3362 "Reset chip to pick up LR SFP setting\n");
3363 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3364 qla2xxx_wake_dpc(base_vha);
3365 }
3366
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 return 0;
3368
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003369probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003370 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003371 ha->req_q_map[0] = NULL;
3372 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003373 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003374 ha->rsp_q_map[0] = NULL;
3375 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003376 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003377
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003379 if (base_vha->timer_active)
3380 qla2x00_stop_timer(base_vha);
3381 base_vha->flags.online = 0;
3382 if (ha->dpc_thread) {
3383 struct task_struct *t = ha->dpc_thread;
3384
3385 ha->dpc_thread = NULL;
3386 kthread_stop(t);
3387 }
3388
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003391 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003393probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003394 qla2x00_clear_drv_active(ha);
3395
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003396iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003397 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003398 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003399 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003400 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003401 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003402 } else {
3403 if (ha->iobase)
3404 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003405 if (ha->cregbase)
3406 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003407 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003408 pci_release_selected_regions(ha->pdev, ha->bars);
3409 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003411disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003412 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003413 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
Adrian Bunk4c993f72008-01-14 00:55:16 -08003416static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003417qla2x00_shutdown(struct pci_dev *pdev)
3418{
3419 scsi_qla_host_t *vha;
3420 struct qla_hw_data *ha;
3421
3422 vha = pci_get_drvdata(pdev);
3423 ha = vha->hw;
3424
Sawan Chandakefdb5762017-08-23 15:05:00 -07003425 ql_log(ql_log_info, vha, 0xfffa,
3426 "Adapter shutdown\n");
3427
3428 /*
3429 * Prevent future board_disable and wait
3430 * until any pending board_disable has completed.
3431 */
3432 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3433 cancel_work_sync(&ha->board_disable);
3434
3435 if (!atomic_read(&pdev->enable_cnt))
3436 return;
3437
Armen Baloyan42479342013-08-27 01:37:37 -04003438 /* Notify ISPFX00 firmware */
3439 if (IS_QLAFX00(ha))
3440 qlafx00_driver_shutdown(vha, 20);
3441
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003442 /* Turn-off FCE trace */
3443 if (ha->flags.fce_enabled) {
3444 qla2x00_disable_fce_trace(vha, NULL, NULL);
3445 ha->flags.fce_enabled = 0;
3446 }
3447
3448 /* Turn-off EFT trace */
3449 if (ha->eft)
3450 qla2x00_disable_eft_trace(vha);
3451
3452 /* Stop currently executing firmware. */
3453 qla2x00_try_to_stop_firmware(vha);
3454
3455 /* Turn adapter off line */
3456 vha->flags.online = 0;
3457
3458 /* turn-off interrupts on the card */
3459 if (ha->interrupts_on) {
3460 vha->flags.init_done = 0;
3461 ha->isp_ops->disable_intrs(ha);
3462 }
3463
3464 qla2x00_free_irqs(vha);
3465
3466 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003467
Chad Dupuis61d41f62014-09-25 05:17:02 -04003468 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003469 ql_log(ql_log_info, vha, 0xfffe,
3470 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003471}
3472
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003473/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003474static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003475qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003477 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003478 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
Arun Easi43ebf162011-05-10 11:18:16 -07003480 mutex_lock(&ha->vport_lock);
3481 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003482 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003483
Arun Easi43ebf162011-05-10 11:18:16 -07003484 BUG_ON(base_vha->list.next == &ha->vp_list);
3485 /* This assumes first entry in ha->vp_list is always base vha */
3486 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003487 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003488
Arun Easi43ebf162011-05-10 11:18:16 -07003489 spin_unlock_irqrestore(&ha->vport_slock, flags);
3490 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003491
Arun Easi43ebf162011-05-10 11:18:16 -07003492 fc_vport_terminate(vha->fc_vport);
3493 scsi_host_put(vha->host);
3494
3495 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003496 }
Arun Easi43ebf162011-05-10 11:18:16 -07003497 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003498}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003499
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003500/* Stops all deferred work threads */
3501static void
3502qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3503{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003504 /* Cancel all work and destroy DPC workqueues */
3505 if (ha->dpc_lp_wq) {
3506 cancel_work_sync(&ha->idc_aen);
3507 destroy_workqueue(ha->dpc_lp_wq);
3508 ha->dpc_lp_wq = NULL;
3509 }
3510
3511 if (ha->dpc_hp_wq) {
3512 cancel_work_sync(&ha->nic_core_reset);
3513 cancel_work_sync(&ha->idc_state_handler);
3514 cancel_work_sync(&ha->nic_core_unrecoverable);
3515 destroy_workqueue(ha->dpc_hp_wq);
3516 ha->dpc_hp_wq = NULL;
3517 }
3518
Andrew Vasquezb9978762009-03-24 09:08:05 -07003519 /* Kill the kernel thread for this host */
3520 if (ha->dpc_thread) {
3521 struct task_struct *t = ha->dpc_thread;
3522
3523 /*
3524 * qla2xxx_wake_dpc checks for ->dpc_thread
3525 * so we need to zero it out.
3526 */
3527 ha->dpc_thread = NULL;
3528 kthread_stop(t);
3529 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003530}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003531
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003532static void
3533qla2x00_unmap_iobases(struct qla_hw_data *ha)
3534{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003535 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003536
Chad Dupuisf73cb692014-02-26 04:15:06 -05003537 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003538 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003539 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003540 } else {
3541 if (ha->iobase)
3542 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003544 if (ha->cregbase)
3545 iounmap(ha->cregbase);
3546
Giridhar Malavalia9083012010-04-12 17:59:55 -07003547 if (ha->mqiobase)
3548 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003549
Chad Dupuisf73cb692014-02-26 04:15:06 -05003550 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003551 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003552 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003553}
3554
3555static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003556qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003557{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003558 if (IS_QLA8044(ha)) {
3559 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003560 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003561 qla8044_idc_unlock(ha);
3562 } else if (IS_QLA82XX(ha)) {
3563 qla82xx_idc_lock(ha);
3564 qla82xx_clear_drv_active(ha);
3565 qla82xx_idc_unlock(ha);
3566 }
3567}
3568
3569static void
3570qla2x00_remove_one(struct pci_dev *pdev)
3571{
3572 scsi_qla_host_t *base_vha;
3573 struct qla_hw_data *ha;
3574
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003575 base_vha = pci_get_drvdata(pdev);
3576 ha = base_vha->hw;
3577
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003578 /* Indicate device removal to prevent future board_disable and wait
3579 * until any pending board_disable has completed. */
3580 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3581 cancel_work_sync(&ha->board_disable);
3582
3583 /*
3584 * If the PCI device is disabled then there was a PCI-disconnect and
3585 * qla2x00_disable_board_on_pci_error has taken care of most of the
3586 * resources.
3587 */
3588 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003589 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3590 base_vha->gnl.l, base_vha->gnl.ldma);
3591
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003592 scsi_host_put(base_vha->host);
3593 kfree(ha);
3594 pci_set_drvdata(pdev, NULL);
3595 return;
3596 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003597 qla2x00_wait_for_hba_ready(base_vha);
3598
Quinn Tran726b8542017-01-19 22:28:00 -08003599 /*
3600 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003601 * where it was set first.
3602 */
3603 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3604 return;
3605
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003606 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003607
3608 qla_nvme_delete(base_vha);
3609
Quinn Tran726b8542017-01-19 22:28:00 -08003610 dma_free_coherent(&ha->pdev->dev,
3611 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003612
3613 if (IS_QLAFX00(ha))
3614 qlafx00_driver_shutdown(base_vha, 20);
3615
3616 qla2x00_delete_all_vps(ha, base_vha);
3617
3618 if (IS_QLA8031(ha)) {
3619 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3620 "Clearing fcoe driver presence.\n");
3621 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3622 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3623 "Error while clearing DRV-Presence.\n");
3624 }
3625
3626 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3627
3628 qla2x00_dfs_remove(base_vha);
3629
3630 qla84xx_put_chip(base_vha);
3631
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04003632 /* Laser should be disabled only for ISP2031 */
3633 if (IS_QLA2031(ha))
3634 qla83xx_disable_laser(base_vha);
3635
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003636 /* Disable timer */
3637 if (base_vha->timer_active)
3638 qla2x00_stop_timer(base_vha);
3639
3640 base_vha->flags.online = 0;
3641
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003642 /* free DMA memory */
3643 if (ha->exlogin_buf)
3644 qla2x00_free_exlogin_buffer(ha);
3645
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003646 /* free DMA memory */
3647 if (ha->exchoffld_buf)
3648 qla2x00_free_exchoffld_buffer(ha);
3649
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003650 qla2x00_destroy_deferred_work(ha);
3651
3652 qlt_remove_target(ha, base_vha);
3653
3654 qla2x00_free_sysfs_attr(base_vha, true);
3655
3656 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003657 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003658
3659 scsi_remove_host(base_vha->host);
3660
3661 qla2x00_free_device(base_vha);
3662
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003663 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003664
Arun Easid2749ff2014-09-25 05:16:51 -04003665 scsi_host_put(base_vha->host);
3666
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003667 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003668
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003669 pci_release_selected_regions(ha->pdev, ha->bars);
3670 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003672 pci_disable_pcie_error_reporting(pdev);
3673
Bernhard Walle665db932007-03-28 00:49:49 +02003674 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676
3677static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003678qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003680 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681
Andrew Vasquez85880802009-12-15 21:29:46 -08003682 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3683
3684 /* Disable timer */
3685 if (vha->timer_active)
3686 qla2x00_stop_timer(vha);
3687
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003688 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003689
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003690 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003691 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003692
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003693 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003694 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003695
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003696 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003697 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698
Andrew Vasquez85880802009-12-15 21:29:46 -08003699 vha->flags.online = 0;
3700
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003701 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003702 if (ha->interrupts_on) {
3703 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003704 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003705 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003706
Quinn Tran093df732016-12-12 14:40:09 -08003707 qla2x00_free_fcports(vha);
3708
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003709 qla2x00_free_irqs(vha);
3710
Quinn Tran093df732016-12-12 14:40:09 -08003711 /* Flush the work queue and remove it */
3712 if (ha->wq) {
3713 flush_workqueue(ha->wq);
3714 destroy_workqueue(ha->wq);
3715 ha->wq = NULL;
3716 }
3717
Chad Dupuis88670482010-07-23 15:28:30 +05003718
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003719 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003720
Giridhar Malavali08de2842011-08-16 11:31:44 -07003721 qla82xx_md_free(vha);
3722
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003723 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724}
3725
Chad Dupuis88670482010-07-23 15:28:30 +05003726void qla2x00_free_fcports(struct scsi_qla_host *vha)
3727{
3728 fc_port_t *fcport, *tfcport;
3729
3730 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3731 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003732 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003733 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003734 }
3735}
3736
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003737static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003738qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003739 int defer)
3740{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003741 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003742 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003743 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003744
3745 if (!fcport->rport)
3746 return;
3747
3748 rport = fcport->rport;
3749 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003750 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003751 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003752 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003753 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003754 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003755 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3756 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003757 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003758 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003759 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003760 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3761 "%s %8phN. rport %p roles %x\n",
3762 __func__, fcport->port_name, rport,
3763 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003764 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003765 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003766 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003767 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003768}
3769
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3772 *
3773 * Input: ha = adapter block pointer. fcport = port structure pointer.
3774 *
3775 * Return: None.
3776 *
3777 * Context:
3778 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003779void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003780 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003782 if (IS_QLAFX00(vha->hw)) {
3783 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3784 qla2x00_schedule_rport_del(vha, fcport, defer);
3785 return;
3786 }
3787
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003788 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003789 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003790 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003791 qla2x00_schedule_rport_del(vha, fcport, defer);
3792 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003793 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 * We may need to retry the login, so don't change the state of the
3795 * port but do the retries.
3796 */
3797 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003798 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799
3800 if (!do_login)
3801 return;
3802
Arun Easia1d02852015-08-04 13:38:02 -04003803 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3804
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807
Quinn Tran83548fe2017-06-02 09:12:01 -07003808 ql_dbg(ql_dbg_disc, vha, 0x20a3,
Quinn Tran726b8542017-01-19 22:28:00 -08003809 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003810 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 }
3812}
3813
3814/*
3815 * qla2x00_mark_all_devices_lost
3816 * Updates fcport state when device goes offline.
3817 *
3818 * Input:
3819 * ha = adapter block pointer.
3820 * fcport = port structure pointer.
3821 *
3822 * Return:
3823 * None.
3824 *
3825 * Context:
3826 */
3827void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003828qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829{
3830 fc_port_t *fcport;
3831
Quinn Tran83548fe2017-06-02 09:12:01 -07003832 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3833 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003836 fcport->scan_state = 0;
3837 qlt_schedule_sess_for_deletion_lock(fcport);
3838
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003839 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003841
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 /*
3843 * No point in marking the device as lost, if the device is
3844 * already DEAD.
3845 */
3846 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3847 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003848 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003849 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003850 if (defer)
3851 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003852 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003853 qla2x00_schedule_rport_del(vha, fcport, defer);
3854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 }
3856}
3857
3858/*
3859* qla2x00_mem_alloc
3860* Allocates adapter memory.
3861*
3862* Returns:
3863* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003864* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003866static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003867qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3868 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869{
3870 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871
Andrew Vasqueze8711082008-01-31 12:33:48 -08003872 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003873 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003874 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003875 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003877 if (qlt_mem_alloc(ha) < 0)
3878 goto fail_free_init_cb;
3879
Chad Dupuis642ef982012-02-09 11:15:57 -08003880 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3881 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003882 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003883 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884
Andrew Vasqueze8711082008-01-31 12:33:48 -08003885 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3886 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003887 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003889 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003890 /* Allocate cache for CT6 Ctx. */
3891 if (!ctx_cachep) {
3892 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3893 sizeof(struct ct6_dsd), 0,
3894 SLAB_HWCACHE_ALIGN, NULL);
3895 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003896 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003897 }
3898 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3899 ctx_cachep);
3900 if (!ha->ctx_mempool)
3901 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003902 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3903 "ctx_cachep=%p ctx_mempool=%p.\n",
3904 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003905 }
3906
Andrew Vasqueze8711082008-01-31 12:33:48 -08003907 /* Get memory for cached NVRAM */
3908 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3909 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003910 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3913 ha->pdev->device);
3914 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3915 DMA_POOL_SIZE, 8, 0);
3916 if (!ha->s_dma_pool)
3917 goto fail_free_nvram;
3918
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003919 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3920 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3921 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3922
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003923 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003924 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3925 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3926 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003927 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3928 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003929 goto fail_s_dma_pool;
3930 }
3931
3932 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3933 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3934 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003935 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3936 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003937 goto fail_dl_dma_pool;
3938 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003939 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3940 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3941 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003942 }
3943
Andrew Vasqueze8711082008-01-31 12:33:48 -08003944 /* Allocate memory for SNS commands */
3945 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003946 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003947 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003948 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003949 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003950 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003951 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003952 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003953 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003954 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003955 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003956 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003957 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003958 goto fail_dma_pool;
3959 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003960 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003961 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003962 if (!ha->ct_sns)
3963 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003964 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3965 "ms_iocb=%p ct_sns=%p.\n",
3966 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 }
3968
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003969 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003970 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3971 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003972 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3973 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003974 goto fail_req;
3975 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003976 (*req)->length = req_len;
3977 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3978 ((*req)->length + 1) * sizeof(request_t),
3979 &(*req)->dma, GFP_KERNEL);
3980 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003981 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3982 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003983 goto fail_req_ring;
3984 }
3985 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003986 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3987 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003988 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3989 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003990 goto fail_rsp;
3991 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003992 (*rsp)->hw = ha;
3993 (*rsp)->length = rsp_len;
3994 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3995 ((*rsp)->length + 1) * sizeof(response_t),
3996 &(*rsp)->dma, GFP_KERNEL);
3997 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003998 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3999 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004000 goto fail_rsp_ring;
4001 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004002 (*req)->rsp = *rsp;
4003 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004004 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4005 "req=%p req->length=%d req->ring=%p rsp=%p "
4006 "rsp->length=%d rsp->ring=%p.\n",
4007 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4008 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004009 /* Allocate memory for NVRAM data for vports */
4010 if (ha->nvram_npiv_size) {
4011 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004012 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004013 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004014 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4015 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004016 goto fail_npiv_info;
4017 }
4018 } else
4019 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004020
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004021 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004022 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004023 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4024 &ha->ex_init_cb_dma);
4025 if (!ha->ex_init_cb)
4026 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004027 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4028 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004029 }
4030
Giridhar Malavalia9083012010-04-12 17:59:55 -07004031 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4032
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004033 /* Get consistent memory allocated for Async Port-Database. */
4034 if (!IS_FWI2_CAPABLE(ha)) {
4035 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4036 &ha->async_pd_dma);
4037 if (!ha->async_pd)
4038 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004039 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4040 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004041 }
4042
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004043 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004044
4045 /* Allocate memory for our loop_id bitmap */
4046 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
4047 GFP_KERNEL);
4048 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004049 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004050 else {
4051 qla2x00_set_reserved_loop_ids(ha);
4052 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004053 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004054 }
4055
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004056 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4057 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4058 if (!ha->sfp_data) {
4059 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4060 "Unable to allocate memory for SFP read-data.\n");
4061 goto fail_sfp_data;
4062 }
4063
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004064 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004065
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004066fail_sfp_data:
4067 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004068fail_loop_id_map:
4069 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004070fail_async_pd:
4071 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004072fail_ex_init_cb:
4073 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004074fail_npiv_info:
4075 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4076 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4077 (*rsp)->ring = NULL;
4078 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004079fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004080 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004081fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004082 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4083 sizeof(request_t), (*req)->ring, (*req)->dma);
4084 (*req)->ring = NULL;
4085 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004086fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004087 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004088fail_req:
4089 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4090 ha->ct_sns, ha->ct_sns_dma);
4091 ha->ct_sns = NULL;
4092 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004093fail_free_ms_iocb:
4094 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4095 ha->ms_iocb = NULL;
4096 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004097
4098 if (ha->sns_cmd)
4099 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4100 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004101fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004102 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004103 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4104 ha->fcp_cmnd_dma_pool = NULL;
4105 }
4106fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004107 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004108 dma_pool_destroy(ha->dl_dma_pool);
4109 ha->dl_dma_pool = NULL;
4110 }
4111fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004112 dma_pool_destroy(ha->s_dma_pool);
4113 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004114fail_free_nvram:
4115 kfree(ha->nvram);
4116 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004117fail_free_ctx_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004118 if (ha->ctx_mempool)
4119 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004120 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004121fail_free_srb_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004122 if (ha->srb_mempool)
4123 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004124 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004125fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004126 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4127 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004128 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004129 ha->gid_list = NULL;
4130 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004131fail_free_tgt_mem:
4132 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133fail_free_init_cb:
4134 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4135 ha->init_cb_dma);
4136 ha->init_cb = NULL;
4137 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004138fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004139 ql_log(ql_log_fatal, NULL, 0x0030,
4140 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004141 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142}
4143
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004144int
4145qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4146{
4147 int rval;
4148 uint16_t size, max_cnt, temp;
4149 struct qla_hw_data *ha = vha->hw;
4150
4151 /* Return if we don't need to alloacate any extended logins */
4152 if (!ql2xexlogins)
4153 return QLA_SUCCESS;
4154
Quinn Tran99e1b682017-06-02 09:12:03 -07004155 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4156 return QLA_SUCCESS;
4157
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004158 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4159 max_cnt = 0;
4160 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4161 if (rval != QLA_SUCCESS) {
4162 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4163 "Failed to get exlogin status.\n");
4164 return rval;
4165 }
4166
4167 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004168 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004169
Quinn Tran99e1b682017-06-02 09:12:03 -07004170 if (temp != ha->exlogin_size) {
4171 qla2x00_free_exlogin_buffer(ha);
4172 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004173
Quinn Tran99e1b682017-06-02 09:12:03 -07004174 ql_log(ql_log_info, vha, 0xd024,
4175 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4176 max_cnt, size, temp);
4177
4178 ql_log(ql_log_info, vha, 0xd025,
4179 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4180
4181 /* Get consistent memory for extended logins */
4182 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4183 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4184 if (!ha->exlogin_buf) {
4185 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004186 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004187 return -ENOMEM;
4188 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004189 }
4190
4191 /* Now configure the dma buffer */
4192 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4193 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004194 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004195 "Setup extended login buffer ****FAILED****.\n");
4196 qla2x00_free_exlogin_buffer(ha);
4197 }
4198
4199 return rval;
4200}
4201
4202/*
4203* qla2x00_free_exlogin_buffer
4204*
4205* Input:
4206* ha = adapter block pointer
4207*/
4208void
4209qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4210{
4211 if (ha->exlogin_buf) {
4212 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4213 ha->exlogin_buf, ha->exlogin_buf_dma);
4214 ha->exlogin_buf = NULL;
4215 ha->exlogin_size = 0;
4216 }
4217}
4218
Quinn Tran99e1b682017-06-02 09:12:03 -07004219static void
4220qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4221{
4222 u32 temp;
4223 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4224
4225 if (qla_ini_mode_enabled(vha)) {
4226 if (ql2xiniexchg > max_cnt)
4227 ql2xiniexchg = max_cnt;
4228
4229 if (ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4230 *ret_cnt = ql2xiniexchg;
4231 } else if (qla_tgt_mode_enabled(vha)) {
4232 if (ql2xexchoffld > max_cnt)
4233 ql2xexchoffld = max_cnt;
4234
4235 if (ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4236 *ret_cnt = ql2xexchoffld;
4237 } else if (qla_dual_mode_enabled(vha)) {
4238 temp = ql2xiniexchg + ql2xexchoffld;
4239 if (temp > max_cnt) {
4240 ql2xiniexchg -= (temp - max_cnt)/2;
4241 ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4242 temp = max_cnt;
4243 }
4244
4245 if (temp > FW_DEF_EXCHANGES_CNT)
4246 *ret_cnt = temp;
4247 }
4248}
4249
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004250int
4251qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4252{
4253 int rval;
Quinn Tran99e1b682017-06-02 09:12:03 -07004254 u16 size, max_cnt;
4255 u32 temp;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004256 struct qla_hw_data *ha = vha->hw;
4257
Quinn Tran99e1b682017-06-02 09:12:03 -07004258 if (!ha->flags.exchoffld_enabled)
4259 return QLA_SUCCESS;
4260
4261 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004262 return QLA_SUCCESS;
4263
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004264 max_cnt = 0;
4265 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4266 if (rval != QLA_SUCCESS) {
4267 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4268 "Failed to get exlogin status.\n");
4269 return rval;
4270 }
4271
Quinn Tran99e1b682017-06-02 09:12:03 -07004272 qla2x00_number_of_exch(vha, &temp, max_cnt);
4273 temp *= size;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004274
Quinn Tran99e1b682017-06-02 09:12:03 -07004275 if (temp != ha->exchoffld_size) {
4276 qla2x00_free_exchoffld_buffer(ha);
4277 ha->exchoffld_size = temp;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004278
Quinn Tran99e1b682017-06-02 09:12:03 -07004279 ql_log(ql_log_info, vha, 0xd016,
4280 "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
4281 max_cnt, size, temp);
4282
4283 ql_log(ql_log_info, vha, 0xd017,
4284 "Exchange Buffers requested size = 0x%x\n",
4285 ha->exchoffld_size);
4286
4287 /* Get consistent memory for extended logins */
4288 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4289 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4290 if (!ha->exchoffld_buf) {
4291 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4292 "Failed to allocate memory for exchoffld_buf_dma.\n");
4293 return -ENOMEM;
4294 }
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004295 }
4296
4297 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004298 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004299 if (rval) {
4300 ql_log(ql_log_fatal, vha, 0xd02e,
4301 "Setup exchange offload buffer ****FAILED****.\n");
4302 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004303 } else {
4304 /* re-adjust number of target exchange */
4305 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4306
4307 if (qla_ini_mode_enabled(vha))
4308 icb->exchange_count = 0;
4309 else
4310 icb->exchange_count = cpu_to_le16(ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004311 }
4312
4313 return rval;
4314}
4315
4316/*
4317* qla2x00_free_exchoffld_buffer
4318*
4319* Input:
4320* ha = adapter block pointer
4321*/
4322void
4323qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4324{
4325 if (ha->exchoffld_buf) {
4326 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4327 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4328 ha->exchoffld_buf = NULL;
4329 ha->exchoffld_size = 0;
4330 }
4331}
4332
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004334* qla2x00_free_fw_dump
4335* Frees fw dump stuff.
4336*
4337* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004338* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004339*/
4340static void
4341qla2x00_free_fw_dump(struct qla_hw_data *ha)
4342{
4343 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004344 dma_free_coherent(&ha->pdev->dev,
4345 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004346
Chad Dupuisf73cb692014-02-26 04:15:06 -05004347 if (ha->eft)
4348 dma_free_coherent(&ha->pdev->dev,
4349 EFT_SIZE, ha->eft, ha->eft_dma);
4350
4351 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004352 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004353 if (ha->fw_dump_template)
4354 vfree(ha->fw_dump_template);
4355
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004356 ha->fce = NULL;
4357 ha->fce_dma = 0;
4358 ha->eft = NULL;
4359 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004360 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004361 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004362 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004363 ha->fw_dump = NULL;
4364 ha->fw_dump_len = 0;
4365 ha->fw_dump_template = NULL;
4366 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004367}
4368
4369/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370* qla2x00_mem_free
4371* Frees all adapter allocated memory.
4372*
4373* Input:
4374* ha = adapter block pointer.
4375*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004376static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004377qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004379 qla2x00_free_fw_dump(ha);
4380
Saurav Kashyap81178772012-08-22 14:21:04 -04004381 if (ha->mctp_dump)
4382 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4383 ha->mctp_dump_dma);
4384
Andrew Vasqueze8711082008-01-31 12:33:48 -08004385 if (ha->srb_mempool)
4386 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004388 if (ha->dcbx_tlv)
4389 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4390 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4391
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004392 if (ha->xgmac_data)
4393 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4394 ha->xgmac_data, ha->xgmac_data_dma);
4395
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 if (ha->sns_cmd)
4397 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004398 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399
4400 if (ha->ct_sns)
4401 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004402 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403
Andrew Vasquez88729e52006-06-23 16:10:50 -07004404 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004405 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4406 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004407
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 if (ha->ms_iocb)
4409 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4410
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004411 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004412 dma_pool_free(ha->s_dma_pool,
4413 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004414
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004415 if (ha->async_pd)
4416 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4417
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 if (ha->s_dma_pool)
4419 dma_pool_destroy(ha->s_dma_pool);
4420
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004422 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4423 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424
Giridhar Malavalia9083012010-04-12 17:59:55 -07004425 if (IS_QLA82XX(ha)) {
4426 if (!list_empty(&ha->gbl_dsd_list)) {
4427 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4428
4429 /* clean up allocated prev pool */
4430 list_for_each_entry_safe(dsd_ptr,
4431 tdsd_ptr, &ha->gbl_dsd_list, list) {
4432 dma_pool_free(ha->dl_dma_pool,
4433 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4434 list_del(&dsd_ptr->list);
4435 kfree(dsd_ptr);
4436 }
4437 }
4438 }
4439
4440 if (ha->dl_dma_pool)
4441 dma_pool_destroy(ha->dl_dma_pool);
4442
4443 if (ha->fcp_cmnd_dma_pool)
4444 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4445
4446 if (ha->ctx_mempool)
4447 mempool_destroy(ha->ctx_mempool);
4448
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004449 qlt_mem_free(ha);
4450
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004451 if (ha->init_cb)
4452 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004453 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004454 vfree(ha->optrom_buffer);
4455 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004456 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08004457 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004458 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459
Andrew Vasqueze8711082008-01-31 12:33:48 -08004460 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004461 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 ha->sns_cmd = NULL;
4463 ha->sns_cmd_dma = 0;
4464 ha->ct_sns = NULL;
4465 ha->ct_sns_dma = 0;
4466 ha->ms_iocb = NULL;
4467 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 ha->init_cb = NULL;
4469 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004470 ha->ex_init_cb = NULL;
4471 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004472 ha->async_pd = NULL;
4473 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474
4475 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004476 ha->dl_dma_pool = NULL;
4477 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 ha->gid_list = NULL;
4480 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004481
4482 ha->tgt.atio_ring = NULL;
4483 ha->tgt.atio_dma = 0;
4484 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004485}
4486
4487struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4488 struct qla_hw_data *ha)
4489{
4490 struct Scsi_Host *host;
4491 struct scsi_qla_host *vha = NULL;
4492
4493 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004494 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004495 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4496 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004497 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004498 }
4499
4500 /* Clear our data area */
4501 vha = shost_priv(host);
4502 memset(vha, 0, sizeof(scsi_qla_host_t));
4503
4504 vha->host = host;
4505 vha->host_no = host->host_no;
4506 vha->hw = ha;
4507
4508 INIT_LIST_HEAD(&vha->vp_fcports);
4509 INIT_LIST_HEAD(&vha->work_list);
4510 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004511 INIT_LIST_HEAD(&vha->qla_cmd_list);
4512 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004513 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004514 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004515 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004516 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004517 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004518 INIT_LIST_HEAD(&vha->gpnid_list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004519
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004520 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004521 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004522 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004523 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004524
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004525 vha->gnl.size = sizeof(struct get_name_list_extended) *
4526 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004527 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4528 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4529 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004530 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004531 "Alloc failed for name list.\n");
4532 scsi_remove_host(vha->host);
4533 return NULL;
4534 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004535
4536 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004537 ql_dbg(ql_dbg_init, vha, 0x0041,
4538 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4539 vha->host, vha->hw, vha,
4540 dev_name(&(ha->pdev->dev)));
4541
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004542 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543}
4544
Quinn Tran726b8542017-01-19 22:28:00 -08004545struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004546qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004547{
4548 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004549 uint8_t bail;
4550
4551 QLA_VHA_MARK_BUSY(vha, bail);
4552 if (bail)
4553 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004554
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004555 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004556 if (!e) {
4557 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004558 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004559 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004560
4561 INIT_LIST_HEAD(&e->list);
4562 e->type = type;
4563 e->flags = QLA_EVT_FLAG_FREE;
4564 return e;
4565}
4566
Quinn Tran726b8542017-01-19 22:28:00 -08004567int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004568qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004569{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004570 unsigned long flags;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004571
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004572 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004573 list_add_tail(&e->list, &vha->work_list);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004574 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004575
4576 if (QLA_EARLY_LINKUP(vha->hw))
4577 schedule_work(&vha->iocb_work);
4578 else
4579 qla2xxx_wake_dpc(vha);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004580
Andrew Vasquez0971de72008-04-03 13:13:18 -07004581 return QLA_SUCCESS;
4582}
4583
4584int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004585qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004586 u32 data)
4587{
4588 struct qla_work_evt *e;
4589
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004590 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004591 if (!e)
4592 return QLA_FUNCTION_FAILED;
4593
4594 e->u.aen.code = code;
4595 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004596 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004597}
4598
Andrew Vasquez8a659572009-02-08 20:50:12 -08004599int
4600qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4601{
4602 struct qla_work_evt *e;
4603
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004604 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004605 if (!e)
4606 return QLA_FUNCTION_FAILED;
4607
4608 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004609 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004610}
4611
Andrew Vasquezac280b62009-08-20 11:06:05 -07004612#define qla2x00_post_async_work(name, type) \
4613int qla2x00_post_async_##name##_work( \
4614 struct scsi_qla_host *vha, \
4615 fc_port_t *fcport, uint16_t *data) \
4616{ \
4617 struct qla_work_evt *e; \
4618 \
4619 e = qla2x00_alloc_work(vha, type); \
4620 if (!e) \
4621 return QLA_FUNCTION_FAILED; \
4622 \
4623 e->u.logio.fcport = fcport; \
4624 if (data) { \
4625 e->u.logio.data[0] = data[0]; \
4626 e->u.logio.data[1] = data[1]; \
4627 } \
4628 return qla2x00_post_work(vha, e); \
4629}
4630
4631qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004632qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4633qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004634qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4635qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004636
Andrew Vasquez3420d362009-10-13 15:16:45 -07004637int
4638qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4639{
4640 struct qla_work_evt *e;
4641
4642 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4643 if (!e)
4644 return QLA_FUNCTION_FAILED;
4645
4646 e->u.uevent.code = code;
4647 return qla2x00_post_work(vha, e);
4648}
4649
4650static void
4651qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4652{
4653 char event_string[40];
4654 char *envp[] = { event_string, NULL };
4655
4656 switch (code) {
4657 case QLA_UEVENT_CODE_FW_DUMP:
4658 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4659 vha->host_no);
4660 break;
4661 default:
4662 /* do nothing */
4663 break;
4664 }
4665 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4666}
4667
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004668int
4669qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4670 uint32_t *data, int cnt)
4671{
4672 struct qla_work_evt *e;
4673
4674 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4675 if (!e)
4676 return QLA_FUNCTION_FAILED;
4677
4678 e->u.aenfx.evtcode = evtcode;
4679 e->u.aenfx.count = cnt;
4680 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4681 return qla2x00_post_work(vha, e);
4682}
4683
Quinn Tran726b8542017-01-19 22:28:00 -08004684int qla24xx_post_upd_fcport_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4685{
4686 struct qla_work_evt *e;
4687
4688 e = qla2x00_alloc_work(vha, QLA_EVT_UPD_FCPORT);
4689 if (!e)
4690 return QLA_FUNCTION_FAILED;
4691
4692 e->u.fcport.fcport = fcport;
4693 return qla2x00_post_work(vha, e);
4694}
4695
4696static
4697void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4698{
4699 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07004700 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08004701 struct qlt_plogi_ack_t *pla =
4702 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07004703 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08004704
4705 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4706 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4707 if (fcport) {
4708 fcport->d_id = e->u.new_sess.id;
4709 if (pla) {
4710 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4711 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4712 /* we took an extra ref_count to prevent PLOGI ACK when
4713 * fcport/sess has not been created.
4714 */
4715 pla->ref_count--;
4716 }
4717 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07004718 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004719 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4720 if (fcport) {
4721 fcport->d_id = e->u.new_sess.id;
4722 fcport->scan_state = QLA_FCPORT_FOUND;
4723 fcport->flags |= FCF_FABRIC_DEVICE;
4724 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
4725
4726 memcpy(fcport->port_name, e->u.new_sess.port_name,
4727 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07004728 } else {
4729 ql_dbg(ql_dbg_disc, vha, 0xffff,
4730 "%s %8phC mem alloc fail.\n",
4731 __func__, e->u.new_sess.port_name);
4732
4733 if (pla)
4734 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4735 return;
4736 }
4737
4738 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4739 /* search again to make sure one else got ahead */
4740 tfcp = qla2x00_find_fcport_by_wwpn(vha,
4741 e->u.new_sess.port_name, 1);
4742 if (tfcp) {
4743 /* should rarily happen */
4744 ql_dbg(ql_dbg_disc, vha, 0xffff,
4745 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
4746 __func__, tfcp->port_name, tfcp->disc_state,
4747 tfcp->fw_login_state);
4748
4749 free_fcport = 1;
4750 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08004751 list_add_tail(&fcport->list, &vha->vp_fcports);
4752
Quinn Tran19759032017-12-04 14:45:15 -08004753 }
4754 if (pla) {
4755 qlt_plogi_ack_link(vha, pla, fcport,
4756 QLT_PLOGI_LINK_SAME_WWN);
4757 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08004758 }
4759 }
4760 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4761
4762 if (fcport) {
Quinn Tran5ef696a2017-12-04 14:45:05 -08004763 if (pla) {
Quinn Tran726b8542017-01-19 22:28:00 -08004764 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08004765 } else {
4766 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4767 tfcp = qla2x00_find_fcport_by_nportid(vha,
4768 &e->u.new_sess.id, 1);
4769 if (tfcp && (tfcp != fcport)) {
4770 /*
4771 * We have a conflict fcport with same NportID.
4772 */
4773 ql_dbg(ql_dbg_disc, vha, 0xffff,
4774 "%s %8phC found conflict b4 add. DS %d LS %d\n",
4775 __func__, tfcp->port_name, tfcp->disc_state,
4776 tfcp->fw_login_state);
4777
4778 switch (tfcp->disc_state) {
4779 case DSC_DELETED:
4780 break;
4781 case DSC_DELETE_PEND:
4782 fcport->login_pause = 1;
4783 tfcp->conflict = fcport;
4784 break;
4785 default:
4786 fcport->login_pause = 1;
4787 tfcp->conflict = fcport;
4788 qlt_schedule_sess_for_deletion_lock
4789 (tfcp);
4790 break;
4791 }
4792 }
4793 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4794 qla24xx_async_gnl(vha, fcport);
4795 }
Quinn Tran726b8542017-01-19 22:28:00 -08004796 }
Quinn Tranb5d15312017-08-30 10:16:49 -07004797
4798 if (free_fcport) {
4799 qla2x00_free_fcport(fcport);
4800 if (pla)
4801 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4802 }
Quinn Tran726b8542017-01-19 22:28:00 -08004803}
4804
Andrew Vasquezac280b62009-08-20 11:06:05 -07004805void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004806qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004807{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004808 struct qla_work_evt *e, *tmp;
4809 unsigned long flags;
4810 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004811
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004812 spin_lock_irqsave(&vha->work_lock, flags);
4813 list_splice_init(&vha->work_list, &work);
4814 spin_unlock_irqrestore(&vha->work_lock, flags);
4815
4816 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004817 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004818
4819 switch (e->type) {
4820 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004821 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004822 e->u.aen.code, e->u.aen.data);
4823 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004824 case QLA_EVT_IDC_ACK:
4825 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4826 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004827 case QLA_EVT_ASYNC_LOGIN:
4828 qla2x00_async_login(vha, e->u.logio.fcport,
4829 e->u.logio.data);
4830 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004831 case QLA_EVT_ASYNC_LOGOUT:
4832 qla2x00_async_logout(vha, e->u.logio.fcport);
4833 break;
4834 case QLA_EVT_ASYNC_LOGOUT_DONE:
4835 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4836 e->u.logio.data);
4837 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004838 case QLA_EVT_ASYNC_ADISC:
4839 qla2x00_async_adisc(vha, e->u.logio.fcport,
4840 e->u.logio.data);
4841 break;
4842 case QLA_EVT_ASYNC_ADISC_DONE:
4843 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4844 e->u.logio.data);
4845 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004846 case QLA_EVT_UEVENT:
4847 qla2x00_uevent_emit(vha, e->u.uevent.code);
4848 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004849 case QLA_EVT_AENFX:
4850 qlafx00_process_aen(vha, e);
4851 break;
Quinn Tran726b8542017-01-19 22:28:00 -08004852 case QLA_EVT_GIDPN:
4853 qla24xx_async_gidpn(vha, e->u.fcport.fcport);
4854 break;
4855 case QLA_EVT_GPNID:
4856 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
4857 break;
4858 case QLA_EVT_GPNID_DONE:
4859 qla24xx_async_gpnid_done(vha, e->u.iosb.sp);
4860 break;
4861 case QLA_EVT_NEW_SESS:
4862 qla24xx_create_new_sess(vha, e);
4863 break;
4864 case QLA_EVT_GPDB:
4865 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
4866 e->u.fcport.opt);
4867 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004868 case QLA_EVT_PRLI:
4869 qla24xx_async_prli(vha, e->u.fcport.fcport);
4870 break;
Quinn Tran726b8542017-01-19 22:28:00 -08004871 case QLA_EVT_GPSC:
4872 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
4873 break;
4874 case QLA_EVT_UPD_FCPORT:
4875 qla2x00_update_fcport(vha, e->u.fcport.fcport);
4876 break;
4877 case QLA_EVT_GNL:
4878 qla24xx_async_gnl(vha, e->u.fcport.fcport);
4879 break;
4880 case QLA_EVT_NACK:
4881 qla24xx_do_nack_work(vha, e);
4882 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004883 }
4884 if (e->flags & QLA_EVT_FLAG_FREE)
4885 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07004886
4887 /* For each work completed decrement vha ref count */
4888 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004889 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004890}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004892/* Relogins all the fcports of a vport
4893 * Context: dpc thread
4894 */
4895void qla2x00_relogin(struct scsi_qla_host *vha)
4896{
4897 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004898 int status;
Quinn Tran726b8542017-01-19 22:28:00 -08004899 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004900
4901 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4902 /*
4903 * If the port is not ONLINE then try to login
4904 * to it if we haven't run out of retries.
4905 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004906 if (atomic_read(&fcport->state) != FCS_ONLINE &&
4907 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Quinn Tran4005a992017-12-04 14:45:06 -08004908
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004909 if (fcport->flags & FCF_FABRIC_DEVICE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004910 ql_dbg(ql_dbg_disc, fcport->vha, 0x2108,
Quinn Tran726b8542017-01-19 22:28:00 -08004911 "%s %8phC DS %d LS %d\n", __func__,
4912 fcport->port_name, fcport->disc_state,
4913 fcport->fw_login_state);
4914 memset(&ea, 0, sizeof(ea));
4915 ea.event = FCME_RELOGIN;
4916 ea.fcport = fcport;
4917 qla2x00_fcport_event_handler(vha, &ea);
4918 } else {
Quinn Tran4005a992017-12-04 14:45:06 -08004919 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004920 status = qla2x00_local_device_login(vha,
4921 fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004922 if (status == QLA_SUCCESS) {
4923 fcport->old_loop_id = fcport->loop_id;
4924 ql_dbg(ql_dbg_disc, vha, 0x2003,
4925 "Port login OK: logged in ID 0x%x.\n",
4926 fcport->loop_id);
4927 qla2x00_update_fcport(vha, fcport);
4928 } else if (status == 1) {
4929 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4930 /* retry the login again */
4931 ql_dbg(ql_dbg_disc, vha, 0x2007,
4932 "Retrying %d login again loop_id 0x%x.\n",
4933 fcport->login_retry,
4934 fcport->loop_id);
4935 } else {
4936 fcport->login_retry = 0;
4937 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004938
Quinn Tran726b8542017-01-19 22:28:00 -08004939 if (fcport->login_retry == 0 &&
4940 status != QLA_SUCCESS)
4941 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004942 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004943 }
4944 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4945 break;
4946 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004947}
4948
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004949/* Schedule work on any of the dpc-workqueues */
4950void
4951qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
4952{
4953 struct qla_hw_data *ha = base_vha->hw;
4954
4955 switch (work_code) {
4956 case MBA_IDC_AEN: /* 0x8200 */
4957 if (ha->dpc_lp_wq)
4958 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
4959 break;
4960
4961 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
4962 if (!ha->flags.nic_core_reset_hdlr_active) {
4963 if (ha->dpc_hp_wq)
4964 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
4965 } else
4966 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
4967 "NIC Core reset is already active. Skip "
4968 "scheduling it again.\n");
4969 break;
4970 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
4971 if (ha->dpc_hp_wq)
4972 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
4973 break;
4974 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
4975 if (ha->dpc_hp_wq)
4976 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
4977 break;
4978 default:
4979 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09004980 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004981 }
4982
4983 return;
4984}
4985
4986/* Work: Perform NIC Core Unrecoverable state handling */
4987void
4988qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
4989{
4990 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04004991 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004992 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4993 uint32_t dev_state = 0;
4994
4995 qla83xx_idc_lock(base_vha, 0);
4996 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4997 qla83xx_reset_ownership(base_vha);
4998 if (ha->flags.nic_core_reset_owner) {
4999 ha->flags.nic_core_reset_owner = 0;
5000 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5001 QLA8XXX_DEV_FAILED);
5002 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5003 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5004 }
5005 qla83xx_idc_unlock(base_vha, 0);
5006}
5007
5008/* Work: Execute IDC state handler */
5009void
5010qla83xx_idc_state_handler_work(struct work_struct *work)
5011{
5012 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005013 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005014 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5015 uint32_t dev_state = 0;
5016
5017 qla83xx_idc_lock(base_vha, 0);
5018 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5019 if (dev_state == QLA8XXX_DEV_FAILED ||
5020 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5021 qla83xx_idc_state_handler(base_vha);
5022 qla83xx_idc_unlock(base_vha, 0);
5023}
5024
Saurav Kashyapfa492632012-11-21 02:40:29 -05005025static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005026qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5027{
5028 int rval = QLA_SUCCESS;
5029 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5030 uint32_t heart_beat_counter1, heart_beat_counter2;
5031
5032 do {
5033 if (time_after(jiffies, heart_beat_wait)) {
5034 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5035 "Nic Core f/w is not alive.\n");
5036 rval = QLA_FUNCTION_FAILED;
5037 break;
5038 }
5039
5040 qla83xx_idc_lock(base_vha, 0);
5041 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5042 &heart_beat_counter1);
5043 qla83xx_idc_unlock(base_vha, 0);
5044 msleep(100);
5045 qla83xx_idc_lock(base_vha, 0);
5046 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5047 &heart_beat_counter2);
5048 qla83xx_idc_unlock(base_vha, 0);
5049 } while (heart_beat_counter1 == heart_beat_counter2);
5050
5051 return rval;
5052}
5053
5054/* Work: Perform NIC Core Reset handling */
5055void
5056qla83xx_nic_core_reset_work(struct work_struct *work)
5057{
5058 struct qla_hw_data *ha =
5059 container_of(work, struct qla_hw_data, nic_core_reset);
5060 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5061 uint32_t dev_state = 0;
5062
Saurav Kashyap81178772012-08-22 14:21:04 -04005063 if (IS_QLA2031(ha)) {
5064 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5065 ql_log(ql_log_warn, base_vha, 0xb081,
5066 "Failed to dump mctp\n");
5067 return;
5068 }
5069
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005070 if (!ha->flags.nic_core_reset_hdlr_active) {
5071 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5072 qla83xx_idc_lock(base_vha, 0);
5073 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5074 &dev_state);
5075 qla83xx_idc_unlock(base_vha, 0);
5076 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5077 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5078 "Nic Core f/w is alive.\n");
5079 return;
5080 }
5081 }
5082
5083 ha->flags.nic_core_reset_hdlr_active = 1;
5084 if (qla83xx_nic_core_reset(base_vha)) {
5085 /* NIC Core reset failed. */
5086 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5087 "NIC Core reset failed.\n");
5088 }
5089 ha->flags.nic_core_reset_hdlr_active = 0;
5090 }
5091}
5092
5093/* Work: Handle 8200 IDC aens */
5094void
5095qla83xx_service_idc_aen(struct work_struct *work)
5096{
5097 struct qla_hw_data *ha =
5098 container_of(work, struct qla_hw_data, idc_aen);
5099 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5100 uint32_t dev_state, idc_control;
5101
5102 qla83xx_idc_lock(base_vha, 0);
5103 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5104 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5105 qla83xx_idc_unlock(base_vha, 0);
5106 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5107 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5108 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5109 "Application requested NIC Core Reset.\n");
5110 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5111 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5112 QLA_SUCCESS) {
5113 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5114 "Other protocol driver requested NIC Core Reset.\n");
5115 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5116 }
5117 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5118 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5119 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5120 }
5121}
5122
5123static void
5124qla83xx_wait_logic(void)
5125{
5126 int i;
5127
5128 /* Yield CPU */
5129 if (!in_interrupt()) {
5130 /*
5131 * Wait about 200ms before retrying again.
5132 * This controls the number of retries for single
5133 * lock operation.
5134 */
5135 msleep(100);
5136 schedule();
5137 } else {
5138 for (i = 0; i < 20; i++)
5139 cpu_relax(); /* This a nop instr on i386 */
5140 }
5141}
5142
Saurav Kashyapfa492632012-11-21 02:40:29 -05005143static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005144qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5145{
5146 int rval;
5147 uint32_t data;
5148 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5149 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5150 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005151 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5152 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005153
5154 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5155 if (rval)
5156 return rval;
5157
5158 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5159 return QLA_SUCCESS;
5160 } else {
5161 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5162 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5163 data);
5164 if (rval)
5165 return rval;
5166
5167 msleep(200);
5168
5169 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5170 &data);
5171 if (rval)
5172 return rval;
5173
5174 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5175 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5176 ~(idc_lck_rcvry_stage_mask));
5177 rval = qla83xx_wr_reg(base_vha,
5178 QLA83XX_IDC_LOCK_RECOVERY, data);
5179 if (rval)
5180 return rval;
5181
5182 /* Forcefully perform IDC UnLock */
5183 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5184 &data);
5185 if (rval)
5186 return rval;
5187 /* Clear lock-id by setting 0xff */
5188 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5189 0xff);
5190 if (rval)
5191 return rval;
5192 /* Clear lock-recovery by setting 0x0 */
5193 rval = qla83xx_wr_reg(base_vha,
5194 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5195 if (rval)
5196 return rval;
5197 } else
5198 return QLA_SUCCESS;
5199 }
5200
5201 return rval;
5202}
5203
Saurav Kashyapfa492632012-11-21 02:40:29 -05005204static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005205qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5206{
5207 int rval = QLA_SUCCESS;
5208 uint32_t o_drv_lockid, n_drv_lockid;
5209 unsigned long lock_recovery_timeout;
5210
5211 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5212retry_lockid:
5213 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5214 if (rval)
5215 goto exit;
5216
5217 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5218 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5219 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5220 return QLA_SUCCESS;
5221 else
5222 return QLA_FUNCTION_FAILED;
5223 }
5224
5225 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5226 if (rval)
5227 goto exit;
5228
5229 if (o_drv_lockid == n_drv_lockid) {
5230 qla83xx_wait_logic();
5231 goto retry_lockid;
5232 } else
5233 return QLA_SUCCESS;
5234
5235exit:
5236 return rval;
5237}
5238
5239void
5240qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5241{
5242 uint16_t options = (requester_id << 15) | BIT_6;
5243 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005244 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005245 struct qla_hw_data *ha = base_vha->hw;
5246
5247 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5248retry_lock:
5249 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5250 == QLA_SUCCESS) {
5251 if (data) {
5252 /* Setting lock-id to our function-number */
5253 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5254 ha->portnum);
5255 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005256 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5257 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005258 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005259 "Failed to acquire IDC lock, acquired by %d, "
5260 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005261
5262 /* Retry/Perform IDC-Lock recovery */
5263 if (qla83xx_idc_lock_recovery(base_vha)
5264 == QLA_SUCCESS) {
5265 qla83xx_wait_logic();
5266 goto retry_lock;
5267 } else
5268 ql_log(ql_log_warn, base_vha, 0xb075,
5269 "IDC Lock recovery FAILED.\n");
5270 }
5271
5272 }
5273
5274 return;
5275
5276 /* XXX: IDC-lock implementation using access-control mbx */
5277retry_lock2:
5278 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5279 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5280 "Failed to acquire IDC lock. retrying...\n");
5281 /* Retry/Perform IDC-Lock recovery */
5282 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5283 qla83xx_wait_logic();
5284 goto retry_lock2;
5285 } else
5286 ql_log(ql_log_warn, base_vha, 0xb076,
5287 "IDC Lock recovery FAILED.\n");
5288 }
5289
5290 return;
5291}
5292
5293void
5294qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5295{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005296#if 0
5297 uint16_t options = (requester_id << 15) | BIT_7;
5298#endif
5299 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005300 uint32_t data;
5301 struct qla_hw_data *ha = base_vha->hw;
5302
5303 /* IDC-unlock implementation using driver-unlock/lock-id
5304 * remote registers
5305 */
5306 retry = 0;
5307retry_unlock:
5308 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5309 == QLA_SUCCESS) {
5310 if (data == ha->portnum) {
5311 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5312 /* Clearing lock-id by setting 0xff */
5313 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5314 } else if (retry < 10) {
5315 /* SV: XXX: IDC unlock retrying needed here? */
5316
5317 /* Retry for IDC-unlock */
5318 qla83xx_wait_logic();
5319 retry++;
5320 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005321 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005322 goto retry_unlock;
5323 }
5324 } else if (retry < 10) {
5325 /* Retry for IDC-unlock */
5326 qla83xx_wait_logic();
5327 retry++;
5328 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005329 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005330 goto retry_unlock;
5331 }
5332
5333 return;
5334
Bart Van Assche5897cb22015-06-04 15:57:20 -07005335#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005336 /* XXX: IDC-unlock implementation using access-control mbx */
5337 retry = 0;
5338retry_unlock2:
5339 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5340 if (retry < 10) {
5341 /* Retry for IDC-unlock */
5342 qla83xx_wait_logic();
5343 retry++;
5344 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005345 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005346 goto retry_unlock2;
5347 }
5348 }
5349
5350 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005351#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005352}
5353
5354int
5355__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5356{
5357 int rval = QLA_SUCCESS;
5358 struct qla_hw_data *ha = vha->hw;
5359 uint32_t drv_presence;
5360
5361 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5362 if (rval == QLA_SUCCESS) {
5363 drv_presence |= (1 << ha->portnum);
5364 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5365 drv_presence);
5366 }
5367
5368 return rval;
5369}
5370
5371int
5372qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5373{
5374 int rval = QLA_SUCCESS;
5375
5376 qla83xx_idc_lock(vha, 0);
5377 rval = __qla83xx_set_drv_presence(vha);
5378 qla83xx_idc_unlock(vha, 0);
5379
5380 return rval;
5381}
5382
5383int
5384__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5385{
5386 int rval = QLA_SUCCESS;
5387 struct qla_hw_data *ha = vha->hw;
5388 uint32_t drv_presence;
5389
5390 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5391 if (rval == QLA_SUCCESS) {
5392 drv_presence &= ~(1 << ha->portnum);
5393 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5394 drv_presence);
5395 }
5396
5397 return rval;
5398}
5399
5400int
5401qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5402{
5403 int rval = QLA_SUCCESS;
5404
5405 qla83xx_idc_lock(vha, 0);
5406 rval = __qla83xx_clear_drv_presence(vha);
5407 qla83xx_idc_unlock(vha, 0);
5408
5409 return rval;
5410}
5411
Saurav Kashyapfa492632012-11-21 02:40:29 -05005412static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005413qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5414{
5415 struct qla_hw_data *ha = vha->hw;
5416 uint32_t drv_ack, drv_presence;
5417 unsigned long ack_timeout;
5418
5419 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5420 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5421 while (1) {
5422 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5423 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005424 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005425 break;
5426
5427 if (time_after_eq(jiffies, ack_timeout)) {
5428 ql_log(ql_log_warn, vha, 0xb067,
5429 "RESET ACK TIMEOUT! drv_presence=0x%x "
5430 "drv_ack=0x%x\n", drv_presence, drv_ack);
5431 /*
5432 * The function(s) which did not ack in time are forced
5433 * to withdraw any further participation in the IDC
5434 * reset.
5435 */
5436 if (drv_ack != drv_presence)
5437 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5438 drv_ack);
5439 break;
5440 }
5441
5442 qla83xx_idc_unlock(vha, 0);
5443 msleep(1000);
5444 qla83xx_idc_lock(vha, 0);
5445 }
5446
5447 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5448 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5449}
5450
Saurav Kashyapfa492632012-11-21 02:40:29 -05005451static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005452qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5453{
5454 int rval = QLA_SUCCESS;
5455 uint32_t idc_control;
5456
5457 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5458 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5459
5460 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5461 __qla83xx_get_idc_control(vha, &idc_control);
5462 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5463 __qla83xx_set_idc_control(vha, 0);
5464
5465 qla83xx_idc_unlock(vha, 0);
5466 rval = qla83xx_restart_nic_firmware(vha);
5467 qla83xx_idc_lock(vha, 0);
5468
5469 if (rval != QLA_SUCCESS) {
5470 ql_log(ql_log_fatal, vha, 0xb06a,
5471 "Failed to restart NIC f/w.\n");
5472 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5473 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5474 } else {
5475 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5476 "Success in restarting nic f/w.\n");
5477 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5478 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5479 }
5480
5481 return rval;
5482}
5483
5484/* Assumes idc_lock always held on entry */
5485int
5486qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5487{
5488 struct qla_hw_data *ha = base_vha->hw;
5489 int rval = QLA_SUCCESS;
5490 unsigned long dev_init_timeout;
5491 uint32_t dev_state;
5492
5493 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5494 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5495
5496 while (1) {
5497
5498 if (time_after_eq(jiffies, dev_init_timeout)) {
5499 ql_log(ql_log_warn, base_vha, 0xb06e,
5500 "Initialization TIMEOUT!\n");
5501 /* Init timeout. Disable further NIC Core
5502 * communication.
5503 */
5504 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5505 QLA8XXX_DEV_FAILED);
5506 ql_log(ql_log_info, base_vha, 0xb06f,
5507 "HW State: FAILED.\n");
5508 }
5509
5510 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5511 switch (dev_state) {
5512 case QLA8XXX_DEV_READY:
5513 if (ha->flags.nic_core_reset_owner)
5514 qla83xx_idc_audit(base_vha,
5515 IDC_AUDIT_COMPLETION);
5516 ha->flags.nic_core_reset_owner = 0;
5517 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5518 "Reset_owner reset by 0x%x.\n",
5519 ha->portnum);
5520 goto exit;
5521 case QLA8XXX_DEV_COLD:
5522 if (ha->flags.nic_core_reset_owner)
5523 rval = qla83xx_device_bootstrap(base_vha);
5524 else {
5525 /* Wait for AEN to change device-state */
5526 qla83xx_idc_unlock(base_vha, 0);
5527 msleep(1000);
5528 qla83xx_idc_lock(base_vha, 0);
5529 }
5530 break;
5531 case QLA8XXX_DEV_INITIALIZING:
5532 /* Wait for AEN to change device-state */
5533 qla83xx_idc_unlock(base_vha, 0);
5534 msleep(1000);
5535 qla83xx_idc_lock(base_vha, 0);
5536 break;
5537 case QLA8XXX_DEV_NEED_RESET:
5538 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5539 qla83xx_need_reset_handler(base_vha);
5540 else {
5541 /* Wait for AEN to change device-state */
5542 qla83xx_idc_unlock(base_vha, 0);
5543 msleep(1000);
5544 qla83xx_idc_lock(base_vha, 0);
5545 }
5546 /* reset timeout value after need reset handler */
5547 dev_init_timeout = jiffies +
5548 (ha->fcoe_dev_init_timeout * HZ);
5549 break;
5550 case QLA8XXX_DEV_NEED_QUIESCENT:
5551 /* XXX: DEBUG for now */
5552 qla83xx_idc_unlock(base_vha, 0);
5553 msleep(1000);
5554 qla83xx_idc_lock(base_vha, 0);
5555 break;
5556 case QLA8XXX_DEV_QUIESCENT:
5557 /* XXX: DEBUG for now */
5558 if (ha->flags.quiesce_owner)
5559 goto exit;
5560
5561 qla83xx_idc_unlock(base_vha, 0);
5562 msleep(1000);
5563 qla83xx_idc_lock(base_vha, 0);
5564 dev_init_timeout = jiffies +
5565 (ha->fcoe_dev_init_timeout * HZ);
5566 break;
5567 case QLA8XXX_DEV_FAILED:
5568 if (ha->flags.nic_core_reset_owner)
5569 qla83xx_idc_audit(base_vha,
5570 IDC_AUDIT_COMPLETION);
5571 ha->flags.nic_core_reset_owner = 0;
5572 __qla83xx_clear_drv_presence(base_vha);
5573 qla83xx_idc_unlock(base_vha, 0);
5574 qla8xxx_dev_failed_handler(base_vha);
5575 rval = QLA_FUNCTION_FAILED;
5576 qla83xx_idc_lock(base_vha, 0);
5577 goto exit;
5578 case QLA8XXX_BAD_VALUE:
5579 qla83xx_idc_unlock(base_vha, 0);
5580 msleep(1000);
5581 qla83xx_idc_lock(base_vha, 0);
5582 break;
5583 default:
5584 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09005585 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005586 qla83xx_idc_unlock(base_vha, 0);
5587 qla8xxx_dev_failed_handler(base_vha);
5588 rval = QLA_FUNCTION_FAILED;
5589 qla83xx_idc_lock(base_vha, 0);
5590 goto exit;
5591 }
5592 }
5593
5594exit:
5595 return rval;
5596}
5597
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005598void
5599qla2x00_disable_board_on_pci_error(struct work_struct *work)
5600{
5601 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5602 board_disable);
5603 struct pci_dev *pdev = ha->pdev;
5604 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5605
Quinn Tran726b8542017-01-19 22:28:00 -08005606 /*
5607 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005608 * where it was set first.
5609 */
5610 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5611 return;
5612
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005613 ql_log(ql_log_warn, base_vha, 0x015b,
5614 "Disabling adapter.\n");
5615
Sawan Chandakefdb5762017-08-23 15:05:00 -07005616 if (!atomic_read(&pdev->enable_cnt)) {
5617 ql_log(ql_log_info, base_vha, 0xfffc,
5618 "PCI device disabled, no action req for PCI error=%lx\n",
5619 base_vha->pci_flags);
5620 return;
5621 }
5622
Quinn Tran726b8542017-01-19 22:28:00 -08005623 qla2x00_wait_for_sess_deletion(base_vha);
5624
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005625 set_bit(UNLOADING, &base_vha->dpc_flags);
5626
5627 qla2x00_delete_all_vps(ha, base_vha);
5628
5629 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5630
5631 qla2x00_dfs_remove(base_vha);
5632
5633 qla84xx_put_chip(base_vha);
5634
5635 if (base_vha->timer_active)
5636 qla2x00_stop_timer(base_vha);
5637
5638 base_vha->flags.online = 0;
5639
5640 qla2x00_destroy_deferred_work(ha);
5641
5642 /*
5643 * Do not try to stop beacon blink as it will issue a mailbox
5644 * command.
5645 */
5646 qla2x00_free_sysfs_attr(base_vha, false);
5647
5648 fc_remove_host(base_vha->host);
5649
5650 scsi_remove_host(base_vha->host);
5651
5652 base_vha->flags.init_done = 0;
5653 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005654 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08005655 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005656 qla2x00_mem_free(ha);
5657 qla82xx_md_free(base_vha);
5658 qla2x00_free_queues(ha);
5659
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005660 qla2x00_unmap_iobases(ha);
5661
5662 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005663 pci_disable_pcie_error_reporting(pdev);
5664 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005665
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005666 /*
5667 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5668 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005669}
5670
Linus Torvalds1da177e2005-04-16 15:20:36 -07005671/**************************************************************************
5672* qla2x00_do_dpc
5673* This kernel thread is a task that is schedule by the interrupt handler
5674* to perform the background processing for interrupts.
5675*
5676* Notes:
5677* This task always run in the context of a kernel thread. It
5678* is kick-off by the driver's detect code and starts up
5679* up one per adapter. It immediately goes to sleep and waits for
5680* some fibre event. When either the interrupt handler or
5681* the timer routine detects a event it will one of the task
5682* bits then wake us up.
5683**************************************************************************/
5684static int
5685qla2x00_do_dpc(void *data)
5686{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005687 scsi_qla_host_t *base_vha;
5688 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08005689 uint32_t online;
5690 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005691
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005692 ha = (struct qla_hw_data *)data;
5693 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694
Dongsheng Yang8698a742014-03-11 18:09:12 +08005695 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005696
James Bottomley563585e2011-01-27 16:12:37 -05005697 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005698 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005699 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5700 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005701
Christoph Hellwig39a11242006-02-14 18:46:22 +01005702 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005704 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5705 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706
Andrew Vasquez85880802009-12-15 21:29:46 -08005707 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005708 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5709 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005710 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005711 }
5712
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713 ha->dpc_active = 1;
5714
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005715 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5716 "DPC handler waking up, dpc_flags=0x%lx.\n",
5717 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005719 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5720 break;
5721
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005722 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005723
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005724 if (IS_P3P_TYPE(ha)) {
5725 if (IS_QLA8044(ha)) {
5726 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5727 &base_vha->dpc_flags)) {
5728 qla8044_idc_lock(ha);
5729 qla8044_wr_direct(base_vha,
5730 QLA8044_CRB_DEV_STATE_INDEX,
5731 QLA8XXX_DEV_FAILED);
5732 qla8044_idc_unlock(ha);
5733 ql_log(ql_log_info, base_vha, 0x4004,
5734 "HW State: FAILED.\n");
5735 qla8044_device_state_handler(base_vha);
5736 continue;
5737 }
5738
5739 } else {
5740 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5741 &base_vha->dpc_flags)) {
5742 qla82xx_idc_lock(ha);
5743 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5744 QLA8XXX_DEV_FAILED);
5745 qla82xx_idc_unlock(ha);
5746 ql_log(ql_log_info, base_vha, 0x0151,
5747 "HW State: FAILED.\n");
5748 qla82xx_device_state_handler(base_vha);
5749 continue;
5750 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005751 }
5752
5753 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5754 &base_vha->dpc_flags)) {
5755
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005756 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5757 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005758 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5759 &base_vha->dpc_flags))) {
5760 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5761 /* FCoE-ctx reset failed.
5762 * Escalate to chip-reset
5763 */
5764 set_bit(ISP_ABORT_NEEDED,
5765 &base_vha->dpc_flags);
5766 }
5767 clear_bit(ABORT_ISP_ACTIVE,
5768 &base_vha->dpc_flags);
5769 }
5770
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005771 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5772 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005773 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005774 } else if (IS_QLAFX00(ha)) {
5775 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5776 &base_vha->dpc_flags)) {
5777 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5778 "Firmware Reset Recovery\n");
5779 if (qlafx00_reset_initialize(base_vha)) {
5780 /* Failed. Abort isp later. */
5781 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005782 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005783 set_bit(ISP_UNRECOVERABLE,
5784 &base_vha->dpc_flags);
5785 ql_dbg(ql_dbg_dpc, base_vha,
5786 0x4021,
5787 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005788 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005789 }
5790 }
5791
5792 if (test_and_clear_bit(FX00_TARGET_SCAN,
5793 &base_vha->dpc_flags)) {
5794 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5795 "ISPFx00 Target Scan scheduled\n");
5796 if (qlafx00_rescan_isp(base_vha)) {
5797 if (!test_bit(UNLOADING,
5798 &base_vha->dpc_flags))
5799 set_bit(ISP_UNRECOVERABLE,
5800 &base_vha->dpc_flags);
5801 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5802 "ISPFx00 Target Scan Failed\n");
5803 }
5804 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5805 "ISPFx00 Target Scan End\n");
5806 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04005807 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5808 &base_vha->dpc_flags)) {
5809 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5810 "ISPFx00 Host Info resend scheduled\n");
5811 qlafx00_fx_disc(base_vha,
5812 &base_vha->hw->mr.fcport,
5813 FXDISC_REG_HOST_INFO);
5814 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005815 }
5816
Quinn Trane4e3a2c2017-08-23 15:05:07 -07005817 if (test_and_clear_bit(DETECT_SFP_CHANGE,
5818 &base_vha->dpc_flags) &&
5819 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
5820 qla24xx_detect_sfp(base_vha);
5821
5822 if (ha->flags.detected_lr_sfp !=
5823 ha->flags.using_lr_setting)
5824 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
5825 }
5826
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005827 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5828 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005830 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5831 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005832 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005833 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834
Giridhar Malavalia9083012010-04-12 17:59:55 -07005835 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 /* failed. retry later */
5837 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005838 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005840 clear_bit(ABORT_ISP_ACTIVE,
5841 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005842 }
5843
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005844 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
5845 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005846 }
5847
David Jefferya394aac2012-11-21 02:39:54 -05005848 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
5849 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005850 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07005851 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005852
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005853 if (IS_QLAFX00(ha))
5854 goto loop_resync_check;
5855
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005856 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005857 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
5858 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005859 if (IS_P3P_TYPE(ha)) {
5860 if (IS_QLA82XX(ha))
5861 qla82xx_device_state_handler(base_vha);
5862 if (IS_QLA8044(ha))
5863 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005864 clear_bit(ISP_QUIESCE_NEEDED,
5865 &base_vha->dpc_flags);
5866 if (!ha->flags.quiesce_owner) {
5867 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005868 if (IS_QLA82XX(ha)) {
5869 qla82xx_idc_lock(ha);
5870 qla82xx_clear_qsnt_ready(
5871 base_vha);
5872 qla82xx_idc_unlock(ha);
5873 } else if (IS_QLA8044(ha)) {
5874 qla8044_idc_lock(ha);
5875 qla8044_clear_qsnt_ready(
5876 base_vha);
5877 qla8044_idc_unlock(ha);
5878 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005879 }
5880 } else {
5881 clear_bit(ISP_QUIESCE_NEEDED,
5882 &base_vha->dpc_flags);
5883 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005884 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005885 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
5886 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005887 }
5888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005889 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005890 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005891 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005893 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
5894 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005895 qla2x00_rst_aen(base_vha);
5896 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005897 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
5898 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899 }
5900
5901 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08005902 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005903 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
5904 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905
Quinn Tran4005a992017-12-04 14:45:06 -08005906 if (!base_vha->relogin_jif ||
5907 time_after_eq(jiffies, base_vha->relogin_jif)) {
5908 base_vha->relogin_jif = jiffies + HZ;
5909 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
5910
5911 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
5912 "Relogin scheduled.\n");
5913 qla2x00_relogin(base_vha);
5914 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
5915 "Relogin end.\n");
5916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005918loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005919 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005920 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005922 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
5923 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924
5925 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005926 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927
Bart Van Assche52c82822015-07-09 07:23:26 -07005928 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005930 clear_bit(LOOP_RESYNC_ACTIVE,
5931 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 }
5933
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005934 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
5935 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 }
5937
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005938 if (IS_QLAFX00(ha))
5939 goto intr_on_check;
5940
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005941 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
5942 atomic_read(&base_vha->loop_state) == LOOP_READY) {
5943 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
5944 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07005945 }
5946
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005947intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005949 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005950
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005951 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04005952 &base_vha->dpc_flags)) {
5953 if (ha->beacon_blink_led == 1)
5954 ha->isp_ops->beacon_blink(base_vha);
5955 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08005956
Michael Hernandezd7459522016-12-12 14:40:07 -08005957 /* qpair online check */
5958 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
5959 &base_vha->dpc_flags)) {
5960 if (ha->flags.eeh_busy ||
5961 ha->flags.pci_channel_io_perm_failure)
5962 online = 0;
5963 else
5964 online = 1;
5965
5966 mutex_lock(&ha->mq_lock);
5967 list_for_each_entry(qpair, &base_vha->qp_list,
5968 qp_list_elem)
5969 qpair->online = online;
5970 mutex_unlock(&ha->mq_lock);
5971 }
5972
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07005973 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED, &base_vha->dpc_flags)) {
5974 ql_log(ql_log_info, base_vha, 0xffffff,
5975 "nvme: SET ZIO Activity exchange threshold to %d.\n",
5976 ha->nvme_last_rptd_aen);
5977 if (qla27xx_set_zio_threshold(base_vha, ha->nvme_last_rptd_aen)) {
5978 ql_log(ql_log_info, base_vha, 0xffffff,
5979 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
5980 ha->nvme_last_rptd_aen);
5981 }
5982 }
5983
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005984 if (!IS_QLAFX00(ha))
5985 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005986
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005988end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05005989 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05005991 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005993 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
5994 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995
5996 /*
5997 * Make sure that nobody tries to wake us up again.
5998 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999 ha->dpc_active = 0;
6000
Andrew Vasquezac280b62009-08-20 11:06:05 -07006001 /* Cleanup any residual CTX SRBs. */
6002 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6003
Christoph Hellwig39a11242006-02-14 18:46:22 +01006004 return 0;
6005}
6006
6007void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006008qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006009{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006010 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006011 struct task_struct *t = ha->dpc_thread;
6012
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006013 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006014 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015}
6016
6017/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006018* qla2x00_rst_aen
6019* Processes asynchronous reset.
6020*
6021* Input:
6022* ha = adapter block pointer.
6023*/
6024static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006025qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006027 if (vha->flags.online && !vha->flags.reset_active &&
6028 !atomic_read(&vha->loop_down_timer) &&
6029 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006031 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032
6033 /*
6034 * Issue marker command only when we are going to start
6035 * the I/O.
6036 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006037 vha->marker_needed = 1;
6038 } while (!atomic_read(&vha->loop_down_timer) &&
6039 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040 }
6041}
6042
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043/**************************************************************************
6044* qla2x00_timer
6045*
6046* Description:
6047* One second timer
6048*
6049* Context: Interrupt
6050***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006051void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006052qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006054 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 int start_dpc = 0;
6057 int index;
6058 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006059 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006060 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006061 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006062
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006063 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006064 ql_dbg(ql_dbg_timer, vha, 0x6000,
6065 "EEH = %d, restarting timer.\n",
6066 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006067 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6068 return;
6069 }
6070
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006071 /*
6072 * Hardware read to raise pending EEH errors during mailbox waits. If
6073 * the read returns -1 then disable the board.
6074 */
6075 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006076 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006077 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006080 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006081 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006082 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6083 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006084 if (IS_QLA82XX(ha))
6085 qla82xx_watchdog(vha);
6086 else if (IS_QLA8044(ha))
6087 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006088 }
6089
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006090 if (!vha->vp_idx && IS_QLAFX00(ha))
6091 qlafx00_timer_routine(vha);
6092
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006094 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006095 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6096 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006097 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006099 if (atomic_read(&vha->loop_down_timer) ==
6100 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006102 ql_log(ql_log_info, vha, 0x6008,
6103 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006105 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6106 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006108 /*
6109 * Schedule an ISP abort to return any FCP2-device
6110 * commands.
6111 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006112 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006113 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006114 spin_lock_irqsave(&ha->hardware_lock,
6115 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006116 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006117 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006118 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006119 index++) {
6120 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006121
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006122 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006123 if (!sp)
6124 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006125 if (sp->cmd_type != TYPE_SRB)
6126 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006127 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006128 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006129 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006130 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006131 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006133 if (IS_QLA82XX(ha))
6134 set_bit(FCOE_CTX_RESET_NEEDED,
6135 &vha->dpc_flags);
6136 else
6137 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006138 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006139 break;
6140 }
6141 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006142 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144 start_dpc++;
6145 }
6146
6147 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006148 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006149 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006150 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151 "Loop down - aborting ISP.\n");
6152
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006153 if (IS_QLA82XX(ha))
6154 set_bit(FCOE_CTX_RESET_NEEDED,
6155 &vha->dpc_flags);
6156 else
6157 set_bit(ISP_ABORT_NEEDED,
6158 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159 }
6160 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006161 ql_dbg(ql_dbg_timer, vha, 0x600a,
6162 "Loop down - seconds remaining %d.\n",
6163 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006165 /* Check if beacon LED needs to be blinked for physical host only */
6166 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006167 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006168 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006169 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6170 start_dpc++;
6171 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006172 }
6173
Andrew Vasquez550bf572008-04-24 15:21:23 -07006174 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006175 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07006176 start_dpc++;
6177
Duane Grigsby7401bc12017-06-21 13:48:42 -07006178 /*
6179 * FC-NVME
6180 * see if the active AEN count has changed from what was last reported.
6181 */
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006182 if (!vha->vp_idx &&
6183 atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen &&
6184 ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006185 ql_log(ql_log_info, vha, 0x3002,
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006186 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6187 ha->nvme_last_rptd_aen);
6188 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
6189 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6190 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006191 }
6192
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006194 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6195 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6196 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006198 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6199 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006200 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6201 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006202 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006203 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006204 ql_dbg(ql_dbg_timer, vha, 0x600b,
6205 "isp_abort_needed=%d loop_resync_needed=%d "
6206 "fcport_update_needed=%d start_dpc=%d "
6207 "reset_marker_needed=%d",
6208 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6209 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6210 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6211 start_dpc,
6212 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6213 ql_dbg(ql_dbg_timer, vha, 0x600c,
6214 "beacon_blink_needed=%d isp_unrecoverable=%d "
6215 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006216 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006217 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6218 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6219 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6220 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006221 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006222 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006224
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006225 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226}
6227
Andrew Vasquez54333832005-11-09 15:49:04 -08006228/* Firmware interface routines. */
6229
Chad Dupuisf73cb692014-02-26 04:15:06 -05006230#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006231#define FW_ISP21XX 0
6232#define FW_ISP22XX 1
6233#define FW_ISP2300 2
6234#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006235#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006236#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006237#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006238#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006239#define FW_ISP2031 8
6240#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006241#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08006242
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006243#define FW_FILE_ISP21XX "ql2100_fw.bin"
6244#define FW_FILE_ISP22XX "ql2200_fw.bin"
6245#define FW_FILE_ISP2300 "ql2300_fw.bin"
6246#define FW_FILE_ISP2322 "ql2322_fw.bin"
6247#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006248#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006249#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006250#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006251#define FW_FILE_ISP2031 "ql2600_fw.bin"
6252#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006253#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006254
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006255
Daniel Walkere1e82b62008-05-12 22:21:10 -07006256static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006257
6258static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006259 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6260 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6261 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6262 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6263 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006264 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006265 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006266 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006267 { .name = FW_FILE_ISP2031, },
6268 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006269 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006270};
6271
6272struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006273qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006274{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006275 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006276 struct fw_blob *blob;
6277
Andrew Vasquez54333832005-11-09 15:49:04 -08006278 if (IS_QLA2100(ha)) {
6279 blob = &qla_fw_blobs[FW_ISP21XX];
6280 } else if (IS_QLA2200(ha)) {
6281 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006282 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006283 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006284 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006285 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006286 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006287 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006288 } else if (IS_QLA25XX(ha)) {
6289 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006290 } else if (IS_QLA81XX(ha)) {
6291 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006292 } else if (IS_QLA82XX(ha)) {
6293 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006294 } else if (IS_QLA2031(ha)) {
6295 blob = &qla_fw_blobs[FW_ISP2031];
6296 } else if (IS_QLA8031(ha)) {
6297 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006298 } else if (IS_QLA27XX(ha)) {
6299 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006300 } else {
6301 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006302 }
6303
Daniel Walkere1e82b62008-05-12 22:21:10 -07006304 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006305 if (blob->fw)
6306 goto out;
6307
6308 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006309 ql_log(ql_log_warn, vha, 0x0063,
6310 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006311 blob->fw = NULL;
6312 blob = NULL;
6313 goto out;
6314 }
6315
6316out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006317 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006318 return blob;
6319}
6320
6321static void
6322qla2x00_release_firmware(void)
6323{
6324 int idx;
6325
Daniel Walkere1e82b62008-05-12 22:21:10 -07006326 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006327 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02006328 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006329 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006330}
6331
Seokmann Ju14e660e2007-09-20 14:07:36 -07006332static pci_ers_result_t
6333qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6334{
Andrew Vasquez85880802009-12-15 21:29:46 -08006335 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6336 struct qla_hw_data *ha = vha->hw;
6337
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006338 ql_dbg(ql_dbg_aer, vha, 0x9000,
6339 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006340
Sawan Chandakefdb5762017-08-23 15:05:00 -07006341 if (!atomic_read(&pdev->enable_cnt)) {
6342 ql_log(ql_log_info, vha, 0xffff,
6343 "PCI device is disabled,state %x\n", state);
6344 return PCI_ERS_RESULT_NEED_RESET;
6345 }
6346
Seokmann Ju14e660e2007-09-20 14:07:36 -07006347 switch (state) {
6348 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006349 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006350 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006351 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6352 qla2xxx_wake_dpc(vha);
6353 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006354 return PCI_ERS_RESULT_CAN_RECOVER;
6355 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006356 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006357 /* For ISP82XX complete any pending mailbox cmd */
6358 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006359 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006360 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6361 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006362 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006363 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006364 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006365 /* Return back all IOs */
6366 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006367 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006368 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6369 qla2xxx_wake_dpc(vha);
6370 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006371 return PCI_ERS_RESULT_NEED_RESET;
6372 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006373 ha->flags.pci_channel_io_perm_failure = 1;
6374 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006375 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006376 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6377 qla2xxx_wake_dpc(vha);
6378 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006379 return PCI_ERS_RESULT_DISCONNECT;
6380 }
6381 return PCI_ERS_RESULT_NEED_RESET;
6382}
6383
6384static pci_ers_result_t
6385qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6386{
6387 int risc_paused = 0;
6388 uint32_t stat;
6389 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006390 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6391 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006392 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6393 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6394
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006395 if (IS_QLA82XX(ha))
6396 return PCI_ERS_RESULT_RECOVERED;
6397
Seokmann Ju14e660e2007-09-20 14:07:36 -07006398 spin_lock_irqsave(&ha->hardware_lock, flags);
6399 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6400 stat = RD_REG_DWORD(&reg->hccr);
6401 if (stat & HCCR_RISC_PAUSE)
6402 risc_paused = 1;
6403 } else if (IS_QLA23XX(ha)) {
6404 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6405 if (stat & HSR_RISC_PAUSED)
6406 risc_paused = 1;
6407 } else if (IS_FWI2_CAPABLE(ha)) {
6408 stat = RD_REG_DWORD(&reg24->host_status);
6409 if (stat & HSRX_RISC_PAUSED)
6410 risc_paused = 1;
6411 }
6412 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6413
6414 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006415 ql_log(ql_log_info, base_vha, 0x9003,
6416 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006417 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006418
6419 return PCI_ERS_RESULT_NEED_RESET;
6420 } else
6421 return PCI_ERS_RESULT_RECOVERED;
6422}
6423
Saurav Kashyapfa492632012-11-21 02:40:29 -05006424static uint32_t
6425qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006426{
6427 uint32_t rval = QLA_FUNCTION_FAILED;
6428 uint32_t drv_active = 0;
6429 struct qla_hw_data *ha = base_vha->hw;
6430 int fn;
6431 struct pci_dev *other_pdev = NULL;
6432
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006433 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6434 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006435
6436 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6437
6438 if (base_vha->flags.online) {
6439 /* Abort all outstanding commands,
6440 * so as to be requeued later */
6441 qla2x00_abort_isp_cleanup(base_vha);
6442 }
6443
6444
6445 fn = PCI_FUNC(ha->pdev->devfn);
6446 while (fn > 0) {
6447 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006448 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6449 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006450 other_pdev =
6451 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6452 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6453 fn));
6454
6455 if (!other_pdev)
6456 continue;
6457 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006458 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6459 "Found PCI func available and enable at 0x%x.\n",
6460 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006461 pci_dev_put(other_pdev);
6462 break;
6463 }
6464 pci_dev_put(other_pdev);
6465 }
6466
6467 if (!fn) {
6468 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006469 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6470 "This devfn is reset owner = 0x%x.\n",
6471 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006472 qla82xx_idc_lock(ha);
6473
6474 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006475 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006476
6477 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6478 QLA82XX_IDC_VERSION);
6479
6480 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006481 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6482 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006483
6484 qla82xx_idc_unlock(ha);
6485 /* Reset if device is not already reset
6486 * drv_active would be 0 if a reset has already been done
6487 */
6488 if (drv_active)
6489 rval = qla82xx_start_firmware(base_vha);
6490 else
6491 rval = QLA_SUCCESS;
6492 qla82xx_idc_lock(ha);
6493
6494 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006495 ql_log(ql_log_info, base_vha, 0x900b,
6496 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006497 qla82xx_clear_drv_active(ha);
6498 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006499 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006500 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006501 ql_log(ql_log_info, base_vha, 0x900c,
6502 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006503 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006504 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006505 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08006506 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006507 rval = qla82xx_restart_isp(base_vha);
6508 qla82xx_idc_lock(ha);
6509 /* Clear driver state register */
6510 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6511 qla82xx_set_drv_active(base_vha);
6512 }
6513 qla82xx_idc_unlock(ha);
6514 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006515 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6516 "This devfn is not reset owner = 0x%x.\n",
6517 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006518 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006519 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006520 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006521 rval = qla82xx_restart_isp(base_vha);
6522 qla82xx_idc_lock(ha);
6523 qla82xx_set_drv_active(base_vha);
6524 qla82xx_idc_unlock(ha);
6525 }
6526 }
6527 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6528
6529 return rval;
6530}
6531
Seokmann Ju14e660e2007-09-20 14:07:36 -07006532static pci_ers_result_t
6533qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6534{
6535 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006536 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6537 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006538 struct rsp_que *rsp;
6539 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006540
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006541 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6542 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006543
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006544 /* Workaround: qla2xxx driver which access hardware earlier
6545 * needs error state to be pci_channel_io_online.
6546 * Otherwise mailbox command timesout.
6547 */
6548 pdev->error_state = pci_channel_io_normal;
6549
6550 pci_restore_state(pdev);
6551
Richard Lary8c1496b2010-02-18 10:07:29 -08006552 /* pci_restore_state() clears the saved_state flag of the device
6553 * save restored state which resets saved_state flag
6554 */
6555 pci_save_state(pdev);
6556
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11006557 if (ha->mem_only)
6558 rc = pci_enable_device_mem(pdev);
6559 else
6560 rc = pci_enable_device(pdev);
6561
6562 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006563 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006564 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006565 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006566 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006567
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006568 rsp = ha->rsp_q_map[0];
6569 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006570 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006571
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006572 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006573 goto exit_slot_reset;
6574
6575 if (IS_QLA82XX(ha)) {
6576 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6577 ret = PCI_ERS_RESULT_RECOVERED;
6578 goto exit_slot_reset;
6579 } else
6580 goto exit_slot_reset;
6581 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006582
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006583 while (ha->flags.mbox_busy && retries--)
6584 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08006585
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006586 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006587 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07006588 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006589 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006590
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006591
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006592exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006593 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6594 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08006595
Seokmann Ju14e660e2007-09-20 14:07:36 -07006596 return ret;
6597}
6598
6599static void
6600qla2xxx_pci_resume(struct pci_dev *pdev)
6601{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006602 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6603 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006604 int ret;
6605
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006606 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6607 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006608
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006609 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006610 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006611 ql_log(ql_log_fatal, base_vha, 0x9002,
6612 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07006613 }
Andrew Vasquez85880802009-12-15 21:29:46 -08006614
Lalit Chandivade3e46f032010-05-04 15:01:23 -07006615 pci_cleanup_aer_uncorrect_error_status(pdev);
6616
Andrew Vasquez85880802009-12-15 21:29:46 -08006617 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006618}
6619
Himanshu Madhani2d5a4c32014-09-25 05:16:55 -04006620static void
6621qla83xx_disable_laser(scsi_qla_host_t *vha)
6622{
6623 uint32_t reg, data, fn;
6624 struct qla_hw_data *ha = vha->hw;
6625 struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
6626
6627 /* pci func #/port # */
6628 ql_dbg(ql_dbg_init, vha, 0x004b,
6629 "Disabling Laser for hba: %p\n", vha);
6630
6631 fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
6632 (BIT_15|BIT_14|BIT_13|BIT_12));
6633
6634 fn = (fn >> 12);
6635
6636 if (fn & 1)
6637 reg = PORT_1_2031;
6638 else
6639 reg = PORT_0_2031;
6640
6641 data = LASER_OFF_2031;
6642
6643 qla83xx_wr_reg(vha, reg, data);
6644}
6645
Michael Hernandez56012362016-12-12 14:40:08 -08006646static int qla2xxx_map_queues(struct Scsi_Host *shost)
6647{
Quinn Trand68b8502017-12-04 14:44:59 -08006648 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006649 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6650
Quinn Trand68b8502017-12-04 14:44:59 -08006651 if (USER_CTRL_IRQ(vha->hw))
6652 rc = blk_mq_map_queues(&shost->tag_set);
6653 else
6654 rc = blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev);
6655 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006656}
6657
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07006658static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07006659 .error_detected = qla2xxx_pci_error_detected,
6660 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6661 .slot_reset = qla2xxx_pci_slot_reset,
6662 .resume = qla2xxx_pci_resume,
6663};
6664
Andrew Vasquez54333832005-11-09 15:49:04 -08006665static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006666 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6667 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6668 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6669 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6670 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6671 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6672 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6673 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6674 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006675 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006676 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6677 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006678 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006679 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006680 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006681 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006682 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006683 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006684 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006685 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006686 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006687 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006688 { 0 },
6689};
6690MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6691
Andrew Vasquezfca29702005-07-06 10:31:47 -07006692static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006693 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006694 .driver = {
6695 .owner = THIS_MODULE,
6696 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006697 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006698 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08006699 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07006700 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006701 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07006702};
6703
Al Viro75ef9de2013-04-04 19:09:41 -04006704static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006705 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02006706 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006707};
6708
Linus Torvalds1da177e2005-04-16 15:20:36 -07006709/**
6710 * qla2x00_module_init - Module initialization.
6711 **/
6712static int __init
6713qla2x00_module_init(void)
6714{
Andrew Vasquezfca29702005-07-06 10:31:47 -07006715 int ret = 0;
6716
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006718 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09006719 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006720 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006721 ql_log(ql_log_fatal, NULL, 0x0001,
6722 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 return -ENOMEM;
6724 }
6725
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006726 /* Initialize target kmem_cache and mem_pools */
6727 ret = qlt_init();
6728 if (ret < 0) {
6729 kmem_cache_destroy(srb_cachep);
6730 return ret;
6731 } else if (ret > 0) {
6732 /*
6733 * If initiator mode is explictly disabled by qlt_init(),
6734 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6735 * performing scsi_scan_target() during LOOP UP event.
6736 */
6737 qla2xxx_transport_functions.disable_target_scan = 1;
6738 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6739 }
6740
Linus Torvalds1da177e2005-04-16 15:20:36 -07006741 /* Derive version string. */
6742 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07006743 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07006744 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07006745 if (ql2xextended_error_logging == 1)
6746 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07006747
Andrew Vasquez1c97a122005-04-21 16:13:36 -04006748 qla2xxx_transport_template =
6749 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006750 if (!qla2xxx_transport_template) {
6751 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006752 ql_log(ql_log_fatal, NULL, 0x0002,
6753 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006754 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006756 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006757
6758 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6759 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006760 ql_log(ql_log_fatal, NULL, 0x0003,
6761 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006762 }
6763
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006764 qla2xxx_transport_vport_template =
6765 fc_attach_transport(&qla2xxx_transport_vport_functions);
6766 if (!qla2xxx_transport_vport_template) {
6767 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006768 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006769 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006770 ql_log(ql_log_fatal, NULL, 0x0004,
6771 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006772 return -ENODEV;
6773 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006774 ql_log(ql_log_info, NULL, 0x0005,
6775 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07006776 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006777 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006778 if (ret) {
6779 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006780 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07006781 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006782 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006783 ql_log(ql_log_fatal, NULL, 0x0006,
6784 "pci_register_driver failed...ret=%d Failing load!.\n",
6785 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006786 }
6787 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788}
6789
6790/**
6791 * qla2x00_module_exit - Module cleanup.
6792 **/
6793static void __exit
6794qla2x00_module_exit(void)
6795{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006796 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006797 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08006798 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006799 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006800 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07006801 if (ctx_cachep)
6802 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006803 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006804 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805}
6806
6807module_init(qla2x00_module_init);
6808module_exit(qla2x00_module_exit);
6809
6810MODULE_AUTHOR("QLogic Corporation");
6811MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6812MODULE_LICENSE("GPL");
6813MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006814MODULE_FIRMWARE(FW_FILE_ISP21XX);
6815MODULE_FIRMWARE(FW_FILE_ISP22XX);
6816MODULE_FIRMWARE(FW_FILE_ISP2300);
6817MODULE_FIRMWARE(FW_FILE_ISP2322);
6818MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08006819MODULE_FIRMWARE(FW_FILE_ISP25XX);