blob: 6671566632e0436472aa9c1cbe33b340e32818bd [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>
Quinn Tran585def92018-09-04 14:19:20 -070017#include <linux/refcount.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <scsi/scsi_tcq.h>
20#include <scsi/scsicam.h>
21#include <scsi/scsi_transport.h>
22#include <scsi/scsi_transport_fc.h>
23
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040024#include "qla_target.h"
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/*
27 * Driver version
28 */
29char qla2x00_version_str[40];
30
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -070031static int apidev_major;
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/*
34 * SRB allocation cache
35 */
Michael Hernandezd7459522016-12-12 14:40:07 -080036struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Giridhar Malavalia9083012010-04-12 17:59:55 -070038/*
39 * CT6 CTX allocation cache
40 */
41static struct kmem_cache *ctx_cachep;
Saurav Kashyap3ce88662011-07-14 12:00:12 -070042/*
43 * error level for logging
44 */
Michael Hernandez3f006ac2019-03-12 11:08:22 -070045uint ql_errlev = 0x8001;
Giridhar Malavalia9083012010-04-12 17:59:55 -070046
Saurav Kashyapfa492632012-11-21 02:40:29 -050047static int ql2xenableclass2;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040048module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
49MODULE_PARM_DESC(ql2xenableclass2,
50 "Specify if Class 2 operations are supported from the very "
51 "beginning. Default is 0 - class 2 not supported.");
52
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054int ql2xlogintimeout = 20;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080055module_param(ql2xlogintimeout, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056MODULE_PARM_DESC(ql2xlogintimeout,
57 "Login timeout value in seconds.");
58
Andrew Vasqueza7b61842007-05-07 07:42:59 -070059int qlport_down_retry;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080060module_param(qlport_down_retry, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070062 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 "a PORT-DOWN status.");
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065int ql2xplogiabsentdevice;
66module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
67MODULE_PARM_DESC(ql2xplogiabsentdevice,
68 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070069 "a Fabric scan. This is needed for several broken switches. "
Masanari Iida0d52e642018-10-28 14:05:48 +090070 "Default is 0 - no PLOGI. 1 - perform PLOGI.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072int ql2xloginretrycount = 0;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080073module_param(ql2xloginretrycount, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074MODULE_PARM_DESC(ql2xloginretrycount,
75 "Specify an alternate value for the NVRAM login retry count.");
76
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070077int ql2xallocfwdump = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080078module_param(ql2xallocfwdump, int, S_IRUGO);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070079MODULE_PARM_DESC(ql2xallocfwdump,
80 "Option to enable allocation of memory for a firmware dump "
81 "during HBA initialization. Memory allocation requirements "
82 "vary by ISP type. Default is 1 - allocate memory.");
83
Andrew Vasquez11010fe2006-10-06 09:54:59 -070084int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070085module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -040086module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070087MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070088 "Option to enable extended error logging,\n"
89 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
90 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
91 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
92 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
93 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
94 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
95 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
96 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
Chad Dupuis29f9f902012-11-21 02:40:41 -050097 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
98 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070099 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -0800100 "\t\t0x1e400000 - Preferred value for capturing essential "
101 "debug information (equivalent to old "
102 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -0700103 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -0700104
Giridhar Malavalia9083012010-04-12 17:59:55 -0700105int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800106module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700107MODULE_PARM_DESC(ql2xshiftctondsd,
108 "Set to control shifting of command type processing "
109 "based on total number of SG elements.");
110
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700111int ql2xfdmienable=1;
Himanshu Madhanide187df2014-09-25 05:16:50 -0400112module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400113module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700114MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100115 "Enables FDMI registrations. "
116 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700117
Michael Hernandezd213a4b2017-08-23 15:05:20 -0700118#define MAX_Q_DEPTH 64
Chad Dupuis50280c02013-10-30 03:38:14 -0400119static int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700120module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
121MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400122 "Maximum queue depth to set for each LUN. "
Michael Hernandezd213a4b2017-08-23 15:05:20 -0700123 "Default is 64.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700124
Duane Grigsbye84067d2017-06-21 13:48:43 -0700125#if (IS_ENABLED(CONFIG_NVME_FC))
126int ql2xenabledif;
127#else
Arun Easi9e522cd2012-08-22 14:21:31 -0400128int ql2xenabledif = 2;
Duane Grigsbye84067d2017-06-21 13:48:43 -0700129#endif
Arun Easi9e522cd2012-08-22 14:21:31 -0400130module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700131MODULE_PARM_DESC(ql2xenabledif,
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600132 " Enable T10-CRC-DIF:\n"
133 " Default is 2.\n"
134 " 0 -- No DIF Support\n"
135 " 1 -- Enable DIF for all types\n"
136 " 2 -- Enable DIF for all types, except Type 0.\n");
Arun Easibad75002010-05-04 15:01:30 -0700137
Duane Grigsbye84067d2017-06-21 13:48:43 -0700138#if (IS_ENABLED(CONFIG_NVME_FC))
139int ql2xnvmeenable = 1;
140#else
141int ql2xnvmeenable;
142#endif
143module_param(ql2xnvmeenable, int, 0644);
144MODULE_PARM_DESC(ql2xnvmeenable,
145 "Enables NVME support. "
146 "0 - no NVMe. Default is Y");
147
Arun Easi8cb20492011-08-16 11:29:22 -0700148int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700149module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
150MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700151 " Enable T10-CRC-DIF Error isolation by HBA:\n"
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600152 " Default is 2.\n"
Arun Easi8cb20492011-08-16 11:29:22 -0700153 " 0 -- Error isolation disabled\n"
154 " 1 -- Error isolation enabled only for DIX Type 0\n"
155 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700156
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700157int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800158module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700159MODULE_PARM_DESC(ql2xiidmaenable,
160 "Enables iIDMA settings "
161 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
162
Michael Hernandezd7459522016-12-12 14:40:07 -0800163int ql2xmqsupport = 1;
164module_param(ql2xmqsupport, int, S_IRUGO);
165MODULE_PARM_DESC(ql2xmqsupport,
166 "Enable on demand multiple queue pairs support "
167 "Default is 1 for supported. "
168 "Set it to 0 to turn off mq qpair support.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700169
170int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700171module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400172module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700173MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700174 "Option to specify location from which to load ISP firmware:.\n"
175 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700176 " interface.\n"
177 " 1 -- load firmware from flash.\n"
178 " 0 -- use default semantics.\n");
179
Andrew Vasquezae97c912010-02-18 10:07:28 -0800180int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800181module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800182MODULE_PARM_DESC(ql2xetsenable,
183 "Enables firmware ETS burst."
184 "Default is 0 - skip ETS enablement.");
185
Giridhar Malavali69078692010-05-28 15:08:28 -0700186int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700187module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700188MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700189 "Option to specify scheme for request queue posting.\n"
190 " 0 -- Regular doorbell.\n"
191 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700192
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700193int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800194module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700195MODULE_PARM_DESC(ql2xtargetreset,
196 "Enable target reset."
197 "Default is 1 - use hw defaults.");
198
Chad Dupuis4da26e12010-10-15 11:27:40 -0700199int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800200module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700201MODULE_PARM_DESC(ql2xgffidenable,
202 "Enables GFF_ID checks of port type. "
203 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700204
himanshu.madhani@cavium.com043dc1d2017-08-23 15:05:19 -0700205int ql2xasynctmfenable = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800206module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700207MODULE_PARM_DESC(ql2xasynctmfenable,
208 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
Masanari Iida84e13c42018-09-11 18:48:11 +0900209 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700210
211int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700212module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700213MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700214 "Option to specify reset behaviour.\n"
215 " 0 (Default) -- Reset on failure.\n"
216 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700217
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200218uint64_t ql2xmaxlun = MAX_LUNS;
219module_param(ql2xmaxlun, ullong, S_IRUGO);
Andrew Vasquez82515922011-05-10 11:30:13 -0700220MODULE_PARM_DESC(ql2xmaxlun,
221 "Defines the maximum LU number to register with the SCSI "
222 "midlayer. Default is 65535.");
223
Giridhar Malavali08de2842011-08-16 11:31:44 -0700224int ql2xmdcapmask = 0x1F;
225module_param(ql2xmdcapmask, int, S_IRUGO);
226MODULE_PARM_DESC(ql2xmdcapmask,
227 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800228 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700229
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800230int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700231module_param(ql2xmdenable, int, S_IRUGO);
232MODULE_PARM_DESC(ql2xmdenable,
233 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800234 "0 - MiniDump disabled. "
235 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700236
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500237int ql2xexlogins = 0;
238module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
239MODULE_PARM_DESC(ql2xexlogins,
240 "Number of extended Logins. "
241 "0 (Default)- Disabled.");
242
Quinn Tran99e1b682017-06-02 09:12:03 -0700243int ql2xexchoffld = 1024;
244module_param(ql2xexchoffld, uint, 0644);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500245MODULE_PARM_DESC(ql2xexchoffld,
Quinn Tran99e1b682017-06-02 09:12:03 -0700246 "Number of target exchanges.");
247
248int ql2xiniexchg = 1024;
249module_param(ql2xiniexchg, uint, 0644);
250MODULE_PARM_DESC(ql2xiniexchg,
251 "Number of initiator exchanges.");
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500252
Himanshu Madhanif198caf2016-01-27 12:03:30 -0500253int ql2xfwholdabts = 0;
254module_param(ql2xfwholdabts, int, S_IRUGO);
255MODULE_PARM_DESC(ql2xfwholdabts,
256 "Allow FW to hold status IOCB until ABTS rsp received. "
257 "0 (Default) Do not set fw option. "
258 "1 - Set fw option to hold ABTS.");
259
Quinn Tran41dc5292017-01-19 22:28:03 -0800260int ql2xmvasynctoatio = 1;
261module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
262MODULE_PARM_DESC(ql2xmvasynctoatio,
263 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
264 "0 (Default). Do not move IOCBs"
265 "1 - Move IOCBs.");
266
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700267int ql2xautodetectsfp = 1;
268module_param(ql2xautodetectsfp, int, 0444);
269MODULE_PARM_DESC(ql2xautodetectsfp,
270 "Detect SFP range and set appropriate distance.\n"
271 "1 (Default): Enable\n");
272
Himanshu Madhanie7240af2017-10-13 09:34:03 -0700273int ql2xenablemsix = 1;
274module_param(ql2xenablemsix, int, 0444);
275MODULE_PARM_DESC(ql2xenablemsix,
276 "Set to enable MSI or MSI-X interrupt mechanism.\n"
277 " Default is 1, enable MSI-X interrupt mechanism.\n"
278 " 0 -- enable traditional pin-based mechanism.\n"
279 " 1 -- enable MSI-X interrupt mechanism.\n"
280 " 2 -- enable MSI interrupt mechanism.\n");
281
Quinn Tran9ecf0b02017-12-28 12:33:19 -0800282int qla2xuseresexchforels;
283module_param(qla2xuseresexchforels, int, 0444);
284MODULE_PARM_DESC(qla2xuseresexchforels,
285 "Reserve 1/2 of emergency exchanges for ELS.\n"
286 " 0 (default): disabled");
287
Martin K. Petersen7855d2b2018-12-21 09:33:44 -0800288int ql2xprotmask;
289module_param(ql2xprotmask, int, 0644);
290MODULE_PARM_DESC(ql2xprotmask,
291 "Override DIF/DIX protection capabilities mask\n"
292 "Default is 0 which sets protection mask based on "
293 "capabilities reported by HBA firmware.\n");
294
295int ql2xprotguard;
296module_param(ql2xprotguard, int, 0644);
297MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
298 " 0 -- Let HBA firmware decide\n"
299 " 1 -- Force T10 CRC\n"
300 " 2 -- Force IP checksum\n");
301
Giridhar Malavali50b81272018-12-21 09:33:45 -0800302int ql2xdifbundlinginternalbuffers;
303module_param(ql2xdifbundlinginternalbuffers, int, 0644);
304MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
305 "Force using internal buffers for DIF information\n"
306 "0 (Default). Based on check.\n"
307 "1 Force using internal buffers\n");
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700310 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 */
312static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500313static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800314static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
315static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500316static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500317static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318static int qla2xxx_eh_abort(struct scsi_cmnd *);
319static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700320static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
322static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400324static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400325static void qla2x00_free_device(scsi_qla_host_t *);
Michael Hernandez56012362016-12-12 14:40:08 -0800326static int qla2xxx_map_queues(struct Scsi_Host *shost);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700327static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700328
Quinn Tran45235022018-07-18 14:29:53 -0700329
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700330struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700332 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700333 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700334
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100335 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700336 .eh_abort_handler = qla2xxx_eh_abort,
337 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700338 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700339 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
340 .eh_host_reset_handler = qla2xxx_eh_host_reset,
341
342 .slave_configure = qla2xxx_slave_configure,
343
344 .slave_alloc = qla2xxx_slave_alloc,
345 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700346 .scan_finished = qla2xxx_scan_finished,
347 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100348 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800349 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700350 .this_id = -1,
351 .cmd_per_lun = 3,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700352 .sg_tablesize = SG_ALL,
353
354 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700355 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400356
357 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100358 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700359};
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700362struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364/* TODO Convert to inlines
365 *
366 * Timer routines
367 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700369__inline__ void
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700370qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700372 timer_setup(&vha->timer, qla2x00_timer, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800373 vha->timer.expires = jiffies + interval * HZ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800374 add_timer(&vha->timer);
375 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800379qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700381 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700382 if (vha->device_flags & DFLG_DEV_FAILED) {
383 ql_dbg(ql_dbg_timer, vha, 0x600d,
384 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700385 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700386 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700387
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800388 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
Adrian Bunka824ebb2008-01-17 09:02:15 -0800391static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800392qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800394 del_timer_sync(&vha->timer);
395 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398static int qla2x00_do_dpc(void *data);
399
400static void qla2x00_rst_aen(scsi_qla_host_t *);
401
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800402static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
403 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700404static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800405static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800406int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
407 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700410static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
411 struct rsp_que *rsp)
412{
413 struct qla_hw_data *ha = vha->hw;
414 rsp->qpair = ha->base_qpair;
415 rsp->req = req;
Quinn Tran06910942018-09-04 14:19:12 -0700416 ha->base_qpair->hw = ha;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700417 ha->base_qpair->req = req;
418 ha->base_qpair->rsp = rsp;
419 ha->base_qpair->vha = vha;
420 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
421 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
422 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
Quinn Tran6a629462018-09-04 14:19:15 -0700423 ha->base_qpair->srb_mempool = ha->srb_mempool;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700424 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
425 ha->base_qpair->enable_class_2 = ql2xenableclass2;
426 /* init qpair to this cpu. Will adjust at run time. */
Bart Van Assche86531882017-11-06 11:59:05 -0800427 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700428 ha->base_qpair->pdev = ha->pdev;
429
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700430 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700431 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
432}
433
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400434static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
435 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800436{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700437 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Kees Cook6396bb22018-06-12 14:03:40 -0700438 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800439 GFP_KERNEL);
440 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700441 ql_log(ql_log_fatal, vha, 0x003b,
442 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800443 goto fail_req_map;
444 }
445
Kees Cook6396bb22018-06-12 14:03:40 -0700446 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800447 GFP_KERNEL);
448 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700449 ql_log(ql_log_fatal, vha, 0x003c,
450 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800451 goto fail_rsp_map;
452 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800453
Quinn Trane326d222017-06-13 20:47:18 -0700454 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
455 if (ha->base_qpair == NULL) {
456 ql_log(ql_log_warn, vha, 0x00e0,
457 "Failed to allocate base queue pair memory.\n");
458 goto fail_base_qpair;
459 }
460
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700461 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700462
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -0700463 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -0800464 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
465 GFP_KERNEL);
466 if (!ha->queue_pair_map) {
467 ql_log(ql_log_fatal, vha, 0x0180,
468 "Unable to allocate memory for queue pair ptrs.\n");
469 goto fail_qpair_map;
470 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800471 }
472
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400473 /*
474 * Make sure we record at least the request and response queue zero in
475 * case we need to free them if part of the probe fails.
476 */
477 ha->rsp_q_map[0] = rsp;
478 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800479 set_bit(0, ha->rsp_qid_map);
480 set_bit(0, ha->req_qid_map);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -0500481 return 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800482
Michael Hernandezd7459522016-12-12 14:40:07 -0800483fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700484 kfree(ha->base_qpair);
485 ha->base_qpair = NULL;
486fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800487 kfree(ha->rsp_q_map);
488 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800489fail_rsp_map:
490 kfree(ha->req_q_map);
491 ha->req_q_map = NULL;
492fail_req_map:
493 return -ENOMEM;
494}
495
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700496static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800497{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400498 if (IS_QLAFX00(ha)) {
499 if (req && req->ring_fx00)
500 dma_free_coherent(&ha->pdev->dev,
501 (req->length_fx00 + 1) * sizeof(request_t),
502 req->ring_fx00, req->dma_fx00);
503 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800504 dma_free_coherent(&ha->pdev->dev,
505 (req->length + 1) * sizeof(request_t),
506 req->ring, req->dma);
507
Bill Kuzeja6d634062018-03-23 10:37:25 -0400508 if (req)
Chad Dupuis8d93f552013-01-30 03:34:37 -0500509 kfree(req->outstanding_cmds);
Bill Kuzeja6d634062018-03-23 10:37:25 -0400510
511 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800512}
513
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700514static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
515{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400516 if (IS_QLAFX00(ha)) {
Meelis Roos3f6c9be2018-03-08 15:44:37 +0200517 if (rsp && rsp->ring_fx00)
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400518 dma_free_coherent(&ha->pdev->dev,
519 (rsp->length_fx00 + 1) * sizeof(request_t),
520 rsp->ring_fx00, rsp->dma_fx00);
521 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700522 dma_free_coherent(&ha->pdev->dev,
523 (rsp->length + 1) * sizeof(response_t),
524 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400525 }
Bill Kuzeja6d634062018-03-23 10:37:25 -0400526 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700527}
528
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800529static void qla2x00_free_queues(struct qla_hw_data *ha)
530{
531 struct req_que *req;
532 struct rsp_que *rsp;
533 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800534 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800535
Quinn Tran82de8022017-06-13 20:47:17 -0700536 if (ha->queue_pair_map) {
537 kfree(ha->queue_pair_map);
538 ha->queue_pair_map = NULL;
539 }
540 if (ha->base_qpair) {
541 kfree(ha->base_qpair);
542 ha->base_qpair = NULL;
543 }
544
Quinn Tran093df732016-12-12 14:40:09 -0800545 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700546 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500547 if (!test_bit(cnt, ha->req_qid_map))
548 continue;
549
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800550 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800551 clear_bit(cnt, ha->req_qid_map);
552 ha->req_q_map[cnt] = NULL;
553
554 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700555 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800556 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700557 }
Quinn Tran093df732016-12-12 14:40:09 -0800558 spin_unlock_irqrestore(&ha->hardware_lock, flags);
559
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700560 kfree(ha->req_q_map);
561 ha->req_q_map = NULL;
562
Quinn Tran093df732016-12-12 14:40:09 -0800563
564 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700565 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500566 if (!test_bit(cnt, ha->rsp_qid_map))
567 continue;
568
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700569 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c4239462016-12-27 13:13:21 -0500570 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800571 ha->rsp_q_map[cnt] = NULL;
572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700573 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800574 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800575 }
Quinn Tran093df732016-12-12 14:40:09 -0800576 spin_unlock_irqrestore(&ha->hardware_lock, flags);
577
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800578 kfree(ha->rsp_q_map);
579 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800580}
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 static char *pci_bus_modes[] = {
587 "33", "66", "100", "133",
588 };
589 uint16_t pci_bus;
590
591 strcpy(str, "PCI");
592 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
593 if (pci_bus) {
594 strcat(str, "-X (");
595 strcat(str, pci_bus_modes[pci_bus]);
596 } else {
597 pci_bus = (ha->pci_attr & BIT_8) >> 8;
598 strcat(str, " (");
599 strcat(str, pci_bus_modes[pci_bus]);
600 }
601 strcat(str, " MHz)");
602
603 return (str);
604}
605
Andrew Vasquezfca29702005-07-06 10:31:47 -0700606static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800607qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700608{
609 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800610 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700611 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700612
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600613 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700614 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600615 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700616
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600617 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
618 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
619 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700620
621 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500622 switch (lspeed) {
623 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700624 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500625 break;
626 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700627 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500628 break;
629 case 3:
630 strcat(str, "8.0GT/s ");
631 break;
632 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700633 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500634 break;
635 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700636 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
637 strcat(str, lwstr);
638
639 return str;
640 }
641
642 strcpy(str, "PCI");
643 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
644 if (pci_bus == 0 || pci_bus == 8) {
645 strcat(str, " (");
646 strcat(str, pci_bus_modes[pci_bus >> 3]);
647 } else {
648 strcat(str, "-X ");
649 if (pci_bus & BIT_2)
650 strcat(str, "Mode 2");
651 else
652 strcat(str, "Mode 1");
653 strcat(str, " (");
654 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
655 }
656 strcat(str, " MHz)");
657
658 return str;
659}
660
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800661static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400662qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
664 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800665 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700666
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400667 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
668 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 if (ha->fw_attributes & BIT_9) {
671 strcat(str, "FLX");
672 return (str);
673 }
674
675 switch (ha->fw_attributes & 0xFF) {
676 case 0x7:
677 strcat(str, "EF");
678 break;
679 case 0x17:
680 strcat(str, "TP");
681 break;
682 case 0x37:
683 strcat(str, "IP");
684 break;
685 case 0x77:
686 strcat(str, "VI");
687 break;
688 default:
689 sprintf(un_str, "(%x)", ha->fw_attributes);
690 strcat(str, un_str);
691 break;
692 }
693 if (ha->fw_attributes & 0x100)
694 strcat(str, "X");
695
696 return (str);
697}
698
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800699static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400700qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700701{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800702 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700703
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400704 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800705 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700706 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700707}
708
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800709void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800710qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700711{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800712 srb_t *sp = ptr;
713 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800714 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800715 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700716
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800717 if (sp->flags & SRB_DMA_VALID) {
718 scsi_dma_unmap(cmd);
719 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700720 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700721
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800722 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
723 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
724 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
725 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
726 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700727
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700728 if (!ctx)
729 goto end;
730
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800731 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
732 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700733 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800734 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
735 }
736
737 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700738 struct crc_context *ctx0 = ctx;
739
740 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800741 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
742 }
743
744 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700745 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800746
747 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700748 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800749 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
750 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
751 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
752 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800753 }
754
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700755end:
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -0700756 if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) {
Duane Grigsby7401bc12017-06-21 13:48:42 -0700757 CMD_SP(cmd) = NULL;
758 qla2x00_rel_sp(sp);
759 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800760}
761
Michael Hernandezd7459522016-12-12 14:40:07 -0800762void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800763qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800764{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800765 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800766 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
767
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800768 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800769 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800770 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
771 sp, GET_CMD_SP(sp));
772 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400773 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800774 return;
775 }
776 if (!atomic_dec_and_test(&sp->ref_count))
777 return;
778
Joe Carnucciof3caa992017-08-23 15:05:09 -0700779 sp->free(sp);
Giridhar Malavali740e2932019-04-02 14:24:20 -0700780 cmd->result = res;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800781 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700782}
783
Michael Hernandezd7459522016-12-12 14:40:07 -0800784void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800785qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800786{
787 srb_t *sp = (srb_t *)ptr;
788 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
789 struct qla_hw_data *ha = sp->fcport->vha->hw;
790 void *ctx = GET_CMD_CTX_SP(sp);
791
792 if (sp->flags & SRB_DMA_VALID) {
793 scsi_dma_unmap(cmd);
794 sp->flags &= ~SRB_DMA_VALID;
795 }
796
797 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
798 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
799 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
800 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
801 }
802
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700803 if (!ctx)
804 goto end;
805
Michael Hernandezd7459522016-12-12 14:40:07 -0800806 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
807 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700808 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800809 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
810 }
811
812 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700813 struct crc_context *ctx0 = ctx;
814
815 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800816 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
817 }
818
819 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700820 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800821 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
822 ctx1->fcp_cmnd_dma);
823 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
824 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
825 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
826 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali50b81272018-12-21 09:33:45 -0800827 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
Michael Hernandezd7459522016-12-12 14:40:07 -0800828 }
Giridhar Malavali50b81272018-12-21 09:33:45 -0800829 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
830 struct crc_context *difctx = sp->u.scmd.ctx;
831 struct dsd_dma *dif_dsd, *nxt_dsd;
832
833 list_for_each_entry_safe(dif_dsd, nxt_dsd,
834 &difctx->ldif_dma_hndl_list, list) {
835 list_del(&dif_dsd->list);
836 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
837 dif_dsd->dsd_list_dma);
838 kfree(dif_dsd);
839 difctx->no_dif_bundl--;
840 }
841
842 list_for_each_entry_safe(dif_dsd, nxt_dsd,
843 &difctx->ldif_dsd_list, list) {
844 list_del(&dif_dsd->list);
845 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
846 dif_dsd->dsd_list_dma);
847 kfree(dif_dsd);
848 difctx->no_ldif_dsd--;
849 }
850
851 if (difctx->no_ldif_dsd) {
852 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
853 "%s: difctx->no_ldif_dsd=%x\n",
854 __func__, difctx->no_ldif_dsd);
855 }
856
857 if (difctx->no_dif_bundl) {
858 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
859 "%s: difctx->no_dif_bundl=%x\n",
860 __func__, difctx->no_dif_bundl);
861 }
862 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
863 }
864
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700865end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800866 CMD_SP(cmd) = NULL;
867 qla2xxx_rel_qpair_sp(sp->qpair, sp);
868}
869
870void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800871qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800872{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800873 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800874 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
875
876 cmd->result = res;
877
878 if (atomic_read(&sp->ref_count) == 0) {
879 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
880 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
881 sp, GET_CMD_SP(sp));
882 if (ql2xextended_error_logging & ql_dbg_io)
883 WARN_ON(atomic_read(&sp->ref_count) == 0);
884 return;
885 }
886 if (!atomic_dec_and_test(&sp->ref_count))
887 return;
888
Joe Carnucciof3caa992017-08-23 15:05:09 -0700889 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800890 cmd->scsi_done(cmd);
891}
892
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400893/* If we are SP1 here, we need to still take and release the host_lock as SP1
894 * does not have the changes necessary to avoid taking host->host_lock.
895 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800897qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700898{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700899 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700900 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400901 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800902 struct qla_hw_data *ha = vha->hw;
903 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700904 srb_t *sp;
905 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800906 struct qla_qpair *qpair = NULL;
907 uint32_t tag;
908 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700909
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200910 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
911 cmd->result = DID_NO_CONNECT << 16;
912 goto qc24_fail_command;
913 }
914
Michael Hernandez56012362016-12-12 14:40:08 -0800915 if (ha->mqenable) {
Jens Axboef664a3c2018-11-01 16:36:27 -0600916 tag = blk_mq_unique_tag(cmd->request);
917 hwq = blk_mq_unique_tag_to_hwq(tag);
918 qpair = ha->queue_pair_map[hwq];
Michael Hernandez56012362016-12-12 14:40:08 -0800919
920 if (qpair)
921 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800922 }
923
Andrew Vasquez85880802009-12-15 21:29:46 -0800924 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700925 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400926 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700927 "PCI Channel IO permanent failure, exiting "
928 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700929 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700930 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400931 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700932 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800933 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700934 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700935 goto qc24_fail_command;
936 }
937
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400938 rval = fc_remote_port_chkready(rport);
939 if (rval) {
940 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400941 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700942 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
943 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700944 goto qc24_fail_command;
945 }
946
Arun Easibad75002010-05-04 15:01:30 -0700947 if (!vha->flags.difdix_supported &&
948 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700949 ql_dbg(ql_dbg_io, vha, 0x3004,
950 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
951 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700952 cmd->result = DID_NO_CONNECT << 16;
953 goto qc24_fail_command;
954 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800955
956 if (!fcport) {
957 cmd->result = DID_NO_CONNECT << 16;
958 goto qc24_fail_command;
959 }
960
Andrew Vasquezfca29702005-07-06 10:31:47 -0700961 if (atomic_read(&fcport->state) != FCS_ONLINE) {
962 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700963 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700964 ql_dbg(ql_dbg_io, vha, 0x3005,
965 "Returning DNC, fcport_state=%d loop_state=%d.\n",
966 atomic_read(&fcport->state),
967 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700968 cmd->result = DID_NO_CONNECT << 16;
969 goto qc24_fail_command;
970 }
Mike Christie7b594132008-08-17 15:24:40 -0500971 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700972 }
973
Chad Dupuise05fe292014-09-25 05:16:59 -0400974 /*
975 * Return target busy if we've received a non-zero retry_delay_timer
976 * in a FCP_RSP.
977 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100978 if (fcport->retry_delay_timestamp == 0) {
979 /* retry delay not set */
980 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400981 fcport->retry_delay_timestamp = 0;
982 else
983 goto qc24_target_busy;
984
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500985 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400986 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800987 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700988
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800989 sp->u.scmd.cmd = cmd;
990 sp->type = SRB_SCSI_CMD;
991 atomic_set(&sp->ref_count, 1);
992 CMD_SP(cmd) = (void *)sp;
993 sp->free = qla2x00_sp_free_dma;
994 sp->done = qla2x00_sp_compl;
995
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800996 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700997 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500998 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700999 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001000 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001001 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001002
Andrew Vasquezfca29702005-07-06 10:31:47 -07001003 return 0;
1004
1005qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001006 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001007
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -08001008qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -07001009 return SCSI_MLQUEUE_HOST_BUSY;
1010
Mike Christie7b594132008-08-17 15:24:40 -05001011qc24_target_busy:
1012 return SCSI_MLQUEUE_TARGET_BUSY;
1013
Andrew Vasquezfca29702005-07-06 10:31:47 -07001014qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -08001015 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001016
1017 return 0;
1018}
1019
Michael Hernandezd7459522016-12-12 14:40:07 -08001020/* For MQ supported I/O */
1021int
1022qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
1023 struct qla_qpair *qpair)
1024{
1025 scsi_qla_host_t *vha = shost_priv(host);
1026 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1027 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
1028 struct qla_hw_data *ha = vha->hw;
1029 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1030 srb_t *sp;
1031 int rval;
1032
1033 rval = fc_remote_port_chkready(rport);
1034 if (rval) {
1035 cmd->result = rval;
1036 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
1037 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
1038 cmd, rval);
1039 goto qc24_fail_command;
1040 }
1041
1042 if (!fcport) {
1043 cmd->result = DID_NO_CONNECT << 16;
1044 goto qc24_fail_command;
1045 }
1046
1047 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1048 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
1049 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1050 ql_dbg(ql_dbg_io, vha, 0x3077,
1051 "Returning DNC, fcport_state=%d loop_state=%d.\n",
1052 atomic_read(&fcport->state),
1053 atomic_read(&base_vha->loop_state));
1054 cmd->result = DID_NO_CONNECT << 16;
1055 goto qc24_fail_command;
1056 }
1057 goto qc24_target_busy;
1058 }
1059
1060 /*
1061 * Return target busy if we've received a non-zero retry_delay_timer
1062 * in a FCP_RSP.
1063 */
1064 if (fcport->retry_delay_timestamp == 0) {
1065 /* retry delay not set */
1066 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1067 fcport->retry_delay_timestamp = 0;
1068 else
1069 goto qc24_target_busy;
1070
Quinn Tran6a629462018-09-04 14:19:15 -07001071 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
Michael Hernandezd7459522016-12-12 14:40:07 -08001072 if (!sp)
1073 goto qc24_host_busy;
1074
1075 sp->u.scmd.cmd = cmd;
1076 sp->type = SRB_SCSI_CMD;
1077 atomic_set(&sp->ref_count, 1);
1078 CMD_SP(cmd) = (void *)sp;
1079 sp->free = qla2xxx_qpair_sp_free_dma;
1080 sp->done = qla2xxx_qpair_sp_compl;
1081 sp->qpair = qpair;
1082
1083 rval = ha->isp_ops->start_scsi_mq(sp);
1084 if (rval != QLA_SUCCESS) {
1085 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1086 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1087 if (rval == QLA_INTERFACE_ERROR)
1088 goto qc24_fail_command;
1089 goto qc24_host_busy_free_sp;
1090 }
1091
1092 return 0;
1093
1094qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001095 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001096
1097qc24_host_busy:
1098 return SCSI_MLQUEUE_HOST_BUSY;
1099
1100qc24_target_busy:
1101 return SCSI_MLQUEUE_TARGET_BUSY;
1102
1103qc24_fail_command:
1104 cmd->scsi_done(cmd);
1105
1106 return 0;
1107}
1108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109/*
1110 * qla2x00_eh_wait_on_command
1111 * Waits for the command to be returned by the Firmware for some
1112 * max time.
1113 *
1114 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 *
1117 * Return:
1118 * Not Found : 0
1119 * Found : 1
1120 */
1121static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001122qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001124#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001125#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001126 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001127 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1128 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001129 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Andrew Vasquez85880802009-12-15 21:29:46 -08001131 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001132 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1133 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001134 return ret;
1135 }
1136
Lalit Chandivaded9704322009-08-25 11:36:18 -07001137 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001138 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001139 }
1140 if (CMD_SP(cmd))
1141 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
f4f051e2005-04-17 15:02:26 -05001143 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
1146/*
1147 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001148 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 * <= MAX_RETRIES_OF_ISP_ABORT or
1150 * finally HBA is disabled ie marked offline
1151 *
1152 * Input:
1153 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001154 *
1155 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 * Does context switching-Release SPIN_LOCK
1157 * (if any) before calling this routine.
1158 *
1159 * Return:
1160 * Success (Adapter is online) : 0
1161 * Failed (Adapter is offline/disabled) : 1
1162 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001163int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001164qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001166 int return_status;
1167 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001168 struct qla_hw_data *ha = vha->hw;
1169 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001171 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001172 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1173 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1174 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1175 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 msleep(1000);
1178 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001179 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001180 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 else
1182 return_status = QLA_FUNCTION_FAILED;
1183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 return (return_status);
1185}
1186
Quinn Tran726b8542017-01-19 22:28:00 -08001187static inline int test_fcport_count(scsi_qla_host_t *vha)
1188{
1189 struct qla_hw_data *ha = vha->hw;
1190 unsigned long flags;
1191 int res;
1192
1193 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001194 ql_dbg(ql_dbg_init, vha, 0x00ec,
1195 "tgt %p, fcport_count=%d\n",
1196 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001197 res = (vha->fcport_count == 0);
1198 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1199
1200 return res;
1201}
1202
1203/*
1204 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1205 * it has dependency on UNLOADING flag to stop device discovery
1206 */
Quinn Tranefa93f42018-07-18 14:29:52 -07001207void
Quinn Tran726b8542017-01-19 22:28:00 -08001208qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1209{
1210 qla2x00_mark_all_devices_lost(vha, 0);
1211
Joe Carnucciob85e0952017-08-23 15:05:11 -07001212 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001213}
1214
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001215/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001216 * qla2x00_wait_for_hba_ready
1217 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001218 *
1219 * Input:
1220 * ha - pointer to host adapter structure
1221 *
1222 * Note:
1223 * Does context switching-Release SPIN_LOCK
1224 * (if any) before calling this routine.
1225 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001226 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001227static void
1228qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001229{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001230 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001231 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001232
Dan Carpenter1d483902016-08-03 21:42:32 +03001233 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1234 ha->flags.mbox_busy) ||
1235 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1236 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1237 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1238 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001239 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001240 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001241}
1242
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001243int
1244qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1245{
1246 int return_status;
1247 unsigned long wait_reset;
1248 struct qla_hw_data *ha = vha->hw;
1249 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1250
1251 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1252 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1253 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1254 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1255 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1256
1257 msleep(1000);
1258
1259 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1260 ha->flags.chip_reset_done)
1261 break;
1262 }
1263 if (ha->flags.chip_reset_done)
1264 return_status = QLA_SUCCESS;
1265 else
1266 return_status = QLA_FUNCTION_FAILED;
1267
1268 return return_status;
1269}
1270
Quinn Tran585def92018-09-04 14:19:20 -07001271static int
Giridhar Malavali083a4692010-05-28 15:08:18 -07001272sp_get(struct srb *sp)
1273{
Quinn Tran585def92018-09-04 14:19:20 -07001274 if (!refcount_inc_not_zero((refcount_t*)&sp->ref_count))
1275 /* kref get fail */
1276 return ENXIO;
1277 else
1278 return 0;
Giridhar Malavali083a4692010-05-28 15:08:18 -07001279}
1280
Sawan Chandaka4655372016-07-06 11:14:32 -04001281#define ISP_REG_DISCONNECT 0xffffffffU
1282/**************************************************************************
1283* qla2x00_isp_reg_stat
1284*
1285* Description:
1286* Read the host status register of ISP before aborting the command.
1287*
1288* Input:
1289* ha = pointer to host adapter structure.
1290*
1291*
1292* Returns:
1293* Either true or false.
1294*
1295* Note: Return true if there is register disconnect.
1296**************************************************************************/
1297static inline
1298uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1299{
1300 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001301 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001302
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001303 if (IS_P3P_TYPE(ha))
1304 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1305 else
1306 return ((RD_REG_DWORD(&reg->host_status)) ==
1307 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001308}
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310/**************************************************************************
1311* qla2xxx_eh_abort
1312*
1313* Description:
1314* The abort function will abort the specified command.
1315*
1316* Input:
1317* cmd = Linux SCSI command packet to be aborted.
1318*
1319* Returns:
1320* Either SUCCESS or FAILED.
1321*
1322* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001323* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001325static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1327{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001328 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001329 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001330 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001331 unsigned int id;
1332 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001333 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001334 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001335 struct qla_hw_data *ha = vha->hw;
Quinn Tran585def92018-09-04 14:19:20 -07001336 struct qla_qpair *qpair;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Sawan Chandaka4655372016-07-06 11:14:32 -04001338 if (qla2x00_isp_reg_stat(ha)) {
1339 ql_log(ql_log_info, vha, 0x8042,
1340 "PCI/Register disconnect, exiting.\n");
1341 return FAILED;
1342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001344 ret = fc_block_scsi_eh(cmd);
1345 if (ret != 0)
1346 return ret;
1347 ret = SUCCESS;
1348
Mike Christie170babc2010-10-15 11:27:47 -07001349 sp = (srb_t *) CMD_SP(cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001350 if (!sp)
1351 return SUCCESS;
1352
1353 qpair = sp->qpair;
1354 if (!qpair)
1355 return SUCCESS;
1356
1357 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1358 if (!CMD_SP(cmd)) {
1359 /* there's a chance an interrupt could clear
1360 the ptr as part of done & free */
1361 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001362 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001363 }
Mike Christie170babc2010-10-15 11:27:47 -07001364
Quinn Tran585def92018-09-04 14:19:20 -07001365 if (sp_get(sp)){
1366 /* ref_count is already 0 */
1367 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1368 return SUCCESS;
1369 }
1370 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1371
1372 id = cmd->device->id;
1373 lun = cmd->device->lun;
1374
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001375 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001376 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1377 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001378
1379 /* Get a reference to the sp and drop the lock.*/
Mike Christie170babc2010-10-15 11:27:47 -07001380
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001381 rval = ha->isp_ops->abort_command(sp);
1382 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001383 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001384 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001385 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001386 ret = FAILED;
1387
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001388 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001389 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001390 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001391 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001392 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001393 wait = 1;
1394 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001395
Quinn Tran585def92018-09-04 14:19:20 -07001396 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1397 /*
1398 * Clear the slot in the oustanding_cmds array if we can't find the
1399 * command to reclaim the resources.
1400 */
1401 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
1402 vha->req->outstanding_cmds[sp->handle] = NULL;
1403
1404 /*
1405 * sp->done will do ref_count--
1406 * sp_get() took an extra count above
1407 */
1408 sp->done(sp, DID_RESET << 16);
f4f051e2005-04-17 15:02:26 -05001409
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001410 /* Did the command return during mailbox execution? */
1411 if (ret == FAILED && !CMD_SP(cmd))
1412 ret = SUCCESS;
1413
Quinn Tran585def92018-09-04 14:19:20 -07001414 if (!CMD_SP(cmd))
1415 wait = 0;
1416
1417 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1418
f4f051e2005-04-17 15:02:26 -05001419 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001420 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001421 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001422 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001423 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001424 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001428 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001429 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001430 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
f4f051e2005-04-17 15:02:26 -05001432 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433}
1434
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001435int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001436qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001437 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001439 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001440 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001441 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001442 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001443 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001444 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Andrew Vasquez523ec772008-04-03 13:13:24 -07001446 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001447
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001448 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001449 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001450 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001451 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001452 sp = req->outstanding_cmds[cnt];
1453 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001454 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001455 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001456 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001457 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001458 continue;
1459 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001460 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001461 switch (type) {
1462 case WAIT_HOST:
1463 match = 1;
1464 break;
1465 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001466 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001467 break;
1468 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001469 match = (cmd->device->id == t &&
1470 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001471 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001473 if (!match)
1474 continue;
1475
1476 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001477 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001478 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001481
1482 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483}
1484
Andrew Vasquez523ec772008-04-03 13:13:24 -07001485static char *reset_errors[] = {
1486 "HBA not online",
1487 "HBA not ready",
1488 "Task management failed",
1489 "Waiting for command completions",
1490};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Andrew Vasquez523ec772008-04-03 13:13:24 -07001492static int
1493__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001494 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001495{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001496 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001497 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1498 int err;
1499
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001500 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001501 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001502 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001503
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001504 err = fc_block_scsi_eh(cmd);
1505 if (err != 0)
1506 return err;
1507
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001508 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001509 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001510 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001511
1512 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001513 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1514 ql_log(ql_log_warn, vha, 0x800a,
1515 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001516 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001517 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001518 err = 2;
Jens Axboe9cf2bab2018-10-31 17:01:22 -06001519 if (do_reset(fcport, cmd->device->lun, blk_mq_rq_cpu(cmd->request) + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001520 != QLA_SUCCESS) {
1521 ql_log(ql_log_warn, vha, 0x800c,
1522 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001523 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001524 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001525 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001527 cmd->device->lun, type) != QLA_SUCCESS) {
1528 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001529 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001530 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001531 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001532
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001533 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001534 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001535 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001536
1537 return SUCCESS;
1538
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001539eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001540 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001541 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001542 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1543 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001544 return FAILED;
1545}
1546
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001547static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1549{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1551 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Sawan Chandaka4655372016-07-06 11:14:32 -04001553 if (qla2x00_isp_reg_stat(ha)) {
1554 ql_log(ql_log_info, vha, 0x803e,
1555 "PCI/Register disconnect, exiting.\n");
1556 return FAILED;
1557 }
1558
Andrew Vasquez523ec772008-04-03 13:13:24 -07001559 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1560 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001564qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001566 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1567 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Sawan Chandaka4655372016-07-06 11:14:32 -04001569 if (qla2x00_isp_reg_stat(ha)) {
1570 ql_log(ql_log_info, vha, 0x803f,
1571 "PCI/Register disconnect, exiting.\n");
1572 return FAILED;
1573 }
1574
Andrew Vasquez523ec772008-04-03 13:13:24 -07001575 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1576 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579/**************************************************************************
1580* qla2xxx_eh_bus_reset
1581*
1582* Description:
1583* The bus reset function will reset the bus and abort any executing
1584* commands.
1585*
1586* Input:
1587* cmd = Linux SCSI command packet of the command that cause the
1588* bus reset.
1589*
1590* Returns:
1591* SUCCESS/FAILURE (defined as macro in scsi.h).
1592*
1593**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001594static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1596{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001598 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001599 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001600 unsigned int id;
1601 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001602 struct qla_hw_data *ha = vha->hw;
1603
1604 if (qla2x00_isp_reg_stat(ha)) {
1605 ql_log(ql_log_info, vha, 0x8040,
1606 "PCI/Register disconnect, exiting.\n");
1607 return FAILED;
1608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
f4f051e2005-04-17 15:02:26 -05001610 id = cmd->device->id;
1611 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001612
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001613 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001614 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001615 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001617 ret = fc_block_scsi_eh(cmd);
1618 if (ret != 0)
1619 return ret;
1620 ret = FAILED;
1621
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001622 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001623 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001625 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001626 ql_log(ql_log_fatal, vha, 0x8013,
1627 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001628 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 }
1630
Saurav Kashyapad5376892011-11-18 09:02:09 -08001631 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1632 ret = SUCCESS;
1633
f4f051e2005-04-17 15:02:26 -05001634 if (ret == FAILED)
1635 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001637 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001638 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001639 QLA_SUCCESS) {
1640 ql_log(ql_log_warn, vha, 0x8014,
1641 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001642 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
f4f051e2005-04-17 15:02:26 -05001645eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001646 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001647 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001648 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
f4f051e2005-04-17 15:02:26 -05001650 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
1653/**************************************************************************
1654* qla2xxx_eh_host_reset
1655*
1656* Description:
1657* The reset function will reset the Adapter.
1658*
1659* Input:
1660* cmd = Linux SCSI command packet of the command that cause the
1661* adapter reset.
1662*
1663* Returns:
1664* Either SUCCESS or FAILED.
1665*
1666* Note:
1667**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001668static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1670{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001671 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001673 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001674 unsigned int id;
1675 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Sawan Chandaka4655372016-07-06 11:14:32 -04001678 if (qla2x00_isp_reg_stat(ha)) {
1679 ql_log(ql_log_info, vha, 0x8041,
1680 "PCI/Register disconnect, exiting.\n");
1681 schedule_work(&ha->board_disable);
1682 return SUCCESS;
1683 }
1684
f4f051e2005-04-17 15:02:26 -05001685 id = cmd->device->id;
1686 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001687
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001688 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001689 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
Chad Dupuis63ee7072014-04-11 16:54:46 -04001691 /*
1692 * No point in issuing another reset if one is active. Also do not
1693 * attempt a reset if we are updating flash.
1694 */
1695 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001696 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001698 if (vha != base_vha) {
1699 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001700 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001701 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001702 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001703 if (!qla82xx_fcoe_ctx_reset(vha)) {
1704 /* Ctx reset success */
1705 ret = SUCCESS;
1706 goto eh_host_reset_lock;
1707 }
1708 /* fall thru if ctx reset failed */
1709 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001710 if (ha->wq)
1711 flush_workqueue(ha->wq);
1712
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001713 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001714 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001715 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1716 /* failed. schedule dpc to try */
1717 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1718
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001719 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1720 ql_log(ql_log_warn, vha, 0x802a,
1721 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001722 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001723 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001724 }
1725 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001728 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001729 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001730 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001731 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
f4f051e2005-04-17 15:02:26 -05001733eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001734 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001735 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001736 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
f4f051e2005-04-17 15:02:26 -05001738 return ret;
1739}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741/*
1742* qla2x00_loop_reset
1743* Issue loop reset.
1744*
1745* Input:
1746* ha = adapter block pointer.
1747*
1748* Returns:
1749* 0 = success
1750*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001751int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001752qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001754 int ret;
bdf79622005-04-17 15:06:53 -05001755 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Armen Baloyan58547712013-08-27 01:37:33 -04001758 if (IS_QLAFX00(ha)) {
1759 return qlafx00_loop_reset(vha);
1760 }
1761
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001762 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001763 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1764 if (fcport->port_type != FCT_TARGET)
1765 continue;
1766
1767 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1768 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001769 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001770 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001771 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001772 }
1773 }
1774 }
1775
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001776
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001777 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001778 atomic_set(&vha->loop_state, LOOP_DOWN);
1779 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1780 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001781 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001782 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001783 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1784 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001785 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 }
1787
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001788 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001789 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001790 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001791 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1792 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001793 }
1794
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001796 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001798 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001801static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1802 unsigned long *flags)
1803 __releases(qp->qp_lock_ptr)
1804 __acquires(qp->qp_lock_ptr)
1805{
1806 scsi_qla_host_t *vha = qp->vha;
1807 struct qla_hw_data *ha = vha->hw;
1808
1809 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS) {
1810 if (!sp_get(sp)) {
1811 /* got sp */
1812 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1813 qla_nvme_abort(ha, sp, res);
1814 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1815 }
1816 } else if (GET_CMD_SP(sp) && !ha->flags.eeh_busy &&
1817 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1818 !qla2x00_isp_reg_stat(ha) && sp->type == SRB_SCSI_CMD) {
1819 /*
1820 * Don't abort commands in adapter during EEH recovery as it's
1821 * not accessible/responding.
1822 *
1823 * Get a reference to the sp and drop the lock. The reference
1824 * ensures this sp->done() call and not the call in
1825 * qla2xxx_eh_abort() ends the SCSI cmd (with result 'res').
1826 */
1827 if (!sp_get(sp)) {
Linus Torvalds938edb82018-12-28 14:48:06 -08001828 int status;
1829
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001830 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
Linus Torvalds938edb82018-12-28 14:48:06 -08001831 status = qla2xxx_eh_abort(GET_CMD_SP(sp));
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001832 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
Linus Torvalds938edb82018-12-28 14:48:06 -08001833 /*
1834 * Get rid of extra reference caused
1835 * by early exit from qla2xxx_eh_abort
1836 */
1837 if (status == FAST_IO_FAIL)
1838 atomic_dec(&sp->ref_count);
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001839 }
1840 }
1841 sp->done(sp, res);
1842}
1843
Quinn Tranbbead492017-12-28 12:33:13 -08001844static void
1845__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001846{
Bart Van Asscheeb023222018-10-18 15:45:44 -07001847 int cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001848 unsigned long flags;
1849 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001850 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001851 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001852 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001853 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1854 struct qla_tgt_cmd *cmd;
Arun Easic0cb4492014-09-25 06:14:51 -04001855
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001856 if (!ha->req_q_map)
1857 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001858 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1859 req = qp->req;
1860 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1861 sp = req->outstanding_cmds[cnt];
1862 if (sp) {
1863 req->outstanding_cmds[cnt] = NULL;
Quinn Tran6b0431d2018-09-04 14:19:13 -07001864 switch (sp->cmd_type) {
1865 case TYPE_SRB:
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001866 qla2x00_abort_srb(qp, sp, res, &flags);
Quinn Tran585def92018-09-04 14:19:20 -07001867 break;
1868 case TYPE_TGT_CMD:
Quinn Tranbbead492017-12-28 12:33:13 -08001869 if (!vha->hw->tgt.tgt_ops || !tgt ||
1870 qla_ini_mode_enabled(vha)) {
Quinn Tran585def92018-09-04 14:19:20 -07001871 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1872 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1873 vha->dpc_flags);
Quinn Tranbbead492017-12-28 12:33:13 -08001874 continue;
1875 }
1876 cmd = (struct qla_tgt_cmd *)sp;
1877 qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001878 break;
1879 case TYPE_TGT_TMCMD:
1880 /*
1881 * Currently, only ABTS response gets on the
1882 * outstanding_cmds[]
1883 */
1884 ha->tgt.tgt_ops->free_mcmd(
1885 (struct qla_tgt_mgmt_cmd *)sp);
1886 break;
1887 default:
1888 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001889 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001890 }
1891 }
Quinn Tranbbead492017-12-28 12:33:13 -08001892 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1893}
1894
1895void
1896qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1897{
1898 int que;
1899 struct qla_hw_data *ha = vha->hw;
1900
1901 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1902
1903 for (que = 0; que < ha->max_qpairs; que++) {
1904 if (!ha->queue_pair_map[que])
1905 continue;
1906
1907 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1908 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001909}
1910
f4f051e2005-04-17 15:02:26 -05001911static int
1912qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
bdf79622005-04-17 15:06:53 -05001914 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001916 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001917 return -ENXIO;
1918
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001919 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001920
1921 return 0;
1922}
1923
1924static int
1925qla2xxx_slave_configure(struct scsi_device *sdev)
1926{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001927 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001928 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001929
Arun Easi9e522cd2012-08-22 14:21:31 -04001930 if (IS_T10_PI_CAPABLE(vha->hw))
1931 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1932
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001933 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001934 return 0;
1935}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
f4f051e2005-04-17 15:02:26 -05001937static void
1938qla2xxx_slave_destroy(struct scsi_device *sdev)
1939{
1940 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941}
1942
1943/**
1944 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1945 * @ha: HA context
1946 *
1947 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1948 * supported addressing method.
1949 */
1950static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001951qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001953 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Yang Hongyang6a355282009-04-06 19:01:13 -07001956 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001957 /* Any upper-dword bits set? */
1958 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001959 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001960 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001962 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1963 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001964 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001967
Yang Hongyang284901a2009-04-06 19:01:15 -07001968 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1969 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970}
1971
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001972static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001973qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001974{
1975 unsigned long flags = 0;
1976 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1977
1978 spin_lock_irqsave(&ha->hardware_lock, flags);
1979 ha->interrupts_on = 1;
1980 /* enable risc and host interrupts */
1981 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1982 RD_REG_WORD(&reg->ictrl);
1983 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1984
1985}
1986
1987static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001988qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001989{
1990 unsigned long flags = 0;
1991 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1992
1993 spin_lock_irqsave(&ha->hardware_lock, flags);
1994 ha->interrupts_on = 0;
1995 /* disable risc and host interrupts */
1996 WRT_REG_WORD(&reg->ictrl, 0);
1997 RD_REG_WORD(&reg->ictrl);
1998 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1999}
2000
2001static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002002qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002003{
2004 unsigned long flags = 0;
2005 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2006
2007 spin_lock_irqsave(&ha->hardware_lock, flags);
2008 ha->interrupts_on = 1;
2009 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
2010 RD_REG_DWORD(&reg->ictrl);
2011 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2012}
2013
2014static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002016{
2017 unsigned long flags = 0;
2018 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2019
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002020 if (IS_NOPOLLING_TYPE(ha))
2021 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002022 spin_lock_irqsave(&ha->hardware_lock, flags);
2023 ha->interrupts_on = 0;
2024 WRT_REG_DWORD(&reg->ictrl, 0);
2025 RD_REG_DWORD(&reg->ictrl);
2026 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2027}
2028
Giridhar Malavali706f4572011-11-18 09:03:16 -08002029static int
2030qla2x00_iospace_config(struct qla_hw_data *ha)
2031{
2032 resource_size_t pio;
2033 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002034
Giridhar Malavali706f4572011-11-18 09:03:16 -08002035 if (pci_request_selected_regions(ha->pdev, ha->bars,
2036 QLA2XXX_DRIVER_NAME)) {
2037 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
2038 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2039 pci_name(ha->pdev));
2040 goto iospace_error_exit;
2041 }
2042 if (!(ha->bars & 1))
2043 goto skip_pio;
2044
2045 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
2046 pio = pci_resource_start(ha->pdev, 0);
2047 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
2048 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2049 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
2050 "Invalid pci I/O region size (%s).\n",
2051 pci_name(ha->pdev));
2052 pio = 0;
2053 }
2054 } else {
2055 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
2056 "Region #0 no a PIO resource (%s).\n",
2057 pci_name(ha->pdev));
2058 pio = 0;
2059 }
2060 ha->pio_address = pio;
2061 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2062 "PIO address=%llu.\n",
2063 (unsigned long long)ha->pio_address);
2064
2065skip_pio:
2066 /* Use MMIO operations for all accesses. */
2067 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2068 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2069 "Region #1 not an MMIO resource (%s), aborting.\n",
2070 pci_name(ha->pdev));
2071 goto iospace_error_exit;
2072 }
2073 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2074 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2075 "Invalid PCI mem region size (%s), aborting.\n",
2076 pci_name(ha->pdev));
2077 goto iospace_error_exit;
2078 }
2079
2080 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2081 if (!ha->iobase) {
2082 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2083 "Cannot remap MMIO (%s), aborting.\n",
2084 pci_name(ha->pdev));
2085 goto iospace_error_exit;
2086 }
2087
2088 /* Determine queue resources */
2089 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002090 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002091 if (!ql2xmqsupport || !ql2xnvmeenable ||
2092 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08002093 goto mqiobase_exit;
2094
2095 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2096 pci_resource_len(ha->pdev, 3));
2097 if (ha->mqiobase) {
2098 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2099 "MQIO Base=%p.\n", ha->mqiobase);
2100 /* Read MSIX vector size of the board */
2101 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002102 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002103 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002104 /* MB interrupt uses 1 vector */
2105 ha->max_req_queues = ha->msix_count - 1;
2106 ha->max_rsp_queues = ha->max_req_queues;
2107 /* Queue pairs is the max value minus the base queue pair */
2108 ha->max_qpairs = ha->max_rsp_queues - 1;
2109 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2110 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2111
Giridhar Malavali706f4572011-11-18 09:03:16 -08002112 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002113 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002114 } else
2115 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2116 "BAR 3 not enabled.\n");
2117
2118mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002119 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002120 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002121 return (0);
2122
2123iospace_error_exit:
2124 return (-ENOMEM);
2125}
2126
2127
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002128static int
2129qla83xx_iospace_config(struct qla_hw_data *ha)
2130{
2131 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002132
2133 if (pci_request_selected_regions(ha->pdev, ha->bars,
2134 QLA2XXX_DRIVER_NAME)) {
2135 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2136 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2137 pci_name(ha->pdev));
2138
2139 goto iospace_error_exit;
2140 }
2141
2142 /* Use MMIO operations for all accesses. */
2143 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2144 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2145 "Invalid pci I/O region size (%s).\n",
2146 pci_name(ha->pdev));
2147 goto iospace_error_exit;
2148 }
2149 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2150 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2151 "Invalid PCI mem region size (%s), aborting\n",
2152 pci_name(ha->pdev));
2153 goto iospace_error_exit;
2154 }
2155
2156 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2157 if (!ha->iobase) {
2158 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2159 "Cannot remap MMIO (%s), aborting.\n",
2160 pci_name(ha->pdev));
2161 goto iospace_error_exit;
2162 }
2163
2164 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2165 /* 83XX 26XX always use MQ type access for queues
2166 * - mbar 2, a.k.a region 4 */
2167 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002168 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002169 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2170 pci_resource_len(ha->pdev, 4));
2171
2172 if (!ha->mqiobase) {
2173 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2174 "BAR2/region4 not enabled\n");
2175 goto mqiobase_exit;
2176 }
2177
2178 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2179 pci_resource_len(ha->pdev, 2));
2180 if (ha->msixbase) {
2181 /* Read MSIX vector size of the board */
2182 pci_read_config_word(ha->pdev,
2183 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002184 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002185 /*
2186 * By default, driver uses at least two msix vectors
2187 * (default & rspq)
2188 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002189 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002190 /* MB interrupt uses 1 vector */
2191 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002192
2193 /* ATIOQ needs 1 vector. That's 1 less QPair */
2194 if (QLA_TGT_MODE_ENABLED())
2195 ha->max_req_queues--;
2196
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002197 ha->max_rsp_queues = ha->max_req_queues;
2198
Michael Hernandezd7459522016-12-12 14:40:07 -08002199 /* Queue pairs is the max value minus
2200 * the base queue pair */
2201 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002202 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002203 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002204 }
2205 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002206 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002207 } else
2208 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2209 "BAR 1 not enabled.\n");
2210
2211mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002212 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002213 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002214 return 0;
2215
2216iospace_error_exit:
2217 return -ENOMEM;
2218}
2219
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002220static struct isp_operations qla2100_isp_ops = {
2221 .pci_config = qla2100_pci_config,
2222 .reset_chip = qla2x00_reset_chip,
2223 .chip_diag = qla2x00_chip_diag,
2224 .config_rings = qla2x00_config_rings,
2225 .reset_adapter = qla2x00_reset_adapter,
2226 .nvram_config = qla2x00_nvram_config,
2227 .update_fw_options = qla2x00_update_fw_options,
2228 .load_risc = qla2x00_load_risc,
2229 .pci_info_str = qla2x00_pci_info_str,
2230 .fw_version_str = qla2x00_fw_version_str,
2231 .intr_handler = qla2100_intr_handler,
2232 .enable_intrs = qla2x00_enable_intrs,
2233 .disable_intrs = qla2x00_disable_intrs,
2234 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002235 .target_reset = qla2x00_abort_target,
2236 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002237 .fabric_login = qla2x00_login_fabric,
2238 .fabric_logout = qla2x00_fabric_logout,
2239 .calc_req_entries = qla2x00_calc_iocbs_32,
2240 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2241 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2242 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2243 .read_nvram = qla2x00_read_nvram_data,
2244 .write_nvram = qla2x00_write_nvram_data,
2245 .fw_dump = qla2100_fw_dump,
2246 .beacon_on = NULL,
2247 .beacon_off = NULL,
2248 .beacon_blink = NULL,
2249 .read_optrom = qla2x00_read_optrom_data,
2250 .write_optrom = qla2x00_write_optrom_data,
2251 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002252 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002253 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002254 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002255 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002256 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002257};
2258
2259static struct isp_operations qla2300_isp_ops = {
2260 .pci_config = qla2300_pci_config,
2261 .reset_chip = qla2x00_reset_chip,
2262 .chip_diag = qla2x00_chip_diag,
2263 .config_rings = qla2x00_config_rings,
2264 .reset_adapter = qla2x00_reset_adapter,
2265 .nvram_config = qla2x00_nvram_config,
2266 .update_fw_options = qla2x00_update_fw_options,
2267 .load_risc = qla2x00_load_risc,
2268 .pci_info_str = qla2x00_pci_info_str,
2269 .fw_version_str = qla2x00_fw_version_str,
2270 .intr_handler = qla2300_intr_handler,
2271 .enable_intrs = qla2x00_enable_intrs,
2272 .disable_intrs = qla2x00_disable_intrs,
2273 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002274 .target_reset = qla2x00_abort_target,
2275 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002276 .fabric_login = qla2x00_login_fabric,
2277 .fabric_logout = qla2x00_fabric_logout,
2278 .calc_req_entries = qla2x00_calc_iocbs_32,
2279 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2280 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2281 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2282 .read_nvram = qla2x00_read_nvram_data,
2283 .write_nvram = qla2x00_write_nvram_data,
2284 .fw_dump = qla2300_fw_dump,
2285 .beacon_on = qla2x00_beacon_on,
2286 .beacon_off = qla2x00_beacon_off,
2287 .beacon_blink = qla2x00_beacon_blink,
2288 .read_optrom = qla2x00_read_optrom_data,
2289 .write_optrom = qla2x00_write_optrom_data,
2290 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002292 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002293 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002294 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002295 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002296};
2297
2298static struct isp_operations qla24xx_isp_ops = {
2299 .pci_config = qla24xx_pci_config,
2300 .reset_chip = qla24xx_reset_chip,
2301 .chip_diag = qla24xx_chip_diag,
2302 .config_rings = qla24xx_config_rings,
2303 .reset_adapter = qla24xx_reset_adapter,
2304 .nvram_config = qla24xx_nvram_config,
2305 .update_fw_options = qla24xx_update_fw_options,
2306 .load_risc = qla24xx_load_risc,
2307 .pci_info_str = qla24xx_pci_info_str,
2308 .fw_version_str = qla24xx_fw_version_str,
2309 .intr_handler = qla24xx_intr_handler,
2310 .enable_intrs = qla24xx_enable_intrs,
2311 .disable_intrs = qla24xx_disable_intrs,
2312 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002313 .target_reset = qla24xx_abort_target,
2314 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002315 .fabric_login = qla24xx_login_fabric,
2316 .fabric_logout = qla24xx_fabric_logout,
2317 .calc_req_entries = NULL,
2318 .build_iocbs = NULL,
2319 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2320 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2321 .read_nvram = qla24xx_read_nvram_data,
2322 .write_nvram = qla24xx_write_nvram_data,
2323 .fw_dump = qla24xx_fw_dump,
2324 .beacon_on = qla24xx_beacon_on,
2325 .beacon_off = qla24xx_beacon_off,
2326 .beacon_blink = qla24xx_beacon_blink,
2327 .read_optrom = qla24xx_read_optrom_data,
2328 .write_optrom = qla24xx_write_optrom_data,
2329 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002330 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002331 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002332 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002333 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002334 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002335};
2336
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002337static struct isp_operations qla25xx_isp_ops = {
2338 .pci_config = qla25xx_pci_config,
2339 .reset_chip = qla24xx_reset_chip,
2340 .chip_diag = qla24xx_chip_diag,
2341 .config_rings = qla24xx_config_rings,
2342 .reset_adapter = qla24xx_reset_adapter,
2343 .nvram_config = qla24xx_nvram_config,
2344 .update_fw_options = qla24xx_update_fw_options,
2345 .load_risc = qla24xx_load_risc,
2346 .pci_info_str = qla24xx_pci_info_str,
2347 .fw_version_str = qla24xx_fw_version_str,
2348 .intr_handler = qla24xx_intr_handler,
2349 .enable_intrs = qla24xx_enable_intrs,
2350 .disable_intrs = qla24xx_disable_intrs,
2351 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002352 .target_reset = qla24xx_abort_target,
2353 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002354 .fabric_login = qla24xx_login_fabric,
2355 .fabric_logout = qla24xx_fabric_logout,
2356 .calc_req_entries = NULL,
2357 .build_iocbs = NULL,
2358 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2359 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2360 .read_nvram = qla25xx_read_nvram_data,
2361 .write_nvram = qla25xx_write_nvram_data,
2362 .fw_dump = qla25xx_fw_dump,
2363 .beacon_on = qla24xx_beacon_on,
2364 .beacon_off = qla24xx_beacon_off,
2365 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002366 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002367 .write_optrom = qla24xx_write_optrom_data,
2368 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002369 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002370 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002371 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002372 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002373 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002374};
2375
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002376static struct isp_operations qla81xx_isp_ops = {
2377 .pci_config = qla25xx_pci_config,
2378 .reset_chip = qla24xx_reset_chip,
2379 .chip_diag = qla24xx_chip_diag,
2380 .config_rings = qla24xx_config_rings,
2381 .reset_adapter = qla24xx_reset_adapter,
2382 .nvram_config = qla81xx_nvram_config,
2383 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002384 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002385 .pci_info_str = qla24xx_pci_info_str,
2386 .fw_version_str = qla24xx_fw_version_str,
2387 .intr_handler = qla24xx_intr_handler,
2388 .enable_intrs = qla24xx_enable_intrs,
2389 .disable_intrs = qla24xx_disable_intrs,
2390 .abort_command = qla24xx_abort_command,
2391 .target_reset = qla24xx_abort_target,
2392 .lun_reset = qla24xx_lun_reset,
2393 .fabric_login = qla24xx_login_fabric,
2394 .fabric_logout = qla24xx_fabric_logout,
2395 .calc_req_entries = NULL,
2396 .build_iocbs = NULL,
2397 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2398 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002399 .read_nvram = NULL,
2400 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002401 .fw_dump = qla81xx_fw_dump,
2402 .beacon_on = qla24xx_beacon_on,
2403 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002404 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002405 .read_optrom = qla25xx_read_optrom_data,
2406 .write_optrom = qla24xx_write_optrom_data,
2407 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002408 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002409 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002410 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002411 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002412 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002413};
2414
2415static struct isp_operations qla82xx_isp_ops = {
2416 .pci_config = qla82xx_pci_config,
2417 .reset_chip = qla82xx_reset_chip,
2418 .chip_diag = qla24xx_chip_diag,
2419 .config_rings = qla82xx_config_rings,
2420 .reset_adapter = qla24xx_reset_adapter,
2421 .nvram_config = qla81xx_nvram_config,
2422 .update_fw_options = qla24xx_update_fw_options,
2423 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002424 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002425 .fw_version_str = qla24xx_fw_version_str,
2426 .intr_handler = qla82xx_intr_handler,
2427 .enable_intrs = qla82xx_enable_intrs,
2428 .disable_intrs = qla82xx_disable_intrs,
2429 .abort_command = qla24xx_abort_command,
2430 .target_reset = qla24xx_abort_target,
2431 .lun_reset = qla24xx_lun_reset,
2432 .fabric_login = qla24xx_login_fabric,
2433 .fabric_logout = qla24xx_fabric_logout,
2434 .calc_req_entries = NULL,
2435 .build_iocbs = NULL,
2436 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2437 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2438 .read_nvram = qla24xx_read_nvram_data,
2439 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002440 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002441 .beacon_on = qla82xx_beacon_on,
2442 .beacon_off = qla82xx_beacon_off,
2443 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002444 .read_optrom = qla82xx_read_optrom_data,
2445 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002446 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002447 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002448 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002449 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002450 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002451 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002452};
2453
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002454static struct isp_operations qla8044_isp_ops = {
2455 .pci_config = qla82xx_pci_config,
2456 .reset_chip = qla82xx_reset_chip,
2457 .chip_diag = qla24xx_chip_diag,
2458 .config_rings = qla82xx_config_rings,
2459 .reset_adapter = qla24xx_reset_adapter,
2460 .nvram_config = qla81xx_nvram_config,
2461 .update_fw_options = qla24xx_update_fw_options,
2462 .load_risc = qla82xx_load_risc,
2463 .pci_info_str = qla24xx_pci_info_str,
2464 .fw_version_str = qla24xx_fw_version_str,
2465 .intr_handler = qla8044_intr_handler,
2466 .enable_intrs = qla82xx_enable_intrs,
2467 .disable_intrs = qla82xx_disable_intrs,
2468 .abort_command = qla24xx_abort_command,
2469 .target_reset = qla24xx_abort_target,
2470 .lun_reset = qla24xx_lun_reset,
2471 .fabric_login = qla24xx_login_fabric,
2472 .fabric_logout = qla24xx_fabric_logout,
2473 .calc_req_entries = NULL,
2474 .build_iocbs = NULL,
2475 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2476 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2477 .read_nvram = NULL,
2478 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002479 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002480 .beacon_on = qla82xx_beacon_on,
2481 .beacon_off = qla82xx_beacon_off,
2482 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002483 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002484 .write_optrom = qla8044_write_optrom_data,
2485 .get_flash_version = qla82xx_get_flash_version,
2486 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002487 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002488 .abort_isp = qla8044_abort_isp,
2489 .iospace_config = qla82xx_iospace_config,
2490 .initialize_adapter = qla2x00_initialize_adapter,
2491};
2492
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002493static struct isp_operations qla83xx_isp_ops = {
2494 .pci_config = qla25xx_pci_config,
2495 .reset_chip = qla24xx_reset_chip,
2496 .chip_diag = qla24xx_chip_diag,
2497 .config_rings = qla24xx_config_rings,
2498 .reset_adapter = qla24xx_reset_adapter,
2499 .nvram_config = qla81xx_nvram_config,
2500 .update_fw_options = qla81xx_update_fw_options,
2501 .load_risc = qla81xx_load_risc,
2502 .pci_info_str = qla24xx_pci_info_str,
2503 .fw_version_str = qla24xx_fw_version_str,
2504 .intr_handler = qla24xx_intr_handler,
2505 .enable_intrs = qla24xx_enable_intrs,
2506 .disable_intrs = qla24xx_disable_intrs,
2507 .abort_command = qla24xx_abort_command,
2508 .target_reset = qla24xx_abort_target,
2509 .lun_reset = qla24xx_lun_reset,
2510 .fabric_login = qla24xx_login_fabric,
2511 .fabric_logout = qla24xx_fabric_logout,
2512 .calc_req_entries = NULL,
2513 .build_iocbs = NULL,
2514 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2515 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2516 .read_nvram = NULL,
2517 .write_nvram = NULL,
2518 .fw_dump = qla83xx_fw_dump,
2519 .beacon_on = qla24xx_beacon_on,
2520 .beacon_off = qla24xx_beacon_off,
2521 .beacon_blink = qla83xx_beacon_blink,
2522 .read_optrom = qla25xx_read_optrom_data,
2523 .write_optrom = qla24xx_write_optrom_data,
2524 .get_flash_version = qla24xx_get_flash_version,
2525 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002526 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002527 .abort_isp = qla2x00_abort_isp,
2528 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002529 .initialize_adapter = qla2x00_initialize_adapter,
2530};
2531
2532static struct isp_operations qlafx00_isp_ops = {
2533 .pci_config = qlafx00_pci_config,
2534 .reset_chip = qlafx00_soft_reset,
2535 .chip_diag = qlafx00_chip_diag,
2536 .config_rings = qlafx00_config_rings,
2537 .reset_adapter = qlafx00_soft_reset,
2538 .nvram_config = NULL,
2539 .update_fw_options = NULL,
2540 .load_risc = NULL,
2541 .pci_info_str = qlafx00_pci_info_str,
2542 .fw_version_str = qlafx00_fw_version_str,
2543 .intr_handler = qlafx00_intr_handler,
2544 .enable_intrs = qlafx00_enable_intrs,
2545 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002546 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002547 .target_reset = qlafx00_abort_target,
2548 .lun_reset = qlafx00_lun_reset,
2549 .fabric_login = NULL,
2550 .fabric_logout = NULL,
2551 .calc_req_entries = NULL,
2552 .build_iocbs = NULL,
2553 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2554 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2555 .read_nvram = qla24xx_read_nvram_data,
2556 .write_nvram = qla24xx_write_nvram_data,
2557 .fw_dump = NULL,
2558 .beacon_on = qla24xx_beacon_on,
2559 .beacon_off = qla24xx_beacon_off,
2560 .beacon_blink = NULL,
2561 .read_optrom = qla24xx_read_optrom_data,
2562 .write_optrom = qla24xx_write_optrom_data,
2563 .get_flash_version = qla24xx_get_flash_version,
2564 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002565 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002566 .abort_isp = qlafx00_abort_isp,
2567 .iospace_config = qlafx00_iospace_config,
2568 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002569};
2570
Chad Dupuisf73cb692014-02-26 04:15:06 -05002571static struct isp_operations qla27xx_isp_ops = {
2572 .pci_config = qla25xx_pci_config,
2573 .reset_chip = qla24xx_reset_chip,
2574 .chip_diag = qla24xx_chip_diag,
2575 .config_rings = qla24xx_config_rings,
2576 .reset_adapter = qla24xx_reset_adapter,
2577 .nvram_config = qla81xx_nvram_config,
2578 .update_fw_options = qla81xx_update_fw_options,
2579 .load_risc = qla81xx_load_risc,
2580 .pci_info_str = qla24xx_pci_info_str,
2581 .fw_version_str = qla24xx_fw_version_str,
2582 .intr_handler = qla24xx_intr_handler,
2583 .enable_intrs = qla24xx_enable_intrs,
2584 .disable_intrs = qla24xx_disable_intrs,
2585 .abort_command = qla24xx_abort_command,
2586 .target_reset = qla24xx_abort_target,
2587 .lun_reset = qla24xx_lun_reset,
2588 .fabric_login = qla24xx_login_fabric,
2589 .fabric_logout = qla24xx_fabric_logout,
2590 .calc_req_entries = NULL,
2591 .build_iocbs = NULL,
2592 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2593 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2594 .read_nvram = NULL,
2595 .write_nvram = NULL,
2596 .fw_dump = qla27xx_fwdump,
2597 .beacon_on = qla24xx_beacon_on,
2598 .beacon_off = qla24xx_beacon_off,
2599 .beacon_blink = qla83xx_beacon_blink,
2600 .read_optrom = qla25xx_read_optrom_data,
2601 .write_optrom = qla24xx_write_optrom_data,
2602 .get_flash_version = qla24xx_get_flash_version,
2603 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002604 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002605 .abort_isp = qla2x00_abort_isp,
2606 .iospace_config = qla83xx_iospace_config,
2607 .initialize_adapter = qla2x00_initialize_adapter,
2608};
2609
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002610static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002612{
2613 ha->device_type = DT_EXTENDED_IDS;
2614 switch (ha->pdev->device) {
2615 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002616 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002617 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002618 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002619 break;
2620 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002621 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002622 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002623 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002624 break;
2625 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002626 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002627 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002628 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002629 break;
2630 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002631 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002632 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002633 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002634 break;
2635 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002636 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002637 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002638 if (ha->pdev->subsystem_vendor == 0x1028 &&
2639 ha->pdev->subsystem_device == 0x0170)
2640 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002641 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002642 break;
2643 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002644 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002645 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002646 break;
2647 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002648 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002649 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002650 break;
2651 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002652 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002653 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002654 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002655 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002656 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002657 break;
2658 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002659 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002660 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002661 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002662 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002663 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002664 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002665 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002666 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002667 ha->device_type |= DT_ZIO_SUPPORTED;
2668 ha->device_type |= DT_FWI2;
2669 ha->device_type |= DT_IIDMA;
2670 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2671 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002672 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002673 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002674 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002675 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002676 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002677 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002678 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002679 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002680 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002681 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002682 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002683 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002684 ha->device_type |= DT_ZIO_SUPPORTED;
2685 ha->device_type |= DT_FWI2;
2686 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002687 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2688 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002689 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002690 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002691 ha->device_type |= DT_ZIO_SUPPORTED;
2692 ha->device_type |= DT_FWI2;
2693 ha->device_type |= DT_IIDMA;
2694 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2695 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002696 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002697 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002698 ha->device_type |= DT_ZIO_SUPPORTED;
2699 ha->device_type |= DT_FWI2;
2700 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2701 /* Initialize 82XX ISP flags */
2702 qla82xx_init_flags(ha);
2703 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002704 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002705 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002706 ha->device_type |= DT_ZIO_SUPPORTED;
2707 ha->device_type |= DT_FWI2;
2708 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2709 /* Initialize 82XX ISP flags */
2710 qla82xx_init_flags(ha);
2711 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002712 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002713 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002714 ha->device_type |= DT_ZIO_SUPPORTED;
2715 ha->device_type |= DT_FWI2;
2716 ha->device_type |= DT_IIDMA;
2717 ha->device_type |= DT_T10_PI;
2718 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2719 break;
2720 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002721 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002722 ha->device_type |= DT_ZIO_SUPPORTED;
2723 ha->device_type |= DT_FWI2;
2724 ha->device_type |= DT_IIDMA;
2725 ha->device_type |= DT_T10_PI;
2726 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2727 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002728 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002729 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002730 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002731 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002732 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002733 ha->device_type |= DT_ZIO_SUPPORTED;
2734 ha->device_type |= DT_FWI2;
2735 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002736 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002737 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2738 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002739 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002740 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002741 ha->device_type |= DT_ZIO_SUPPORTED;
2742 ha->device_type |= DT_FWI2;
2743 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002744 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002745 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2746 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002747 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002748 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002749 ha->device_type |= DT_ZIO_SUPPORTED;
2750 ha->device_type |= DT_FWI2;
2751 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002752 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002753 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2754 break;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002755 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2756 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2757 ha->isp_type |= DT_ISP2081;
2758 ha->device_type |= DT_ZIO_SUPPORTED;
2759 ha->device_type |= DT_FWI2;
2760 ha->device_type |= DT_IIDMA;
2761 ha->device_type |= DT_T10_PI;
2762 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2763 break;
2764 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2765 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2766 ha->isp_type |= DT_ISP2281;
2767 ha->device_type |= DT_ZIO_SUPPORTED;
2768 ha->device_type |= DT_FWI2;
2769 ha->device_type |= DT_IIDMA;
2770 ha->device_type |= DT_T10_PI;
2771 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2772 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002773 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002774
Giridhar Malavalia9083012010-04-12 17:59:55 -07002775 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002776 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002777 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002778 /* Get adapter physical port no from interrupt pin register. */
2779 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002780 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2781 IS_QLA27XX(ha) || IS_QLA28XX(ha))
Chad Dupuisf73cb692014-02-26 04:15:06 -05002782 ha->port_no--;
2783 else
2784 ha->port_no = !(ha->port_no & 1);
2785 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002786
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002787 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002788 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002789 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002790}
2791
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002792static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002793qla2xxx_scan_start(struct Scsi_Host *shost)
2794{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002796
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002797 if (vha->hw->flags.running_gold_fw)
2798 return;
2799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002800 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2801 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2802 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2803 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002804}
2805
2806static int
2807qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2808{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002809 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002810
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002811 if (test_bit(UNLOADING, &vha->dpc_flags))
2812 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002814 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002816 return 1;
2817
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002818 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002819}
2820
Quinn Tranec7193e2017-03-15 09:48:55 -07002821static void qla2x00_iocb_work_fn(struct work_struct *work)
2822{
2823 struct scsi_qla_host *vha = container_of(work,
2824 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002825 struct qla_hw_data *ha = vha->hw;
2826 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran0aca7782018-09-04 14:19:16 -07002827 int i = 2;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002828 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002829
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002830 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2831 return;
2832
2833 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002834 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002835 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002836 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002837
2838 spin_lock_irqsave(&vha->work_lock, flags);
2839 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2840 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002841}
2842
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843/*
2844 * PCI driver interface
2845 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002846static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002847qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002849 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851 scsi_qla_host_t *base_vha = NULL;
2852 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002853 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002854 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002855 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002856 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002858 struct req_que *req = NULL;
2859 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002860 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002861
Andrew Vasquez285d0322007-10-19 15:59:17 -07002862 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002863 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002864 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2865 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002866 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002867 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2868 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002869 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002870 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002871 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2872 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002873 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002874 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002875 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002876 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002877 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002878 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2879 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2880 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2881 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2882 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002883 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002884 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002885 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2886 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002887 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002888 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2889 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002890
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002891 if (mem_only) {
2892 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002893 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002894 } else {
2895 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002896 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
Jesse Barnes09276782008-10-18 17:33:19 -07002899 /* This may fail but that's ok */
2900 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002901
Giridhar Malavali5da05a22019-04-02 14:24:24 -07002902 /* Turn off T10-DIF when FC-NVMe is enabled */
2903 if (ql2xnvmeenable)
2904 ql2xenabledif = 0;
2905
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002906 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2907 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002908 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2909 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002910 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002912 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2913 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002914 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002915 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2916 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002917 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002918 spin_lock_init(&ha->tgt.atio_lock);
2919
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002920 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
2922 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002923 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002924 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002925 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002926 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002927 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002928 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002930 /* Set ISP-type information. */
2931 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002932
2933 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002934 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002935 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002936 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002937
Chad Dupuiscba1e472011-11-18 09:03:21 -08002938 ha->prev_topology = 0;
2939 ha->init_cb_size = sizeof(init_cb_t);
2940 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2941 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002942 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Quinn Tranb2000802018-08-02 13:16:52 -07002943 atomic_set(&ha->num_pend_mbx_stage1, 0);
2944 atomic_set(&ha->num_pend_mbx_stage2, 0);
2945 atomic_set(&ha->num_pend_mbx_stage3, 0);
Quinn Tran8b4673b2018-09-04 14:19:14 -07002946 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2947 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002948
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002949 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002951 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 req_length = REQUEST_ENTRY_CNT_2100;
2954 rsp_length = RESPONSE_ENTRY_CNT_2100;
2955 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002956 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002957 ha->flash_conf_off = ~0;
2958 ha->flash_data_off = ~0;
2959 ha->nvram_conf_off = ~0;
2960 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002961 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002963 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002964 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 req_length = REQUEST_ENTRY_CNT_2200;
2966 rsp_length = RESPONSE_ENTRY_CNT_2100;
2967 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002968 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002969 ha->flash_conf_off = ~0;
2970 ha->flash_data_off = ~0;
2971 ha->nvram_conf_off = ~0;
2972 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002973 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002974 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002975 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 req_length = REQUEST_ENTRY_CNT_2200;
2978 rsp_length = RESPONSE_ENTRY_CNT_2300;
2979 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002980 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002981 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2982 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002983 ha->flash_conf_off = ~0;
2984 ha->flash_data_off = ~0;
2985 ha->nvram_conf_off = ~0;
2986 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002987 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002988 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002989 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002990 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991 req_length = REQUEST_ENTRY_CNT_24XX;
2992 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002993 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002994 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002995 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002996 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002997 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002998 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002999 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003000 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3001 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3002 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3003 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003004 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08003005 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003006 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 req_length = REQUEST_ENTRY_CNT_24XX;
3008 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003009 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003010 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003011 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003012 ha->gid_list_info_size = 8;
3013 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003014 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003015 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003016 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3017 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3018 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3019 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3020 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08003021 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003022 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3023 req_length = REQUEST_ENTRY_CNT_24XX;
3024 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05003025 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003026 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3027 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3028 ha->gid_list_info_size = 8;
3029 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07003030 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003031 ha->isp_ops = &qla81xx_isp_ops;
3032 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3033 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3034 ha->nvram_conf_off = ~0;
3035 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003036 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08003037 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003038 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3039 req_length = REQUEST_ENTRY_CNT_82XX;
3040 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3041 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3042 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3043 ha->gid_list_info_size = 8;
3044 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08003045 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003046 ha->isp_ops = &qla82xx_isp_ops;
3047 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3048 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3049 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3050 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003051 } else if (IS_QLA8044(ha)) {
3052 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3053 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3054 req_length = REQUEST_ENTRY_CNT_82XX;
3055 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3056 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3057 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3058 ha->gid_list_info_size = 8;
3059 ha->optrom_size = OPTROM_SIZE_83XX;
3060 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3061 ha->isp_ops = &qla8044_isp_ops;
3062 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3063 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3064 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3065 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003066 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003067 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08003068 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003069 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04003070 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05003071 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05003072 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003073 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3074 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3075 ha->gid_list_info_size = 8;
3076 ha->optrom_size = OPTROM_SIZE_83XX;
3077 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3078 ha->isp_ops = &qla83xx_isp_ops;
3079 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3080 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3081 ha->nvram_conf_off = ~0;
3082 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003083 } else if (IS_QLAFX00(ha)) {
3084 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
3085 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3086 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3087 req_length = REQUEST_ENTRY_CNT_FX00;
3088 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003089 ha->isp_ops = &qlafx00_isp_ops;
3090 ha->port_down_retry_count = 30; /* default value */
3091 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3092 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04003093 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003094 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04003095 ha->mr.host_info_resend = false;
3096 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003097 } else if (IS_QLA27XX(ha)) {
3098 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3099 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3100 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05003101 req_length = REQUEST_ENTRY_CNT_83XX;
3102 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04003103 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003104 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3105 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3106 ha->gid_list_info_size = 8;
3107 ha->optrom_size = OPTROM_SIZE_83XX;
3108 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3109 ha->isp_ops = &qla27xx_isp_ops;
3110 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3111 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3112 ha->nvram_conf_off = ~0;
3113 ha->nvram_data_off = ~0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003114 } else if (IS_QLA28XX(ha)) {
3115 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3116 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3117 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3118 req_length = REQUEST_ENTRY_CNT_24XX;
3119 rsp_length = RESPONSE_ENTRY_CNT_2300;
3120 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3121 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3122 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3123 ha->gid_list_info_size = 8;
3124 ha->optrom_size = OPTROM_SIZE_28XX;
3125 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3126 ha->isp_ops = &qla27xx_isp_ops;
3127 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3128 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3129 ha->nvram_conf_off = ~0;
3130 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003132
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003133 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3134 "mbx_count=%d, req_length=%d, "
3135 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08003136 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3137 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003138 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3139 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08003140 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003141 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3142 "isp_ops=%p, flash_conf_off=%d, "
3143 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3144 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3145 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08003146
3147 /* Configure PCI I/O space */
3148 ret = ha->isp_ops->iospace_config(ha);
3149 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003150 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003151
3152 ql_log_pci(ql_log_info, pdev, 0x001d,
3153 "Found an ISP%04X irq %d iobase 0x%p.\n",
3154 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003155 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003156 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003157 init_completion(&ha->mbx_cmd_comp);
3158 complete(&ha->mbx_cmd_comp);
3159 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003160 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003161 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003163 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
Andrew Vasquez53303c42009-01-22 09:45:37 -08003165 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003166 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3167 "64 Bit addressing is %s.\n",
3168 ha->flags.enable_64bit_addressing ? "enable" :
3169 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003170 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec32014-01-21 10:00:10 +03003171 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003172 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3173 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003175 goto probe_hw_failed;
3176 }
3177
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003178 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003179 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003180 req->max_q_depth = ql2xmaxqdepth;
3181
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182
3183 base_vha = qla2x00_create_host(sht, ha);
3184 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003185 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 }
3188
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003189 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003190 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003193 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003194 if (IS_QLA2XXX_MIDTYPE(ha))
Quinn Tranf6602f32018-08-02 13:16:53 -07003195 base_vha->mgmt_svr_loop_id =
3196 qla2x00_reserve_mgmt_server_loop_id(base_vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003197 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003198 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3199 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003200
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003201 /* Setup fcport template structure. */
3202 ha->mr.fcport.vha = base_vha;
3203 ha->mr.fcport.port_type = FCT_UNKNOWN;
3204 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3205 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3206 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3207 ha->mr.fcport.scan_state = 1;
3208
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003209 /* Set the SG table size based on ISP type */
3210 if (!IS_FWI2_CAPABLE(ha)) {
3211 if (IS_QLA2100(ha))
3212 host->sg_tablesize = 32;
3213 } else {
3214 if (!IS_QLA82XX(ha))
3215 host->sg_tablesize = QLA_SG_ALL;
3216 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003217 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003218 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003219 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003220 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003221 host->max_cmd_len = 32;
3222 else
3223 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003224 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003225 /* Older HBAs support only 16-bit LUNs */
3226 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3227 ql2xmaxlun > 0xffff)
3228 host->max_lun = 0xffff;
3229 else
3230 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003231 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003232 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003233
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003234 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3235 "max_id=%d this_id=%d "
3236 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003237 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003238 host->this_id, host->cmd_per_lun, host->unique_id,
3239 host->max_cmd_len, host->max_channel, host->max_lun,
3240 host->transportt, sht->vendor_id);
3241
Himanshu Madhani1010f212017-10-16 11:26:05 -07003242 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3243
Michael Hernandezd7459522016-12-12 14:40:07 -08003244 /* Set up the irqs */
3245 ret = qla2x00_request_irqs(ha, rsp);
3246 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003247 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003248
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003249 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003250 ret = qla2x00_alloc_queues(ha, req, rsp);
3251 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003252 ql_log(ql_log_fatal, base_vha, 0x003d,
3253 "Failed to allocate memory for queue pointers..."
3254 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003255 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003256 }
3257
Jens Axboef664a3c2018-11-01 16:36:27 -06003258 if (ha->mqenable) {
Michael Hernandez56012362016-12-12 14:40:08 -08003259 /* number of hardware queues supported by blk/scsi-mq*/
3260 host->nr_hw_queues = ha->max_qpairs;
3261
3262 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3263 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003264 } else {
3265 if (ql2xnvmeenable) {
3266 host->nr_hw_queues = ha->max_qpairs;
3267 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3268 "FC-NVMe support is enabled, HW queues=%d\n",
3269 host->nr_hw_queues);
3270 } else {
3271 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3272 "blk/scsi-mq disabled.\n");
3273 }
3274 }
Michael Hernandez56012362016-12-12 14:40:08 -08003275
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003276 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003277
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003278 pci_save_state(pdev);
3279
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003280 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003281 rsp->req = req;
3282 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003283
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003284 if (IS_QLAFX00(ha)) {
3285 ha->rsp_q_map[0] = rsp;
3286 ha->req_q_map[0] = req;
3287 set_bit(0, ha->req_qid_map);
3288 set_bit(0, ha->rsp_qid_map);
3289 }
3290
Andrew Vasquez080299902009-03-24 09:07:55 -07003291 /* FWI2-capable only. */
3292 req->req_q_in = &ha->iobase->isp24.req_q_in;
3293 req->req_q_out = &ha->iobase->isp24.req_q_out;
3294 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3295 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003296 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3297 IS_QLA28XX(ha)) {
Andrew Vasquez080299902009-03-24 09:07:55 -07003298 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3299 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3300 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3301 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003302 }
3303
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003304 if (IS_QLAFX00(ha)) {
3305 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3306 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3307 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3308 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3309 }
3310
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003311 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003312 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3313 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3314 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3315 }
3316
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003317 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3318 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3319 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3320 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3321 "req->req_q_in=%p req->req_q_out=%p "
3322 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3323 req->req_q_in, req->req_q_out,
3324 rsp->rsp_q_in, rsp->rsp_q_out);
3325 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3326 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3327 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3328 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3329 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3330 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003331
himanshu.madhani@cavium.comd48cc672018-07-02 13:01:59 -07003332 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3333
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003334 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003335 ql_log(ql_log_fatal, base_vha, 0x00d6,
3336 "Failed to initialize adapter - Adapter flags %x.\n",
3337 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338
Giridhar Malavalia9083012010-04-12 17:59:55 -07003339 if (IS_QLA82XX(ha)) {
3340 qla82xx_idc_lock(ha);
3341 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003342 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003343 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003344 ql_log(ql_log_fatal, base_vha, 0x00d7,
3345 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003346 } else if (IS_QLA8044(ha)) {
3347 qla8044_idc_lock(ha);
3348 qla8044_wr_direct(base_vha,
3349 QLA8044_CRB_DEV_STATE_INDEX,
3350 QLA8XXX_DEV_FAILED);
3351 qla8044_idc_unlock(ha);
3352 ql_log(ql_log_fatal, base_vha, 0x0150,
3353 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003354 }
3355
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003356 ret = -ENODEV;
3357 goto probe_failed;
3358 }
3359
Chad Dupuis3b1bef642014-02-26 04:15:04 -05003360 if (IS_QLAFX00(ha))
3361 host->can_queue = QLAFX00_MAX_CANQUEUE;
3362 else
3363 host->can_queue = req->num_outstanding_cmds - 10;
3364
3365 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3366 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3367 host->can_queue, base_vha->req,
3368 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3369
Quinn Trane326d222017-06-13 20:47:18 -07003370 if (ha->mqenable) {
Quinn Trane326d222017-06-13 20:47:18 -07003371 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003372
Jens Axboef664a3c2018-11-01 16:36:27 -06003373 if (QLA_TGT_MODE_ENABLED())
Quinn Trane326d222017-06-13 20:47:18 -07003374 startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003375
Jens Axboef664a3c2018-11-01 16:36:27 -06003376 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
Quinn Trane326d222017-06-13 20:47:18 -07003377 startit = true;
Quinn Trane326d222017-06-13 20:47:18 -07003378
Jens Axboef664a3c2018-11-01 16:36:27 -06003379 /* Create start of day qpairs for Block MQ */
3380 for (i = 0; i < ha->max_qpairs; i++)
3381 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003382 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003383
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003384 if (ha->flags.running_gold_fw)
3385 goto skip_dpc;
3386
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 /*
3388 * Startup the kernel thread for this host adapter
3389 */
3390 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003391 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003393 ql_log(ql_log_fatal, base_vha, 0x00ed,
3394 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003395 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003396 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 goto probe_failed;
3398 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003399 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3400 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003401
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003402 /*
3403 * If we're not coming up in initiator mode, we might sit for
3404 * a while without waking up the dpc thread, which leads to a
3405 * stuck process warning. So just kick the dpc once here and
3406 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3407 */
3408 qla2xxx_wake_dpc(base_vha);
3409
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003410 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3411
Saurav Kashyap81178772012-08-22 14:21:04 -04003412 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3413 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3414 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3415 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3416
3417 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3418 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3419 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3420 INIT_WORK(&ha->idc_state_handler,
3421 qla83xx_idc_state_handler_work);
3422 INIT_WORK(&ha->nic_core_unrecoverable,
3423 qla83xx_nic_core_unrecoverable_work);
3424 }
3425
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003426skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003427 list_add_tail(&base_vha->list, &ha->vp_list);
3428 base_vha->host->irq = ha->pdev->irq;
3429
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003431 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003432 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3433 "Started qla2x00_timer with "
3434 "interval=%d.\n", WATCH_INTERVAL);
3435 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3436 "Detected hba at address=%p.\n",
3437 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438
Arun Easie02587d2011-08-16 11:29:23 -07003439 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003440 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003441 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003442 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003443 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3444 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003445 if (ql2xenabledif == 1)
3446 prot = SHOST_DIX_TYPE0_PROTECTION;
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003447 if (ql2xprotmask)
3448 scsi_host_set_prot(host, ql2xprotmask);
3449 else
3450 scsi_host_set_prot(host,
3451 prot | SHOST_DIF_TYPE1_PROTECTION
3452 | SHOST_DIF_TYPE2_PROTECTION
3453 | SHOST_DIF_TYPE3_PROTECTION
3454 | SHOST_DIX_TYPE1_PROTECTION
3455 | SHOST_DIX_TYPE2_PROTECTION
3456 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003457
3458 guard = SHOST_DIX_GUARD_CRC;
3459
3460 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3461 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3462 guard |= SHOST_DIX_GUARD_IP;
3463
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003464 if (ql2xprotguard)
3465 scsi_host_set_guard(host, ql2xprotguard);
3466 else
3467 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003468 } else
3469 base_vha->flags.difdix_supported = 0;
3470 }
3471
Giridhar Malavalia9083012010-04-12 17:59:55 -07003472 ha->isp_ops->enable_intrs(ha);
3473
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003474 if (IS_QLAFX00(ha)) {
3475 ret = qlafx00_fx_disc(base_vha,
3476 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3477 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3478 QLA_SG_ALL : 128;
3479 }
3480
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003481 ret = scsi_add_host(host, &pdev->dev);
3482 if (ret)
3483 goto probe_failed;
3484
Michael Reed14864002009-12-02 09:11:16 -06003485 base_vha->flags.init_done = 1;
3486 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003487 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003488
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003489 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3490 "Init done and hba is online.\n");
3491
Quinn Tran726b8542017-01-19 22:28:00 -08003492 if (qla_ini_mode_enabled(base_vha) ||
3493 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003494 scsi_scan_host(host);
3495 else
3496 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3497 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003499 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003500
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003501 if (IS_QLAFX00(ha)) {
3502 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003503 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3504
3505 /* Register system information */
3506 ret = qlafx00_fx_disc(base_vha,
3507 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3508 }
3509
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003510 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003511
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003512 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003513
Armen Baloyan03eb9122013-10-30 03:38:22 -04003514 ql_log(ql_log_info, base_vha, 0x00fb,
3515 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003516 ql_log(ql_log_info, base_vha, 0x00fc,
3517 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3518 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3519 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3520 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003521 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003523 qlt_add_target(ha, base_vha);
3524
Joe Lawrence6b383972014-08-26 17:12:29 -04003525 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003526
3527 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3528 return -ENODEV;
3529
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003530 if (ha->flags.detected_lr_sfp) {
3531 ql_log(ql_log_info, base_vha, 0xffff,
3532 "Reset chip to pick up LR SFP setting\n");
3533 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3534 qla2xxx_wake_dpc(base_vha);
3535 }
3536
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 return 0;
3538
3539probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003540 if (base_vha->timer_active)
3541 qla2x00_stop_timer(base_vha);
3542 base_vha->flags.online = 0;
3543 if (ha->dpc_thread) {
3544 struct task_struct *t = ha->dpc_thread;
3545
3546 ha->dpc_thread = NULL;
3547 kthread_stop(t);
3548 }
3549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003551 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003552 /*
3553 * Need to NULL out local req/rsp after
3554 * qla2x00_free_device => qla2x00_free_queues frees
3555 * what these are pointing to. Or else we'll
3556 * fall over below in qla2x00_free_req/rsp_que.
3557 */
3558 req = NULL;
3559 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003561probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003562 qla2x00_mem_free(ha);
3563 qla2x00_free_req_que(ha, req);
3564 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003565 qla2x00_clear_drv_active(ha);
3566
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003567iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003568 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003569 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003570 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003571 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003572 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003573 } else {
3574 if (ha->iobase)
3575 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003576 if (ha->cregbase)
3577 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003578 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 pci_release_selected_regions(ha->pdev, ha->bars);
3580 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003582disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003583 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003584 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586
Adrian Bunk4c993f72008-01-14 00:55:16 -08003587static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003588qla2x00_shutdown(struct pci_dev *pdev)
3589{
3590 scsi_qla_host_t *vha;
3591 struct qla_hw_data *ha;
3592
3593 vha = pci_get_drvdata(pdev);
3594 ha = vha->hw;
3595
Sawan Chandakefdb5762017-08-23 15:05:00 -07003596 ql_log(ql_log_info, vha, 0xfffa,
3597 "Adapter shutdown\n");
3598
3599 /*
3600 * Prevent future board_disable and wait
3601 * until any pending board_disable has completed.
3602 */
3603 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3604 cancel_work_sync(&ha->board_disable);
3605
3606 if (!atomic_read(&pdev->enable_cnt))
3607 return;
3608
Armen Baloyan42479342013-08-27 01:37:37 -04003609 /* Notify ISPFX00 firmware */
3610 if (IS_QLAFX00(ha))
3611 qlafx00_driver_shutdown(vha, 20);
3612
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003613 /* Turn-off FCE trace */
3614 if (ha->flags.fce_enabled) {
3615 qla2x00_disable_fce_trace(vha, NULL, NULL);
3616 ha->flags.fce_enabled = 0;
3617 }
3618
3619 /* Turn-off EFT trace */
3620 if (ha->eft)
3621 qla2x00_disable_eft_trace(vha);
3622
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003623 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3624 IS_QLA28XX(ha)) {
Quinn Tran3407fc32017-12-28 12:33:11 -08003625 if (ha->flags.fw_started)
3626 qla2x00_abort_isp_cleanup(vha);
3627 } else {
3628 /* Stop currently executing firmware. */
3629 qla2x00_try_to_stop_firmware(vha);
3630 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003631
3632 /* Turn adapter off line */
3633 vha->flags.online = 0;
3634
3635 /* turn-off interrupts on the card */
3636 if (ha->interrupts_on) {
3637 vha->flags.init_done = 0;
3638 ha->isp_ops->disable_intrs(ha);
3639 }
3640
3641 qla2x00_free_irqs(vha);
3642
3643 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003644
Chad Dupuis61d41f62014-09-25 05:17:02 -04003645 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003646 ql_log(ql_log_info, vha, 0xfffe,
3647 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003648}
3649
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003650/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003651static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003652qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003654 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003655 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656
Arun Easi43ebf162011-05-10 11:18:16 -07003657 mutex_lock(&ha->vport_lock);
3658 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003659 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003660
Arun Easi43ebf162011-05-10 11:18:16 -07003661 BUG_ON(base_vha->list.next == &ha->vp_list);
3662 /* This assumes first entry in ha->vp_list is always base vha */
3663 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003664 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003665
Arun Easi43ebf162011-05-10 11:18:16 -07003666 spin_unlock_irqrestore(&ha->vport_slock, flags);
3667 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003668
Himanshu Madhani5e6803b2018-12-10 12:36:23 -08003669 qla_nvme_delete(vha);
3670
Arun Easi43ebf162011-05-10 11:18:16 -07003671 fc_vport_terminate(vha->fc_vport);
3672 scsi_host_put(vha->host);
3673
3674 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003675 }
Arun Easi43ebf162011-05-10 11:18:16 -07003676 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003677}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003678
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003679/* Stops all deferred work threads */
3680static void
3681qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3682{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003683 /* Cancel all work and destroy DPC workqueues */
3684 if (ha->dpc_lp_wq) {
3685 cancel_work_sync(&ha->idc_aen);
3686 destroy_workqueue(ha->dpc_lp_wq);
3687 ha->dpc_lp_wq = NULL;
3688 }
3689
3690 if (ha->dpc_hp_wq) {
3691 cancel_work_sync(&ha->nic_core_reset);
3692 cancel_work_sync(&ha->idc_state_handler);
3693 cancel_work_sync(&ha->nic_core_unrecoverable);
3694 destroy_workqueue(ha->dpc_hp_wq);
3695 ha->dpc_hp_wq = NULL;
3696 }
3697
Andrew Vasquezb9978762009-03-24 09:08:05 -07003698 /* Kill the kernel thread for this host */
3699 if (ha->dpc_thread) {
3700 struct task_struct *t = ha->dpc_thread;
3701
3702 /*
3703 * qla2xxx_wake_dpc checks for ->dpc_thread
3704 * so we need to zero it out.
3705 */
3706 ha->dpc_thread = NULL;
3707 kthread_stop(t);
3708 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003709}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003710
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003711static void
3712qla2x00_unmap_iobases(struct qla_hw_data *ha)
3713{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003714 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003715
Chad Dupuisf73cb692014-02-26 04:15:06 -05003716 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003717 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003718 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003719 } else {
3720 if (ha->iobase)
3721 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003722
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003723 if (ha->cregbase)
3724 iounmap(ha->cregbase);
3725
Giridhar Malavalia9083012010-04-12 17:59:55 -07003726 if (ha->mqiobase)
3727 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003728
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003729 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) &&
3730 ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003731 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003732 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003733}
3734
3735static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003736qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003737{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003738 if (IS_QLA8044(ha)) {
3739 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003740 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003741 qla8044_idc_unlock(ha);
3742 } else if (IS_QLA82XX(ha)) {
3743 qla82xx_idc_lock(ha);
3744 qla82xx_clear_drv_active(ha);
3745 qla82xx_idc_unlock(ha);
3746 }
3747}
3748
3749static void
3750qla2x00_remove_one(struct pci_dev *pdev)
3751{
3752 scsi_qla_host_t *base_vha;
3753 struct qla_hw_data *ha;
3754
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003755 base_vha = pci_get_drvdata(pdev);
3756 ha = base_vha->hw;
Quinn Tran45235022018-07-18 14:29:53 -07003757 ql_log(ql_log_info, base_vha, 0xb079,
3758 "Removing driver\n");
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003759
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003760 /* Indicate device removal to prevent future board_disable and wait
3761 * until any pending board_disable has completed. */
3762 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3763 cancel_work_sync(&ha->board_disable);
3764
3765 /*
3766 * If the PCI device is disabled then there was a PCI-disconnect and
3767 * qla2x00_disable_board_on_pci_error has taken care of most of the
3768 * resources.
3769 */
3770 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003771 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3772 base_vha->gnl.l, base_vha->gnl.ldma);
3773
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003774 scsi_host_put(base_vha->host);
3775 kfree(ha);
3776 pci_set_drvdata(pdev, NULL);
3777 return;
3778 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003779 qla2x00_wait_for_hba_ready(base_vha);
3780
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003781 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3782 IS_QLA28XX(ha)) {
Quinn Tran45235022018-07-18 14:29:53 -07003783 if (ha->flags.fw_started)
3784 qla2x00_abort_isp_cleanup(base_vha);
3785 } else if (!IS_QLAFX00(ha)) {
3786 if (IS_QLA8031(ha)) {
3787 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3788 "Clearing fcoe driver presence.\n");
3789 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3790 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3791 "Error while clearing DRV-Presence.\n");
3792 }
3793
3794 qla2x00_try_to_stop_firmware(base_vha);
3795 }
3796
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003797 qla2x00_wait_for_sess_deletion(base_vha);
3798
Quinn Tran726b8542017-01-19 22:28:00 -08003799 /*
3800 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003801 * where it was set first.
3802 */
3803 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3804 return;
3805
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003806 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003807
3808 qla_nvme_delete(base_vha);
3809
Quinn Tran726b8542017-01-19 22:28:00 -08003810 dma_free_coherent(&ha->pdev->dev,
3811 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003812
Quinn Trana4239942017-12-28 12:33:26 -08003813 vfree(base_vha->scan.l);
3814
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003815 if (IS_QLAFX00(ha))
3816 qlafx00_driver_shutdown(base_vha, 20);
3817
3818 qla2x00_delete_all_vps(ha, base_vha);
3819
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003820 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3821
3822 qla2x00_dfs_remove(base_vha);
3823
3824 qla84xx_put_chip(base_vha);
3825
3826 /* Disable timer */
3827 if (base_vha->timer_active)
3828 qla2x00_stop_timer(base_vha);
3829
3830 base_vha->flags.online = 0;
3831
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003832 /* free DMA memory */
3833 if (ha->exlogin_buf)
3834 qla2x00_free_exlogin_buffer(ha);
3835
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003836 /* free DMA memory */
3837 if (ha->exchoffld_buf)
3838 qla2x00_free_exchoffld_buffer(ha);
3839
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003840 qla2x00_destroy_deferred_work(ha);
3841
3842 qlt_remove_target(ha, base_vha);
3843
3844 qla2x00_free_sysfs_attr(base_vha, true);
3845
3846 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003847 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003848
3849 scsi_remove_host(base_vha->host);
3850
3851 qla2x00_free_device(base_vha);
3852
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003853 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003854
Arun Easid2749ff2014-09-25 05:16:51 -04003855 scsi_host_put(base_vha->host);
3856
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003857 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003859 pci_release_selected_regions(ha->pdev, ha->bars);
3860 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003862 pci_disable_pcie_error_reporting(pdev);
3863
Bernhard Walle665db932007-03-28 00:49:49 +02003864 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866
3867static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003868qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003870 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871
Andrew Vasquez85880802009-12-15 21:29:46 -08003872 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3873
3874 /* Disable timer */
3875 if (vha->timer_active)
3876 qla2x00_stop_timer(vha);
3877
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003878 qla25xx_delete_queues(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003879 vha->flags.online = 0;
3880
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003881 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003882 if (ha->interrupts_on) {
3883 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003884 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003885 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003886
Quinn Tran093df732016-12-12 14:40:09 -08003887 qla2x00_free_fcports(vha);
3888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003889 qla2x00_free_irqs(vha);
3890
Quinn Tran093df732016-12-12 14:40:09 -08003891 /* Flush the work queue and remove it */
3892 if (ha->wq) {
3893 flush_workqueue(ha->wq);
3894 destroy_workqueue(ha->wq);
3895 ha->wq = NULL;
3896 }
3897
Chad Dupuis88670482010-07-23 15:28:30 +05003898
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003899 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003900
Giridhar Malavali08de2842011-08-16 11:31:44 -07003901 qla82xx_md_free(vha);
3902
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003903 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
3905
Chad Dupuis88670482010-07-23 15:28:30 +05003906void qla2x00_free_fcports(struct scsi_qla_host *vha)
3907{
3908 fc_port_t *fcport, *tfcport;
3909
3910 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3911 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003912 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003913 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003914 }
3915}
3916
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003917static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003918qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003919 int defer)
3920{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003921 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003922 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003923 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003924
3925 if (!fcport->rport)
3926 return;
3927
3928 rport = fcport->rport;
3929 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003930 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003931 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003932 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003933 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003934 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003935 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3936 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003937 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003938 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003939 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003940 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3941 "%s %8phN. rport %p roles %x\n",
3942 __func__, fcport->port_name, rport,
3943 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003944 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003945 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003946 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003947 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003948}
3949
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3952 *
3953 * Input: ha = adapter block pointer. fcport = port structure pointer.
3954 *
3955 * Return: None.
3956 *
3957 * Context:
3958 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003959void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003960 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003962 if (IS_QLAFX00(vha->hw)) {
3963 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3964 qla2x00_schedule_rport_del(vha, fcport, defer);
3965 return;
3966 }
3967
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003968 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003969 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003970 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971 qla2x00_schedule_rport_del(vha, fcport, defer);
3972 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003973 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 * We may need to retry the login, so don't change the state of the
3975 * port but do the retries.
3976 */
3977 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003978 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979
3980 if (!do_login)
3981 return;
3982
Arun Easia1d02852015-08-04 13:38:02 -04003983 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984}
3985
3986/*
3987 * qla2x00_mark_all_devices_lost
3988 * Updates fcport state when device goes offline.
3989 *
3990 * Input:
3991 * ha = adapter block pointer.
3992 * fcport = port structure pointer.
3993 *
3994 * Return:
3995 * None.
3996 *
3997 * Context:
3998 */
3999void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004000qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001{
4002 fc_port_t *fcport;
4003
Quinn Tran83548fe2017-06-02 09:12:01 -07004004 ql_dbg(ql_dbg_disc, vha, 0x20f1,
4005 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08004006
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004007 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08004008 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08004009 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004010
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04004011 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004013
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 /*
4015 * No point in marking the device as lost, if the device is
4016 * already DEAD.
4017 */
4018 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
4019 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004020 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07004021 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004022 if (defer)
4023 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04004024 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004025 qla2x00_schedule_rport_del(vha, fcport, defer);
4026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 }
4028}
4029
4030/*
4031* qla2x00_mem_alloc
4032* Allocates adapter memory.
4033*
4034* Returns:
4035* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08004036* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08004038static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004039qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
4040 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041{
4042 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043
Andrew Vasqueze8711082008-01-31 12:33:48 -08004044 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004045 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004046 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004047 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004049 if (qlt_mem_alloc(ha) < 0)
4050 goto fail_free_init_cb;
4051
Chad Dupuis642ef982012-02-09 11:15:57 -08004052 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
4053 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004054 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004055 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056
Andrew Vasqueze8711082008-01-31 12:33:48 -08004057 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
4058 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004059 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004061 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004062 /* Allocate cache for CT6 Ctx. */
4063 if (!ctx_cachep) {
4064 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
4065 sizeof(struct ct6_dsd), 0,
4066 SLAB_HWCACHE_ALIGN, NULL);
4067 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004068 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004069 }
4070 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4071 ctx_cachep);
4072 if (!ha->ctx_mempool)
4073 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004074 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4075 "ctx_cachep=%p ctx_mempool=%p.\n",
4076 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004077 }
4078
Andrew Vasqueze8711082008-01-31 12:33:48 -08004079 /* Get memory for cached NVRAM */
4080 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4081 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004082 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004084 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4085 ha->pdev->device);
4086 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4087 DMA_POOL_SIZE, 8, 0);
4088 if (!ha->s_dma_pool)
4089 goto fail_free_nvram;
4090
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004091 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4092 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4093 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4094
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004095 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004096 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4097 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4098 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004099 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4100 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004101 goto fail_s_dma_pool;
4102 }
4103
4104 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4105 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4106 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004107 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4108 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004109 goto fail_dl_dma_pool;
4110 }
Giridhar Malavali50b81272018-12-21 09:33:45 -08004111
4112 if (ql2xenabledif) {
4113 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4114 struct dsd_dma *dsd, *nxt;
4115 uint i;
4116 /* Creata a DMA pool of buffers for DIF bundling */
4117 ha->dif_bundl_pool = dma_pool_create(name,
4118 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4119 if (!ha->dif_bundl_pool) {
4120 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4121 "%s: failed create dif_bundl_pool\n",
4122 __func__);
4123 goto fail_dif_bundl_dma_pool;
4124 }
4125
4126 INIT_LIST_HEAD(&ha->pool.good.head);
4127 INIT_LIST_HEAD(&ha->pool.unusable.head);
4128 ha->pool.good.count = 0;
4129 ha->pool.unusable.count = 0;
4130 for (i = 0; i < 128; i++) {
4131 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4132 if (!dsd) {
4133 ql_dbg_pci(ql_dbg_init, ha->pdev,
4134 0xe0ee, "%s: failed alloc dsd\n",
4135 __func__);
4136 return 1;
4137 }
4138 ha->dif_bundle_kallocs++;
4139
4140 dsd->dsd_addr = dma_pool_alloc(
4141 ha->dif_bundl_pool, GFP_ATOMIC,
4142 &dsd->dsd_list_dma);
4143 if (!dsd->dsd_addr) {
4144 ql_dbg_pci(ql_dbg_init, ha->pdev,
4145 0xe0ee,
4146 "%s: failed alloc ->dsd_addr\n",
4147 __func__);
4148 kfree(dsd);
4149 ha->dif_bundle_kallocs--;
4150 continue;
4151 }
4152 ha->dif_bundle_dma_allocs++;
4153
4154 /*
4155 * if DMA buffer crosses 4G boundary,
4156 * put it on bad list
4157 */
4158 if (MSD(dsd->dsd_list_dma) ^
4159 MSD(dsd->dsd_list_dma + bufsize)) {
4160 list_add_tail(&dsd->list,
4161 &ha->pool.unusable.head);
4162 ha->pool.unusable.count++;
4163 } else {
4164 list_add_tail(&dsd->list,
4165 &ha->pool.good.head);
4166 ha->pool.good.count++;
4167 }
4168 }
4169
4170 /* return the good ones back to the pool */
4171 list_for_each_entry_safe(dsd, nxt,
4172 &ha->pool.good.head, list) {
4173 list_del(&dsd->list);
4174 dma_pool_free(ha->dif_bundl_pool,
4175 dsd->dsd_addr, dsd->dsd_list_dma);
4176 ha->dif_bundle_dma_allocs--;
4177 kfree(dsd);
4178 ha->dif_bundle_kallocs--;
4179 }
4180
4181 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4182 "%s: dif dma pool (good=%u unusable=%u)\n",
4183 __func__, ha->pool.good.count,
4184 ha->pool.unusable.count);
4185 }
4186
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004187 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
Giridhar Malavali50b81272018-12-21 09:33:45 -08004188 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4189 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4190 ha->dif_bundl_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004191 }
4192
Andrew Vasqueze8711082008-01-31 12:33:48 -08004193 /* Allocate memory for SNS commands */
4194 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004195 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004196 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004197 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004198 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004199 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004200 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08004201 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004202 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004203 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004204 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004205 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004206 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004207 goto fail_dma_pool;
4208 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004209 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004210 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004211 if (!ha->ct_sns)
4212 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004213 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4214 "ms_iocb=%p ct_sns=%p.\n",
4215 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 }
4217
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004218 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004219 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4220 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004221 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4222 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004223 goto fail_req;
4224 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004225 (*req)->length = req_len;
4226 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4227 ((*req)->length + 1) * sizeof(request_t),
4228 &(*req)->dma, GFP_KERNEL);
4229 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004230 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4231 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232 goto fail_req_ring;
4233 }
4234 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004235 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4236 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004237 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4238 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004239 goto fail_rsp;
4240 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004241 (*rsp)->hw = ha;
4242 (*rsp)->length = rsp_len;
4243 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4244 ((*rsp)->length + 1) * sizeof(response_t),
4245 &(*rsp)->dma, GFP_KERNEL);
4246 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004247 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4248 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004249 goto fail_rsp_ring;
4250 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004251 (*req)->rsp = *rsp;
4252 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004253 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4254 "req=%p req->length=%d req->ring=%p rsp=%p "
4255 "rsp->length=%d rsp->ring=%p.\n",
4256 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4257 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004258 /* Allocate memory for NVRAM data for vports */
4259 if (ha->nvram_npiv_size) {
Kees Cook6396bb22018-06-12 14:03:40 -07004260 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4261 sizeof(struct qla_npiv_entry),
4262 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004263 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004264 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4265 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004266 goto fail_npiv_info;
4267 }
4268 } else
4269 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004270
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004271 /* Get consistent memory allocated for EX-INIT-CB. */
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004272 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4273 IS_QLA28XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004274 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4275 &ha->ex_init_cb_dma);
4276 if (!ha->ex_init_cb)
4277 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004278 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4279 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004280 }
4281
Giridhar Malavalia9083012010-04-12 17:59:55 -07004282 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4283
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004284 /* Get consistent memory allocated for Async Port-Database. */
4285 if (!IS_FWI2_CAPABLE(ha)) {
4286 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4287 &ha->async_pd_dma);
4288 if (!ha->async_pd)
4289 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004290 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4291 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004292 }
4293
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004294 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004295
4296 /* Allocate memory for our loop_id bitmap */
Kees Cook6396bb22018-06-12 14:03:40 -07004297 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4298 sizeof(long),
4299 GFP_KERNEL);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004300 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004301 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004302 else {
4303 qla2x00_set_reserved_loop_ids(ha);
4304 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec32014-01-21 10:00:10 +03004305 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004306 }
4307
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004308 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4309 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4310 if (!ha->sfp_data) {
4311 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4312 "Unable to allocate memory for SFP read-data.\n");
4313 goto fail_sfp_data;
4314 }
4315
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004316 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4317 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4318 GFP_KERNEL);
4319 if (!ha->flt) {
4320 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4321 "Unable to allocate memory for FLT.\n");
4322 goto fail_flt_buffer;
4323 }
4324
Dan Carpenterb2a72ec32014-01-21 10:00:10 +03004325 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004326
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004327fail_flt_buffer:
4328 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4329 ha->sfp_data, ha->sfp_data_dma);
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004330fail_sfp_data:
4331 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004332fail_loop_id_map:
4333 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004334fail_async_pd:
4335 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004336fail_ex_init_cb:
4337 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004338fail_npiv_info:
4339 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4340 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4341 (*rsp)->ring = NULL;
4342 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004343fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004344 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004345 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004346fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004347 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4348 sizeof(request_t), (*req)->ring, (*req)->dma);
4349 (*req)->ring = NULL;
4350 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004351fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004352 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004353 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004354fail_req:
4355 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4356 ha->ct_sns, ha->ct_sns_dma);
4357 ha->ct_sns = NULL;
4358 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004359fail_free_ms_iocb:
4360 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4361 ha->ms_iocb = NULL;
4362 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004363
4364 if (ha->sns_cmd)
4365 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4366 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004367fail_dma_pool:
Giridhar Malavali50b81272018-12-21 09:33:45 -08004368 if (ql2xenabledif) {
4369 struct dsd_dma *dsd, *nxt;
4370
4371 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4372 list) {
4373 list_del(&dsd->list);
4374 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4375 dsd->dsd_list_dma);
4376 ha->dif_bundle_dma_allocs--;
4377 kfree(dsd);
4378 ha->dif_bundle_kallocs--;
4379 ha->pool.unusable.count--;
4380 }
4381 dma_pool_destroy(ha->dif_bundl_pool);
4382 ha->dif_bundl_pool = NULL;
4383 }
4384
4385fail_dif_bundl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004386 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004387 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4388 ha->fcp_cmnd_dma_pool = NULL;
4389 }
4390fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004391 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004392 dma_pool_destroy(ha->dl_dma_pool);
4393 ha->dl_dma_pool = NULL;
4394 }
4395fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004396 dma_pool_destroy(ha->s_dma_pool);
4397 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004398fail_free_nvram:
4399 kfree(ha->nvram);
4400 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004401fail_free_ctx_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004402 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004403 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004404fail_free_srb_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004405 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004406 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004407fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004408 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4409 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004410 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004411 ha->gid_list = NULL;
4412 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004413fail_free_tgt_mem:
4414 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004415fail_free_init_cb:
4416 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4417 ha->init_cb_dma);
4418 ha->init_cb = NULL;
4419 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004420fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004421 ql_log(ql_log_fatal, NULL, 0x0030,
4422 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004423 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424}
4425
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004426int
4427qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4428{
4429 int rval;
4430 uint16_t size, max_cnt, temp;
4431 struct qla_hw_data *ha = vha->hw;
4432
4433 /* Return if we don't need to alloacate any extended logins */
4434 if (!ql2xexlogins)
4435 return QLA_SUCCESS;
4436
Quinn Tran99e1b682017-06-02 09:12:03 -07004437 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4438 return QLA_SUCCESS;
4439
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004440 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4441 max_cnt = 0;
4442 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4443 if (rval != QLA_SUCCESS) {
4444 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4445 "Failed to get exlogin status.\n");
4446 return rval;
4447 }
4448
4449 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004450 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004451
Quinn Tran99e1b682017-06-02 09:12:03 -07004452 if (temp != ha->exlogin_size) {
4453 qla2x00_free_exlogin_buffer(ha);
4454 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004455
Quinn Tran99e1b682017-06-02 09:12:03 -07004456 ql_log(ql_log_info, vha, 0xd024,
4457 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4458 max_cnt, size, temp);
4459
4460 ql_log(ql_log_info, vha, 0xd025,
4461 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4462
4463 /* Get consistent memory for extended logins */
4464 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4465 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4466 if (!ha->exlogin_buf) {
4467 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004468 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004469 return -ENOMEM;
4470 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004471 }
4472
4473 /* Now configure the dma buffer */
4474 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4475 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004476 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004477 "Setup extended login buffer ****FAILED****.\n");
4478 qla2x00_free_exlogin_buffer(ha);
4479 }
4480
4481 return rval;
4482}
4483
4484/*
4485* qla2x00_free_exlogin_buffer
4486*
4487* Input:
4488* ha = adapter block pointer
4489*/
4490void
4491qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4492{
4493 if (ha->exlogin_buf) {
4494 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4495 ha->exlogin_buf, ha->exlogin_buf_dma);
4496 ha->exlogin_buf = NULL;
4497 ha->exlogin_size = 0;
4498 }
4499}
4500
Quinn Tran99e1b682017-06-02 09:12:03 -07004501static void
4502qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4503{
4504 u32 temp;
Quinn Tran0645cb82018-09-11 10:18:18 -07004505 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
Quinn Tran99e1b682017-06-02 09:12:03 -07004506 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4507
Quinn Trand1e36352017-12-28 12:33:12 -08004508 if (max_cnt > vha->hw->max_exchg)
4509 max_cnt = vha->hw->max_exchg;
4510
Quinn Tran99e1b682017-06-02 09:12:03 -07004511 if (qla_ini_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004512 if (vha->ql2xiniexchg > max_cnt)
4513 vha->ql2xiniexchg = max_cnt;
Quinn Tran99e1b682017-06-02 09:12:03 -07004514
Quinn Tran0645cb82018-09-11 10:18:18 -07004515 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4516 *ret_cnt = vha->ql2xiniexchg;
4517
Quinn Tran99e1b682017-06-02 09:12:03 -07004518 } else if (qla_tgt_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004519 if (vha->ql2xexchoffld > max_cnt) {
4520 vha->ql2xexchoffld = max_cnt;
4521 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4522 }
Quinn Tran99e1b682017-06-02 09:12:03 -07004523
Quinn Tran0645cb82018-09-11 10:18:18 -07004524 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4525 *ret_cnt = vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004526 } else if (qla_dual_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004527 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004528 if (temp > max_cnt) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004529 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4530 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
Quinn Tran99e1b682017-06-02 09:12:03 -07004531 temp = max_cnt;
Quinn Tran0645cb82018-09-11 10:18:18 -07004532 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Quinn Tran99e1b682017-06-02 09:12:03 -07004533 }
4534
4535 if (temp > FW_DEF_EXCHANGES_CNT)
4536 *ret_cnt = temp;
4537 }
4538}
4539
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004540int
4541qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4542{
4543 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004544 u16 size, max_cnt;
4545 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004546 struct qla_hw_data *ha = vha->hw;
4547
Quinn Tran99e1b682017-06-02 09:12:03 -07004548 if (!ha->flags.exchoffld_enabled)
4549 return QLA_SUCCESS;
4550
4551 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004552 return QLA_SUCCESS;
4553
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004554 max_cnt = 0;
4555 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4556 if (rval != QLA_SUCCESS) {
4557 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4558 "Failed to get exlogin status.\n");
4559 return rval;
4560 }
4561
Quinn Trand1e36352017-12-28 12:33:12 -08004562 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4563 ql_log(ql_log_info, vha, 0xd014,
4564 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004565
Quinn Trand1e36352017-12-28 12:33:12 -08004566 totsz = actual_cnt * size;
4567
4568 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004569 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran0645cb82018-09-11 10:18:18 -07004570 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4571 ha->exchoffld_size = 0;
4572 ha->flags.exchoffld_enabled = 0;
4573 return QLA_SUCCESS;
4574 }
4575
Quinn Trand1e36352017-12-28 12:33:12 -08004576 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004577
Quinn Tran99e1b682017-06-02 09:12:03 -07004578 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004579 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4580 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004581
4582 ql_log(ql_log_info, vha, 0xd017,
4583 "Exchange Buffers requested size = 0x%x\n",
4584 ha->exchoffld_size);
4585
4586 /* Get consistent memory for extended logins */
4587 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4588 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4589 if (!ha->exchoffld_buf) {
4590 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004591 "Failed to allocate memory for Exchange Offload.\n");
4592
4593 if (ha->max_exchg >
4594 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4595 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4596 } else if (ha->max_exchg >
4597 (FW_DEF_EXCHANGES_CNT + 512)) {
4598 ha->max_exchg -= 512;
4599 } else {
4600 ha->flags.exchoffld_enabled = 0;
4601 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4602 "Disabling Exchange offload due to lack of memory\n");
4603 }
4604 ha->exchoffld_size = 0;
4605
Quinn Tran99e1b682017-06-02 09:12:03 -07004606 return -ENOMEM;
4607 }
Quinn Tran0645cb82018-09-11 10:18:18 -07004608 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4609 /* pathological case */
4610 qla2x00_free_exchoffld_buffer(ha);
4611 ha->exchoffld_size = 0;
4612 ha->flags.exchoffld_enabled = 0;
4613 ql_log(ql_log_info, vha, 0xd016,
4614 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4615 ha->exchoffld_size, actual_cnt, size, totsz);
4616 return 0;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004617 }
4618
4619 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004620 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004621 if (rval) {
4622 ql_log(ql_log_fatal, vha, 0xd02e,
4623 "Setup exchange offload buffer ****FAILED****.\n");
4624 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004625 } else {
4626 /* re-adjust number of target exchange */
4627 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4628
4629 if (qla_ini_mode_enabled(vha))
4630 icb->exchange_count = 0;
4631 else
Quinn Tran0645cb82018-09-11 10:18:18 -07004632 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004633 }
4634
4635 return rval;
4636}
4637
4638/*
4639* qla2x00_free_exchoffld_buffer
4640*
4641* Input:
4642* ha = adapter block pointer
4643*/
4644void
4645qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4646{
4647 if (ha->exchoffld_buf) {
4648 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4649 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4650 ha->exchoffld_buf = NULL;
4651 ha->exchoffld_size = 0;
4652 }
4653}
4654
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004656* qla2x00_free_fw_dump
4657* Frees fw dump stuff.
4658*
4659* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004660* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004661*/
4662static void
4663qla2x00_free_fw_dump(struct qla_hw_data *ha)
4664{
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004665 struct fwdt *fwdt = ha->fwdt;
4666 uint j;
4667
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004668 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004669 dma_free_coherent(&ha->pdev->dev,
4670 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004671
Chad Dupuisf73cb692014-02-26 04:15:06 -05004672 if (ha->eft)
4673 dma_free_coherent(&ha->pdev->dev,
4674 EFT_SIZE, ha->eft, ha->eft_dma);
4675
4676 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004677 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004678
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004679 ha->fce = NULL;
4680 ha->fce_dma = 0;
4681 ha->eft = NULL;
4682 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004683 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004684 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004685 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004686 ha->fw_dump = NULL;
4687 ha->fw_dump_len = 0;
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004688
4689 for (j = 0; j < 2; j++, fwdt++) {
4690 if (fwdt->template)
4691 vfree(fwdt->template);
4692 fwdt->template = NULL;
4693 fwdt->length = 0;
4694 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004695}
4696
4697/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698* qla2x00_mem_free
4699* Frees all adapter allocated memory.
4700*
4701* Input:
4702* ha = adapter block pointer.
4703*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004704static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004705qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004707 qla2x00_free_fw_dump(ha);
4708
Saurav Kashyap81178772012-08-22 14:21:04 -04004709 if (ha->mctp_dump)
4710 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4711 ha->mctp_dump_dma);
4712
Thomas Meyer75c1d482018-12-02 21:52:11 +01004713 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004715 if (ha->dcbx_tlv)
4716 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4717 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4718
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004719 if (ha->xgmac_data)
4720 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4721 ha->xgmac_data, ha->xgmac_data_dma);
4722
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 if (ha->sns_cmd)
4724 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004725 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726
4727 if (ha->ct_sns)
4728 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004729 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730
Andrew Vasquez88729e52006-06-23 16:10:50 -07004731 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004732 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4733 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004734
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004735 if (ha->flt)
4736 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4737 ha->flt, ha->flt_dma);
4738
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 if (ha->ms_iocb)
4740 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4741
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004742 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004743 dma_pool_free(ha->s_dma_pool,
4744 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004745
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004746 if (ha->async_pd)
4747 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4748
Thomas Meyer75c1d482018-12-02 21:52:11 +01004749 dma_pool_destroy(ha->s_dma_pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004752 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4753 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754
Giridhar Malavalia9083012010-04-12 17:59:55 -07004755 if (IS_QLA82XX(ha)) {
4756 if (!list_empty(&ha->gbl_dsd_list)) {
4757 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4758
4759 /* clean up allocated prev pool */
4760 list_for_each_entry_safe(dsd_ptr,
4761 tdsd_ptr, &ha->gbl_dsd_list, list) {
4762 dma_pool_free(ha->dl_dma_pool,
4763 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4764 list_del(&dsd_ptr->list);
4765 kfree(dsd_ptr);
4766 }
4767 }
4768 }
4769
Thomas Meyer75c1d482018-12-02 21:52:11 +01004770 dma_pool_destroy(ha->dl_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004771
Thomas Meyer75c1d482018-12-02 21:52:11 +01004772 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004773
Thomas Meyer75c1d482018-12-02 21:52:11 +01004774 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004775
Giridhar Malavali50b81272018-12-21 09:33:45 -08004776 if (ql2xenabledif) {
4777 struct dsd_dma *dsd, *nxt;
4778
4779 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4780 list) {
4781 list_del(&dsd->list);
4782 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4783 dsd->dsd_list_dma);
4784 ha->dif_bundle_dma_allocs--;
4785 kfree(dsd);
4786 ha->dif_bundle_kallocs--;
4787 ha->pool.unusable.count--;
4788 }
4789 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4790 list_del(&dsd->list);
4791 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4792 dsd->dsd_list_dma);
4793 ha->dif_bundle_dma_allocs--;
4794 kfree(dsd);
4795 ha->dif_bundle_kallocs--;
4796 }
4797 }
4798
4799 if (ha->dif_bundl_pool)
4800 dma_pool_destroy(ha->dif_bundl_pool);
4801
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004802 qlt_mem_free(ha);
4803
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004804 if (ha->init_cb)
4805 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004806 ha->init_cb, ha->init_cb_dma);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004807
Bill Kuzeja6d634062018-03-23 10:37:25 -04004808 vfree(ha->optrom_buffer);
4809 kfree(ha->nvram);
4810 kfree(ha->npiv_info);
4811 kfree(ha->swl);
4812 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813
Andrew Vasqueze8711082008-01-31 12:33:48 -08004814 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004815 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 ha->sns_cmd = NULL;
4817 ha->sns_cmd_dma = 0;
4818 ha->ct_sns = NULL;
4819 ha->ct_sns_dma = 0;
4820 ha->ms_iocb = NULL;
4821 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 ha->init_cb = NULL;
4823 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004824 ha->ex_init_cb = NULL;
4825 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004826 ha->async_pd = NULL;
4827 ha->async_pd_dma = 0;
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004828 ha->loop_id_map = NULL;
4829 ha->npiv_info = NULL;
4830 ha->optrom_buffer = NULL;
4831 ha->swl = NULL;
4832 ha->nvram = NULL;
4833 ha->mctp_dump = NULL;
4834 ha->dcbx_tlv = NULL;
4835 ha->xgmac_data = NULL;
4836 ha->sfp_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837
4838 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004839 ha->dl_dma_pool = NULL;
4840 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 ha->gid_list = NULL;
4843 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004844
4845 ha->tgt.atio_ring = NULL;
4846 ha->tgt.atio_dma = 0;
4847 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004848}
4849
4850struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4851 struct qla_hw_data *ha)
4852{
4853 struct Scsi_Host *host;
4854 struct scsi_qla_host *vha = NULL;
4855
4856 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004857 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004858 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4859 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004860 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004861 }
4862
4863 /* Clear our data area */
4864 vha = shost_priv(host);
4865 memset(vha, 0, sizeof(scsi_qla_host_t));
4866
4867 vha->host = host;
4868 vha->host_no = host->host_no;
4869 vha->hw = ha;
4870
Quinn Tran0645cb82018-09-11 10:18:18 -07004871 vha->qlini_mode = ql2x_ini_mode;
4872 vha->ql2xexchoffld = ql2xexchoffld;
4873 vha->ql2xiniexchg = ql2xiniexchg;
4874
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004875 INIT_LIST_HEAD(&vha->vp_fcports);
4876 INIT_LIST_HEAD(&vha->work_list);
4877 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004878 INIT_LIST_HEAD(&vha->qla_cmd_list);
4879 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004880 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004881 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004882 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004883 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004884 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004885 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004886 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004887
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004888 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004889 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004890 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004891 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004892
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004893 vha->gnl.size = sizeof(struct get_name_list_extended) *
4894 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004895 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4896 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4897 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004898 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004899 "Alloc failed for name list.\n");
4900 scsi_remove_host(vha->host);
4901 return NULL;
4902 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004903
Quinn Trana4239942017-12-28 12:33:26 -08004904 /* todo: what about ext login? */
4905 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4906 vha->scan.l = vmalloc(vha->scan.size);
4907 if (!vha->scan.l) {
4908 ql_log(ql_log_fatal, vha, 0xd04a,
4909 "Alloc failed for scan database.\n");
4910 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4911 vha->gnl.l, vha->gnl.ldma);
4912 scsi_remove_host(vha->host);
4913 return NULL;
4914 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004915 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004917 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004918 ql_dbg(ql_dbg_init, vha, 0x0041,
4919 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4920 vha->host, vha->hw, vha,
4921 dev_name(&(ha->pdev->dev)));
4922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004923 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924}
4925
Quinn Tran726b8542017-01-19 22:28:00 -08004926struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004927qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004928{
4929 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004930 uint8_t bail;
4931
4932 QLA_VHA_MARK_BUSY(vha, bail);
4933 if (bail)
4934 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004935
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004936 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004937 if (!e) {
4938 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004939 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004940 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004941
4942 INIT_LIST_HEAD(&e->list);
4943 e->type = type;
4944 e->flags = QLA_EVT_FLAG_FREE;
4945 return e;
4946}
4947
Quinn Tran726b8542017-01-19 22:28:00 -08004948int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004949qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004950{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004951 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004952 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004953
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004954 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004955 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004956
4957 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4958 q = true;
4959
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004960 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004961
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004962 if (q)
4963 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004964
Andrew Vasquez0971de72008-04-03 13:13:18 -07004965 return QLA_SUCCESS;
4966}
4967
4968int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004969qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004970 u32 data)
4971{
4972 struct qla_work_evt *e;
4973
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004974 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004975 if (!e)
4976 return QLA_FUNCTION_FAILED;
4977
4978 e->u.aen.code = code;
4979 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004980 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004981}
4982
Andrew Vasquez8a659572009-02-08 20:50:12 -08004983int
4984qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4985{
4986 struct qla_work_evt *e;
4987
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004988 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004989 if (!e)
4990 return QLA_FUNCTION_FAILED;
4991
4992 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004993 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004994}
4995
Andrew Vasquezac280b62009-08-20 11:06:05 -07004996#define qla2x00_post_async_work(name, type) \
4997int qla2x00_post_async_##name##_work( \
4998 struct scsi_qla_host *vha, \
4999 fc_port_t *fcport, uint16_t *data) \
5000{ \
5001 struct qla_work_evt *e; \
5002 \
5003 e = qla2x00_alloc_work(vha, type); \
5004 if (!e) \
5005 return QLA_FUNCTION_FAILED; \
5006 \
5007 e->u.logio.fcport = fcport; \
5008 if (data) { \
5009 e->u.logio.data[0] = data[0]; \
5010 e->u.logio.data[1] = data[1]; \
5011 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08005012 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07005013 return qla2x00_post_work(vha, e); \
5014}
5015
5016qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07005017qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
5018qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005019qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
Quinn Tran11aea162017-12-28 12:33:20 -08005020qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
5021qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07005022
Andrew Vasquez3420d362009-10-13 15:16:45 -07005023int
5024qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
5025{
5026 struct qla_work_evt *e;
5027
5028 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
5029 if (!e)
5030 return QLA_FUNCTION_FAILED;
5031
5032 e->u.uevent.code = code;
5033 return qla2x00_post_work(vha, e);
5034}
5035
5036static void
5037qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
5038{
5039 char event_string[40];
5040 char *envp[] = { event_string, NULL };
5041
5042 switch (code) {
5043 case QLA_UEVENT_CODE_FW_DUMP:
5044 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
5045 vha->host_no);
5046 break;
5047 default:
5048 /* do nothing */
5049 break;
5050 }
5051 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
5052}
5053
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005054int
5055qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
5056 uint32_t *data, int cnt)
5057{
5058 struct qla_work_evt *e;
5059
5060 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
5061 if (!e)
5062 return QLA_FUNCTION_FAILED;
5063
5064 e->u.aenfx.evtcode = evtcode;
5065 e->u.aenfx.count = cnt;
5066 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
5067 return qla2x00_post_work(vha, e);
5068}
5069
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005070void qla24xx_sched_upd_fcport(fc_port_t *fcport)
Quinn Tran726b8542017-01-19 22:28:00 -08005071{
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005072 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08005073
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005074 if (IS_SW_RESV_ADDR(fcport->d_id))
5075 return;
Quinn Tran726b8542017-01-19 22:28:00 -08005076
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005077 spin_lock_irqsave(&fcport->vha->work_lock, flags);
5078 if (fcport->disc_state == DSC_UPD_FCPORT) {
5079 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5080 return;
5081 }
5082 fcport->jiffies_at_registration = jiffies;
5083 fcport->sec_since_registration = 0;
5084 fcport->next_disc_state = DSC_DELETED;
5085 fcport->disc_state = DSC_UPD_FCPORT;
5086 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5087
5088 queue_work(system_unbound_wq, &fcport->reg_work);
Quinn Tran726b8542017-01-19 22:28:00 -08005089}
5090
5091static
5092void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5093{
5094 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07005095 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08005096 struct qlt_plogi_ack_t *pla =
5097 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07005098 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005099
Quinn Tran9cd883f2017-12-28 12:33:24 -08005100 ql_dbg(ql_dbg_disc, vha, 0xffff,
5101 "%s %d %8phC enter\n",
5102 __func__, __LINE__, e->u.new_sess.port_name);
5103
Quinn Tran726b8542017-01-19 22:28:00 -08005104 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5105 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5106 if (fcport) {
5107 fcport->d_id = e->u.new_sess.id;
5108 if (pla) {
5109 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005110 memcpy(fcport->node_name,
5111 pla->iocb.u.isp24.u.plogi.node_name,
5112 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08005113 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5114 /* we took an extra ref_count to prevent PLOGI ACK when
5115 * fcport/sess has not been created.
5116 */
5117 pla->ref_count--;
5118 }
5119 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07005120 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08005121 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5122 if (fcport) {
5123 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08005124 fcport->flags |= FCF_FABRIC_DEVICE;
5125 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005126 if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08005127 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08005128
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005129 if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08005130 fcport->fc4_type = FC4_TYPE_OTHER;
5131 fcport->fc4f_nvme = FC4_TYPE_NVME;
5132 }
Quinn Tran33b28352018-03-20 23:09:40 -07005133
Quinn Tran726b8542017-01-19 22:28:00 -08005134 memcpy(fcport->port_name, e->u.new_sess.port_name,
5135 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07005136 } else {
5137 ql_dbg(ql_dbg_disc, vha, 0xffff,
5138 "%s %8phC mem alloc fail.\n",
5139 __func__, e->u.new_sess.port_name);
5140
5141 if (pla)
5142 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5143 return;
5144 }
5145
5146 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08005147 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07005148 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5149 e->u.new_sess.port_name, 1);
5150 if (tfcp) {
5151 /* should rarily happen */
5152 ql_dbg(ql_dbg_disc, vha, 0xffff,
5153 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5154 __func__, tfcp->port_name, tfcp->disc_state,
5155 tfcp->fw_login_state);
5156
5157 free_fcport = 1;
5158 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08005159 list_add_tail(&fcport->list, &vha->vp_fcports);
5160
Quinn Tran19759032017-12-04 14:45:15 -08005161 }
5162 if (pla) {
5163 qlt_plogi_ack_link(vha, pla, fcport,
5164 QLT_PLOGI_LINK_SAME_WWN);
5165 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08005166 }
5167 }
5168 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5169
5170 if (fcport) {
Quinn Trana4239942017-12-28 12:33:26 -08005171 fcport->id_changed = 1;
5172 fcport->scan_state = QLA_FCPORT_FOUND;
5173 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5174
Quinn Tran5ef696a2017-12-04 14:45:05 -08005175 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005176 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5177 u16 wd3_lo;
5178
5179 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5180 fcport->local = 0;
5181 fcport->loop_id =
5182 le16_to_cpu(
5183 pla->iocb.u.isp24.nport_handle);
5184 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5185 wd3_lo =
5186 le16_to_cpu(
5187 pla->iocb.u.isp24.u.prli.wd3_lo);
5188
5189 if (wd3_lo & BIT_7)
5190 fcport->conf_compl_supported = 1;
5191
5192 if ((wd3_lo & BIT_4) == 0)
5193 fcport->port_type = FCT_INITIATOR;
5194 else
5195 fcport->port_type = FCT_TARGET;
5196 }
Quinn Tran726b8542017-01-19 22:28:00 -08005197 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08005198 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005199 fc_port_t *dfcp = NULL;
5200
Quinn Tran5ef696a2017-12-04 14:45:05 -08005201 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5202 tfcp = qla2x00_find_fcport_by_nportid(vha,
5203 &e->u.new_sess.id, 1);
5204 if (tfcp && (tfcp != fcport)) {
5205 /*
5206 * We have a conflict fcport with same NportID.
5207 */
5208 ql_dbg(ql_dbg_disc, vha, 0xffff,
5209 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5210 __func__, tfcp->port_name, tfcp->disc_state,
5211 tfcp->fw_login_state);
5212
5213 switch (tfcp->disc_state) {
5214 case DSC_DELETED:
5215 break;
5216 case DSC_DELETE_PEND:
5217 fcport->login_pause = 1;
5218 tfcp->conflict = fcport;
5219 break;
5220 default:
5221 fcport->login_pause = 1;
5222 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005223 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08005224 break;
5225 }
5226 }
5227 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005228 if (dfcp)
5229 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08005230
Quinn Trana4239942017-12-28 12:33:26 -08005231
Quinn Tran8777e432018-08-02 13:16:57 -07005232 if (N2N_TOPO(vha->hw))
5233 fcport->flags &= ~FCF_FABRIC_DEVICE;
5234
5235 if (N2N_TOPO(vha->hw)) {
5236 if (vha->flags.nvme_enabled) {
5237 fcport->fc4f_nvme = 1;
5238 fcport->n2n_flag = 1;
5239 }
5240 fcport->fw_login_state = 0;
5241 /*
5242 * wait link init done before sending login
5243 */
5244 } else {
5245 qla24xx_fcport_handle_login(vha, fcport);
5246 }
Quinn Tran5ef696a2017-12-04 14:45:05 -08005247 }
Quinn Tran726b8542017-01-19 22:28:00 -08005248 }
Quinn Tranb5d15312017-08-30 10:16:49 -07005249
5250 if (free_fcport) {
5251 qla2x00_free_fcport(fcport);
5252 if (pla)
5253 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5254 }
Quinn Tran726b8542017-01-19 22:28:00 -08005255}
5256
Quinn Trane374f9f2017-12-28 12:33:31 -08005257static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5258{
5259 struct srb *sp = e->u.iosb.sp;
5260 int rval;
5261
5262 rval = qla2x00_start_sp(sp);
5263 if (rval != QLA_SUCCESS) {
5264 ql_dbg(ql_dbg_disc, vha, 0x2043,
5265 "%s: %s: Re-issue IOCB failed (%d).\n",
5266 __func__, sp->name, rval);
5267 qla24xx_sp_unmap(vha, sp);
5268 }
5269}
5270
Andrew Vasquezac280b62009-08-20 11:06:05 -07005271void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005272qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07005273{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005274 struct qla_work_evt *e, *tmp;
5275 unsigned long flags;
5276 LIST_HEAD(work);
Quinn Tran80676d02019-01-24 23:23:42 -08005277 int rc;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005278
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005279 spin_lock_irqsave(&vha->work_lock, flags);
5280 list_splice_init(&vha->work_list, &work);
5281 spin_unlock_irqrestore(&vha->work_lock, flags);
5282
5283 list_for_each_entry_safe(e, tmp, &work, list) {
Quinn Tran80676d02019-01-24 23:23:42 -08005284 rc = QLA_SUCCESS;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005285 switch (e->type) {
5286 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005287 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07005288 e->u.aen.code, e->u.aen.data);
5289 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08005290 case QLA_EVT_IDC_ACK:
5291 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5292 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005293 case QLA_EVT_ASYNC_LOGIN:
5294 qla2x00_async_login(vha, e->u.logio.fcport,
5295 e->u.logio.data);
5296 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005297 case QLA_EVT_ASYNC_LOGOUT:
Quinn Tran80676d02019-01-24 23:23:42 -08005298 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07005299 break;
5300 case QLA_EVT_ASYNC_LOGOUT_DONE:
5301 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5302 e->u.logio.data);
5303 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005304 case QLA_EVT_ASYNC_ADISC:
5305 qla2x00_async_adisc(vha, e->u.logio.fcport,
5306 e->u.logio.data);
5307 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005308 case QLA_EVT_UEVENT:
5309 qla2x00_uevent_emit(vha, e->u.uevent.code);
5310 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005311 case QLA_EVT_AENFX:
5312 qlafx00_process_aen(vha, e);
5313 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005314 case QLA_EVT_GPNID:
5315 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5316 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005317 case QLA_EVT_UNMAP:
5318 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005319 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005320 case QLA_EVT_RELOGIN:
5321 qla2x00_relogin(vha);
5322 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005323 case QLA_EVT_NEW_SESS:
5324 qla24xx_create_new_sess(vha, e);
5325 break;
5326 case QLA_EVT_GPDB:
5327 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5328 e->u.fcport.opt);
5329 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005330 case QLA_EVT_PRLI:
5331 qla24xx_async_prli(vha, e->u.fcport.fcport);
5332 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005333 case QLA_EVT_GPSC:
5334 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5335 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005336 case QLA_EVT_GNL:
5337 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5338 break;
5339 case QLA_EVT_NACK:
5340 qla24xx_do_nack_work(vha, e);
5341 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005342 case QLA_EVT_ASYNC_PRLO:
Quinn Tran80676d02019-01-24 23:23:42 -08005343 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
Quinn Tran11aea162017-12-28 12:33:20 -08005344 break;
5345 case QLA_EVT_ASYNC_PRLO_DONE:
5346 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5347 e->u.logio.data);
5348 break;
Quinn Trana4239942017-12-28 12:33:26 -08005349 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005350 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5351 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005352 break;
5353 case QLA_EVT_GPNFT_DONE:
5354 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5355 break;
5356 case QLA_EVT_GNNFT_DONE:
5357 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5358 break;
5359 case QLA_EVT_GNNID:
5360 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5361 break;
5362 case QLA_EVT_GFPNID:
5363 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5364 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005365 case QLA_EVT_SP_RETRY:
5366 qla_sp_retry(vha, e);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005367 break;
5368 case QLA_EVT_IIDMA:
5369 qla_do_iidma_work(vha, e->u.fcport.fcport);
5370 break;
Quinn Tran8777e432018-08-02 13:16:57 -07005371 case QLA_EVT_ELS_PLOGI:
5372 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5373 e->u.fcport.fcport, false);
5374 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005375 }
Quinn Tran80676d02019-01-24 23:23:42 -08005376
5377 if (rc == EAGAIN) {
5378 /* put 'work' at head of 'vha->work_list' */
5379 spin_lock_irqsave(&vha->work_lock, flags);
5380 list_splice(&work, &vha->work_list);
5381 spin_unlock_irqrestore(&vha->work_lock, flags);
5382 break;
5383 }
5384 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005385 if (e->flags & QLA_EVT_FLAG_FREE)
5386 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005387
5388 /* For each work completed decrement vha ref count */
5389 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005390 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005391}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005392
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005393int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5394{
5395 struct qla_work_evt *e;
5396
5397 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5398
5399 if (!e) {
5400 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5401 return QLA_FUNCTION_FAILED;
5402 }
5403
5404 return qla2x00_post_work(vha, e);
5405}
5406
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005407/* Relogins all the fcports of a vport
5408 * Context: dpc thread
5409 */
5410void qla2x00_relogin(struct scsi_qla_host *vha)
5411{
5412 fc_port_t *fcport;
Quinn Tran23dd98a2018-08-02 13:16:45 -07005413 int status, relogin_needed = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005414 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005415
5416 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005417 /*
5418 * If the port is not ONLINE then try to login
5419 * to it if we haven't run out of retries.
5420 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005421 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran23dd98a2018-08-02 13:16:45 -07005422 fcport->login_retry) {
5423 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5424 fcport->disc_state == DSC_LOGIN_COMPLETE)
5425 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005426
Quinn Tran23dd98a2018-08-02 13:16:45 -07005427 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5428 fcport->disc_state == DSC_DELETE_PEND) {
5429 relogin_needed = 1;
5430 } else {
5431 if (vha->hw->current_topology != ISP_CFG_NL) {
5432 memset(&ea, 0, sizeof(ea));
5433 ea.event = FCME_RELOGIN;
5434 ea.fcport = fcport;
5435 qla2x00_fcport_event_handler(vha, &ea);
5436 } else if (vha->hw->current_topology ==
5437 ISP_CFG_NL) {
5438 fcport->login_retry--;
5439 status =
5440 qla2x00_local_device_login(vha,
5441 fcport);
5442 if (status == QLA_SUCCESS) {
5443 fcport->old_loop_id =
5444 fcport->loop_id;
5445 ql_dbg(ql_dbg_disc, vha, 0x2003,
5446 "Port login OK: logged in ID 0x%x.\n",
5447 fcport->loop_id);
5448 qla2x00_update_fcport
5449 (vha, fcport);
5450 } else if (status == 1) {
5451 set_bit(RELOGIN_NEEDED,
5452 &vha->dpc_flags);
5453 /* retry the login again */
5454 ql_dbg(ql_dbg_disc, vha, 0x2007,
5455 "Retrying %d login again loop_id 0x%x.\n",
5456 fcport->login_retry,
5457 fcport->loop_id);
5458 } else {
5459 fcport->login_retry = 0;
5460 }
5461
5462 if (fcport->login_retry == 0 &&
5463 status != QLA_SUCCESS)
5464 qla2x00_clear_loop_id(fcport);
5465 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005466 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005467 }
5468 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5469 break;
5470 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005471
Quinn Tran23dd98a2018-08-02 13:16:45 -07005472 if (relogin_needed)
5473 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5474
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005475 ql_dbg(ql_dbg_disc, vha, 0x400e,
5476 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005477}
5478
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005479/* Schedule work on any of the dpc-workqueues */
5480void
5481qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5482{
5483 struct qla_hw_data *ha = base_vha->hw;
5484
5485 switch (work_code) {
5486 case MBA_IDC_AEN: /* 0x8200 */
5487 if (ha->dpc_lp_wq)
5488 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5489 break;
5490
5491 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5492 if (!ha->flags.nic_core_reset_hdlr_active) {
5493 if (ha->dpc_hp_wq)
5494 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5495 } else
5496 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5497 "NIC Core reset is already active. Skip "
5498 "scheduling it again.\n");
5499 break;
5500 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5501 if (ha->dpc_hp_wq)
5502 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5503 break;
5504 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5505 if (ha->dpc_hp_wq)
5506 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5507 break;
5508 default:
5509 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005510 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005511 }
5512
5513 return;
5514}
5515
5516/* Work: Perform NIC Core Unrecoverable state handling */
5517void
5518qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5519{
5520 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005521 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005522 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5523 uint32_t dev_state = 0;
5524
5525 qla83xx_idc_lock(base_vha, 0);
5526 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5527 qla83xx_reset_ownership(base_vha);
5528 if (ha->flags.nic_core_reset_owner) {
5529 ha->flags.nic_core_reset_owner = 0;
5530 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5531 QLA8XXX_DEV_FAILED);
5532 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5533 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5534 }
5535 qla83xx_idc_unlock(base_vha, 0);
5536}
5537
5538/* Work: Execute IDC state handler */
5539void
5540qla83xx_idc_state_handler_work(struct work_struct *work)
5541{
5542 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005543 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005544 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5545 uint32_t dev_state = 0;
5546
5547 qla83xx_idc_lock(base_vha, 0);
5548 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5549 if (dev_state == QLA8XXX_DEV_FAILED ||
5550 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5551 qla83xx_idc_state_handler(base_vha);
5552 qla83xx_idc_unlock(base_vha, 0);
5553}
5554
Saurav Kashyapfa492632012-11-21 02:40:29 -05005555static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005556qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5557{
5558 int rval = QLA_SUCCESS;
5559 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5560 uint32_t heart_beat_counter1, heart_beat_counter2;
5561
5562 do {
5563 if (time_after(jiffies, heart_beat_wait)) {
5564 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5565 "Nic Core f/w is not alive.\n");
5566 rval = QLA_FUNCTION_FAILED;
5567 break;
5568 }
5569
5570 qla83xx_idc_lock(base_vha, 0);
5571 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5572 &heart_beat_counter1);
5573 qla83xx_idc_unlock(base_vha, 0);
5574 msleep(100);
5575 qla83xx_idc_lock(base_vha, 0);
5576 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5577 &heart_beat_counter2);
5578 qla83xx_idc_unlock(base_vha, 0);
5579 } while (heart_beat_counter1 == heart_beat_counter2);
5580
5581 return rval;
5582}
5583
5584/* Work: Perform NIC Core Reset handling */
5585void
5586qla83xx_nic_core_reset_work(struct work_struct *work)
5587{
5588 struct qla_hw_data *ha =
5589 container_of(work, struct qla_hw_data, nic_core_reset);
5590 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5591 uint32_t dev_state = 0;
5592
Saurav Kashyap81178772012-08-22 14:21:04 -04005593 if (IS_QLA2031(ha)) {
5594 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5595 ql_log(ql_log_warn, base_vha, 0xb081,
5596 "Failed to dump mctp\n");
5597 return;
5598 }
5599
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005600 if (!ha->flags.nic_core_reset_hdlr_active) {
5601 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5602 qla83xx_idc_lock(base_vha, 0);
5603 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5604 &dev_state);
5605 qla83xx_idc_unlock(base_vha, 0);
5606 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5607 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5608 "Nic Core f/w is alive.\n");
5609 return;
5610 }
5611 }
5612
5613 ha->flags.nic_core_reset_hdlr_active = 1;
5614 if (qla83xx_nic_core_reset(base_vha)) {
5615 /* NIC Core reset failed. */
5616 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5617 "NIC Core reset failed.\n");
5618 }
5619 ha->flags.nic_core_reset_hdlr_active = 0;
5620 }
5621}
5622
5623/* Work: Handle 8200 IDC aens */
5624void
5625qla83xx_service_idc_aen(struct work_struct *work)
5626{
5627 struct qla_hw_data *ha =
5628 container_of(work, struct qla_hw_data, idc_aen);
5629 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5630 uint32_t dev_state, idc_control;
5631
5632 qla83xx_idc_lock(base_vha, 0);
5633 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5634 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5635 qla83xx_idc_unlock(base_vha, 0);
5636 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5637 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5638 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5639 "Application requested NIC Core Reset.\n");
5640 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5641 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5642 QLA_SUCCESS) {
5643 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5644 "Other protocol driver requested NIC Core Reset.\n");
5645 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5646 }
5647 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5648 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5649 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5650 }
5651}
5652
5653static void
5654qla83xx_wait_logic(void)
5655{
5656 int i;
5657
5658 /* Yield CPU */
5659 if (!in_interrupt()) {
5660 /*
5661 * Wait about 200ms before retrying again.
5662 * This controls the number of retries for single
5663 * lock operation.
5664 */
5665 msleep(100);
5666 schedule();
5667 } else {
5668 for (i = 0; i < 20; i++)
5669 cpu_relax(); /* This a nop instr on i386 */
5670 }
5671}
5672
Saurav Kashyapfa492632012-11-21 02:40:29 -05005673static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005674qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5675{
5676 int rval;
5677 uint32_t data;
5678 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5679 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5680 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005681 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5682 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005683
5684 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5685 if (rval)
5686 return rval;
5687
5688 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5689 return QLA_SUCCESS;
5690 } else {
5691 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5692 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5693 data);
5694 if (rval)
5695 return rval;
5696
5697 msleep(200);
5698
5699 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5700 &data);
5701 if (rval)
5702 return rval;
5703
5704 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5705 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5706 ~(idc_lck_rcvry_stage_mask));
5707 rval = qla83xx_wr_reg(base_vha,
5708 QLA83XX_IDC_LOCK_RECOVERY, data);
5709 if (rval)
5710 return rval;
5711
5712 /* Forcefully perform IDC UnLock */
5713 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5714 &data);
5715 if (rval)
5716 return rval;
5717 /* Clear lock-id by setting 0xff */
5718 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5719 0xff);
5720 if (rval)
5721 return rval;
5722 /* Clear lock-recovery by setting 0x0 */
5723 rval = qla83xx_wr_reg(base_vha,
5724 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5725 if (rval)
5726 return rval;
5727 } else
5728 return QLA_SUCCESS;
5729 }
5730
5731 return rval;
5732}
5733
Saurav Kashyapfa492632012-11-21 02:40:29 -05005734static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005735qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5736{
5737 int rval = QLA_SUCCESS;
5738 uint32_t o_drv_lockid, n_drv_lockid;
5739 unsigned long lock_recovery_timeout;
5740
5741 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5742retry_lockid:
5743 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5744 if (rval)
5745 goto exit;
5746
5747 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5748 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5749 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5750 return QLA_SUCCESS;
5751 else
5752 return QLA_FUNCTION_FAILED;
5753 }
5754
5755 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5756 if (rval)
5757 goto exit;
5758
5759 if (o_drv_lockid == n_drv_lockid) {
5760 qla83xx_wait_logic();
5761 goto retry_lockid;
5762 } else
5763 return QLA_SUCCESS;
5764
5765exit:
5766 return rval;
5767}
5768
5769void
5770qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5771{
5772 uint16_t options = (requester_id << 15) | BIT_6;
5773 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005774 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005775 struct qla_hw_data *ha = base_vha->hw;
5776
5777 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5778retry_lock:
5779 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5780 == QLA_SUCCESS) {
5781 if (data) {
5782 /* Setting lock-id to our function-number */
5783 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5784 ha->portnum);
5785 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005786 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5787 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005788 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005789 "Failed to acquire IDC lock, acquired by %d, "
5790 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005791
5792 /* Retry/Perform IDC-Lock recovery */
5793 if (qla83xx_idc_lock_recovery(base_vha)
5794 == QLA_SUCCESS) {
5795 qla83xx_wait_logic();
5796 goto retry_lock;
5797 } else
5798 ql_log(ql_log_warn, base_vha, 0xb075,
5799 "IDC Lock recovery FAILED.\n");
5800 }
5801
5802 }
5803
5804 return;
5805
5806 /* XXX: IDC-lock implementation using access-control mbx */
5807retry_lock2:
5808 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5809 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5810 "Failed to acquire IDC lock. retrying...\n");
5811 /* Retry/Perform IDC-Lock recovery */
5812 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5813 qla83xx_wait_logic();
5814 goto retry_lock2;
5815 } else
5816 ql_log(ql_log_warn, base_vha, 0xb076,
5817 "IDC Lock recovery FAILED.\n");
5818 }
5819
5820 return;
5821}
5822
5823void
5824qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5825{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005826#if 0
5827 uint16_t options = (requester_id << 15) | BIT_7;
5828#endif
5829 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005830 uint32_t data;
5831 struct qla_hw_data *ha = base_vha->hw;
5832
5833 /* IDC-unlock implementation using driver-unlock/lock-id
5834 * remote registers
5835 */
5836 retry = 0;
5837retry_unlock:
5838 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5839 == QLA_SUCCESS) {
5840 if (data == ha->portnum) {
5841 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5842 /* Clearing lock-id by setting 0xff */
5843 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5844 } else if (retry < 10) {
5845 /* SV: XXX: IDC unlock retrying needed here? */
5846
5847 /* Retry for IDC-unlock */
5848 qla83xx_wait_logic();
5849 retry++;
5850 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005851 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005852 goto retry_unlock;
5853 }
5854 } else if (retry < 10) {
5855 /* Retry for IDC-unlock */
5856 qla83xx_wait_logic();
5857 retry++;
5858 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005859 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005860 goto retry_unlock;
5861 }
5862
5863 return;
5864
Bart Van Assche5897cb22015-06-04 15:57:20 -07005865#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005866 /* XXX: IDC-unlock implementation using access-control mbx */
5867 retry = 0;
5868retry_unlock2:
5869 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5870 if (retry < 10) {
5871 /* Retry for IDC-unlock */
5872 qla83xx_wait_logic();
5873 retry++;
5874 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005875 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005876 goto retry_unlock2;
5877 }
5878 }
5879
5880 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005881#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005882}
5883
5884int
5885__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5886{
5887 int rval = QLA_SUCCESS;
5888 struct qla_hw_data *ha = vha->hw;
5889 uint32_t drv_presence;
5890
5891 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5892 if (rval == QLA_SUCCESS) {
5893 drv_presence |= (1 << ha->portnum);
5894 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5895 drv_presence);
5896 }
5897
5898 return rval;
5899}
5900
5901int
5902qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5903{
5904 int rval = QLA_SUCCESS;
5905
5906 qla83xx_idc_lock(vha, 0);
5907 rval = __qla83xx_set_drv_presence(vha);
5908 qla83xx_idc_unlock(vha, 0);
5909
5910 return rval;
5911}
5912
5913int
5914__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5915{
5916 int rval = QLA_SUCCESS;
5917 struct qla_hw_data *ha = vha->hw;
5918 uint32_t drv_presence;
5919
5920 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5921 if (rval == QLA_SUCCESS) {
5922 drv_presence &= ~(1 << ha->portnum);
5923 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5924 drv_presence);
5925 }
5926
5927 return rval;
5928}
5929
5930int
5931qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5932{
5933 int rval = QLA_SUCCESS;
5934
5935 qla83xx_idc_lock(vha, 0);
5936 rval = __qla83xx_clear_drv_presence(vha);
5937 qla83xx_idc_unlock(vha, 0);
5938
5939 return rval;
5940}
5941
Saurav Kashyapfa492632012-11-21 02:40:29 -05005942static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005943qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5944{
5945 struct qla_hw_data *ha = vha->hw;
5946 uint32_t drv_ack, drv_presence;
5947 unsigned long ack_timeout;
5948
5949 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5950 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5951 while (1) {
5952 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5953 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005954 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005955 break;
5956
5957 if (time_after_eq(jiffies, ack_timeout)) {
5958 ql_log(ql_log_warn, vha, 0xb067,
5959 "RESET ACK TIMEOUT! drv_presence=0x%x "
5960 "drv_ack=0x%x\n", drv_presence, drv_ack);
5961 /*
5962 * The function(s) which did not ack in time are forced
5963 * to withdraw any further participation in the IDC
5964 * reset.
5965 */
5966 if (drv_ack != drv_presence)
5967 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5968 drv_ack);
5969 break;
5970 }
5971
5972 qla83xx_idc_unlock(vha, 0);
5973 msleep(1000);
5974 qla83xx_idc_lock(vha, 0);
5975 }
5976
5977 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5978 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5979}
5980
Saurav Kashyapfa492632012-11-21 02:40:29 -05005981static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005982qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5983{
5984 int rval = QLA_SUCCESS;
5985 uint32_t idc_control;
5986
5987 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5988 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5989
5990 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5991 __qla83xx_get_idc_control(vha, &idc_control);
5992 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5993 __qla83xx_set_idc_control(vha, 0);
5994
5995 qla83xx_idc_unlock(vha, 0);
5996 rval = qla83xx_restart_nic_firmware(vha);
5997 qla83xx_idc_lock(vha, 0);
5998
5999 if (rval != QLA_SUCCESS) {
6000 ql_log(ql_log_fatal, vha, 0xb06a,
6001 "Failed to restart NIC f/w.\n");
6002 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
6003 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
6004 } else {
6005 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
6006 "Success in restarting nic f/w.\n");
6007 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
6008 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
6009 }
6010
6011 return rval;
6012}
6013
6014/* Assumes idc_lock always held on entry */
6015int
6016qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
6017{
6018 struct qla_hw_data *ha = base_vha->hw;
6019 int rval = QLA_SUCCESS;
6020 unsigned long dev_init_timeout;
6021 uint32_t dev_state;
6022
6023 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
6024 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
6025
6026 while (1) {
6027
6028 if (time_after_eq(jiffies, dev_init_timeout)) {
6029 ql_log(ql_log_warn, base_vha, 0xb06e,
6030 "Initialization TIMEOUT!\n");
6031 /* Init timeout. Disable further NIC Core
6032 * communication.
6033 */
6034 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
6035 QLA8XXX_DEV_FAILED);
6036 ql_log(ql_log_info, base_vha, 0xb06f,
6037 "HW State: FAILED.\n");
6038 }
6039
6040 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6041 switch (dev_state) {
6042 case QLA8XXX_DEV_READY:
6043 if (ha->flags.nic_core_reset_owner)
6044 qla83xx_idc_audit(base_vha,
6045 IDC_AUDIT_COMPLETION);
6046 ha->flags.nic_core_reset_owner = 0;
6047 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
6048 "Reset_owner reset by 0x%x.\n",
6049 ha->portnum);
6050 goto exit;
6051 case QLA8XXX_DEV_COLD:
6052 if (ha->flags.nic_core_reset_owner)
6053 rval = qla83xx_device_bootstrap(base_vha);
6054 else {
6055 /* Wait for AEN to change device-state */
6056 qla83xx_idc_unlock(base_vha, 0);
6057 msleep(1000);
6058 qla83xx_idc_lock(base_vha, 0);
6059 }
6060 break;
6061 case QLA8XXX_DEV_INITIALIZING:
6062 /* Wait for AEN to change device-state */
6063 qla83xx_idc_unlock(base_vha, 0);
6064 msleep(1000);
6065 qla83xx_idc_lock(base_vha, 0);
6066 break;
6067 case QLA8XXX_DEV_NEED_RESET:
6068 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
6069 qla83xx_need_reset_handler(base_vha);
6070 else {
6071 /* Wait for AEN to change device-state */
6072 qla83xx_idc_unlock(base_vha, 0);
6073 msleep(1000);
6074 qla83xx_idc_lock(base_vha, 0);
6075 }
6076 /* reset timeout value after need reset handler */
6077 dev_init_timeout = jiffies +
6078 (ha->fcoe_dev_init_timeout * HZ);
6079 break;
6080 case QLA8XXX_DEV_NEED_QUIESCENT:
6081 /* XXX: DEBUG for now */
6082 qla83xx_idc_unlock(base_vha, 0);
6083 msleep(1000);
6084 qla83xx_idc_lock(base_vha, 0);
6085 break;
6086 case QLA8XXX_DEV_QUIESCENT:
6087 /* XXX: DEBUG for now */
6088 if (ha->flags.quiesce_owner)
6089 goto exit;
6090
6091 qla83xx_idc_unlock(base_vha, 0);
6092 msleep(1000);
6093 qla83xx_idc_lock(base_vha, 0);
6094 dev_init_timeout = jiffies +
6095 (ha->fcoe_dev_init_timeout * HZ);
6096 break;
6097 case QLA8XXX_DEV_FAILED:
6098 if (ha->flags.nic_core_reset_owner)
6099 qla83xx_idc_audit(base_vha,
6100 IDC_AUDIT_COMPLETION);
6101 ha->flags.nic_core_reset_owner = 0;
6102 __qla83xx_clear_drv_presence(base_vha);
6103 qla83xx_idc_unlock(base_vha, 0);
6104 qla8xxx_dev_failed_handler(base_vha);
6105 rval = QLA_FUNCTION_FAILED;
6106 qla83xx_idc_lock(base_vha, 0);
6107 goto exit;
6108 case QLA8XXX_BAD_VALUE:
6109 qla83xx_idc_unlock(base_vha, 0);
6110 msleep(1000);
6111 qla83xx_idc_lock(base_vha, 0);
6112 break;
6113 default:
6114 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09006115 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006116 qla83xx_idc_unlock(base_vha, 0);
6117 qla8xxx_dev_failed_handler(base_vha);
6118 rval = QLA_FUNCTION_FAILED;
6119 qla83xx_idc_lock(base_vha, 0);
6120 goto exit;
6121 }
6122 }
6123
6124exit:
6125 return rval;
6126}
6127
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006128void
6129qla2x00_disable_board_on_pci_error(struct work_struct *work)
6130{
6131 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6132 board_disable);
6133 struct pci_dev *pdev = ha->pdev;
6134 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6135
Quinn Tran726b8542017-01-19 22:28:00 -08006136 /*
6137 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04006138 * where it was set first.
6139 */
6140 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6141 return;
6142
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006143 ql_log(ql_log_warn, base_vha, 0x015b,
6144 "Disabling adapter.\n");
6145
Sawan Chandakefdb5762017-08-23 15:05:00 -07006146 if (!atomic_read(&pdev->enable_cnt)) {
6147 ql_log(ql_log_info, base_vha, 0xfffc,
6148 "PCI device disabled, no action req for PCI error=%lx\n",
6149 base_vha->pci_flags);
6150 return;
6151 }
6152
Quinn Tran726b8542017-01-19 22:28:00 -08006153 qla2x00_wait_for_sess_deletion(base_vha);
6154
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006155 set_bit(UNLOADING, &base_vha->dpc_flags);
6156
6157 qla2x00_delete_all_vps(ha, base_vha);
6158
6159 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6160
6161 qla2x00_dfs_remove(base_vha);
6162
6163 qla84xx_put_chip(base_vha);
6164
6165 if (base_vha->timer_active)
6166 qla2x00_stop_timer(base_vha);
6167
6168 base_vha->flags.online = 0;
6169
6170 qla2x00_destroy_deferred_work(ha);
6171
6172 /*
6173 * Do not try to stop beacon blink as it will issue a mailbox
6174 * command.
6175 */
6176 qla2x00_free_sysfs_attr(base_vha, false);
6177
6178 fc_remove_host(base_vha->host);
6179
6180 scsi_remove_host(base_vha->host);
6181
6182 base_vha->flags.init_done = 0;
6183 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006184 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08006185 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006186 qla2x00_mem_free(ha);
6187 qla82xx_md_free(base_vha);
6188 qla2x00_free_queues(ha);
6189
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006190 qla2x00_unmap_iobases(ha);
6191
6192 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006193 pci_disable_pcie_error_reporting(pdev);
6194 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006195
Joe Lawrencebeb9e312014-08-26 17:12:14 -04006196 /*
6197 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6198 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006199}
6200
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201/**************************************************************************
6202* qla2x00_do_dpc
6203* This kernel thread is a task that is schedule by the interrupt handler
6204* to perform the background processing for interrupts.
6205*
6206* Notes:
6207* This task always run in the context of a kernel thread. It
6208* is kick-off by the driver's detect code and starts up
6209* up one per adapter. It immediately goes to sleep and waits for
6210* some fibre event. When either the interrupt handler or
6211* the timer routine detects a event it will one of the task
6212* bits then wake us up.
6213**************************************************************************/
6214static int
6215qla2x00_do_dpc(void *data)
6216{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006217 scsi_qla_host_t *base_vha;
6218 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08006219 uint32_t online;
6220 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08006221
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006222 ha = (struct qla_hw_data *)data;
6223 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006224
Dongsheng Yang8698a742014-03-11 18:09:12 +08006225 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226
James Bottomley563585e2011-01-27 16:12:37 -05006227 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01006228 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006229 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6230 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231
Christoph Hellwig39a11242006-02-14 18:46:22 +01006232 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006234 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6235 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236
Andrew Vasquez85880802009-12-15 21:29:46 -08006237 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006238 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6239 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006240 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08006241 }
6242
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 ha->dpc_active = 1;
6244
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04006245 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6246 "DPC handler waking up, dpc_flags=0x%lx.\n",
6247 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04006249 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6250 break;
6251
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006252 if (IS_P3P_TYPE(ha)) {
6253 if (IS_QLA8044(ha)) {
6254 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6255 &base_vha->dpc_flags)) {
6256 qla8044_idc_lock(ha);
6257 qla8044_wr_direct(base_vha,
6258 QLA8044_CRB_DEV_STATE_INDEX,
6259 QLA8XXX_DEV_FAILED);
6260 qla8044_idc_unlock(ha);
6261 ql_log(ql_log_info, base_vha, 0x4004,
6262 "HW State: FAILED.\n");
6263 qla8044_device_state_handler(base_vha);
6264 continue;
6265 }
6266
6267 } else {
6268 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6269 &base_vha->dpc_flags)) {
6270 qla82xx_idc_lock(ha);
6271 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6272 QLA8XXX_DEV_FAILED);
6273 qla82xx_idc_unlock(ha);
6274 ql_log(ql_log_info, base_vha, 0x0151,
6275 "HW State: FAILED.\n");
6276 qla82xx_device_state_handler(base_vha);
6277 continue;
6278 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006279 }
6280
6281 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6282 &base_vha->dpc_flags)) {
6283
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006284 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6285 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006286 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6287 &base_vha->dpc_flags))) {
6288 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6289 /* FCoE-ctx reset failed.
6290 * Escalate to chip-reset
6291 */
6292 set_bit(ISP_ABORT_NEEDED,
6293 &base_vha->dpc_flags);
6294 }
6295 clear_bit(ABORT_ISP_ACTIVE,
6296 &base_vha->dpc_flags);
6297 }
6298
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006299 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6300 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006301 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006302 } else if (IS_QLAFX00(ha)) {
6303 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6304 &base_vha->dpc_flags)) {
6305 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6306 "Firmware Reset Recovery\n");
6307 if (qlafx00_reset_initialize(base_vha)) {
6308 /* Failed. Abort isp later. */
6309 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006310 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006311 set_bit(ISP_UNRECOVERABLE,
6312 &base_vha->dpc_flags);
6313 ql_dbg(ql_dbg_dpc, base_vha,
6314 0x4021,
6315 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006316 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006317 }
6318 }
6319
6320 if (test_and_clear_bit(FX00_TARGET_SCAN,
6321 &base_vha->dpc_flags)) {
6322 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6323 "ISPFx00 Target Scan scheduled\n");
6324 if (qlafx00_rescan_isp(base_vha)) {
6325 if (!test_bit(UNLOADING,
6326 &base_vha->dpc_flags))
6327 set_bit(ISP_UNRECOVERABLE,
6328 &base_vha->dpc_flags);
6329 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6330 "ISPFx00 Target Scan Failed\n");
6331 }
6332 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6333 "ISPFx00 Target Scan End\n");
6334 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006335 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6336 &base_vha->dpc_flags)) {
6337 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6338 "ISPFx00 Host Info resend scheduled\n");
6339 qlafx00_fx_disc(base_vha,
6340 &base_vha->hw->mr.fcport,
6341 FXDISC_REG_HOST_INFO);
6342 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006343 }
6344
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006345 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6346 &base_vha->dpc_flags) &&
6347 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6348 qla24xx_detect_sfp(base_vha);
6349
6350 if (ha->flags.detected_lr_sfp !=
6351 ha->flags.using_lr_setting)
6352 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6353 }
6354
Quinn Tranb08abbd2018-07-18 14:29:54 -07006355 if (test_and_clear_bit
6356 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6357 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran93eca612018-08-31 11:24:37 -07006358 bool do_reset = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359
Quinn Tran0645cb82018-09-11 10:18:18 -07006360 switch (base_vha->qlini_mode) {
Quinn Tran93eca612018-08-31 11:24:37 -07006361 case QLA2XXX_INI_MODE_ENABLED:
6362 break;
6363 case QLA2XXX_INI_MODE_DISABLED:
Quinn Tran0645cb82018-09-11 10:18:18 -07006364 if (!qla_tgt_mode_enabled(base_vha) &&
6365 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006366 do_reset = false;
6367 break;
6368 case QLA2XXX_INI_MODE_DUAL:
Quinn Tran0645cb82018-09-11 10:18:18 -07006369 if (!qla_dual_mode_enabled(base_vha) &&
6370 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006371 do_reset = false;
6372 break;
6373 default:
6374 break;
6375 }
6376
6377 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006378 &base_vha->dpc_flags))) {
Quinn Tran93eca612018-08-31 11:24:37 -07006379 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6380 "ISP abort scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006381 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382 /* failed. retry later */
6383 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006384 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006386 clear_bit(ABORT_ISP_ACTIVE,
6387 &base_vha->dpc_flags);
Quinn Tran93eca612018-08-31 11:24:37 -07006388 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6389 "ISP abort end.\n");
Seokmann Ju99363ef2008-01-31 12:33:51 -08006390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 }
6392
David Jefferya394aac2012-11-21 02:39:54 -05006393 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6394 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006395 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006396 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006397
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006398 if (IS_QLAFX00(ha))
6399 goto loop_resync_check;
6400
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006401 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006402 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6403 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006404 if (IS_P3P_TYPE(ha)) {
6405 if (IS_QLA82XX(ha))
6406 qla82xx_device_state_handler(base_vha);
6407 if (IS_QLA8044(ha))
6408 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006409 clear_bit(ISP_QUIESCE_NEEDED,
6410 &base_vha->dpc_flags);
6411 if (!ha->flags.quiesce_owner) {
6412 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006413 if (IS_QLA82XX(ha)) {
6414 qla82xx_idc_lock(ha);
6415 qla82xx_clear_qsnt_ready(
6416 base_vha);
6417 qla82xx_idc_unlock(ha);
6418 } else if (IS_QLA8044(ha)) {
6419 qla8044_idc_lock(ha);
6420 qla8044_clear_qsnt_ready(
6421 base_vha);
6422 qla8044_idc_unlock(ha);
6423 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006424 }
6425 } else {
6426 clear_bit(ISP_QUIESCE_NEEDED,
6427 &base_vha->dpc_flags);
6428 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006429 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006430 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6431 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006432 }
6433
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006434 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006435 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006436 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006438 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6439 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006440 qla2x00_rst_aen(base_vha);
6441 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006442 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6443 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 }
6445
6446 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006447 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006448 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6449 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450
Quinn Tran4005a992017-12-04 14:45:06 -08006451 if (!base_vha->relogin_jif ||
6452 time_after_eq(jiffies, base_vha->relogin_jif)) {
6453 base_vha->relogin_jif = jiffies + HZ;
6454 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6455
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006456 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006457 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006458 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006461loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006462 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006463 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006465 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6466 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467
6468 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006469 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470
Bart Van Assche52c82822015-07-09 07:23:26 -07006471 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006473 clear_bit(LOOP_RESYNC_ACTIVE,
6474 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 }
6476
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006477 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6478 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479 }
6480
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006481 if (IS_QLAFX00(ha))
6482 goto intr_on_check;
6483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006484 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6485 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6486 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6487 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006488 }
6489
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006490intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006492 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006494 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006495 &base_vha->dpc_flags)) {
6496 if (ha->beacon_blink_led == 1)
6497 ha->isp_ops->beacon_blink(base_vha);
6498 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006499
Michael Hernandezd7459522016-12-12 14:40:07 -08006500 /* qpair online check */
6501 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6502 &base_vha->dpc_flags)) {
6503 if (ha->flags.eeh_busy ||
6504 ha->flags.pci_channel_io_perm_failure)
6505 online = 0;
6506 else
6507 online = 1;
6508
6509 mutex_lock(&ha->mq_lock);
6510 list_for_each_entry(qpair, &base_vha->qp_list,
6511 qp_list_elem)
6512 qpair->online = online;
6513 mutex_unlock(&ha->mq_lock);
6514 }
6515
Quinn Tran8b4673b2018-09-04 14:19:14 -07006516 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6517 &base_vha->dpc_flags)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006518 ql_log(ql_log_info, base_vha, 0xffffff,
6519 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6520 ha->nvme_last_rptd_aen);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006521 if (qla27xx_set_zio_threshold(base_vha,
6522 ha->nvme_last_rptd_aen)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006523 ql_log(ql_log_info, base_vha, 0xffffff,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006524 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6525 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006526 }
6527 }
6528
Quinn Tran8b4673b2018-09-04 14:19:14 -07006529 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6530 &base_vha->dpc_flags)) {
6531 ql_log(ql_log_info, base_vha, 0xffffff,
6532 "SET ZIO Activity exchange threshold to %d.\n",
6533 ha->last_zio_threshold);
6534 qla27xx_set_zio_threshold(base_vha,
6535 ha->last_zio_threshold);
6536 }
6537
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006538 if (!IS_QLAFX00(ha))
6539 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006540
Quinn Tran48acad02018-08-02 13:16:44 -07006541 if (test_and_clear_bit(N2N_LINK_RESET,
6542 &base_vha->dpc_flags)) {
6543 qla2x00_lip_reset(base_vha);
6544 }
6545
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006547end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006548 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006550 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006552 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6553 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554
6555 /*
6556 * Make sure that nobody tries to wake us up again.
6557 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558 ha->dpc_active = 0;
6559
Andrew Vasquezac280b62009-08-20 11:06:05 -07006560 /* Cleanup any residual CTX SRBs. */
6561 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6562
Christoph Hellwig39a11242006-02-14 18:46:22 +01006563 return 0;
6564}
6565
6566void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006567qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006568{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006569 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006570 struct task_struct *t = ha->dpc_thread;
6571
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006572 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006573 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574}
6575
6576/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577* qla2x00_rst_aen
6578* Processes asynchronous reset.
6579*
6580* Input:
6581* ha = adapter block pointer.
6582*/
6583static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006584qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006586 if (vha->flags.online && !vha->flags.reset_active &&
6587 !atomic_read(&vha->loop_down_timer) &&
6588 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006590 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591
6592 /*
6593 * Issue marker command only when we are going to start
6594 * the I/O.
6595 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006596 vha->marker_needed = 1;
6597 } while (!atomic_read(&vha->loop_down_timer) &&
6598 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 }
6600}
6601
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602/**************************************************************************
6603* qla2x00_timer
6604*
6605* Description:
6606* One second timer
6607*
6608* Context: Interrupt
6609***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006610void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006611qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006613 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615 int start_dpc = 0;
6616 int index;
6617 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006618 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006619 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006620 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006621
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006622 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006623 ql_dbg(ql_dbg_timer, vha, 0x6000,
6624 "EEH = %d, restarting timer.\n",
6625 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006626 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6627 return;
6628 }
6629
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006630 /*
6631 * Hardware read to raise pending EEH errors during mailbox waits. If
6632 * the read returns -1 then disable the board.
6633 */
6634 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006635 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006636 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006639 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006640 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006641 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6642 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006643 if (IS_QLA82XX(ha))
6644 qla82xx_watchdog(vha);
6645 else if (IS_QLA8044(ha))
6646 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006647 }
6648
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006649 if (!vha->vp_idx && IS_QLAFX00(ha))
6650 qlafx00_timer_routine(vha);
6651
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006653 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006654 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6655 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006656 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006658 if (atomic_read(&vha->loop_down_timer) ==
6659 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006661 ql_log(ql_log_info, vha, 0x6008,
6662 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006664 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6665 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006667 /*
6668 * Schedule an ISP abort to return any FCP2-device
6669 * commands.
6670 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006671 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006672 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006673 spin_lock_irqsave(&ha->hardware_lock,
6674 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006675 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006676 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006677 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006678 index++) {
6679 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006680
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006681 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006682 if (!sp)
6683 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006684 if (sp->cmd_type != TYPE_SRB)
6685 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006686 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006687 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006688 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006689 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006690 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006692 if (IS_QLA82XX(ha))
6693 set_bit(FCOE_CTX_RESET_NEEDED,
6694 &vha->dpc_flags);
6695 else
6696 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006697 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006698 break;
6699 }
6700 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006701 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703 start_dpc++;
6704 }
6705
6706 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006707 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006708 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006709 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710 "Loop down - aborting ISP.\n");
6711
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006712 if (IS_QLA82XX(ha))
6713 set_bit(FCOE_CTX_RESET_NEEDED,
6714 &vha->dpc_flags);
6715 else
6716 set_bit(ISP_ABORT_NEEDED,
6717 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 }
6719 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006720 ql_dbg(ql_dbg_timer, vha, 0x600a,
6721 "Loop down - seconds remaining %d.\n",
6722 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006724 /* Check if beacon LED needs to be blinked for physical host only */
6725 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006726 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006727 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006728 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6729 start_dpc++;
6730 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006731 }
6732
Andrew Vasquez550bf572008-04-24 15:21:23 -07006733 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006734 if (!list_empty(&vha->work_list)) {
6735 unsigned long flags;
6736 bool q = false;
6737
6738 spin_lock_irqsave(&vha->work_lock, flags);
6739 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6740 q = true;
6741 spin_unlock_irqrestore(&vha->work_lock, flags);
6742 if (q)
6743 queue_work(vha->hw->wq, &vha->iocb_work);
6744 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006745
Duane Grigsby7401bc12017-06-21 13:48:42 -07006746 /*
6747 * FC-NVME
6748 * see if the active AEN count has changed from what was last reported.
6749 */
Quinn Tran8b4673b2018-09-04 14:19:14 -07006750 if (!vha->vp_idx && (atomic_read(&ha->nvme_active_aen_cnt) !=
6751 ha->nvme_last_rptd_aen) && ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006752 ql_log(ql_log_info, vha, 0x3002,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006753 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6754 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006755 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006756 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6757 start_dpc++;
6758 }
6759
6760 if (!vha->vp_idx &&
6761 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6762 (ha->zio_mode == QLA_ZIO_MODE_6) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006763 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
Quinn Tran8b4673b2018-09-04 14:19:14 -07006764 ql_log(ql_log_info, vha, 0x3002,
6765 "Sched: Set ZIO exchange threshold to %d.\n",
6766 ha->last_zio_threshold);
6767 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006768 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6769 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006770 }
6771
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006773 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6774 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6775 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006776 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006777 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6778 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006779 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6780 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006781 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006782 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006783 ql_dbg(ql_dbg_timer, vha, 0x600b,
6784 "isp_abort_needed=%d loop_resync_needed=%d "
6785 "fcport_update_needed=%d start_dpc=%d "
6786 "reset_marker_needed=%d",
6787 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6788 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6789 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6790 start_dpc,
6791 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6792 ql_dbg(ql_dbg_timer, vha, 0x600c,
6793 "beacon_blink_needed=%d isp_unrecoverable=%d "
6794 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006795 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006796 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6797 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6798 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6799 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006800 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006801 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006802 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006803
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006804 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006805}
6806
Andrew Vasquez54333832005-11-09 15:49:04 -08006807/* Firmware interface routines. */
6808
Andrew Vasquez54333832005-11-09 15:49:04 -08006809#define FW_ISP21XX 0
6810#define FW_ISP22XX 1
6811#define FW_ISP2300 2
6812#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006813#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006814#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006815#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006816#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006817#define FW_ISP2031 8
6818#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006819#define FW_ISP27XX 10
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006820#define FW_ISP28XX 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006821
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006822#define FW_FILE_ISP21XX "ql2100_fw.bin"
6823#define FW_FILE_ISP22XX "ql2200_fw.bin"
6824#define FW_FILE_ISP2300 "ql2300_fw.bin"
6825#define FW_FILE_ISP2322 "ql2322_fw.bin"
6826#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006827#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006828#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006829#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006830#define FW_FILE_ISP2031 "ql2600_fw.bin"
6831#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006832#define FW_FILE_ISP27XX "ql2700_fw.bin"
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006833#define FW_FILE_ISP28XX "ql2800_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006834
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006835
Daniel Walkere1e82b62008-05-12 22:21:10 -07006836static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006837
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006838static struct fw_blob qla_fw_blobs[] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006839 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6840 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6841 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6842 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6843 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006844 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006845 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006846 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006847 { .name = FW_FILE_ISP2031, },
6848 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006849 { .name = FW_FILE_ISP27XX, },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006850 { .name = FW_FILE_ISP28XX, },
6851 { .name = NULL, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006852};
6853
6854struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006855qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006856{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006857 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006858 struct fw_blob *blob;
6859
Andrew Vasquez54333832005-11-09 15:49:04 -08006860 if (IS_QLA2100(ha)) {
6861 blob = &qla_fw_blobs[FW_ISP21XX];
6862 } else if (IS_QLA2200(ha)) {
6863 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006864 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006865 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006866 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006867 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006868 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006869 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006870 } else if (IS_QLA25XX(ha)) {
6871 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006872 } else if (IS_QLA81XX(ha)) {
6873 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006874 } else if (IS_QLA82XX(ha)) {
6875 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006876 } else if (IS_QLA2031(ha)) {
6877 blob = &qla_fw_blobs[FW_ISP2031];
6878 } else if (IS_QLA8031(ha)) {
6879 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006880 } else if (IS_QLA27XX(ha)) {
6881 blob = &qla_fw_blobs[FW_ISP27XX];
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006882 } else if (IS_QLA28XX(ha)) {
6883 blob = &qla_fw_blobs[FW_ISP28XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006884 } else {
6885 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006886 }
6887
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006888 if (!blob->name)
6889 return NULL;
6890
Daniel Walkere1e82b62008-05-12 22:21:10 -07006891 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006892 if (blob->fw)
6893 goto out;
6894
6895 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006896 ql_log(ql_log_warn, vha, 0x0063,
6897 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006898 blob->fw = NULL;
6899 blob = NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006900 }
6901
6902out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006903 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006904 return blob;
6905}
6906
6907static void
6908qla2x00_release_firmware(void)
6909{
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006910 struct fw_blob *blob;
Andrew Vasquez54333832005-11-09 15:49:04 -08006911
Daniel Walkere1e82b62008-05-12 22:21:10 -07006912 mutex_lock(&qla_fw_lock);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006913 for (blob = qla_fw_blobs; blob->name; blob++)
6914 release_firmware(blob->fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006915 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006916}
6917
Seokmann Ju14e660e2007-09-20 14:07:36 -07006918static pci_ers_result_t
6919qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6920{
Andrew Vasquez85880802009-12-15 21:29:46 -08006921 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6922 struct qla_hw_data *ha = vha->hw;
6923
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006924 ql_dbg(ql_dbg_aer, vha, 0x9000,
6925 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006926
Sawan Chandakefdb5762017-08-23 15:05:00 -07006927 if (!atomic_read(&pdev->enable_cnt)) {
6928 ql_log(ql_log_info, vha, 0xffff,
6929 "PCI device is disabled,state %x\n", state);
6930 return PCI_ERS_RESULT_NEED_RESET;
6931 }
6932
Seokmann Ju14e660e2007-09-20 14:07:36 -07006933 switch (state) {
6934 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006935 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006936 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006937 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6938 qla2xxx_wake_dpc(vha);
6939 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006940 return PCI_ERS_RESULT_CAN_RECOVER;
6941 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006942 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006943 /* For ISP82XX complete any pending mailbox cmd */
6944 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006945 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006946 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6947 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006948 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006949 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006950 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006951 /* Return back all IOs */
6952 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006953 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006954 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6955 qla2xxx_wake_dpc(vha);
6956 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006957 return PCI_ERS_RESULT_NEED_RESET;
6958 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006959 ha->flags.pci_channel_io_perm_failure = 1;
6960 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006961 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006962 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6963 qla2xxx_wake_dpc(vha);
6964 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006965 return PCI_ERS_RESULT_DISCONNECT;
6966 }
6967 return PCI_ERS_RESULT_NEED_RESET;
6968}
6969
6970static pci_ers_result_t
6971qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6972{
6973 int risc_paused = 0;
6974 uint32_t stat;
6975 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006976 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6977 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006978 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6979 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6980
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006981 if (IS_QLA82XX(ha))
6982 return PCI_ERS_RESULT_RECOVERED;
6983
Seokmann Ju14e660e2007-09-20 14:07:36 -07006984 spin_lock_irqsave(&ha->hardware_lock, flags);
6985 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6986 stat = RD_REG_DWORD(&reg->hccr);
6987 if (stat & HCCR_RISC_PAUSE)
6988 risc_paused = 1;
6989 } else if (IS_QLA23XX(ha)) {
6990 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6991 if (stat & HSR_RISC_PAUSED)
6992 risc_paused = 1;
6993 } else if (IS_FWI2_CAPABLE(ha)) {
6994 stat = RD_REG_DWORD(&reg24->host_status);
6995 if (stat & HSRX_RISC_PAUSED)
6996 risc_paused = 1;
6997 }
6998 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6999
7000 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007001 ql_log(ql_log_info, base_vha, 0x9003,
7002 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007003 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007004
7005 return PCI_ERS_RESULT_NEED_RESET;
7006 } else
7007 return PCI_ERS_RESULT_RECOVERED;
7008}
7009
Saurav Kashyapfa492632012-11-21 02:40:29 -05007010static uint32_t
7011qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007012{
7013 uint32_t rval = QLA_FUNCTION_FAILED;
7014 uint32_t drv_active = 0;
7015 struct qla_hw_data *ha = base_vha->hw;
7016 int fn;
7017 struct pci_dev *other_pdev = NULL;
7018
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007019 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
7020 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007021
7022 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7023
7024 if (base_vha->flags.online) {
7025 /* Abort all outstanding commands,
7026 * so as to be requeued later */
7027 qla2x00_abort_isp_cleanup(base_vha);
7028 }
7029
7030
7031 fn = PCI_FUNC(ha->pdev->devfn);
7032 while (fn > 0) {
7033 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007034 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
7035 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007036 other_pdev =
7037 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
7038 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
7039 fn));
7040
7041 if (!other_pdev)
7042 continue;
7043 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007044 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
7045 "Found PCI func available and enable at 0x%x.\n",
7046 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007047 pci_dev_put(other_pdev);
7048 break;
7049 }
7050 pci_dev_put(other_pdev);
7051 }
7052
7053 if (!fn) {
7054 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007055 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
7056 "This devfn is reset owner = 0x%x.\n",
7057 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007058 qla82xx_idc_lock(ha);
7059
7060 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007061 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007062
7063 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
7064 QLA82XX_IDC_VERSION);
7065
7066 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007067 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
7068 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007069
7070 qla82xx_idc_unlock(ha);
7071 /* Reset if device is not already reset
7072 * drv_active would be 0 if a reset has already been done
7073 */
7074 if (drv_active)
7075 rval = qla82xx_start_firmware(base_vha);
7076 else
7077 rval = QLA_SUCCESS;
7078 qla82xx_idc_lock(ha);
7079
7080 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007081 ql_log(ql_log_info, base_vha, 0x900b,
7082 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007083 qla82xx_clear_drv_active(ha);
7084 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007085 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007086 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007087 ql_log(ql_log_info, base_vha, 0x900c,
7088 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007089 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007090 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007091 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08007092 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007093 rval = qla82xx_restart_isp(base_vha);
7094 qla82xx_idc_lock(ha);
7095 /* Clear driver state register */
7096 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
7097 qla82xx_set_drv_active(base_vha);
7098 }
7099 qla82xx_idc_unlock(ha);
7100 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007101 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
7102 "This devfn is not reset owner = 0x%x.\n",
7103 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007104 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007105 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08007106 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007107 rval = qla82xx_restart_isp(base_vha);
7108 qla82xx_idc_lock(ha);
7109 qla82xx_set_drv_active(base_vha);
7110 qla82xx_idc_unlock(ha);
7111 }
7112 }
7113 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7114
7115 return rval;
7116}
7117
Seokmann Ju14e660e2007-09-20 14:07:36 -07007118static pci_ers_result_t
7119qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7120{
7121 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007122 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7123 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007124 struct rsp_que *rsp;
7125 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007126
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007127 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
7128 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007129
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007130 /* Workaround: qla2xxx driver which access hardware earlier
7131 * needs error state to be pci_channel_io_online.
7132 * Otherwise mailbox command timesout.
7133 */
7134 pdev->error_state = pci_channel_io_normal;
7135
7136 pci_restore_state(pdev);
7137
Richard Lary8c1496b2010-02-18 10:07:29 -08007138 /* pci_restore_state() clears the saved_state flag of the device
7139 * save restored state which resets saved_state flag
7140 */
7141 pci_save_state(pdev);
7142
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11007143 if (ha->mem_only)
7144 rc = pci_enable_device_mem(pdev);
7145 else
7146 rc = pci_enable_device(pdev);
7147
7148 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007149 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007150 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007151 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007152 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007153
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007154 rsp = ha->rsp_q_map[0];
7155 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007156 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007157
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007158 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007159 goto exit_slot_reset;
7160
7161 if (IS_QLA82XX(ha)) {
7162 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
7163 ret = PCI_ERS_RESULT_RECOVERED;
7164 goto exit_slot_reset;
7165 } else
7166 goto exit_slot_reset;
7167 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007168
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007169 while (ha->flags.mbox_busy && retries--)
7170 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08007171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007172 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007173 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07007174 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007175 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007176
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007177
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007178exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007179 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7180 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08007181
Seokmann Ju14e660e2007-09-20 14:07:36 -07007182 return ret;
7183}
7184
7185static void
7186qla2xxx_pci_resume(struct pci_dev *pdev)
7187{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007188 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7189 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007190 int ret;
7191
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007192 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
7193 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007194
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007195 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007196 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007197 ql_log(ql_log_fatal, base_vha, 0x9002,
7198 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07007199 }
Andrew Vasquez85880802009-12-15 21:29:46 -08007200
7201 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007202}
7203
Quinn Tran590f8062019-01-24 23:23:40 -08007204static void
7205qla_pci_reset_prepare(struct pci_dev *pdev)
7206{
7207 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7208 struct qla_hw_data *ha = base_vha->hw;
7209 struct qla_qpair *qpair;
7210
7211 ql_log(ql_log_warn, base_vha, 0xffff,
7212 "%s.\n", __func__);
7213
7214 /*
7215 * PCI FLR/function reset is about to reset the
7216 * slot. Stop the chip to stop all DMA access.
7217 * It is assumed that pci_reset_done will be called
7218 * after FLR to resume Chip operation.
7219 */
7220 ha->flags.eeh_busy = 1;
7221 mutex_lock(&ha->mq_lock);
7222 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7223 qpair->online = 0;
7224 mutex_unlock(&ha->mq_lock);
7225
7226 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7227 qla2x00_abort_isp_cleanup(base_vha);
7228 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7229}
7230
7231static void
7232qla_pci_reset_done(struct pci_dev *pdev)
7233{
7234 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7235 struct qla_hw_data *ha = base_vha->hw;
7236 struct qla_qpair *qpair;
7237
7238 ql_log(ql_log_warn, base_vha, 0xffff,
7239 "%s.\n", __func__);
7240
7241 /*
7242 * FLR just completed by PCI layer. Resume adapter
7243 */
7244 ha->flags.eeh_busy = 0;
7245 mutex_lock(&ha->mq_lock);
7246 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7247 qpair->online = 1;
7248 mutex_unlock(&ha->mq_lock);
7249
7250 base_vha->flags.online = 1;
7251 ha->isp_ops->abort_isp(base_vha);
7252 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7253}
7254
Michael Hernandez56012362016-12-12 14:40:08 -08007255static int qla2xxx_map_queues(struct Scsi_Host *shost)
7256{
Quinn Trand68b8502017-12-04 14:44:59 -08007257 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007258 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
Dongli Zhang485b0ec2019-03-12 09:00:30 +08007259 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
Michael Hernandez56012362016-12-12 14:40:08 -08007260
Giridhar Malavalif3e02692019-02-15 16:42:55 -08007261 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
Jens Axboeed76e322018-10-29 13:06:14 -06007262 rc = blk_mq_map_queues(qmap);
Quinn Trand68b8502017-12-04 14:44:59 -08007263 else
Ming Leif0783d42019-01-11 09:40:47 -08007264 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
Quinn Trand68b8502017-12-04 14:44:59 -08007265 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007266}
7267
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07007268static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07007269 .error_detected = qla2xxx_pci_error_detected,
7270 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7271 .slot_reset = qla2xxx_pci_slot_reset,
7272 .resume = qla2xxx_pci_resume,
Quinn Tran590f8062019-01-24 23:23:40 -08007273 .reset_prepare = qla_pci_reset_prepare,
7274 .reset_done = qla_pci_reset_done,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007275};
7276
Andrew Vasquez54333832005-11-09 15:49:04 -08007277static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007278 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7279 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7280 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7281 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7282 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7283 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7284 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7285 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7286 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007287 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007288 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7289 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07007290 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007291 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007292 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07007293 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04007294 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04007295 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007296 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05007297 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04007298 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04007299 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07007300 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7301 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7302 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7303 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7304 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
Andrew Vasquez54333832005-11-09 15:49:04 -08007305 { 0 },
7306};
7307MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7308
Andrew Vasquezfca29702005-07-06 10:31:47 -07007309static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07007310 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06007311 .driver = {
7312 .owner = THIS_MODULE,
7313 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07007314 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007315 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08007316 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07007317 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007318 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07007319};
7320
Al Viro75ef9de2013-04-04 19:09:41 -04007321static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007322 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02007323 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007324};
7325
Linus Torvalds1da177e2005-04-16 15:20:36 -07007326/**
7327 * qla2x00_module_init - Module initialization.
7328 **/
7329static int __init
7330qla2x00_module_init(void)
7331{
Andrew Vasquezfca29702005-07-06 10:31:47 -07007332 int ret = 0;
7333
Linus Torvalds1da177e2005-04-16 15:20:36 -07007334 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007335 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09007336 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007337 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007338 ql_log(ql_log_fatal, NULL, 0x0001,
7339 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007340 return -ENOMEM;
7341 }
7342
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007343 /* Initialize target kmem_cache and mem_pools */
7344 ret = qlt_init();
7345 if (ret < 0) {
7346 kmem_cache_destroy(srb_cachep);
7347 return ret;
7348 } else if (ret > 0) {
7349 /*
7350 * If initiator mode is explictly disabled by qlt_init(),
7351 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7352 * performing scsi_scan_target() during LOOP UP event.
7353 */
7354 qla2xxx_transport_functions.disable_target_scan = 1;
7355 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7356 }
7357
Linus Torvalds1da177e2005-04-16 15:20:36 -07007358 /* Derive version string. */
7359 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07007360 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07007361 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07007362 if (ql2xextended_error_logging == 1)
7363 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07007364
Quinn Tran0645cb82018-09-11 10:18:18 -07007365 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7366 qla_insert_tgt_attrs();
7367
Andrew Vasquez1c97a122005-04-21 16:13:36 -04007368 qla2xxx_transport_template =
7369 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007370 if (!qla2xxx_transport_template) {
7371 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007372 ql_log(ql_log_fatal, NULL, 0x0002,
7373 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007374 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07007375 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007376 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007377
7378 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7379 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007380 ql_log(ql_log_fatal, NULL, 0x0003,
7381 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007382 }
7383
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007384 qla2xxx_transport_vport_template =
7385 fc_attach_transport(&qla2xxx_transport_vport_functions);
7386 if (!qla2xxx_transport_vport_template) {
7387 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007388 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007389 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007390 ql_log(ql_log_fatal, NULL, 0x0004,
7391 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007392 return -ENODEV;
7393 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007394 ql_log(ql_log_info, NULL, 0x0005,
7395 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07007396 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007397 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007398 if (ret) {
7399 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007400 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07007401 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007402 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007403 ql_log(ql_log_fatal, NULL, 0x0006,
7404 "pci_register_driver failed...ret=%d Failing load!.\n",
7405 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007406 }
7407 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007408}
7409
7410/**
7411 * qla2x00_module_exit - Module cleanup.
7412 **/
7413static void __exit
7414qla2x00_module_exit(void)
7415{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007416 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007417 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08007418 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007419 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007420 qlt_exit();
Thomas Meyer75c1d482018-12-02 21:52:11 +01007421 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007422 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007423 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007424}
7425
7426module_init(qla2x00_module_init);
7427module_exit(qla2x00_module_exit);
7428
7429MODULE_AUTHOR("QLogic Corporation");
7430MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7431MODULE_LICENSE("GPL");
7432MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07007433MODULE_FIRMWARE(FW_FILE_ISP21XX);
7434MODULE_FIRMWARE(FW_FILE_ISP22XX);
7435MODULE_FIRMWARE(FW_FILE_ISP2300);
7436MODULE_FIRMWARE(FW_FILE_ISP2322);
7437MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08007438MODULE_FIRMWARE(FW_FILE_ISP25XX);