blob: 5d909f4ab6c2ce789ed79d018628168b27870a11 [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
Quinn Tran9ecf0b02017-12-28 12:33:19 -0800280int qla2xuseresexchforels;
281module_param(qla2xuseresexchforels, int, 0444);
282MODULE_PARM_DESC(qla2xuseresexchforels,
283 "Reserve 1/2 of emergency exchanges for ELS.\n"
284 " 0 (default): disabled");
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700287 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 */
289static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500290static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800291static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
292static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500293static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500294static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295static int qla2xxx_eh_abort(struct scsi_cmnd *);
296static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700297static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
299static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400301static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400302static void qla2x00_free_device(scsi_qla_host_t *);
Michael Hernandez56012362016-12-12 14:40:08 -0800303static int qla2xxx_map_queues(struct Scsi_Host *shost);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700304static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700305
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700306struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700308 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700309 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700310
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100311 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700312 .eh_abort_handler = qla2xxx_eh_abort,
313 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700314 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700315 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
316 .eh_host_reset_handler = qla2xxx_eh_host_reset,
317
318 .slave_configure = qla2xxx_slave_configure,
319
320 .slave_alloc = qla2xxx_slave_alloc,
321 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700322 .scan_finished = qla2xxx_scan_finished,
323 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100324 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800325 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700326 .this_id = -1,
327 .cmd_per_lun = 3,
328 .use_clustering = ENABLE_CLUSTERING,
329 .sg_tablesize = SG_ALL,
330
331 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700332 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400333
334 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100335 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700336};
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700339struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/* TODO Convert to inlines
342 *
343 * Timer routines
344 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700346__inline__ void
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700347qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700349 timer_setup(&vha->timer, qla2x00_timer, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800350 vha->timer.expires = jiffies + interval * HZ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800351 add_timer(&vha->timer);
352 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
355static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800356qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700358 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700359 if (vha->device_flags & DFLG_DEV_FAILED) {
360 ql_dbg(ql_dbg_timer, vha, 0x600d,
361 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700362 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700363 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700364
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800365 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
Adrian Bunka824ebb2008-01-17 09:02:15 -0800368static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800369qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800371 del_timer_sync(&vha->timer);
372 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375static int qla2x00_do_dpc(void *data);
376
377static void qla2x00_rst_aen(scsi_qla_host_t *);
378
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800379static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
380 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700381static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800382static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800383int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
384 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700387static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
388 struct rsp_que *rsp)
389{
390 struct qla_hw_data *ha = vha->hw;
391 rsp->qpair = ha->base_qpair;
392 rsp->req = req;
393 ha->base_qpair->req = req;
394 ha->base_qpair->rsp = rsp;
395 ha->base_qpair->vha = vha;
396 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
397 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
398 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
399 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
Duane Grigsbycf19c452017-08-23 15:04:58 -0700400 INIT_LIST_HEAD(&ha->base_qpair->nvme_done_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700401 ha->base_qpair->enable_class_2 = ql2xenableclass2;
402 /* init qpair to this cpu. Will adjust at run time. */
Bart Van Assche86531882017-11-06 11:59:05 -0800403 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700404 ha->base_qpair->pdev = ha->pdev;
405
406 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
407 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
408}
409
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400410static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
411 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800412{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700413 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700414 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800415 GFP_KERNEL);
416 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700417 ql_log(ql_log_fatal, vha, 0x003b,
418 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800419 goto fail_req_map;
420 }
421
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700422 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800423 GFP_KERNEL);
424 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700425 ql_log(ql_log_fatal, vha, 0x003c,
426 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800427 goto fail_rsp_map;
428 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800429
Quinn Trane326d222017-06-13 20:47:18 -0700430 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
431 if (ha->base_qpair == NULL) {
432 ql_log(ql_log_warn, vha, 0x00e0,
433 "Failed to allocate base queue pair memory.\n");
434 goto fail_base_qpair;
435 }
436
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700437 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700438
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -0700439 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -0800440 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
441 GFP_KERNEL);
442 if (!ha->queue_pair_map) {
443 ql_log(ql_log_fatal, vha, 0x0180,
444 "Unable to allocate memory for queue pair ptrs.\n");
445 goto fail_qpair_map;
446 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800447 }
448
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400449 /*
450 * Make sure we record at least the request and response queue zero in
451 * case we need to free them if part of the probe fails.
452 */
453 ha->rsp_q_map[0] = rsp;
454 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800455 set_bit(0, ha->rsp_qid_map);
456 set_bit(0, ha->req_qid_map);
457 return 1;
458
Michael Hernandezd7459522016-12-12 14:40:07 -0800459fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700460 kfree(ha->base_qpair);
461 ha->base_qpair = NULL;
462fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800463 kfree(ha->rsp_q_map);
464 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800465fail_rsp_map:
466 kfree(ha->req_q_map);
467 ha->req_q_map = NULL;
468fail_req_map:
469 return -ENOMEM;
470}
471
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700472static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800473{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400474 if (IS_QLAFX00(ha)) {
475 if (req && req->ring_fx00)
476 dma_free_coherent(&ha->pdev->dev,
477 (req->length_fx00 + 1) * sizeof(request_t),
478 req->ring_fx00, req->dma_fx00);
479 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800480 dma_free_coherent(&ha->pdev->dev,
481 (req->length + 1) * sizeof(request_t),
482 req->ring, req->dma);
483
Chad Dupuis8d93f552013-01-30 03:34:37 -0500484 if (req)
485 kfree(req->outstanding_cmds);
486
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800487 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800488}
489
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700490static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
491{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400492 if (IS_QLAFX00(ha)) {
493 if (rsp && rsp->ring)
494 dma_free_coherent(&ha->pdev->dev,
495 (rsp->length_fx00 + 1) * sizeof(request_t),
496 rsp->ring_fx00, rsp->dma_fx00);
497 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700498 dma_free_coherent(&ha->pdev->dev,
499 (rsp->length + 1) * sizeof(response_t),
500 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400501 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700502 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700503}
504
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800505static void qla2x00_free_queues(struct qla_hw_data *ha)
506{
507 struct req_que *req;
508 struct rsp_que *rsp;
509 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800510 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800511
Quinn Tran82de8022017-06-13 20:47:17 -0700512 if (ha->queue_pair_map) {
513 kfree(ha->queue_pair_map);
514 ha->queue_pair_map = NULL;
515 }
516 if (ha->base_qpair) {
517 kfree(ha->base_qpair);
518 ha->base_qpair = NULL;
519 }
520
Quinn Tran093df732016-12-12 14:40:09 -0800521 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700522 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500523 if (!test_bit(cnt, ha->req_qid_map))
524 continue;
525
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800526 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800527 clear_bit(cnt, ha->req_qid_map);
528 ha->req_q_map[cnt] = NULL;
529
530 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700531 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800532 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700533 }
Quinn Tran093df732016-12-12 14:40:09 -0800534 spin_unlock_irqrestore(&ha->hardware_lock, flags);
535
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700536 kfree(ha->req_q_map);
537 ha->req_q_map = NULL;
538
Quinn Tran093df732016-12-12 14:40:09 -0800539
540 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700541 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500542 if (!test_bit(cnt, ha->rsp_qid_map))
543 continue;
544
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700545 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c42392016-12-27 13:13:21 -0500546 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800547 ha->rsp_q_map[cnt] = NULL;
548 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700549 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800550 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800551 }
Quinn Tran093df732016-12-12 14:40:09 -0800552 spin_unlock_irqrestore(&ha->hardware_lock, flags);
553
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800554 kfree(ha->rsp_q_map);
555 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800556}
557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800559qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800561 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 static char *pci_bus_modes[] = {
563 "33", "66", "100", "133",
564 };
565 uint16_t pci_bus;
566
567 strcpy(str, "PCI");
568 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
569 if (pci_bus) {
570 strcat(str, "-X (");
571 strcat(str, pci_bus_modes[pci_bus]);
572 } else {
573 pci_bus = (ha->pci_attr & BIT_8) >> 8;
574 strcat(str, " (");
575 strcat(str, pci_bus_modes[pci_bus]);
576 }
577 strcat(str, " MHz)");
578
579 return (str);
580}
581
Andrew Vasquezfca29702005-07-06 10:31:47 -0700582static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700584{
585 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800586 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700587 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700588
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600589 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700590 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600591 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700592
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600593 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
594 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
595 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700596
597 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500598 switch (lspeed) {
599 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700600 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500601 break;
602 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700603 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500604 break;
605 case 3:
606 strcat(str, "8.0GT/s ");
607 break;
608 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700609 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500610 break;
611 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700612 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
613 strcat(str, lwstr);
614
615 return str;
616 }
617
618 strcpy(str, "PCI");
619 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
620 if (pci_bus == 0 || pci_bus == 8) {
621 strcat(str, " (");
622 strcat(str, pci_bus_modes[pci_bus >> 3]);
623 } else {
624 strcat(str, "-X ");
625 if (pci_bus & BIT_2)
626 strcat(str, "Mode 2");
627 else
628 strcat(str, "Mode 1");
629 strcat(str, " (");
630 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
631 }
632 strcat(str, " MHz)");
633
634 return str;
635}
636
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800637static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400638qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
640 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800641 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700642
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400643 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
644 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 if (ha->fw_attributes & BIT_9) {
647 strcat(str, "FLX");
648 return (str);
649 }
650
651 switch (ha->fw_attributes & 0xFF) {
652 case 0x7:
653 strcat(str, "EF");
654 break;
655 case 0x17:
656 strcat(str, "TP");
657 break;
658 case 0x37:
659 strcat(str, "IP");
660 break;
661 case 0x77:
662 strcat(str, "VI");
663 break;
664 default:
665 sprintf(un_str, "(%x)", ha->fw_attributes);
666 strcat(str, un_str);
667 break;
668 }
669 if (ha->fw_attributes & 0x100)
670 strcat(str, "X");
671
672 return (str);
673}
674
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800675static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400676qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700677{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700679
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400680 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800681 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700682 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700683}
684
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800685void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800686qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700687{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800688 srb_t *sp = ptr;
689 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800690 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800691 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700692
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800693 if (sp->flags & SRB_DMA_VALID) {
694 scsi_dma_unmap(cmd);
695 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700696 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700697
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800698 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
699 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
700 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
701 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
702 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700703
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700704 if (!ctx)
705 goto end;
706
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800707 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
708 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700709 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800710 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
711 }
712
713 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700714 struct crc_context *ctx0 = ctx;
715
716 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800717 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
718 }
719
720 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700721 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800722
723 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700724 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800725 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
726 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
727 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
728 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800729 }
730
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700731end:
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -0700732 if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) {
Duane Grigsby7401bc12017-06-21 13:48:42 -0700733 CMD_SP(cmd) = NULL;
734 qla2x00_rel_sp(sp);
735 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800736}
737
Michael Hernandezd7459522016-12-12 14:40:07 -0800738void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800739qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800740{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800741 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800742 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
743
744 cmd->result = res;
745
746 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800747 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800748 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
749 sp, GET_CMD_SP(sp));
750 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400751 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800752 return;
753 }
754 if (!atomic_dec_and_test(&sp->ref_count))
755 return;
756
Joe Carnucciof3caa992017-08-23 15:05:09 -0700757 sp->free(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800758 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700759}
760
Michael Hernandezd7459522016-12-12 14:40:07 -0800761void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800762qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800763{
764 srb_t *sp = (srb_t *)ptr;
765 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
766 struct qla_hw_data *ha = sp->fcport->vha->hw;
767 void *ctx = GET_CMD_CTX_SP(sp);
768
769 if (sp->flags & SRB_DMA_VALID) {
770 scsi_dma_unmap(cmd);
771 sp->flags &= ~SRB_DMA_VALID;
772 }
773
774 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
775 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
776 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
777 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
778 }
779
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700780 if (!ctx)
781 goto end;
782
Michael Hernandezd7459522016-12-12 14:40:07 -0800783 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
784 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700785 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800786 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
787 }
788
789 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700790 struct crc_context *ctx0 = ctx;
791
792 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800793 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
794 }
795
796 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700797 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800798 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
799 ctx1->fcp_cmnd_dma);
800 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
801 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
802 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
803 mempool_free(ctx1, ha->ctx_mempool);
804 }
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700805end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800806 CMD_SP(cmd) = NULL;
807 qla2xxx_rel_qpair_sp(sp->qpair, sp);
808}
809
810void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800811qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800812{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800813 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800814 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
815
816 cmd->result = res;
817
818 if (atomic_read(&sp->ref_count) == 0) {
819 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
820 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
821 sp, GET_CMD_SP(sp));
822 if (ql2xextended_error_logging & ql_dbg_io)
823 WARN_ON(atomic_read(&sp->ref_count) == 0);
824 return;
825 }
826 if (!atomic_dec_and_test(&sp->ref_count))
827 return;
828
Joe Carnucciof3caa992017-08-23 15:05:09 -0700829 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800830 cmd->scsi_done(cmd);
831}
832
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400833/* If we are SP1 here, we need to still take and release the host_lock as SP1
834 * does not have the changes necessary to avoid taking host->host_lock.
835 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800837qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700838{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700839 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700840 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400841 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800842 struct qla_hw_data *ha = vha->hw;
843 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700844 srb_t *sp;
845 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800846 struct qla_qpair *qpair = NULL;
847 uint32_t tag;
848 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700849
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200850 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
851 cmd->result = DID_NO_CONNECT << 16;
852 goto qc24_fail_command;
853 }
854
Michael Hernandez56012362016-12-12 14:40:08 -0800855 if (ha->mqenable) {
856 if (shost_use_blk_mq(vha->host)) {
857 tag = blk_mq_unique_tag(cmd->request);
858 hwq = blk_mq_unique_tag_to_hwq(tag);
859 qpair = ha->queue_pair_map[hwq];
860 } else if (vha->vp_idx && vha->qpair) {
861 qpair = vha->qpair;
862 }
863
864 if (qpair)
865 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800866 }
867
Andrew Vasquez85880802009-12-15 21:29:46 -0800868 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700869 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400870 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700871 "PCI Channel IO permanent failure, exiting "
872 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700873 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700874 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400875 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700876 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800877 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700878 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700879 goto qc24_fail_command;
880 }
881
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400882 rval = fc_remote_port_chkready(rport);
883 if (rval) {
884 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400885 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700886 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
887 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700888 goto qc24_fail_command;
889 }
890
Arun Easibad75002010-05-04 15:01:30 -0700891 if (!vha->flags.difdix_supported &&
892 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700893 ql_dbg(ql_dbg_io, vha, 0x3004,
894 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
895 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700896 cmd->result = DID_NO_CONNECT << 16;
897 goto qc24_fail_command;
898 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800899
900 if (!fcport) {
901 cmd->result = DID_NO_CONNECT << 16;
902 goto qc24_fail_command;
903 }
904
Andrew Vasquezfca29702005-07-06 10:31:47 -0700905 if (atomic_read(&fcport->state) != FCS_ONLINE) {
906 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700907 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700908 ql_dbg(ql_dbg_io, vha, 0x3005,
909 "Returning DNC, fcport_state=%d loop_state=%d.\n",
910 atomic_read(&fcport->state),
911 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700912 cmd->result = DID_NO_CONNECT << 16;
913 goto qc24_fail_command;
914 }
Mike Christie7b594132008-08-17 15:24:40 -0500915 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700916 }
917
Chad Dupuise05fe292014-09-25 05:16:59 -0400918 /*
919 * Return target busy if we've received a non-zero retry_delay_timer
920 * in a FCP_RSP.
921 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100922 if (fcport->retry_delay_timestamp == 0) {
923 /* retry delay not set */
924 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400925 fcport->retry_delay_timestamp = 0;
926 else
927 goto qc24_target_busy;
928
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500929 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400930 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800931 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700932
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800933 sp->u.scmd.cmd = cmd;
934 sp->type = SRB_SCSI_CMD;
935 atomic_set(&sp->ref_count, 1);
936 CMD_SP(cmd) = (void *)sp;
937 sp->free = qla2x00_sp_free_dma;
938 sp->done = qla2x00_sp_compl;
939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700941 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500942 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700943 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700944 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700945 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700946
Andrew Vasquezfca29702005-07-06 10:31:47 -0700947 return 0;
948
949qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700950 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700951
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800952qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700953 return SCSI_MLQUEUE_HOST_BUSY;
954
Mike Christie7b594132008-08-17 15:24:40 -0500955qc24_target_busy:
956 return SCSI_MLQUEUE_TARGET_BUSY;
957
Andrew Vasquezfca29702005-07-06 10:31:47 -0700958qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800959 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700960
961 return 0;
962}
963
Michael Hernandezd7459522016-12-12 14:40:07 -0800964/* For MQ supported I/O */
965int
966qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
967 struct qla_qpair *qpair)
968{
969 scsi_qla_host_t *vha = shost_priv(host);
970 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
971 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
972 struct qla_hw_data *ha = vha->hw;
973 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
974 srb_t *sp;
975 int rval;
976
977 rval = fc_remote_port_chkready(rport);
978 if (rval) {
979 cmd->result = rval;
980 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
981 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
982 cmd, rval);
983 goto qc24_fail_command;
984 }
985
986 if (!fcport) {
987 cmd->result = DID_NO_CONNECT << 16;
988 goto qc24_fail_command;
989 }
990
991 if (atomic_read(&fcport->state) != FCS_ONLINE) {
992 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
993 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
994 ql_dbg(ql_dbg_io, vha, 0x3077,
995 "Returning DNC, fcport_state=%d loop_state=%d.\n",
996 atomic_read(&fcport->state),
997 atomic_read(&base_vha->loop_state));
998 cmd->result = DID_NO_CONNECT << 16;
999 goto qc24_fail_command;
1000 }
1001 goto qc24_target_busy;
1002 }
1003
1004 /*
1005 * Return target busy if we've received a non-zero retry_delay_timer
1006 * in a FCP_RSP.
1007 */
1008 if (fcport->retry_delay_timestamp == 0) {
1009 /* retry delay not set */
1010 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1011 fcport->retry_delay_timestamp = 0;
1012 else
1013 goto qc24_target_busy;
1014
1015 sp = qla2xxx_get_qpair_sp(qpair, fcport, GFP_ATOMIC);
1016 if (!sp)
1017 goto qc24_host_busy;
1018
1019 sp->u.scmd.cmd = cmd;
1020 sp->type = SRB_SCSI_CMD;
1021 atomic_set(&sp->ref_count, 1);
1022 CMD_SP(cmd) = (void *)sp;
1023 sp->free = qla2xxx_qpair_sp_free_dma;
1024 sp->done = qla2xxx_qpair_sp_compl;
1025 sp->qpair = qpair;
1026
1027 rval = ha->isp_ops->start_scsi_mq(sp);
1028 if (rval != QLA_SUCCESS) {
1029 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1030 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1031 if (rval == QLA_INTERFACE_ERROR)
1032 goto qc24_fail_command;
1033 goto qc24_host_busy_free_sp;
1034 }
1035
1036 return 0;
1037
1038qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001039 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001040
1041qc24_host_busy:
1042 return SCSI_MLQUEUE_HOST_BUSY;
1043
1044qc24_target_busy:
1045 return SCSI_MLQUEUE_TARGET_BUSY;
1046
1047qc24_fail_command:
1048 cmd->scsi_done(cmd);
1049
1050 return 0;
1051}
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053/*
1054 * qla2x00_eh_wait_on_command
1055 * Waits for the command to be returned by the Firmware for some
1056 * max time.
1057 *
1058 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 *
1061 * Return:
1062 * Not Found : 0
1063 * Found : 1
1064 */
1065static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001066qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001068#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001069#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001070 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001071 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1072 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001073 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Andrew Vasquez85880802009-12-15 21:29:46 -08001075 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001076 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1077 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001078 return ret;
1079 }
1080
Lalit Chandivaded9704322009-08-25 11:36:18 -07001081 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001082 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001083 }
1084 if (CMD_SP(cmd))
1085 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
f4f051e2005-04-17 15:02:26 -05001087 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
1090/*
1091 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001092 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 * <= MAX_RETRIES_OF_ISP_ABORT or
1094 * finally HBA is disabled ie marked offline
1095 *
1096 * Input:
1097 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001098 *
1099 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 * Does context switching-Release SPIN_LOCK
1101 * (if any) before calling this routine.
1102 *
1103 * Return:
1104 * Success (Adapter is online) : 0
1105 * Failed (Adapter is offline/disabled) : 1
1106 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001107int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001108qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001110 int return_status;
1111 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001112 struct qla_hw_data *ha = vha->hw;
1113 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001115 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001116 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1117 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1118 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1119 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 msleep(1000);
1122 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001123 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001124 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 else
1126 return_status = QLA_FUNCTION_FAILED;
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 return (return_status);
1129}
1130
Quinn Tran726b8542017-01-19 22:28:00 -08001131static inline int test_fcport_count(scsi_qla_host_t *vha)
1132{
1133 struct qla_hw_data *ha = vha->hw;
1134 unsigned long flags;
1135 int res;
1136
1137 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001138 ql_dbg(ql_dbg_init, vha, 0x00ec,
1139 "tgt %p, fcport_count=%d\n",
1140 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001141 res = (vha->fcport_count == 0);
1142 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1143
1144 return res;
1145}
1146
1147/*
1148 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1149 * it has dependency on UNLOADING flag to stop device discovery
1150 */
1151static void
1152qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1153{
1154 qla2x00_mark_all_devices_lost(vha, 0);
1155
Joe Carnucciob85e0952017-08-23 15:05:11 -07001156 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001157}
1158
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001159/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001160 * qla2x00_wait_for_hba_ready
1161 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001162 *
1163 * Input:
1164 * ha - pointer to host adapter structure
1165 *
1166 * Note:
1167 * Does context switching-Release SPIN_LOCK
1168 * (if any) before calling this routine.
1169 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001170 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001171static void
1172qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001173{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001174 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001175 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001176
Dan Carpenter1d483902016-08-03 21:42:32 +03001177 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1178 ha->flags.mbox_busy) ||
1179 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1180 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1181 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1182 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001183 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001184 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001185}
1186
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001187int
1188qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1189{
1190 int return_status;
1191 unsigned long wait_reset;
1192 struct qla_hw_data *ha = vha->hw;
1193 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1194
1195 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1196 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1197 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1198 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1199 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1200
1201 msleep(1000);
1202
1203 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1204 ha->flags.chip_reset_done)
1205 break;
1206 }
1207 if (ha->flags.chip_reset_done)
1208 return_status = QLA_SUCCESS;
1209 else
1210 return_status = QLA_FUNCTION_FAILED;
1211
1212 return return_status;
1213}
1214
Giridhar Malavali083a4692010-05-28 15:08:18 -07001215static void
1216sp_get(struct srb *sp)
1217{
1218 atomic_inc(&sp->ref_count);
1219}
1220
Sawan Chandaka4655372016-07-06 11:14:32 -04001221#define ISP_REG_DISCONNECT 0xffffffffU
1222/**************************************************************************
1223* qla2x00_isp_reg_stat
1224*
1225* Description:
1226* Read the host status register of ISP before aborting the command.
1227*
1228* Input:
1229* ha = pointer to host adapter structure.
1230*
1231*
1232* Returns:
1233* Either true or false.
1234*
1235* Note: Return true if there is register disconnect.
1236**************************************************************************/
1237static inline
1238uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1239{
1240 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001241 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001242
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001243 if (IS_P3P_TYPE(ha))
1244 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1245 else
1246 return ((RD_REG_DWORD(&reg->host_status)) ==
1247 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001248}
1249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250/**************************************************************************
1251* qla2xxx_eh_abort
1252*
1253* Description:
1254* The abort function will abort the specified command.
1255*
1256* Input:
1257* cmd = Linux SCSI command packet to be aborted.
1258*
1259* Returns:
1260* Either SUCCESS or FAILED.
1261*
1262* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001263* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001265static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1267{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001268 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001269 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001270 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001271 unsigned int id;
1272 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001273 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001274 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001275 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Sawan Chandaka4655372016-07-06 11:14:32 -04001277 if (qla2x00_isp_reg_stat(ha)) {
1278 ql_log(ql_log_info, vha, 0x8042,
1279 "PCI/Register disconnect, exiting.\n");
1280 return FAILED;
1281 }
f4f051e2005-04-17 15:02:26 -05001282 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -07001283 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001285 ret = fc_block_scsi_eh(cmd);
1286 if (ret != 0)
1287 return ret;
1288 ret = SUCCESS;
1289
f4f051e2005-04-17 15:02:26 -05001290 id = cmd->device->id;
1291 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001292
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001293 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001294 sp = (srb_t *) CMD_SP(cmd);
1295 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001296 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001297 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001298 }
Mike Christie170babc2010-10-15 11:27:47 -07001299
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001300 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001301 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1302 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001303
1304 /* Get a reference to the sp and drop the lock.*/
1305 sp_get(sp);
1306
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001307 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001308 rval = ha->isp_ops->abort_command(sp);
1309 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001310 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001311 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001312 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001313 ret = FAILED;
1314
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001315 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001316 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001317 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001318 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001319 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001320 wait = 1;
1321 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001322
1323 spin_lock_irqsave(&ha->hardware_lock, flags);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001324 sp->done(sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -07001325 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -05001326
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001327 /* Did the command return during mailbox execution? */
1328 if (ret == FAILED && !CMD_SP(cmd))
1329 ret = SUCCESS;
1330
f4f051e2005-04-17 15:02:26 -05001331 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001332 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001333 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001334 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001335 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001336 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001340 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001341 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001342 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
f4f051e2005-04-17 15:02:26 -05001344 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001347int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001349 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001351 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001352 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001353 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001354 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001355 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001356 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Andrew Vasquez523ec772008-04-03 13:13:24 -07001358 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001359
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001360 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001361 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001362 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001363 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001364 sp = req->outstanding_cmds[cnt];
1365 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001366 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001367 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001368 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001369 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001370 continue;
1371 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001372 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001373 switch (type) {
1374 case WAIT_HOST:
1375 match = 1;
1376 break;
1377 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001378 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001379 break;
1380 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001381 match = (cmd->device->id == t &&
1382 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001383 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001385 if (!match)
1386 continue;
1387
1388 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001389 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001390 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001392 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001393
1394 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395}
1396
Andrew Vasquez523ec772008-04-03 13:13:24 -07001397static char *reset_errors[] = {
1398 "HBA not online",
1399 "HBA not ready",
1400 "Task management failed",
1401 "Waiting for command completions",
1402};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Andrew Vasquez523ec772008-04-03 13:13:24 -07001404static int
1405__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001406 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001407{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001408 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001409 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1410 int err;
1411
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001412 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001413 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001414 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001415
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001416 err = fc_block_scsi_eh(cmd);
1417 if (err != 0)
1418 return err;
1419
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001420 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001421 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001422 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001423
1424 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001425 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1426 ql_log(ql_log_warn, vha, 0x800a,
1427 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001428 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001429 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001430 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001431 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001432 != QLA_SUCCESS) {
1433 ql_log(ql_log_warn, vha, 0x800c,
1434 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001435 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001436 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001437 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001438 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001439 cmd->device->lun, type) != QLA_SUCCESS) {
1440 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001441 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001442 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001443 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001444
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001445 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001446 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001447 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001448
1449 return SUCCESS;
1450
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001451eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001452 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001453 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001454 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1455 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001456 return FAILED;
1457}
1458
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001459static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1461{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001462 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1463 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Sawan Chandaka4655372016-07-06 11:14:32 -04001465 if (qla2x00_isp_reg_stat(ha)) {
1466 ql_log(ql_log_info, vha, 0x803e,
1467 "PCI/Register disconnect, exiting.\n");
1468 return FAILED;
1469 }
1470
Andrew Vasquez523ec772008-04-03 13:13:24 -07001471 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1472 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001476qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1479 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Sawan Chandaka4655372016-07-06 11:14:32 -04001481 if (qla2x00_isp_reg_stat(ha)) {
1482 ql_log(ql_log_info, vha, 0x803f,
1483 "PCI/Register disconnect, exiting.\n");
1484 return FAILED;
1485 }
1486
Andrew Vasquez523ec772008-04-03 13:13:24 -07001487 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1488 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491/**************************************************************************
1492* qla2xxx_eh_bus_reset
1493*
1494* Description:
1495* The bus reset function will reset the bus and abort any executing
1496* commands.
1497*
1498* Input:
1499* cmd = Linux SCSI command packet of the command that cause the
1500* bus reset.
1501*
1502* Returns:
1503* SUCCESS/FAILURE (defined as macro in scsi.h).
1504*
1505**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001506static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1508{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001509 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001510 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001511 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001512 unsigned int id;
1513 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001514 struct qla_hw_data *ha = vha->hw;
1515
1516 if (qla2x00_isp_reg_stat(ha)) {
1517 ql_log(ql_log_info, vha, 0x8040,
1518 "PCI/Register disconnect, exiting.\n");
1519 return FAILED;
1520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
f4f051e2005-04-17 15:02:26 -05001522 id = cmd->device->id;
1523 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001524
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001525 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001526 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001529 ret = fc_block_scsi_eh(cmd);
1530 if (ret != 0)
1531 return ret;
1532 ret = FAILED;
1533
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001534 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001535 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001537 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001538 ql_log(ql_log_fatal, vha, 0x8013,
1539 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001540 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 }
1542
Saurav Kashyapad5376892011-11-18 09:02:09 -08001543 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1544 ret = SUCCESS;
1545
f4f051e2005-04-17 15:02:26 -05001546 if (ret == FAILED)
1547 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001549 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001550 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001551 QLA_SUCCESS) {
1552 ql_log(ql_log_warn, vha, 0x8014,
1553 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001554 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
f4f051e2005-04-17 15:02:26 -05001557eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001558 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001559 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001560 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
f4f051e2005-04-17 15:02:26 -05001562 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
1565/**************************************************************************
1566* qla2xxx_eh_host_reset
1567*
1568* Description:
1569* The reset function will reset the Adapter.
1570*
1571* Input:
1572* cmd = Linux SCSI command packet of the command that cause the
1573* adapter reset.
1574*
1575* Returns:
1576* Either SUCCESS or FAILED.
1577*
1578* Note:
1579**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001580static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1582{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001583 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001584 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001585 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001586 unsigned int id;
1587 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001588 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Sawan Chandaka4655372016-07-06 11:14:32 -04001590 if (qla2x00_isp_reg_stat(ha)) {
1591 ql_log(ql_log_info, vha, 0x8041,
1592 "PCI/Register disconnect, exiting.\n");
1593 schedule_work(&ha->board_disable);
1594 return SUCCESS;
1595 }
1596
f4f051e2005-04-17 15:02:26 -05001597 id = cmd->device->id;
1598 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001599
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001600 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001601 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
Chad Dupuis63ee7072014-04-11 16:54:46 -04001603 /*
1604 * No point in issuing another reset if one is active. Also do not
1605 * attempt a reset if we are updating flash.
1606 */
1607 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001608 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001610 if (vha != base_vha) {
1611 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001612 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001614 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001615 if (!qla82xx_fcoe_ctx_reset(vha)) {
1616 /* Ctx reset success */
1617 ret = SUCCESS;
1618 goto eh_host_reset_lock;
1619 }
1620 /* fall thru if ctx reset failed */
1621 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001622 if (ha->wq)
1623 flush_workqueue(ha->wq);
1624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001625 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001626 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001627 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1628 /* failed. schedule dpc to try */
1629 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1630
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001631 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1632 ql_log(ql_log_warn, vha, 0x802a,
1633 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001634 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001635 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001636 }
1637 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001640 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001641 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001642 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001643 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
f4f051e2005-04-17 15:02:26 -05001645eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001646 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001647 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001648 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
f4f051e2005-04-17 15:02:26 -05001650 return ret;
1651}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
1653/*
1654* qla2x00_loop_reset
1655* Issue loop reset.
1656*
1657* Input:
1658* ha = adapter block pointer.
1659*
1660* Returns:
1661* 0 = success
1662*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001663int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001664qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001666 int ret;
bdf79622005-04-17 15:06:53 -05001667 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001668 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Armen Baloyan58547712013-08-27 01:37:33 -04001670 if (IS_QLAFX00(ha)) {
1671 return qlafx00_loop_reset(vha);
1672 }
1673
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001674 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001675 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1676 if (fcport->port_type != FCT_TARGET)
1677 continue;
1678
1679 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1680 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001681 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001682 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001683 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001684 }
1685 }
1686 }
1687
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001688
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001689 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001690 atomic_set(&vha->loop_state, LOOP_DOWN);
1691 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1692 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001693 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001694 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001695 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1696 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 }
1699
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001700 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001701 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001702 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001703 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1704 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001705 }
1706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001708 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001710 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711}
1712
Quinn Tranbbead492017-12-28 12:33:13 -08001713static void
1714__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001715{
Quinn Tranbbead492017-12-28 12:33:13 -08001716 int cnt, status;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001717 unsigned long flags;
1718 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001719 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001720 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001721 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001722 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1723 struct qla_tgt_cmd *cmd;
1724 uint8_t trace = 0;
Arun Easic0cb4492014-09-25 06:14:51 -04001725
Quinn Tranbbead492017-12-28 12:33:13 -08001726 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1727 req = qp->req;
1728 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1729 sp = req->outstanding_cmds[cnt];
1730 if (sp) {
1731 req->outstanding_cmds[cnt] = NULL;
1732 if (sp->cmd_type == TYPE_SRB) {
1733 if (sp->type == SRB_NVME_CMD ||
1734 sp->type == SRB_NVME_LS) {
1735 sp_get(sp);
1736 spin_unlock_irqrestore(qp->qp_lock_ptr,
1737 flags);
1738 qla_nvme_abort(ha, sp);
1739 spin_lock_irqsave(qp->qp_lock_ptr,
1740 flags);
1741 } else if (GET_CMD_SP(sp) &&
1742 !ha->flags.eeh_busy &&
1743 (!test_bit(ABORT_ISP_ACTIVE,
1744 &vha->dpc_flags)) &&
1745 (sp->type == SRB_SCSI_CMD)) {
1746 /*
1747 * Don't abort commands in
1748 * adapter during EEH
1749 * recovery as it's not
1750 * accessible/responding.
1751 *
1752 * Get a reference to the sp
1753 * and drop the lock. The
1754 * reference ensures this
1755 * sp->done() call and not the
1756 * call in qla2xxx_eh_abort()
1757 * ends the SCSI command (with
1758 * result 'res').
1759 */
1760 sp_get(sp);
1761 spin_unlock_irqrestore(qp->qp_lock_ptr,
1762 flags);
1763 status = qla2xxx_eh_abort(
1764 GET_CMD_SP(sp));
1765 spin_lock_irqsave(qp->qp_lock_ptr,
1766 flags);
1767 /*
1768 * Get rid of extra reference
1769 * if immediate exit from
1770 * ql2xxx_eh_abort
1771 */
1772 if (status == FAILED &&
1773 (qla2x00_isp_reg_stat(ha)))
1774 atomic_dec(
1775 &sp->ref_count);
Quinn Tranc5419e22017-06-13 20:47:16 -07001776 }
Quinn Tranbbead492017-12-28 12:33:13 -08001777 sp->done(sp, res);
1778 } else {
1779 if (!vha->hw->tgt.tgt_ops || !tgt ||
1780 qla_ini_mode_enabled(vha)) {
1781 if (!trace)
1782 ql_dbg(ql_dbg_tgt_mgt,
1783 vha, 0xf003,
1784 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1785 vha->dpc_flags);
1786 continue;
1787 }
1788 cmd = (struct qla_tgt_cmd *)sp;
1789 qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001790 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001791 }
1792 }
Quinn Tranbbead492017-12-28 12:33:13 -08001793 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1794}
1795
1796void
1797qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1798{
1799 int que;
1800 struct qla_hw_data *ha = vha->hw;
1801
1802 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1803
1804 for (que = 0; que < ha->max_qpairs; que++) {
1805 if (!ha->queue_pair_map[que])
1806 continue;
1807
1808 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1809 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001810}
1811
f4f051e2005-04-17 15:02:26 -05001812static int
1813qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
bdf79622005-04-17 15:06:53 -05001815 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001817 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001818 return -ENXIO;
1819
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001820 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001821
1822 return 0;
1823}
1824
1825static int
1826qla2xxx_slave_configure(struct scsi_device *sdev)
1827{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001828 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001829 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001830
Arun Easi9e522cd2012-08-22 14:21:31 -04001831 if (IS_T10_PI_CAPABLE(vha->hw))
1832 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1833
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001834 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001835 return 0;
1836}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
f4f051e2005-04-17 15:02:26 -05001838static void
1839qla2xxx_slave_destroy(struct scsi_device *sdev)
1840{
1841 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842}
1843
1844/**
1845 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1846 * @ha: HA context
1847 *
1848 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1849 * supported addressing method.
1850 */
1851static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001852qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001854 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Yang Hongyang6a355282009-04-06 19:01:13 -07001857 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001858 /* Any upper-dword bits set? */
1859 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001860 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001861 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001863 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1864 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001865 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001868
Yang Hongyang284901a2009-04-06 19:01:15 -07001869 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1870 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001873static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874qla2x00_enable_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 = 1;
1881 /* enable risc and host interrupts */
1882 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1883 RD_REG_WORD(&reg->ictrl);
1884 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1885
1886}
1887
1888static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001889qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001890{
1891 unsigned long flags = 0;
1892 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1893
1894 spin_lock_irqsave(&ha->hardware_lock, flags);
1895 ha->interrupts_on = 0;
1896 /* disable risc and host interrupts */
1897 WRT_REG_WORD(&reg->ictrl, 0);
1898 RD_REG_WORD(&reg->ictrl);
1899 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1900}
1901
1902static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001904{
1905 unsigned long flags = 0;
1906 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1907
1908 spin_lock_irqsave(&ha->hardware_lock, flags);
1909 ha->interrupts_on = 1;
1910 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1911 RD_REG_DWORD(&reg->ictrl);
1912 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1913}
1914
1915static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001917{
1918 unsigned long flags = 0;
1919 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1920
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001921 if (IS_NOPOLLING_TYPE(ha))
1922 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001923 spin_lock_irqsave(&ha->hardware_lock, flags);
1924 ha->interrupts_on = 0;
1925 WRT_REG_DWORD(&reg->ictrl, 0);
1926 RD_REG_DWORD(&reg->ictrl);
1927 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1928}
1929
Giridhar Malavali706f4572011-11-18 09:03:16 -08001930static int
1931qla2x00_iospace_config(struct qla_hw_data *ha)
1932{
1933 resource_size_t pio;
1934 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001935
Giridhar Malavali706f4572011-11-18 09:03:16 -08001936 if (pci_request_selected_regions(ha->pdev, ha->bars,
1937 QLA2XXX_DRIVER_NAME)) {
1938 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1939 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1940 pci_name(ha->pdev));
1941 goto iospace_error_exit;
1942 }
1943 if (!(ha->bars & 1))
1944 goto skip_pio;
1945
1946 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1947 pio = pci_resource_start(ha->pdev, 0);
1948 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1949 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1950 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1951 "Invalid pci I/O region size (%s).\n",
1952 pci_name(ha->pdev));
1953 pio = 0;
1954 }
1955 } else {
1956 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1957 "Region #0 no a PIO resource (%s).\n",
1958 pci_name(ha->pdev));
1959 pio = 0;
1960 }
1961 ha->pio_address = pio;
1962 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1963 "PIO address=%llu.\n",
1964 (unsigned long long)ha->pio_address);
1965
1966skip_pio:
1967 /* Use MMIO operations for all accesses. */
1968 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1969 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1970 "Region #1 not an MMIO resource (%s), aborting.\n",
1971 pci_name(ha->pdev));
1972 goto iospace_error_exit;
1973 }
1974 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1975 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1976 "Invalid PCI mem region size (%s), aborting.\n",
1977 pci_name(ha->pdev));
1978 goto iospace_error_exit;
1979 }
1980
1981 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1982 if (!ha->iobase) {
1983 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1984 "Cannot remap MMIO (%s), aborting.\n",
1985 pci_name(ha->pdev));
1986 goto iospace_error_exit;
1987 }
1988
1989 /* Determine queue resources */
1990 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08001991 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07001992 if (!ql2xmqsupport || !ql2xnvmeenable ||
1993 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08001994 goto mqiobase_exit;
1995
1996 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1997 pci_resource_len(ha->pdev, 3));
1998 if (ha->mqiobase) {
1999 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2000 "MQIO Base=%p.\n", ha->mqiobase);
2001 /* Read MSIX vector size of the board */
2002 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002003 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002004 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002005 /* MB interrupt uses 1 vector */
2006 ha->max_req_queues = ha->msix_count - 1;
2007 ha->max_rsp_queues = ha->max_req_queues;
2008 /* Queue pairs is the max value minus the base queue pair */
2009 ha->max_qpairs = ha->max_rsp_queues - 1;
2010 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2011 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2012
Giridhar Malavali706f4572011-11-18 09:03:16 -08002013 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002014 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002015 } else
2016 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2017 "BAR 3 not enabled.\n");
2018
2019mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002020 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002021 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002022 return (0);
2023
2024iospace_error_exit:
2025 return (-ENOMEM);
2026}
2027
2028
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002029static int
2030qla83xx_iospace_config(struct qla_hw_data *ha)
2031{
2032 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002033
2034 if (pci_request_selected_regions(ha->pdev, ha->bars,
2035 QLA2XXX_DRIVER_NAME)) {
2036 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2037 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2038 pci_name(ha->pdev));
2039
2040 goto iospace_error_exit;
2041 }
2042
2043 /* Use MMIO operations for all accesses. */
2044 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2045 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2046 "Invalid pci I/O region size (%s).\n",
2047 pci_name(ha->pdev));
2048 goto iospace_error_exit;
2049 }
2050 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2051 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2052 "Invalid PCI mem region size (%s), aborting\n",
2053 pci_name(ha->pdev));
2054 goto iospace_error_exit;
2055 }
2056
2057 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2058 if (!ha->iobase) {
2059 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2060 "Cannot remap MMIO (%s), aborting.\n",
2061 pci_name(ha->pdev));
2062 goto iospace_error_exit;
2063 }
2064
2065 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2066 /* 83XX 26XX always use MQ type access for queues
2067 * - mbar 2, a.k.a region 4 */
2068 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002069 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002070 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2071 pci_resource_len(ha->pdev, 4));
2072
2073 if (!ha->mqiobase) {
2074 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2075 "BAR2/region4 not enabled\n");
2076 goto mqiobase_exit;
2077 }
2078
2079 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2080 pci_resource_len(ha->pdev, 2));
2081 if (ha->msixbase) {
2082 /* Read MSIX vector size of the board */
2083 pci_read_config_word(ha->pdev,
2084 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002085 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002086 /*
2087 * By default, driver uses at least two msix vectors
2088 * (default & rspq)
2089 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002090 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002091 /* MB interrupt uses 1 vector */
2092 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002093
2094 /* ATIOQ needs 1 vector. That's 1 less QPair */
2095 if (QLA_TGT_MODE_ENABLED())
2096 ha->max_req_queues--;
2097
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002098 ha->max_rsp_queues = ha->max_req_queues;
2099
Michael Hernandezd7459522016-12-12 14:40:07 -08002100 /* Queue pairs is the max value minus
2101 * the base queue pair */
2102 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002103 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002104 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002105 }
2106 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002107 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002108 } else
2109 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2110 "BAR 1 not enabled.\n");
2111
2112mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002113 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002114 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002115 return 0;
2116
2117iospace_error_exit:
2118 return -ENOMEM;
2119}
2120
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002121static struct isp_operations qla2100_isp_ops = {
2122 .pci_config = qla2100_pci_config,
2123 .reset_chip = qla2x00_reset_chip,
2124 .chip_diag = qla2x00_chip_diag,
2125 .config_rings = qla2x00_config_rings,
2126 .reset_adapter = qla2x00_reset_adapter,
2127 .nvram_config = qla2x00_nvram_config,
2128 .update_fw_options = qla2x00_update_fw_options,
2129 .load_risc = qla2x00_load_risc,
2130 .pci_info_str = qla2x00_pci_info_str,
2131 .fw_version_str = qla2x00_fw_version_str,
2132 .intr_handler = qla2100_intr_handler,
2133 .enable_intrs = qla2x00_enable_intrs,
2134 .disable_intrs = qla2x00_disable_intrs,
2135 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002136 .target_reset = qla2x00_abort_target,
2137 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002138 .fabric_login = qla2x00_login_fabric,
2139 .fabric_logout = qla2x00_fabric_logout,
2140 .calc_req_entries = qla2x00_calc_iocbs_32,
2141 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2142 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2143 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2144 .read_nvram = qla2x00_read_nvram_data,
2145 .write_nvram = qla2x00_write_nvram_data,
2146 .fw_dump = qla2100_fw_dump,
2147 .beacon_on = NULL,
2148 .beacon_off = NULL,
2149 .beacon_blink = NULL,
2150 .read_optrom = qla2x00_read_optrom_data,
2151 .write_optrom = qla2x00_write_optrom_data,
2152 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002153 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002154 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002155 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002156 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002157 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002158};
2159
2160static struct isp_operations qla2300_isp_ops = {
2161 .pci_config = qla2300_pci_config,
2162 .reset_chip = qla2x00_reset_chip,
2163 .chip_diag = qla2x00_chip_diag,
2164 .config_rings = qla2x00_config_rings,
2165 .reset_adapter = qla2x00_reset_adapter,
2166 .nvram_config = qla2x00_nvram_config,
2167 .update_fw_options = qla2x00_update_fw_options,
2168 .load_risc = qla2x00_load_risc,
2169 .pci_info_str = qla2x00_pci_info_str,
2170 .fw_version_str = qla2x00_fw_version_str,
2171 .intr_handler = qla2300_intr_handler,
2172 .enable_intrs = qla2x00_enable_intrs,
2173 .disable_intrs = qla2x00_disable_intrs,
2174 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002175 .target_reset = qla2x00_abort_target,
2176 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002177 .fabric_login = qla2x00_login_fabric,
2178 .fabric_logout = qla2x00_fabric_logout,
2179 .calc_req_entries = qla2x00_calc_iocbs_32,
2180 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2181 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2182 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2183 .read_nvram = qla2x00_read_nvram_data,
2184 .write_nvram = qla2x00_write_nvram_data,
2185 .fw_dump = qla2300_fw_dump,
2186 .beacon_on = qla2x00_beacon_on,
2187 .beacon_off = qla2x00_beacon_off,
2188 .beacon_blink = qla2x00_beacon_blink,
2189 .read_optrom = qla2x00_read_optrom_data,
2190 .write_optrom = qla2x00_write_optrom_data,
2191 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002192 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002193 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002194 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002195 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002196 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002197};
2198
2199static struct isp_operations qla24xx_isp_ops = {
2200 .pci_config = qla24xx_pci_config,
2201 .reset_chip = qla24xx_reset_chip,
2202 .chip_diag = qla24xx_chip_diag,
2203 .config_rings = qla24xx_config_rings,
2204 .reset_adapter = qla24xx_reset_adapter,
2205 .nvram_config = qla24xx_nvram_config,
2206 .update_fw_options = qla24xx_update_fw_options,
2207 .load_risc = qla24xx_load_risc,
2208 .pci_info_str = qla24xx_pci_info_str,
2209 .fw_version_str = qla24xx_fw_version_str,
2210 .intr_handler = qla24xx_intr_handler,
2211 .enable_intrs = qla24xx_enable_intrs,
2212 .disable_intrs = qla24xx_disable_intrs,
2213 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002214 .target_reset = qla24xx_abort_target,
2215 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002216 .fabric_login = qla24xx_login_fabric,
2217 .fabric_logout = qla24xx_fabric_logout,
2218 .calc_req_entries = NULL,
2219 .build_iocbs = NULL,
2220 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2221 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2222 .read_nvram = qla24xx_read_nvram_data,
2223 .write_nvram = qla24xx_write_nvram_data,
2224 .fw_dump = qla24xx_fw_dump,
2225 .beacon_on = qla24xx_beacon_on,
2226 .beacon_off = qla24xx_beacon_off,
2227 .beacon_blink = qla24xx_beacon_blink,
2228 .read_optrom = qla24xx_read_optrom_data,
2229 .write_optrom = qla24xx_write_optrom_data,
2230 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002231 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002232 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002233 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002234 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002235 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002236};
2237
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002238static struct isp_operations qla25xx_isp_ops = {
2239 .pci_config = qla25xx_pci_config,
2240 .reset_chip = qla24xx_reset_chip,
2241 .chip_diag = qla24xx_chip_diag,
2242 .config_rings = qla24xx_config_rings,
2243 .reset_adapter = qla24xx_reset_adapter,
2244 .nvram_config = qla24xx_nvram_config,
2245 .update_fw_options = qla24xx_update_fw_options,
2246 .load_risc = qla24xx_load_risc,
2247 .pci_info_str = qla24xx_pci_info_str,
2248 .fw_version_str = qla24xx_fw_version_str,
2249 .intr_handler = qla24xx_intr_handler,
2250 .enable_intrs = qla24xx_enable_intrs,
2251 .disable_intrs = qla24xx_disable_intrs,
2252 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002253 .target_reset = qla24xx_abort_target,
2254 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002255 .fabric_login = qla24xx_login_fabric,
2256 .fabric_logout = qla24xx_fabric_logout,
2257 .calc_req_entries = NULL,
2258 .build_iocbs = NULL,
2259 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2260 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2261 .read_nvram = qla25xx_read_nvram_data,
2262 .write_nvram = qla25xx_write_nvram_data,
2263 .fw_dump = qla25xx_fw_dump,
2264 .beacon_on = qla24xx_beacon_on,
2265 .beacon_off = qla24xx_beacon_off,
2266 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002267 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002268 .write_optrom = qla24xx_write_optrom_data,
2269 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002270 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002271 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002272 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002273 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002274 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002275};
2276
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002277static struct isp_operations qla81xx_isp_ops = {
2278 .pci_config = qla25xx_pci_config,
2279 .reset_chip = qla24xx_reset_chip,
2280 .chip_diag = qla24xx_chip_diag,
2281 .config_rings = qla24xx_config_rings,
2282 .reset_adapter = qla24xx_reset_adapter,
2283 .nvram_config = qla81xx_nvram_config,
2284 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002285 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002286 .pci_info_str = qla24xx_pci_info_str,
2287 .fw_version_str = qla24xx_fw_version_str,
2288 .intr_handler = qla24xx_intr_handler,
2289 .enable_intrs = qla24xx_enable_intrs,
2290 .disable_intrs = qla24xx_disable_intrs,
2291 .abort_command = qla24xx_abort_command,
2292 .target_reset = qla24xx_abort_target,
2293 .lun_reset = qla24xx_lun_reset,
2294 .fabric_login = qla24xx_login_fabric,
2295 .fabric_logout = qla24xx_fabric_logout,
2296 .calc_req_entries = NULL,
2297 .build_iocbs = NULL,
2298 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2299 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002300 .read_nvram = NULL,
2301 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002302 .fw_dump = qla81xx_fw_dump,
2303 .beacon_on = qla24xx_beacon_on,
2304 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002305 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002306 .read_optrom = qla25xx_read_optrom_data,
2307 .write_optrom = qla24xx_write_optrom_data,
2308 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002309 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002310 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002311 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002312 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002313 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002314};
2315
2316static struct isp_operations qla82xx_isp_ops = {
2317 .pci_config = qla82xx_pci_config,
2318 .reset_chip = qla82xx_reset_chip,
2319 .chip_diag = qla24xx_chip_diag,
2320 .config_rings = qla82xx_config_rings,
2321 .reset_adapter = qla24xx_reset_adapter,
2322 .nvram_config = qla81xx_nvram_config,
2323 .update_fw_options = qla24xx_update_fw_options,
2324 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002325 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002326 .fw_version_str = qla24xx_fw_version_str,
2327 .intr_handler = qla82xx_intr_handler,
2328 .enable_intrs = qla82xx_enable_intrs,
2329 .disable_intrs = qla82xx_disable_intrs,
2330 .abort_command = qla24xx_abort_command,
2331 .target_reset = qla24xx_abort_target,
2332 .lun_reset = qla24xx_lun_reset,
2333 .fabric_login = qla24xx_login_fabric,
2334 .fabric_logout = qla24xx_fabric_logout,
2335 .calc_req_entries = NULL,
2336 .build_iocbs = NULL,
2337 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2338 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2339 .read_nvram = qla24xx_read_nvram_data,
2340 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002341 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002342 .beacon_on = qla82xx_beacon_on,
2343 .beacon_off = qla82xx_beacon_off,
2344 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002345 .read_optrom = qla82xx_read_optrom_data,
2346 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002347 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002348 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002349 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002350 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002351 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002352 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002353};
2354
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002355static struct isp_operations qla8044_isp_ops = {
2356 .pci_config = qla82xx_pci_config,
2357 .reset_chip = qla82xx_reset_chip,
2358 .chip_diag = qla24xx_chip_diag,
2359 .config_rings = qla82xx_config_rings,
2360 .reset_adapter = qla24xx_reset_adapter,
2361 .nvram_config = qla81xx_nvram_config,
2362 .update_fw_options = qla24xx_update_fw_options,
2363 .load_risc = qla82xx_load_risc,
2364 .pci_info_str = qla24xx_pci_info_str,
2365 .fw_version_str = qla24xx_fw_version_str,
2366 .intr_handler = qla8044_intr_handler,
2367 .enable_intrs = qla82xx_enable_intrs,
2368 .disable_intrs = qla82xx_disable_intrs,
2369 .abort_command = qla24xx_abort_command,
2370 .target_reset = qla24xx_abort_target,
2371 .lun_reset = qla24xx_lun_reset,
2372 .fabric_login = qla24xx_login_fabric,
2373 .fabric_logout = qla24xx_fabric_logout,
2374 .calc_req_entries = NULL,
2375 .build_iocbs = NULL,
2376 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2377 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2378 .read_nvram = NULL,
2379 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002380 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002381 .beacon_on = qla82xx_beacon_on,
2382 .beacon_off = qla82xx_beacon_off,
2383 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002384 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002385 .write_optrom = qla8044_write_optrom_data,
2386 .get_flash_version = qla82xx_get_flash_version,
2387 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002388 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002389 .abort_isp = qla8044_abort_isp,
2390 .iospace_config = qla82xx_iospace_config,
2391 .initialize_adapter = qla2x00_initialize_adapter,
2392};
2393
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002394static struct isp_operations qla83xx_isp_ops = {
2395 .pci_config = qla25xx_pci_config,
2396 .reset_chip = qla24xx_reset_chip,
2397 .chip_diag = qla24xx_chip_diag,
2398 .config_rings = qla24xx_config_rings,
2399 .reset_adapter = qla24xx_reset_adapter,
2400 .nvram_config = qla81xx_nvram_config,
2401 .update_fw_options = qla81xx_update_fw_options,
2402 .load_risc = qla81xx_load_risc,
2403 .pci_info_str = qla24xx_pci_info_str,
2404 .fw_version_str = qla24xx_fw_version_str,
2405 .intr_handler = qla24xx_intr_handler,
2406 .enable_intrs = qla24xx_enable_intrs,
2407 .disable_intrs = qla24xx_disable_intrs,
2408 .abort_command = qla24xx_abort_command,
2409 .target_reset = qla24xx_abort_target,
2410 .lun_reset = qla24xx_lun_reset,
2411 .fabric_login = qla24xx_login_fabric,
2412 .fabric_logout = qla24xx_fabric_logout,
2413 .calc_req_entries = NULL,
2414 .build_iocbs = NULL,
2415 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2416 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2417 .read_nvram = NULL,
2418 .write_nvram = NULL,
2419 .fw_dump = qla83xx_fw_dump,
2420 .beacon_on = qla24xx_beacon_on,
2421 .beacon_off = qla24xx_beacon_off,
2422 .beacon_blink = qla83xx_beacon_blink,
2423 .read_optrom = qla25xx_read_optrom_data,
2424 .write_optrom = qla24xx_write_optrom_data,
2425 .get_flash_version = qla24xx_get_flash_version,
2426 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002427 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002428 .abort_isp = qla2x00_abort_isp,
2429 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002430 .initialize_adapter = qla2x00_initialize_adapter,
2431};
2432
2433static struct isp_operations qlafx00_isp_ops = {
2434 .pci_config = qlafx00_pci_config,
2435 .reset_chip = qlafx00_soft_reset,
2436 .chip_diag = qlafx00_chip_diag,
2437 .config_rings = qlafx00_config_rings,
2438 .reset_adapter = qlafx00_soft_reset,
2439 .nvram_config = NULL,
2440 .update_fw_options = NULL,
2441 .load_risc = NULL,
2442 .pci_info_str = qlafx00_pci_info_str,
2443 .fw_version_str = qlafx00_fw_version_str,
2444 .intr_handler = qlafx00_intr_handler,
2445 .enable_intrs = qlafx00_enable_intrs,
2446 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002447 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002448 .target_reset = qlafx00_abort_target,
2449 .lun_reset = qlafx00_lun_reset,
2450 .fabric_login = NULL,
2451 .fabric_logout = NULL,
2452 .calc_req_entries = NULL,
2453 .build_iocbs = NULL,
2454 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2455 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2456 .read_nvram = qla24xx_read_nvram_data,
2457 .write_nvram = qla24xx_write_nvram_data,
2458 .fw_dump = NULL,
2459 .beacon_on = qla24xx_beacon_on,
2460 .beacon_off = qla24xx_beacon_off,
2461 .beacon_blink = NULL,
2462 .read_optrom = qla24xx_read_optrom_data,
2463 .write_optrom = qla24xx_write_optrom_data,
2464 .get_flash_version = qla24xx_get_flash_version,
2465 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002466 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002467 .abort_isp = qlafx00_abort_isp,
2468 .iospace_config = qlafx00_iospace_config,
2469 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002470};
2471
Chad Dupuisf73cb692014-02-26 04:15:06 -05002472static struct isp_operations qla27xx_isp_ops = {
2473 .pci_config = qla25xx_pci_config,
2474 .reset_chip = qla24xx_reset_chip,
2475 .chip_diag = qla24xx_chip_diag,
2476 .config_rings = qla24xx_config_rings,
2477 .reset_adapter = qla24xx_reset_adapter,
2478 .nvram_config = qla81xx_nvram_config,
2479 .update_fw_options = qla81xx_update_fw_options,
2480 .load_risc = qla81xx_load_risc,
2481 .pci_info_str = qla24xx_pci_info_str,
2482 .fw_version_str = qla24xx_fw_version_str,
2483 .intr_handler = qla24xx_intr_handler,
2484 .enable_intrs = qla24xx_enable_intrs,
2485 .disable_intrs = qla24xx_disable_intrs,
2486 .abort_command = qla24xx_abort_command,
2487 .target_reset = qla24xx_abort_target,
2488 .lun_reset = qla24xx_lun_reset,
2489 .fabric_login = qla24xx_login_fabric,
2490 .fabric_logout = qla24xx_fabric_logout,
2491 .calc_req_entries = NULL,
2492 .build_iocbs = NULL,
2493 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2494 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2495 .read_nvram = NULL,
2496 .write_nvram = NULL,
2497 .fw_dump = qla27xx_fwdump,
2498 .beacon_on = qla24xx_beacon_on,
2499 .beacon_off = qla24xx_beacon_off,
2500 .beacon_blink = qla83xx_beacon_blink,
2501 .read_optrom = qla25xx_read_optrom_data,
2502 .write_optrom = qla24xx_write_optrom_data,
2503 .get_flash_version = qla24xx_get_flash_version,
2504 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002505 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002506 .abort_isp = qla2x00_abort_isp,
2507 .iospace_config = qla83xx_iospace_config,
2508 .initialize_adapter = qla2x00_initialize_adapter,
2509};
2510
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002511static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002512qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002513{
2514 ha->device_type = DT_EXTENDED_IDS;
2515 switch (ha->pdev->device) {
2516 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002517 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002518 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002519 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002520 break;
2521 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002522 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002523 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002524 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002525 break;
2526 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002527 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002528 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002529 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002530 break;
2531 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002532 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002533 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002534 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002535 break;
2536 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002537 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002538 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002539 if (ha->pdev->subsystem_vendor == 0x1028 &&
2540 ha->pdev->subsystem_device == 0x0170)
2541 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002542 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002543 break;
2544 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002545 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002546 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002547 break;
2548 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002549 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002550 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002551 break;
2552 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002553 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002554 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002555 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002556 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002557 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002558 break;
2559 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002560 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002561 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002562 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002563 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002564 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002565 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002566 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002567 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002568 ha->device_type |= DT_ZIO_SUPPORTED;
2569 ha->device_type |= DT_FWI2;
2570 ha->device_type |= DT_IIDMA;
2571 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2572 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002573 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002574 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002575 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002576 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002577 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002578 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002579 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002580 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002581 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002582 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002583 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002584 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002585 ha->device_type |= DT_ZIO_SUPPORTED;
2586 ha->device_type |= DT_FWI2;
2587 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002588 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2589 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002590 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002591 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002592 ha->device_type |= DT_ZIO_SUPPORTED;
2593 ha->device_type |= DT_FWI2;
2594 ha->device_type |= DT_IIDMA;
2595 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2596 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002597 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002598 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002599 ha->device_type |= DT_ZIO_SUPPORTED;
2600 ha->device_type |= DT_FWI2;
2601 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2602 /* Initialize 82XX ISP flags */
2603 qla82xx_init_flags(ha);
2604 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002605 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002606 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002607 ha->device_type |= DT_ZIO_SUPPORTED;
2608 ha->device_type |= DT_FWI2;
2609 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2610 /* Initialize 82XX ISP flags */
2611 qla82xx_init_flags(ha);
2612 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002613 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002614 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002615 ha->device_type |= DT_ZIO_SUPPORTED;
2616 ha->device_type |= DT_FWI2;
2617 ha->device_type |= DT_IIDMA;
2618 ha->device_type |= DT_T10_PI;
2619 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2620 break;
2621 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002622 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002623 ha->device_type |= DT_ZIO_SUPPORTED;
2624 ha->device_type |= DT_FWI2;
2625 ha->device_type |= DT_IIDMA;
2626 ha->device_type |= DT_T10_PI;
2627 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2628 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002629 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002630 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002631 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002632 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002633 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002634 ha->device_type |= DT_ZIO_SUPPORTED;
2635 ha->device_type |= DT_FWI2;
2636 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002637 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002638 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2639 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002640 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002641 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002642 ha->device_type |= DT_ZIO_SUPPORTED;
2643 ha->device_type |= DT_FWI2;
2644 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002645 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002646 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2647 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002648 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002649 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002650 ha->device_type |= DT_ZIO_SUPPORTED;
2651 ha->device_type |= DT_FWI2;
2652 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002653 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002654 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2655 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002656 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002657
Giridhar Malavalia9083012010-04-12 17:59:55 -07002658 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002659 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002660 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002661 /* Get adapter physical port no from interrupt pin register. */
2662 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002663 if (IS_QLA27XX(ha))
2664 ha->port_no--;
2665 else
2666 ha->port_no = !(ha->port_no & 1);
2667 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002668
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002669 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002670 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002671 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002672}
2673
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002674static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002675qla2xxx_scan_start(struct Scsi_Host *shost)
2676{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002678
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002679 if (vha->hw->flags.running_gold_fw)
2680 return;
2681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2683 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2684 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2685 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002686}
2687
2688static int
2689qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2690{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002691 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002692
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002693 if (test_bit(UNLOADING, &vha->dpc_flags))
2694 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002695 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002696 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002698 return 1;
2699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002701}
2702
Quinn Tranec7193e2017-03-15 09:48:55 -07002703static void qla2x00_iocb_work_fn(struct work_struct *work)
2704{
2705 struct scsi_qla_host *vha = container_of(work,
2706 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002707 struct qla_hw_data *ha = vha->hw;
2708 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2709 int i = 20;
2710 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002711
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002712 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2713 return;
2714
2715 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002716 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002717 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002718 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002719
2720 spin_lock_irqsave(&vha->work_lock, flags);
2721 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2722 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002723}
2724
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725/*
2726 * PCI driver interface
2727 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002728static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002729qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002731 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002733 scsi_qla_host_t *base_vha = NULL;
2734 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002735 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002736 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002737 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002738 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002740 struct req_que *req = NULL;
2741 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002742 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002743
Andrew Vasquez285d0322007-10-19 15:59:17 -07002744 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002745 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002746 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2747 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002748 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002749 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2750 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002751 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002752 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002753 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2754 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002755 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002756 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002757 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002758 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002759 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2760 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002761 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002762 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002763 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2764 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002765 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002766 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2767 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002768
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002769 if (mem_only) {
2770 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002771 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002772 } else {
2773 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002774 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
Jesse Barnes09276782008-10-18 17:33:19 -07002777 /* This may fail but that's ok */
2778 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002779
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002780 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2781 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002782 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2783 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002784 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002786 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2787 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002788 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002789 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2790 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002791 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002792 spin_lock_init(&ha->tgt.atio_lock);
2793
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002794 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
2796 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002797 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002798 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002799 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002800 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002801 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002802 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002804 /* Set ISP-type information. */
2805 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002806
2807 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002808 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002809 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002810 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002811
Chad Dupuiscba1e472011-11-18 09:03:21 -08002812 ha->prev_topology = 0;
2813 ha->init_cb_size = sizeof(init_cb_t);
2814 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2815 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002816 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002817
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002818 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 if (IS_QLA2100(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_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822 req_length = REQUEST_ENTRY_CNT_2100;
2823 rsp_length = RESPONSE_ENTRY_CNT_2100;
2824 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002825 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002826 ha->flash_conf_off = ~0;
2827 ha->flash_data_off = ~0;
2828 ha->nvram_conf_off = ~0;
2829 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002830 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002832 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002833 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002834 req_length = REQUEST_ENTRY_CNT_2200;
2835 rsp_length = RESPONSE_ENTRY_CNT_2100;
2836 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002837 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002838 ha->flash_conf_off = ~0;
2839 ha->flash_data_off = ~0;
2840 ha->nvram_conf_off = ~0;
2841 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002842 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002843 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002844 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002846 req_length = REQUEST_ENTRY_CNT_2200;
2847 rsp_length = RESPONSE_ENTRY_CNT_2300;
2848 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002849 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002850 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2851 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002852 ha->flash_conf_off = ~0;
2853 ha->flash_data_off = ~0;
2854 ha->nvram_conf_off = ~0;
2855 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002856 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002857 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002858 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002859 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860 req_length = REQUEST_ENTRY_CNT_24XX;
2861 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002862 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002863 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002864 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002865 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002866 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002867 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002868 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002869 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2870 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2871 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2872 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002873 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002874 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002875 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876 req_length = REQUEST_ENTRY_CNT_24XX;
2877 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002878 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002880 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002881 ha->gid_list_info_size = 8;
2882 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002883 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002884 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002885 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2886 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2887 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2888 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2889 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002890 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002891 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2892 req_length = REQUEST_ENTRY_CNT_24XX;
2893 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002894 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002895 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2896 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2897 ha->gid_list_info_size = 8;
2898 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002899 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002900 ha->isp_ops = &qla81xx_isp_ops;
2901 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2902 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2903 ha->nvram_conf_off = ~0;
2904 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002905 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002906 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002907 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2908 req_length = REQUEST_ENTRY_CNT_82XX;
2909 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2910 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2911 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2912 ha->gid_list_info_size = 8;
2913 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002914 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002915 ha->isp_ops = &qla82xx_isp_ops;
2916 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2917 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2918 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2919 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002920 } else if (IS_QLA8044(ha)) {
2921 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2922 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2923 req_length = REQUEST_ENTRY_CNT_82XX;
2924 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2925 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2926 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2927 ha->gid_list_info_size = 8;
2928 ha->optrom_size = OPTROM_SIZE_83XX;
2929 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2930 ha->isp_ops = &qla8044_isp_ops;
2931 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2932 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2933 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2934 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002935 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002936 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002937 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002938 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002939 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002940 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002941 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002942 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2943 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2944 ha->gid_list_info_size = 8;
2945 ha->optrom_size = OPTROM_SIZE_83XX;
2946 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2947 ha->isp_ops = &qla83xx_isp_ops;
2948 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2949 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2950 ha->nvram_conf_off = ~0;
2951 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002952 } else if (IS_QLAFX00(ha)) {
2953 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2954 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2955 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2956 req_length = REQUEST_ENTRY_CNT_FX00;
2957 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002958 ha->isp_ops = &qlafx00_isp_ops;
2959 ha->port_down_retry_count = 30; /* default value */
2960 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2961 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002962 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002963 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002964 ha->mr.host_info_resend = false;
2965 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002966 } else if (IS_QLA27XX(ha)) {
2967 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2968 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2969 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05002970 req_length = REQUEST_ENTRY_CNT_83XX;
2971 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002972 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002973 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2974 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2975 ha->gid_list_info_size = 8;
2976 ha->optrom_size = OPTROM_SIZE_83XX;
2977 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2978 ha->isp_ops = &qla27xx_isp_ops;
2979 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2980 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2981 ha->nvram_conf_off = ~0;
2982 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002984
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002985 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2986 "mbx_count=%d, req_length=%d, "
2987 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08002988 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
2989 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002990 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2991 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08002992 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002993 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2994 "isp_ops=%p, flash_conf_off=%d, "
2995 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2996 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2997 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002998
2999 /* Configure PCI I/O space */
3000 ret = ha->isp_ops->iospace_config(ha);
3001 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003002 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003003
3004 ql_log_pci(ql_log_info, pdev, 0x001d,
3005 "Found an ISP%04X irq %d iobase 0x%p.\n",
3006 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003007 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003008 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003009 init_completion(&ha->mbx_cmd_comp);
3010 complete(&ha->mbx_cmd_comp);
3011 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003012 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003013 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003015 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
Andrew Vasquez53303c42009-01-22 09:45:37 -08003017 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003018 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3019 "64 Bit addressing is %s.\n",
3020 ha->flags.enable_64bit_addressing ? "enable" :
3021 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003022 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003023 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003024 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3025 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003027 goto probe_hw_failed;
3028 }
3029
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003030 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003031 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003032 req->max_q_depth = ql2xmaxqdepth;
3033
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003034
3035 base_vha = qla2x00_create_host(sht, ha);
3036 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003037 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003038 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003039 qla2x00_free_req_que(ha, req);
3040 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 }
3043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003044 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003045 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003048 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003049 if (IS_QLA2XXX_MIDTYPE(ha))
himanshu.madhani@cavium.com1429f042017-12-28 12:33:25 -08003050 base_vha->mgmt_svr_loop_id = NPH_MGMT_SERVER;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003051 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003052 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3053 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003054
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003055 /* Setup fcport template structure. */
3056 ha->mr.fcport.vha = base_vha;
3057 ha->mr.fcport.port_type = FCT_UNKNOWN;
3058 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3059 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3060 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3061 ha->mr.fcport.scan_state = 1;
3062
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003063 /* Set the SG table size based on ISP type */
3064 if (!IS_FWI2_CAPABLE(ha)) {
3065 if (IS_QLA2100(ha))
3066 host->sg_tablesize = 32;
3067 } else {
3068 if (!IS_QLA82XX(ha))
3069 host->sg_tablesize = QLA_SG_ALL;
3070 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003071 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003072 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003073 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003074 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003075 host->max_cmd_len = 32;
3076 else
3077 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003078 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003079 /* Older HBAs support only 16-bit LUNs */
3080 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3081 ql2xmaxlun > 0xffff)
3082 host->max_lun = 0xffff;
3083 else
3084 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003085 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003086 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003087
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003088 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3089 "max_id=%d this_id=%d "
3090 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003091 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003092 host->this_id, host->cmd_per_lun, host->unique_id,
3093 host->max_cmd_len, host->max_channel, host->max_lun,
3094 host->transportt, sht->vendor_id);
3095
Himanshu Madhani1010f212017-10-16 11:26:05 -07003096 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3097
Michael Hernandezd7459522016-12-12 14:40:07 -08003098 /* Set up the irqs */
3099 ret = qla2x00_request_irqs(ha, rsp);
3100 if (ret)
3101 goto probe_init_failed;
3102
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003103 /* Alloc arrays of request and response ring ptrs */
3104 if (!qla2x00_alloc_queues(ha, req, rsp)) {
3105 ql_log(ql_log_fatal, base_vha, 0x003d,
3106 "Failed to allocate memory for queue pointers..."
3107 "aborting.\n");
3108 goto probe_init_failed;
3109 }
3110
Michael Hernandez56012362016-12-12 14:40:08 -08003111 if (ha->mqenable && shost_use_blk_mq(host)) {
3112 /* number of hardware queues supported by blk/scsi-mq*/
3113 host->nr_hw_queues = ha->max_qpairs;
3114
3115 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3116 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003117 } else {
3118 if (ql2xnvmeenable) {
3119 host->nr_hw_queues = ha->max_qpairs;
3120 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3121 "FC-NVMe support is enabled, HW queues=%d\n",
3122 host->nr_hw_queues);
3123 } else {
3124 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3125 "blk/scsi-mq disabled.\n");
3126 }
3127 }
Michael Hernandez56012362016-12-12 14:40:08 -08003128
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003129 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003130
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003131 pci_save_state(pdev);
3132
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003133 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003134 rsp->req = req;
3135 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003136
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003137 if (IS_QLAFX00(ha)) {
3138 ha->rsp_q_map[0] = rsp;
3139 ha->req_q_map[0] = req;
3140 set_bit(0, ha->req_qid_map);
3141 set_bit(0, ha->rsp_qid_map);
3142 }
3143
Andrew Vasquez08029992009-03-24 09:07:55 -07003144 /* FWI2-capable only. */
3145 req->req_q_in = &ha->iobase->isp24.req_q_in;
3146 req->req_q_out = &ha->iobase->isp24.req_q_out;
3147 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3148 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003149 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003150 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3151 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3152 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3153 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003154 }
3155
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003156 if (IS_QLAFX00(ha)) {
3157 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3158 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3159 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3160 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3161 }
3162
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003163 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003164 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3165 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3166 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3167 }
3168
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003169 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3170 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3171 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3172 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3173 "req->req_q_in=%p req->req_q_out=%p "
3174 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3175 req->req_q_in, req->req_q_out,
3176 rsp->rsp_q_in, rsp->rsp_q_out);
3177 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3178 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3179 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3180 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3181 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3182 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003184 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003185 ql_log(ql_log_fatal, base_vha, 0x00d6,
3186 "Failed to initialize adapter - Adapter flags %x.\n",
3187 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003188
Giridhar Malavalia9083012010-04-12 17:59:55 -07003189 if (IS_QLA82XX(ha)) {
3190 qla82xx_idc_lock(ha);
3191 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003192 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003193 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003194 ql_log(ql_log_fatal, base_vha, 0x00d7,
3195 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003196 } else if (IS_QLA8044(ha)) {
3197 qla8044_idc_lock(ha);
3198 qla8044_wr_direct(base_vha,
3199 QLA8044_CRB_DEV_STATE_INDEX,
3200 QLA8XXX_DEV_FAILED);
3201 qla8044_idc_unlock(ha);
3202 ql_log(ql_log_fatal, base_vha, 0x0150,
3203 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003204 }
3205
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003206 ret = -ENODEV;
3207 goto probe_failed;
3208 }
3209
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003210 if (IS_QLAFX00(ha))
3211 host->can_queue = QLAFX00_MAX_CANQUEUE;
3212 else
3213 host->can_queue = req->num_outstanding_cmds - 10;
3214
3215 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3216 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3217 host->can_queue, base_vha->req,
3218 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3219
Quinn Tran9b3e0f42017-12-28 12:33:16 -08003220 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
Quinn Trana01c77d2017-12-04 14:44:58 -08003221
Quinn Trane326d222017-06-13 20:47:18 -07003222 if (ha->mqenable) {
3223 bool mq = false;
3224 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003225
3226 if (QLA_TGT_MODE_ENABLED()) {
3227 mq = true;
3228 startit = false;
3229 }
3230
3231 if ((ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) &&
3232 shost_use_blk_mq(host)) {
3233 mq = true;
3234 startit = true;
3235 }
3236
3237 if (mq) {
3238 /* Create start of day qpairs for Block MQ */
Michael Hernandez56012362016-12-12 14:40:08 -08003239 for (i = 0; i < ha->max_qpairs; i++)
Quinn Trane326d222017-06-13 20:47:18 -07003240 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003241 }
3242 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003243
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003244 if (ha->flags.running_gold_fw)
3245 goto skip_dpc;
3246
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003247 /*
3248 * Startup the kernel thread for this host adapter
3249 */
3250 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003251 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003252 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003253 ql_log(ql_log_fatal, base_vha, 0x00ed,
3254 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003256 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 goto probe_failed;
3258 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003259 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3260 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003261
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003262 /*
3263 * If we're not coming up in initiator mode, we might sit for
3264 * a while without waking up the dpc thread, which leads to a
3265 * stuck process warning. So just kick the dpc once here and
3266 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3267 */
3268 qla2xxx_wake_dpc(base_vha);
3269
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003270 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3271
Saurav Kashyap81178772012-08-22 14:21:04 -04003272 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3273 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3274 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3275 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3276
3277 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3278 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3279 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3280 INIT_WORK(&ha->idc_state_handler,
3281 qla83xx_idc_state_handler_work);
3282 INIT_WORK(&ha->nic_core_unrecoverable,
3283 qla83xx_nic_core_unrecoverable_work);
3284 }
3285
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003286skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 list_add_tail(&base_vha->list, &ha->vp_list);
3288 base_vha->host->irq = ha->pdev->irq;
3289
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003291 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003292 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3293 "Started qla2x00_timer with "
3294 "interval=%d.\n", WATCH_INTERVAL);
3295 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3296 "Detected hba at address=%p.\n",
3297 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298
Arun Easie02587d2011-08-16 11:29:23 -07003299 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003300 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003301 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003302 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003303 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3304 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003305 if (ql2xenabledif == 1)
3306 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07003307 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07003308 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003309 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003310 | SHOST_DIF_TYPE3_PROTECTION
3311 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003312 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003313 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003314
3315 guard = SHOST_DIX_GUARD_CRC;
3316
3317 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3318 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3319 guard |= SHOST_DIX_GUARD_IP;
3320
3321 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003322 } else
3323 base_vha->flags.difdix_supported = 0;
3324 }
3325
Giridhar Malavalia9083012010-04-12 17:59:55 -07003326 ha->isp_ops->enable_intrs(ha);
3327
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003328 if (IS_QLAFX00(ha)) {
3329 ret = qlafx00_fx_disc(base_vha,
3330 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3331 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3332 QLA_SG_ALL : 128;
3333 }
3334
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003335 ret = scsi_add_host(host, &pdev->dev);
3336 if (ret)
3337 goto probe_failed;
3338
Michael Reed14864002009-12-02 09:11:16 -06003339 base_vha->flags.init_done = 1;
3340 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003341 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003342
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003343 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3344 "Init done and hba is online.\n");
3345
Quinn Tran726b8542017-01-19 22:28:00 -08003346 if (qla_ini_mode_enabled(base_vha) ||
3347 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003348 scsi_scan_host(host);
3349 else
3350 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3351 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003352
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003354
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003355 if (IS_QLAFX00(ha)) {
3356 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003357 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3358
3359 /* Register system information */
3360 ret = qlafx00_fx_disc(base_vha,
3361 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3362 }
3363
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003364 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003365
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003366 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003367
Armen Baloyan03eb9122013-10-30 03:38:22 -04003368 ql_log(ql_log_info, base_vha, 0x00fb,
3369 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003370 ql_log(ql_log_info, base_vha, 0x00fc,
3371 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3372 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3373 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3374 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003375 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003377 qlt_add_target(ha, base_vha);
3378
Joe Lawrence6b383972014-08-26 17:12:29 -04003379 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003380
3381 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3382 return -ENODEV;
3383
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003384 if (ha->flags.detected_lr_sfp) {
3385 ql_log(ql_log_info, base_vha, 0xffff,
3386 "Reset chip to pick up LR SFP setting\n");
3387 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3388 qla2xxx_wake_dpc(base_vha);
3389 }
3390
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 return 0;
3392
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003393probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003394 qla2x00_free_req_que(ha, req);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003395 ha->req_q_map[0] = NULL;
3396 clear_bit(0, ha->req_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003397 qla2x00_free_rsp_que(ha, rsp);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003398 ha->rsp_q_map[0] = NULL;
3399 clear_bit(0, ha->rsp_qid_map);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003400 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08003401
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003403 if (base_vha->timer_active)
3404 qla2x00_stop_timer(base_vha);
3405 base_vha->flags.online = 0;
3406 if (ha->dpc_thread) {
3407 struct task_struct *t = ha->dpc_thread;
3408
3409 ha->dpc_thread = NULL;
3410 kthread_stop(t);
3411 }
3412
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003415 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003417probe_hw_failed:
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003418 qla2x00_clear_drv_active(ha);
3419
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003420iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003421 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003422 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003423 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003424 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003425 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003426 } else {
3427 if (ha->iobase)
3428 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003429 if (ha->cregbase)
3430 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003431 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 pci_release_selected_regions(ha->pdev, ha->bars);
3433 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003435disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003437 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439
Adrian Bunk4c993f72008-01-14 00:55:16 -08003440static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003441qla2x00_shutdown(struct pci_dev *pdev)
3442{
3443 scsi_qla_host_t *vha;
3444 struct qla_hw_data *ha;
3445
3446 vha = pci_get_drvdata(pdev);
3447 ha = vha->hw;
3448
Sawan Chandakefdb5762017-08-23 15:05:00 -07003449 ql_log(ql_log_info, vha, 0xfffa,
3450 "Adapter shutdown\n");
3451
3452 /*
3453 * Prevent future board_disable and wait
3454 * until any pending board_disable has completed.
3455 */
3456 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3457 cancel_work_sync(&ha->board_disable);
3458
3459 if (!atomic_read(&pdev->enable_cnt))
3460 return;
3461
Armen Baloyan42479342013-08-27 01:37:37 -04003462 /* Notify ISPFX00 firmware */
3463 if (IS_QLAFX00(ha))
3464 qlafx00_driver_shutdown(vha, 20);
3465
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003466 /* Turn-off FCE trace */
3467 if (ha->flags.fce_enabled) {
3468 qla2x00_disable_fce_trace(vha, NULL, NULL);
3469 ha->flags.fce_enabled = 0;
3470 }
3471
3472 /* Turn-off EFT trace */
3473 if (ha->eft)
3474 qla2x00_disable_eft_trace(vha);
3475
Quinn Tran3407fc32017-12-28 12:33:11 -08003476 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3477 if (ha->flags.fw_started)
3478 qla2x00_abort_isp_cleanup(vha);
3479 } else {
3480 /* Stop currently executing firmware. */
3481 qla2x00_try_to_stop_firmware(vha);
3482 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003483
3484 /* Turn adapter off line */
3485 vha->flags.online = 0;
3486
3487 /* turn-off interrupts on the card */
3488 if (ha->interrupts_on) {
3489 vha->flags.init_done = 0;
3490 ha->isp_ops->disable_intrs(ha);
3491 }
3492
3493 qla2x00_free_irqs(vha);
3494
3495 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003496
Chad Dupuis61d41f62014-09-25 05:17:02 -04003497 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003498 ql_log(ql_log_info, vha, 0xfffe,
3499 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003500}
3501
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003502/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003503static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003504qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003506 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003507 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508
Arun Easi43ebf162011-05-10 11:18:16 -07003509 mutex_lock(&ha->vport_lock);
3510 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003511 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003512
Arun Easi43ebf162011-05-10 11:18:16 -07003513 BUG_ON(base_vha->list.next == &ha->vp_list);
3514 /* This assumes first entry in ha->vp_list is always base vha */
3515 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003516 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003517
Arun Easi43ebf162011-05-10 11:18:16 -07003518 spin_unlock_irqrestore(&ha->vport_slock, flags);
3519 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003520
Arun Easi43ebf162011-05-10 11:18:16 -07003521 fc_vport_terminate(vha->fc_vport);
3522 scsi_host_put(vha->host);
3523
3524 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525 }
Arun Easi43ebf162011-05-10 11:18:16 -07003526 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003527}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003528
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003529/* Stops all deferred work threads */
3530static void
3531qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3532{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003533 /* Cancel all work and destroy DPC workqueues */
3534 if (ha->dpc_lp_wq) {
3535 cancel_work_sync(&ha->idc_aen);
3536 destroy_workqueue(ha->dpc_lp_wq);
3537 ha->dpc_lp_wq = NULL;
3538 }
3539
3540 if (ha->dpc_hp_wq) {
3541 cancel_work_sync(&ha->nic_core_reset);
3542 cancel_work_sync(&ha->idc_state_handler);
3543 cancel_work_sync(&ha->nic_core_unrecoverable);
3544 destroy_workqueue(ha->dpc_hp_wq);
3545 ha->dpc_hp_wq = NULL;
3546 }
3547
Andrew Vasquezb9978762009-03-24 09:08:05 -07003548 /* Kill the kernel thread for this host */
3549 if (ha->dpc_thread) {
3550 struct task_struct *t = ha->dpc_thread;
3551
3552 /*
3553 * qla2xxx_wake_dpc checks for ->dpc_thread
3554 * so we need to zero it out.
3555 */
3556 ha->dpc_thread = NULL;
3557 kthread_stop(t);
3558 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003559}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003560
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003561static void
3562qla2x00_unmap_iobases(struct qla_hw_data *ha)
3563{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003564 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003565
Chad Dupuisf73cb692014-02-26 04:15:06 -05003566 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003567 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003568 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003569 } else {
3570 if (ha->iobase)
3571 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003573 if (ha->cregbase)
3574 iounmap(ha->cregbase);
3575
Giridhar Malavalia9083012010-04-12 17:59:55 -07003576 if (ha->mqiobase)
3577 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003578
Chad Dupuisf73cb692014-02-26 04:15:06 -05003579 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003580 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003581 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003582}
3583
3584static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003585qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003586{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003587 if (IS_QLA8044(ha)) {
3588 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003589 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003590 qla8044_idc_unlock(ha);
3591 } else if (IS_QLA82XX(ha)) {
3592 qla82xx_idc_lock(ha);
3593 qla82xx_clear_drv_active(ha);
3594 qla82xx_idc_unlock(ha);
3595 }
3596}
3597
3598static void
3599qla2x00_remove_one(struct pci_dev *pdev)
3600{
3601 scsi_qla_host_t *base_vha;
3602 struct qla_hw_data *ha;
3603
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003604 base_vha = pci_get_drvdata(pdev);
3605 ha = base_vha->hw;
3606
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003607 /* Indicate device removal to prevent future board_disable and wait
3608 * until any pending board_disable has completed. */
3609 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3610 cancel_work_sync(&ha->board_disable);
3611
3612 /*
3613 * If the PCI device is disabled then there was a PCI-disconnect and
3614 * qla2x00_disable_board_on_pci_error has taken care of most of the
3615 * resources.
3616 */
3617 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003618 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3619 base_vha->gnl.l, base_vha->gnl.ldma);
3620
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003621 scsi_host_put(base_vha->host);
3622 kfree(ha);
3623 pci_set_drvdata(pdev, NULL);
3624 return;
3625 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003626 qla2x00_wait_for_hba_ready(base_vha);
3627
Quinn Tran726b8542017-01-19 22:28:00 -08003628 /*
3629 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003630 * where it was set first.
3631 */
3632 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3633 return;
3634
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003635 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003636
3637 qla_nvme_delete(base_vha);
3638
Quinn Tran726b8542017-01-19 22:28:00 -08003639 dma_free_coherent(&ha->pdev->dev,
3640 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003641
Quinn Trana4239942017-12-28 12:33:26 -08003642 vfree(base_vha->scan.l);
3643
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003644 if (IS_QLAFX00(ha))
3645 qlafx00_driver_shutdown(base_vha, 20);
3646
3647 qla2x00_delete_all_vps(ha, base_vha);
3648
3649 if (IS_QLA8031(ha)) {
3650 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3651 "Clearing fcoe driver presence.\n");
3652 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3653 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3654 "Error while clearing DRV-Presence.\n");
3655 }
3656
3657 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3658
3659 qla2x00_dfs_remove(base_vha);
3660
3661 qla84xx_put_chip(base_vha);
3662
3663 /* Disable timer */
3664 if (base_vha->timer_active)
3665 qla2x00_stop_timer(base_vha);
3666
3667 base_vha->flags.online = 0;
3668
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003669 /* free DMA memory */
3670 if (ha->exlogin_buf)
3671 qla2x00_free_exlogin_buffer(ha);
3672
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003673 /* free DMA memory */
3674 if (ha->exchoffld_buf)
3675 qla2x00_free_exchoffld_buffer(ha);
3676
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003677 qla2x00_destroy_deferred_work(ha);
3678
3679 qlt_remove_target(ha, base_vha);
3680
3681 qla2x00_free_sysfs_attr(base_vha, true);
3682
3683 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003684 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003685
3686 scsi_remove_host(base_vha->host);
3687
3688 qla2x00_free_device(base_vha);
3689
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003690 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003691
Arun Easid2749ff2014-09-25 05:16:51 -04003692 scsi_host_put(base_vha->host);
3693
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003694 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003696 pci_release_selected_regions(ha->pdev, ha->bars);
3697 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003699 pci_disable_pcie_error_reporting(pdev);
3700
Bernhard Walle665db932007-03-28 00:49:49 +02003701 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703
3704static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003705qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003707 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708
Andrew Vasquez85880802009-12-15 21:29:46 -08003709 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3710
3711 /* Disable timer */
3712 if (vha->timer_active)
3713 qla2x00_stop_timer(vha);
3714
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003715 qla25xx_delete_queues(vha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003716
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003717 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003718 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003719
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003720 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003721 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003722
Quinn Tran3407fc32017-12-28 12:33:11 -08003723 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3724 if (ha->flags.fw_started)
3725 qla2x00_abort_isp_cleanup(vha);
3726 } else {
3727 if (ha->flags.fw_started) {
3728 /* Stop currently executing firmware. */
3729 qla2x00_try_to_stop_firmware(vha);
3730 ha->flags.fw_started = 0;
3731 }
3732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733
Andrew Vasquez85880802009-12-15 21:29:46 -08003734 vha->flags.online = 0;
3735
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003736 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003737 if (ha->interrupts_on) {
3738 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003739 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003740 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003741
Quinn Tran093df732016-12-12 14:40:09 -08003742 qla2x00_free_fcports(vha);
3743
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003744 qla2x00_free_irqs(vha);
3745
Quinn Tran093df732016-12-12 14:40:09 -08003746 /* Flush the work queue and remove it */
3747 if (ha->wq) {
3748 flush_workqueue(ha->wq);
3749 destroy_workqueue(ha->wq);
3750 ha->wq = NULL;
3751 }
3752
Chad Dupuis88670482010-07-23 15:28:30 +05003753
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003754 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003755
Giridhar Malavali08de2842011-08-16 11:31:44 -07003756 qla82xx_md_free(vha);
3757
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003758 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759}
3760
Chad Dupuis88670482010-07-23 15:28:30 +05003761void qla2x00_free_fcports(struct scsi_qla_host *vha)
3762{
3763 fc_port_t *fcport, *tfcport;
3764
3765 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3766 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003767 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003768 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003769 }
3770}
3771
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003772static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003773qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003774 int defer)
3775{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003776 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003777 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003778 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003779
3780 if (!fcport->rport)
3781 return;
3782
3783 rport = fcport->rport;
3784 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003785 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003786 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003787 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003788 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003789 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003790 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3791 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003792 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003793 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003794 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003795 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3796 "%s %8phN. rport %p roles %x\n",
3797 __func__, fcport->port_name, rport,
3798 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003799 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003800 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003801 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003802 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003803}
3804
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3807 *
3808 * Input: ha = adapter block pointer. fcport = port structure pointer.
3809 *
3810 * Return: None.
3811 *
3812 * Context:
3813 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003815 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003817 if (IS_QLAFX00(vha->hw)) {
3818 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3819 qla2x00_schedule_rport_del(vha, fcport, defer);
3820 return;
3821 }
3822
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003823 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003824 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003825 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003826 qla2x00_schedule_rport_del(vha, fcport, defer);
3827 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003828 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 * We may need to retry the login, so don't change the state of the
3830 * port but do the retries.
3831 */
3832 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003833 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834
3835 if (!do_login)
3836 return;
3837
Arun Easia1d02852015-08-04 13:38:02 -04003838 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3839
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841 fcport->login_retry = vha->hw->login_retry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
Quinn Tran83548fe2017-06-02 09:12:01 -07003843 ql_dbg(ql_dbg_disc, vha, 0x20a3,
Quinn Tran726b8542017-01-19 22:28:00 -08003844 "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003845 fcport->port_name, fcport->loop_id, fcport->login_retry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 }
3847}
3848
3849/*
3850 * qla2x00_mark_all_devices_lost
3851 * Updates fcport state when device goes offline.
3852 *
3853 * Input:
3854 * ha = adapter block pointer.
3855 * fcport = port structure pointer.
3856 *
3857 * Return:
3858 * None.
3859 *
3860 * Context:
3861 */
3862void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003863qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864{
3865 fc_port_t *fcport;
3866
Quinn Tran83548fe2017-06-02 09:12:01 -07003867 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3868 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003869
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003870 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003871 fcport->scan_state = 0;
3872 qlt_schedule_sess_for_deletion_lock(fcport);
3873
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003874 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003876
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 /*
3878 * No point in marking the device as lost, if the device is
3879 * already DEAD.
3880 */
3881 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3882 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003883 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003884 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003885 if (defer)
3886 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003887 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003888 qla2x00_schedule_rport_del(vha, fcport, defer);
3889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 }
3891}
3892
3893/*
3894* qla2x00_mem_alloc
3895* Allocates adapter memory.
3896*
3897* Returns:
3898* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003899* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003901static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003902qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3903 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904{
3905 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906
Andrew Vasqueze8711082008-01-31 12:33:48 -08003907 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003908 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003909 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003910 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003912 if (qlt_mem_alloc(ha) < 0)
3913 goto fail_free_init_cb;
3914
Chad Dupuis642ef982012-02-09 11:15:57 -08003915 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3916 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003918 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919
Andrew Vasqueze8711082008-01-31 12:33:48 -08003920 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3921 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003924 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003925 /* Allocate cache for CT6 Ctx. */
3926 if (!ctx_cachep) {
3927 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3928 sizeof(struct ct6_dsd), 0,
3929 SLAB_HWCACHE_ALIGN, NULL);
3930 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003931 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003932 }
3933 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3934 ctx_cachep);
3935 if (!ha->ctx_mempool)
3936 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003937 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3938 "ctx_cachep=%p ctx_mempool=%p.\n",
3939 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003940 }
3941
Andrew Vasqueze8711082008-01-31 12:33:48 -08003942 /* Get memory for cached NVRAM */
3943 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3944 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003945 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003947 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3948 ha->pdev->device);
3949 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3950 DMA_POOL_SIZE, 8, 0);
3951 if (!ha->s_dma_pool)
3952 goto fail_free_nvram;
3953
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003954 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3955 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3956 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3957
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003958 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003959 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3960 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3961 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003962 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3963 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003964 goto fail_s_dma_pool;
3965 }
3966
3967 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3968 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3969 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003970 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3971 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003972 goto fail_dl_dma_pool;
3973 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003974 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3975 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3976 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003977 }
3978
Andrew Vasqueze8711082008-01-31 12:33:48 -08003979 /* Allocate memory for SNS commands */
3980 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003981 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003982 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003983 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003984 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003985 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003986 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08003987 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003988 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003989 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003990 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003991 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003992 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003993 goto fail_dma_pool;
3994 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003995 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003996 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003997 if (!ha->ct_sns)
3998 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003999 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4000 "ms_iocb=%p ct_sns=%p.\n",
4001 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 }
4003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004005 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4006 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004007 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4008 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004009 goto fail_req;
4010 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004011 (*req)->length = req_len;
4012 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4013 ((*req)->length + 1) * sizeof(request_t),
4014 &(*req)->dma, GFP_KERNEL);
4015 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004016 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4017 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004018 goto fail_req_ring;
4019 }
4020 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004021 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4022 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004023 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4024 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004025 goto fail_rsp;
4026 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004027 (*rsp)->hw = ha;
4028 (*rsp)->length = rsp_len;
4029 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4030 ((*rsp)->length + 1) * sizeof(response_t),
4031 &(*rsp)->dma, GFP_KERNEL);
4032 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004033 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4034 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 goto fail_rsp_ring;
4036 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004037 (*req)->rsp = *rsp;
4038 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004039 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4040 "req=%p req->length=%d req->ring=%p rsp=%p "
4041 "rsp->length=%d rsp->ring=%p.\n",
4042 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4043 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004044 /* Allocate memory for NVRAM data for vports */
4045 if (ha->nvram_npiv_size) {
4046 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004047 ha->nvram_npiv_size, GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004048 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004049 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4050 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004051 goto fail_npiv_info;
4052 }
4053 } else
4054 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004055
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004056 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004057 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004058 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4059 &ha->ex_init_cb_dma);
4060 if (!ha->ex_init_cb)
4061 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004062 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4063 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004064 }
4065
Giridhar Malavalia9083012010-04-12 17:59:55 -07004066 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4067
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004068 /* Get consistent memory allocated for Async Port-Database. */
4069 if (!IS_FWI2_CAPABLE(ha)) {
4070 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4071 &ha->async_pd_dma);
4072 if (!ha->async_pd)
4073 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004074 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4075 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004076 }
4077
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004078 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004079
4080 /* Allocate memory for our loop_id bitmap */
4081 ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
4082 GFP_KERNEL);
4083 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004084 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004085 else {
4086 qla2x00_set_reserved_loop_ids(ha);
4087 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004088 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004089 }
4090
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004091 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4092 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4093 if (!ha->sfp_data) {
4094 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4095 "Unable to allocate memory for SFP read-data.\n");
4096 goto fail_sfp_data;
4097 }
4098
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004099 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004100
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004101fail_sfp_data:
4102 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004103fail_loop_id_map:
4104 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004105fail_async_pd:
4106 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004107fail_ex_init_cb:
4108 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004109fail_npiv_info:
4110 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4111 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4112 (*rsp)->ring = NULL;
4113 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004114fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004115 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004116fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004117 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4118 sizeof(request_t), (*req)->ring, (*req)->dma);
4119 (*req)->ring = NULL;
4120 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004121fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004122 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004123fail_req:
4124 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4125 ha->ct_sns, ha->ct_sns_dma);
4126 ha->ct_sns = NULL;
4127 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004128fail_free_ms_iocb:
4129 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4130 ha->ms_iocb = NULL;
4131 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004132
4133 if (ha->sns_cmd)
4134 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4135 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004136fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004137 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004138 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4139 ha->fcp_cmnd_dma_pool = NULL;
4140 }
4141fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004142 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004143 dma_pool_destroy(ha->dl_dma_pool);
4144 ha->dl_dma_pool = NULL;
4145 }
4146fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004147 dma_pool_destroy(ha->s_dma_pool);
4148 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004149fail_free_nvram:
4150 kfree(ha->nvram);
4151 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004152fail_free_ctx_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004153 if (ha->ctx_mempool)
4154 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004155 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004156fail_free_srb_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004157 if (ha->srb_mempool)
4158 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004159 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004160fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004161 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4162 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004164 ha->gid_list = NULL;
4165 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004166fail_free_tgt_mem:
4167 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004168fail_free_init_cb:
4169 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4170 ha->init_cb_dma);
4171 ha->init_cb = NULL;
4172 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004173fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004174 ql_log(ql_log_fatal, NULL, 0x0030,
4175 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004176 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177}
4178
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004179int
4180qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4181{
4182 int rval;
4183 uint16_t size, max_cnt, temp;
4184 struct qla_hw_data *ha = vha->hw;
4185
4186 /* Return if we don't need to alloacate any extended logins */
4187 if (!ql2xexlogins)
4188 return QLA_SUCCESS;
4189
Quinn Tran99e1b682017-06-02 09:12:03 -07004190 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4191 return QLA_SUCCESS;
4192
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004193 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4194 max_cnt = 0;
4195 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4196 if (rval != QLA_SUCCESS) {
4197 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4198 "Failed to get exlogin status.\n");
4199 return rval;
4200 }
4201
4202 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004203 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004204
Quinn Tran99e1b682017-06-02 09:12:03 -07004205 if (temp != ha->exlogin_size) {
4206 qla2x00_free_exlogin_buffer(ha);
4207 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004208
Quinn Tran99e1b682017-06-02 09:12:03 -07004209 ql_log(ql_log_info, vha, 0xd024,
4210 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4211 max_cnt, size, temp);
4212
4213 ql_log(ql_log_info, vha, 0xd025,
4214 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4215
4216 /* Get consistent memory for extended logins */
4217 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4218 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4219 if (!ha->exlogin_buf) {
4220 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004221 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004222 return -ENOMEM;
4223 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004224 }
4225
4226 /* Now configure the dma buffer */
4227 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4228 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004229 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004230 "Setup extended login buffer ****FAILED****.\n");
4231 qla2x00_free_exlogin_buffer(ha);
4232 }
4233
4234 return rval;
4235}
4236
4237/*
4238* qla2x00_free_exlogin_buffer
4239*
4240* Input:
4241* ha = adapter block pointer
4242*/
4243void
4244qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4245{
4246 if (ha->exlogin_buf) {
4247 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4248 ha->exlogin_buf, ha->exlogin_buf_dma);
4249 ha->exlogin_buf = NULL;
4250 ha->exlogin_size = 0;
4251 }
4252}
4253
Quinn Tran99e1b682017-06-02 09:12:03 -07004254static void
4255qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4256{
4257 u32 temp;
4258 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4259
Quinn Trand1e36352017-12-28 12:33:12 -08004260 if (max_cnt > vha->hw->max_exchg)
4261 max_cnt = vha->hw->max_exchg;
4262
Quinn Tran99e1b682017-06-02 09:12:03 -07004263 if (qla_ini_mode_enabled(vha)) {
4264 if (ql2xiniexchg > max_cnt)
4265 ql2xiniexchg = max_cnt;
4266
4267 if (ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4268 *ret_cnt = ql2xiniexchg;
4269 } else if (qla_tgt_mode_enabled(vha)) {
4270 if (ql2xexchoffld > max_cnt)
4271 ql2xexchoffld = max_cnt;
4272
4273 if (ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4274 *ret_cnt = ql2xexchoffld;
4275 } else if (qla_dual_mode_enabled(vha)) {
4276 temp = ql2xiniexchg + ql2xexchoffld;
4277 if (temp > max_cnt) {
4278 ql2xiniexchg -= (temp - max_cnt)/2;
4279 ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4280 temp = max_cnt;
4281 }
4282
4283 if (temp > FW_DEF_EXCHANGES_CNT)
4284 *ret_cnt = temp;
4285 }
4286}
4287
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004288int
4289qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4290{
4291 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004292 u16 size, max_cnt;
4293 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004294 struct qla_hw_data *ha = vha->hw;
4295
Quinn Tran99e1b682017-06-02 09:12:03 -07004296 if (!ha->flags.exchoffld_enabled)
4297 return QLA_SUCCESS;
4298
4299 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004300 return QLA_SUCCESS;
4301
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004302 max_cnt = 0;
4303 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4304 if (rval != QLA_SUCCESS) {
4305 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4306 "Failed to get exlogin status.\n");
4307 return rval;
4308 }
4309
Quinn Trand1e36352017-12-28 12:33:12 -08004310 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4311 ql_log(ql_log_info, vha, 0xd014,
4312 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004313
Quinn Trand1e36352017-12-28 12:33:12 -08004314 totsz = actual_cnt * size;
4315
4316 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004317 qla2x00_free_exchoffld_buffer(ha);
Quinn Trand1e36352017-12-28 12:33:12 -08004318 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004319
Quinn Tran99e1b682017-06-02 09:12:03 -07004320 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004321 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4322 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004323
4324 ql_log(ql_log_info, vha, 0xd017,
4325 "Exchange Buffers requested size = 0x%x\n",
4326 ha->exchoffld_size);
4327
4328 /* Get consistent memory for extended logins */
4329 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4330 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4331 if (!ha->exchoffld_buf) {
4332 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004333 "Failed to allocate memory for Exchange Offload.\n");
4334
4335 if (ha->max_exchg >
4336 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4337 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4338 } else if (ha->max_exchg >
4339 (FW_DEF_EXCHANGES_CNT + 512)) {
4340 ha->max_exchg -= 512;
4341 } else {
4342 ha->flags.exchoffld_enabled = 0;
4343 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4344 "Disabling Exchange offload due to lack of memory\n");
4345 }
4346 ha->exchoffld_size = 0;
4347
Quinn Tran99e1b682017-06-02 09:12:03 -07004348 return -ENOMEM;
4349 }
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004350 }
4351
4352 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004353 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004354 if (rval) {
4355 ql_log(ql_log_fatal, vha, 0xd02e,
4356 "Setup exchange offload buffer ****FAILED****.\n");
4357 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004358 } else {
4359 /* re-adjust number of target exchange */
4360 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4361
4362 if (qla_ini_mode_enabled(vha))
4363 icb->exchange_count = 0;
4364 else
4365 icb->exchange_count = cpu_to_le16(ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004366 }
4367
4368 return rval;
4369}
4370
4371/*
4372* qla2x00_free_exchoffld_buffer
4373*
4374* Input:
4375* ha = adapter block pointer
4376*/
4377void
4378qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4379{
4380 if (ha->exchoffld_buf) {
4381 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4382 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4383 ha->exchoffld_buf = NULL;
4384 ha->exchoffld_size = 0;
4385 }
4386}
4387
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004389* qla2x00_free_fw_dump
4390* Frees fw dump stuff.
4391*
4392* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004393* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004394*/
4395static void
4396qla2x00_free_fw_dump(struct qla_hw_data *ha)
4397{
4398 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004399 dma_free_coherent(&ha->pdev->dev,
4400 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004401
Chad Dupuisf73cb692014-02-26 04:15:06 -05004402 if (ha->eft)
4403 dma_free_coherent(&ha->pdev->dev,
4404 EFT_SIZE, ha->eft, ha->eft_dma);
4405
4406 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004407 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004408 if (ha->fw_dump_template)
4409 vfree(ha->fw_dump_template);
4410
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004411 ha->fce = NULL;
4412 ha->fce_dma = 0;
4413 ha->eft = NULL;
4414 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004415 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004416 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004417 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004418 ha->fw_dump = NULL;
4419 ha->fw_dump_len = 0;
4420 ha->fw_dump_template = NULL;
4421 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004422}
4423
4424/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425* qla2x00_mem_free
4426* Frees all adapter allocated memory.
4427*
4428* Input:
4429* ha = adapter block pointer.
4430*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004431static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004432qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004434 qla2x00_free_fw_dump(ha);
4435
Saurav Kashyap81178772012-08-22 14:21:04 -04004436 if (ha->mctp_dump)
4437 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4438 ha->mctp_dump_dma);
4439
Andrew Vasqueze8711082008-01-31 12:33:48 -08004440 if (ha->srb_mempool)
4441 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004443 if (ha->dcbx_tlv)
4444 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4445 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4446
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004447 if (ha->xgmac_data)
4448 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4449 ha->xgmac_data, ha->xgmac_data_dma);
4450
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 if (ha->sns_cmd)
4452 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004453 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454
4455 if (ha->ct_sns)
4456 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004457 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458
Andrew Vasquez88729e52006-06-23 16:10:50 -07004459 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004460 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4461 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004462
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 if (ha->ms_iocb)
4464 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4465
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004466 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004467 dma_pool_free(ha->s_dma_pool,
4468 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004469
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004470 if (ha->async_pd)
4471 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4472
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 if (ha->s_dma_pool)
4474 dma_pool_destroy(ha->s_dma_pool);
4475
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004477 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4478 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479
Giridhar Malavalia9083012010-04-12 17:59:55 -07004480 if (IS_QLA82XX(ha)) {
4481 if (!list_empty(&ha->gbl_dsd_list)) {
4482 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4483
4484 /* clean up allocated prev pool */
4485 list_for_each_entry_safe(dsd_ptr,
4486 tdsd_ptr, &ha->gbl_dsd_list, list) {
4487 dma_pool_free(ha->dl_dma_pool,
4488 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4489 list_del(&dsd_ptr->list);
4490 kfree(dsd_ptr);
4491 }
4492 }
4493 }
4494
4495 if (ha->dl_dma_pool)
4496 dma_pool_destroy(ha->dl_dma_pool);
4497
4498 if (ha->fcp_cmnd_dma_pool)
4499 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4500
4501 if (ha->ctx_mempool)
4502 mempool_destroy(ha->ctx_mempool);
4503
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004504 qlt_mem_free(ha);
4505
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004506 if (ha->init_cb)
4507 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004508 ha->init_cb, ha->init_cb_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004509 vfree(ha->optrom_buffer);
4510 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004511 kfree(ha->npiv_info);
Andrew Vasquez7a677352012-02-09 11:15:56 -08004512 kfree(ha->swl);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004513 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514
Andrew Vasqueze8711082008-01-31 12:33:48 -08004515 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004516 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 ha->sns_cmd = NULL;
4518 ha->sns_cmd_dma = 0;
4519 ha->ct_sns = NULL;
4520 ha->ct_sns_dma = 0;
4521 ha->ms_iocb = NULL;
4522 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 ha->init_cb = NULL;
4524 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004525 ha->ex_init_cb = NULL;
4526 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004527 ha->async_pd = NULL;
4528 ha->async_pd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529
4530 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004531 ha->dl_dma_pool = NULL;
4532 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534 ha->gid_list = NULL;
4535 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004536
4537 ha->tgt.atio_ring = NULL;
4538 ha->tgt.atio_dma = 0;
4539 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004540}
4541
4542struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4543 struct qla_hw_data *ha)
4544{
4545 struct Scsi_Host *host;
4546 struct scsi_qla_host *vha = NULL;
4547
4548 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004549 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004550 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4551 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004552 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004553 }
4554
4555 /* Clear our data area */
4556 vha = shost_priv(host);
4557 memset(vha, 0, sizeof(scsi_qla_host_t));
4558
4559 vha->host = host;
4560 vha->host_no = host->host_no;
4561 vha->hw = ha;
4562
4563 INIT_LIST_HEAD(&vha->vp_fcports);
4564 INIT_LIST_HEAD(&vha->work_list);
4565 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004566 INIT_LIST_HEAD(&vha->qla_cmd_list);
4567 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004568 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004569 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004570 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004571 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004572 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004573 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004574 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004575
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004576 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004577 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004578 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004579 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004580
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004581 vha->gnl.size = sizeof(struct get_name_list_extended) *
4582 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004583 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4584 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4585 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004586 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004587 "Alloc failed for name list.\n");
4588 scsi_remove_host(vha->host);
4589 return NULL;
4590 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004591
Quinn Trana4239942017-12-28 12:33:26 -08004592 /* todo: what about ext login? */
4593 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4594 vha->scan.l = vmalloc(vha->scan.size);
4595 if (!vha->scan.l) {
4596 ql_log(ql_log_fatal, vha, 0xd04a,
4597 "Alloc failed for scan database.\n");
4598 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4599 vha->gnl.l, vha->gnl.ldma);
4600 scsi_remove_host(vha->host);
4601 return NULL;
4602 }
4603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004604 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004605 ql_dbg(ql_dbg_init, vha, 0x0041,
4606 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4607 vha->host, vha->hw, vha,
4608 dev_name(&(ha->pdev->dev)));
4609
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004610 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611}
4612
Quinn Tran726b8542017-01-19 22:28:00 -08004613struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004614qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004615{
4616 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004617 uint8_t bail;
4618
4619 QLA_VHA_MARK_BUSY(vha, bail);
4620 if (bail)
4621 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004622
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004623 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004624 if (!e) {
4625 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004626 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004627 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004628
4629 INIT_LIST_HEAD(&e->list);
4630 e->type = type;
4631 e->flags = QLA_EVT_FLAG_FREE;
4632 return e;
4633}
4634
Quinn Tran726b8542017-01-19 22:28:00 -08004635int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004636qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004637{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004638 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004639 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004640
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004641 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004642 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004643
4644 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4645 q = true;
4646
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004647 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004648
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004649 if (q)
4650 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004651
Andrew Vasquez0971de72008-04-03 13:13:18 -07004652 return QLA_SUCCESS;
4653}
4654
4655int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004656qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004657 u32 data)
4658{
4659 struct qla_work_evt *e;
4660
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004661 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004662 if (!e)
4663 return QLA_FUNCTION_FAILED;
4664
4665 e->u.aen.code = code;
4666 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004667 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004668}
4669
Andrew Vasquez8a659572009-02-08 20:50:12 -08004670int
4671qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4672{
4673 struct qla_work_evt *e;
4674
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004675 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004676 if (!e)
4677 return QLA_FUNCTION_FAILED;
4678
4679 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004680 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004681}
4682
Andrew Vasquezac280b62009-08-20 11:06:05 -07004683#define qla2x00_post_async_work(name, type) \
4684int qla2x00_post_async_##name##_work( \
4685 struct scsi_qla_host *vha, \
4686 fc_port_t *fcport, uint16_t *data) \
4687{ \
4688 struct qla_work_evt *e; \
4689 \
4690 e = qla2x00_alloc_work(vha, type); \
4691 if (!e) \
4692 return QLA_FUNCTION_FAILED; \
4693 \
4694 e->u.logio.fcport = fcport; \
4695 if (data) { \
4696 e->u.logio.data[0] = data[0]; \
4697 e->u.logio.data[1] = data[1]; \
4698 } \
4699 return qla2x00_post_work(vha, e); \
4700}
4701
4702qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004703qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4704qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004705qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4706qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Quinn Tran11aea162017-12-28 12:33:20 -08004707qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4708qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004709
Andrew Vasquez3420d362009-10-13 15:16:45 -07004710int
4711qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4712{
4713 struct qla_work_evt *e;
4714
4715 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4716 if (!e)
4717 return QLA_FUNCTION_FAILED;
4718
4719 e->u.uevent.code = code;
4720 return qla2x00_post_work(vha, e);
4721}
4722
4723static void
4724qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4725{
4726 char event_string[40];
4727 char *envp[] = { event_string, NULL };
4728
4729 switch (code) {
4730 case QLA_UEVENT_CODE_FW_DUMP:
4731 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4732 vha->host_no);
4733 break;
4734 default:
4735 /* do nothing */
4736 break;
4737 }
4738 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4739}
4740
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004741int
4742qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4743 uint32_t *data, int cnt)
4744{
4745 struct qla_work_evt *e;
4746
4747 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4748 if (!e)
4749 return QLA_FUNCTION_FAILED;
4750
4751 e->u.aenfx.evtcode = evtcode;
4752 e->u.aenfx.count = cnt;
4753 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4754 return qla2x00_post_work(vha, e);
4755}
4756
Quinn Tran726b8542017-01-19 22:28:00 -08004757int qla24xx_post_upd_fcport_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4758{
4759 struct qla_work_evt *e;
4760
4761 e = qla2x00_alloc_work(vha, QLA_EVT_UPD_FCPORT);
4762 if (!e)
4763 return QLA_FUNCTION_FAILED;
4764
4765 e->u.fcport.fcport = fcport;
4766 return qla2x00_post_work(vha, e);
4767}
4768
4769static
4770void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4771{
4772 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07004773 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08004774 struct qlt_plogi_ack_t *pla =
4775 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07004776 uint8_t free_fcport = 0;
Quinn Trana4239942017-12-28 12:33:26 -08004777 u64 wwn;
Quinn Tran726b8542017-01-19 22:28:00 -08004778
Quinn Tran9cd883f2017-12-28 12:33:24 -08004779 ql_dbg(ql_dbg_disc, vha, 0xffff,
4780 "%s %d %8phC enter\n",
4781 __func__, __LINE__, e->u.new_sess.port_name);
4782
Quinn Tran726b8542017-01-19 22:28:00 -08004783 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4784 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4785 if (fcport) {
4786 fcport->d_id = e->u.new_sess.id;
4787 if (pla) {
4788 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004789 memcpy(fcport->node_name,
4790 pla->iocb.u.isp24.u.plogi.node_name,
4791 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08004792 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4793 /* we took an extra ref_count to prevent PLOGI ACK when
4794 * fcport/sess has not been created.
4795 */
4796 pla->ref_count--;
4797 }
4798 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07004799 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004800 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4801 if (fcport) {
4802 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08004803 fcport->flags |= FCF_FABRIC_DEVICE;
4804 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Trana4239942017-12-28 12:33:26 -08004805 if (e->u.new_sess.fc4_type == FC4_TYPE_FCP_SCSI)
4806 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08004807
4808 memcpy(fcport->port_name, e->u.new_sess.port_name,
4809 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07004810 } else {
4811 ql_dbg(ql_dbg_disc, vha, 0xffff,
4812 "%s %8phC mem alloc fail.\n",
4813 __func__, e->u.new_sess.port_name);
4814
4815 if (pla)
4816 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4817 return;
4818 }
4819
4820 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08004821 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07004822 tfcp = qla2x00_find_fcport_by_wwpn(vha,
4823 e->u.new_sess.port_name, 1);
4824 if (tfcp) {
4825 /* should rarily happen */
4826 ql_dbg(ql_dbg_disc, vha, 0xffff,
4827 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
4828 __func__, tfcp->port_name, tfcp->disc_state,
4829 tfcp->fw_login_state);
4830
4831 free_fcport = 1;
4832 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08004833 list_add_tail(&fcport->list, &vha->vp_fcports);
4834
Quinn Tran19759032017-12-04 14:45:15 -08004835 }
4836 if (pla) {
4837 qlt_plogi_ack_link(vha, pla, fcport,
4838 QLT_PLOGI_LINK_SAME_WWN);
4839 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08004840 }
4841 }
4842 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4843
4844 if (fcport) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08004845 if (N2N_TOPO(vha->hw))
4846 fcport->flags &= ~FCF_FABRIC_DEVICE;
4847
Quinn Trana4239942017-12-28 12:33:26 -08004848 fcport->id_changed = 1;
4849 fcport->scan_state = QLA_FCPORT_FOUND;
4850 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
4851
Quinn Tran5ef696a2017-12-04 14:45:05 -08004852 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08004853 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
4854 u16 wd3_lo;
4855
4856 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4857 fcport->local = 0;
4858 fcport->loop_id =
4859 le16_to_cpu(
4860 pla->iocb.u.isp24.nport_handle);
4861 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4862 wd3_lo =
4863 le16_to_cpu(
4864 pla->iocb.u.isp24.u.prli.wd3_lo);
4865
4866 if (wd3_lo & BIT_7)
4867 fcport->conf_compl_supported = 1;
4868
4869 if ((wd3_lo & BIT_4) == 0)
4870 fcport->port_type = FCT_INITIATOR;
4871 else
4872 fcport->port_type = FCT_TARGET;
4873 }
Quinn Tran726b8542017-01-19 22:28:00 -08004874 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08004875 } else {
4876 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4877 tfcp = qla2x00_find_fcport_by_nportid(vha,
4878 &e->u.new_sess.id, 1);
4879 if (tfcp && (tfcp != fcport)) {
4880 /*
4881 * We have a conflict fcport with same NportID.
4882 */
4883 ql_dbg(ql_dbg_disc, vha, 0xffff,
4884 "%s %8phC found conflict b4 add. DS %d LS %d\n",
4885 __func__, tfcp->port_name, tfcp->disc_state,
4886 tfcp->fw_login_state);
4887
4888 switch (tfcp->disc_state) {
4889 case DSC_DELETED:
4890 break;
4891 case DSC_DELETE_PEND:
4892 fcport->login_pause = 1;
4893 tfcp->conflict = fcport;
4894 break;
4895 default:
4896 fcport->login_pause = 1;
4897 tfcp->conflict = fcport;
4898 qlt_schedule_sess_for_deletion_lock
4899 (tfcp);
4900 break;
4901 }
4902 }
4903 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08004904
4905 wwn = wwn_to_u64(fcport->node_name);
4906
4907 if (!wwn)
4908 qla24xx_async_gnnid(vha, fcport);
4909 else
4910 qla24xx_async_gnl(vha, fcport);
Quinn Tran5ef696a2017-12-04 14:45:05 -08004911 }
Quinn Tran726b8542017-01-19 22:28:00 -08004912 }
Quinn Tranb5d15312017-08-30 10:16:49 -07004913
4914 if (free_fcport) {
4915 qla2x00_free_fcport(fcport);
4916 if (pla)
4917 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4918 }
Quinn Tran726b8542017-01-19 22:28:00 -08004919}
4920
Andrew Vasquezac280b62009-08-20 11:06:05 -07004921void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004922qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004923{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004924 struct qla_work_evt *e, *tmp;
4925 unsigned long flags;
4926 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004927
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004928 spin_lock_irqsave(&vha->work_lock, flags);
4929 list_splice_init(&vha->work_list, &work);
4930 spin_unlock_irqrestore(&vha->work_lock, flags);
4931
4932 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07004933 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004934
4935 switch (e->type) {
4936 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004937 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07004938 e->u.aen.code, e->u.aen.data);
4939 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08004940 case QLA_EVT_IDC_ACK:
4941 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
4942 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004943 case QLA_EVT_ASYNC_LOGIN:
4944 qla2x00_async_login(vha, e->u.logio.fcport,
4945 e->u.logio.data);
4946 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004947 case QLA_EVT_ASYNC_LOGOUT:
4948 qla2x00_async_logout(vha, e->u.logio.fcport);
4949 break;
4950 case QLA_EVT_ASYNC_LOGOUT_DONE:
4951 qla2x00_async_logout_done(vha, e->u.logio.fcport,
4952 e->u.logio.data);
4953 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004954 case QLA_EVT_ASYNC_ADISC:
4955 qla2x00_async_adisc(vha, e->u.logio.fcport,
4956 e->u.logio.data);
4957 break;
4958 case QLA_EVT_ASYNC_ADISC_DONE:
4959 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
4960 e->u.logio.data);
4961 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07004962 case QLA_EVT_UEVENT:
4963 qla2x00_uevent_emit(vha, e->u.uevent.code);
4964 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004965 case QLA_EVT_AENFX:
4966 qlafx00_process_aen(vha, e);
4967 break;
Quinn Tran726b8542017-01-19 22:28:00 -08004968 case QLA_EVT_GIDPN:
4969 qla24xx_async_gidpn(vha, e->u.fcport.fcport);
4970 break;
4971 case QLA_EVT_GPNID:
4972 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
4973 break;
4974 case QLA_EVT_GPNID_DONE:
4975 qla24xx_async_gpnid_done(vha, e->u.iosb.sp);
4976 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004977 case QLA_EVT_RELOGIN:
4978 qla2x00_relogin(vha);
4979 break;
Quinn Tran726b8542017-01-19 22:28:00 -08004980 case QLA_EVT_NEW_SESS:
4981 qla24xx_create_new_sess(vha, e);
4982 break;
4983 case QLA_EVT_GPDB:
4984 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
4985 e->u.fcport.opt);
4986 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004987 case QLA_EVT_PRLI:
4988 qla24xx_async_prli(vha, e->u.fcport.fcport);
4989 break;
Quinn Tran726b8542017-01-19 22:28:00 -08004990 case QLA_EVT_GPSC:
4991 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
4992 break;
4993 case QLA_EVT_UPD_FCPORT:
4994 qla2x00_update_fcport(vha, e->u.fcport.fcport);
4995 break;
4996 case QLA_EVT_GNL:
4997 qla24xx_async_gnl(vha, e->u.fcport.fcport);
4998 break;
4999 case QLA_EVT_NACK:
5000 qla24xx_do_nack_work(vha, e);
5001 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005002 case QLA_EVT_ASYNC_PRLO:
5003 qla2x00_async_prlo(vha, e->u.logio.fcport);
5004 break;
5005 case QLA_EVT_ASYNC_PRLO_DONE:
5006 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5007 e->u.logio.data);
5008 break;
Quinn Trana4239942017-12-28 12:33:26 -08005009 case QLA_EVT_GPNFT:
5010 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type);
5011 break;
5012 case QLA_EVT_GPNFT_DONE:
5013 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5014 break;
5015 case QLA_EVT_GNNFT_DONE:
5016 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5017 break;
5018 case QLA_EVT_GNNID:
5019 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5020 break;
5021 case QLA_EVT_GFPNID:
5022 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5023 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005024 }
5025 if (e->flags & QLA_EVT_FLAG_FREE)
5026 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005027
5028 /* For each work completed decrement vha ref count */
5029 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005030 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005031}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005032
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005033int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5034{
5035 struct qla_work_evt *e;
5036
5037 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5038
5039 if (!e) {
5040 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5041 return QLA_FUNCTION_FAILED;
5042 }
5043
5044 return qla2x00_post_work(vha, e);
5045}
5046
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005047/* Relogins all the fcports of a vport
5048 * Context: dpc thread
5049 */
5050void qla2x00_relogin(struct scsi_qla_host *vha)
5051{
5052 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08005053 int status;
Quinn Tran726b8542017-01-19 22:28:00 -08005054 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005055
5056 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005057 /*
5058 * If the port is not ONLINE then try to login
5059 * to it if we haven't run out of retries.
5060 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005061 if (atomic_read(&fcport->state) != FCS_ONLINE &&
5062 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005063 if (vha->hw->current_topology != ISP_CFG_NL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005064 ql_dbg(ql_dbg_disc, fcport->vha, 0x2108,
Quinn Tran726b8542017-01-19 22:28:00 -08005065 "%s %8phC DS %d LS %d\n", __func__,
5066 fcport->port_name, fcport->disc_state,
5067 fcport->fw_login_state);
5068 memset(&ea, 0, sizeof(ea));
5069 ea.event = FCME_RELOGIN;
5070 ea.fcport = fcport;
5071 qla2x00_fcport_event_handler(vha, &ea);
Quinn Tran9cd883f2017-12-28 12:33:24 -08005072 } else if (vha->hw->current_topology == ISP_CFG_NL) {
Quinn Tran4005a992017-12-04 14:45:06 -08005073 fcport->login_retry--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005074 status = qla2x00_local_device_login(vha,
5075 fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08005076 if (status == QLA_SUCCESS) {
5077 fcport->old_loop_id = fcport->loop_id;
5078 ql_dbg(ql_dbg_disc, vha, 0x2003,
5079 "Port login OK: logged in ID 0x%x.\n",
5080 fcport->loop_id);
5081 qla2x00_update_fcport(vha, fcport);
5082 } else if (status == 1) {
5083 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5084 /* retry the login again */
5085 ql_dbg(ql_dbg_disc, vha, 0x2007,
5086 "Retrying %d login again loop_id 0x%x.\n",
5087 fcport->login_retry,
5088 fcport->loop_id);
5089 } else {
5090 fcport->login_retry = 0;
5091 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005092
Quinn Tran726b8542017-01-19 22:28:00 -08005093 if (fcport->login_retry == 0 &&
5094 status != QLA_SUCCESS)
5095 qla2x00_clear_loop_id(fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005096 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005097 }
5098 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5099 break;
5100 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005101
5102 ql_dbg(ql_dbg_disc, vha, 0x400e,
5103 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005104}
5105
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005106/* Schedule work on any of the dpc-workqueues */
5107void
5108qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5109{
5110 struct qla_hw_data *ha = base_vha->hw;
5111
5112 switch (work_code) {
5113 case MBA_IDC_AEN: /* 0x8200 */
5114 if (ha->dpc_lp_wq)
5115 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5116 break;
5117
5118 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5119 if (!ha->flags.nic_core_reset_hdlr_active) {
5120 if (ha->dpc_hp_wq)
5121 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5122 } else
5123 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5124 "NIC Core reset is already active. Skip "
5125 "scheduling it again.\n");
5126 break;
5127 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5128 if (ha->dpc_hp_wq)
5129 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5130 break;
5131 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5132 if (ha->dpc_hp_wq)
5133 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5134 break;
5135 default:
5136 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005137 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005138 }
5139
5140 return;
5141}
5142
5143/* Work: Perform NIC Core Unrecoverable state handling */
5144void
5145qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5146{
5147 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005148 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005149 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5150 uint32_t dev_state = 0;
5151
5152 qla83xx_idc_lock(base_vha, 0);
5153 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5154 qla83xx_reset_ownership(base_vha);
5155 if (ha->flags.nic_core_reset_owner) {
5156 ha->flags.nic_core_reset_owner = 0;
5157 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5158 QLA8XXX_DEV_FAILED);
5159 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5160 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5161 }
5162 qla83xx_idc_unlock(base_vha, 0);
5163}
5164
5165/* Work: Execute IDC state handler */
5166void
5167qla83xx_idc_state_handler_work(struct work_struct *work)
5168{
5169 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005170 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005171 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5172 uint32_t dev_state = 0;
5173
5174 qla83xx_idc_lock(base_vha, 0);
5175 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5176 if (dev_state == QLA8XXX_DEV_FAILED ||
5177 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5178 qla83xx_idc_state_handler(base_vha);
5179 qla83xx_idc_unlock(base_vha, 0);
5180}
5181
Saurav Kashyapfa492632012-11-21 02:40:29 -05005182static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005183qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5184{
5185 int rval = QLA_SUCCESS;
5186 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5187 uint32_t heart_beat_counter1, heart_beat_counter2;
5188
5189 do {
5190 if (time_after(jiffies, heart_beat_wait)) {
5191 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5192 "Nic Core f/w is not alive.\n");
5193 rval = QLA_FUNCTION_FAILED;
5194 break;
5195 }
5196
5197 qla83xx_idc_lock(base_vha, 0);
5198 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5199 &heart_beat_counter1);
5200 qla83xx_idc_unlock(base_vha, 0);
5201 msleep(100);
5202 qla83xx_idc_lock(base_vha, 0);
5203 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5204 &heart_beat_counter2);
5205 qla83xx_idc_unlock(base_vha, 0);
5206 } while (heart_beat_counter1 == heart_beat_counter2);
5207
5208 return rval;
5209}
5210
5211/* Work: Perform NIC Core Reset handling */
5212void
5213qla83xx_nic_core_reset_work(struct work_struct *work)
5214{
5215 struct qla_hw_data *ha =
5216 container_of(work, struct qla_hw_data, nic_core_reset);
5217 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5218 uint32_t dev_state = 0;
5219
Saurav Kashyap81178772012-08-22 14:21:04 -04005220 if (IS_QLA2031(ha)) {
5221 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5222 ql_log(ql_log_warn, base_vha, 0xb081,
5223 "Failed to dump mctp\n");
5224 return;
5225 }
5226
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005227 if (!ha->flags.nic_core_reset_hdlr_active) {
5228 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5229 qla83xx_idc_lock(base_vha, 0);
5230 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5231 &dev_state);
5232 qla83xx_idc_unlock(base_vha, 0);
5233 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5234 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5235 "Nic Core f/w is alive.\n");
5236 return;
5237 }
5238 }
5239
5240 ha->flags.nic_core_reset_hdlr_active = 1;
5241 if (qla83xx_nic_core_reset(base_vha)) {
5242 /* NIC Core reset failed. */
5243 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5244 "NIC Core reset failed.\n");
5245 }
5246 ha->flags.nic_core_reset_hdlr_active = 0;
5247 }
5248}
5249
5250/* Work: Handle 8200 IDC aens */
5251void
5252qla83xx_service_idc_aen(struct work_struct *work)
5253{
5254 struct qla_hw_data *ha =
5255 container_of(work, struct qla_hw_data, idc_aen);
5256 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5257 uint32_t dev_state, idc_control;
5258
5259 qla83xx_idc_lock(base_vha, 0);
5260 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5261 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5262 qla83xx_idc_unlock(base_vha, 0);
5263 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5264 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5265 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5266 "Application requested NIC Core Reset.\n");
5267 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5268 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5269 QLA_SUCCESS) {
5270 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5271 "Other protocol driver requested NIC Core Reset.\n");
5272 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5273 }
5274 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5275 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5276 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5277 }
5278}
5279
5280static void
5281qla83xx_wait_logic(void)
5282{
5283 int i;
5284
5285 /* Yield CPU */
5286 if (!in_interrupt()) {
5287 /*
5288 * Wait about 200ms before retrying again.
5289 * This controls the number of retries for single
5290 * lock operation.
5291 */
5292 msleep(100);
5293 schedule();
5294 } else {
5295 for (i = 0; i < 20; i++)
5296 cpu_relax(); /* This a nop instr on i386 */
5297 }
5298}
5299
Saurav Kashyapfa492632012-11-21 02:40:29 -05005300static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005301qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5302{
5303 int rval;
5304 uint32_t data;
5305 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5306 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5307 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005308 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5309 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005310
5311 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5312 if (rval)
5313 return rval;
5314
5315 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5316 return QLA_SUCCESS;
5317 } else {
5318 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5319 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5320 data);
5321 if (rval)
5322 return rval;
5323
5324 msleep(200);
5325
5326 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5327 &data);
5328 if (rval)
5329 return rval;
5330
5331 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5332 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5333 ~(idc_lck_rcvry_stage_mask));
5334 rval = qla83xx_wr_reg(base_vha,
5335 QLA83XX_IDC_LOCK_RECOVERY, data);
5336 if (rval)
5337 return rval;
5338
5339 /* Forcefully perform IDC UnLock */
5340 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5341 &data);
5342 if (rval)
5343 return rval;
5344 /* Clear lock-id by setting 0xff */
5345 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5346 0xff);
5347 if (rval)
5348 return rval;
5349 /* Clear lock-recovery by setting 0x0 */
5350 rval = qla83xx_wr_reg(base_vha,
5351 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5352 if (rval)
5353 return rval;
5354 } else
5355 return QLA_SUCCESS;
5356 }
5357
5358 return rval;
5359}
5360
Saurav Kashyapfa492632012-11-21 02:40:29 -05005361static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005362qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5363{
5364 int rval = QLA_SUCCESS;
5365 uint32_t o_drv_lockid, n_drv_lockid;
5366 unsigned long lock_recovery_timeout;
5367
5368 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5369retry_lockid:
5370 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5371 if (rval)
5372 goto exit;
5373
5374 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5375 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5376 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5377 return QLA_SUCCESS;
5378 else
5379 return QLA_FUNCTION_FAILED;
5380 }
5381
5382 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5383 if (rval)
5384 goto exit;
5385
5386 if (o_drv_lockid == n_drv_lockid) {
5387 qla83xx_wait_logic();
5388 goto retry_lockid;
5389 } else
5390 return QLA_SUCCESS;
5391
5392exit:
5393 return rval;
5394}
5395
5396void
5397qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5398{
5399 uint16_t options = (requester_id << 15) | BIT_6;
5400 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005401 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005402 struct qla_hw_data *ha = base_vha->hw;
5403
5404 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5405retry_lock:
5406 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5407 == QLA_SUCCESS) {
5408 if (data) {
5409 /* Setting lock-id to our function-number */
5410 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5411 ha->portnum);
5412 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005413 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5414 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005415 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005416 "Failed to acquire IDC lock, acquired by %d, "
5417 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005418
5419 /* Retry/Perform IDC-Lock recovery */
5420 if (qla83xx_idc_lock_recovery(base_vha)
5421 == QLA_SUCCESS) {
5422 qla83xx_wait_logic();
5423 goto retry_lock;
5424 } else
5425 ql_log(ql_log_warn, base_vha, 0xb075,
5426 "IDC Lock recovery FAILED.\n");
5427 }
5428
5429 }
5430
5431 return;
5432
5433 /* XXX: IDC-lock implementation using access-control mbx */
5434retry_lock2:
5435 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5436 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5437 "Failed to acquire IDC lock. retrying...\n");
5438 /* Retry/Perform IDC-Lock recovery */
5439 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5440 qla83xx_wait_logic();
5441 goto retry_lock2;
5442 } else
5443 ql_log(ql_log_warn, base_vha, 0xb076,
5444 "IDC Lock recovery FAILED.\n");
5445 }
5446
5447 return;
5448}
5449
5450void
5451qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5452{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005453#if 0
5454 uint16_t options = (requester_id << 15) | BIT_7;
5455#endif
5456 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005457 uint32_t data;
5458 struct qla_hw_data *ha = base_vha->hw;
5459
5460 /* IDC-unlock implementation using driver-unlock/lock-id
5461 * remote registers
5462 */
5463 retry = 0;
5464retry_unlock:
5465 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5466 == QLA_SUCCESS) {
5467 if (data == ha->portnum) {
5468 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5469 /* Clearing lock-id by setting 0xff */
5470 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5471 } else if (retry < 10) {
5472 /* SV: XXX: IDC unlock retrying needed here? */
5473
5474 /* Retry for IDC-unlock */
5475 qla83xx_wait_logic();
5476 retry++;
5477 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005478 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005479 goto retry_unlock;
5480 }
5481 } else if (retry < 10) {
5482 /* Retry for IDC-unlock */
5483 qla83xx_wait_logic();
5484 retry++;
5485 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005486 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005487 goto retry_unlock;
5488 }
5489
5490 return;
5491
Bart Van Assche5897cb22015-06-04 15:57:20 -07005492#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005493 /* XXX: IDC-unlock implementation using access-control mbx */
5494 retry = 0;
5495retry_unlock2:
5496 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5497 if (retry < 10) {
5498 /* Retry for IDC-unlock */
5499 qla83xx_wait_logic();
5500 retry++;
5501 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005502 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005503 goto retry_unlock2;
5504 }
5505 }
5506
5507 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005508#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005509}
5510
5511int
5512__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5513{
5514 int rval = QLA_SUCCESS;
5515 struct qla_hw_data *ha = vha->hw;
5516 uint32_t drv_presence;
5517
5518 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5519 if (rval == QLA_SUCCESS) {
5520 drv_presence |= (1 << ha->portnum);
5521 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5522 drv_presence);
5523 }
5524
5525 return rval;
5526}
5527
5528int
5529qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5530{
5531 int rval = QLA_SUCCESS;
5532
5533 qla83xx_idc_lock(vha, 0);
5534 rval = __qla83xx_set_drv_presence(vha);
5535 qla83xx_idc_unlock(vha, 0);
5536
5537 return rval;
5538}
5539
5540int
5541__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5542{
5543 int rval = QLA_SUCCESS;
5544 struct qla_hw_data *ha = vha->hw;
5545 uint32_t drv_presence;
5546
5547 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5548 if (rval == QLA_SUCCESS) {
5549 drv_presence &= ~(1 << ha->portnum);
5550 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5551 drv_presence);
5552 }
5553
5554 return rval;
5555}
5556
5557int
5558qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5559{
5560 int rval = QLA_SUCCESS;
5561
5562 qla83xx_idc_lock(vha, 0);
5563 rval = __qla83xx_clear_drv_presence(vha);
5564 qla83xx_idc_unlock(vha, 0);
5565
5566 return rval;
5567}
5568
Saurav Kashyapfa492632012-11-21 02:40:29 -05005569static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005570qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5571{
5572 struct qla_hw_data *ha = vha->hw;
5573 uint32_t drv_ack, drv_presence;
5574 unsigned long ack_timeout;
5575
5576 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5577 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5578 while (1) {
5579 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5580 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005581 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005582 break;
5583
5584 if (time_after_eq(jiffies, ack_timeout)) {
5585 ql_log(ql_log_warn, vha, 0xb067,
5586 "RESET ACK TIMEOUT! drv_presence=0x%x "
5587 "drv_ack=0x%x\n", drv_presence, drv_ack);
5588 /*
5589 * The function(s) which did not ack in time are forced
5590 * to withdraw any further participation in the IDC
5591 * reset.
5592 */
5593 if (drv_ack != drv_presence)
5594 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5595 drv_ack);
5596 break;
5597 }
5598
5599 qla83xx_idc_unlock(vha, 0);
5600 msleep(1000);
5601 qla83xx_idc_lock(vha, 0);
5602 }
5603
5604 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5605 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5606}
5607
Saurav Kashyapfa492632012-11-21 02:40:29 -05005608static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005609qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5610{
5611 int rval = QLA_SUCCESS;
5612 uint32_t idc_control;
5613
5614 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5615 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5616
5617 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5618 __qla83xx_get_idc_control(vha, &idc_control);
5619 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5620 __qla83xx_set_idc_control(vha, 0);
5621
5622 qla83xx_idc_unlock(vha, 0);
5623 rval = qla83xx_restart_nic_firmware(vha);
5624 qla83xx_idc_lock(vha, 0);
5625
5626 if (rval != QLA_SUCCESS) {
5627 ql_log(ql_log_fatal, vha, 0xb06a,
5628 "Failed to restart NIC f/w.\n");
5629 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5630 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5631 } else {
5632 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5633 "Success in restarting nic f/w.\n");
5634 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5635 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5636 }
5637
5638 return rval;
5639}
5640
5641/* Assumes idc_lock always held on entry */
5642int
5643qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5644{
5645 struct qla_hw_data *ha = base_vha->hw;
5646 int rval = QLA_SUCCESS;
5647 unsigned long dev_init_timeout;
5648 uint32_t dev_state;
5649
5650 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5651 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5652
5653 while (1) {
5654
5655 if (time_after_eq(jiffies, dev_init_timeout)) {
5656 ql_log(ql_log_warn, base_vha, 0xb06e,
5657 "Initialization TIMEOUT!\n");
5658 /* Init timeout. Disable further NIC Core
5659 * communication.
5660 */
5661 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5662 QLA8XXX_DEV_FAILED);
5663 ql_log(ql_log_info, base_vha, 0xb06f,
5664 "HW State: FAILED.\n");
5665 }
5666
5667 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5668 switch (dev_state) {
5669 case QLA8XXX_DEV_READY:
5670 if (ha->flags.nic_core_reset_owner)
5671 qla83xx_idc_audit(base_vha,
5672 IDC_AUDIT_COMPLETION);
5673 ha->flags.nic_core_reset_owner = 0;
5674 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5675 "Reset_owner reset by 0x%x.\n",
5676 ha->portnum);
5677 goto exit;
5678 case QLA8XXX_DEV_COLD:
5679 if (ha->flags.nic_core_reset_owner)
5680 rval = qla83xx_device_bootstrap(base_vha);
5681 else {
5682 /* Wait for AEN to change device-state */
5683 qla83xx_idc_unlock(base_vha, 0);
5684 msleep(1000);
5685 qla83xx_idc_lock(base_vha, 0);
5686 }
5687 break;
5688 case QLA8XXX_DEV_INITIALIZING:
5689 /* Wait for AEN to change device-state */
5690 qla83xx_idc_unlock(base_vha, 0);
5691 msleep(1000);
5692 qla83xx_idc_lock(base_vha, 0);
5693 break;
5694 case QLA8XXX_DEV_NEED_RESET:
5695 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5696 qla83xx_need_reset_handler(base_vha);
5697 else {
5698 /* Wait for AEN to change device-state */
5699 qla83xx_idc_unlock(base_vha, 0);
5700 msleep(1000);
5701 qla83xx_idc_lock(base_vha, 0);
5702 }
5703 /* reset timeout value after need reset handler */
5704 dev_init_timeout = jiffies +
5705 (ha->fcoe_dev_init_timeout * HZ);
5706 break;
5707 case QLA8XXX_DEV_NEED_QUIESCENT:
5708 /* XXX: DEBUG for now */
5709 qla83xx_idc_unlock(base_vha, 0);
5710 msleep(1000);
5711 qla83xx_idc_lock(base_vha, 0);
5712 break;
5713 case QLA8XXX_DEV_QUIESCENT:
5714 /* XXX: DEBUG for now */
5715 if (ha->flags.quiesce_owner)
5716 goto exit;
5717
5718 qla83xx_idc_unlock(base_vha, 0);
5719 msleep(1000);
5720 qla83xx_idc_lock(base_vha, 0);
5721 dev_init_timeout = jiffies +
5722 (ha->fcoe_dev_init_timeout * HZ);
5723 break;
5724 case QLA8XXX_DEV_FAILED:
5725 if (ha->flags.nic_core_reset_owner)
5726 qla83xx_idc_audit(base_vha,
5727 IDC_AUDIT_COMPLETION);
5728 ha->flags.nic_core_reset_owner = 0;
5729 __qla83xx_clear_drv_presence(base_vha);
5730 qla83xx_idc_unlock(base_vha, 0);
5731 qla8xxx_dev_failed_handler(base_vha);
5732 rval = QLA_FUNCTION_FAILED;
5733 qla83xx_idc_lock(base_vha, 0);
5734 goto exit;
5735 case QLA8XXX_BAD_VALUE:
5736 qla83xx_idc_unlock(base_vha, 0);
5737 msleep(1000);
5738 qla83xx_idc_lock(base_vha, 0);
5739 break;
5740 default:
5741 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09005742 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005743 qla83xx_idc_unlock(base_vha, 0);
5744 qla8xxx_dev_failed_handler(base_vha);
5745 rval = QLA_FUNCTION_FAILED;
5746 qla83xx_idc_lock(base_vha, 0);
5747 goto exit;
5748 }
5749 }
5750
5751exit:
5752 return rval;
5753}
5754
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005755void
5756qla2x00_disable_board_on_pci_error(struct work_struct *work)
5757{
5758 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5759 board_disable);
5760 struct pci_dev *pdev = ha->pdev;
5761 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5762
Quinn Tran726b8542017-01-19 22:28:00 -08005763 /*
5764 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005765 * where it was set first.
5766 */
5767 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5768 return;
5769
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005770 ql_log(ql_log_warn, base_vha, 0x015b,
5771 "Disabling adapter.\n");
5772
Sawan Chandakefdb5762017-08-23 15:05:00 -07005773 if (!atomic_read(&pdev->enable_cnt)) {
5774 ql_log(ql_log_info, base_vha, 0xfffc,
5775 "PCI device disabled, no action req for PCI error=%lx\n",
5776 base_vha->pci_flags);
5777 return;
5778 }
5779
Quinn Tran726b8542017-01-19 22:28:00 -08005780 qla2x00_wait_for_sess_deletion(base_vha);
5781
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005782 set_bit(UNLOADING, &base_vha->dpc_flags);
5783
5784 qla2x00_delete_all_vps(ha, base_vha);
5785
5786 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5787
5788 qla2x00_dfs_remove(base_vha);
5789
5790 qla84xx_put_chip(base_vha);
5791
5792 if (base_vha->timer_active)
5793 qla2x00_stop_timer(base_vha);
5794
5795 base_vha->flags.online = 0;
5796
5797 qla2x00_destroy_deferred_work(ha);
5798
5799 /*
5800 * Do not try to stop beacon blink as it will issue a mailbox
5801 * command.
5802 */
5803 qla2x00_free_sysfs_attr(base_vha, false);
5804
5805 fc_remove_host(base_vha->host);
5806
5807 scsi_remove_host(base_vha->host);
5808
5809 base_vha->flags.init_done = 0;
5810 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005811 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08005812 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005813 qla2x00_mem_free(ha);
5814 qla82xx_md_free(base_vha);
5815 qla2x00_free_queues(ha);
5816
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005817 qla2x00_unmap_iobases(ha);
5818
5819 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005820 pci_disable_pcie_error_reporting(pdev);
5821 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005822
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005823 /*
5824 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5825 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005826}
5827
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828/**************************************************************************
5829* qla2x00_do_dpc
5830* This kernel thread is a task that is schedule by the interrupt handler
5831* to perform the background processing for interrupts.
5832*
5833* Notes:
5834* This task always run in the context of a kernel thread. It
5835* is kick-off by the driver's detect code and starts up
5836* up one per adapter. It immediately goes to sleep and waits for
5837* some fibre event. When either the interrupt handler or
5838* the timer routine detects a event it will one of the task
5839* bits then wake us up.
5840**************************************************************************/
5841static int
5842qla2x00_do_dpc(void *data)
5843{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005844 scsi_qla_host_t *base_vha;
5845 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08005846 uint32_t online;
5847 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005848
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005849 ha = (struct qla_hw_data *)data;
5850 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851
Dongsheng Yang8698a742014-03-11 18:09:12 +08005852 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853
James Bottomley563585e2011-01-27 16:12:37 -05005854 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005855 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005856 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5857 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858
Christoph Hellwig39a11242006-02-14 18:46:22 +01005859 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005861 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5862 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863
Andrew Vasquez85880802009-12-15 21:29:46 -08005864 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005865 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5866 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005867 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005868 }
5869
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 ha->dpc_active = 1;
5871
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005872 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5873 "DPC handler waking up, dpc_flags=0x%lx.\n",
5874 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005876 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5877 break;
5878
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005879 if (IS_P3P_TYPE(ha)) {
5880 if (IS_QLA8044(ha)) {
5881 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5882 &base_vha->dpc_flags)) {
5883 qla8044_idc_lock(ha);
5884 qla8044_wr_direct(base_vha,
5885 QLA8044_CRB_DEV_STATE_INDEX,
5886 QLA8XXX_DEV_FAILED);
5887 qla8044_idc_unlock(ha);
5888 ql_log(ql_log_info, base_vha, 0x4004,
5889 "HW State: FAILED.\n");
5890 qla8044_device_state_handler(base_vha);
5891 continue;
5892 }
5893
5894 } else {
5895 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5896 &base_vha->dpc_flags)) {
5897 qla82xx_idc_lock(ha);
5898 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5899 QLA8XXX_DEV_FAILED);
5900 qla82xx_idc_unlock(ha);
5901 ql_log(ql_log_info, base_vha, 0x0151,
5902 "HW State: FAILED.\n");
5903 qla82xx_device_state_handler(base_vha);
5904 continue;
5905 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005906 }
5907
5908 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5909 &base_vha->dpc_flags)) {
5910
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005911 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
5912 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005913 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
5914 &base_vha->dpc_flags))) {
5915 if (qla82xx_fcoe_ctx_reset(base_vha)) {
5916 /* FCoE-ctx reset failed.
5917 * Escalate to chip-reset
5918 */
5919 set_bit(ISP_ABORT_NEEDED,
5920 &base_vha->dpc_flags);
5921 }
5922 clear_bit(ABORT_ISP_ACTIVE,
5923 &base_vha->dpc_flags);
5924 }
5925
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005926 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
5927 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005928 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005929 } else if (IS_QLAFX00(ha)) {
5930 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5931 &base_vha->dpc_flags)) {
5932 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
5933 "Firmware Reset Recovery\n");
5934 if (qlafx00_reset_initialize(base_vha)) {
5935 /* Failed. Abort isp later. */
5936 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005937 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005938 set_bit(ISP_UNRECOVERABLE,
5939 &base_vha->dpc_flags);
5940 ql_dbg(ql_dbg_dpc, base_vha,
5941 0x4021,
5942 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03005943 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005944 }
5945 }
5946
5947 if (test_and_clear_bit(FX00_TARGET_SCAN,
5948 &base_vha->dpc_flags)) {
5949 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
5950 "ISPFx00 Target Scan scheduled\n");
5951 if (qlafx00_rescan_isp(base_vha)) {
5952 if (!test_bit(UNLOADING,
5953 &base_vha->dpc_flags))
5954 set_bit(ISP_UNRECOVERABLE,
5955 &base_vha->dpc_flags);
5956 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
5957 "ISPFx00 Target Scan Failed\n");
5958 }
5959 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
5960 "ISPFx00 Target Scan End\n");
5961 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04005962 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
5963 &base_vha->dpc_flags)) {
5964 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
5965 "ISPFx00 Host Info resend scheduled\n");
5966 qlafx00_fx_disc(base_vha,
5967 &base_vha->hw->mr.fcport,
5968 FXDISC_REG_HOST_INFO);
5969 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005970 }
5971
Quinn Trane4e3a2c2017-08-23 15:05:07 -07005972 if (test_and_clear_bit(DETECT_SFP_CHANGE,
5973 &base_vha->dpc_flags) &&
5974 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
5975 qla24xx_detect_sfp(base_vha);
5976
5977 if (ha->flags.detected_lr_sfp !=
5978 ha->flags.using_lr_setting)
5979 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
5980 }
5981
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005982 if (test_and_clear_bit(ISP_ABORT_NEEDED,
5983 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005985 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
5986 "ISP abort scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005988 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989
Giridhar Malavalia9083012010-04-12 17:59:55 -07005990 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991 /* failed. retry later */
5992 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005993 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005995 clear_bit(ABORT_ISP_ACTIVE,
5996 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08005997 }
5998
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005999 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6000 "ISP abort end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001 }
6002
David Jefferya394aac2012-11-21 02:39:54 -05006003 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6004 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006005 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006006 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006007
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006008 if (IS_QLAFX00(ha))
6009 goto loop_resync_check;
6010
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006011 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006012 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6013 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006014 if (IS_P3P_TYPE(ha)) {
6015 if (IS_QLA82XX(ha))
6016 qla82xx_device_state_handler(base_vha);
6017 if (IS_QLA8044(ha))
6018 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006019 clear_bit(ISP_QUIESCE_NEEDED,
6020 &base_vha->dpc_flags);
6021 if (!ha->flags.quiesce_owner) {
6022 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006023 if (IS_QLA82XX(ha)) {
6024 qla82xx_idc_lock(ha);
6025 qla82xx_clear_qsnt_ready(
6026 base_vha);
6027 qla82xx_idc_unlock(ha);
6028 } else if (IS_QLA8044(ha)) {
6029 qla8044_idc_lock(ha);
6030 qla8044_clear_qsnt_ready(
6031 base_vha);
6032 qla8044_idc_unlock(ha);
6033 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006034 }
6035 } else {
6036 clear_bit(ISP_QUIESCE_NEEDED,
6037 &base_vha->dpc_flags);
6038 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006039 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006040 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6041 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006042 }
6043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006044 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006045 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006046 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006048 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6049 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006050 qla2x00_rst_aen(base_vha);
6051 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006052 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6053 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054 }
6055
6056 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006057 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006058 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6059 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060
Quinn Tran4005a992017-12-04 14:45:06 -08006061 if (!base_vha->relogin_jif ||
6062 time_after_eq(jiffies, base_vha->relogin_jif)) {
6063 base_vha->relogin_jif = jiffies + HZ;
6064 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6065
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006066 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006067 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006068 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006071loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006072 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006073 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006075 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6076 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077
6078 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006079 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080
Bart Van Assche52c82822015-07-09 07:23:26 -07006081 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006083 clear_bit(LOOP_RESYNC_ACTIVE,
6084 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 }
6086
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006087 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6088 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 }
6090
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006091 if (IS_QLAFX00(ha))
6092 goto intr_on_check;
6093
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006094 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6095 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6096 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6097 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006098 }
6099
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006100intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006102 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006104 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006105 &base_vha->dpc_flags)) {
6106 if (ha->beacon_blink_led == 1)
6107 ha->isp_ops->beacon_blink(base_vha);
6108 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006109
Michael Hernandezd7459522016-12-12 14:40:07 -08006110 /* qpair online check */
6111 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6112 &base_vha->dpc_flags)) {
6113 if (ha->flags.eeh_busy ||
6114 ha->flags.pci_channel_io_perm_failure)
6115 online = 0;
6116 else
6117 online = 1;
6118
6119 mutex_lock(&ha->mq_lock);
6120 list_for_each_entry(qpair, &base_vha->qp_list,
6121 qp_list_elem)
6122 qpair->online = online;
6123 mutex_unlock(&ha->mq_lock);
6124 }
6125
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006126 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED, &base_vha->dpc_flags)) {
6127 ql_log(ql_log_info, base_vha, 0xffffff,
6128 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6129 ha->nvme_last_rptd_aen);
6130 if (qla27xx_set_zio_threshold(base_vha, ha->nvme_last_rptd_aen)) {
6131 ql_log(ql_log_info, base_vha, 0xffffff,
6132 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6133 ha->nvme_last_rptd_aen);
6134 }
6135 }
6136
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006137 if (!IS_QLAFX00(ha))
6138 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006139
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006141end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006142 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006144 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006146 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6147 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148
6149 /*
6150 * Make sure that nobody tries to wake us up again.
6151 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 ha->dpc_active = 0;
6153
Andrew Vasquezac280b62009-08-20 11:06:05 -07006154 /* Cleanup any residual CTX SRBs. */
6155 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6156
Christoph Hellwig39a11242006-02-14 18:46:22 +01006157 return 0;
6158}
6159
6160void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006161qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006162{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006163 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006164 struct task_struct *t = ha->dpc_thread;
6165
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006166 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006167 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006168}
6169
6170/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171* qla2x00_rst_aen
6172* Processes asynchronous reset.
6173*
6174* Input:
6175* ha = adapter block pointer.
6176*/
6177static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006178qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006180 if (vha->flags.online && !vha->flags.reset_active &&
6181 !atomic_read(&vha->loop_down_timer) &&
6182 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006184 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185
6186 /*
6187 * Issue marker command only when we are going to start
6188 * the I/O.
6189 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006190 vha->marker_needed = 1;
6191 } while (!atomic_read(&vha->loop_down_timer) &&
6192 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193 }
6194}
6195
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196/**************************************************************************
6197* qla2x00_timer
6198*
6199* Description:
6200* One second timer
6201*
6202* Context: Interrupt
6203***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006204void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006205qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006207 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 int start_dpc = 0;
6210 int index;
6211 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006212 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006213 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006214 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006215
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006216 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006217 ql_dbg(ql_dbg_timer, vha, 0x6000,
6218 "EEH = %d, restarting timer.\n",
6219 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006220 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6221 return;
6222 }
6223
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006224 /*
6225 * Hardware read to raise pending EEH errors during mailbox waits. If
6226 * the read returns -1 then disable the board.
6227 */
6228 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006229 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006230 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006233 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006234 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006235 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6236 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006237 if (IS_QLA82XX(ha))
6238 qla82xx_watchdog(vha);
6239 else if (IS_QLA8044(ha))
6240 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006241 }
6242
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006243 if (!vha->vp_idx && IS_QLAFX00(ha))
6244 qlafx00_timer_routine(vha);
6245
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006247 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006248 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6249 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006250 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006252 if (atomic_read(&vha->loop_down_timer) ==
6253 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006255 ql_log(ql_log_info, vha, 0x6008,
6256 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006258 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6259 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006261 /*
6262 * Schedule an ISP abort to return any FCP2-device
6263 * commands.
6264 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006265 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006266 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006267 spin_lock_irqsave(&ha->hardware_lock,
6268 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006269 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006270 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006271 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006272 index++) {
6273 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006274
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006275 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006276 if (!sp)
6277 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006278 if (sp->cmd_type != TYPE_SRB)
6279 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006280 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006281 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006282 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006283 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006284 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006286 if (IS_QLA82XX(ha))
6287 set_bit(FCOE_CTX_RESET_NEEDED,
6288 &vha->dpc_flags);
6289 else
6290 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006291 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006292 break;
6293 }
6294 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006295 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297 start_dpc++;
6298 }
6299
6300 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006301 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006302 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006303 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304 "Loop down - aborting ISP.\n");
6305
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006306 if (IS_QLA82XX(ha))
6307 set_bit(FCOE_CTX_RESET_NEEDED,
6308 &vha->dpc_flags);
6309 else
6310 set_bit(ISP_ABORT_NEEDED,
6311 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 }
6313 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006314 ql_dbg(ql_dbg_timer, vha, 0x600a,
6315 "Loop down - seconds remaining %d.\n",
6316 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006318 /* Check if beacon LED needs to be blinked for physical host only */
6319 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006320 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006321 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006322 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6323 start_dpc++;
6324 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006325 }
6326
Andrew Vasquez550bf572008-04-24 15:21:23 -07006327 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006328 if (!list_empty(&vha->work_list)) {
6329 unsigned long flags;
6330 bool q = false;
6331
6332 spin_lock_irqsave(&vha->work_lock, flags);
6333 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6334 q = true;
6335 spin_unlock_irqrestore(&vha->work_lock, flags);
6336 if (q)
6337 queue_work(vha->hw->wq, &vha->iocb_work);
6338 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006339
Duane Grigsby7401bc12017-06-21 13:48:42 -07006340 /*
6341 * FC-NVME
6342 * see if the active AEN count has changed from what was last reported.
6343 */
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006344 if (!vha->vp_idx &&
6345 atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen &&
6346 ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006347 ql_log(ql_log_info, vha, 0x3002,
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006348 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6349 ha->nvme_last_rptd_aen);
6350 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
6351 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6352 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006353 }
6354
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006356 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6357 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6358 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006360 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6361 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006362 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6363 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006364 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006365 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006366 ql_dbg(ql_dbg_timer, vha, 0x600b,
6367 "isp_abort_needed=%d loop_resync_needed=%d "
6368 "fcport_update_needed=%d start_dpc=%d "
6369 "reset_marker_needed=%d",
6370 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6371 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6372 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6373 start_dpc,
6374 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6375 ql_dbg(ql_dbg_timer, vha, 0x600c,
6376 "beacon_blink_needed=%d isp_unrecoverable=%d "
6377 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006378 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006379 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6380 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6381 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6382 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006383 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006384 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006387 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388}
6389
Andrew Vasquez54333832005-11-09 15:49:04 -08006390/* Firmware interface routines. */
6391
Chad Dupuisf73cb692014-02-26 04:15:06 -05006392#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006393#define FW_ISP21XX 0
6394#define FW_ISP22XX 1
6395#define FW_ISP2300 2
6396#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006397#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006398#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006399#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006400#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006401#define FW_ISP2031 8
6402#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006403#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08006404
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006405#define FW_FILE_ISP21XX "ql2100_fw.bin"
6406#define FW_FILE_ISP22XX "ql2200_fw.bin"
6407#define FW_FILE_ISP2300 "ql2300_fw.bin"
6408#define FW_FILE_ISP2322 "ql2322_fw.bin"
6409#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006410#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006411#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006412#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006413#define FW_FILE_ISP2031 "ql2600_fw.bin"
6414#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006415#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006416
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006417
Daniel Walkere1e82b62008-05-12 22:21:10 -07006418static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006419
6420static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006421 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6422 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6423 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6424 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6425 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006426 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006427 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006428 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006429 { .name = FW_FILE_ISP2031, },
6430 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006431 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006432};
6433
6434struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006435qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006436{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006437 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006438 struct fw_blob *blob;
6439
Andrew Vasquez54333832005-11-09 15:49:04 -08006440 if (IS_QLA2100(ha)) {
6441 blob = &qla_fw_blobs[FW_ISP21XX];
6442 } else if (IS_QLA2200(ha)) {
6443 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006444 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006445 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006446 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006447 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006448 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006449 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006450 } else if (IS_QLA25XX(ha)) {
6451 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006452 } else if (IS_QLA81XX(ha)) {
6453 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006454 } else if (IS_QLA82XX(ha)) {
6455 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006456 } else if (IS_QLA2031(ha)) {
6457 blob = &qla_fw_blobs[FW_ISP2031];
6458 } else if (IS_QLA8031(ha)) {
6459 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006460 } else if (IS_QLA27XX(ha)) {
6461 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006462 } else {
6463 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006464 }
6465
Daniel Walkere1e82b62008-05-12 22:21:10 -07006466 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006467 if (blob->fw)
6468 goto out;
6469
6470 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006471 ql_log(ql_log_warn, vha, 0x0063,
6472 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006473 blob->fw = NULL;
6474 blob = NULL;
6475 goto out;
6476 }
6477
6478out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006479 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006480 return blob;
6481}
6482
6483static void
6484qla2x00_release_firmware(void)
6485{
6486 int idx;
6487
Daniel Walkere1e82b62008-05-12 22:21:10 -07006488 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006489 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02006490 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006491 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006492}
6493
Seokmann Ju14e660e2007-09-20 14:07:36 -07006494static pci_ers_result_t
6495qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6496{
Andrew Vasquez85880802009-12-15 21:29:46 -08006497 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6498 struct qla_hw_data *ha = vha->hw;
6499
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006500 ql_dbg(ql_dbg_aer, vha, 0x9000,
6501 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006502
Sawan Chandakefdb5762017-08-23 15:05:00 -07006503 if (!atomic_read(&pdev->enable_cnt)) {
6504 ql_log(ql_log_info, vha, 0xffff,
6505 "PCI device is disabled,state %x\n", state);
6506 return PCI_ERS_RESULT_NEED_RESET;
6507 }
6508
Seokmann Ju14e660e2007-09-20 14:07:36 -07006509 switch (state) {
6510 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006511 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006512 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006513 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6514 qla2xxx_wake_dpc(vha);
6515 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006516 return PCI_ERS_RESULT_CAN_RECOVER;
6517 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006518 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006519 /* For ISP82XX complete any pending mailbox cmd */
6520 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006521 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006522 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6523 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006524 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006525 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006526 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006527 /* Return back all IOs */
6528 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006529 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006530 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6531 qla2xxx_wake_dpc(vha);
6532 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006533 return PCI_ERS_RESULT_NEED_RESET;
6534 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006535 ha->flags.pci_channel_io_perm_failure = 1;
6536 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006537 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006538 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6539 qla2xxx_wake_dpc(vha);
6540 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006541 return PCI_ERS_RESULT_DISCONNECT;
6542 }
6543 return PCI_ERS_RESULT_NEED_RESET;
6544}
6545
6546static pci_ers_result_t
6547qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6548{
6549 int risc_paused = 0;
6550 uint32_t stat;
6551 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006552 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6553 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006554 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6555 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6556
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006557 if (IS_QLA82XX(ha))
6558 return PCI_ERS_RESULT_RECOVERED;
6559
Seokmann Ju14e660e2007-09-20 14:07:36 -07006560 spin_lock_irqsave(&ha->hardware_lock, flags);
6561 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6562 stat = RD_REG_DWORD(&reg->hccr);
6563 if (stat & HCCR_RISC_PAUSE)
6564 risc_paused = 1;
6565 } else if (IS_QLA23XX(ha)) {
6566 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6567 if (stat & HSR_RISC_PAUSED)
6568 risc_paused = 1;
6569 } else if (IS_FWI2_CAPABLE(ha)) {
6570 stat = RD_REG_DWORD(&reg24->host_status);
6571 if (stat & HSRX_RISC_PAUSED)
6572 risc_paused = 1;
6573 }
6574 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6575
6576 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006577 ql_log(ql_log_info, base_vha, 0x9003,
6578 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006579 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006580
6581 return PCI_ERS_RESULT_NEED_RESET;
6582 } else
6583 return PCI_ERS_RESULT_RECOVERED;
6584}
6585
Saurav Kashyapfa492632012-11-21 02:40:29 -05006586static uint32_t
6587qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006588{
6589 uint32_t rval = QLA_FUNCTION_FAILED;
6590 uint32_t drv_active = 0;
6591 struct qla_hw_data *ha = base_vha->hw;
6592 int fn;
6593 struct pci_dev *other_pdev = NULL;
6594
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006595 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6596 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006597
6598 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6599
6600 if (base_vha->flags.online) {
6601 /* Abort all outstanding commands,
6602 * so as to be requeued later */
6603 qla2x00_abort_isp_cleanup(base_vha);
6604 }
6605
6606
6607 fn = PCI_FUNC(ha->pdev->devfn);
6608 while (fn > 0) {
6609 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006610 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6611 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006612 other_pdev =
6613 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6614 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6615 fn));
6616
6617 if (!other_pdev)
6618 continue;
6619 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006620 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6621 "Found PCI func available and enable at 0x%x.\n",
6622 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006623 pci_dev_put(other_pdev);
6624 break;
6625 }
6626 pci_dev_put(other_pdev);
6627 }
6628
6629 if (!fn) {
6630 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006631 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6632 "This devfn is reset owner = 0x%x.\n",
6633 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006634 qla82xx_idc_lock(ha);
6635
6636 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006637 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006638
6639 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6640 QLA82XX_IDC_VERSION);
6641
6642 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006643 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6644 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006645
6646 qla82xx_idc_unlock(ha);
6647 /* Reset if device is not already reset
6648 * drv_active would be 0 if a reset has already been done
6649 */
6650 if (drv_active)
6651 rval = qla82xx_start_firmware(base_vha);
6652 else
6653 rval = QLA_SUCCESS;
6654 qla82xx_idc_lock(ha);
6655
6656 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006657 ql_log(ql_log_info, base_vha, 0x900b,
6658 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006659 qla82xx_clear_drv_active(ha);
6660 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006661 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006662 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006663 ql_log(ql_log_info, base_vha, 0x900c,
6664 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006665 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006666 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006667 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08006668 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006669 rval = qla82xx_restart_isp(base_vha);
6670 qla82xx_idc_lock(ha);
6671 /* Clear driver state register */
6672 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6673 qla82xx_set_drv_active(base_vha);
6674 }
6675 qla82xx_idc_unlock(ha);
6676 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006677 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6678 "This devfn is not reset owner = 0x%x.\n",
6679 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006680 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006681 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006682 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006683 rval = qla82xx_restart_isp(base_vha);
6684 qla82xx_idc_lock(ha);
6685 qla82xx_set_drv_active(base_vha);
6686 qla82xx_idc_unlock(ha);
6687 }
6688 }
6689 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6690
6691 return rval;
6692}
6693
Seokmann Ju14e660e2007-09-20 14:07:36 -07006694static pci_ers_result_t
6695qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6696{
6697 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006698 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6699 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006700 struct rsp_que *rsp;
6701 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006702
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006703 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6704 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006705
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006706 /* Workaround: qla2xxx driver which access hardware earlier
6707 * needs error state to be pci_channel_io_online.
6708 * Otherwise mailbox command timesout.
6709 */
6710 pdev->error_state = pci_channel_io_normal;
6711
6712 pci_restore_state(pdev);
6713
Richard Lary8c1496b2010-02-18 10:07:29 -08006714 /* pci_restore_state() clears the saved_state flag of the device
6715 * save restored state which resets saved_state flag
6716 */
6717 pci_save_state(pdev);
6718
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11006719 if (ha->mem_only)
6720 rc = pci_enable_device_mem(pdev);
6721 else
6722 rc = pci_enable_device(pdev);
6723
6724 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006725 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006726 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006727 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006728 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006729
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006730 rsp = ha->rsp_q_map[0];
6731 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006732 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006734 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006735 goto exit_slot_reset;
6736
6737 if (IS_QLA82XX(ha)) {
6738 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6739 ret = PCI_ERS_RESULT_RECOVERED;
6740 goto exit_slot_reset;
6741 } else
6742 goto exit_slot_reset;
6743 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006744
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006745 while (ha->flags.mbox_busy && retries--)
6746 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08006747
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006748 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006749 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07006750 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006751 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006752
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006753
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006754exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006755 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6756 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08006757
Seokmann Ju14e660e2007-09-20 14:07:36 -07006758 return ret;
6759}
6760
6761static void
6762qla2xxx_pci_resume(struct pci_dev *pdev)
6763{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006764 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6765 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006766 int ret;
6767
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006768 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6769 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006770
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006771 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006772 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006773 ql_log(ql_log_fatal, base_vha, 0x9002,
6774 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07006775 }
Andrew Vasquez85880802009-12-15 21:29:46 -08006776
Lalit Chandivade3e46f032010-05-04 15:01:23 -07006777 pci_cleanup_aer_uncorrect_error_status(pdev);
6778
Andrew Vasquez85880802009-12-15 21:29:46 -08006779 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006780}
6781
Michael Hernandez56012362016-12-12 14:40:08 -08006782static int qla2xxx_map_queues(struct Scsi_Host *shost)
6783{
Quinn Trand68b8502017-12-04 14:44:59 -08006784 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006785 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6786
Quinn Trand68b8502017-12-04 14:44:59 -08006787 if (USER_CTRL_IRQ(vha->hw))
6788 rc = blk_mq_map_queues(&shost->tag_set);
6789 else
6790 rc = blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev);
6791 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006792}
6793
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07006794static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07006795 .error_detected = qla2xxx_pci_error_detected,
6796 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6797 .slot_reset = qla2xxx_pci_slot_reset,
6798 .resume = qla2xxx_pci_resume,
6799};
6800
Andrew Vasquez54333832005-11-09 15:49:04 -08006801static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006802 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6803 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6804 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6805 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6806 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6807 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6808 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6809 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6810 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006811 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006812 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6813 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006814 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006815 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006816 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006817 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006818 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006819 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006820 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006821 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006822 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006823 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006824 { 0 },
6825};
6826MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6827
Andrew Vasquezfca29702005-07-06 10:31:47 -07006828static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006829 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006830 .driver = {
6831 .owner = THIS_MODULE,
6832 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006833 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006834 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08006835 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07006836 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006837 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07006838};
6839
Al Viro75ef9de2013-04-04 19:09:41 -04006840static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006841 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02006842 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006843};
6844
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845/**
6846 * qla2x00_module_init - Module initialization.
6847 **/
6848static int __init
6849qla2x00_module_init(void)
6850{
Andrew Vasquezfca29702005-07-06 10:31:47 -07006851 int ret = 0;
6852
Linus Torvalds1da177e2005-04-16 15:20:36 -07006853 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006854 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09006855 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006856 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006857 ql_log(ql_log_fatal, NULL, 0x0001,
6858 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859 return -ENOMEM;
6860 }
6861
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006862 /* Initialize target kmem_cache and mem_pools */
6863 ret = qlt_init();
6864 if (ret < 0) {
6865 kmem_cache_destroy(srb_cachep);
6866 return ret;
6867 } else if (ret > 0) {
6868 /*
6869 * If initiator mode is explictly disabled by qlt_init(),
6870 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
6871 * performing scsi_scan_target() during LOOP UP event.
6872 */
6873 qla2xxx_transport_functions.disable_target_scan = 1;
6874 qla2xxx_transport_vport_functions.disable_target_scan = 1;
6875 }
6876
Linus Torvalds1da177e2005-04-16 15:20:36 -07006877 /* Derive version string. */
6878 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07006879 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07006880 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07006881 if (ql2xextended_error_logging == 1)
6882 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07006883
Andrew Vasquez1c97a122005-04-21 16:13:36 -04006884 qla2xxx_transport_template =
6885 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006886 if (!qla2xxx_transport_template) {
6887 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006888 ql_log(ql_log_fatal, NULL, 0x0002,
6889 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006890 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006891 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006892 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006893
6894 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
6895 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006896 ql_log(ql_log_fatal, NULL, 0x0003,
6897 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006898 }
6899
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006900 qla2xxx_transport_vport_template =
6901 fc_attach_transport(&qla2xxx_transport_vport_functions);
6902 if (!qla2xxx_transport_vport_template) {
6903 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006904 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006905 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006906 ql_log(ql_log_fatal, NULL, 0x0004,
6907 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006908 return -ENODEV;
6909 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006910 ql_log(ql_log_info, NULL, 0x0005,
6911 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07006912 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006913 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006914 if (ret) {
6915 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006916 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07006917 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006918 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006919 ql_log(ql_log_fatal, NULL, 0x0006,
6920 "pci_register_driver failed...ret=%d Failing load!.\n",
6921 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07006922 }
6923 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924}
6925
6926/**
6927 * qla2x00_module_exit - Module cleanup.
6928 **/
6929static void __exit
6930qla2x00_module_exit(void)
6931{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006932 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006933 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08006934 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006935 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006936 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07006937 if (ctx_cachep)
6938 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006939 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006940 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006941}
6942
6943module_init(qla2x00_module_init);
6944module_exit(qla2x00_module_exit);
6945
6946MODULE_AUTHOR("QLogic Corporation");
6947MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
6948MODULE_LICENSE("GPL");
6949MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006950MODULE_FIRMWARE(FW_FILE_ISP21XX);
6951MODULE_FIRMWARE(FW_FILE_ISP22XX);
6952MODULE_FIRMWARE(FW_FILE_ISP2300);
6953MODULE_FIRMWARE(FW_FILE_ISP2322);
6954MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08006955MODULE_FIRMWARE(FW_FILE_ISP25XX);