blob: b8b7415bc59d0abf2bbd5ef0c107382fb1993404 [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
Quinn Tran45235022018-07-18 14:29:53 -0700306
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700307struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700309 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700310 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700311
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100312 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700313 .eh_abort_handler = qla2xxx_eh_abort,
314 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700315 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700316 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
317 .eh_host_reset_handler = qla2xxx_eh_host_reset,
318
319 .slave_configure = qla2xxx_slave_configure,
320
321 .slave_alloc = qla2xxx_slave_alloc,
322 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700323 .scan_finished = qla2xxx_scan_finished,
324 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100325 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800326 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700327 .this_id = -1,
328 .cmd_per_lun = 3,
329 .use_clustering = ENABLE_CLUSTERING,
330 .sg_tablesize = SG_ALL,
331
332 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700333 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400334
335 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100336 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700337};
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700340struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342/* TODO Convert to inlines
343 *
344 * Timer routines
345 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700347__inline__ void
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700348qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700350 timer_setup(&vha->timer, qla2x00_timer, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800351 vha->timer.expires = jiffies + interval * HZ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800352 add_timer(&vha->timer);
353 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
356static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800357qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700359 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700360 if (vha->device_flags & DFLG_DEV_FAILED) {
361 ql_dbg(ql_dbg_timer, vha, 0x600d,
362 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700363 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700364 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700365
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800366 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
368
Adrian Bunka824ebb2008-01-17 09:02:15 -0800369static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800370qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800372 del_timer_sync(&vha->timer);
373 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374}
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376static int qla2x00_do_dpc(void *data);
377
378static void qla2x00_rst_aen(scsi_qla_host_t *);
379
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800380static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
381 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700382static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800383static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800384int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
385 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700388static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
389 struct rsp_que *rsp)
390{
391 struct qla_hw_data *ha = vha->hw;
392 rsp->qpair = ha->base_qpair;
393 rsp->req = req;
Quinn Tran06910942018-09-04 14:19:12 -0700394 ha->base_qpair->hw = ha;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700395 ha->base_qpair->req = req;
396 ha->base_qpair->rsp = rsp;
397 ha->base_qpair->vha = vha;
398 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
399 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
400 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
Quinn Tran6a629462018-09-04 14:19:15 -0700401 ha->base_qpair->srb_mempool = ha->srb_mempool;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700402 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
403 ha->base_qpair->enable_class_2 = ql2xenableclass2;
404 /* init qpair to this cpu. Will adjust at run time. */
Bart Van Assche86531882017-11-06 11:59:05 -0800405 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700406 ha->base_qpair->pdev = ha->pdev;
407
408 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
409 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
410}
411
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400412static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
413 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800414{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700415 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Kees Cook6396bb22018-06-12 14:03:40 -0700416 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800417 GFP_KERNEL);
418 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700419 ql_log(ql_log_fatal, vha, 0x003b,
420 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800421 goto fail_req_map;
422 }
423
Kees Cook6396bb22018-06-12 14:03:40 -0700424 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800425 GFP_KERNEL);
426 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700427 ql_log(ql_log_fatal, vha, 0x003c,
428 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800429 goto fail_rsp_map;
430 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800431
Quinn Trane326d222017-06-13 20:47:18 -0700432 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
433 if (ha->base_qpair == NULL) {
434 ql_log(ql_log_warn, vha, 0x00e0,
435 "Failed to allocate base queue pair memory.\n");
436 goto fail_base_qpair;
437 }
438
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700439 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700440
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -0700441 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -0800442 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
443 GFP_KERNEL);
444 if (!ha->queue_pair_map) {
445 ql_log(ql_log_fatal, vha, 0x0180,
446 "Unable to allocate memory for queue pair ptrs.\n");
447 goto fail_qpair_map;
448 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800449 }
450
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400451 /*
452 * Make sure we record at least the request and response queue zero in
453 * case we need to free them if part of the probe fails.
454 */
455 ha->rsp_q_map[0] = rsp;
456 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800457 set_bit(0, ha->rsp_qid_map);
458 set_bit(0, ha->req_qid_map);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -0500459 return 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800460
Michael Hernandezd7459522016-12-12 14:40:07 -0800461fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700462 kfree(ha->base_qpair);
463 ha->base_qpair = NULL;
464fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800465 kfree(ha->rsp_q_map);
466 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800467fail_rsp_map:
468 kfree(ha->req_q_map);
469 ha->req_q_map = NULL;
470fail_req_map:
471 return -ENOMEM;
472}
473
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700474static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800475{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400476 if (IS_QLAFX00(ha)) {
477 if (req && req->ring_fx00)
478 dma_free_coherent(&ha->pdev->dev,
479 (req->length_fx00 + 1) * sizeof(request_t),
480 req->ring_fx00, req->dma_fx00);
481 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800482 dma_free_coherent(&ha->pdev->dev,
483 (req->length + 1) * sizeof(request_t),
484 req->ring, req->dma);
485
Bill Kuzeja6d634062018-03-23 10:37:25 -0400486 if (req)
Chad Dupuis8d93f552013-01-30 03:34:37 -0500487 kfree(req->outstanding_cmds);
Bill Kuzeja6d634062018-03-23 10:37:25 -0400488
489 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800490}
491
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700492static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
493{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400494 if (IS_QLAFX00(ha)) {
Meelis Roos3f6c9be2018-03-08 15:44:37 +0200495 if (rsp && rsp->ring_fx00)
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400496 dma_free_coherent(&ha->pdev->dev,
497 (rsp->length_fx00 + 1) * sizeof(request_t),
498 rsp->ring_fx00, rsp->dma_fx00);
499 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700500 dma_free_coherent(&ha->pdev->dev,
501 (rsp->length + 1) * sizeof(response_t),
502 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400503 }
Bill Kuzeja6d634062018-03-23 10:37:25 -0400504 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700505}
506
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800507static void qla2x00_free_queues(struct qla_hw_data *ha)
508{
509 struct req_que *req;
510 struct rsp_que *rsp;
511 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800512 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800513
Quinn Tran82de8022017-06-13 20:47:17 -0700514 if (ha->queue_pair_map) {
515 kfree(ha->queue_pair_map);
516 ha->queue_pair_map = NULL;
517 }
518 if (ha->base_qpair) {
519 kfree(ha->base_qpair);
520 ha->base_qpair = NULL;
521 }
522
Quinn Tran093df732016-12-12 14:40:09 -0800523 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700524 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500525 if (!test_bit(cnt, ha->req_qid_map))
526 continue;
527
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800528 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800529 clear_bit(cnt, ha->req_qid_map);
530 ha->req_q_map[cnt] = NULL;
531
532 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700533 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800534 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700535 }
Quinn Tran093df732016-12-12 14:40:09 -0800536 spin_unlock_irqrestore(&ha->hardware_lock, flags);
537
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700538 kfree(ha->req_q_map);
539 ha->req_q_map = NULL;
540
Quinn Tran093df732016-12-12 14:40:09 -0800541
542 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700543 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500544 if (!test_bit(cnt, ha->rsp_qid_map))
545 continue;
546
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700547 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c42392016-12-27 13:13:21 -0500548 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800549 ha->rsp_q_map[cnt] = NULL;
550 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700551 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800552 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800553 }
Quinn Tran093df732016-12-12 14:40:09 -0800554 spin_unlock_irqrestore(&ha->hardware_lock, flags);
555
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800556 kfree(ha->rsp_q_map);
557 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800558}
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800561qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 static char *pci_bus_modes[] = {
565 "33", "66", "100", "133",
566 };
567 uint16_t pci_bus;
568
569 strcpy(str, "PCI");
570 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
571 if (pci_bus) {
572 strcat(str, "-X (");
573 strcat(str, pci_bus_modes[pci_bus]);
574 } else {
575 pci_bus = (ha->pci_attr & BIT_8) >> 8;
576 strcat(str, " (");
577 strcat(str, pci_bus_modes[pci_bus]);
578 }
579 strcat(str, " MHz)");
580
581 return (str);
582}
583
Andrew Vasquezfca29702005-07-06 10:31:47 -0700584static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700586{
587 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800588 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700589 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700590
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600591 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700592 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600593 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700594
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600595 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
596 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
597 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700598
599 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500600 switch (lspeed) {
601 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700602 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500603 break;
604 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700605 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500606 break;
607 case 3:
608 strcat(str, "8.0GT/s ");
609 break;
610 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700611 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500612 break;
613 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700614 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
615 strcat(str, lwstr);
616
617 return str;
618 }
619
620 strcpy(str, "PCI");
621 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
622 if (pci_bus == 0 || pci_bus == 8) {
623 strcat(str, " (");
624 strcat(str, pci_bus_modes[pci_bus >> 3]);
625 } else {
626 strcat(str, "-X ");
627 if (pci_bus & BIT_2)
628 strcat(str, "Mode 2");
629 else
630 strcat(str, "Mode 1");
631 strcat(str, " (");
632 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
633 }
634 strcat(str, " MHz)");
635
636 return str;
637}
638
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800639static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400640qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
642 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800643 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700644
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400645 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
646 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 if (ha->fw_attributes & BIT_9) {
649 strcat(str, "FLX");
650 return (str);
651 }
652
653 switch (ha->fw_attributes & 0xFF) {
654 case 0x7:
655 strcat(str, "EF");
656 break;
657 case 0x17:
658 strcat(str, "TP");
659 break;
660 case 0x37:
661 strcat(str, "IP");
662 break;
663 case 0x77:
664 strcat(str, "VI");
665 break;
666 default:
667 sprintf(un_str, "(%x)", ha->fw_attributes);
668 strcat(str, un_str);
669 break;
670 }
671 if (ha->fw_attributes & 0x100)
672 strcat(str, "X");
673
674 return (str);
675}
676
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800677static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400678qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700679{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800680 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700681
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400682 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800683 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700684 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700685}
686
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800687void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800688qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700689{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800690 srb_t *sp = ptr;
691 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800692 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800693 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700694
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800695 if (sp->flags & SRB_DMA_VALID) {
696 scsi_dma_unmap(cmd);
697 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700698 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700699
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800700 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
701 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
702 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
703 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
704 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700705
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700706 if (!ctx)
707 goto end;
708
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800709 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
710 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700711 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800712 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
713 }
714
715 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700716 struct crc_context *ctx0 = ctx;
717
718 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800719 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
720 }
721
722 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700723 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800724
725 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700726 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800727 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
728 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
729 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
730 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800731 }
732
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700733end:
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -0700734 if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) {
Duane Grigsby7401bc12017-06-21 13:48:42 -0700735 CMD_SP(cmd) = NULL;
736 qla2x00_rel_sp(sp);
737 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800738}
739
Michael Hernandezd7459522016-12-12 14:40:07 -0800740void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800741qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800742{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800743 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800744 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
745
746 cmd->result = res;
747
748 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800749 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800750 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
751 sp, GET_CMD_SP(sp));
752 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400753 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800754 return;
755 }
756 if (!atomic_dec_and_test(&sp->ref_count))
757 return;
758
Joe Carnucciof3caa992017-08-23 15:05:09 -0700759 sp->free(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800760 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700761}
762
Michael Hernandezd7459522016-12-12 14:40:07 -0800763void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800764qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800765{
766 srb_t *sp = (srb_t *)ptr;
767 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
768 struct qla_hw_data *ha = sp->fcport->vha->hw;
769 void *ctx = GET_CMD_CTX_SP(sp);
770
771 if (sp->flags & SRB_DMA_VALID) {
772 scsi_dma_unmap(cmd);
773 sp->flags &= ~SRB_DMA_VALID;
774 }
775
776 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
777 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
778 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
779 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
780 }
781
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700782 if (!ctx)
783 goto end;
784
Michael Hernandezd7459522016-12-12 14:40:07 -0800785 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
786 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700787 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800788 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
789 }
790
791 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700792 struct crc_context *ctx0 = ctx;
793
794 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800795 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
796 }
797
798 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700799 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800800 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
801 ctx1->fcp_cmnd_dma);
802 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
803 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
804 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
805 mempool_free(ctx1, ha->ctx_mempool);
806 }
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700807end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800808 CMD_SP(cmd) = NULL;
809 qla2xxx_rel_qpair_sp(sp->qpair, sp);
810}
811
812void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800813qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800814{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800815 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800816 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
817
818 cmd->result = res;
819
820 if (atomic_read(&sp->ref_count) == 0) {
821 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
822 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
823 sp, GET_CMD_SP(sp));
824 if (ql2xextended_error_logging & ql_dbg_io)
825 WARN_ON(atomic_read(&sp->ref_count) == 0);
826 return;
827 }
828 if (!atomic_dec_and_test(&sp->ref_count))
829 return;
830
Joe Carnucciof3caa992017-08-23 15:05:09 -0700831 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800832 cmd->scsi_done(cmd);
833}
834
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400835/* If we are SP1 here, we need to still take and release the host_lock as SP1
836 * does not have the changes necessary to avoid taking host->host_lock.
837 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800839qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700840{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700841 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700842 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400843 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800844 struct qla_hw_data *ha = vha->hw;
845 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700846 srb_t *sp;
847 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800848 struct qla_qpair *qpair = NULL;
849 uint32_t tag;
850 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700851
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200852 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
853 cmd->result = DID_NO_CONNECT << 16;
854 goto qc24_fail_command;
855 }
856
Michael Hernandez56012362016-12-12 14:40:08 -0800857 if (ha->mqenable) {
858 if (shost_use_blk_mq(vha->host)) {
859 tag = blk_mq_unique_tag(cmd->request);
860 hwq = blk_mq_unique_tag_to_hwq(tag);
861 qpair = ha->queue_pair_map[hwq];
862 } else if (vha->vp_idx && vha->qpair) {
863 qpair = vha->qpair;
864 }
865
866 if (qpair)
867 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800868 }
869
Andrew Vasquez85880802009-12-15 21:29:46 -0800870 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700871 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400872 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700873 "PCI Channel IO permanent failure, exiting "
874 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700875 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700876 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400877 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700878 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800879 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700880 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700881 goto qc24_fail_command;
882 }
883
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400884 rval = fc_remote_port_chkready(rport);
885 if (rval) {
886 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400887 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700888 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
889 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700890 goto qc24_fail_command;
891 }
892
Arun Easibad75002010-05-04 15:01:30 -0700893 if (!vha->flags.difdix_supported &&
894 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700895 ql_dbg(ql_dbg_io, vha, 0x3004,
896 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
897 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700898 cmd->result = DID_NO_CONNECT << 16;
899 goto qc24_fail_command;
900 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800901
902 if (!fcport) {
903 cmd->result = DID_NO_CONNECT << 16;
904 goto qc24_fail_command;
905 }
906
Andrew Vasquezfca29702005-07-06 10:31:47 -0700907 if (atomic_read(&fcport->state) != FCS_ONLINE) {
908 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700909 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700910 ql_dbg(ql_dbg_io, vha, 0x3005,
911 "Returning DNC, fcport_state=%d loop_state=%d.\n",
912 atomic_read(&fcport->state),
913 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700914 cmd->result = DID_NO_CONNECT << 16;
915 goto qc24_fail_command;
916 }
Mike Christie7b594132008-08-17 15:24:40 -0500917 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700918 }
919
Chad Dupuise05fe292014-09-25 05:16:59 -0400920 /*
921 * Return target busy if we've received a non-zero retry_delay_timer
922 * in a FCP_RSP.
923 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100924 if (fcport->retry_delay_timestamp == 0) {
925 /* retry delay not set */
926 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400927 fcport->retry_delay_timestamp = 0;
928 else
929 goto qc24_target_busy;
930
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500931 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400932 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800933 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700934
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800935 sp->u.scmd.cmd = cmd;
936 sp->type = SRB_SCSI_CMD;
937 atomic_set(&sp->ref_count, 1);
938 CMD_SP(cmd) = (void *)sp;
939 sp->free = qla2x00_sp_free_dma;
940 sp->done = qla2x00_sp_compl;
941
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800942 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700943 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500944 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700945 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700946 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700947 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700948
Andrew Vasquezfca29702005-07-06 10:31:47 -0700949 return 0;
950
951qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700952 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700953
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800954qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700955 return SCSI_MLQUEUE_HOST_BUSY;
956
Mike Christie7b594132008-08-17 15:24:40 -0500957qc24_target_busy:
958 return SCSI_MLQUEUE_TARGET_BUSY;
959
Andrew Vasquezfca29702005-07-06 10:31:47 -0700960qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800961 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700962
963 return 0;
964}
965
Michael Hernandezd7459522016-12-12 14:40:07 -0800966/* For MQ supported I/O */
967int
968qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
969 struct qla_qpair *qpair)
970{
971 scsi_qla_host_t *vha = shost_priv(host);
972 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
973 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
974 struct qla_hw_data *ha = vha->hw;
975 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
976 srb_t *sp;
977 int rval;
978
979 rval = fc_remote_port_chkready(rport);
980 if (rval) {
981 cmd->result = rval;
982 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
983 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
984 cmd, rval);
985 goto qc24_fail_command;
986 }
987
988 if (!fcport) {
989 cmd->result = DID_NO_CONNECT << 16;
990 goto qc24_fail_command;
991 }
992
993 if (atomic_read(&fcport->state) != FCS_ONLINE) {
994 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
995 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
996 ql_dbg(ql_dbg_io, vha, 0x3077,
997 "Returning DNC, fcport_state=%d loop_state=%d.\n",
998 atomic_read(&fcport->state),
999 atomic_read(&base_vha->loop_state));
1000 cmd->result = DID_NO_CONNECT << 16;
1001 goto qc24_fail_command;
1002 }
1003 goto qc24_target_busy;
1004 }
1005
1006 /*
1007 * Return target busy if we've received a non-zero retry_delay_timer
1008 * in a FCP_RSP.
1009 */
1010 if (fcport->retry_delay_timestamp == 0) {
1011 /* retry delay not set */
1012 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1013 fcport->retry_delay_timestamp = 0;
1014 else
1015 goto qc24_target_busy;
1016
Quinn Tran6a629462018-09-04 14:19:15 -07001017 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
Michael Hernandezd7459522016-12-12 14:40:07 -08001018 if (!sp)
1019 goto qc24_host_busy;
1020
1021 sp->u.scmd.cmd = cmd;
1022 sp->type = SRB_SCSI_CMD;
1023 atomic_set(&sp->ref_count, 1);
1024 CMD_SP(cmd) = (void *)sp;
1025 sp->free = qla2xxx_qpair_sp_free_dma;
1026 sp->done = qla2xxx_qpair_sp_compl;
1027 sp->qpair = qpair;
1028
1029 rval = ha->isp_ops->start_scsi_mq(sp);
1030 if (rval != QLA_SUCCESS) {
1031 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1032 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1033 if (rval == QLA_INTERFACE_ERROR)
1034 goto qc24_fail_command;
1035 goto qc24_host_busy_free_sp;
1036 }
1037
1038 return 0;
1039
1040qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001041 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001042
1043qc24_host_busy:
1044 return SCSI_MLQUEUE_HOST_BUSY;
1045
1046qc24_target_busy:
1047 return SCSI_MLQUEUE_TARGET_BUSY;
1048
1049qc24_fail_command:
1050 cmd->scsi_done(cmd);
1051
1052 return 0;
1053}
1054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055/*
1056 * qla2x00_eh_wait_on_command
1057 * Waits for the command to be returned by the Firmware for some
1058 * max time.
1059 *
1060 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 *
1063 * Return:
1064 * Not Found : 0
1065 * Found : 1
1066 */
1067static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001068qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001070#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001071#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001072 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001073 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1074 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001075 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Andrew Vasquez85880802009-12-15 21:29:46 -08001077 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001078 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1079 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001080 return ret;
1081 }
1082
Lalit Chandivaded9704322009-08-25 11:36:18 -07001083 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001084 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001085 }
1086 if (CMD_SP(cmd))
1087 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
f4f051e2005-04-17 15:02:26 -05001089 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090}
1091
1092/*
1093 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001094 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 * <= MAX_RETRIES_OF_ISP_ABORT or
1096 * finally HBA is disabled ie marked offline
1097 *
1098 * Input:
1099 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001100 *
1101 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 * Does context switching-Release SPIN_LOCK
1103 * (if any) before calling this routine.
1104 *
1105 * Return:
1106 * Success (Adapter is online) : 0
1107 * Failed (Adapter is offline/disabled) : 1
1108 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001109int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001110qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001112 int return_status;
1113 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001114 struct qla_hw_data *ha = vha->hw;
1115 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001117 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001118 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1119 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1120 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1121 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 msleep(1000);
1124 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001125 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001126 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 else
1128 return_status = QLA_FUNCTION_FAILED;
1129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 return (return_status);
1131}
1132
Quinn Tran726b8542017-01-19 22:28:00 -08001133static inline int test_fcport_count(scsi_qla_host_t *vha)
1134{
1135 struct qla_hw_data *ha = vha->hw;
1136 unsigned long flags;
1137 int res;
1138
1139 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001140 ql_dbg(ql_dbg_init, vha, 0x00ec,
1141 "tgt %p, fcport_count=%d\n",
1142 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001143 res = (vha->fcport_count == 0);
1144 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1145
1146 return res;
1147}
1148
1149/*
1150 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1151 * it has dependency on UNLOADING flag to stop device discovery
1152 */
Quinn Tranefa93f42018-07-18 14:29:52 -07001153void
Quinn Tran726b8542017-01-19 22:28:00 -08001154qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1155{
1156 qla2x00_mark_all_devices_lost(vha, 0);
1157
Joe Carnucciob85e0952017-08-23 15:05:11 -07001158 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001159}
1160
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001161/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001162 * qla2x00_wait_for_hba_ready
1163 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001164 *
1165 * Input:
1166 * ha - pointer to host adapter structure
1167 *
1168 * Note:
1169 * Does context switching-Release SPIN_LOCK
1170 * (if any) before calling this routine.
1171 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001172 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001173static void
1174qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001175{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001176 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001177 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001178
Dan Carpenter1d483902016-08-03 21:42:32 +03001179 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1180 ha->flags.mbox_busy) ||
1181 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1182 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1183 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1184 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001185 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001186 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001187}
1188
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001189int
1190qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1191{
1192 int return_status;
1193 unsigned long wait_reset;
1194 struct qla_hw_data *ha = vha->hw;
1195 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1196
1197 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1198 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1199 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1200 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1201 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1202
1203 msleep(1000);
1204
1205 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1206 ha->flags.chip_reset_done)
1207 break;
1208 }
1209 if (ha->flags.chip_reset_done)
1210 return_status = QLA_SUCCESS;
1211 else
1212 return_status = QLA_FUNCTION_FAILED;
1213
1214 return return_status;
1215}
1216
Giridhar Malavali083a4692010-05-28 15:08:18 -07001217static void
1218sp_get(struct srb *sp)
1219{
1220 atomic_inc(&sp->ref_count);
1221}
1222
Sawan Chandaka4655372016-07-06 11:14:32 -04001223#define ISP_REG_DISCONNECT 0xffffffffU
1224/**************************************************************************
1225* qla2x00_isp_reg_stat
1226*
1227* Description:
1228* Read the host status register of ISP before aborting the command.
1229*
1230* Input:
1231* ha = pointer to host adapter structure.
1232*
1233*
1234* Returns:
1235* Either true or false.
1236*
1237* Note: Return true if there is register disconnect.
1238**************************************************************************/
1239static inline
1240uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1241{
1242 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001243 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001244
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001245 if (IS_P3P_TYPE(ha))
1246 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1247 else
1248 return ((RD_REG_DWORD(&reg->host_status)) ==
1249 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001250}
1251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252/**************************************************************************
1253* qla2xxx_eh_abort
1254*
1255* Description:
1256* The abort function will abort the specified command.
1257*
1258* Input:
1259* cmd = Linux SCSI command packet to be aborted.
1260*
1261* Returns:
1262* Either SUCCESS or FAILED.
1263*
1264* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001265* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001267static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1269{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001270 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001271 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001272 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001273 unsigned int id;
1274 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001275 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001276 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001277 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Sawan Chandaka4655372016-07-06 11:14:32 -04001279 if (qla2x00_isp_reg_stat(ha)) {
1280 ql_log(ql_log_info, vha, 0x8042,
1281 "PCI/Register disconnect, exiting.\n");
1282 return FAILED;
1283 }
f4f051e2005-04-17 15:02:26 -05001284 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -07001285 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001287 ret = fc_block_scsi_eh(cmd);
1288 if (ret != 0)
1289 return ret;
1290 ret = SUCCESS;
1291
f4f051e2005-04-17 15:02:26 -05001292 id = cmd->device->id;
1293 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001294
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001295 spin_lock_irqsave(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001296 sp = (srb_t *) CMD_SP(cmd);
1297 if (!sp) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001298 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001299 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001300 }
Mike Christie170babc2010-10-15 11:27:47 -07001301
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001302 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001303 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1304 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001305
1306 /* Get a reference to the sp and drop the lock.*/
1307 sp_get(sp);
1308
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001309 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001310 rval = ha->isp_ops->abort_command(sp);
1311 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001312 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001313 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001314 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001315 ret = FAILED;
1316
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001317 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001318 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001319 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001320 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001321 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001322 wait = 1;
1323 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001324
1325 spin_lock_irqsave(&ha->hardware_lock, flags);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001326 sp->done(sp, 0);
Saurav Kashyap75942062011-08-16 11:29:25 -07001327 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -05001328
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001329 /* Did the command return during mailbox execution? */
1330 if (ret == FAILED && !CMD_SP(cmd))
1331 ret = SUCCESS;
1332
f4f051e2005-04-17 15:02:26 -05001333 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001334 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001335 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001336 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001337 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001338 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001342 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001343 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001344 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
f4f051e2005-04-17 15:02:26 -05001346 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001349int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001350qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001351 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001353 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001354 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001355 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001356 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001357 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001358 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
Andrew Vasquez523ec772008-04-03 13:13:24 -07001360 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001361
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001362 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001363 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001364 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001365 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001366 sp = req->outstanding_cmds[cnt];
1367 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001368 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001369 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001370 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001371 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001372 continue;
1373 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001374 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001375 switch (type) {
1376 case WAIT_HOST:
1377 match = 1;
1378 break;
1379 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001380 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001381 break;
1382 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001383 match = (cmd->device->id == t &&
1384 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001385 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001387 if (!match)
1388 continue;
1389
1390 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001391 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001392 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001394 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001395
1396 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397}
1398
Andrew Vasquez523ec772008-04-03 13:13:24 -07001399static char *reset_errors[] = {
1400 "HBA not online",
1401 "HBA not ready",
1402 "Task management failed",
1403 "Waiting for command completions",
1404};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Andrew Vasquez523ec772008-04-03 13:13:24 -07001406static int
1407__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001408 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001409{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001410 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001411 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1412 int err;
1413
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001414 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001415 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001416 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001417
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001418 err = fc_block_scsi_eh(cmd);
1419 if (err != 0)
1420 return err;
1421
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001422 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001423 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001424 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001425
1426 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001427 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1428 ql_log(ql_log_warn, vha, 0x800a,
1429 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001430 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001431 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001432 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001433 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001434 != QLA_SUCCESS) {
1435 ql_log(ql_log_warn, vha, 0x800c,
1436 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001437 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001438 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001439 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001440 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001441 cmd->device->lun, type) != QLA_SUCCESS) {
1442 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001443 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001444 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001445 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001446
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001447 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001448 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001449 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001450
1451 return SUCCESS;
1452
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001453eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001454 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001455 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001456 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1457 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001458 return FAILED;
1459}
1460
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001461static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1463{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001464 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1465 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Sawan Chandaka4655372016-07-06 11:14:32 -04001467 if (qla2x00_isp_reg_stat(ha)) {
1468 ql_log(ql_log_info, vha, 0x803e,
1469 "PCI/Register disconnect, exiting.\n");
1470 return FAILED;
1471 }
1472
Andrew Vasquez523ec772008-04-03 13:13:24 -07001473 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1474 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475}
1476
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001478qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1481 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Sawan Chandaka4655372016-07-06 11:14:32 -04001483 if (qla2x00_isp_reg_stat(ha)) {
1484 ql_log(ql_log_info, vha, 0x803f,
1485 "PCI/Register disconnect, exiting.\n");
1486 return FAILED;
1487 }
1488
Andrew Vasquez523ec772008-04-03 13:13:24 -07001489 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1490 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491}
1492
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493/**************************************************************************
1494* qla2xxx_eh_bus_reset
1495*
1496* Description:
1497* The bus reset function will reset the bus and abort any executing
1498* commands.
1499*
1500* Input:
1501* cmd = Linux SCSI command packet of the command that cause the
1502* bus reset.
1503*
1504* Returns:
1505* SUCCESS/FAILURE (defined as macro in scsi.h).
1506*
1507**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001508static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1510{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001511 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001512 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001513 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001514 unsigned int id;
1515 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001516 struct qla_hw_data *ha = vha->hw;
1517
1518 if (qla2x00_isp_reg_stat(ha)) {
1519 ql_log(ql_log_info, vha, 0x8040,
1520 "PCI/Register disconnect, exiting.\n");
1521 return FAILED;
1522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
f4f051e2005-04-17 15:02:26 -05001524 id = cmd->device->id;
1525 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001526
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001527 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001528 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001531 ret = fc_block_scsi_eh(cmd);
1532 if (ret != 0)
1533 return ret;
1534 ret = FAILED;
1535
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001536 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001537 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001540 ql_log(ql_log_fatal, vha, 0x8013,
1541 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001542 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 }
1544
Saurav Kashyapad5376892011-11-18 09:02:09 -08001545 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1546 ret = SUCCESS;
1547
f4f051e2005-04-17 15:02:26 -05001548 if (ret == FAILED)
1549 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001551 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001552 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001553 QLA_SUCCESS) {
1554 ql_log(ql_log_warn, vha, 0x8014,
1555 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001556 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
f4f051e2005-04-17 15:02:26 -05001559eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001560 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001561 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001562 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
f4f051e2005-04-17 15:02:26 -05001564 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
1567/**************************************************************************
1568* qla2xxx_eh_host_reset
1569*
1570* Description:
1571* The reset function will reset the Adapter.
1572*
1573* Input:
1574* cmd = Linux SCSI command packet of the command that cause the
1575* adapter reset.
1576*
1577* Returns:
1578* Either SUCCESS or FAILED.
1579*
1580* Note:
1581**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001582static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1584{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001585 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001586 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001587 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001588 unsigned int id;
1589 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001590 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
Sawan Chandaka4655372016-07-06 11:14:32 -04001592 if (qla2x00_isp_reg_stat(ha)) {
1593 ql_log(ql_log_info, vha, 0x8041,
1594 "PCI/Register disconnect, exiting.\n");
1595 schedule_work(&ha->board_disable);
1596 return SUCCESS;
1597 }
1598
f4f051e2005-04-17 15:02:26 -05001599 id = cmd->device->id;
1600 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001601
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001602 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001603 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Chad Dupuis63ee7072014-04-11 16:54:46 -04001605 /*
1606 * No point in issuing another reset if one is active. Also do not
1607 * attempt a reset if we are updating flash.
1608 */
1609 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001610 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001612 if (vha != base_vha) {
1613 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001614 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001615 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001616 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001617 if (!qla82xx_fcoe_ctx_reset(vha)) {
1618 /* Ctx reset success */
1619 ret = SUCCESS;
1620 goto eh_host_reset_lock;
1621 }
1622 /* fall thru if ctx reset failed */
1623 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001624 if (ha->wq)
1625 flush_workqueue(ha->wq);
1626
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001627 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001628 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001629 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1630 /* failed. schedule dpc to try */
1631 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1632
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001633 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1634 ql_log(ql_log_warn, vha, 0x802a,
1635 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001636 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001637 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 }
1639 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001642 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001643 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001644 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001645 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
f4f051e2005-04-17 15:02:26 -05001647eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001648 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001649 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001650 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
f4f051e2005-04-17 15:02:26 -05001652 return ret;
1653}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655/*
1656* qla2x00_loop_reset
1657* Issue loop reset.
1658*
1659* Input:
1660* ha = adapter block pointer.
1661*
1662* Returns:
1663* 0 = success
1664*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001665int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001666qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001668 int ret;
bdf79622005-04-17 15:06:53 -05001669 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Armen Baloyan58547712013-08-27 01:37:33 -04001672 if (IS_QLAFX00(ha)) {
1673 return qlafx00_loop_reset(vha);
1674 }
1675
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001676 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001677 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1678 if (fcport->port_type != FCT_TARGET)
1679 continue;
1680
1681 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1682 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001683 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001684 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001685 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001686 }
1687 }
1688 }
1689
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001690
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001691 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001692 atomic_set(&vha->loop_state, LOOP_DOWN);
1693 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1694 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001695 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001696 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001697 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1698 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 }
1701
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001702 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001703 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001704 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001705 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1706 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001707 }
1708
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001710 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001712 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
Quinn Tranbbead492017-12-28 12:33:13 -08001715static void
1716__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001717{
Quinn Tranbbead492017-12-28 12:33:13 -08001718 int cnt, status;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001719 unsigned long flags;
1720 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001721 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001722 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001723 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001724 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1725 struct qla_tgt_cmd *cmd;
1726 uint8_t trace = 0;
Arun Easic0cb4492014-09-25 06:14:51 -04001727
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001728 if (!ha->req_q_map)
1729 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001730 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1731 req = qp->req;
1732 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1733 sp = req->outstanding_cmds[cnt];
1734 if (sp) {
1735 req->outstanding_cmds[cnt] = NULL;
Quinn Tran6b0431d2018-09-04 14:19:13 -07001736 switch (sp->cmd_type) {
1737 case TYPE_SRB:
1738 if (sp->cmd_type == TYPE_SRB) {
1739 if (sp->type == SRB_NVME_CMD ||
1740 sp->type == SRB_NVME_LS) {
1741 sp_get(sp);
1742 spin_unlock_irqrestore
1743 (qp->qp_lock_ptr,
1744 flags);
1745 qla_nvme_abort(ha, sp, res);
1746 spin_lock_irqsave
1747 (qp->qp_lock_ptr,
1748 flags);
1749 } else if (GET_CMD_SP(sp) &&
1750 !ha->flags.eeh_busy &&
1751 (!test_bit(ABORT_ISP_ACTIVE,
1752 &vha->dpc_flags)) &&
1753 (sp->type == SRB_SCSI_CMD)) {
1754 /*
1755 * Don't abort commands in
1756 * adapter during EEH
1757 * recovery as it's not
1758 * accessible/responding.
1759 *
1760 * Get a reference to the sp
1761 * and drop the lock. The
1762 * reference ensures this
1763 * sp->done() call and not the
1764 * call in qla2xxx_eh_abort()
1765 * ends the SCSI command (with
1766 * result 'res').
1767 */
1768 sp_get(sp);
1769 spin_unlock_irqrestore
1770 (qp->qp_lock_ptr,
1771 flags);
1772 status = qla2xxx_eh_abort(
1773 GET_CMD_SP(sp));
1774 spin_lock_irqsave
1775 (qp->qp_lock_ptr,
1776 flags);
1777 /*
1778 * Get rid of extra reference
1779 * if immediate exit from
1780 * ql2xxx_eh_abort
1781 */
1782 if (status == FAILED &&
1783 (qla2x00_isp_reg_stat(ha)))
1784 atomic_dec(
1785 &sp->ref_count);
1786 }
1787 sp->done(sp, res);
1788 break;
1789 case TYPE_TGT_CMD:
1790 if (!vha->hw->tgt.tgt_ops ||
1791 !tgt || qla_ini_mode_enabled(vha)) {
1792 if (!trace)
1793 ql_dbg(ql_dbg_tgt_mgt,
1794 vha, 0xf003,
1795 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1796 vha->dpc_flags);
1797 continue;
1798 }
1799 cmd = (struct qla_tgt_cmd *)sp;
1800 qlt_abort_cmd_on_host_reset(cmd->vha,
1801 cmd);
1802 break;
1803 case TYPE_TGT_TMCMD:
Quinn Tranbbead492017-12-28 12:33:13 -08001804 /*
Quinn Tran6b0431d2018-09-04 14:19:13 -07001805 * Currently, only ABTS response gets on
1806 * the outstanding_cmds[]
Quinn Tranbbead492017-12-28 12:33:13 -08001807 */
Quinn Tran6b0431d2018-09-04 14:19:13 -07001808 ha->tgt.tgt_ops->free_mcmd(
1809 (struct qla_tgt_mgmt_cmd *)sp);
1810 break;
1811 default:
1812 break;
Quinn Tranc5419e22017-06-13 20:47:16 -07001813 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001814 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001815 }
1816 }
Quinn Tranbbead492017-12-28 12:33:13 -08001817 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1818}
1819
1820void
1821qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1822{
1823 int que;
1824 struct qla_hw_data *ha = vha->hw;
1825
1826 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1827
1828 for (que = 0; que < ha->max_qpairs; que++) {
1829 if (!ha->queue_pair_map[que])
1830 continue;
1831
1832 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1833 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001834}
1835
f4f051e2005-04-17 15:02:26 -05001836static int
1837qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
bdf79622005-04-17 15:06:53 -05001839 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001841 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001842 return -ENXIO;
1843
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001844 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001845
1846 return 0;
1847}
1848
1849static int
1850qla2xxx_slave_configure(struct scsi_device *sdev)
1851{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001852 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001853 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001854
Arun Easi9e522cd2012-08-22 14:21:31 -04001855 if (IS_T10_PI_CAPABLE(vha->hw))
1856 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1857
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001858 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001859 return 0;
1860}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
f4f051e2005-04-17 15:02:26 -05001862static void
1863qla2xxx_slave_destroy(struct scsi_device *sdev)
1864{
1865 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866}
1867
1868/**
1869 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1870 * @ha: HA context
1871 *
1872 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1873 * supported addressing method.
1874 */
1875static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001876qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001878 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
Yang Hongyang6a355282009-04-06 19:01:13 -07001881 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001882 /* Any upper-dword bits set? */
1883 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001884 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001885 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001887 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1888 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001889 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001892
Yang Hongyang284901a2009-04-06 19:01:15 -07001893 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1894 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895}
1896
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001897static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001898qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001899{
1900 unsigned long flags = 0;
1901 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1902
1903 spin_lock_irqsave(&ha->hardware_lock, flags);
1904 ha->interrupts_on = 1;
1905 /* enable risc and host interrupts */
1906 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1907 RD_REG_WORD(&reg->ictrl);
1908 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1909
1910}
1911
1912static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001914{
1915 unsigned long flags = 0;
1916 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1917
1918 spin_lock_irqsave(&ha->hardware_lock, flags);
1919 ha->interrupts_on = 0;
1920 /* disable risc and host interrupts */
1921 WRT_REG_WORD(&reg->ictrl, 0);
1922 RD_REG_WORD(&reg->ictrl);
1923 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1924}
1925
1926static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001927qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001928{
1929 unsigned long flags = 0;
1930 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1931
1932 spin_lock_irqsave(&ha->hardware_lock, flags);
1933 ha->interrupts_on = 1;
1934 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1935 RD_REG_DWORD(&reg->ictrl);
1936 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1937}
1938
1939static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001941{
1942 unsigned long flags = 0;
1943 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1944
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001945 if (IS_NOPOLLING_TYPE(ha))
1946 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001947 spin_lock_irqsave(&ha->hardware_lock, flags);
1948 ha->interrupts_on = 0;
1949 WRT_REG_DWORD(&reg->ictrl, 0);
1950 RD_REG_DWORD(&reg->ictrl);
1951 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1952}
1953
Giridhar Malavali706f4572011-11-18 09:03:16 -08001954static int
1955qla2x00_iospace_config(struct qla_hw_data *ha)
1956{
1957 resource_size_t pio;
1958 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001959
Giridhar Malavali706f4572011-11-18 09:03:16 -08001960 if (pci_request_selected_regions(ha->pdev, ha->bars,
1961 QLA2XXX_DRIVER_NAME)) {
1962 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1963 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1964 pci_name(ha->pdev));
1965 goto iospace_error_exit;
1966 }
1967 if (!(ha->bars & 1))
1968 goto skip_pio;
1969
1970 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1971 pio = pci_resource_start(ha->pdev, 0);
1972 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1973 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1974 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1975 "Invalid pci I/O region size (%s).\n",
1976 pci_name(ha->pdev));
1977 pio = 0;
1978 }
1979 } else {
1980 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1981 "Region #0 no a PIO resource (%s).\n",
1982 pci_name(ha->pdev));
1983 pio = 0;
1984 }
1985 ha->pio_address = pio;
1986 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1987 "PIO address=%llu.\n",
1988 (unsigned long long)ha->pio_address);
1989
1990skip_pio:
1991 /* Use MMIO operations for all accesses. */
1992 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1993 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1994 "Region #1 not an MMIO resource (%s), aborting.\n",
1995 pci_name(ha->pdev));
1996 goto iospace_error_exit;
1997 }
1998 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1999 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2000 "Invalid PCI mem region size (%s), aborting.\n",
2001 pci_name(ha->pdev));
2002 goto iospace_error_exit;
2003 }
2004
2005 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2006 if (!ha->iobase) {
2007 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2008 "Cannot remap MMIO (%s), aborting.\n",
2009 pci_name(ha->pdev));
2010 goto iospace_error_exit;
2011 }
2012
2013 /* Determine queue resources */
2014 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002015 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002016 if (!ql2xmqsupport || !ql2xnvmeenable ||
2017 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08002018 goto mqiobase_exit;
2019
2020 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2021 pci_resource_len(ha->pdev, 3));
2022 if (ha->mqiobase) {
2023 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2024 "MQIO Base=%p.\n", ha->mqiobase);
2025 /* Read MSIX vector size of the board */
2026 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002027 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002028 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002029 /* MB interrupt uses 1 vector */
2030 ha->max_req_queues = ha->msix_count - 1;
2031 ha->max_rsp_queues = ha->max_req_queues;
2032 /* Queue pairs is the max value minus the base queue pair */
2033 ha->max_qpairs = ha->max_rsp_queues - 1;
2034 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2035 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2036
Giridhar Malavali706f4572011-11-18 09:03:16 -08002037 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002038 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002039 } else
2040 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2041 "BAR 3 not enabled.\n");
2042
2043mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002044 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002045 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002046 return (0);
2047
2048iospace_error_exit:
2049 return (-ENOMEM);
2050}
2051
2052
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002053static int
2054qla83xx_iospace_config(struct qla_hw_data *ha)
2055{
2056 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002057
2058 if (pci_request_selected_regions(ha->pdev, ha->bars,
2059 QLA2XXX_DRIVER_NAME)) {
2060 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2061 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2062 pci_name(ha->pdev));
2063
2064 goto iospace_error_exit;
2065 }
2066
2067 /* Use MMIO operations for all accesses. */
2068 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2069 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2070 "Invalid pci I/O region size (%s).\n",
2071 pci_name(ha->pdev));
2072 goto iospace_error_exit;
2073 }
2074 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2075 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2076 "Invalid PCI mem region size (%s), aborting\n",
2077 pci_name(ha->pdev));
2078 goto iospace_error_exit;
2079 }
2080
2081 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2082 if (!ha->iobase) {
2083 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2084 "Cannot remap MMIO (%s), aborting.\n",
2085 pci_name(ha->pdev));
2086 goto iospace_error_exit;
2087 }
2088
2089 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2090 /* 83XX 26XX always use MQ type access for queues
2091 * - mbar 2, a.k.a region 4 */
2092 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002093 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002094 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2095 pci_resource_len(ha->pdev, 4));
2096
2097 if (!ha->mqiobase) {
2098 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2099 "BAR2/region4 not enabled\n");
2100 goto mqiobase_exit;
2101 }
2102
2103 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2104 pci_resource_len(ha->pdev, 2));
2105 if (ha->msixbase) {
2106 /* Read MSIX vector size of the board */
2107 pci_read_config_word(ha->pdev,
2108 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002109 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002110 /*
2111 * By default, driver uses at least two msix vectors
2112 * (default & rspq)
2113 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002114 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002115 /* MB interrupt uses 1 vector */
2116 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002117
2118 /* ATIOQ needs 1 vector. That's 1 less QPair */
2119 if (QLA_TGT_MODE_ENABLED())
2120 ha->max_req_queues--;
2121
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002122 ha->max_rsp_queues = ha->max_req_queues;
2123
Michael Hernandezd7459522016-12-12 14:40:07 -08002124 /* Queue pairs is the max value minus
2125 * the base queue pair */
2126 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002127 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002128 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002129 }
2130 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002131 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002132 } else
2133 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2134 "BAR 1 not enabled.\n");
2135
2136mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002137 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002138 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002139 return 0;
2140
2141iospace_error_exit:
2142 return -ENOMEM;
2143}
2144
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002145static struct isp_operations qla2100_isp_ops = {
2146 .pci_config = qla2100_pci_config,
2147 .reset_chip = qla2x00_reset_chip,
2148 .chip_diag = qla2x00_chip_diag,
2149 .config_rings = qla2x00_config_rings,
2150 .reset_adapter = qla2x00_reset_adapter,
2151 .nvram_config = qla2x00_nvram_config,
2152 .update_fw_options = qla2x00_update_fw_options,
2153 .load_risc = qla2x00_load_risc,
2154 .pci_info_str = qla2x00_pci_info_str,
2155 .fw_version_str = qla2x00_fw_version_str,
2156 .intr_handler = qla2100_intr_handler,
2157 .enable_intrs = qla2x00_enable_intrs,
2158 .disable_intrs = qla2x00_disable_intrs,
2159 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002160 .target_reset = qla2x00_abort_target,
2161 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002162 .fabric_login = qla2x00_login_fabric,
2163 .fabric_logout = qla2x00_fabric_logout,
2164 .calc_req_entries = qla2x00_calc_iocbs_32,
2165 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2166 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2167 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2168 .read_nvram = qla2x00_read_nvram_data,
2169 .write_nvram = qla2x00_write_nvram_data,
2170 .fw_dump = qla2100_fw_dump,
2171 .beacon_on = NULL,
2172 .beacon_off = NULL,
2173 .beacon_blink = NULL,
2174 .read_optrom = qla2x00_read_optrom_data,
2175 .write_optrom = qla2x00_write_optrom_data,
2176 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002177 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002178 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002179 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002180 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002181 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002182};
2183
2184static struct isp_operations qla2300_isp_ops = {
2185 .pci_config = qla2300_pci_config,
2186 .reset_chip = qla2x00_reset_chip,
2187 .chip_diag = qla2x00_chip_diag,
2188 .config_rings = qla2x00_config_rings,
2189 .reset_adapter = qla2x00_reset_adapter,
2190 .nvram_config = qla2x00_nvram_config,
2191 .update_fw_options = qla2x00_update_fw_options,
2192 .load_risc = qla2x00_load_risc,
2193 .pci_info_str = qla2x00_pci_info_str,
2194 .fw_version_str = qla2x00_fw_version_str,
2195 .intr_handler = qla2300_intr_handler,
2196 .enable_intrs = qla2x00_enable_intrs,
2197 .disable_intrs = qla2x00_disable_intrs,
2198 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002199 .target_reset = qla2x00_abort_target,
2200 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002201 .fabric_login = qla2x00_login_fabric,
2202 .fabric_logout = qla2x00_fabric_logout,
2203 .calc_req_entries = qla2x00_calc_iocbs_32,
2204 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2205 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2206 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2207 .read_nvram = qla2x00_read_nvram_data,
2208 .write_nvram = qla2x00_write_nvram_data,
2209 .fw_dump = qla2300_fw_dump,
2210 .beacon_on = qla2x00_beacon_on,
2211 .beacon_off = qla2x00_beacon_off,
2212 .beacon_blink = qla2x00_beacon_blink,
2213 .read_optrom = qla2x00_read_optrom_data,
2214 .write_optrom = qla2x00_write_optrom_data,
2215 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002216 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002217 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002218 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002219 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002220 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002221};
2222
2223static struct isp_operations qla24xx_isp_ops = {
2224 .pci_config = qla24xx_pci_config,
2225 .reset_chip = qla24xx_reset_chip,
2226 .chip_diag = qla24xx_chip_diag,
2227 .config_rings = qla24xx_config_rings,
2228 .reset_adapter = qla24xx_reset_adapter,
2229 .nvram_config = qla24xx_nvram_config,
2230 .update_fw_options = qla24xx_update_fw_options,
2231 .load_risc = qla24xx_load_risc,
2232 .pci_info_str = qla24xx_pci_info_str,
2233 .fw_version_str = qla24xx_fw_version_str,
2234 .intr_handler = qla24xx_intr_handler,
2235 .enable_intrs = qla24xx_enable_intrs,
2236 .disable_intrs = qla24xx_disable_intrs,
2237 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002238 .target_reset = qla24xx_abort_target,
2239 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002240 .fabric_login = qla24xx_login_fabric,
2241 .fabric_logout = qla24xx_fabric_logout,
2242 .calc_req_entries = NULL,
2243 .build_iocbs = NULL,
2244 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2245 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2246 .read_nvram = qla24xx_read_nvram_data,
2247 .write_nvram = qla24xx_write_nvram_data,
2248 .fw_dump = qla24xx_fw_dump,
2249 .beacon_on = qla24xx_beacon_on,
2250 .beacon_off = qla24xx_beacon_off,
2251 .beacon_blink = qla24xx_beacon_blink,
2252 .read_optrom = qla24xx_read_optrom_data,
2253 .write_optrom = qla24xx_write_optrom_data,
2254 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002255 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002256 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002257 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002258 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002259 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002260};
2261
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002262static struct isp_operations qla25xx_isp_ops = {
2263 .pci_config = qla25xx_pci_config,
2264 .reset_chip = qla24xx_reset_chip,
2265 .chip_diag = qla24xx_chip_diag,
2266 .config_rings = qla24xx_config_rings,
2267 .reset_adapter = qla24xx_reset_adapter,
2268 .nvram_config = qla24xx_nvram_config,
2269 .update_fw_options = qla24xx_update_fw_options,
2270 .load_risc = qla24xx_load_risc,
2271 .pci_info_str = qla24xx_pci_info_str,
2272 .fw_version_str = qla24xx_fw_version_str,
2273 .intr_handler = qla24xx_intr_handler,
2274 .enable_intrs = qla24xx_enable_intrs,
2275 .disable_intrs = qla24xx_disable_intrs,
2276 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002277 .target_reset = qla24xx_abort_target,
2278 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002279 .fabric_login = qla24xx_login_fabric,
2280 .fabric_logout = qla24xx_fabric_logout,
2281 .calc_req_entries = NULL,
2282 .build_iocbs = NULL,
2283 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2284 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2285 .read_nvram = qla25xx_read_nvram_data,
2286 .write_nvram = qla25xx_write_nvram_data,
2287 .fw_dump = qla25xx_fw_dump,
2288 .beacon_on = qla24xx_beacon_on,
2289 .beacon_off = qla24xx_beacon_off,
2290 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002291 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002292 .write_optrom = qla24xx_write_optrom_data,
2293 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002294 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002295 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002296 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002297 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002298 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002299};
2300
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002301static struct isp_operations qla81xx_isp_ops = {
2302 .pci_config = qla25xx_pci_config,
2303 .reset_chip = qla24xx_reset_chip,
2304 .chip_diag = qla24xx_chip_diag,
2305 .config_rings = qla24xx_config_rings,
2306 .reset_adapter = qla24xx_reset_adapter,
2307 .nvram_config = qla81xx_nvram_config,
2308 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002309 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002310 .pci_info_str = qla24xx_pci_info_str,
2311 .fw_version_str = qla24xx_fw_version_str,
2312 .intr_handler = qla24xx_intr_handler,
2313 .enable_intrs = qla24xx_enable_intrs,
2314 .disable_intrs = qla24xx_disable_intrs,
2315 .abort_command = qla24xx_abort_command,
2316 .target_reset = qla24xx_abort_target,
2317 .lun_reset = qla24xx_lun_reset,
2318 .fabric_login = qla24xx_login_fabric,
2319 .fabric_logout = qla24xx_fabric_logout,
2320 .calc_req_entries = NULL,
2321 .build_iocbs = NULL,
2322 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2323 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002324 .read_nvram = NULL,
2325 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002326 .fw_dump = qla81xx_fw_dump,
2327 .beacon_on = qla24xx_beacon_on,
2328 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002329 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002330 .read_optrom = qla25xx_read_optrom_data,
2331 .write_optrom = qla24xx_write_optrom_data,
2332 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002333 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002334 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002335 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002336 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002337 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002338};
2339
2340static struct isp_operations qla82xx_isp_ops = {
2341 .pci_config = qla82xx_pci_config,
2342 .reset_chip = qla82xx_reset_chip,
2343 .chip_diag = qla24xx_chip_diag,
2344 .config_rings = qla82xx_config_rings,
2345 .reset_adapter = qla24xx_reset_adapter,
2346 .nvram_config = qla81xx_nvram_config,
2347 .update_fw_options = qla24xx_update_fw_options,
2348 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002349 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002350 .fw_version_str = qla24xx_fw_version_str,
2351 .intr_handler = qla82xx_intr_handler,
2352 .enable_intrs = qla82xx_enable_intrs,
2353 .disable_intrs = qla82xx_disable_intrs,
2354 .abort_command = qla24xx_abort_command,
2355 .target_reset = qla24xx_abort_target,
2356 .lun_reset = qla24xx_lun_reset,
2357 .fabric_login = qla24xx_login_fabric,
2358 .fabric_logout = qla24xx_fabric_logout,
2359 .calc_req_entries = NULL,
2360 .build_iocbs = NULL,
2361 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2362 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2363 .read_nvram = qla24xx_read_nvram_data,
2364 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002365 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002366 .beacon_on = qla82xx_beacon_on,
2367 .beacon_off = qla82xx_beacon_off,
2368 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002369 .read_optrom = qla82xx_read_optrom_data,
2370 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002371 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002372 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002373 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002374 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002375 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002376 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002377};
2378
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002379static struct isp_operations qla8044_isp_ops = {
2380 .pci_config = qla82xx_pci_config,
2381 .reset_chip = qla82xx_reset_chip,
2382 .chip_diag = qla24xx_chip_diag,
2383 .config_rings = qla82xx_config_rings,
2384 .reset_adapter = qla24xx_reset_adapter,
2385 .nvram_config = qla81xx_nvram_config,
2386 .update_fw_options = qla24xx_update_fw_options,
2387 .load_risc = qla82xx_load_risc,
2388 .pci_info_str = qla24xx_pci_info_str,
2389 .fw_version_str = qla24xx_fw_version_str,
2390 .intr_handler = qla8044_intr_handler,
2391 .enable_intrs = qla82xx_enable_intrs,
2392 .disable_intrs = qla82xx_disable_intrs,
2393 .abort_command = qla24xx_abort_command,
2394 .target_reset = qla24xx_abort_target,
2395 .lun_reset = qla24xx_lun_reset,
2396 .fabric_login = qla24xx_login_fabric,
2397 .fabric_logout = qla24xx_fabric_logout,
2398 .calc_req_entries = NULL,
2399 .build_iocbs = NULL,
2400 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2401 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2402 .read_nvram = NULL,
2403 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002404 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002405 .beacon_on = qla82xx_beacon_on,
2406 .beacon_off = qla82xx_beacon_off,
2407 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002408 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002409 .write_optrom = qla8044_write_optrom_data,
2410 .get_flash_version = qla82xx_get_flash_version,
2411 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002412 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002413 .abort_isp = qla8044_abort_isp,
2414 .iospace_config = qla82xx_iospace_config,
2415 .initialize_adapter = qla2x00_initialize_adapter,
2416};
2417
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002418static struct isp_operations qla83xx_isp_ops = {
2419 .pci_config = qla25xx_pci_config,
2420 .reset_chip = qla24xx_reset_chip,
2421 .chip_diag = qla24xx_chip_diag,
2422 .config_rings = qla24xx_config_rings,
2423 .reset_adapter = qla24xx_reset_adapter,
2424 .nvram_config = qla81xx_nvram_config,
2425 .update_fw_options = qla81xx_update_fw_options,
2426 .load_risc = qla81xx_load_risc,
2427 .pci_info_str = qla24xx_pci_info_str,
2428 .fw_version_str = qla24xx_fw_version_str,
2429 .intr_handler = qla24xx_intr_handler,
2430 .enable_intrs = qla24xx_enable_intrs,
2431 .disable_intrs = qla24xx_disable_intrs,
2432 .abort_command = qla24xx_abort_command,
2433 .target_reset = qla24xx_abort_target,
2434 .lun_reset = qla24xx_lun_reset,
2435 .fabric_login = qla24xx_login_fabric,
2436 .fabric_logout = qla24xx_fabric_logout,
2437 .calc_req_entries = NULL,
2438 .build_iocbs = NULL,
2439 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2440 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2441 .read_nvram = NULL,
2442 .write_nvram = NULL,
2443 .fw_dump = qla83xx_fw_dump,
2444 .beacon_on = qla24xx_beacon_on,
2445 .beacon_off = qla24xx_beacon_off,
2446 .beacon_blink = qla83xx_beacon_blink,
2447 .read_optrom = qla25xx_read_optrom_data,
2448 .write_optrom = qla24xx_write_optrom_data,
2449 .get_flash_version = qla24xx_get_flash_version,
2450 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002451 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002452 .abort_isp = qla2x00_abort_isp,
2453 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002454 .initialize_adapter = qla2x00_initialize_adapter,
2455};
2456
2457static struct isp_operations qlafx00_isp_ops = {
2458 .pci_config = qlafx00_pci_config,
2459 .reset_chip = qlafx00_soft_reset,
2460 .chip_diag = qlafx00_chip_diag,
2461 .config_rings = qlafx00_config_rings,
2462 .reset_adapter = qlafx00_soft_reset,
2463 .nvram_config = NULL,
2464 .update_fw_options = NULL,
2465 .load_risc = NULL,
2466 .pci_info_str = qlafx00_pci_info_str,
2467 .fw_version_str = qlafx00_fw_version_str,
2468 .intr_handler = qlafx00_intr_handler,
2469 .enable_intrs = qlafx00_enable_intrs,
2470 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002471 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002472 .target_reset = qlafx00_abort_target,
2473 .lun_reset = qlafx00_lun_reset,
2474 .fabric_login = NULL,
2475 .fabric_logout = NULL,
2476 .calc_req_entries = NULL,
2477 .build_iocbs = NULL,
2478 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2479 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2480 .read_nvram = qla24xx_read_nvram_data,
2481 .write_nvram = qla24xx_write_nvram_data,
2482 .fw_dump = NULL,
2483 .beacon_on = qla24xx_beacon_on,
2484 .beacon_off = qla24xx_beacon_off,
2485 .beacon_blink = NULL,
2486 .read_optrom = qla24xx_read_optrom_data,
2487 .write_optrom = qla24xx_write_optrom_data,
2488 .get_flash_version = qla24xx_get_flash_version,
2489 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002490 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002491 .abort_isp = qlafx00_abort_isp,
2492 .iospace_config = qlafx00_iospace_config,
2493 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002494};
2495
Chad Dupuisf73cb692014-02-26 04:15:06 -05002496static struct isp_operations qla27xx_isp_ops = {
2497 .pci_config = qla25xx_pci_config,
2498 .reset_chip = qla24xx_reset_chip,
2499 .chip_diag = qla24xx_chip_diag,
2500 .config_rings = qla24xx_config_rings,
2501 .reset_adapter = qla24xx_reset_adapter,
2502 .nvram_config = qla81xx_nvram_config,
2503 .update_fw_options = qla81xx_update_fw_options,
2504 .load_risc = qla81xx_load_risc,
2505 .pci_info_str = qla24xx_pci_info_str,
2506 .fw_version_str = qla24xx_fw_version_str,
2507 .intr_handler = qla24xx_intr_handler,
2508 .enable_intrs = qla24xx_enable_intrs,
2509 .disable_intrs = qla24xx_disable_intrs,
2510 .abort_command = qla24xx_abort_command,
2511 .target_reset = qla24xx_abort_target,
2512 .lun_reset = qla24xx_lun_reset,
2513 .fabric_login = qla24xx_login_fabric,
2514 .fabric_logout = qla24xx_fabric_logout,
2515 .calc_req_entries = NULL,
2516 .build_iocbs = NULL,
2517 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2518 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2519 .read_nvram = NULL,
2520 .write_nvram = NULL,
2521 .fw_dump = qla27xx_fwdump,
2522 .beacon_on = qla24xx_beacon_on,
2523 .beacon_off = qla24xx_beacon_off,
2524 .beacon_blink = qla83xx_beacon_blink,
2525 .read_optrom = qla25xx_read_optrom_data,
2526 .write_optrom = qla24xx_write_optrom_data,
2527 .get_flash_version = qla24xx_get_flash_version,
2528 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002529 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002530 .abort_isp = qla2x00_abort_isp,
2531 .iospace_config = qla83xx_iospace_config,
2532 .initialize_adapter = qla2x00_initialize_adapter,
2533};
2534
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002535static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002536qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002537{
2538 ha->device_type = DT_EXTENDED_IDS;
2539 switch (ha->pdev->device) {
2540 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002541 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002542 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002543 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002544 break;
2545 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002546 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002547 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002548 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002549 break;
2550 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002551 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002552 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002553 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002554 break;
2555 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002556 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002557 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002558 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002559 break;
2560 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002561 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002562 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002563 if (ha->pdev->subsystem_vendor == 0x1028 &&
2564 ha->pdev->subsystem_device == 0x0170)
2565 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002566 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002567 break;
2568 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002569 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002570 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002571 break;
2572 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002573 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002574 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002575 break;
2576 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002577 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002578 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002579 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002580 ha->device_type |= DT_IIDMA;
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;
2583 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002584 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002585 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002586 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002587 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002588 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002589 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002590 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002591 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002592 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;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002597 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002598 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002599 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002600 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002601 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002602 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002603 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002604 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002605 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002606 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002607 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002608 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002609 ha->device_type |= DT_ZIO_SUPPORTED;
2610 ha->device_type |= DT_FWI2;
2611 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002612 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2613 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002614 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002615 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002616 ha->device_type |= DT_ZIO_SUPPORTED;
2617 ha->device_type |= DT_FWI2;
2618 ha->device_type |= DT_IIDMA;
2619 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2620 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002621 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002622 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002623 ha->device_type |= DT_ZIO_SUPPORTED;
2624 ha->device_type |= DT_FWI2;
2625 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2626 /* Initialize 82XX ISP flags */
2627 qla82xx_init_flags(ha);
2628 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002629 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002630 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002631 ha->device_type |= DT_ZIO_SUPPORTED;
2632 ha->device_type |= DT_FWI2;
2633 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2634 /* Initialize 82XX ISP flags */
2635 qla82xx_init_flags(ha);
2636 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002637 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002638 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002639 ha->device_type |= DT_ZIO_SUPPORTED;
2640 ha->device_type |= DT_FWI2;
2641 ha->device_type |= DT_IIDMA;
2642 ha->device_type |= DT_T10_PI;
2643 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2644 break;
2645 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002646 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002647 ha->device_type |= DT_ZIO_SUPPORTED;
2648 ha->device_type |= DT_FWI2;
2649 ha->device_type |= DT_IIDMA;
2650 ha->device_type |= DT_T10_PI;
2651 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2652 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002653 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002654 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002655 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002656 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002657 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002658 ha->device_type |= DT_ZIO_SUPPORTED;
2659 ha->device_type |= DT_FWI2;
2660 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002661 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002662 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2663 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002664 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002665 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002666 ha->device_type |= DT_ZIO_SUPPORTED;
2667 ha->device_type |= DT_FWI2;
2668 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002669 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002670 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2671 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002672 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002673 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002674 ha->device_type |= DT_ZIO_SUPPORTED;
2675 ha->device_type |= DT_FWI2;
2676 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002677 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002678 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2679 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002680 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002681
Giridhar Malavalia9083012010-04-12 17:59:55 -07002682 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002683 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002684 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002685 /* Get adapter physical port no from interrupt pin register. */
2686 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002687 if (IS_QLA27XX(ha))
2688 ha->port_no--;
2689 else
2690 ha->port_no = !(ha->port_no & 1);
2691 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002692
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002693 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002694 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002695 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002696}
2697
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002698static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002699qla2xxx_scan_start(struct Scsi_Host *shost)
2700{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002702
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002703 if (vha->hw->flags.running_gold_fw)
2704 return;
2705
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2707 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2708 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2709 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002710}
2711
2712static int
2713qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2714{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002716
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002717 if (test_bit(UNLOADING, &vha->dpc_flags))
2718 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002719 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002720 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002722 return 1;
2723
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002725}
2726
Quinn Tranec7193e2017-03-15 09:48:55 -07002727static void qla2x00_iocb_work_fn(struct work_struct *work)
2728{
2729 struct scsi_qla_host *vha = container_of(work,
2730 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002731 struct qla_hw_data *ha = vha->hw;
2732 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran0aca7782018-09-04 14:19:16 -07002733 int i = 2;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002734 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002735
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002736 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2737 return;
2738
2739 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002740 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002741 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002742 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002743
2744 spin_lock_irqsave(&vha->work_lock, flags);
2745 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2746 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002747}
2748
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749/*
2750 * PCI driver interface
2751 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002752static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002753qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002755 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 scsi_qla_host_t *base_vha = NULL;
2758 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002759 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002760 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002761 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002762 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002764 struct req_que *req = NULL;
2765 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002766 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002767
Andrew Vasquez285d0322007-10-19 15:59:17 -07002768 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002769 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002770 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2771 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002772 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002773 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2774 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002775 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002776 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002777 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2778 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002779 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002780 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002781 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002782 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002783 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
2784 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002785 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002786 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002787 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2788 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002789 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002790 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2791 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002792
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002793 if (mem_only) {
2794 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002795 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002796 } else {
2797 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002798 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002799 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
Jesse Barnes09276782008-10-18 17:33:19 -07002801 /* This may fail but that's ok */
2802 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002803
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002804 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2805 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002806 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2807 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002808 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002810 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2811 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002812 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002813 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2814 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002815 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002816 spin_lock_init(&ha->tgt.atio_lock);
2817
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002818 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
2820 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002821 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002822 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002823 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002824 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002825 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002826 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002828 /* Set ISP-type information. */
2829 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002830
2831 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002832 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002833 IS_QLA83XX(ha) || IS_QLA27XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002834 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002835
Chad Dupuiscba1e472011-11-18 09:03:21 -08002836 ha->prev_topology = 0;
2837 ha->init_cb_size = sizeof(init_cb_t);
2838 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2839 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002840 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Quinn Tranb2000802018-08-02 13:16:52 -07002841 atomic_set(&ha->num_pend_mbx_stage1, 0);
2842 atomic_set(&ha->num_pend_mbx_stage2, 0);
2843 atomic_set(&ha->num_pend_mbx_stage3, 0);
Quinn Tran8b4673b2018-09-04 14:19:14 -07002844 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2845 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002846
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002847 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002849 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851 req_length = REQUEST_ENTRY_CNT_2100;
2852 rsp_length = RESPONSE_ENTRY_CNT_2100;
2853 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002854 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002855 ha->flash_conf_off = ~0;
2856 ha->flash_data_off = ~0;
2857 ha->nvram_conf_off = ~0;
2858 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002859 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002861 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002862 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002863 req_length = REQUEST_ENTRY_CNT_2200;
2864 rsp_length = RESPONSE_ENTRY_CNT_2100;
2865 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002866 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002867 ha->flash_conf_off = ~0;
2868 ha->flash_data_off = ~0;
2869 ha->nvram_conf_off = ~0;
2870 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002871 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002872 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002873 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 req_length = REQUEST_ENTRY_CNT_2200;
2876 rsp_length = RESPONSE_ENTRY_CNT_2300;
2877 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002878 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002879 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2880 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002881 ha->flash_conf_off = ~0;
2882 ha->flash_data_off = ~0;
2883 ha->nvram_conf_off = ~0;
2884 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002885 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002886 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002887 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002888 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889 req_length = REQUEST_ENTRY_CNT_24XX;
2890 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002891 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002893 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002894 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002895 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002896 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002897 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002898 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2899 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2900 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2901 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002902 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002903 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002904 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 req_length = REQUEST_ENTRY_CNT_24XX;
2906 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002907 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002908 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002909 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002910 ha->gid_list_info_size = 8;
2911 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002912 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002913 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002914 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2915 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2916 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2917 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2918 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002919 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002920 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2921 req_length = REQUEST_ENTRY_CNT_24XX;
2922 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002923 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002924 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2925 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2926 ha->gid_list_info_size = 8;
2927 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002928 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002929 ha->isp_ops = &qla81xx_isp_ops;
2930 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2931 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2932 ha->nvram_conf_off = ~0;
2933 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002934 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002935 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002936 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2937 req_length = REQUEST_ENTRY_CNT_82XX;
2938 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2939 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2940 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2941 ha->gid_list_info_size = 8;
2942 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002943 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002944 ha->isp_ops = &qla82xx_isp_ops;
2945 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2946 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2947 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2948 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002949 } else if (IS_QLA8044(ha)) {
2950 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2951 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2952 req_length = REQUEST_ENTRY_CNT_82XX;
2953 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2954 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2955 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2956 ha->gid_list_info_size = 8;
2957 ha->optrom_size = OPTROM_SIZE_83XX;
2958 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2959 ha->isp_ops = &qla8044_isp_ops;
2960 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2961 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2962 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2963 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002964 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002965 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002966 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002967 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002968 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002969 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002970 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002971 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2972 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2973 ha->gid_list_info_size = 8;
2974 ha->optrom_size = OPTROM_SIZE_83XX;
2975 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2976 ha->isp_ops = &qla83xx_isp_ops;
2977 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2978 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2979 ha->nvram_conf_off = ~0;
2980 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002981 } else if (IS_QLAFX00(ha)) {
2982 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2983 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2984 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2985 req_length = REQUEST_ENTRY_CNT_FX00;
2986 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002987 ha->isp_ops = &qlafx00_isp_ops;
2988 ha->port_down_retry_count = 30; /* default value */
2989 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
2990 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04002991 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002992 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04002993 ha->mr.host_info_resend = false;
2994 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002995 } else if (IS_QLA27XX(ha)) {
2996 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2997 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2998 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05002999 req_length = REQUEST_ENTRY_CNT_83XX;
3000 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04003001 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003002 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3003 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3004 ha->gid_list_info_size = 8;
3005 ha->optrom_size = OPTROM_SIZE_83XX;
3006 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3007 ha->isp_ops = &qla27xx_isp_ops;
3008 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3009 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3010 ha->nvram_conf_off = ~0;
3011 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003013
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003014 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3015 "mbx_count=%d, req_length=%d, "
3016 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08003017 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3018 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003019 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3020 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08003021 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003022 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3023 "isp_ops=%p, flash_conf_off=%d, "
3024 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3025 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3026 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08003027
3028 /* Configure PCI I/O space */
3029 ret = ha->isp_ops->iospace_config(ha);
3030 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003031 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003032
3033 ql_log_pci(ql_log_info, pdev, 0x001d,
3034 "Found an ISP%04X irq %d iobase 0x%p.\n",
3035 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003036 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003037 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003038 init_completion(&ha->mbx_cmd_comp);
3039 complete(&ha->mbx_cmd_comp);
3040 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003041 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003042 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003044 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
Andrew Vasquez53303c42009-01-22 09:45:37 -08003046 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003047 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3048 "64 Bit addressing is %s.\n",
3049 ha->flags.enable_64bit_addressing ? "enable" :
3050 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003051 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003052 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003053 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3054 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003056 goto probe_hw_failed;
3057 }
3058
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003059 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003061 req->max_q_depth = ql2xmaxqdepth;
3062
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003063
3064 base_vha = qla2x00_create_host(sht, ha);
3065 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003066 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 }
3069
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003070 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003071 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003073 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003074 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003075 if (IS_QLA2XXX_MIDTYPE(ha))
Quinn Tranf6602f32018-08-02 13:16:53 -07003076 base_vha->mgmt_svr_loop_id =
3077 qla2x00_reserve_mgmt_server_loop_id(base_vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003078 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003079 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3080 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003081
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003082 /* Setup fcport template structure. */
3083 ha->mr.fcport.vha = base_vha;
3084 ha->mr.fcport.port_type = FCT_UNKNOWN;
3085 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3086 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3087 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3088 ha->mr.fcport.scan_state = 1;
3089
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003090 /* Set the SG table size based on ISP type */
3091 if (!IS_FWI2_CAPABLE(ha)) {
3092 if (IS_QLA2100(ha))
3093 host->sg_tablesize = 32;
3094 } else {
3095 if (!IS_QLA82XX(ha))
3096 host->sg_tablesize = QLA_SG_ALL;
3097 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003098 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003099 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003100 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003101 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003102 host->max_cmd_len = 32;
3103 else
3104 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003105 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003106 /* Older HBAs support only 16-bit LUNs */
3107 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3108 ql2xmaxlun > 0xffff)
3109 host->max_lun = 0xffff;
3110 else
3111 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003112 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003113 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003114
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003115 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3116 "max_id=%d this_id=%d "
3117 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003118 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003119 host->this_id, host->cmd_per_lun, host->unique_id,
3120 host->max_cmd_len, host->max_channel, host->max_lun,
3121 host->transportt, sht->vendor_id);
3122
Himanshu Madhani1010f212017-10-16 11:26:05 -07003123 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3124
Michael Hernandezd7459522016-12-12 14:40:07 -08003125 /* Set up the irqs */
3126 ret = qla2x00_request_irqs(ha, rsp);
3127 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003128 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003129
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003130 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003131 ret = qla2x00_alloc_queues(ha, req, rsp);
3132 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003133 ql_log(ql_log_fatal, base_vha, 0x003d,
3134 "Failed to allocate memory for queue pointers..."
3135 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003136 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003137 }
3138
Michael Hernandez56012362016-12-12 14:40:08 -08003139 if (ha->mqenable && shost_use_blk_mq(host)) {
3140 /* number of hardware queues supported by blk/scsi-mq*/
3141 host->nr_hw_queues = ha->max_qpairs;
3142
3143 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3144 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003145 } else {
3146 if (ql2xnvmeenable) {
3147 host->nr_hw_queues = ha->max_qpairs;
3148 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3149 "FC-NVMe support is enabled, HW queues=%d\n",
3150 host->nr_hw_queues);
3151 } else {
3152 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3153 "blk/scsi-mq disabled.\n");
3154 }
3155 }
Michael Hernandez56012362016-12-12 14:40:08 -08003156
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003157 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003158
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003159 pci_save_state(pdev);
3160
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003161 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003162 rsp->req = req;
3163 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003164
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003165 if (IS_QLAFX00(ha)) {
3166 ha->rsp_q_map[0] = rsp;
3167 ha->req_q_map[0] = req;
3168 set_bit(0, ha->req_qid_map);
3169 set_bit(0, ha->rsp_qid_map);
3170 }
3171
Andrew Vasquez08029992009-03-24 09:07:55 -07003172 /* FWI2-capable only. */
3173 req->req_q_in = &ha->iobase->isp24.req_q_in;
3174 req->req_q_out = &ha->iobase->isp24.req_q_out;
3175 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3176 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003177 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003178 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3179 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3180 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3181 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003182 }
3183
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003184 if (IS_QLAFX00(ha)) {
3185 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3186 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3187 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3188 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3189 }
3190
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003191 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003192 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3193 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3194 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3195 }
3196
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003197 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3198 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3199 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3200 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3201 "req->req_q_in=%p req->req_q_out=%p "
3202 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3203 req->req_q_in, req->req_q_out,
3204 rsp->rsp_q_in, rsp->rsp_q_out);
3205 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3206 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3207 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3208 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3209 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3210 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003211
himanshu.madhani@cavium.comd48cc672018-07-02 13:01:59 -07003212 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3213
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003214 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003215 ql_log(ql_log_fatal, base_vha, 0x00d6,
3216 "Failed to initialize adapter - Adapter flags %x.\n",
3217 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003218
Giridhar Malavalia9083012010-04-12 17:59:55 -07003219 if (IS_QLA82XX(ha)) {
3220 qla82xx_idc_lock(ha);
3221 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003222 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003223 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003224 ql_log(ql_log_fatal, base_vha, 0x00d7,
3225 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003226 } else if (IS_QLA8044(ha)) {
3227 qla8044_idc_lock(ha);
3228 qla8044_wr_direct(base_vha,
3229 QLA8044_CRB_DEV_STATE_INDEX,
3230 QLA8XXX_DEV_FAILED);
3231 qla8044_idc_unlock(ha);
3232 ql_log(ql_log_fatal, base_vha, 0x0150,
3233 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003234 }
3235
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003236 ret = -ENODEV;
3237 goto probe_failed;
3238 }
3239
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003240 if (IS_QLAFX00(ha))
3241 host->can_queue = QLAFX00_MAX_CANQUEUE;
3242 else
3243 host->can_queue = req->num_outstanding_cmds - 10;
3244
3245 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3246 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3247 host->can_queue, base_vha->req,
3248 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3249
Quinn Trane326d222017-06-13 20:47:18 -07003250 if (ha->mqenable) {
3251 bool mq = false;
3252 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003253
3254 if (QLA_TGT_MODE_ENABLED()) {
3255 mq = true;
3256 startit = false;
3257 }
3258
3259 if ((ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED) &&
3260 shost_use_blk_mq(host)) {
3261 mq = true;
3262 startit = true;
3263 }
3264
3265 if (mq) {
3266 /* Create start of day qpairs for Block MQ */
Michael Hernandez56012362016-12-12 14:40:08 -08003267 for (i = 0; i < ha->max_qpairs; i++)
Quinn Trane326d222017-06-13 20:47:18 -07003268 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003269 }
3270 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003271
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003272 if (ha->flags.running_gold_fw)
3273 goto skip_dpc;
3274
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275 /*
3276 * Startup the kernel thread for this host adapter
3277 */
3278 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003279 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003281 ql_log(ql_log_fatal, base_vha, 0x00ed,
3282 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003283 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003284 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285 goto probe_failed;
3286 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003287 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3288 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003290 /*
3291 * If we're not coming up in initiator mode, we might sit for
3292 * a while without waking up the dpc thread, which leads to a
3293 * stuck process warning. So just kick the dpc once here and
3294 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3295 */
3296 qla2xxx_wake_dpc(base_vha);
3297
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003298 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3299
Saurav Kashyap81178772012-08-22 14:21:04 -04003300 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3301 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3302 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3303 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3304
3305 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3306 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3307 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3308 INIT_WORK(&ha->idc_state_handler,
3309 qla83xx_idc_state_handler_work);
3310 INIT_WORK(&ha->nic_core_unrecoverable,
3311 qla83xx_nic_core_unrecoverable_work);
3312 }
3313
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003314skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 list_add_tail(&base_vha->list, &ha->vp_list);
3316 base_vha->host->irq = ha->pdev->irq;
3317
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003319 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003320 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3321 "Started qla2x00_timer with "
3322 "interval=%d.\n", WATCH_INTERVAL);
3323 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3324 "Detected hba at address=%p.\n",
3325 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
Arun Easie02587d2011-08-16 11:29:23 -07003327 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003328 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003329 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003330 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003331 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3332 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003333 if (ql2xenabledif == 1)
3334 prot = SHOST_DIX_TYPE0_PROTECTION;
Arun Easibad75002010-05-04 15:01:30 -07003335 scsi_host_set_prot(host,
Arun Easi8cb20492011-08-16 11:29:22 -07003336 prot | SHOST_DIF_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003337 | SHOST_DIF_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003338 | SHOST_DIF_TYPE3_PROTECTION
3339 | SHOST_DIX_TYPE1_PROTECTION
Arun Easi0c470872010-07-23 15:28:38 +05003340 | SHOST_DIX_TYPE2_PROTECTION
Arun Easibad75002010-05-04 15:01:30 -07003341 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003342
3343 guard = SHOST_DIX_GUARD_CRC;
3344
3345 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3346 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3347 guard |= SHOST_DIX_GUARD_IP;
3348
3349 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003350 } else
3351 base_vha->flags.difdix_supported = 0;
3352 }
3353
Giridhar Malavalia9083012010-04-12 17:59:55 -07003354 ha->isp_ops->enable_intrs(ha);
3355
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003356 if (IS_QLAFX00(ha)) {
3357 ret = qlafx00_fx_disc(base_vha,
3358 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3359 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3360 QLA_SG_ALL : 128;
3361 }
3362
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003363 ret = scsi_add_host(host, &pdev->dev);
3364 if (ret)
3365 goto probe_failed;
3366
Michael Reed14864002009-12-02 09:11:16 -06003367 base_vha->flags.init_done = 1;
3368 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003369 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003370
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003371 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3372 "Init done and hba is online.\n");
3373
Quinn Tran726b8542017-01-19 22:28:00 -08003374 if (qla_ini_mode_enabled(base_vha) ||
3375 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003376 scsi_scan_host(host);
3377 else
3378 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3379 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003380
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003381 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003382
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003383 if (IS_QLAFX00(ha)) {
3384 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003385 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3386
3387 /* Register system information */
3388 ret = qlafx00_fx_disc(base_vha,
3389 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3390 }
3391
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003395
Armen Baloyan03eb9122013-10-30 03:38:22 -04003396 ql_log(ql_log_info, base_vha, 0x00fb,
3397 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003398 ql_log(ql_log_info, base_vha, 0x00fc,
3399 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3400 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3401 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3402 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003403 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003405 qlt_add_target(ha, base_vha);
3406
Joe Lawrence6b383972014-08-26 17:12:29 -04003407 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003408
3409 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3410 return -ENODEV;
3411
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003412 if (ha->flags.detected_lr_sfp) {
3413 ql_log(ql_log_info, base_vha, 0xffff,
3414 "Reset chip to pick up LR SFP setting\n");
3415 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3416 qla2xxx_wake_dpc(base_vha);
3417 }
3418
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 return 0;
3420
3421probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003422 if (base_vha->timer_active)
3423 qla2x00_stop_timer(base_vha);
3424 base_vha->flags.online = 0;
3425 if (ha->dpc_thread) {
3426 struct task_struct *t = ha->dpc_thread;
3427
3428 ha->dpc_thread = NULL;
3429 kthread_stop(t);
3430 }
3431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003434 /*
3435 * Need to NULL out local req/rsp after
3436 * qla2x00_free_device => qla2x00_free_queues frees
3437 * what these are pointing to. Or else we'll
3438 * fall over below in qla2x00_free_req/rsp_que.
3439 */
3440 req = NULL;
3441 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003444 qla2x00_mem_free(ha);
3445 qla2x00_free_req_que(ha, req);
3446 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003447 qla2x00_clear_drv_active(ha);
3448
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003449iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003450 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003451 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003452 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003453 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003454 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003455 } else {
3456 if (ha->iobase)
3457 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003458 if (ha->cregbase)
3459 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003460 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003461 pci_release_selected_regions(ha->pdev, ha->bars);
3462 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003464disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003465 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003466 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468
Adrian Bunk4c993f72008-01-14 00:55:16 -08003469static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003470qla2x00_shutdown(struct pci_dev *pdev)
3471{
3472 scsi_qla_host_t *vha;
3473 struct qla_hw_data *ha;
3474
3475 vha = pci_get_drvdata(pdev);
3476 ha = vha->hw;
3477
Sawan Chandakefdb5762017-08-23 15:05:00 -07003478 ql_log(ql_log_info, vha, 0xfffa,
3479 "Adapter shutdown\n");
3480
3481 /*
3482 * Prevent future board_disable and wait
3483 * until any pending board_disable has completed.
3484 */
3485 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3486 cancel_work_sync(&ha->board_disable);
3487
3488 if (!atomic_read(&pdev->enable_cnt))
3489 return;
3490
Armen Baloyan42479342013-08-27 01:37:37 -04003491 /* Notify ISPFX00 firmware */
3492 if (IS_QLAFX00(ha))
3493 qlafx00_driver_shutdown(vha, 20);
3494
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003495 /* Turn-off FCE trace */
3496 if (ha->flags.fce_enabled) {
3497 qla2x00_disable_fce_trace(vha, NULL, NULL);
3498 ha->flags.fce_enabled = 0;
3499 }
3500
3501 /* Turn-off EFT trace */
3502 if (ha->eft)
3503 qla2x00_disable_eft_trace(vha);
3504
Quinn Tran3407fc32017-12-28 12:33:11 -08003505 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3506 if (ha->flags.fw_started)
3507 qla2x00_abort_isp_cleanup(vha);
3508 } else {
3509 /* Stop currently executing firmware. */
3510 qla2x00_try_to_stop_firmware(vha);
3511 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003512
3513 /* Turn adapter off line */
3514 vha->flags.online = 0;
3515
3516 /* turn-off interrupts on the card */
3517 if (ha->interrupts_on) {
3518 vha->flags.init_done = 0;
3519 ha->isp_ops->disable_intrs(ha);
3520 }
3521
3522 qla2x00_free_irqs(vha);
3523
3524 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003525
Chad Dupuis61d41f62014-09-25 05:17:02 -04003526 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003527 ql_log(ql_log_info, vha, 0xfffe,
3528 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003529}
3530
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003531/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003532static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003533qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003535 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003536 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537
Arun Easi43ebf162011-05-10 11:18:16 -07003538 mutex_lock(&ha->vport_lock);
3539 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003540 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003541
Arun Easi43ebf162011-05-10 11:18:16 -07003542 BUG_ON(base_vha->list.next == &ha->vp_list);
3543 /* This assumes first entry in ha->vp_list is always base vha */
3544 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003545 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003546
Arun Easi43ebf162011-05-10 11:18:16 -07003547 spin_unlock_irqrestore(&ha->vport_slock, flags);
3548 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003549
Arun Easi43ebf162011-05-10 11:18:16 -07003550 fc_vport_terminate(vha->fc_vport);
3551 scsi_host_put(vha->host);
3552
3553 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003554 }
Arun Easi43ebf162011-05-10 11:18:16 -07003555 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003556}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003557
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003558/* Stops all deferred work threads */
3559static void
3560qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3561{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003562 /* Cancel all work and destroy DPC workqueues */
3563 if (ha->dpc_lp_wq) {
3564 cancel_work_sync(&ha->idc_aen);
3565 destroy_workqueue(ha->dpc_lp_wq);
3566 ha->dpc_lp_wq = NULL;
3567 }
3568
3569 if (ha->dpc_hp_wq) {
3570 cancel_work_sync(&ha->nic_core_reset);
3571 cancel_work_sync(&ha->idc_state_handler);
3572 cancel_work_sync(&ha->nic_core_unrecoverable);
3573 destroy_workqueue(ha->dpc_hp_wq);
3574 ha->dpc_hp_wq = NULL;
3575 }
3576
Andrew Vasquezb9978762009-03-24 09:08:05 -07003577 /* Kill the kernel thread for this host */
3578 if (ha->dpc_thread) {
3579 struct task_struct *t = ha->dpc_thread;
3580
3581 /*
3582 * qla2xxx_wake_dpc checks for ->dpc_thread
3583 * so we need to zero it out.
3584 */
3585 ha->dpc_thread = NULL;
3586 kthread_stop(t);
3587 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003588}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003589
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003590static void
3591qla2x00_unmap_iobases(struct qla_hw_data *ha)
3592{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003593 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003594
Chad Dupuisf73cb692014-02-26 04:15:06 -05003595 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003596 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003597 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003598 } else {
3599 if (ha->iobase)
3600 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003601
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003602 if (ha->cregbase)
3603 iounmap(ha->cregbase);
3604
Giridhar Malavalia9083012010-04-12 17:59:55 -07003605 if (ha->mqiobase)
3606 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003607
Chad Dupuisf73cb692014-02-26 04:15:06 -05003608 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003609 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003610 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003611}
3612
3613static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003614qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003615{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003616 if (IS_QLA8044(ha)) {
3617 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003618 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003619 qla8044_idc_unlock(ha);
3620 } else if (IS_QLA82XX(ha)) {
3621 qla82xx_idc_lock(ha);
3622 qla82xx_clear_drv_active(ha);
3623 qla82xx_idc_unlock(ha);
3624 }
3625}
3626
3627static void
3628qla2x00_remove_one(struct pci_dev *pdev)
3629{
3630 scsi_qla_host_t *base_vha;
3631 struct qla_hw_data *ha;
3632
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003633 base_vha = pci_get_drvdata(pdev);
3634 ha = base_vha->hw;
Quinn Tran45235022018-07-18 14:29:53 -07003635 ql_log(ql_log_info, base_vha, 0xb079,
3636 "Removing driver\n");
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003637
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003638 /* Indicate device removal to prevent future board_disable and wait
3639 * until any pending board_disable has completed. */
3640 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3641 cancel_work_sync(&ha->board_disable);
3642
3643 /*
3644 * If the PCI device is disabled then there was a PCI-disconnect and
3645 * qla2x00_disable_board_on_pci_error has taken care of most of the
3646 * resources.
3647 */
3648 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003649 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3650 base_vha->gnl.l, base_vha->gnl.ldma);
3651
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003652 scsi_host_put(base_vha->host);
3653 kfree(ha);
3654 pci_set_drvdata(pdev, NULL);
3655 return;
3656 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003657 qla2x00_wait_for_hba_ready(base_vha);
3658
Quinn Tran45235022018-07-18 14:29:53 -07003659 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
3660 if (ha->flags.fw_started)
3661 qla2x00_abort_isp_cleanup(base_vha);
3662 } else if (!IS_QLAFX00(ha)) {
3663 if (IS_QLA8031(ha)) {
3664 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3665 "Clearing fcoe driver presence.\n");
3666 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3667 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3668 "Error while clearing DRV-Presence.\n");
3669 }
3670
3671 qla2x00_try_to_stop_firmware(base_vha);
3672 }
3673
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003674 qla2x00_wait_for_sess_deletion(base_vha);
3675
Quinn Tran726b8542017-01-19 22:28:00 -08003676 /*
3677 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003678 * where it was set first.
3679 */
3680 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3681 return;
3682
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003683 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003684
3685 qla_nvme_delete(base_vha);
3686
Quinn Tran726b8542017-01-19 22:28:00 -08003687 dma_free_coherent(&ha->pdev->dev,
3688 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003689
Quinn Trana4239942017-12-28 12:33:26 -08003690 vfree(base_vha->scan.l);
3691
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003692 if (IS_QLAFX00(ha))
3693 qlafx00_driver_shutdown(base_vha, 20);
3694
3695 qla2x00_delete_all_vps(ha, base_vha);
3696
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003697 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3698
3699 qla2x00_dfs_remove(base_vha);
3700
3701 qla84xx_put_chip(base_vha);
3702
3703 /* Disable timer */
3704 if (base_vha->timer_active)
3705 qla2x00_stop_timer(base_vha);
3706
3707 base_vha->flags.online = 0;
3708
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003709 /* free DMA memory */
3710 if (ha->exlogin_buf)
3711 qla2x00_free_exlogin_buffer(ha);
3712
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003713 /* free DMA memory */
3714 if (ha->exchoffld_buf)
3715 qla2x00_free_exchoffld_buffer(ha);
3716
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003717 qla2x00_destroy_deferred_work(ha);
3718
3719 qlt_remove_target(ha, base_vha);
3720
3721 qla2x00_free_sysfs_attr(base_vha, true);
3722
3723 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003724 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003725
3726 scsi_remove_host(base_vha->host);
3727
3728 qla2x00_free_device(base_vha);
3729
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003730 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003731
Arun Easid2749ff2014-09-25 05:16:51 -04003732 scsi_host_put(base_vha->host);
3733
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003734 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003735
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003736 pci_release_selected_regions(ha->pdev, ha->bars);
3737 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003739 pci_disable_pcie_error_reporting(pdev);
3740
Bernhard Walle665db932007-03-28 00:49:49 +02003741 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743
3744static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003745qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003747 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748
Andrew Vasquez85880802009-12-15 21:29:46 -08003749 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3750
3751 /* Disable timer */
3752 if (vha->timer_active)
3753 qla2x00_stop_timer(vha);
3754
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003755 qla25xx_delete_queues(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003756 vha->flags.online = 0;
3757
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003758 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003759 if (ha->interrupts_on) {
3760 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003761 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003762 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003763
Quinn Tran093df732016-12-12 14:40:09 -08003764 qla2x00_free_fcports(vha);
3765
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003766 qla2x00_free_irqs(vha);
3767
Quinn Tran093df732016-12-12 14:40:09 -08003768 /* Flush the work queue and remove it */
3769 if (ha->wq) {
3770 flush_workqueue(ha->wq);
3771 destroy_workqueue(ha->wq);
3772 ha->wq = NULL;
3773 }
3774
Chad Dupuis88670482010-07-23 15:28:30 +05003775
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003776 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003777
Giridhar Malavali08de2842011-08-16 11:31:44 -07003778 qla82xx_md_free(vha);
3779
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003780 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781}
3782
Chad Dupuis88670482010-07-23 15:28:30 +05003783void qla2x00_free_fcports(struct scsi_qla_host *vha)
3784{
3785 fc_port_t *fcport, *tfcport;
3786
3787 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3788 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003789 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003790 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003791 }
3792}
3793
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003794static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003795qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003796 int defer)
3797{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003798 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003799 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003800 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003801
3802 if (!fcport->rport)
3803 return;
3804
3805 rport = fcport->rport;
3806 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003807 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003808 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003809 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003810 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003811 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003812 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3813 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003814 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003815 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003816 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003817 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3818 "%s %8phN. rport %p roles %x\n",
3819 __func__, fcport->port_name, rport,
3820 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003821 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003822 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003823 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003824 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003825}
3826
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3829 *
3830 * Input: ha = adapter block pointer. fcport = port structure pointer.
3831 *
3832 * Return: None.
3833 *
3834 * Context:
3835 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003836void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003837 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003839 if (IS_QLAFX00(vha->hw)) {
3840 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3841 qla2x00_schedule_rport_del(vha, fcport, defer);
3842 return;
3843 }
3844
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003845 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003846 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003847 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003848 qla2x00_schedule_rport_del(vha, fcport, defer);
3849 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003850 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 * We may need to retry the login, so don't change the state of the
3852 * port but do the retries.
3853 */
3854 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003855 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856
3857 if (!do_login)
3858 return;
3859
Arun Easia1d02852015-08-04 13:38:02 -04003860 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861}
3862
3863/*
3864 * qla2x00_mark_all_devices_lost
3865 * Updates fcport state when device goes offline.
3866 *
3867 * Input:
3868 * ha = adapter block pointer.
3869 * fcport = port structure pointer.
3870 *
3871 * Return:
3872 * None.
3873 *
3874 * Context:
3875 */
3876void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003877qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878{
3879 fc_port_t *fcport;
3880
Quinn Tran83548fe2017-06-02 09:12:01 -07003881 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3882 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003883
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003884 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003885 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08003886 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003887
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003888 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003890
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 /*
3892 * No point in marking the device as lost, if the device is
3893 * already DEAD.
3894 */
3895 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3896 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003897 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003898 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003899 if (defer)
3900 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003901 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003902 qla2x00_schedule_rport_del(vha, fcport, defer);
3903 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 }
3905}
3906
3907/*
3908* qla2x00_mem_alloc
3909* Allocates adapter memory.
3910*
3911* Returns:
3912* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003913* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003915static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003916qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3917 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918{
3919 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920
Andrew Vasqueze8711082008-01-31 12:33:48 -08003921 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003923 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003924 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003926 if (qlt_mem_alloc(ha) < 0)
3927 goto fail_free_init_cb;
3928
Chad Dupuis642ef982012-02-09 11:15:57 -08003929 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3930 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003931 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003932 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933
Andrew Vasqueze8711082008-01-31 12:33:48 -08003934 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3935 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003936 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003938 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003939 /* Allocate cache for CT6 Ctx. */
3940 if (!ctx_cachep) {
3941 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3942 sizeof(struct ct6_dsd), 0,
3943 SLAB_HWCACHE_ALIGN, NULL);
3944 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003945 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003946 }
3947 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3948 ctx_cachep);
3949 if (!ha->ctx_mempool)
3950 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003951 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3952 "ctx_cachep=%p ctx_mempool=%p.\n",
3953 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003954 }
3955
Andrew Vasqueze8711082008-01-31 12:33:48 -08003956 /* Get memory for cached NVRAM */
3957 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
3958 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07003959 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003961 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
3962 ha->pdev->device);
3963 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3964 DMA_POOL_SIZE, 8, 0);
3965 if (!ha->s_dma_pool)
3966 goto fail_free_nvram;
3967
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003968 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
3969 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
3970 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
3971
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003972 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003973 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3974 DSD_LIST_DMA_POOL_SIZE, 8, 0);
3975 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003976 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
3977 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003978 goto fail_s_dma_pool;
3979 }
3980
3981 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
3982 FCP_CMND_DMA_POOL_SIZE, 8, 0);
3983 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003984 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
3985 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003986 goto fail_dl_dma_pool;
3987 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003988 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3989 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3990 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003991 }
3992
Andrew Vasqueze8711082008-01-31 12:33:48 -08003993 /* Allocate memory for SNS commands */
3994 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003995 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08003996 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003997 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003998 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003999 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004000 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08004001 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004002 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004003 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004004 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004006 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004007 goto fail_dma_pool;
4008 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004009 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004010 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004011 if (!ha->ct_sns)
4012 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004013 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4014 "ms_iocb=%p ct_sns=%p.\n",
4015 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 }
4017
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004018 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004019 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4020 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004021 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4022 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004023 goto fail_req;
4024 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004025 (*req)->length = req_len;
4026 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4027 ((*req)->length + 1) * sizeof(request_t),
4028 &(*req)->dma, GFP_KERNEL);
4029 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004030 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4031 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004032 goto fail_req_ring;
4033 }
4034 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004035 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4036 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004037 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4038 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004039 goto fail_rsp;
4040 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004041 (*rsp)->hw = ha;
4042 (*rsp)->length = rsp_len;
4043 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4044 ((*rsp)->length + 1) * sizeof(response_t),
4045 &(*rsp)->dma, GFP_KERNEL);
4046 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004047 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4048 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004049 goto fail_rsp_ring;
4050 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004051 (*req)->rsp = *rsp;
4052 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004053 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4054 "req=%p req->length=%d req->ring=%p rsp=%p "
4055 "rsp->length=%d rsp->ring=%p.\n",
4056 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4057 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004058 /* Allocate memory for NVRAM data for vports */
4059 if (ha->nvram_npiv_size) {
Kees Cook6396bb22018-06-12 14:03:40 -07004060 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4061 sizeof(struct qla_npiv_entry),
4062 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004063 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004064 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4065 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004066 goto fail_npiv_info;
4067 }
4068 } else
4069 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004070
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004071 /* Get consistent memory allocated for EX-INIT-CB. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004072 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004073 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4074 &ha->ex_init_cb_dma);
4075 if (!ha->ex_init_cb)
4076 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004077 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4078 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004079 }
4080
Giridhar Malavalia9083012010-04-12 17:59:55 -07004081 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4082
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004083 /* Get consistent memory allocated for Async Port-Database. */
4084 if (!IS_FWI2_CAPABLE(ha)) {
4085 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4086 &ha->async_pd_dma);
4087 if (!ha->async_pd)
4088 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004089 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4090 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004091 }
4092
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004093 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004094
4095 /* Allocate memory for our loop_id bitmap */
Kees Cook6396bb22018-06-12 14:03:40 -07004096 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4097 sizeof(long),
4098 GFP_KERNEL);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004099 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004100 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004101 else {
4102 qla2x00_set_reserved_loop_ids(ha);
4103 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004104 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004105 }
4106
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004107 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4108 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4109 if (!ha->sfp_data) {
4110 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4111 "Unable to allocate memory for SFP read-data.\n");
4112 goto fail_sfp_data;
4113 }
4114
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004115 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004116
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004117fail_sfp_data:
4118 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004119fail_loop_id_map:
4120 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004121fail_async_pd:
4122 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004123fail_ex_init_cb:
4124 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004125fail_npiv_info:
4126 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4127 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4128 (*rsp)->ring = NULL;
4129 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004130fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004131 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004132 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004134 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4135 sizeof(request_t), (*req)->ring, (*req)->dma);
4136 (*req)->ring = NULL;
4137 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004138fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004139 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004140 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004141fail_req:
4142 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4143 ha->ct_sns, ha->ct_sns_dma);
4144 ha->ct_sns = NULL;
4145 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004146fail_free_ms_iocb:
4147 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4148 ha->ms_iocb = NULL;
4149 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004150
4151 if (ha->sns_cmd)
4152 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4153 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004154fail_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004155 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004156 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4157 ha->fcp_cmnd_dma_pool = NULL;
4158 }
4159fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004160 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004161 dma_pool_destroy(ha->dl_dma_pool);
4162 ha->dl_dma_pool = NULL;
4163 }
4164fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004165 dma_pool_destroy(ha->s_dma_pool);
4166 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004167fail_free_nvram:
4168 kfree(ha->nvram);
4169 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004170fail_free_ctx_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004171 if (ha->ctx_mempool)
4172 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004173 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004174fail_free_srb_mempool:
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004175 if (ha->srb_mempool)
4176 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004177 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004178fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004179 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4180 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004181 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004182 ha->gid_list = NULL;
4183 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004184fail_free_tgt_mem:
4185 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004186fail_free_init_cb:
4187 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4188 ha->init_cb_dma);
4189 ha->init_cb = NULL;
4190 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004191fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004192 ql_log(ql_log_fatal, NULL, 0x0030,
4193 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004194 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195}
4196
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004197int
4198qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4199{
4200 int rval;
4201 uint16_t size, max_cnt, temp;
4202 struct qla_hw_data *ha = vha->hw;
4203
4204 /* Return if we don't need to alloacate any extended logins */
4205 if (!ql2xexlogins)
4206 return QLA_SUCCESS;
4207
Quinn Tran99e1b682017-06-02 09:12:03 -07004208 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4209 return QLA_SUCCESS;
4210
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004211 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4212 max_cnt = 0;
4213 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4214 if (rval != QLA_SUCCESS) {
4215 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4216 "Failed to get exlogin status.\n");
4217 return rval;
4218 }
4219
4220 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004221 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004222
Quinn Tran99e1b682017-06-02 09:12:03 -07004223 if (temp != ha->exlogin_size) {
4224 qla2x00_free_exlogin_buffer(ha);
4225 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004226
Quinn Tran99e1b682017-06-02 09:12:03 -07004227 ql_log(ql_log_info, vha, 0xd024,
4228 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4229 max_cnt, size, temp);
4230
4231 ql_log(ql_log_info, vha, 0xd025,
4232 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4233
4234 /* Get consistent memory for extended logins */
4235 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4236 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4237 if (!ha->exlogin_buf) {
4238 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004239 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004240 return -ENOMEM;
4241 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004242 }
4243
4244 /* Now configure the dma buffer */
4245 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4246 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004247 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004248 "Setup extended login buffer ****FAILED****.\n");
4249 qla2x00_free_exlogin_buffer(ha);
4250 }
4251
4252 return rval;
4253}
4254
4255/*
4256* qla2x00_free_exlogin_buffer
4257*
4258* Input:
4259* ha = adapter block pointer
4260*/
4261void
4262qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4263{
4264 if (ha->exlogin_buf) {
4265 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4266 ha->exlogin_buf, ha->exlogin_buf_dma);
4267 ha->exlogin_buf = NULL;
4268 ha->exlogin_size = 0;
4269 }
4270}
4271
Quinn Tran99e1b682017-06-02 09:12:03 -07004272static void
4273qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4274{
4275 u32 temp;
4276 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4277
Quinn Trand1e36352017-12-28 12:33:12 -08004278 if (max_cnt > vha->hw->max_exchg)
4279 max_cnt = vha->hw->max_exchg;
4280
Quinn Tran99e1b682017-06-02 09:12:03 -07004281 if (qla_ini_mode_enabled(vha)) {
4282 if (ql2xiniexchg > max_cnt)
4283 ql2xiniexchg = max_cnt;
4284
4285 if (ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4286 *ret_cnt = ql2xiniexchg;
4287 } else if (qla_tgt_mode_enabled(vha)) {
4288 if (ql2xexchoffld > max_cnt)
4289 ql2xexchoffld = max_cnt;
4290
4291 if (ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4292 *ret_cnt = ql2xexchoffld;
4293 } else if (qla_dual_mode_enabled(vha)) {
4294 temp = ql2xiniexchg + ql2xexchoffld;
4295 if (temp > max_cnt) {
4296 ql2xiniexchg -= (temp - max_cnt)/2;
4297 ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
4298 temp = max_cnt;
4299 }
4300
4301 if (temp > FW_DEF_EXCHANGES_CNT)
4302 *ret_cnt = temp;
4303 }
4304}
4305
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004306int
4307qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4308{
4309 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004310 u16 size, max_cnt;
4311 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004312 struct qla_hw_data *ha = vha->hw;
4313
Quinn Tran99e1b682017-06-02 09:12:03 -07004314 if (!ha->flags.exchoffld_enabled)
4315 return QLA_SUCCESS;
4316
4317 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004318 return QLA_SUCCESS;
4319
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004320 max_cnt = 0;
4321 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4322 if (rval != QLA_SUCCESS) {
4323 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4324 "Failed to get exlogin status.\n");
4325 return rval;
4326 }
4327
Quinn Trand1e36352017-12-28 12:33:12 -08004328 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4329 ql_log(ql_log_info, vha, 0xd014,
4330 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004331
Quinn Trand1e36352017-12-28 12:33:12 -08004332 totsz = actual_cnt * size;
4333
4334 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004335 qla2x00_free_exchoffld_buffer(ha);
Quinn Trand1e36352017-12-28 12:33:12 -08004336 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004337
Quinn Tran99e1b682017-06-02 09:12:03 -07004338 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004339 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4340 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004341
4342 ql_log(ql_log_info, vha, 0xd017,
4343 "Exchange Buffers requested size = 0x%x\n",
4344 ha->exchoffld_size);
4345
4346 /* Get consistent memory for extended logins */
4347 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4348 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4349 if (!ha->exchoffld_buf) {
4350 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004351 "Failed to allocate memory for Exchange Offload.\n");
4352
4353 if (ha->max_exchg >
4354 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4355 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4356 } else if (ha->max_exchg >
4357 (FW_DEF_EXCHANGES_CNT + 512)) {
4358 ha->max_exchg -= 512;
4359 } else {
4360 ha->flags.exchoffld_enabled = 0;
4361 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4362 "Disabling Exchange offload due to lack of memory\n");
4363 }
4364 ha->exchoffld_size = 0;
4365
Quinn Tran99e1b682017-06-02 09:12:03 -07004366 return -ENOMEM;
4367 }
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004368 }
4369
4370 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004371 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004372 if (rval) {
4373 ql_log(ql_log_fatal, vha, 0xd02e,
4374 "Setup exchange offload buffer ****FAILED****.\n");
4375 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004376 } else {
4377 /* re-adjust number of target exchange */
4378 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4379
4380 if (qla_ini_mode_enabled(vha))
4381 icb->exchange_count = 0;
4382 else
4383 icb->exchange_count = cpu_to_le16(ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004384 }
4385
4386 return rval;
4387}
4388
4389/*
4390* qla2x00_free_exchoffld_buffer
4391*
4392* Input:
4393* ha = adapter block pointer
4394*/
4395void
4396qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4397{
4398 if (ha->exchoffld_buf) {
4399 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4400 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4401 ha->exchoffld_buf = NULL;
4402 ha->exchoffld_size = 0;
4403 }
4404}
4405
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004407* qla2x00_free_fw_dump
4408* Frees fw dump stuff.
4409*
4410* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004411* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004412*/
4413static void
4414qla2x00_free_fw_dump(struct qla_hw_data *ha)
4415{
4416 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004417 dma_free_coherent(&ha->pdev->dev,
4418 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004419
Chad Dupuisf73cb692014-02-26 04:15:06 -05004420 if (ha->eft)
4421 dma_free_coherent(&ha->pdev->dev,
4422 EFT_SIZE, ha->eft, ha->eft_dma);
4423
4424 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004425 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004426 if (ha->fw_dump_template)
4427 vfree(ha->fw_dump_template);
4428
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004429 ha->fce = NULL;
4430 ha->fce_dma = 0;
4431 ha->eft = NULL;
4432 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004433 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004434 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004435 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004436 ha->fw_dump = NULL;
4437 ha->fw_dump_len = 0;
4438 ha->fw_dump_template = NULL;
4439 ha->fw_dump_template_len = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004440}
4441
4442/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443* qla2x00_mem_free
4444* Frees all adapter allocated memory.
4445*
4446* Input:
4447* ha = adapter block pointer.
4448*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004449static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004450qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004452 qla2x00_free_fw_dump(ha);
4453
Saurav Kashyap81178772012-08-22 14:21:04 -04004454 if (ha->mctp_dump)
4455 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4456 ha->mctp_dump_dma);
4457
Andrew Vasqueze8711082008-01-31 12:33:48 -08004458 if (ha->srb_mempool)
4459 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004461 if (ha->dcbx_tlv)
4462 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4463 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4464
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004465 if (ha->xgmac_data)
4466 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4467 ha->xgmac_data, ha->xgmac_data_dma);
4468
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 if (ha->sns_cmd)
4470 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004471 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472
4473 if (ha->ct_sns)
4474 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004475 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476
Andrew Vasquez88729e52006-06-23 16:10:50 -07004477 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004478 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4479 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004480
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 if (ha->ms_iocb)
4482 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4483
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004484 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004485 dma_pool_free(ha->s_dma_pool,
4486 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004487
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004488 if (ha->async_pd)
4489 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4490
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 if (ha->s_dma_pool)
4492 dma_pool_destroy(ha->s_dma_pool);
4493
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004495 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4496 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497
Giridhar Malavalia9083012010-04-12 17:59:55 -07004498 if (IS_QLA82XX(ha)) {
4499 if (!list_empty(&ha->gbl_dsd_list)) {
4500 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4501
4502 /* clean up allocated prev pool */
4503 list_for_each_entry_safe(dsd_ptr,
4504 tdsd_ptr, &ha->gbl_dsd_list, list) {
4505 dma_pool_free(ha->dl_dma_pool,
4506 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4507 list_del(&dsd_ptr->list);
4508 kfree(dsd_ptr);
4509 }
4510 }
4511 }
4512
4513 if (ha->dl_dma_pool)
4514 dma_pool_destroy(ha->dl_dma_pool);
4515
4516 if (ha->fcp_cmnd_dma_pool)
4517 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4518
4519 if (ha->ctx_mempool)
4520 mempool_destroy(ha->ctx_mempool);
4521
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004522 qlt_mem_free(ha);
4523
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004524 if (ha->init_cb)
4525 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004526 ha->init_cb, ha->init_cb_dma);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004527
Bill Kuzeja6d634062018-03-23 10:37:25 -04004528 vfree(ha->optrom_buffer);
4529 kfree(ha->nvram);
4530 kfree(ha->npiv_info);
4531 kfree(ha->swl);
4532 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533
Andrew Vasqueze8711082008-01-31 12:33:48 -08004534 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004535 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 ha->sns_cmd = NULL;
4537 ha->sns_cmd_dma = 0;
4538 ha->ct_sns = NULL;
4539 ha->ct_sns_dma = 0;
4540 ha->ms_iocb = NULL;
4541 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 ha->init_cb = NULL;
4543 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004544 ha->ex_init_cb = NULL;
4545 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004546 ha->async_pd = NULL;
4547 ha->async_pd_dma = 0;
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004548 ha->loop_id_map = NULL;
4549 ha->npiv_info = NULL;
4550 ha->optrom_buffer = NULL;
4551 ha->swl = NULL;
4552 ha->nvram = NULL;
4553 ha->mctp_dump = NULL;
4554 ha->dcbx_tlv = NULL;
4555 ha->xgmac_data = NULL;
4556 ha->sfp_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557
4558 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004559 ha->dl_dma_pool = NULL;
4560 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 ha->gid_list = NULL;
4563 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004564
4565 ha->tgt.atio_ring = NULL;
4566 ha->tgt.atio_dma = 0;
4567 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004568}
4569
4570struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4571 struct qla_hw_data *ha)
4572{
4573 struct Scsi_Host *host;
4574 struct scsi_qla_host *vha = NULL;
4575
4576 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004577 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004578 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4579 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004580 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004581 }
4582
4583 /* Clear our data area */
4584 vha = shost_priv(host);
4585 memset(vha, 0, sizeof(scsi_qla_host_t));
4586
4587 vha->host = host;
4588 vha->host_no = host->host_no;
4589 vha->hw = ha;
4590
4591 INIT_LIST_HEAD(&vha->vp_fcports);
4592 INIT_LIST_HEAD(&vha->work_list);
4593 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004594 INIT_LIST_HEAD(&vha->qla_cmd_list);
4595 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004596 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004597 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004598 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004599 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004600 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004601 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004602 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004603
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004604 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004605 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004606 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004607 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004608
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004609 vha->gnl.size = sizeof(struct get_name_list_extended) *
4610 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004611 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4612 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4613 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004614 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004615 "Alloc failed for name list.\n");
4616 scsi_remove_host(vha->host);
4617 return NULL;
4618 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004619
Quinn Trana4239942017-12-28 12:33:26 -08004620 /* todo: what about ext login? */
4621 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4622 vha->scan.l = vmalloc(vha->scan.size);
4623 if (!vha->scan.l) {
4624 ql_log(ql_log_fatal, vha, 0xd04a,
4625 "Alloc failed for scan database.\n");
4626 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4627 vha->gnl.l, vha->gnl.ldma);
4628 scsi_remove_host(vha->host);
4629 return NULL;
4630 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004631 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004632
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004633 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004634 ql_dbg(ql_dbg_init, vha, 0x0041,
4635 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4636 vha->host, vha->hw, vha,
4637 dev_name(&(ha->pdev->dev)));
4638
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004639 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640}
4641
Quinn Tran726b8542017-01-19 22:28:00 -08004642struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004643qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004644{
4645 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004646 uint8_t bail;
4647
4648 QLA_VHA_MARK_BUSY(vha, bail);
4649 if (bail)
4650 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004651
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004652 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004653 if (!e) {
4654 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004655 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004656 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004657
4658 INIT_LIST_HEAD(&e->list);
4659 e->type = type;
4660 e->flags = QLA_EVT_FLAG_FREE;
4661 return e;
4662}
4663
Quinn Tran726b8542017-01-19 22:28:00 -08004664int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004665qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004666{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004667 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004668 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004669
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004670 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004671 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004672
4673 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4674 q = true;
4675
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004676 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004677
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004678 if (q)
4679 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004680
Andrew Vasquez0971de72008-04-03 13:13:18 -07004681 return QLA_SUCCESS;
4682}
4683
4684int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004685qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004686 u32 data)
4687{
4688 struct qla_work_evt *e;
4689
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004690 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004691 if (!e)
4692 return QLA_FUNCTION_FAILED;
4693
4694 e->u.aen.code = code;
4695 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004696 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004697}
4698
Andrew Vasquez8a659572009-02-08 20:50:12 -08004699int
4700qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4701{
4702 struct qla_work_evt *e;
4703
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004704 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004705 if (!e)
4706 return QLA_FUNCTION_FAILED;
4707
4708 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004709 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004710}
4711
Andrew Vasquezac280b62009-08-20 11:06:05 -07004712#define qla2x00_post_async_work(name, type) \
4713int qla2x00_post_async_##name##_work( \
4714 struct scsi_qla_host *vha, \
4715 fc_port_t *fcport, uint16_t *data) \
4716{ \
4717 struct qla_work_evt *e; \
4718 \
4719 e = qla2x00_alloc_work(vha, type); \
4720 if (!e) \
4721 return QLA_FUNCTION_FAILED; \
4722 \
4723 e->u.logio.fcport = fcport; \
4724 if (data) { \
4725 e->u.logio.data[0] = data[0]; \
4726 e->u.logio.data[1] = data[1]; \
4727 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08004728 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07004729 return qla2x00_post_work(vha, e); \
4730}
4731
4732qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004733qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4734qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004735qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
4736qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
Quinn Tran11aea162017-12-28 12:33:20 -08004737qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4738qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004739
Andrew Vasquez3420d362009-10-13 15:16:45 -07004740int
4741qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4742{
4743 struct qla_work_evt *e;
4744
4745 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4746 if (!e)
4747 return QLA_FUNCTION_FAILED;
4748
4749 e->u.uevent.code = code;
4750 return qla2x00_post_work(vha, e);
4751}
4752
4753static void
4754qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4755{
4756 char event_string[40];
4757 char *envp[] = { event_string, NULL };
4758
4759 switch (code) {
4760 case QLA_UEVENT_CODE_FW_DUMP:
4761 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4762 vha->host_no);
4763 break;
4764 default:
4765 /* do nothing */
4766 break;
4767 }
4768 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4769}
4770
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004771int
4772qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4773 uint32_t *data, int cnt)
4774{
4775 struct qla_work_evt *e;
4776
4777 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4778 if (!e)
4779 return QLA_FUNCTION_FAILED;
4780
4781 e->u.aenfx.evtcode = evtcode;
4782 e->u.aenfx.count = cnt;
4783 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4784 return qla2x00_post_work(vha, e);
4785}
4786
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004787void qla24xx_sched_upd_fcport(fc_port_t *fcport)
Quinn Tran726b8542017-01-19 22:28:00 -08004788{
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004789 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08004790
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004791 if (IS_SW_RESV_ADDR(fcport->d_id))
4792 return;
Quinn Tran726b8542017-01-19 22:28:00 -08004793
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004794 spin_lock_irqsave(&fcport->vha->work_lock, flags);
4795 if (fcport->disc_state == DSC_UPD_FCPORT) {
4796 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4797 return;
4798 }
4799 fcport->jiffies_at_registration = jiffies;
4800 fcport->sec_since_registration = 0;
4801 fcport->next_disc_state = DSC_DELETED;
4802 fcport->disc_state = DSC_UPD_FCPORT;
4803 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4804
4805 queue_work(system_unbound_wq, &fcport->reg_work);
Quinn Tran726b8542017-01-19 22:28:00 -08004806}
4807
4808static
4809void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
4810{
4811 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07004812 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08004813 struct qlt_plogi_ack_t *pla =
4814 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07004815 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08004816
Quinn Tran9cd883f2017-12-28 12:33:24 -08004817 ql_dbg(ql_dbg_disc, vha, 0xffff,
4818 "%s %d %8phC enter\n",
4819 __func__, __LINE__, e->u.new_sess.port_name);
4820
Quinn Tran726b8542017-01-19 22:28:00 -08004821 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4822 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
4823 if (fcport) {
4824 fcport->d_id = e->u.new_sess.id;
4825 if (pla) {
4826 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004827 memcpy(fcport->node_name,
4828 pla->iocb.u.isp24.u.plogi.node_name,
4829 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08004830 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
4831 /* we took an extra ref_count to prevent PLOGI ACK when
4832 * fcport/sess has not been created.
4833 */
4834 pla->ref_count--;
4835 }
4836 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07004837 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004838 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4839 if (fcport) {
4840 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08004841 fcport->flags |= FCF_FABRIC_DEVICE;
4842 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran8777e432018-08-02 13:16:57 -07004843 if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08004844 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08004845
Quinn Tran8777e432018-08-02 13:16:57 -07004846 if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08004847 fcport->fc4_type = FC4_TYPE_OTHER;
4848 fcport->fc4f_nvme = FC4_TYPE_NVME;
4849 }
Quinn Tran33b28352018-03-20 23:09:40 -07004850
Quinn Tran726b8542017-01-19 22:28:00 -08004851 memcpy(fcport->port_name, e->u.new_sess.port_name,
4852 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07004853 } else {
4854 ql_dbg(ql_dbg_disc, vha, 0xffff,
4855 "%s %8phC mem alloc fail.\n",
4856 __func__, e->u.new_sess.port_name);
4857
4858 if (pla)
4859 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4860 return;
4861 }
4862
4863 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08004864 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07004865 tfcp = qla2x00_find_fcport_by_wwpn(vha,
4866 e->u.new_sess.port_name, 1);
4867 if (tfcp) {
4868 /* should rarily happen */
4869 ql_dbg(ql_dbg_disc, vha, 0xffff,
4870 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
4871 __func__, tfcp->port_name, tfcp->disc_state,
4872 tfcp->fw_login_state);
4873
4874 free_fcport = 1;
4875 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08004876 list_add_tail(&fcport->list, &vha->vp_fcports);
4877
Quinn Tran19759032017-12-04 14:45:15 -08004878 }
4879 if (pla) {
4880 qlt_plogi_ack_link(vha, pla, fcport,
4881 QLT_PLOGI_LINK_SAME_WWN);
4882 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08004883 }
4884 }
4885 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4886
4887 if (fcport) {
Quinn Trana4239942017-12-28 12:33:26 -08004888 fcport->id_changed = 1;
4889 fcport->scan_state = QLA_FCPORT_FOUND;
4890 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
4891
Quinn Tran5ef696a2017-12-04 14:45:05 -08004892 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08004893 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
4894 u16 wd3_lo;
4895
4896 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4897 fcport->local = 0;
4898 fcport->loop_id =
4899 le16_to_cpu(
4900 pla->iocb.u.isp24.nport_handle);
4901 fcport->fw_login_state = DSC_LS_PRLI_PEND;
4902 wd3_lo =
4903 le16_to_cpu(
4904 pla->iocb.u.isp24.u.prli.wd3_lo);
4905
4906 if (wd3_lo & BIT_7)
4907 fcport->conf_compl_supported = 1;
4908
4909 if ((wd3_lo & BIT_4) == 0)
4910 fcport->port_type = FCT_INITIATOR;
4911 else
4912 fcport->port_type = FCT_TARGET;
4913 }
Quinn Tran726b8542017-01-19 22:28:00 -08004914 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08004915 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004916 fc_port_t *dfcp = NULL;
4917
Quinn Tran5ef696a2017-12-04 14:45:05 -08004918 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4919 tfcp = qla2x00_find_fcport_by_nportid(vha,
4920 &e->u.new_sess.id, 1);
4921 if (tfcp && (tfcp != fcport)) {
4922 /*
4923 * We have a conflict fcport with same NportID.
4924 */
4925 ql_dbg(ql_dbg_disc, vha, 0xffff,
4926 "%s %8phC found conflict b4 add. DS %d LS %d\n",
4927 __func__, tfcp->port_name, tfcp->disc_state,
4928 tfcp->fw_login_state);
4929
4930 switch (tfcp->disc_state) {
4931 case DSC_DELETED:
4932 break;
4933 case DSC_DELETE_PEND:
4934 fcport->login_pause = 1;
4935 tfcp->conflict = fcport;
4936 break;
4937 default:
4938 fcport->login_pause = 1;
4939 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004940 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08004941 break;
4942 }
4943 }
4944 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01004945 if (dfcp)
4946 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08004947
Quinn Trana4239942017-12-28 12:33:26 -08004948
Quinn Tran8777e432018-08-02 13:16:57 -07004949 if (N2N_TOPO(vha->hw))
4950 fcport->flags &= ~FCF_FABRIC_DEVICE;
4951
4952 if (N2N_TOPO(vha->hw)) {
4953 if (vha->flags.nvme_enabled) {
4954 fcport->fc4f_nvme = 1;
4955 fcport->n2n_flag = 1;
4956 }
4957 fcport->fw_login_state = 0;
4958 /*
4959 * wait link init done before sending login
4960 */
4961 } else {
4962 qla24xx_fcport_handle_login(vha, fcport);
4963 }
Quinn Tran5ef696a2017-12-04 14:45:05 -08004964 }
Quinn Tran726b8542017-01-19 22:28:00 -08004965 }
Quinn Tranb5d15312017-08-30 10:16:49 -07004966
4967 if (free_fcport) {
4968 qla2x00_free_fcport(fcport);
4969 if (pla)
4970 kmem_cache_free(qla_tgt_plogi_cachep, pla);
4971 }
Quinn Tran726b8542017-01-19 22:28:00 -08004972}
4973
Quinn Trane374f9f2017-12-28 12:33:31 -08004974static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
4975{
4976 struct srb *sp = e->u.iosb.sp;
4977 int rval;
4978
4979 rval = qla2x00_start_sp(sp);
4980 if (rval != QLA_SUCCESS) {
4981 ql_dbg(ql_dbg_disc, vha, 0x2043,
4982 "%s: %s: Re-issue IOCB failed (%d).\n",
4983 __func__, sp->name, rval);
4984 qla24xx_sp_unmap(vha, sp);
4985 }
4986}
4987
Andrew Vasquezac280b62009-08-20 11:06:05 -07004988void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004989qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004990{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004991 struct qla_work_evt *e, *tmp;
4992 unsigned long flags;
4993 LIST_HEAD(work);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004994
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004995 spin_lock_irqsave(&vha->work_lock, flags);
4996 list_splice_init(&vha->work_list, &work);
4997 spin_unlock_irqrestore(&vha->work_lock, flags);
4998
4999 list_for_each_entry_safe(e, tmp, &work, list) {
Andrew Vasquez0971de72008-04-03 13:13:18 -07005000 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005001
5002 switch (e->type) {
5003 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005004 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07005005 e->u.aen.code, e->u.aen.data);
5006 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08005007 case QLA_EVT_IDC_ACK:
5008 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5009 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005010 case QLA_EVT_ASYNC_LOGIN:
5011 qla2x00_async_login(vha, e->u.logio.fcport,
5012 e->u.logio.data);
5013 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005014 case QLA_EVT_ASYNC_LOGOUT:
5015 qla2x00_async_logout(vha, e->u.logio.fcport);
5016 break;
5017 case QLA_EVT_ASYNC_LOGOUT_DONE:
5018 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5019 e->u.logio.data);
5020 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005021 case QLA_EVT_ASYNC_ADISC:
5022 qla2x00_async_adisc(vha, e->u.logio.fcport,
5023 e->u.logio.data);
5024 break;
5025 case QLA_EVT_ASYNC_ADISC_DONE:
5026 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
5027 e->u.logio.data);
5028 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005029 case QLA_EVT_UEVENT:
5030 qla2x00_uevent_emit(vha, e->u.uevent.code);
5031 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005032 case QLA_EVT_AENFX:
5033 qlafx00_process_aen(vha, e);
5034 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005035 case QLA_EVT_GIDPN:
5036 qla24xx_async_gidpn(vha, e->u.fcport.fcport);
5037 break;
5038 case QLA_EVT_GPNID:
5039 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5040 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005041 case QLA_EVT_UNMAP:
5042 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005043 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005044 case QLA_EVT_RELOGIN:
5045 qla2x00_relogin(vha);
5046 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005047 case QLA_EVT_NEW_SESS:
5048 qla24xx_create_new_sess(vha, e);
5049 break;
5050 case QLA_EVT_GPDB:
5051 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5052 e->u.fcport.opt);
5053 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005054 case QLA_EVT_PRLI:
5055 qla24xx_async_prli(vha, e->u.fcport.fcport);
5056 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005057 case QLA_EVT_GPSC:
5058 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5059 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005060 case QLA_EVT_GNL:
5061 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5062 break;
5063 case QLA_EVT_NACK:
5064 qla24xx_do_nack_work(vha, e);
5065 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005066 case QLA_EVT_ASYNC_PRLO:
5067 qla2x00_async_prlo(vha, e->u.logio.fcport);
5068 break;
5069 case QLA_EVT_ASYNC_PRLO_DONE:
5070 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5071 e->u.logio.data);
5072 break;
Quinn Trana4239942017-12-28 12:33:26 -08005073 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005074 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5075 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005076 break;
5077 case QLA_EVT_GPNFT_DONE:
5078 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5079 break;
5080 case QLA_EVT_GNNFT_DONE:
5081 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5082 break;
5083 case QLA_EVT_GNNID:
5084 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5085 break;
5086 case QLA_EVT_GFPNID:
5087 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5088 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005089 case QLA_EVT_SP_RETRY:
5090 qla_sp_retry(vha, e);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005091 break;
5092 case QLA_EVT_IIDMA:
5093 qla_do_iidma_work(vha, e->u.fcport.fcport);
5094 break;
Quinn Tran8777e432018-08-02 13:16:57 -07005095 case QLA_EVT_ELS_PLOGI:
5096 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5097 e->u.fcport.fcport, false);
5098 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005099 }
5100 if (e->flags & QLA_EVT_FLAG_FREE)
5101 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005102
5103 /* For each work completed decrement vha ref count */
5104 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005105 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005106}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005107
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005108int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5109{
5110 struct qla_work_evt *e;
5111
5112 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5113
5114 if (!e) {
5115 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5116 return QLA_FUNCTION_FAILED;
5117 }
5118
5119 return qla2x00_post_work(vha, e);
5120}
5121
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005122/* Relogins all the fcports of a vport
5123 * Context: dpc thread
5124 */
5125void qla2x00_relogin(struct scsi_qla_host *vha)
5126{
5127 fc_port_t *fcport;
Quinn Tran23dd98a2018-08-02 13:16:45 -07005128 int status, relogin_needed = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005129 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005130
5131 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005132 /*
5133 * If the port is not ONLINE then try to login
5134 * to it if we haven't run out of retries.
5135 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005136 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran23dd98a2018-08-02 13:16:45 -07005137 fcport->login_retry) {
5138 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5139 fcport->disc_state == DSC_LOGIN_COMPLETE)
5140 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005141
Quinn Tran23dd98a2018-08-02 13:16:45 -07005142 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5143 fcport->disc_state == DSC_DELETE_PEND) {
5144 relogin_needed = 1;
5145 } else {
5146 if (vha->hw->current_topology != ISP_CFG_NL) {
5147 memset(&ea, 0, sizeof(ea));
5148 ea.event = FCME_RELOGIN;
5149 ea.fcport = fcport;
5150 qla2x00_fcport_event_handler(vha, &ea);
5151 } else if (vha->hw->current_topology ==
5152 ISP_CFG_NL) {
5153 fcport->login_retry--;
5154 status =
5155 qla2x00_local_device_login(vha,
5156 fcport);
5157 if (status == QLA_SUCCESS) {
5158 fcport->old_loop_id =
5159 fcport->loop_id;
5160 ql_dbg(ql_dbg_disc, vha, 0x2003,
5161 "Port login OK: logged in ID 0x%x.\n",
5162 fcport->loop_id);
5163 qla2x00_update_fcport
5164 (vha, fcport);
5165 } else if (status == 1) {
5166 set_bit(RELOGIN_NEEDED,
5167 &vha->dpc_flags);
5168 /* retry the login again */
5169 ql_dbg(ql_dbg_disc, vha, 0x2007,
5170 "Retrying %d login again loop_id 0x%x.\n",
5171 fcport->login_retry,
5172 fcport->loop_id);
5173 } else {
5174 fcport->login_retry = 0;
5175 }
5176
5177 if (fcport->login_retry == 0 &&
5178 status != QLA_SUCCESS)
5179 qla2x00_clear_loop_id(fcport);
5180 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005181 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005182 }
5183 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5184 break;
5185 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005186
Quinn Tran23dd98a2018-08-02 13:16:45 -07005187 if (relogin_needed)
5188 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5189
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005190 ql_dbg(ql_dbg_disc, vha, 0x400e,
5191 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005192}
5193
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005194/* Schedule work on any of the dpc-workqueues */
5195void
5196qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5197{
5198 struct qla_hw_data *ha = base_vha->hw;
5199
5200 switch (work_code) {
5201 case MBA_IDC_AEN: /* 0x8200 */
5202 if (ha->dpc_lp_wq)
5203 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5204 break;
5205
5206 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5207 if (!ha->flags.nic_core_reset_hdlr_active) {
5208 if (ha->dpc_hp_wq)
5209 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5210 } else
5211 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5212 "NIC Core reset is already active. Skip "
5213 "scheduling it again.\n");
5214 break;
5215 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5216 if (ha->dpc_hp_wq)
5217 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5218 break;
5219 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5220 if (ha->dpc_hp_wq)
5221 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5222 break;
5223 default:
5224 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005225 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005226 }
5227
5228 return;
5229}
5230
5231/* Work: Perform NIC Core Unrecoverable state handling */
5232void
5233qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5234{
5235 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005236 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005237 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5238 uint32_t dev_state = 0;
5239
5240 qla83xx_idc_lock(base_vha, 0);
5241 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5242 qla83xx_reset_ownership(base_vha);
5243 if (ha->flags.nic_core_reset_owner) {
5244 ha->flags.nic_core_reset_owner = 0;
5245 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5246 QLA8XXX_DEV_FAILED);
5247 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5248 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5249 }
5250 qla83xx_idc_unlock(base_vha, 0);
5251}
5252
5253/* Work: Execute IDC state handler */
5254void
5255qla83xx_idc_state_handler_work(struct work_struct *work)
5256{
5257 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005258 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005259 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5260 uint32_t dev_state = 0;
5261
5262 qla83xx_idc_lock(base_vha, 0);
5263 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5264 if (dev_state == QLA8XXX_DEV_FAILED ||
5265 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5266 qla83xx_idc_state_handler(base_vha);
5267 qla83xx_idc_unlock(base_vha, 0);
5268}
5269
Saurav Kashyapfa492632012-11-21 02:40:29 -05005270static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005271qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5272{
5273 int rval = QLA_SUCCESS;
5274 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5275 uint32_t heart_beat_counter1, heart_beat_counter2;
5276
5277 do {
5278 if (time_after(jiffies, heart_beat_wait)) {
5279 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5280 "Nic Core f/w is not alive.\n");
5281 rval = QLA_FUNCTION_FAILED;
5282 break;
5283 }
5284
5285 qla83xx_idc_lock(base_vha, 0);
5286 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5287 &heart_beat_counter1);
5288 qla83xx_idc_unlock(base_vha, 0);
5289 msleep(100);
5290 qla83xx_idc_lock(base_vha, 0);
5291 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5292 &heart_beat_counter2);
5293 qla83xx_idc_unlock(base_vha, 0);
5294 } while (heart_beat_counter1 == heart_beat_counter2);
5295
5296 return rval;
5297}
5298
5299/* Work: Perform NIC Core Reset handling */
5300void
5301qla83xx_nic_core_reset_work(struct work_struct *work)
5302{
5303 struct qla_hw_data *ha =
5304 container_of(work, struct qla_hw_data, nic_core_reset);
5305 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5306 uint32_t dev_state = 0;
5307
Saurav Kashyap81178772012-08-22 14:21:04 -04005308 if (IS_QLA2031(ha)) {
5309 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5310 ql_log(ql_log_warn, base_vha, 0xb081,
5311 "Failed to dump mctp\n");
5312 return;
5313 }
5314
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005315 if (!ha->flags.nic_core_reset_hdlr_active) {
5316 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5317 qla83xx_idc_lock(base_vha, 0);
5318 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5319 &dev_state);
5320 qla83xx_idc_unlock(base_vha, 0);
5321 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5322 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5323 "Nic Core f/w is alive.\n");
5324 return;
5325 }
5326 }
5327
5328 ha->flags.nic_core_reset_hdlr_active = 1;
5329 if (qla83xx_nic_core_reset(base_vha)) {
5330 /* NIC Core reset failed. */
5331 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5332 "NIC Core reset failed.\n");
5333 }
5334 ha->flags.nic_core_reset_hdlr_active = 0;
5335 }
5336}
5337
5338/* Work: Handle 8200 IDC aens */
5339void
5340qla83xx_service_idc_aen(struct work_struct *work)
5341{
5342 struct qla_hw_data *ha =
5343 container_of(work, struct qla_hw_data, idc_aen);
5344 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5345 uint32_t dev_state, idc_control;
5346
5347 qla83xx_idc_lock(base_vha, 0);
5348 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5349 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5350 qla83xx_idc_unlock(base_vha, 0);
5351 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5352 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5353 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5354 "Application requested NIC Core Reset.\n");
5355 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5356 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5357 QLA_SUCCESS) {
5358 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5359 "Other protocol driver requested NIC Core Reset.\n");
5360 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5361 }
5362 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5363 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5364 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5365 }
5366}
5367
5368static void
5369qla83xx_wait_logic(void)
5370{
5371 int i;
5372
5373 /* Yield CPU */
5374 if (!in_interrupt()) {
5375 /*
5376 * Wait about 200ms before retrying again.
5377 * This controls the number of retries for single
5378 * lock operation.
5379 */
5380 msleep(100);
5381 schedule();
5382 } else {
5383 for (i = 0; i < 20; i++)
5384 cpu_relax(); /* This a nop instr on i386 */
5385 }
5386}
5387
Saurav Kashyapfa492632012-11-21 02:40:29 -05005388static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005389qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5390{
5391 int rval;
5392 uint32_t data;
5393 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5394 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5395 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005396 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5397 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005398
5399 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5400 if (rval)
5401 return rval;
5402
5403 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5404 return QLA_SUCCESS;
5405 } else {
5406 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5407 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5408 data);
5409 if (rval)
5410 return rval;
5411
5412 msleep(200);
5413
5414 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5415 &data);
5416 if (rval)
5417 return rval;
5418
5419 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5420 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5421 ~(idc_lck_rcvry_stage_mask));
5422 rval = qla83xx_wr_reg(base_vha,
5423 QLA83XX_IDC_LOCK_RECOVERY, data);
5424 if (rval)
5425 return rval;
5426
5427 /* Forcefully perform IDC UnLock */
5428 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5429 &data);
5430 if (rval)
5431 return rval;
5432 /* Clear lock-id by setting 0xff */
5433 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5434 0xff);
5435 if (rval)
5436 return rval;
5437 /* Clear lock-recovery by setting 0x0 */
5438 rval = qla83xx_wr_reg(base_vha,
5439 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5440 if (rval)
5441 return rval;
5442 } else
5443 return QLA_SUCCESS;
5444 }
5445
5446 return rval;
5447}
5448
Saurav Kashyapfa492632012-11-21 02:40:29 -05005449static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005450qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5451{
5452 int rval = QLA_SUCCESS;
5453 uint32_t o_drv_lockid, n_drv_lockid;
5454 unsigned long lock_recovery_timeout;
5455
5456 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5457retry_lockid:
5458 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5459 if (rval)
5460 goto exit;
5461
5462 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5463 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5464 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5465 return QLA_SUCCESS;
5466 else
5467 return QLA_FUNCTION_FAILED;
5468 }
5469
5470 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5471 if (rval)
5472 goto exit;
5473
5474 if (o_drv_lockid == n_drv_lockid) {
5475 qla83xx_wait_logic();
5476 goto retry_lockid;
5477 } else
5478 return QLA_SUCCESS;
5479
5480exit:
5481 return rval;
5482}
5483
5484void
5485qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5486{
5487 uint16_t options = (requester_id << 15) | BIT_6;
5488 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005489 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005490 struct qla_hw_data *ha = base_vha->hw;
5491
5492 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5493retry_lock:
5494 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5495 == QLA_SUCCESS) {
5496 if (data) {
5497 /* Setting lock-id to our function-number */
5498 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5499 ha->portnum);
5500 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005501 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5502 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005503 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005504 "Failed to acquire IDC lock, acquired by %d, "
5505 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005506
5507 /* Retry/Perform IDC-Lock recovery */
5508 if (qla83xx_idc_lock_recovery(base_vha)
5509 == QLA_SUCCESS) {
5510 qla83xx_wait_logic();
5511 goto retry_lock;
5512 } else
5513 ql_log(ql_log_warn, base_vha, 0xb075,
5514 "IDC Lock recovery FAILED.\n");
5515 }
5516
5517 }
5518
5519 return;
5520
5521 /* XXX: IDC-lock implementation using access-control mbx */
5522retry_lock2:
5523 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5524 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5525 "Failed to acquire IDC lock. retrying...\n");
5526 /* Retry/Perform IDC-Lock recovery */
5527 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5528 qla83xx_wait_logic();
5529 goto retry_lock2;
5530 } else
5531 ql_log(ql_log_warn, base_vha, 0xb076,
5532 "IDC Lock recovery FAILED.\n");
5533 }
5534
5535 return;
5536}
5537
5538void
5539qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5540{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005541#if 0
5542 uint16_t options = (requester_id << 15) | BIT_7;
5543#endif
5544 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005545 uint32_t data;
5546 struct qla_hw_data *ha = base_vha->hw;
5547
5548 /* IDC-unlock implementation using driver-unlock/lock-id
5549 * remote registers
5550 */
5551 retry = 0;
5552retry_unlock:
5553 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5554 == QLA_SUCCESS) {
5555 if (data == ha->portnum) {
5556 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5557 /* Clearing lock-id by setting 0xff */
5558 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5559 } else if (retry < 10) {
5560 /* SV: XXX: IDC unlock retrying needed here? */
5561
5562 /* Retry for IDC-unlock */
5563 qla83xx_wait_logic();
5564 retry++;
5565 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005566 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005567 goto retry_unlock;
5568 }
5569 } else if (retry < 10) {
5570 /* Retry for IDC-unlock */
5571 qla83xx_wait_logic();
5572 retry++;
5573 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005574 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005575 goto retry_unlock;
5576 }
5577
5578 return;
5579
Bart Van Assche5897cb22015-06-04 15:57:20 -07005580#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005581 /* XXX: IDC-unlock implementation using access-control mbx */
5582 retry = 0;
5583retry_unlock2:
5584 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5585 if (retry < 10) {
5586 /* Retry for IDC-unlock */
5587 qla83xx_wait_logic();
5588 retry++;
5589 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005590 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005591 goto retry_unlock2;
5592 }
5593 }
5594
5595 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005596#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005597}
5598
5599int
5600__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5601{
5602 int rval = QLA_SUCCESS;
5603 struct qla_hw_data *ha = vha->hw;
5604 uint32_t drv_presence;
5605
5606 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5607 if (rval == QLA_SUCCESS) {
5608 drv_presence |= (1 << ha->portnum);
5609 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5610 drv_presence);
5611 }
5612
5613 return rval;
5614}
5615
5616int
5617qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5618{
5619 int rval = QLA_SUCCESS;
5620
5621 qla83xx_idc_lock(vha, 0);
5622 rval = __qla83xx_set_drv_presence(vha);
5623 qla83xx_idc_unlock(vha, 0);
5624
5625 return rval;
5626}
5627
5628int
5629__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5630{
5631 int rval = QLA_SUCCESS;
5632 struct qla_hw_data *ha = vha->hw;
5633 uint32_t drv_presence;
5634
5635 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5636 if (rval == QLA_SUCCESS) {
5637 drv_presence &= ~(1 << ha->portnum);
5638 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5639 drv_presence);
5640 }
5641
5642 return rval;
5643}
5644
5645int
5646qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5647{
5648 int rval = QLA_SUCCESS;
5649
5650 qla83xx_idc_lock(vha, 0);
5651 rval = __qla83xx_clear_drv_presence(vha);
5652 qla83xx_idc_unlock(vha, 0);
5653
5654 return rval;
5655}
5656
Saurav Kashyapfa492632012-11-21 02:40:29 -05005657static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005658qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5659{
5660 struct qla_hw_data *ha = vha->hw;
5661 uint32_t drv_ack, drv_presence;
5662 unsigned long ack_timeout;
5663
5664 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5665 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5666 while (1) {
5667 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5668 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005669 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005670 break;
5671
5672 if (time_after_eq(jiffies, ack_timeout)) {
5673 ql_log(ql_log_warn, vha, 0xb067,
5674 "RESET ACK TIMEOUT! drv_presence=0x%x "
5675 "drv_ack=0x%x\n", drv_presence, drv_ack);
5676 /*
5677 * The function(s) which did not ack in time are forced
5678 * to withdraw any further participation in the IDC
5679 * reset.
5680 */
5681 if (drv_ack != drv_presence)
5682 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5683 drv_ack);
5684 break;
5685 }
5686
5687 qla83xx_idc_unlock(vha, 0);
5688 msleep(1000);
5689 qla83xx_idc_lock(vha, 0);
5690 }
5691
5692 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5693 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5694}
5695
Saurav Kashyapfa492632012-11-21 02:40:29 -05005696static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005697qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5698{
5699 int rval = QLA_SUCCESS;
5700 uint32_t idc_control;
5701
5702 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5703 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5704
5705 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5706 __qla83xx_get_idc_control(vha, &idc_control);
5707 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5708 __qla83xx_set_idc_control(vha, 0);
5709
5710 qla83xx_idc_unlock(vha, 0);
5711 rval = qla83xx_restart_nic_firmware(vha);
5712 qla83xx_idc_lock(vha, 0);
5713
5714 if (rval != QLA_SUCCESS) {
5715 ql_log(ql_log_fatal, vha, 0xb06a,
5716 "Failed to restart NIC f/w.\n");
5717 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5718 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5719 } else {
5720 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5721 "Success in restarting nic f/w.\n");
5722 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5723 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5724 }
5725
5726 return rval;
5727}
5728
5729/* Assumes idc_lock always held on entry */
5730int
5731qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5732{
5733 struct qla_hw_data *ha = base_vha->hw;
5734 int rval = QLA_SUCCESS;
5735 unsigned long dev_init_timeout;
5736 uint32_t dev_state;
5737
5738 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5739 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5740
5741 while (1) {
5742
5743 if (time_after_eq(jiffies, dev_init_timeout)) {
5744 ql_log(ql_log_warn, base_vha, 0xb06e,
5745 "Initialization TIMEOUT!\n");
5746 /* Init timeout. Disable further NIC Core
5747 * communication.
5748 */
5749 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5750 QLA8XXX_DEV_FAILED);
5751 ql_log(ql_log_info, base_vha, 0xb06f,
5752 "HW State: FAILED.\n");
5753 }
5754
5755 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5756 switch (dev_state) {
5757 case QLA8XXX_DEV_READY:
5758 if (ha->flags.nic_core_reset_owner)
5759 qla83xx_idc_audit(base_vha,
5760 IDC_AUDIT_COMPLETION);
5761 ha->flags.nic_core_reset_owner = 0;
5762 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5763 "Reset_owner reset by 0x%x.\n",
5764 ha->portnum);
5765 goto exit;
5766 case QLA8XXX_DEV_COLD:
5767 if (ha->flags.nic_core_reset_owner)
5768 rval = qla83xx_device_bootstrap(base_vha);
5769 else {
5770 /* Wait for AEN to change device-state */
5771 qla83xx_idc_unlock(base_vha, 0);
5772 msleep(1000);
5773 qla83xx_idc_lock(base_vha, 0);
5774 }
5775 break;
5776 case QLA8XXX_DEV_INITIALIZING:
5777 /* Wait for AEN to change device-state */
5778 qla83xx_idc_unlock(base_vha, 0);
5779 msleep(1000);
5780 qla83xx_idc_lock(base_vha, 0);
5781 break;
5782 case QLA8XXX_DEV_NEED_RESET:
5783 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5784 qla83xx_need_reset_handler(base_vha);
5785 else {
5786 /* Wait for AEN to change device-state */
5787 qla83xx_idc_unlock(base_vha, 0);
5788 msleep(1000);
5789 qla83xx_idc_lock(base_vha, 0);
5790 }
5791 /* reset timeout value after need reset handler */
5792 dev_init_timeout = jiffies +
5793 (ha->fcoe_dev_init_timeout * HZ);
5794 break;
5795 case QLA8XXX_DEV_NEED_QUIESCENT:
5796 /* XXX: DEBUG for now */
5797 qla83xx_idc_unlock(base_vha, 0);
5798 msleep(1000);
5799 qla83xx_idc_lock(base_vha, 0);
5800 break;
5801 case QLA8XXX_DEV_QUIESCENT:
5802 /* XXX: DEBUG for now */
5803 if (ha->flags.quiesce_owner)
5804 goto exit;
5805
5806 qla83xx_idc_unlock(base_vha, 0);
5807 msleep(1000);
5808 qla83xx_idc_lock(base_vha, 0);
5809 dev_init_timeout = jiffies +
5810 (ha->fcoe_dev_init_timeout * HZ);
5811 break;
5812 case QLA8XXX_DEV_FAILED:
5813 if (ha->flags.nic_core_reset_owner)
5814 qla83xx_idc_audit(base_vha,
5815 IDC_AUDIT_COMPLETION);
5816 ha->flags.nic_core_reset_owner = 0;
5817 __qla83xx_clear_drv_presence(base_vha);
5818 qla83xx_idc_unlock(base_vha, 0);
5819 qla8xxx_dev_failed_handler(base_vha);
5820 rval = QLA_FUNCTION_FAILED;
5821 qla83xx_idc_lock(base_vha, 0);
5822 goto exit;
5823 case QLA8XXX_BAD_VALUE:
5824 qla83xx_idc_unlock(base_vha, 0);
5825 msleep(1000);
5826 qla83xx_idc_lock(base_vha, 0);
5827 break;
5828 default:
5829 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09005830 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005831 qla83xx_idc_unlock(base_vha, 0);
5832 qla8xxx_dev_failed_handler(base_vha);
5833 rval = QLA_FUNCTION_FAILED;
5834 qla83xx_idc_lock(base_vha, 0);
5835 goto exit;
5836 }
5837 }
5838
5839exit:
5840 return rval;
5841}
5842
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005843void
5844qla2x00_disable_board_on_pci_error(struct work_struct *work)
5845{
5846 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
5847 board_disable);
5848 struct pci_dev *pdev = ha->pdev;
5849 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5850
Quinn Tran726b8542017-01-19 22:28:00 -08005851 /*
5852 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04005853 * where it was set first.
5854 */
5855 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5856 return;
5857
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005858 ql_log(ql_log_warn, base_vha, 0x015b,
5859 "Disabling adapter.\n");
5860
Sawan Chandakefdb5762017-08-23 15:05:00 -07005861 if (!atomic_read(&pdev->enable_cnt)) {
5862 ql_log(ql_log_info, base_vha, 0xfffc,
5863 "PCI device disabled, no action req for PCI error=%lx\n",
5864 base_vha->pci_flags);
5865 return;
5866 }
5867
Quinn Tran726b8542017-01-19 22:28:00 -08005868 qla2x00_wait_for_sess_deletion(base_vha);
5869
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005870 set_bit(UNLOADING, &base_vha->dpc_flags);
5871
5872 qla2x00_delete_all_vps(ha, base_vha);
5873
5874 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
5875
5876 qla2x00_dfs_remove(base_vha);
5877
5878 qla84xx_put_chip(base_vha);
5879
5880 if (base_vha->timer_active)
5881 qla2x00_stop_timer(base_vha);
5882
5883 base_vha->flags.online = 0;
5884
5885 qla2x00_destroy_deferred_work(ha);
5886
5887 /*
5888 * Do not try to stop beacon blink as it will issue a mailbox
5889 * command.
5890 */
5891 qla2x00_free_sysfs_attr(base_vha, false);
5892
5893 fc_remove_host(base_vha->host);
5894
5895 scsi_remove_host(base_vha->host);
5896
5897 base_vha->flags.init_done = 0;
5898 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005899 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08005900 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005901 qla2x00_mem_free(ha);
5902 qla82xx_md_free(base_vha);
5903 qla2x00_free_queues(ha);
5904
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005905 qla2x00_unmap_iobases(ha);
5906
5907 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005908 pci_disable_pcie_error_reporting(pdev);
5909 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005910
Joe Lawrencebeb9e312014-08-26 17:12:14 -04005911 /*
5912 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
5913 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04005914}
5915
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916/**************************************************************************
5917* qla2x00_do_dpc
5918* This kernel thread is a task that is schedule by the interrupt handler
5919* to perform the background processing for interrupts.
5920*
5921* Notes:
5922* This task always run in the context of a kernel thread. It
5923* is kick-off by the driver's detect code and starts up
5924* up one per adapter. It immediately goes to sleep and waits for
5925* some fibre event. When either the interrupt handler or
5926* the timer routine detects a event it will one of the task
5927* bits then wake us up.
5928**************************************************************************/
5929static int
5930qla2x00_do_dpc(void *data)
5931{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005932 scsi_qla_host_t *base_vha;
5933 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08005934 uint32_t online;
5935 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08005936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005937 ha = (struct qla_hw_data *)data;
5938 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939
Dongsheng Yang8698a742014-03-11 18:09:12 +08005940 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005941
James Bottomley563585e2011-01-27 16:12:37 -05005942 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01005943 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005944 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
5945 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946
Christoph Hellwig39a11242006-02-14 18:46:22 +01005947 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005949 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
5950 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951
Andrew Vasquez85880802009-12-15 21:29:46 -08005952 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005953 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
5954 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08005955 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08005956 }
5957
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958 ha->dpc_active = 1;
5959
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005960 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
5961 "DPC handler waking up, dpc_flags=0x%lx.\n",
5962 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04005964 if (test_bit(UNLOADING, &base_vha->dpc_flags))
5965 break;
5966
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005967 if (IS_P3P_TYPE(ha)) {
5968 if (IS_QLA8044(ha)) {
5969 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5970 &base_vha->dpc_flags)) {
5971 qla8044_idc_lock(ha);
5972 qla8044_wr_direct(base_vha,
5973 QLA8044_CRB_DEV_STATE_INDEX,
5974 QLA8XXX_DEV_FAILED);
5975 qla8044_idc_unlock(ha);
5976 ql_log(ql_log_info, base_vha, 0x4004,
5977 "HW State: FAILED.\n");
5978 qla8044_device_state_handler(base_vha);
5979 continue;
5980 }
5981
5982 } else {
5983 if (test_and_clear_bit(ISP_UNRECOVERABLE,
5984 &base_vha->dpc_flags)) {
5985 qla82xx_idc_lock(ha);
5986 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5987 QLA8XXX_DEV_FAILED);
5988 qla82xx_idc_unlock(ha);
5989 ql_log(ql_log_info, base_vha, 0x0151,
5990 "HW State: FAILED.\n");
5991 qla82xx_device_state_handler(base_vha);
5992 continue;
5993 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005994 }
5995
5996 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
5997 &base_vha->dpc_flags)) {
5998
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005999 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6000 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006001 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6002 &base_vha->dpc_flags))) {
6003 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6004 /* FCoE-ctx reset failed.
6005 * Escalate to chip-reset
6006 */
6007 set_bit(ISP_ABORT_NEEDED,
6008 &base_vha->dpc_flags);
6009 }
6010 clear_bit(ABORT_ISP_ACTIVE,
6011 &base_vha->dpc_flags);
6012 }
6013
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006014 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6015 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006016 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006017 } else if (IS_QLAFX00(ha)) {
6018 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6019 &base_vha->dpc_flags)) {
6020 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6021 "Firmware Reset Recovery\n");
6022 if (qlafx00_reset_initialize(base_vha)) {
6023 /* Failed. Abort isp later. */
6024 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006025 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006026 set_bit(ISP_UNRECOVERABLE,
6027 &base_vha->dpc_flags);
6028 ql_dbg(ql_dbg_dpc, base_vha,
6029 0x4021,
6030 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006031 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006032 }
6033 }
6034
6035 if (test_and_clear_bit(FX00_TARGET_SCAN,
6036 &base_vha->dpc_flags)) {
6037 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6038 "ISPFx00 Target Scan scheduled\n");
6039 if (qlafx00_rescan_isp(base_vha)) {
6040 if (!test_bit(UNLOADING,
6041 &base_vha->dpc_flags))
6042 set_bit(ISP_UNRECOVERABLE,
6043 &base_vha->dpc_flags);
6044 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6045 "ISPFx00 Target Scan Failed\n");
6046 }
6047 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6048 "ISPFx00 Target Scan End\n");
6049 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006050 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6051 &base_vha->dpc_flags)) {
6052 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6053 "ISPFx00 Host Info resend scheduled\n");
6054 qlafx00_fx_disc(base_vha,
6055 &base_vha->hw->mr.fcport,
6056 FXDISC_REG_HOST_INFO);
6057 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006058 }
6059
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006060 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6061 &base_vha->dpc_flags) &&
6062 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6063 qla24xx_detect_sfp(base_vha);
6064
6065 if (ha->flags.detected_lr_sfp !=
6066 ha->flags.using_lr_setting)
6067 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6068 }
6069
Quinn Tranb08abbd2018-07-18 14:29:54 -07006070 if (test_and_clear_bit
6071 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6072 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran93eca612018-08-31 11:24:37 -07006073 bool do_reset = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074
Quinn Tran93eca612018-08-31 11:24:37 -07006075 switch (ql2x_ini_mode) {
6076 case QLA2XXX_INI_MODE_ENABLED:
6077 break;
6078 case QLA2XXX_INI_MODE_DISABLED:
6079 if (!qla_tgt_mode_enabled(base_vha))
6080 do_reset = false;
6081 break;
6082 case QLA2XXX_INI_MODE_DUAL:
6083 if (!qla_dual_mode_enabled(base_vha))
6084 do_reset = false;
6085 break;
6086 default:
6087 break;
6088 }
6089
6090 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006091 &base_vha->dpc_flags))) {
Quinn Tran93eca612018-08-31 11:24:37 -07006092 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6093 "ISP abort scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006094 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095 /* failed. retry later */
6096 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006097 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006099 clear_bit(ABORT_ISP_ACTIVE,
6100 &base_vha->dpc_flags);
Quinn Tran93eca612018-08-31 11:24:37 -07006101 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6102 "ISP abort end.\n");
Seokmann Ju99363ef2008-01-31 12:33:51 -08006103 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 }
6105
David Jefferya394aac2012-11-21 02:39:54 -05006106 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6107 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006108 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006109 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006110
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006111 if (IS_QLAFX00(ha))
6112 goto loop_resync_check;
6113
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006114 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006115 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6116 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006117 if (IS_P3P_TYPE(ha)) {
6118 if (IS_QLA82XX(ha))
6119 qla82xx_device_state_handler(base_vha);
6120 if (IS_QLA8044(ha))
6121 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006122 clear_bit(ISP_QUIESCE_NEEDED,
6123 &base_vha->dpc_flags);
6124 if (!ha->flags.quiesce_owner) {
6125 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006126 if (IS_QLA82XX(ha)) {
6127 qla82xx_idc_lock(ha);
6128 qla82xx_clear_qsnt_ready(
6129 base_vha);
6130 qla82xx_idc_unlock(ha);
6131 } else if (IS_QLA8044(ha)) {
6132 qla8044_idc_lock(ha);
6133 qla8044_clear_qsnt_ready(
6134 base_vha);
6135 qla8044_idc_unlock(ha);
6136 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006137 }
6138 } else {
6139 clear_bit(ISP_QUIESCE_NEEDED,
6140 &base_vha->dpc_flags);
6141 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006142 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006143 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6144 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006145 }
6146
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006147 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006148 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006149 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006151 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6152 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006153 qla2x00_rst_aen(base_vha);
6154 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006155 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6156 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157 }
6158
6159 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006160 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006161 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6162 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163
Quinn Tran4005a992017-12-04 14:45:06 -08006164 if (!base_vha->relogin_jif ||
6165 time_after_eq(jiffies, base_vha->relogin_jif)) {
6166 base_vha->relogin_jif = jiffies + HZ;
6167 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6168
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006169 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006170 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006171 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006174loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006175 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006176 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006178 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6179 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180
6181 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006182 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183
Bart Van Assche52c82822015-07-09 07:23:26 -07006184 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006186 clear_bit(LOOP_RESYNC_ACTIVE,
6187 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 }
6189
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006190 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6191 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 }
6193
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006194 if (IS_QLAFX00(ha))
6195 goto intr_on_check;
6196
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006197 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6198 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6199 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6200 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006201 }
6202
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006203intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006205 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006207 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006208 &base_vha->dpc_flags)) {
6209 if (ha->beacon_blink_led == 1)
6210 ha->isp_ops->beacon_blink(base_vha);
6211 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006212
Michael Hernandezd7459522016-12-12 14:40:07 -08006213 /* qpair online check */
6214 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6215 &base_vha->dpc_flags)) {
6216 if (ha->flags.eeh_busy ||
6217 ha->flags.pci_channel_io_perm_failure)
6218 online = 0;
6219 else
6220 online = 1;
6221
6222 mutex_lock(&ha->mq_lock);
6223 list_for_each_entry(qpair, &base_vha->qp_list,
6224 qp_list_elem)
6225 qpair->online = online;
6226 mutex_unlock(&ha->mq_lock);
6227 }
6228
Quinn Tran8b4673b2018-09-04 14:19:14 -07006229 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6230 &base_vha->dpc_flags)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006231 ql_log(ql_log_info, base_vha, 0xffffff,
6232 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6233 ha->nvme_last_rptd_aen);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006234 if (qla27xx_set_zio_threshold(base_vha,
6235 ha->nvme_last_rptd_aen)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006236 ql_log(ql_log_info, base_vha, 0xffffff,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006237 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6238 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006239 }
6240 }
6241
Quinn Tran8b4673b2018-09-04 14:19:14 -07006242 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6243 &base_vha->dpc_flags)) {
6244 ql_log(ql_log_info, base_vha, 0xffffff,
6245 "SET ZIO Activity exchange threshold to %d.\n",
6246 ha->last_zio_threshold);
6247 qla27xx_set_zio_threshold(base_vha,
6248 ha->last_zio_threshold);
6249 }
6250
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006251 if (!IS_QLAFX00(ha))
6252 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006253
Quinn Tran48acad02018-08-02 13:16:44 -07006254 if (test_and_clear_bit(N2N_LINK_RESET,
6255 &base_vha->dpc_flags)) {
6256 qla2x00_lip_reset(base_vha);
6257 }
6258
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006260end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006261 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006263 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006265 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6266 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267
6268 /*
6269 * Make sure that nobody tries to wake us up again.
6270 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271 ha->dpc_active = 0;
6272
Andrew Vasquezac280b62009-08-20 11:06:05 -07006273 /* Cleanup any residual CTX SRBs. */
6274 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6275
Christoph Hellwig39a11242006-02-14 18:46:22 +01006276 return 0;
6277}
6278
6279void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006280qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006281{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006282 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006283 struct task_struct *t = ha->dpc_thread;
6284
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006285 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006286 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287}
6288
6289/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290* qla2x00_rst_aen
6291* Processes asynchronous reset.
6292*
6293* Input:
6294* ha = adapter block pointer.
6295*/
6296static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006297qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006299 if (vha->flags.online && !vha->flags.reset_active &&
6300 !atomic_read(&vha->loop_down_timer) &&
6301 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006303 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304
6305 /*
6306 * Issue marker command only when we are going to start
6307 * the I/O.
6308 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006309 vha->marker_needed = 1;
6310 } while (!atomic_read(&vha->loop_down_timer) &&
6311 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 }
6313}
6314
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315/**************************************************************************
6316* qla2x00_timer
6317*
6318* Description:
6319* One second timer
6320*
6321* Context: Interrupt
6322***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006323void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006324qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006326 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 int start_dpc = 0;
6329 int index;
6330 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006331 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006332 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006333 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006334
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006335 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006336 ql_dbg(ql_dbg_timer, vha, 0x6000,
6337 "EEH = %d, restarting timer.\n",
6338 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006339 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6340 return;
6341 }
6342
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006343 /*
6344 * Hardware read to raise pending EEH errors during mailbox waits. If
6345 * the read returns -1 then disable the board.
6346 */
6347 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006348 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006349 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006352 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006353 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006354 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6355 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006356 if (IS_QLA82XX(ha))
6357 qla82xx_watchdog(vha);
6358 else if (IS_QLA8044(ha))
6359 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006360 }
6361
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006362 if (!vha->vp_idx && IS_QLAFX00(ha))
6363 qlafx00_timer_routine(vha);
6364
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006366 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006367 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6368 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006369 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006371 if (atomic_read(&vha->loop_down_timer) ==
6372 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006374 ql_log(ql_log_info, vha, 0x6008,
6375 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006377 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6378 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006380 /*
6381 * Schedule an ISP abort to return any FCP2-device
6382 * commands.
6383 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006384 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006385 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006386 spin_lock_irqsave(&ha->hardware_lock,
6387 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006388 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006389 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006390 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006391 index++) {
6392 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006394 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006395 if (!sp)
6396 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006397 if (sp->cmd_type != TYPE_SRB)
6398 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006399 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006400 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006401 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006402 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006403 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006405 if (IS_QLA82XX(ha))
6406 set_bit(FCOE_CTX_RESET_NEEDED,
6407 &vha->dpc_flags);
6408 else
6409 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006410 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006411 break;
6412 }
6413 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006414 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 start_dpc++;
6417 }
6418
6419 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006420 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006421 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006422 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423 "Loop down - aborting ISP.\n");
6424
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006425 if (IS_QLA82XX(ha))
6426 set_bit(FCOE_CTX_RESET_NEEDED,
6427 &vha->dpc_flags);
6428 else
6429 set_bit(ISP_ABORT_NEEDED,
6430 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 }
6432 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006433 ql_dbg(ql_dbg_timer, vha, 0x600a,
6434 "Loop down - seconds remaining %d.\n",
6435 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006437 /* Check if beacon LED needs to be blinked for physical host only */
6438 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006439 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006440 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006441 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6442 start_dpc++;
6443 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006444 }
6445
Andrew Vasquez550bf572008-04-24 15:21:23 -07006446 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006447 if (!list_empty(&vha->work_list)) {
6448 unsigned long flags;
6449 bool q = false;
6450
6451 spin_lock_irqsave(&vha->work_lock, flags);
6452 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6453 q = true;
6454 spin_unlock_irqrestore(&vha->work_lock, flags);
6455 if (q)
6456 queue_work(vha->hw->wq, &vha->iocb_work);
6457 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006458
Duane Grigsby7401bc12017-06-21 13:48:42 -07006459 /*
6460 * FC-NVME
6461 * see if the active AEN count has changed from what was last reported.
6462 */
Quinn Tran8b4673b2018-09-04 14:19:14 -07006463 if (!vha->vp_idx && (atomic_read(&ha->nvme_active_aen_cnt) !=
6464 ha->nvme_last_rptd_aen) && ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006465 ql_log(ql_log_info, vha, 0x3002,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006466 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6467 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006468 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006469 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6470 start_dpc++;
6471 }
6472
6473 if (!vha->vp_idx &&
6474 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6475 (ha->zio_mode == QLA_ZIO_MODE_6) &&
6476 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
6477 ql_log(ql_log_info, vha, 0x3002,
6478 "Sched: Set ZIO exchange threshold to %d.\n",
6479 ha->last_zio_threshold);
6480 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006481 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6482 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006483 }
6484
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006486 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6487 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6488 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006490 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6491 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006492 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6493 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006494 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006495 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006496 ql_dbg(ql_dbg_timer, vha, 0x600b,
6497 "isp_abort_needed=%d loop_resync_needed=%d "
6498 "fcport_update_needed=%d start_dpc=%d "
6499 "reset_marker_needed=%d",
6500 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6501 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6502 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6503 start_dpc,
6504 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6505 ql_dbg(ql_dbg_timer, vha, 0x600c,
6506 "beacon_blink_needed=%d isp_unrecoverable=%d "
6507 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006508 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006509 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6510 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6511 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6512 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006513 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006514 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006517 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518}
6519
Andrew Vasquez54333832005-11-09 15:49:04 -08006520/* Firmware interface routines. */
6521
Chad Dupuisf73cb692014-02-26 04:15:06 -05006522#define FW_BLOBS 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006523#define FW_ISP21XX 0
6524#define FW_ISP22XX 1
6525#define FW_ISP2300 2
6526#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006527#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006528#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006529#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006530#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006531#define FW_ISP2031 8
6532#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006533#define FW_ISP27XX 10
Andrew Vasquez54333832005-11-09 15:49:04 -08006534
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006535#define FW_FILE_ISP21XX "ql2100_fw.bin"
6536#define FW_FILE_ISP22XX "ql2200_fw.bin"
6537#define FW_FILE_ISP2300 "ql2300_fw.bin"
6538#define FW_FILE_ISP2322 "ql2322_fw.bin"
6539#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006540#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006541#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006542#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006543#define FW_FILE_ISP2031 "ql2600_fw.bin"
6544#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006545#define FW_FILE_ISP27XX "ql2700_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006546
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006547
Daniel Walkere1e82b62008-05-12 22:21:10 -07006548static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006549
6550static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006551 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6552 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6553 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6554 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6555 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006556 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006557 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006558 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006559 { .name = FW_FILE_ISP2031, },
6560 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006561 { .name = FW_FILE_ISP27XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006562};
6563
6564struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006565qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006566{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006567 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006568 struct fw_blob *blob;
6569
Andrew Vasquez54333832005-11-09 15:49:04 -08006570 if (IS_QLA2100(ha)) {
6571 blob = &qla_fw_blobs[FW_ISP21XX];
6572 } else if (IS_QLA2200(ha)) {
6573 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006574 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006575 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006576 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006577 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006578 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006579 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006580 } else if (IS_QLA25XX(ha)) {
6581 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006582 } else if (IS_QLA81XX(ha)) {
6583 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006584 } else if (IS_QLA82XX(ha)) {
6585 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006586 } else if (IS_QLA2031(ha)) {
6587 blob = &qla_fw_blobs[FW_ISP2031];
6588 } else if (IS_QLA8031(ha)) {
6589 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006590 } else if (IS_QLA27XX(ha)) {
6591 blob = &qla_fw_blobs[FW_ISP27XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006592 } else {
6593 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006594 }
6595
Daniel Walkere1e82b62008-05-12 22:21:10 -07006596 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006597 if (blob->fw)
6598 goto out;
6599
6600 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006601 ql_log(ql_log_warn, vha, 0x0063,
6602 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006603 blob->fw = NULL;
6604 blob = NULL;
6605 goto out;
6606 }
6607
6608out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006609 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006610 return blob;
6611}
6612
6613static void
6614qla2x00_release_firmware(void)
6615{
6616 int idx;
6617
Daniel Walkere1e82b62008-05-12 22:21:10 -07006618 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006619 for (idx = 0; idx < FW_BLOBS; idx++)
Jesper Juhlcf925492012-04-09 22:51:41 +02006620 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006621 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006622}
6623
Seokmann Ju14e660e2007-09-20 14:07:36 -07006624static pci_ers_result_t
6625qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6626{
Andrew Vasquez85880802009-12-15 21:29:46 -08006627 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6628 struct qla_hw_data *ha = vha->hw;
6629
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006630 ql_dbg(ql_dbg_aer, vha, 0x9000,
6631 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006632
Sawan Chandakefdb5762017-08-23 15:05:00 -07006633 if (!atomic_read(&pdev->enable_cnt)) {
6634 ql_log(ql_log_info, vha, 0xffff,
6635 "PCI device is disabled,state %x\n", state);
6636 return PCI_ERS_RESULT_NEED_RESET;
6637 }
6638
Seokmann Ju14e660e2007-09-20 14:07:36 -07006639 switch (state) {
6640 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006641 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006642 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006643 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6644 qla2xxx_wake_dpc(vha);
6645 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006646 return PCI_ERS_RESULT_CAN_RECOVER;
6647 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006648 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006649 /* For ISP82XX complete any pending mailbox cmd */
6650 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006651 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006652 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6653 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006654 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006655 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006656 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006657 /* Return back all IOs */
6658 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006659 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006660 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6661 qla2xxx_wake_dpc(vha);
6662 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006663 return PCI_ERS_RESULT_NEED_RESET;
6664 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006665 ha->flags.pci_channel_io_perm_failure = 1;
6666 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006667 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006668 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6669 qla2xxx_wake_dpc(vha);
6670 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006671 return PCI_ERS_RESULT_DISCONNECT;
6672 }
6673 return PCI_ERS_RESULT_NEED_RESET;
6674}
6675
6676static pci_ers_result_t
6677qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6678{
6679 int risc_paused = 0;
6680 uint32_t stat;
6681 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006682 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6683 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006684 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6685 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6686
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006687 if (IS_QLA82XX(ha))
6688 return PCI_ERS_RESULT_RECOVERED;
6689
Seokmann Ju14e660e2007-09-20 14:07:36 -07006690 spin_lock_irqsave(&ha->hardware_lock, flags);
6691 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6692 stat = RD_REG_DWORD(&reg->hccr);
6693 if (stat & HCCR_RISC_PAUSE)
6694 risc_paused = 1;
6695 } else if (IS_QLA23XX(ha)) {
6696 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6697 if (stat & HSR_RISC_PAUSED)
6698 risc_paused = 1;
6699 } else if (IS_FWI2_CAPABLE(ha)) {
6700 stat = RD_REG_DWORD(&reg24->host_status);
6701 if (stat & HSRX_RISC_PAUSED)
6702 risc_paused = 1;
6703 }
6704 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6705
6706 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006707 ql_log(ql_log_info, base_vha, 0x9003,
6708 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006709 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006710
6711 return PCI_ERS_RESULT_NEED_RESET;
6712 } else
6713 return PCI_ERS_RESULT_RECOVERED;
6714}
6715
Saurav Kashyapfa492632012-11-21 02:40:29 -05006716static uint32_t
6717qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006718{
6719 uint32_t rval = QLA_FUNCTION_FAILED;
6720 uint32_t drv_active = 0;
6721 struct qla_hw_data *ha = base_vha->hw;
6722 int fn;
6723 struct pci_dev *other_pdev = NULL;
6724
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006725 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6726 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006727
6728 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6729
6730 if (base_vha->flags.online) {
6731 /* Abort all outstanding commands,
6732 * so as to be requeued later */
6733 qla2x00_abort_isp_cleanup(base_vha);
6734 }
6735
6736
6737 fn = PCI_FUNC(ha->pdev->devfn);
6738 while (fn > 0) {
6739 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006740 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6741 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006742 other_pdev =
6743 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6744 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6745 fn));
6746
6747 if (!other_pdev)
6748 continue;
6749 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006750 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6751 "Found PCI func available and enable at 0x%x.\n",
6752 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006753 pci_dev_put(other_pdev);
6754 break;
6755 }
6756 pci_dev_put(other_pdev);
6757 }
6758
6759 if (!fn) {
6760 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006761 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6762 "This devfn is reset owner = 0x%x.\n",
6763 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006764 qla82xx_idc_lock(ha);
6765
6766 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006767 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006768
6769 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6770 QLA82XX_IDC_VERSION);
6771
6772 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006773 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6774 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006775
6776 qla82xx_idc_unlock(ha);
6777 /* Reset if device is not already reset
6778 * drv_active would be 0 if a reset has already been done
6779 */
6780 if (drv_active)
6781 rval = qla82xx_start_firmware(base_vha);
6782 else
6783 rval = QLA_SUCCESS;
6784 qla82xx_idc_lock(ha);
6785
6786 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006787 ql_log(ql_log_info, base_vha, 0x900b,
6788 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006789 qla82xx_clear_drv_active(ha);
6790 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006791 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006792 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006793 ql_log(ql_log_info, base_vha, 0x900c,
6794 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006795 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006796 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006797 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08006798 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006799 rval = qla82xx_restart_isp(base_vha);
6800 qla82xx_idc_lock(ha);
6801 /* Clear driver state register */
6802 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
6803 qla82xx_set_drv_active(base_vha);
6804 }
6805 qla82xx_idc_unlock(ha);
6806 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006807 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
6808 "This devfn is not reset owner = 0x%x.\n",
6809 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006810 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006811 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006812 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006813 rval = qla82xx_restart_isp(base_vha);
6814 qla82xx_idc_lock(ha);
6815 qla82xx_set_drv_active(base_vha);
6816 qla82xx_idc_unlock(ha);
6817 }
6818 }
6819 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6820
6821 return rval;
6822}
6823
Seokmann Ju14e660e2007-09-20 14:07:36 -07006824static pci_ers_result_t
6825qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6826{
6827 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006828 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6829 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006830 struct rsp_que *rsp;
6831 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006832
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006833 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6834 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006835
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006836 /* Workaround: qla2xxx driver which access hardware earlier
6837 * needs error state to be pci_channel_io_online.
6838 * Otherwise mailbox command timesout.
6839 */
6840 pdev->error_state = pci_channel_io_normal;
6841
6842 pci_restore_state(pdev);
6843
Richard Lary8c1496b2010-02-18 10:07:29 -08006844 /* pci_restore_state() clears the saved_state flag of the device
6845 * save restored state which resets saved_state flag
6846 */
6847 pci_save_state(pdev);
6848
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11006849 if (ha->mem_only)
6850 rc = pci_enable_device_mem(pdev);
6851 else
6852 rc = pci_enable_device(pdev);
6853
6854 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006855 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006856 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006857 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006858 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006859
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006860 rsp = ha->rsp_q_map[0];
6861 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006862 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006863
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006864 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006865 goto exit_slot_reset;
6866
6867 if (IS_QLA82XX(ha)) {
6868 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
6869 ret = PCI_ERS_RESULT_RECOVERED;
6870 goto exit_slot_reset;
6871 } else
6872 goto exit_slot_reset;
6873 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006874
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006875 while (ha->flags.mbox_busy && retries--)
6876 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08006877
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006878 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006879 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07006880 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006881 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006882
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006883
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006884exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006885 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
6886 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08006887
Seokmann Ju14e660e2007-09-20 14:07:36 -07006888 return ret;
6889}
6890
6891static void
6892qla2xxx_pci_resume(struct pci_dev *pdev)
6893{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006894 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6895 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006896 int ret;
6897
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006898 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
6899 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006901 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006902 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006903 ql_log(ql_log_fatal, base_vha, 0x9002,
6904 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07006905 }
Andrew Vasquez85880802009-12-15 21:29:46 -08006906
Lalit Chandivade3e46f032010-05-04 15:01:23 -07006907 pci_cleanup_aer_uncorrect_error_status(pdev);
6908
Andrew Vasquez85880802009-12-15 21:29:46 -08006909 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006910}
6911
Michael Hernandez56012362016-12-12 14:40:08 -08006912static int qla2xxx_map_queues(struct Scsi_Host *shost)
6913{
Quinn Trand68b8502017-12-04 14:44:59 -08006914 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006915 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
6916
Quinn Trand68b8502017-12-04 14:44:59 -08006917 if (USER_CTRL_IRQ(vha->hw))
6918 rc = blk_mq_map_queues(&shost->tag_set);
6919 else
Keith Buschf23f5bec2018-03-27 09:39:06 -06006920 rc = blk_mq_pci_map_queues(&shost->tag_set, vha->hw->pdev, 0);
Quinn Trand68b8502017-12-04 14:44:59 -08006921 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08006922}
6923
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07006924static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07006925 .error_detected = qla2xxx_pci_error_detected,
6926 .mmio_enabled = qla2xxx_pci_mmio_enabled,
6927 .slot_reset = qla2xxx_pci_slot_reset,
6928 .resume = qla2xxx_pci_resume,
6929};
6930
Andrew Vasquez54333832005-11-09 15:49:04 -08006931static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006932 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
6933 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
6934 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
6935 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
6936 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
6937 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
6938 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
6939 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
6940 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006941 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07006942 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
6943 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006944 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006945 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006946 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006947 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04006948 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006949 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006950 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05006951 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006952 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04006953 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Andrew Vasquez54333832005-11-09 15:49:04 -08006954 { 0 },
6955};
6956MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
6957
Andrew Vasquezfca29702005-07-06 10:31:47 -07006958static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07006959 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06006960 .driver = {
6961 .owner = THIS_MODULE,
6962 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07006963 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07006964 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08006965 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07006966 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07006967 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07006968};
6969
Al Viro75ef9de2013-04-04 19:09:41 -04006970static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006971 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02006972 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07006973};
6974
Linus Torvalds1da177e2005-04-16 15:20:36 -07006975/**
6976 * qla2x00_module_init - Module initialization.
6977 **/
6978static int __init
6979qla2x00_module_init(void)
6980{
Andrew Vasquezfca29702005-07-06 10:31:47 -07006981 int ret = 0;
6982
Linus Torvalds1da177e2005-04-16 15:20:36 -07006983 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04006984 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09006985 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006986 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006987 ql_log(ql_log_fatal, NULL, 0x0001,
6988 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006989 return -ENOMEM;
6990 }
6991
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006992 /* Initialize target kmem_cache and mem_pools */
6993 ret = qlt_init();
6994 if (ret < 0) {
6995 kmem_cache_destroy(srb_cachep);
6996 return ret;
6997 } else if (ret > 0) {
6998 /*
6999 * If initiator mode is explictly disabled by qlt_init(),
7000 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7001 * performing scsi_scan_target() during LOOP UP event.
7002 */
7003 qla2xxx_transport_functions.disable_target_scan = 1;
7004 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7005 }
7006
Linus Torvalds1da177e2005-04-16 15:20:36 -07007007 /* Derive version string. */
7008 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07007009 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07007010 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07007011 if (ql2xextended_error_logging == 1)
7012 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07007013
Andrew Vasquez1c97a122005-04-21 16:13:36 -04007014 qla2xxx_transport_template =
7015 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007016 if (!qla2xxx_transport_template) {
7017 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007018 ql_log(ql_log_fatal, NULL, 0x0002,
7019 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007020 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07007021 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007022 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007023
7024 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7025 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007026 ql_log(ql_log_fatal, NULL, 0x0003,
7027 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007028 }
7029
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007030 qla2xxx_transport_vport_template =
7031 fc_attach_transport(&qla2xxx_transport_vport_functions);
7032 if (!qla2xxx_transport_vport_template) {
7033 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007034 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007035 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007036 ql_log(ql_log_fatal, NULL, 0x0004,
7037 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007038 return -ENODEV;
7039 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007040 ql_log(ql_log_info, NULL, 0x0005,
7041 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07007042 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007043 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007044 if (ret) {
7045 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007046 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07007047 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007048 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007049 ql_log(ql_log_fatal, NULL, 0x0006,
7050 "pci_register_driver failed...ret=%d Failing load!.\n",
7051 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007052 }
7053 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007054}
7055
7056/**
7057 * qla2x00_module_exit - Module cleanup.
7058 **/
7059static void __exit
7060qla2x00_module_exit(void)
7061{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007062 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007063 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08007064 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007065 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007066 qlt_exit();
Giridhar Malavalia9083012010-04-12 17:59:55 -07007067 if (ctx_cachep)
7068 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007069 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007070 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007071}
7072
7073module_init(qla2x00_module_init);
7074module_exit(qla2x00_module_exit);
7075
7076MODULE_AUTHOR("QLogic Corporation");
7077MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7078MODULE_LICENSE("GPL");
7079MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07007080MODULE_FIRMWARE(FW_FILE_ISP21XX);
7081MODULE_FIRMWARE(FW_FILE_ISP22XX);
7082MODULE_FIRMWARE(FW_FILE_ISP2300);
7083MODULE_FIRMWARE(FW_FILE_ISP2322);
7084MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08007085MODULE_FIRMWARE(FW_FILE_ISP25XX);