blob: 35f62f171b208d31e9ef7d86529d7a40d8734248 [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
Bart Van Assche58e27532019-04-11 14:53:19 -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
Bart Van Assche58e27532019-04-11 14:53:19 -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
Bart Van Asscheb3ede8e2019-04-04 12:44:42 -0700288static int ql2xprotmask;
Martin K. Petersen7855d2b2018-12-21 09:33:44 -0800289module_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
Bart Van Asscheb3ede8e2019-04-04 12:44:42 -0700295static int ql2xprotguard;
Martin K. Petersen7855d2b2018-12-21 09:33:44 -0800296module_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
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400309static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400310static void qla2x00_free_device(scsi_qla_host_t *);
Michael Hernandez56012362016-12-12 14:40:08 -0800311static int qla2xxx_map_queues(struct Scsi_Host *shost);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700312static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700313
Quinn Tran45235022018-07-18 14:29:53 -0700314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700316struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318/* TODO Convert to inlines
319 *
320 * Timer routines
321 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700323__inline__ void
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700324qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700326 timer_setup(&vha->timer, qla2x00_timer, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800327 vha->timer.expires = jiffies + interval * HZ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800328 add_timer(&vha->timer);
329 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
332static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800333qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700335 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700336 if (vha->device_flags & DFLG_DEV_FAILED) {
337 ql_dbg(ql_dbg_timer, vha, 0x600d,
338 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700339 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700340 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700341
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800342 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
Adrian Bunka824ebb2008-01-17 09:02:15 -0800345static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800346qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800348 del_timer_sync(&vha->timer);
349 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352static int qla2x00_do_dpc(void *data);
353
354static void qla2x00_rst_aen(scsi_qla_host_t *);
355
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800356static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
357 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700358static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800359static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800360int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
361 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700364static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
365 struct rsp_que *rsp)
366{
367 struct qla_hw_data *ha = vha->hw;
Bart Van Asschebd432bb2019-04-11 14:53:17 -0700368
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700369 rsp->qpair = ha->base_qpair;
370 rsp->req = req;
Quinn Tran06910942018-09-04 14:19:12 -0700371 ha->base_qpair->hw = ha;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700372 ha->base_qpair->req = req;
373 ha->base_qpair->rsp = rsp;
374 ha->base_qpair->vha = vha;
375 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
376 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
377 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
Quinn Tran6a629462018-09-04 14:19:15 -0700378 ha->base_qpair->srb_mempool = ha->srb_mempool;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700379 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
380 ha->base_qpair->enable_class_2 = ql2xenableclass2;
381 /* init qpair to this cpu. Will adjust at run time. */
Bart Van Assche86531882017-11-06 11:59:05 -0800382 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700383 ha->base_qpair->pdev = ha->pdev;
384
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700385 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700386 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
387}
388
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400389static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
390 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800391{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700392 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Bart Van Asschebd432bb2019-04-11 14:53:17 -0700393
Kees Cook6396bb22018-06-12 14:03:40 -0700394 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800395 GFP_KERNEL);
396 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700397 ql_log(ql_log_fatal, vha, 0x003b,
398 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800399 goto fail_req_map;
400 }
401
Kees Cook6396bb22018-06-12 14:03:40 -0700402 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800403 GFP_KERNEL);
404 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700405 ql_log(ql_log_fatal, vha, 0x003c,
406 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800407 goto fail_rsp_map;
408 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800409
Quinn Trane326d222017-06-13 20:47:18 -0700410 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
411 if (ha->base_qpair == NULL) {
412 ql_log(ql_log_warn, vha, 0x00e0,
413 "Failed to allocate base queue pair memory.\n");
414 goto fail_base_qpair;
415 }
416
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700417 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700418
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -0700419 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -0800420 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
421 GFP_KERNEL);
422 if (!ha->queue_pair_map) {
423 ql_log(ql_log_fatal, vha, 0x0180,
424 "Unable to allocate memory for queue pair ptrs.\n");
425 goto fail_qpair_map;
426 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800427 }
428
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400429 /*
430 * Make sure we record at least the request and response queue zero in
431 * case we need to free them if part of the probe fails.
432 */
433 ha->rsp_q_map[0] = rsp;
434 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800435 set_bit(0, ha->rsp_qid_map);
436 set_bit(0, ha->req_qid_map);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -0500437 return 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800438
Michael Hernandezd7459522016-12-12 14:40:07 -0800439fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700440 kfree(ha->base_qpair);
441 ha->base_qpair = NULL;
442fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800443 kfree(ha->rsp_q_map);
444 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800445fail_rsp_map:
446 kfree(ha->req_q_map);
447 ha->req_q_map = NULL;
448fail_req_map:
449 return -ENOMEM;
450}
451
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700452static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800453{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400454 if (IS_QLAFX00(ha)) {
455 if (req && req->ring_fx00)
456 dma_free_coherent(&ha->pdev->dev,
457 (req->length_fx00 + 1) * sizeof(request_t),
458 req->ring_fx00, req->dma_fx00);
459 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800460 dma_free_coherent(&ha->pdev->dev,
461 (req->length + 1) * sizeof(request_t),
462 req->ring, req->dma);
463
Bill Kuzeja6d634062018-03-23 10:37:25 -0400464 if (req)
Chad Dupuis8d93f552013-01-30 03:34:37 -0500465 kfree(req->outstanding_cmds);
Bill Kuzeja6d634062018-03-23 10:37:25 -0400466
467 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800468}
469
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700470static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
471{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400472 if (IS_QLAFX00(ha)) {
Meelis Roos3f6c9be2018-03-08 15:44:37 +0200473 if (rsp && rsp->ring_fx00)
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400474 dma_free_coherent(&ha->pdev->dev,
475 (rsp->length_fx00 + 1) * sizeof(request_t),
476 rsp->ring_fx00, rsp->dma_fx00);
477 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700478 dma_free_coherent(&ha->pdev->dev,
479 (rsp->length + 1) * sizeof(response_t),
480 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400481 }
Bill Kuzeja6d634062018-03-23 10:37:25 -0400482 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700483}
484
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800485static void qla2x00_free_queues(struct qla_hw_data *ha)
486{
487 struct req_que *req;
488 struct rsp_que *rsp;
489 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800490 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800491
Quinn Tran82de8022017-06-13 20:47:17 -0700492 if (ha->queue_pair_map) {
493 kfree(ha->queue_pair_map);
494 ha->queue_pair_map = NULL;
495 }
496 if (ha->base_qpair) {
497 kfree(ha->base_qpair);
498 ha->base_qpair = NULL;
499 }
500
Quinn Tran093df732016-12-12 14:40:09 -0800501 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700502 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500503 if (!test_bit(cnt, ha->req_qid_map))
504 continue;
505
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800506 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800507 clear_bit(cnt, ha->req_qid_map);
508 ha->req_q_map[cnt] = NULL;
509
510 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700511 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800512 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700513 }
Quinn Tran093df732016-12-12 14:40:09 -0800514 spin_unlock_irqrestore(&ha->hardware_lock, flags);
515
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700516 kfree(ha->req_q_map);
517 ha->req_q_map = NULL;
518
Quinn Tran093df732016-12-12 14:40:09 -0800519
520 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700521 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500522 if (!test_bit(cnt, ha->rsp_qid_map))
523 continue;
524
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700525 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c4239462016-12-27 13:13:21 -0500526 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800527 ha->rsp_q_map[cnt] = NULL;
528 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700529 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800530 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800531 }
Quinn Tran093df732016-12-12 14:40:09 -0800532 spin_unlock_irqrestore(&ha->hardware_lock, flags);
533
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800534 kfree(ha->rsp_q_map);
535 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800536}
537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800539qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800541 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 static char *pci_bus_modes[] = {
543 "33", "66", "100", "133",
544 };
545 uint16_t pci_bus;
546
547 strcpy(str, "PCI");
548 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
549 if (pci_bus) {
550 strcat(str, "-X (");
551 strcat(str, pci_bus_modes[pci_bus]);
552 } else {
553 pci_bus = (ha->pci_attr & BIT_8) >> 8;
554 strcat(str, " (");
555 strcat(str, pci_bus_modes[pci_bus]);
556 }
557 strcat(str, " MHz)");
558
559 return (str);
560}
561
Andrew Vasquezfca29702005-07-06 10:31:47 -0700562static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700564{
565 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800566 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700567 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700568
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600569 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700570 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600571 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700572
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600573 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
574 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
575 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700576
577 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500578 switch (lspeed) {
579 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700580 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500581 break;
582 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700583 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500584 break;
585 case 3:
586 strcat(str, "8.0GT/s ");
587 break;
588 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700589 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500590 break;
591 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700592 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
593 strcat(str, lwstr);
594
595 return str;
596 }
597
598 strcpy(str, "PCI");
599 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
600 if (pci_bus == 0 || pci_bus == 8) {
601 strcat(str, " (");
602 strcat(str, pci_bus_modes[pci_bus >> 3]);
603 } else {
604 strcat(str, "-X ");
605 if (pci_bus & BIT_2)
606 strcat(str, "Mode 2");
607 else
608 strcat(str, "Mode 1");
609 strcat(str, " (");
610 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
611 }
612 strcat(str, " MHz)");
613
614 return str;
615}
616
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800617static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400618qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
620 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800621 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700622
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400623 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
624 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 if (ha->fw_attributes & BIT_9) {
627 strcat(str, "FLX");
628 return (str);
629 }
630
631 switch (ha->fw_attributes & 0xFF) {
632 case 0x7:
633 strcat(str, "EF");
634 break;
635 case 0x17:
636 strcat(str, "TP");
637 break;
638 case 0x37:
639 strcat(str, "IP");
640 break;
641 case 0x77:
642 strcat(str, "VI");
643 break;
644 default:
645 sprintf(un_str, "(%x)", ha->fw_attributes);
646 strcat(str, un_str);
647 break;
648 }
649 if (ha->fw_attributes & 0x100)
650 strcat(str, "X");
651
652 return (str);
653}
654
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800655static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400656qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700657{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800658 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700659
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400660 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800661 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700662 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700663}
664
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800665void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800666qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700667{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800668 srb_t *sp = ptr;
669 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800670 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800671 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700672
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800673 if (sp->flags & SRB_DMA_VALID) {
674 scsi_dma_unmap(cmd);
675 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700676 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700677
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800678 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
679 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
680 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
681 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
682 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700683
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700684 if (!ctx)
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700685 return;
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700686
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800687 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
688 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700689 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800690 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
691 }
692
693 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700694 struct crc_context *ctx0 = ctx;
695
696 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800697 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
698 }
699
700 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700701 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800702
703 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700704 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800705 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
706 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
707 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
708 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800709 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800710}
711
Michael Hernandezd7459522016-12-12 14:40:07 -0800712void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800713qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800714{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800715 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800716 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Bart Van Assche219d27d2019-04-17 14:44:35 -0700717 struct completion *comp = sp->comp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800718
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800719 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800720 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800721 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
722 sp, GET_CMD_SP(sp));
723 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400724 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800725 return;
726 }
Bart Van Assche219d27d2019-04-17 14:44:35 -0700727
728 atomic_dec(&sp->ref_count);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800729
Joe Carnucciof3caa992017-08-23 15:05:09 -0700730 sp->free(sp);
Giridhar Malavali740e2932019-04-02 14:24:20 -0700731 cmd->result = res;
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700732 CMD_SP(cmd) = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800733 cmd->scsi_done(cmd);
Bart Van Assche219d27d2019-04-17 14:44:35 -0700734 if (comp)
735 complete(comp);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700736 qla2x00_rel_sp(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700737}
738
Michael Hernandezd7459522016-12-12 14:40:07 -0800739void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800740qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800741{
742 srb_t *sp = (srb_t *)ptr;
743 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
744 struct qla_hw_data *ha = sp->fcport->vha->hw;
745 void *ctx = GET_CMD_CTX_SP(sp);
746
747 if (sp->flags & SRB_DMA_VALID) {
748 scsi_dma_unmap(cmd);
749 sp->flags &= ~SRB_DMA_VALID;
750 }
751
752 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
753 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
754 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
755 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
756 }
757
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700758 if (!ctx)
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700759 return;
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700760
Michael Hernandezd7459522016-12-12 14:40:07 -0800761 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
762 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700763 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800764 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
765 }
766
Giridhar Malavali50b81272018-12-21 09:33:45 -0800767 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
Bart Van Assched8f945b2019-04-17 14:44:25 -0700768 struct crc_context *difctx = ctx;
Giridhar Malavali50b81272018-12-21 09:33:45 -0800769 struct dsd_dma *dif_dsd, *nxt_dsd;
770
771 list_for_each_entry_safe(dif_dsd, nxt_dsd,
772 &difctx->ldif_dma_hndl_list, list) {
773 list_del(&dif_dsd->list);
774 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
775 dif_dsd->dsd_list_dma);
776 kfree(dif_dsd);
777 difctx->no_dif_bundl--;
778 }
779
780 list_for_each_entry_safe(dif_dsd, nxt_dsd,
781 &difctx->ldif_dsd_list, list) {
782 list_del(&dif_dsd->list);
783 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
784 dif_dsd->dsd_list_dma);
785 kfree(dif_dsd);
786 difctx->no_ldif_dsd--;
787 }
788
789 if (difctx->no_ldif_dsd) {
790 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
791 "%s: difctx->no_ldif_dsd=%x\n",
792 __func__, difctx->no_ldif_dsd);
793 }
794
795 if (difctx->no_dif_bundl) {
796 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
797 "%s: difctx->no_dif_bundl=%x\n",
798 __func__, difctx->no_dif_bundl);
799 }
800 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
801 }
Bart Van Assched8f945b2019-04-17 14:44:25 -0700802
803 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
804 struct ct6_dsd *ctx1 = ctx;
805
806 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
807 ctx1->fcp_cmnd_dma);
808 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
809 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
810 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
811 mempool_free(ctx1, ha->ctx_mempool);
812 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
813 }
814
815 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
816 struct crc_context *ctx0 = ctx;
817
818 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
819 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
820 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800821}
822
823void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800824qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800825{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800826 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800827 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Bart Van Assche219d27d2019-04-17 14:44:35 -0700828 struct completion *comp = sp->comp;
Michael Hernandezd7459522016-12-12 14:40:07 -0800829
830 if (atomic_read(&sp->ref_count) == 0) {
831 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
832 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
833 sp, GET_CMD_SP(sp));
834 if (ql2xextended_error_logging & ql_dbg_io)
835 WARN_ON(atomic_read(&sp->ref_count) == 0);
836 return;
837 }
Bart Van Assche219d27d2019-04-17 14:44:35 -0700838
839 atomic_dec(&sp->ref_count);
Michael Hernandezd7459522016-12-12 14:40:07 -0800840
Joe Carnucciof3caa992017-08-23 15:05:09 -0700841 sp->free(sp);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700842 cmd->result = res;
843 CMD_SP(cmd) = NULL;
Michael Hernandezd7459522016-12-12 14:40:07 -0800844 cmd->scsi_done(cmd);
Bart Van Assche219d27d2019-04-17 14:44:35 -0700845 if (comp)
846 complete(comp);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700847 qla2xxx_rel_qpair_sp(sp->qpair, sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800848}
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800851qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700852{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700853 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700854 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400855 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800856 struct qla_hw_data *ha = vha->hw;
857 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700858 srb_t *sp;
859 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800860 struct qla_qpair *qpair = NULL;
861 uint32_t tag;
862 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700863
Bart Van Assche2dbb02f2019-04-17 14:44:19 -0700864 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
865 WARN_ON_ONCE(!rport)) {
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200866 cmd->result = DID_NO_CONNECT << 16;
867 goto qc24_fail_command;
868 }
869
Michael Hernandez56012362016-12-12 14:40:08 -0800870 if (ha->mqenable) {
Jens Axboef664a3c2018-11-01 16:36:27 -0600871 tag = blk_mq_unique_tag(cmd->request);
872 hwq = blk_mq_unique_tag_to_hwq(tag);
873 qpair = ha->queue_pair_map[hwq];
Michael Hernandez56012362016-12-12 14:40:08 -0800874
875 if (qpair)
876 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800877 }
878
Andrew Vasquez85880802009-12-15 21:29:46 -0800879 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700880 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400881 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700882 "PCI Channel IO permanent failure, exiting "
883 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700884 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700885 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400886 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700887 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800888 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700889 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700890 goto qc24_fail_command;
891 }
892
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400893 rval = fc_remote_port_chkready(rport);
894 if (rval) {
895 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400896 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700897 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
898 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700899 goto qc24_fail_command;
900 }
901
Arun Easibad75002010-05-04 15:01:30 -0700902 if (!vha->flags.difdix_supported &&
903 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700904 ql_dbg(ql_dbg_io, vha, 0x3004,
905 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
906 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700907 cmd->result = DID_NO_CONNECT << 16;
908 goto qc24_fail_command;
909 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800910
911 if (!fcport) {
912 cmd->result = DID_NO_CONNECT << 16;
913 goto qc24_fail_command;
914 }
915
Andrew Vasquezfca29702005-07-06 10:31:47 -0700916 if (atomic_read(&fcport->state) != FCS_ONLINE) {
917 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700918 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700919 ql_dbg(ql_dbg_io, vha, 0x3005,
920 "Returning DNC, fcport_state=%d loop_state=%d.\n",
921 atomic_read(&fcport->state),
922 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700923 cmd->result = DID_NO_CONNECT << 16;
924 goto qc24_fail_command;
925 }
Mike Christie7b594132008-08-17 15:24:40 -0500926 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700927 }
928
Chad Dupuise05fe292014-09-25 05:16:59 -0400929 /*
930 * Return target busy if we've received a non-zero retry_delay_timer
931 * in a FCP_RSP.
932 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100933 if (fcport->retry_delay_timestamp == 0) {
934 /* retry delay not set */
935 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400936 fcport->retry_delay_timestamp = 0;
937 else
938 goto qc24_target_busy;
939
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500940 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400941 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800942 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700943
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800944 sp->u.scmd.cmd = cmd;
945 sp->type = SRB_SCSI_CMD;
946 atomic_set(&sp->ref_count, 1);
947 CMD_SP(cmd) = (void *)sp;
948 sp->free = qla2x00_sp_free_dma;
949 sp->done = qla2x00_sp_compl;
950
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800951 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700952 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500953 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700954 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700955 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700956 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700957
Andrew Vasquezfca29702005-07-06 10:31:47 -0700958 return 0;
959
960qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700961 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700962
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800963qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700964 return SCSI_MLQUEUE_HOST_BUSY;
965
Mike Christie7b594132008-08-17 15:24:40 -0500966qc24_target_busy:
967 return SCSI_MLQUEUE_TARGET_BUSY;
968
Andrew Vasquezfca29702005-07-06 10:31:47 -0700969qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800970 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700971
972 return 0;
973}
974
Michael Hernandezd7459522016-12-12 14:40:07 -0800975/* For MQ supported I/O */
976int
977qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
978 struct qla_qpair *qpair)
979{
980 scsi_qla_host_t *vha = shost_priv(host);
981 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
982 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
983 struct qla_hw_data *ha = vha->hw;
984 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
985 srb_t *sp;
986 int rval;
987
Bart Van Assche2dbb02f2019-04-17 14:44:19 -0700988 rval = rport ? fc_remote_port_chkready(rport) : FC_PORTSTATE_OFFLINE;
Michael Hernandezd7459522016-12-12 14:40:07 -0800989 if (rval) {
990 cmd->result = rval;
991 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
992 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
993 cmd, rval);
994 goto qc24_fail_command;
995 }
996
997 if (!fcport) {
998 cmd->result = DID_NO_CONNECT << 16;
999 goto qc24_fail_command;
1000 }
1001
1002 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1003 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
1004 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1005 ql_dbg(ql_dbg_io, vha, 0x3077,
1006 "Returning DNC, fcport_state=%d loop_state=%d.\n",
1007 atomic_read(&fcport->state),
1008 atomic_read(&base_vha->loop_state));
1009 cmd->result = DID_NO_CONNECT << 16;
1010 goto qc24_fail_command;
1011 }
1012 goto qc24_target_busy;
1013 }
1014
1015 /*
1016 * Return target busy if we've received a non-zero retry_delay_timer
1017 * in a FCP_RSP.
1018 */
1019 if (fcport->retry_delay_timestamp == 0) {
1020 /* retry delay not set */
1021 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1022 fcport->retry_delay_timestamp = 0;
1023 else
1024 goto qc24_target_busy;
1025
Quinn Tran6a629462018-09-04 14:19:15 -07001026 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
Michael Hernandezd7459522016-12-12 14:40:07 -08001027 if (!sp)
1028 goto qc24_host_busy;
1029
1030 sp->u.scmd.cmd = cmd;
1031 sp->type = SRB_SCSI_CMD;
1032 atomic_set(&sp->ref_count, 1);
1033 CMD_SP(cmd) = (void *)sp;
1034 sp->free = qla2xxx_qpair_sp_free_dma;
1035 sp->done = qla2xxx_qpair_sp_compl;
1036 sp->qpair = qpair;
1037
1038 rval = ha->isp_ops->start_scsi_mq(sp);
1039 if (rval != QLA_SUCCESS) {
1040 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1041 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1042 if (rval == QLA_INTERFACE_ERROR)
1043 goto qc24_fail_command;
1044 goto qc24_host_busy_free_sp;
1045 }
1046
1047 return 0;
1048
1049qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001050 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001051
1052qc24_host_busy:
1053 return SCSI_MLQUEUE_HOST_BUSY;
1054
1055qc24_target_busy:
1056 return SCSI_MLQUEUE_TARGET_BUSY;
1057
1058qc24_fail_command:
1059 cmd->scsi_done(cmd);
1060
1061 return 0;
1062}
1063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064/*
1065 * qla2x00_eh_wait_on_command
1066 * Waits for the command to be returned by the Firmware for some
1067 * max time.
1068 *
1069 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 *
1072 * Return:
1073 * Not Found : 0
1074 * Found : 1
1075 */
1076static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001077qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001079#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001080#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001081 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001082 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1083 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001084 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Andrew Vasquez85880802009-12-15 21:29:46 -08001086 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001087 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1088 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001089 return ret;
1090 }
1091
Lalit Chandivaded9704322009-08-25 11:36:18 -07001092 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001093 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001094 }
1095 if (CMD_SP(cmd))
1096 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
f4f051e2005-04-17 15:02:26 -05001098 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
1101/*
1102 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001103 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 * <= MAX_RETRIES_OF_ISP_ABORT or
1105 * finally HBA is disabled ie marked offline
1106 *
1107 * Input:
1108 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001109 *
1110 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 * Does context switching-Release SPIN_LOCK
1112 * (if any) before calling this routine.
1113 *
1114 * Return:
1115 * Success (Adapter is online) : 0
1116 * Failed (Adapter is offline/disabled) : 1
1117 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001118int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001119qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001121 int return_status;
1122 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001123 struct qla_hw_data *ha = vha->hw;
1124 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001126 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001127 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1128 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1129 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1130 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 msleep(1000);
1133 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001134 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001135 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 else
1137 return_status = QLA_FUNCTION_FAILED;
1138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 return (return_status);
1140}
1141
Quinn Tran726b8542017-01-19 22:28:00 -08001142static inline int test_fcport_count(scsi_qla_host_t *vha)
1143{
1144 struct qla_hw_data *ha = vha->hw;
1145 unsigned long flags;
1146 int res;
1147
1148 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001149 ql_dbg(ql_dbg_init, vha, 0x00ec,
1150 "tgt %p, fcport_count=%d\n",
1151 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001152 res = (vha->fcport_count == 0);
1153 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1154
1155 return res;
1156}
1157
1158/*
1159 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1160 * it has dependency on UNLOADING flag to stop device discovery
1161 */
Quinn Tranefa93f42018-07-18 14:29:52 -07001162void
Quinn Tran726b8542017-01-19 22:28:00 -08001163qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1164{
1165 qla2x00_mark_all_devices_lost(vha, 0);
1166
Joe Carnucciob85e0952017-08-23 15:05:11 -07001167 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001168}
1169
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001170/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001171 * qla2x00_wait_for_hba_ready
1172 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001173 *
1174 * Input:
1175 * ha - pointer to host adapter structure
1176 *
1177 * Note:
1178 * Does context switching-Release SPIN_LOCK
1179 * (if any) before calling this routine.
1180 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001181 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001182static void
1183qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001184{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001185 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001186 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001187
Dan Carpenter1d483902016-08-03 21:42:32 +03001188 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1189 ha->flags.mbox_busy) ||
1190 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1191 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1192 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1193 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001194 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001195 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001196}
1197
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001198int
1199qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1200{
1201 int return_status;
1202 unsigned long wait_reset;
1203 struct qla_hw_data *ha = vha->hw;
1204 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1205
1206 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1207 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1208 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1209 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1210 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1211
1212 msleep(1000);
1213
1214 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1215 ha->flags.chip_reset_done)
1216 break;
1217 }
1218 if (ha->flags.chip_reset_done)
1219 return_status = QLA_SUCCESS;
1220 else
1221 return_status = QLA_FUNCTION_FAILED;
1222
1223 return return_status;
1224}
1225
Quinn Tran585def92018-09-04 14:19:20 -07001226static int
Giridhar Malavali083a4692010-05-28 15:08:18 -07001227sp_get(struct srb *sp)
1228{
Bart Van Assche845bbb02019-04-11 14:53:18 -07001229 if (!refcount_inc_not_zero((refcount_t *)&sp->ref_count))
Quinn Tran585def92018-09-04 14:19:20 -07001230 /* kref get fail */
1231 return ENXIO;
1232 else
1233 return 0;
Giridhar Malavali083a4692010-05-28 15:08:18 -07001234}
1235
Sawan Chandaka4655372016-07-06 11:14:32 -04001236#define ISP_REG_DISCONNECT 0xffffffffU
1237/**************************************************************************
1238* qla2x00_isp_reg_stat
1239*
1240* Description:
1241* Read the host status register of ISP before aborting the command.
1242*
1243* Input:
1244* ha = pointer to host adapter structure.
1245*
1246*
1247* Returns:
1248* Either true or false.
1249*
1250* Note: Return true if there is register disconnect.
1251**************************************************************************/
1252static inline
1253uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1254{
1255 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001256 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001257
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001258 if (IS_P3P_TYPE(ha))
1259 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1260 else
1261 return ((RD_REG_DWORD(&reg->host_status)) ==
1262 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001263}
1264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265/**************************************************************************
1266* qla2xxx_eh_abort
1267*
1268* Description:
1269* The abort function will abort the specified command.
1270*
1271* Input:
1272* cmd = Linux SCSI command packet to be aborted.
1273*
1274* Returns:
1275* Either SUCCESS or FAILED.
1276*
1277* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001278* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001280static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1282{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001283 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001284 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001285 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001286 unsigned int id;
1287 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001288 unsigned long flags;
Bart Van Assche219d27d2019-04-17 14:44:35 -07001289 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001290 struct qla_hw_data *ha = vha->hw;
Quinn Tran585def92018-09-04 14:19:20 -07001291 struct qla_qpair *qpair;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Sawan Chandaka4655372016-07-06 11:14:32 -04001293 if (qla2x00_isp_reg_stat(ha)) {
1294 ql_log(ql_log_info, vha, 0x8042,
1295 "PCI/Register disconnect, exiting.\n");
1296 return FAILED;
1297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001299 ret = fc_block_scsi_eh(cmd);
1300 if (ret != 0)
1301 return ret;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001302
Mike Christie170babc2010-10-15 11:27:47 -07001303 sp = (srb_t *) CMD_SP(cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001304 if (!sp)
1305 return SUCCESS;
1306
1307 qpair = sp->qpair;
1308 if (!qpair)
1309 return SUCCESS;
1310
1311 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
Bart Van Assche219d27d2019-04-17 14:44:35 -07001312 if (sp->type != SRB_SCSI_CMD || GET_CMD_SP(sp) != cmd) {
Quinn Tran585def92018-09-04 14:19:20 -07001313 /* there's a chance an interrupt could clear
1314 the ptr as part of done & free */
1315 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001316 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001317 }
Mike Christie170babc2010-10-15 11:27:47 -07001318
Quinn Tran585def92018-09-04 14:19:20 -07001319 if (sp_get(sp)){
1320 /* ref_count is already 0 */
1321 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1322 return SUCCESS;
1323 }
1324 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1325
1326 id = cmd->device->id;
1327 lun = cmd->device->lun;
1328
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001329 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001330 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1331 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001332
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001333 rval = ha->isp_ops->abort_command(sp);
Bart Van Assche219d27d2019-04-17 14:44:35 -07001334 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1335 "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001336
Bart Van Assche219d27d2019-04-17 14:44:35 -07001337 switch (rval) {
1338 case QLA_SUCCESS:
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001339 /*
Bart Van Assche219d27d2019-04-17 14:44:35 -07001340 * The command has been aborted. That means that the firmware
1341 * won't report a completion.
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001342 */
Bart Van Assche219d27d2019-04-17 14:44:35 -07001343 sp->done(sp, DID_ABORT << 16);
1344 ret = SUCCESS;
1345 break;
1346 default:
1347 /*
1348 * Either abort failed or abort and completion raced. Let
1349 * the SCSI core retry the abort in the former case.
1350 */
1351 ret = FAILED;
1352 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 }
Bart Van Assche219d27d2019-04-17 14:44:35 -07001354
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001355 ql_log(ql_log_info, vha, 0x801c,
Bart Van Assche219d27d2019-04-17 14:44:35 -07001356 "Abort command issued nexus=%ld:%d:%llu -- %x.\n",
1357 vha->host_no, id, lun, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
f4f051e2005-04-17 15:02:26 -05001359 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360}
1361
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001362int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001363qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001364 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001366 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001367 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001368 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001369 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001370 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001371 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
Andrew Vasquez523ec772008-04-03 13:13:24 -07001373 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001374
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001375 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001376 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001377 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001378 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001379 sp = req->outstanding_cmds[cnt];
1380 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001381 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001382 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001383 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001384 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001385 continue;
1386 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001387 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001388 switch (type) {
1389 case WAIT_HOST:
1390 match = 1;
1391 break;
1392 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001393 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001394 break;
1395 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001396 match = (cmd->device->id == t &&
1397 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001398 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001400 if (!match)
1401 continue;
1402
1403 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001404 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001405 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001407 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001408
1409 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
1411
Andrew Vasquez523ec772008-04-03 13:13:24 -07001412static char *reset_errors[] = {
1413 "HBA not online",
1414 "HBA not ready",
1415 "Task management failed",
1416 "Waiting for command completions",
1417};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Andrew Vasquez523ec772008-04-03 13:13:24 -07001419static int
1420__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001421 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001422{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001423 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001424 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1425 int err;
1426
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001427 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001428 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001429 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001430
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001431 err = fc_block_scsi_eh(cmd);
1432 if (err != 0)
1433 return err;
1434
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001435 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001436 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001437 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001438
1439 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001440 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1441 ql_log(ql_log_warn, vha, 0x800a,
1442 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001443 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001444 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001445 err = 2;
Himanshu Madhaniac444b42019-03-15 15:04:19 -07001446 if (do_reset(fcport, cmd->device->lun, 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001447 != QLA_SUCCESS) {
1448 ql_log(ql_log_warn, vha, 0x800c,
1449 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001450 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001451 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001452 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001453 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001454 cmd->device->lun, type) != QLA_SUCCESS) {
1455 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001456 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001457 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001458 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001459
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001460 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001461 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001462 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001463
1464 return SUCCESS;
1465
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001466eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001467 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001468 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001469 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1470 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001471 return FAILED;
1472}
1473
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001474static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1476{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001477 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1478 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Sawan Chandaka4655372016-07-06 11:14:32 -04001480 if (qla2x00_isp_reg_stat(ha)) {
1481 ql_log(ql_log_info, vha, 0x803e,
1482 "PCI/Register disconnect, exiting.\n");
1483 return FAILED;
1484 }
1485
Andrew Vasquez523ec772008-04-03 13:13:24 -07001486 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1487 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488}
1489
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001491qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001493 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1494 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Sawan Chandaka4655372016-07-06 11:14:32 -04001496 if (qla2x00_isp_reg_stat(ha)) {
1497 ql_log(ql_log_info, vha, 0x803f,
1498 "PCI/Register disconnect, exiting.\n");
1499 return FAILED;
1500 }
1501
Andrew Vasquez523ec772008-04-03 13:13:24 -07001502 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1503 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504}
1505
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506/**************************************************************************
1507* qla2xxx_eh_bus_reset
1508*
1509* Description:
1510* The bus reset function will reset the bus and abort any executing
1511* commands.
1512*
1513* Input:
1514* cmd = Linux SCSI command packet of the command that cause the
1515* bus reset.
1516*
1517* Returns:
1518* SUCCESS/FAILURE (defined as macro in scsi.h).
1519*
1520**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001521static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1523{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001524 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001525 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001526 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001527 unsigned int id;
1528 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001529 struct qla_hw_data *ha = vha->hw;
1530
1531 if (qla2x00_isp_reg_stat(ha)) {
1532 ql_log(ql_log_info, vha, 0x8040,
1533 "PCI/Register disconnect, exiting.\n");
1534 return FAILED;
1535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
f4f051e2005-04-17 15:02:26 -05001537 id = cmd->device->id;
1538 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001539
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001540 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001541 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001542 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001544 ret = fc_block_scsi_eh(cmd);
1545 if (ret != 0)
1546 return ret;
1547 ret = FAILED;
1548
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001549 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001550 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001552 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001553 ql_log(ql_log_fatal, vha, 0x8013,
1554 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001555 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 }
1557
Saurav Kashyapad5376892011-11-18 09:02:09 -08001558 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1559 ret = SUCCESS;
1560
f4f051e2005-04-17 15:02:26 -05001561 if (ret == FAILED)
1562 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001564 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001565 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001566 QLA_SUCCESS) {
1567 ql_log(ql_log_warn, vha, 0x8014,
1568 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001569 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001570 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
f4f051e2005-04-17 15:02:26 -05001572eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001573 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001574 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001575 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
f4f051e2005-04-17 15:02:26 -05001577 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
1580/**************************************************************************
1581* qla2xxx_eh_host_reset
1582*
1583* Description:
1584* The reset function will reset the Adapter.
1585*
1586* Input:
1587* cmd = Linux SCSI command packet of the command that cause the
1588* adapter reset.
1589*
1590* Returns:
1591* Either SUCCESS or FAILED.
1592*
1593* Note:
1594**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001595static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1597{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001598 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001599 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001600 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001601 unsigned int id;
1602 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001603 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Sawan Chandaka4655372016-07-06 11:14:32 -04001605 if (qla2x00_isp_reg_stat(ha)) {
1606 ql_log(ql_log_info, vha, 0x8041,
1607 "PCI/Register disconnect, exiting.\n");
1608 schedule_work(&ha->board_disable);
1609 return SUCCESS;
1610 }
1611
f4f051e2005-04-17 15:02:26 -05001612 id = cmd->device->id;
1613 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001614
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001615 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001616 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Chad Dupuis63ee7072014-04-11 16:54:46 -04001618 /*
1619 * No point in issuing another reset if one is active. Also do not
1620 * attempt a reset if we are updating flash.
1621 */
1622 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001623 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001625 if (vha != base_vha) {
1626 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001627 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001628 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001629 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001630 if (!qla82xx_fcoe_ctx_reset(vha)) {
1631 /* Ctx reset success */
1632 ret = SUCCESS;
1633 goto eh_host_reset_lock;
1634 }
1635 /* fall thru if ctx reset failed */
1636 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001637 if (ha->wq)
1638 flush_workqueue(ha->wq);
1639
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001640 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001641 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001642 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1643 /* failed. schedule dpc to try */
1644 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1645
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001646 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1647 ql_log(ql_log_warn, vha, 0x802a,
1648 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001650 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001651 }
1652 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001655 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001656 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001657 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001658 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
f4f051e2005-04-17 15:02:26 -05001660eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001661 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001662 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001663 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
f4f051e2005-04-17 15:02:26 -05001665 return ret;
1666}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668/*
1669* qla2x00_loop_reset
1670* Issue loop reset.
1671*
1672* Input:
1673* ha = adapter block pointer.
1674*
1675* Returns:
1676* 0 = success
1677*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001678int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001679qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001681 int ret;
bdf79622005-04-17 15:06:53 -05001682 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001683 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Armen Baloyan58547712013-08-27 01:37:33 -04001685 if (IS_QLAFX00(ha)) {
1686 return qlafx00_loop_reset(vha);
1687 }
1688
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001689 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001690 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1691 if (fcport->port_type != FCT_TARGET)
1692 continue;
1693
1694 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1695 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001696 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001697 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001698 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001699 }
1700 }
1701 }
1702
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001703
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001704 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001705 atomic_set(&vha->loop_state, LOOP_DOWN);
1706 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1707 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001708 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001709 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001710 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1711 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 }
1714
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001715 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001717 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001718 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1719 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001720 }
1721
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001723 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001725 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726}
1727
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001728static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1729 unsigned long *flags)
1730 __releases(qp->qp_lock_ptr)
1731 __acquires(qp->qp_lock_ptr)
1732{
Bart Van Assche219d27d2019-04-17 14:44:35 -07001733 DECLARE_COMPLETION_ONSTACK(comp);
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001734 scsi_qla_host_t *vha = qp->vha;
1735 struct qla_hw_data *ha = vha->hw;
Bart Van Assche219d27d2019-04-17 14:44:35 -07001736 int rval;
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001737
Bart Van Assche219d27d2019-04-17 14:44:35 -07001738 if (sp_get(sp))
1739 return;
Linus Torvalds938edb82018-12-28 14:48:06 -08001740
Bart Van Assche219d27d2019-04-17 14:44:35 -07001741 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1742 (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1743 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1744 !qla2x00_isp_reg_stat(ha))) {
1745 sp->comp = &comp;
1746 rval = ha->isp_ops->abort_command(sp);
1747 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1748
1749 switch (rval) {
1750 case QLA_SUCCESS:
1751 sp->done(sp, res);
1752 break;
1753 case QLA_FUNCTION_PARAMETER_ERROR:
1754 wait_for_completion(&comp);
1755 break;
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001756 }
Bart Van Assche219d27d2019-04-17 14:44:35 -07001757
1758 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1759 sp->comp = NULL;
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001760 }
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001761}
1762
Quinn Tranbbead492017-12-28 12:33:13 -08001763static void
1764__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001765{
Bart Van Asscheeb023222018-10-18 15:45:44 -07001766 int cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001767 unsigned long flags;
1768 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001769 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001770 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001771 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001772 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1773 struct qla_tgt_cmd *cmd;
Arun Easic0cb4492014-09-25 06:14:51 -04001774
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001775 if (!ha->req_q_map)
1776 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001777 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1778 req = qp->req;
1779 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1780 sp = req->outstanding_cmds[cnt];
1781 if (sp) {
1782 req->outstanding_cmds[cnt] = NULL;
Quinn Tran6b0431d2018-09-04 14:19:13 -07001783 switch (sp->cmd_type) {
1784 case TYPE_SRB:
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001785 qla2x00_abort_srb(qp, sp, res, &flags);
Quinn Tran585def92018-09-04 14:19:20 -07001786 break;
1787 case TYPE_TGT_CMD:
Quinn Tranbbead492017-12-28 12:33:13 -08001788 if (!vha->hw->tgt.tgt_ops || !tgt ||
1789 qla_ini_mode_enabled(vha)) {
Quinn Tran585def92018-09-04 14:19:20 -07001790 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1791 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1792 vha->dpc_flags);
Quinn Tranbbead492017-12-28 12:33:13 -08001793 continue;
1794 }
1795 cmd = (struct qla_tgt_cmd *)sp;
Bart Van Asscheaefed3e2019-04-17 14:44:29 -07001796 cmd->aborted = 1;
Quinn Tran585def92018-09-04 14:19:20 -07001797 break;
1798 case TYPE_TGT_TMCMD:
Bart Van Asscheaefed3e2019-04-17 14:44:29 -07001799 /* Skip task management functions. */
Quinn Tran585def92018-09-04 14:19:20 -07001800 break;
1801 default:
1802 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001803 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001804 }
1805 }
Quinn Tranbbead492017-12-28 12:33:13 -08001806 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1807}
1808
1809void
1810qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1811{
1812 int que;
1813 struct qla_hw_data *ha = vha->hw;
1814
1815 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1816
1817 for (que = 0; que < ha->max_qpairs; que++) {
1818 if (!ha->queue_pair_map[que])
1819 continue;
1820
1821 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1822 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001823}
1824
f4f051e2005-04-17 15:02:26 -05001825static int
1826qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
bdf79622005-04-17 15:06:53 -05001828 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001830 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001831 return -ENXIO;
1832
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001833 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001834
1835 return 0;
1836}
1837
1838static int
1839qla2xxx_slave_configure(struct scsi_device *sdev)
1840{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001841 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001842 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001843
Arun Easi9e522cd2012-08-22 14:21:31 -04001844 if (IS_T10_PI_CAPABLE(vha->hw))
1845 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1846
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001847 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001848 return 0;
1849}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
f4f051e2005-04-17 15:02:26 -05001851static void
1852qla2xxx_slave_destroy(struct scsi_device *sdev)
1853{
1854 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855}
1856
1857/**
1858 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1859 * @ha: HA context
1860 *
1861 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1862 * supported addressing method.
1863 */
1864static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001865qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001867 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Yang Hongyang6a355282009-04-06 19:01:13 -07001870 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001871 /* Any upper-dword bits set? */
1872 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001873 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001874 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001876 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1877 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001878 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001881
Yang Hongyang284901a2009-04-06 19:01:15 -07001882 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1883 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884}
1885
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001886static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001888{
1889 unsigned long flags = 0;
1890 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1891
1892 spin_lock_irqsave(&ha->hardware_lock, flags);
1893 ha->interrupts_on = 1;
1894 /* enable risc and host interrupts */
1895 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1896 RD_REG_WORD(&reg->ictrl);
1897 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1898
1899}
1900
1901static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001902qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001903{
1904 unsigned long flags = 0;
1905 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1906
1907 spin_lock_irqsave(&ha->hardware_lock, flags);
1908 ha->interrupts_on = 0;
1909 /* disable risc and host interrupts */
1910 WRT_REG_WORD(&reg->ictrl, 0);
1911 RD_REG_WORD(&reg->ictrl);
1912 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1913}
1914
1915static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001917{
1918 unsigned long flags = 0;
1919 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1920
1921 spin_lock_irqsave(&ha->hardware_lock, flags);
1922 ha->interrupts_on = 1;
1923 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1924 RD_REG_DWORD(&reg->ictrl);
1925 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1926}
1927
1928static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001930{
1931 unsigned long flags = 0;
1932 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1933
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001934 if (IS_NOPOLLING_TYPE(ha))
1935 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001936 spin_lock_irqsave(&ha->hardware_lock, flags);
1937 ha->interrupts_on = 0;
1938 WRT_REG_DWORD(&reg->ictrl, 0);
1939 RD_REG_DWORD(&reg->ictrl);
1940 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1941}
1942
Giridhar Malavali706f4572011-11-18 09:03:16 -08001943static int
1944qla2x00_iospace_config(struct qla_hw_data *ha)
1945{
1946 resource_size_t pio;
1947 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001948
Giridhar Malavali706f4572011-11-18 09:03:16 -08001949 if (pci_request_selected_regions(ha->pdev, ha->bars,
1950 QLA2XXX_DRIVER_NAME)) {
1951 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1952 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1953 pci_name(ha->pdev));
1954 goto iospace_error_exit;
1955 }
1956 if (!(ha->bars & 1))
1957 goto skip_pio;
1958
1959 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1960 pio = pci_resource_start(ha->pdev, 0);
1961 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1962 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1963 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1964 "Invalid pci I/O region size (%s).\n",
1965 pci_name(ha->pdev));
1966 pio = 0;
1967 }
1968 } else {
1969 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1970 "Region #0 no a PIO resource (%s).\n",
1971 pci_name(ha->pdev));
1972 pio = 0;
1973 }
1974 ha->pio_address = pio;
1975 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1976 "PIO address=%llu.\n",
1977 (unsigned long long)ha->pio_address);
1978
1979skip_pio:
1980 /* Use MMIO operations for all accesses. */
1981 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1982 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1983 "Region #1 not an MMIO resource (%s), aborting.\n",
1984 pci_name(ha->pdev));
1985 goto iospace_error_exit;
1986 }
1987 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1988 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1989 "Invalid PCI mem region size (%s), aborting.\n",
1990 pci_name(ha->pdev));
1991 goto iospace_error_exit;
1992 }
1993
1994 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1995 if (!ha->iobase) {
1996 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1997 "Cannot remap MMIO (%s), aborting.\n",
1998 pci_name(ha->pdev));
1999 goto iospace_error_exit;
2000 }
2001
2002 /* Determine queue resources */
2003 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002004 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002005 if (!ql2xmqsupport || !ql2xnvmeenable ||
2006 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08002007 goto mqiobase_exit;
2008
2009 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2010 pci_resource_len(ha->pdev, 3));
2011 if (ha->mqiobase) {
2012 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2013 "MQIO Base=%p.\n", ha->mqiobase);
2014 /* Read MSIX vector size of the board */
2015 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002016 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002017 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002018 /* MB interrupt uses 1 vector */
2019 ha->max_req_queues = ha->msix_count - 1;
2020 ha->max_rsp_queues = ha->max_req_queues;
2021 /* Queue pairs is the max value minus the base queue pair */
2022 ha->max_qpairs = ha->max_rsp_queues - 1;
2023 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2024 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2025
Giridhar Malavali706f4572011-11-18 09:03:16 -08002026 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002027 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002028 } else
2029 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2030 "BAR 3 not enabled.\n");
2031
2032mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002033 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002034 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002035 return (0);
2036
2037iospace_error_exit:
2038 return (-ENOMEM);
2039}
2040
2041
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002042static int
2043qla83xx_iospace_config(struct qla_hw_data *ha)
2044{
2045 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002046
2047 if (pci_request_selected_regions(ha->pdev, ha->bars,
2048 QLA2XXX_DRIVER_NAME)) {
2049 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2050 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2051 pci_name(ha->pdev));
2052
2053 goto iospace_error_exit;
2054 }
2055
2056 /* Use MMIO operations for all accesses. */
2057 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2058 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2059 "Invalid pci I/O region size (%s).\n",
2060 pci_name(ha->pdev));
2061 goto iospace_error_exit;
2062 }
2063 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2064 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2065 "Invalid PCI mem region size (%s), aborting\n",
2066 pci_name(ha->pdev));
2067 goto iospace_error_exit;
2068 }
2069
2070 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2071 if (!ha->iobase) {
2072 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2073 "Cannot remap MMIO (%s), aborting.\n",
2074 pci_name(ha->pdev));
2075 goto iospace_error_exit;
2076 }
2077
2078 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2079 /* 83XX 26XX always use MQ type access for queues
2080 * - mbar 2, a.k.a region 4 */
2081 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002082 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002083 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2084 pci_resource_len(ha->pdev, 4));
2085
2086 if (!ha->mqiobase) {
2087 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2088 "BAR2/region4 not enabled\n");
2089 goto mqiobase_exit;
2090 }
2091
2092 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2093 pci_resource_len(ha->pdev, 2));
2094 if (ha->msixbase) {
2095 /* Read MSIX vector size of the board */
2096 pci_read_config_word(ha->pdev,
2097 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002098 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002099 /*
2100 * By default, driver uses at least two msix vectors
2101 * (default & rspq)
2102 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002103 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002104 /* MB interrupt uses 1 vector */
2105 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002106
2107 /* ATIOQ needs 1 vector. That's 1 less QPair */
2108 if (QLA_TGT_MODE_ENABLED())
2109 ha->max_req_queues--;
2110
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002111 ha->max_rsp_queues = ha->max_req_queues;
2112
Michael Hernandezd7459522016-12-12 14:40:07 -08002113 /* Queue pairs is the max value minus
2114 * the base queue pair */
2115 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002116 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002117 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002118 }
2119 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002120 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002121 } else
2122 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2123 "BAR 1 not enabled.\n");
2124
2125mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002126 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002127 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002128 return 0;
2129
2130iospace_error_exit:
2131 return -ENOMEM;
2132}
2133
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002134static struct isp_operations qla2100_isp_ops = {
2135 .pci_config = qla2100_pci_config,
2136 .reset_chip = qla2x00_reset_chip,
2137 .chip_diag = qla2x00_chip_diag,
2138 .config_rings = qla2x00_config_rings,
2139 .reset_adapter = qla2x00_reset_adapter,
2140 .nvram_config = qla2x00_nvram_config,
2141 .update_fw_options = qla2x00_update_fw_options,
2142 .load_risc = qla2x00_load_risc,
2143 .pci_info_str = qla2x00_pci_info_str,
2144 .fw_version_str = qla2x00_fw_version_str,
2145 .intr_handler = qla2100_intr_handler,
2146 .enable_intrs = qla2x00_enable_intrs,
2147 .disable_intrs = qla2x00_disable_intrs,
2148 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002149 .target_reset = qla2x00_abort_target,
2150 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002151 .fabric_login = qla2x00_login_fabric,
2152 .fabric_logout = qla2x00_fabric_logout,
2153 .calc_req_entries = qla2x00_calc_iocbs_32,
2154 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2155 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2156 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2157 .read_nvram = qla2x00_read_nvram_data,
2158 .write_nvram = qla2x00_write_nvram_data,
2159 .fw_dump = qla2100_fw_dump,
2160 .beacon_on = NULL,
2161 .beacon_off = NULL,
2162 .beacon_blink = NULL,
2163 .read_optrom = qla2x00_read_optrom_data,
2164 .write_optrom = qla2x00_write_optrom_data,
2165 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002167 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002168 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002169 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002170 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002171};
2172
2173static struct isp_operations qla2300_isp_ops = {
2174 .pci_config = qla2300_pci_config,
2175 .reset_chip = qla2x00_reset_chip,
2176 .chip_diag = qla2x00_chip_diag,
2177 .config_rings = qla2x00_config_rings,
2178 .reset_adapter = qla2x00_reset_adapter,
2179 .nvram_config = qla2x00_nvram_config,
2180 .update_fw_options = qla2x00_update_fw_options,
2181 .load_risc = qla2x00_load_risc,
2182 .pci_info_str = qla2x00_pci_info_str,
2183 .fw_version_str = qla2x00_fw_version_str,
2184 .intr_handler = qla2300_intr_handler,
2185 .enable_intrs = qla2x00_enable_intrs,
2186 .disable_intrs = qla2x00_disable_intrs,
2187 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002188 .target_reset = qla2x00_abort_target,
2189 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002190 .fabric_login = qla2x00_login_fabric,
2191 .fabric_logout = qla2x00_fabric_logout,
2192 .calc_req_entries = qla2x00_calc_iocbs_32,
2193 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2194 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2195 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2196 .read_nvram = qla2x00_read_nvram_data,
2197 .write_nvram = qla2x00_write_nvram_data,
2198 .fw_dump = qla2300_fw_dump,
2199 .beacon_on = qla2x00_beacon_on,
2200 .beacon_off = qla2x00_beacon_off,
2201 .beacon_blink = qla2x00_beacon_blink,
2202 .read_optrom = qla2x00_read_optrom_data,
2203 .write_optrom = qla2x00_write_optrom_data,
2204 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002205 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002206 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002207 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002208 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002209 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002210};
2211
2212static struct isp_operations qla24xx_isp_ops = {
2213 .pci_config = qla24xx_pci_config,
2214 .reset_chip = qla24xx_reset_chip,
2215 .chip_diag = qla24xx_chip_diag,
2216 .config_rings = qla24xx_config_rings,
2217 .reset_adapter = qla24xx_reset_adapter,
2218 .nvram_config = qla24xx_nvram_config,
2219 .update_fw_options = qla24xx_update_fw_options,
2220 .load_risc = qla24xx_load_risc,
2221 .pci_info_str = qla24xx_pci_info_str,
2222 .fw_version_str = qla24xx_fw_version_str,
2223 .intr_handler = qla24xx_intr_handler,
2224 .enable_intrs = qla24xx_enable_intrs,
2225 .disable_intrs = qla24xx_disable_intrs,
2226 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002227 .target_reset = qla24xx_abort_target,
2228 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002229 .fabric_login = qla24xx_login_fabric,
2230 .fabric_logout = qla24xx_fabric_logout,
2231 .calc_req_entries = NULL,
2232 .build_iocbs = NULL,
2233 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2234 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2235 .read_nvram = qla24xx_read_nvram_data,
2236 .write_nvram = qla24xx_write_nvram_data,
2237 .fw_dump = qla24xx_fw_dump,
2238 .beacon_on = qla24xx_beacon_on,
2239 .beacon_off = qla24xx_beacon_off,
2240 .beacon_blink = qla24xx_beacon_blink,
2241 .read_optrom = qla24xx_read_optrom_data,
2242 .write_optrom = qla24xx_write_optrom_data,
2243 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002244 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002245 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002246 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002247 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002248 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002249};
2250
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002251static struct isp_operations qla25xx_isp_ops = {
2252 .pci_config = qla25xx_pci_config,
2253 .reset_chip = qla24xx_reset_chip,
2254 .chip_diag = qla24xx_chip_diag,
2255 .config_rings = qla24xx_config_rings,
2256 .reset_adapter = qla24xx_reset_adapter,
2257 .nvram_config = qla24xx_nvram_config,
2258 .update_fw_options = qla24xx_update_fw_options,
2259 .load_risc = qla24xx_load_risc,
2260 .pci_info_str = qla24xx_pci_info_str,
2261 .fw_version_str = qla24xx_fw_version_str,
2262 .intr_handler = qla24xx_intr_handler,
2263 .enable_intrs = qla24xx_enable_intrs,
2264 .disable_intrs = qla24xx_disable_intrs,
2265 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002266 .target_reset = qla24xx_abort_target,
2267 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002268 .fabric_login = qla24xx_login_fabric,
2269 .fabric_logout = qla24xx_fabric_logout,
2270 .calc_req_entries = NULL,
2271 .build_iocbs = NULL,
2272 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2273 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2274 .read_nvram = qla25xx_read_nvram_data,
2275 .write_nvram = qla25xx_write_nvram_data,
2276 .fw_dump = qla25xx_fw_dump,
2277 .beacon_on = qla24xx_beacon_on,
2278 .beacon_off = qla24xx_beacon_off,
2279 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002280 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002281 .write_optrom = qla24xx_write_optrom_data,
2282 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002283 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002284 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002285 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002286 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002287 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002288};
2289
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002290static struct isp_operations qla81xx_isp_ops = {
2291 .pci_config = qla25xx_pci_config,
2292 .reset_chip = qla24xx_reset_chip,
2293 .chip_diag = qla24xx_chip_diag,
2294 .config_rings = qla24xx_config_rings,
2295 .reset_adapter = qla24xx_reset_adapter,
2296 .nvram_config = qla81xx_nvram_config,
2297 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002298 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002299 .pci_info_str = qla24xx_pci_info_str,
2300 .fw_version_str = qla24xx_fw_version_str,
2301 .intr_handler = qla24xx_intr_handler,
2302 .enable_intrs = qla24xx_enable_intrs,
2303 .disable_intrs = qla24xx_disable_intrs,
2304 .abort_command = qla24xx_abort_command,
2305 .target_reset = qla24xx_abort_target,
2306 .lun_reset = qla24xx_lun_reset,
2307 .fabric_login = qla24xx_login_fabric,
2308 .fabric_logout = qla24xx_fabric_logout,
2309 .calc_req_entries = NULL,
2310 .build_iocbs = NULL,
2311 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2312 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002313 .read_nvram = NULL,
2314 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002315 .fw_dump = qla81xx_fw_dump,
2316 .beacon_on = qla24xx_beacon_on,
2317 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002318 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002319 .read_optrom = qla25xx_read_optrom_data,
2320 .write_optrom = qla24xx_write_optrom_data,
2321 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002322 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002323 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002324 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002325 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002326 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002327};
2328
2329static struct isp_operations qla82xx_isp_ops = {
2330 .pci_config = qla82xx_pci_config,
2331 .reset_chip = qla82xx_reset_chip,
2332 .chip_diag = qla24xx_chip_diag,
2333 .config_rings = qla82xx_config_rings,
2334 .reset_adapter = qla24xx_reset_adapter,
2335 .nvram_config = qla81xx_nvram_config,
2336 .update_fw_options = qla24xx_update_fw_options,
2337 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002338 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002339 .fw_version_str = qla24xx_fw_version_str,
2340 .intr_handler = qla82xx_intr_handler,
2341 .enable_intrs = qla82xx_enable_intrs,
2342 .disable_intrs = qla82xx_disable_intrs,
2343 .abort_command = qla24xx_abort_command,
2344 .target_reset = qla24xx_abort_target,
2345 .lun_reset = qla24xx_lun_reset,
2346 .fabric_login = qla24xx_login_fabric,
2347 .fabric_logout = qla24xx_fabric_logout,
2348 .calc_req_entries = NULL,
2349 .build_iocbs = NULL,
2350 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2351 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2352 .read_nvram = qla24xx_read_nvram_data,
2353 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002354 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002355 .beacon_on = qla82xx_beacon_on,
2356 .beacon_off = qla82xx_beacon_off,
2357 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002358 .read_optrom = qla82xx_read_optrom_data,
2359 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002360 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002361 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002362 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002363 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002364 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002365 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002366};
2367
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002368static struct isp_operations qla8044_isp_ops = {
2369 .pci_config = qla82xx_pci_config,
2370 .reset_chip = qla82xx_reset_chip,
2371 .chip_diag = qla24xx_chip_diag,
2372 .config_rings = qla82xx_config_rings,
2373 .reset_adapter = qla24xx_reset_adapter,
2374 .nvram_config = qla81xx_nvram_config,
2375 .update_fw_options = qla24xx_update_fw_options,
2376 .load_risc = qla82xx_load_risc,
2377 .pci_info_str = qla24xx_pci_info_str,
2378 .fw_version_str = qla24xx_fw_version_str,
2379 .intr_handler = qla8044_intr_handler,
2380 .enable_intrs = qla82xx_enable_intrs,
2381 .disable_intrs = qla82xx_disable_intrs,
2382 .abort_command = qla24xx_abort_command,
2383 .target_reset = qla24xx_abort_target,
2384 .lun_reset = qla24xx_lun_reset,
2385 .fabric_login = qla24xx_login_fabric,
2386 .fabric_logout = qla24xx_fabric_logout,
2387 .calc_req_entries = NULL,
2388 .build_iocbs = NULL,
2389 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2390 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2391 .read_nvram = NULL,
2392 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002393 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002394 .beacon_on = qla82xx_beacon_on,
2395 .beacon_off = qla82xx_beacon_off,
2396 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002397 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002398 .write_optrom = qla8044_write_optrom_data,
2399 .get_flash_version = qla82xx_get_flash_version,
2400 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002401 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002402 .abort_isp = qla8044_abort_isp,
2403 .iospace_config = qla82xx_iospace_config,
2404 .initialize_adapter = qla2x00_initialize_adapter,
2405};
2406
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002407static struct isp_operations qla83xx_isp_ops = {
2408 .pci_config = qla25xx_pci_config,
2409 .reset_chip = qla24xx_reset_chip,
2410 .chip_diag = qla24xx_chip_diag,
2411 .config_rings = qla24xx_config_rings,
2412 .reset_adapter = qla24xx_reset_adapter,
2413 .nvram_config = qla81xx_nvram_config,
2414 .update_fw_options = qla81xx_update_fw_options,
2415 .load_risc = qla81xx_load_risc,
2416 .pci_info_str = qla24xx_pci_info_str,
2417 .fw_version_str = qla24xx_fw_version_str,
2418 .intr_handler = qla24xx_intr_handler,
2419 .enable_intrs = qla24xx_enable_intrs,
2420 .disable_intrs = qla24xx_disable_intrs,
2421 .abort_command = qla24xx_abort_command,
2422 .target_reset = qla24xx_abort_target,
2423 .lun_reset = qla24xx_lun_reset,
2424 .fabric_login = qla24xx_login_fabric,
2425 .fabric_logout = qla24xx_fabric_logout,
2426 .calc_req_entries = NULL,
2427 .build_iocbs = NULL,
2428 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2429 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2430 .read_nvram = NULL,
2431 .write_nvram = NULL,
2432 .fw_dump = qla83xx_fw_dump,
2433 .beacon_on = qla24xx_beacon_on,
2434 .beacon_off = qla24xx_beacon_off,
2435 .beacon_blink = qla83xx_beacon_blink,
2436 .read_optrom = qla25xx_read_optrom_data,
2437 .write_optrom = qla24xx_write_optrom_data,
2438 .get_flash_version = qla24xx_get_flash_version,
2439 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002440 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002441 .abort_isp = qla2x00_abort_isp,
2442 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002443 .initialize_adapter = qla2x00_initialize_adapter,
2444};
2445
2446static struct isp_operations qlafx00_isp_ops = {
2447 .pci_config = qlafx00_pci_config,
2448 .reset_chip = qlafx00_soft_reset,
2449 .chip_diag = qlafx00_chip_diag,
2450 .config_rings = qlafx00_config_rings,
2451 .reset_adapter = qlafx00_soft_reset,
2452 .nvram_config = NULL,
2453 .update_fw_options = NULL,
2454 .load_risc = NULL,
2455 .pci_info_str = qlafx00_pci_info_str,
2456 .fw_version_str = qlafx00_fw_version_str,
2457 .intr_handler = qlafx00_intr_handler,
2458 .enable_intrs = qlafx00_enable_intrs,
2459 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002460 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002461 .target_reset = qlafx00_abort_target,
2462 .lun_reset = qlafx00_lun_reset,
2463 .fabric_login = NULL,
2464 .fabric_logout = NULL,
2465 .calc_req_entries = NULL,
2466 .build_iocbs = NULL,
2467 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2468 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2469 .read_nvram = qla24xx_read_nvram_data,
2470 .write_nvram = qla24xx_write_nvram_data,
2471 .fw_dump = NULL,
2472 .beacon_on = qla24xx_beacon_on,
2473 .beacon_off = qla24xx_beacon_off,
2474 .beacon_blink = NULL,
2475 .read_optrom = qla24xx_read_optrom_data,
2476 .write_optrom = qla24xx_write_optrom_data,
2477 .get_flash_version = qla24xx_get_flash_version,
2478 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002479 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002480 .abort_isp = qlafx00_abort_isp,
2481 .iospace_config = qlafx00_iospace_config,
2482 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002483};
2484
Chad Dupuisf73cb692014-02-26 04:15:06 -05002485static struct isp_operations qla27xx_isp_ops = {
2486 .pci_config = qla25xx_pci_config,
2487 .reset_chip = qla24xx_reset_chip,
2488 .chip_diag = qla24xx_chip_diag,
2489 .config_rings = qla24xx_config_rings,
2490 .reset_adapter = qla24xx_reset_adapter,
2491 .nvram_config = qla81xx_nvram_config,
2492 .update_fw_options = qla81xx_update_fw_options,
2493 .load_risc = qla81xx_load_risc,
2494 .pci_info_str = qla24xx_pci_info_str,
2495 .fw_version_str = qla24xx_fw_version_str,
2496 .intr_handler = qla24xx_intr_handler,
2497 .enable_intrs = qla24xx_enable_intrs,
2498 .disable_intrs = qla24xx_disable_intrs,
2499 .abort_command = qla24xx_abort_command,
2500 .target_reset = qla24xx_abort_target,
2501 .lun_reset = qla24xx_lun_reset,
2502 .fabric_login = qla24xx_login_fabric,
2503 .fabric_logout = qla24xx_fabric_logout,
2504 .calc_req_entries = NULL,
2505 .build_iocbs = NULL,
2506 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2507 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2508 .read_nvram = NULL,
2509 .write_nvram = NULL,
2510 .fw_dump = qla27xx_fwdump,
2511 .beacon_on = qla24xx_beacon_on,
2512 .beacon_off = qla24xx_beacon_off,
2513 .beacon_blink = qla83xx_beacon_blink,
2514 .read_optrom = qla25xx_read_optrom_data,
2515 .write_optrom = qla24xx_write_optrom_data,
2516 .get_flash_version = qla24xx_get_flash_version,
2517 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002518 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002519 .abort_isp = qla2x00_abort_isp,
2520 .iospace_config = qla83xx_iospace_config,
2521 .initialize_adapter = qla2x00_initialize_adapter,
2522};
2523
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002524static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002525qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002526{
2527 ha->device_type = DT_EXTENDED_IDS;
2528 switch (ha->pdev->device) {
2529 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002530 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002531 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002532 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002533 break;
2534 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002535 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002536 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002537 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002538 break;
2539 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002540 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002541 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002542 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002543 break;
2544 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002545 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002546 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002547 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002548 break;
2549 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002550 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002551 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002552 if (ha->pdev->subsystem_vendor == 0x1028 &&
2553 ha->pdev->subsystem_device == 0x0170)
2554 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002555 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002556 break;
2557 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002558 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002559 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002560 break;
2561 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002562 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002563 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002564 break;
2565 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002566 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002567 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002568 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002569 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002570 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002571 break;
2572 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002573 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002574 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002575 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002576 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002577 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002578 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002579 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002580 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002581 ha->device_type |= DT_ZIO_SUPPORTED;
2582 ha->device_type |= DT_FWI2;
2583 ha->device_type |= DT_IIDMA;
2584 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2585 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002586 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002587 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002588 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002589 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002590 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002591 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002592 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002593 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002594 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002595 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002596 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002597 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002598 ha->device_type |= DT_ZIO_SUPPORTED;
2599 ha->device_type |= DT_FWI2;
2600 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002601 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2602 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002603 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002604 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002605 ha->device_type |= DT_ZIO_SUPPORTED;
2606 ha->device_type |= DT_FWI2;
2607 ha->device_type |= DT_IIDMA;
2608 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2609 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002610 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002611 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002612 ha->device_type |= DT_ZIO_SUPPORTED;
2613 ha->device_type |= DT_FWI2;
2614 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2615 /* Initialize 82XX ISP flags */
2616 qla82xx_init_flags(ha);
2617 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002618 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002619 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002620 ha->device_type |= DT_ZIO_SUPPORTED;
2621 ha->device_type |= DT_FWI2;
2622 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2623 /* Initialize 82XX ISP flags */
2624 qla82xx_init_flags(ha);
2625 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002626 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002627 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002628 ha->device_type |= DT_ZIO_SUPPORTED;
2629 ha->device_type |= DT_FWI2;
2630 ha->device_type |= DT_IIDMA;
2631 ha->device_type |= DT_T10_PI;
2632 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2633 break;
2634 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002635 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002636 ha->device_type |= DT_ZIO_SUPPORTED;
2637 ha->device_type |= DT_FWI2;
2638 ha->device_type |= DT_IIDMA;
2639 ha->device_type |= DT_T10_PI;
2640 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2641 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002642 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002643 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002644 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002645 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002646 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002647 ha->device_type |= DT_ZIO_SUPPORTED;
2648 ha->device_type |= DT_FWI2;
2649 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002650 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002651 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2652 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002653 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002654 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002655 ha->device_type |= DT_ZIO_SUPPORTED;
2656 ha->device_type |= DT_FWI2;
2657 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002658 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002659 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2660 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002661 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002662 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002663 ha->device_type |= DT_ZIO_SUPPORTED;
2664 ha->device_type |= DT_FWI2;
2665 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002666 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002667 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2668 break;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002669 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2670 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2671 ha->isp_type |= DT_ISP2081;
2672 ha->device_type |= DT_ZIO_SUPPORTED;
2673 ha->device_type |= DT_FWI2;
2674 ha->device_type |= DT_IIDMA;
2675 ha->device_type |= DT_T10_PI;
2676 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2677 break;
2678 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2679 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2680 ha->isp_type |= DT_ISP2281;
2681 ha->device_type |= DT_ZIO_SUPPORTED;
2682 ha->device_type |= DT_FWI2;
2683 ha->device_type |= DT_IIDMA;
2684 ha->device_type |= DT_T10_PI;
2685 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2686 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002687 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002688
Giridhar Malavalia9083012010-04-12 17:59:55 -07002689 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002690 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002691 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002692 /* Get adapter physical port no from interrupt pin register. */
2693 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002694 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2695 IS_QLA27XX(ha) || IS_QLA28XX(ha))
Chad Dupuisf73cb692014-02-26 04:15:06 -05002696 ha->port_no--;
2697 else
2698 ha->port_no = !(ha->port_no & 1);
2699 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002700
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002701 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002702 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002703 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002704}
2705
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002706static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002707qla2xxx_scan_start(struct Scsi_Host *shost)
2708{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002709 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002710
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002711 if (vha->hw->flags.running_gold_fw)
2712 return;
2713
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002714 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2715 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2716 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2717 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002718}
2719
2720static int
2721qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2722{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002724
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002725 if (test_bit(UNLOADING, &vha->dpc_flags))
2726 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002728 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002729 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002730 return 1;
2731
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002733}
2734
Quinn Tranec7193e2017-03-15 09:48:55 -07002735static void qla2x00_iocb_work_fn(struct work_struct *work)
2736{
2737 struct scsi_qla_host *vha = container_of(work,
2738 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002739 struct qla_hw_data *ha = vha->hw;
2740 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran0aca7782018-09-04 14:19:16 -07002741 int i = 2;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002742 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002743
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002744 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2745 return;
2746
2747 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002748 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002749 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002750 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002751
2752 spin_lock_irqsave(&vha->work_lock, flags);
2753 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2754 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002755}
2756
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757/*
2758 * PCI driver interface
2759 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002760static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002761qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002763 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002765 scsi_qla_host_t *base_vha = NULL;
2766 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002767 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002768 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002769 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002770 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002772 struct req_que *req = NULL;
2773 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002774 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002775
Andrew Vasquez285d0322007-10-19 15:59:17 -07002776 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002777 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002778 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2779 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002780 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002781 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2782 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002783 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002784 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002785 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2786 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002787 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002788 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002789 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002790 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002791 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002792 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2793 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2794 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2795 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2796 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002797 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002798 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002799 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2800 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002801 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002802 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2803 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002804
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002805 if (mem_only) {
2806 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002807 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002808 } else {
2809 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002810 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002811 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
Jesse Barnes09276782008-10-18 17:33:19 -07002813 /* This may fail but that's ok */
2814 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002815
Giridhar Malavali5da05a22019-04-02 14:24:24 -07002816 /* Turn off T10-DIF when FC-NVMe is enabled */
2817 if (ql2xnvmeenable)
2818 ql2xenabledif = 0;
2819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002820 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2821 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002822 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2823 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002824 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002826 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2827 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002829 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2830 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002831 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002832 spin_lock_init(&ha->tgt.atio_lock);
2833
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002834 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
2836 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002837 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002838 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002839 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002840 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002841 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002842 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002844 /* Set ISP-type information. */
2845 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002846
2847 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002848 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002849 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002850 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002851
Chad Dupuiscba1e472011-11-18 09:03:21 -08002852 ha->prev_topology = 0;
2853 ha->init_cb_size = sizeof(init_cb_t);
2854 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2855 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002856 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Quinn Tranb2000802018-08-02 13:16:52 -07002857 atomic_set(&ha->num_pend_mbx_stage1, 0);
2858 atomic_set(&ha->num_pend_mbx_stage2, 0);
2859 atomic_set(&ha->num_pend_mbx_stage3, 0);
Quinn Tran8b4673b2018-09-04 14:19:14 -07002860 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2861 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002862
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002863 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002865 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 req_length = REQUEST_ENTRY_CNT_2100;
2868 rsp_length = RESPONSE_ENTRY_CNT_2100;
2869 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002870 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002871 ha->flash_conf_off = ~0;
2872 ha->flash_data_off = ~0;
2873 ha->nvram_conf_off = ~0;
2874 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002875 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002877 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002878 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 req_length = REQUEST_ENTRY_CNT_2200;
2880 rsp_length = RESPONSE_ENTRY_CNT_2100;
2881 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002882 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002883 ha->flash_conf_off = ~0;
2884 ha->flash_data_off = ~0;
2885 ha->nvram_conf_off = ~0;
2886 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002887 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002888 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002889 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891 req_length = REQUEST_ENTRY_CNT_2200;
2892 rsp_length = RESPONSE_ENTRY_CNT_2300;
2893 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002894 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002895 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2896 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002897 ha->flash_conf_off = ~0;
2898 ha->flash_data_off = ~0;
2899 ha->nvram_conf_off = ~0;
2900 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002901 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002902 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002903 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002904 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 req_length = REQUEST_ENTRY_CNT_24XX;
2906 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002907 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002908 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002909 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002910 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002911 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002912 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002913 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002914 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2915 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2916 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2917 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002918 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002919 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002920 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921 req_length = REQUEST_ENTRY_CNT_24XX;
2922 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002923 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002925 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002926 ha->gid_list_info_size = 8;
2927 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002928 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002929 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002930 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2931 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2932 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2933 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2934 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002935 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002936 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2937 req_length = REQUEST_ENTRY_CNT_24XX;
2938 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002939 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002940 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2941 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2942 ha->gid_list_info_size = 8;
2943 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002944 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002945 ha->isp_ops = &qla81xx_isp_ops;
2946 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2947 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2948 ha->nvram_conf_off = ~0;
2949 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002950 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002951 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002952 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2953 req_length = REQUEST_ENTRY_CNT_82XX;
2954 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2955 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2956 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2957 ha->gid_list_info_size = 8;
2958 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002959 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002960 ha->isp_ops = &qla82xx_isp_ops;
2961 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2962 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2963 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2964 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002965 } else if (IS_QLA8044(ha)) {
2966 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2967 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2968 req_length = REQUEST_ENTRY_CNT_82XX;
2969 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2970 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2971 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2972 ha->gid_list_info_size = 8;
2973 ha->optrom_size = OPTROM_SIZE_83XX;
2974 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2975 ha->isp_ops = &qla8044_isp_ops;
2976 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2977 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2978 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2979 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002980 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002981 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002982 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002983 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002984 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002985 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002986 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002987 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2988 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2989 ha->gid_list_info_size = 8;
2990 ha->optrom_size = OPTROM_SIZE_83XX;
2991 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2992 ha->isp_ops = &qla83xx_isp_ops;
2993 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2994 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2995 ha->nvram_conf_off = ~0;
2996 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002997 } else if (IS_QLAFX00(ha)) {
2998 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2999 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3000 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3001 req_length = REQUEST_ENTRY_CNT_FX00;
3002 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003003 ha->isp_ops = &qlafx00_isp_ops;
3004 ha->port_down_retry_count = 30; /* default value */
3005 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3006 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04003007 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003008 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04003009 ha->mr.host_info_resend = false;
3010 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003011 } else if (IS_QLA27XX(ha)) {
3012 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3013 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3014 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05003015 req_length = REQUEST_ENTRY_CNT_83XX;
3016 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04003017 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003018 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3019 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3020 ha->gid_list_info_size = 8;
3021 ha->optrom_size = OPTROM_SIZE_83XX;
3022 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3023 ha->isp_ops = &qla27xx_isp_ops;
3024 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3025 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3026 ha->nvram_conf_off = ~0;
3027 ha->nvram_data_off = ~0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003028 } else if (IS_QLA28XX(ha)) {
3029 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3030 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3031 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3032 req_length = REQUEST_ENTRY_CNT_24XX;
3033 rsp_length = RESPONSE_ENTRY_CNT_2300;
3034 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3035 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3036 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3037 ha->gid_list_info_size = 8;
3038 ha->optrom_size = OPTROM_SIZE_28XX;
3039 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3040 ha->isp_ops = &qla27xx_isp_ops;
3041 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3042 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3043 ha->nvram_conf_off = ~0;
3044 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003046
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003047 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3048 "mbx_count=%d, req_length=%d, "
3049 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08003050 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3051 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003052 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3053 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08003054 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003055 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3056 "isp_ops=%p, flash_conf_off=%d, "
3057 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3058 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3059 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08003060
3061 /* Configure PCI I/O space */
3062 ret = ha->isp_ops->iospace_config(ha);
3063 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003064 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003065
3066 ql_log_pci(ql_log_info, pdev, 0x001d,
3067 "Found an ISP%04X irq %d iobase 0x%p.\n",
3068 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003069 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003070 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003071 init_completion(&ha->mbx_cmd_comp);
3072 complete(&ha->mbx_cmd_comp);
3073 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003074 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003075 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003077 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078
Andrew Vasquez53303c42009-01-22 09:45:37 -08003079 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003080 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3081 "64 Bit addressing is %s.\n",
3082 ha->flags.enable_64bit_addressing ? "enable" :
3083 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003084 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec32014-01-21 10:00:10 +03003085 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003086 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3087 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003089 goto probe_hw_failed;
3090 }
3091
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003092 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003093 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003094 req->max_q_depth = ql2xmaxqdepth;
3095
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096
3097 base_vha = qla2x00_create_host(sht, ha);
3098 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003099 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003100 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 }
3102
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003103 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003104 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003106 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003107 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003108 if (IS_QLA2XXX_MIDTYPE(ha))
Quinn Tranf6602f32018-08-02 13:16:53 -07003109 base_vha->mgmt_svr_loop_id =
3110 qla2x00_reserve_mgmt_server_loop_id(base_vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003111 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003112 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3113 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003114
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003115 /* Setup fcport template structure. */
3116 ha->mr.fcport.vha = base_vha;
3117 ha->mr.fcport.port_type = FCT_UNKNOWN;
3118 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3119 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3120 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3121 ha->mr.fcport.scan_state = 1;
3122
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003123 /* Set the SG table size based on ISP type */
3124 if (!IS_FWI2_CAPABLE(ha)) {
3125 if (IS_QLA2100(ha))
3126 host->sg_tablesize = 32;
3127 } else {
3128 if (!IS_QLA82XX(ha))
3129 host->sg_tablesize = QLA_SG_ALL;
3130 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003131 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003132 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003133 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003134 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003135 host->max_cmd_len = 32;
3136 else
3137 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003138 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003139 /* Older HBAs support only 16-bit LUNs */
3140 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3141 ql2xmaxlun > 0xffff)
3142 host->max_lun = 0xffff;
3143 else
3144 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003145 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003146 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003147
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003148 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3149 "max_id=%d this_id=%d "
3150 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003151 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003152 host->this_id, host->cmd_per_lun, host->unique_id,
3153 host->max_cmd_len, host->max_channel, host->max_lun,
3154 host->transportt, sht->vendor_id);
3155
Himanshu Madhani1010f212017-10-16 11:26:05 -07003156 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3157
Michael Hernandezd7459522016-12-12 14:40:07 -08003158 /* Set up the irqs */
3159 ret = qla2x00_request_irqs(ha, rsp);
3160 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003161 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003162
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003163 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003164 ret = qla2x00_alloc_queues(ha, req, rsp);
3165 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003166 ql_log(ql_log_fatal, base_vha, 0x003d,
3167 "Failed to allocate memory for queue pointers..."
3168 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003169 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003170 }
3171
Jens Axboef664a3c2018-11-01 16:36:27 -06003172 if (ha->mqenable) {
Michael Hernandez56012362016-12-12 14:40:08 -08003173 /* number of hardware queues supported by blk/scsi-mq*/
3174 host->nr_hw_queues = ha->max_qpairs;
3175
3176 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3177 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003178 } else {
3179 if (ql2xnvmeenable) {
3180 host->nr_hw_queues = ha->max_qpairs;
3181 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3182 "FC-NVMe support is enabled, HW queues=%d\n",
3183 host->nr_hw_queues);
3184 } else {
3185 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3186 "blk/scsi-mq disabled.\n");
3187 }
3188 }
Michael Hernandez56012362016-12-12 14:40:08 -08003189
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003190 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003191
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003192 pci_save_state(pdev);
3193
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003194 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003195 rsp->req = req;
3196 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003197
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003198 if (IS_QLAFX00(ha)) {
3199 ha->rsp_q_map[0] = rsp;
3200 ha->req_q_map[0] = req;
3201 set_bit(0, ha->req_qid_map);
3202 set_bit(0, ha->rsp_qid_map);
3203 }
3204
Andrew Vasquez080299902009-03-24 09:07:55 -07003205 /* FWI2-capable only. */
3206 req->req_q_in = &ha->iobase->isp24.req_q_in;
3207 req->req_q_out = &ha->iobase->isp24.req_q_out;
3208 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3209 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003210 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3211 IS_QLA28XX(ha)) {
Andrew Vasquez080299902009-03-24 09:07:55 -07003212 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3213 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3214 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3215 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003216 }
3217
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003218 if (IS_QLAFX00(ha)) {
3219 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3220 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3221 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3222 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3223 }
3224
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003225 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003226 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3227 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3228 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3229 }
3230
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003231 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3232 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3233 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3234 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3235 "req->req_q_in=%p req->req_q_out=%p "
3236 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3237 req->req_q_in, req->req_q_out,
3238 rsp->rsp_q_in, rsp->rsp_q_out);
3239 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3240 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3241 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3242 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3243 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3244 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245
himanshu.madhani@cavium.comd48cc672018-07-02 13:01:59 -07003246 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3247
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003248 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003249 ql_log(ql_log_fatal, base_vha, 0x00d6,
3250 "Failed to initialize adapter - Adapter flags %x.\n",
3251 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003252
Giridhar Malavalia9083012010-04-12 17:59:55 -07003253 if (IS_QLA82XX(ha)) {
3254 qla82xx_idc_lock(ha);
3255 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003256 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003257 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003258 ql_log(ql_log_fatal, base_vha, 0x00d7,
3259 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003260 } else if (IS_QLA8044(ha)) {
3261 qla8044_idc_lock(ha);
3262 qla8044_wr_direct(base_vha,
3263 QLA8044_CRB_DEV_STATE_INDEX,
3264 QLA8XXX_DEV_FAILED);
3265 qla8044_idc_unlock(ha);
3266 ql_log(ql_log_fatal, base_vha, 0x0150,
3267 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003268 }
3269
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270 ret = -ENODEV;
3271 goto probe_failed;
3272 }
3273
Chad Dupuis3b1bef642014-02-26 04:15:04 -05003274 if (IS_QLAFX00(ha))
3275 host->can_queue = QLAFX00_MAX_CANQUEUE;
3276 else
3277 host->can_queue = req->num_outstanding_cmds - 10;
3278
3279 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3280 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3281 host->can_queue, base_vha->req,
3282 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3283
Quinn Trane326d222017-06-13 20:47:18 -07003284 if (ha->mqenable) {
Quinn Trane326d222017-06-13 20:47:18 -07003285 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003286
Jens Axboef664a3c2018-11-01 16:36:27 -06003287 if (QLA_TGT_MODE_ENABLED())
Quinn Trane326d222017-06-13 20:47:18 -07003288 startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003289
Jens Axboef664a3c2018-11-01 16:36:27 -06003290 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
Quinn Trane326d222017-06-13 20:47:18 -07003291 startit = true;
Quinn Trane326d222017-06-13 20:47:18 -07003292
Jens Axboef664a3c2018-11-01 16:36:27 -06003293 /* Create start of day qpairs for Block MQ */
3294 for (i = 0; i < ha->max_qpairs; i++)
3295 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003296 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003297
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003298 if (ha->flags.running_gold_fw)
3299 goto skip_dpc;
3300
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301 /*
3302 * Startup the kernel thread for this host adapter
3303 */
3304 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003305 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003307 ql_log(ql_log_fatal, base_vha, 0x00ed,
3308 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003309 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003310 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003311 goto probe_failed;
3312 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003313 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3314 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003316 /*
3317 * If we're not coming up in initiator mode, we might sit for
3318 * a while without waking up the dpc thread, which leads to a
3319 * stuck process warning. So just kick the dpc once here and
3320 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3321 */
3322 qla2xxx_wake_dpc(base_vha);
3323
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003324 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3325
Saurav Kashyap81178772012-08-22 14:21:04 -04003326 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3327 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3328 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3329 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3330
3331 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3332 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3333 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3334 INIT_WORK(&ha->idc_state_handler,
3335 qla83xx_idc_state_handler_work);
3336 INIT_WORK(&ha->nic_core_unrecoverable,
3337 qla83xx_nic_core_unrecoverable_work);
3338 }
3339
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003340skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341 list_add_tail(&base_vha->list, &ha->vp_list);
3342 base_vha->host->irq = ha->pdev->irq;
3343
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003345 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003346 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3347 "Started qla2x00_timer with "
3348 "interval=%d.\n", WATCH_INTERVAL);
3349 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3350 "Detected hba at address=%p.\n",
3351 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352
Arun Easie02587d2011-08-16 11:29:23 -07003353 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003354 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003355 int prot = 0, guard;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07003356
Arun Easibad75002010-05-04 15:01:30 -07003357 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003358 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3359 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003360 if (ql2xenabledif == 1)
3361 prot = SHOST_DIX_TYPE0_PROTECTION;
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003362 if (ql2xprotmask)
3363 scsi_host_set_prot(host, ql2xprotmask);
3364 else
3365 scsi_host_set_prot(host,
3366 prot | SHOST_DIF_TYPE1_PROTECTION
3367 | SHOST_DIF_TYPE2_PROTECTION
3368 | SHOST_DIF_TYPE3_PROTECTION
3369 | SHOST_DIX_TYPE1_PROTECTION
3370 | SHOST_DIX_TYPE2_PROTECTION
3371 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003372
3373 guard = SHOST_DIX_GUARD_CRC;
3374
3375 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3376 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3377 guard |= SHOST_DIX_GUARD_IP;
3378
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003379 if (ql2xprotguard)
3380 scsi_host_set_guard(host, ql2xprotguard);
3381 else
3382 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003383 } else
3384 base_vha->flags.difdix_supported = 0;
3385 }
3386
Giridhar Malavalia9083012010-04-12 17:59:55 -07003387 ha->isp_ops->enable_intrs(ha);
3388
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003389 if (IS_QLAFX00(ha)) {
3390 ret = qlafx00_fx_disc(base_vha,
3391 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3392 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3393 QLA_SG_ALL : 128;
3394 }
3395
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003396 ret = scsi_add_host(host, &pdev->dev);
3397 if (ret)
3398 goto probe_failed;
3399
Michael Reed14864002009-12-02 09:11:16 -06003400 base_vha->flags.init_done = 1;
3401 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003402 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003403
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003404 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3405 "Init done and hba is online.\n");
3406
Quinn Tran726b8542017-01-19 22:28:00 -08003407 if (qla_ini_mode_enabled(base_vha) ||
3408 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003409 scsi_scan_host(host);
3410 else
3411 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3412 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003413
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003415
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003416 if (IS_QLAFX00(ha)) {
3417 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003418 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3419
3420 /* Register system information */
3421 ret = qlafx00_fx_disc(base_vha,
3422 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3423 }
3424
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003425 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003426
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003427 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003428
Armen Baloyan03eb9122013-10-30 03:38:22 -04003429 ql_log(ql_log_info, base_vha, 0x00fb,
3430 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003431 ql_log(ql_log_info, base_vha, 0x00fc,
3432 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3433 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3434 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3435 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003436 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003438 qlt_add_target(ha, base_vha);
3439
Joe Lawrence6b383972014-08-26 17:12:29 -04003440 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003441
3442 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3443 return -ENODEV;
3444
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003445 if (ha->flags.detected_lr_sfp) {
3446 ql_log(ql_log_info, base_vha, 0xffff,
3447 "Reset chip to pick up LR SFP setting\n");
3448 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3449 qla2xxx_wake_dpc(base_vha);
3450 }
3451
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 return 0;
3453
3454probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003455 if (base_vha->timer_active)
3456 qla2x00_stop_timer(base_vha);
3457 base_vha->flags.online = 0;
3458 if (ha->dpc_thread) {
3459 struct task_struct *t = ha->dpc_thread;
3460
3461 ha->dpc_thread = NULL;
3462 kthread_stop(t);
3463 }
3464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003465 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003466 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003467 /*
3468 * Need to NULL out local req/rsp after
3469 * qla2x00_free_device => qla2x00_free_queues frees
3470 * what these are pointing to. Or else we'll
3471 * fall over below in qla2x00_free_req/rsp_que.
3472 */
3473 req = NULL;
3474 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003476probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003477 qla2x00_mem_free(ha);
3478 qla2x00_free_req_que(ha, req);
3479 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003480 qla2x00_clear_drv_active(ha);
3481
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003482iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003483 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003484 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003485 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003486 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003487 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003488 } else {
3489 if (ha->iobase)
3490 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003491 if (ha->cregbase)
3492 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003493 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003494 pci_release_selected_regions(ha->pdev, ha->bars);
3495 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003497disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003498 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003499 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
Adrian Bunk4c993f72008-01-14 00:55:16 -08003502static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003503qla2x00_shutdown(struct pci_dev *pdev)
3504{
3505 scsi_qla_host_t *vha;
3506 struct qla_hw_data *ha;
3507
3508 vha = pci_get_drvdata(pdev);
3509 ha = vha->hw;
3510
Sawan Chandakefdb5762017-08-23 15:05:00 -07003511 ql_log(ql_log_info, vha, 0xfffa,
3512 "Adapter shutdown\n");
3513
3514 /*
3515 * Prevent future board_disable and wait
3516 * until any pending board_disable has completed.
3517 */
3518 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3519 cancel_work_sync(&ha->board_disable);
3520
3521 if (!atomic_read(&pdev->enable_cnt))
3522 return;
3523
Armen Baloyan42479342013-08-27 01:37:37 -04003524 /* Notify ISPFX00 firmware */
3525 if (IS_QLAFX00(ha))
3526 qlafx00_driver_shutdown(vha, 20);
3527
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003528 /* Turn-off FCE trace */
3529 if (ha->flags.fce_enabled) {
3530 qla2x00_disable_fce_trace(vha, NULL, NULL);
3531 ha->flags.fce_enabled = 0;
3532 }
3533
3534 /* Turn-off EFT trace */
3535 if (ha->eft)
3536 qla2x00_disable_eft_trace(vha);
3537
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003538 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3539 IS_QLA28XX(ha)) {
Quinn Tran3407fc32017-12-28 12:33:11 -08003540 if (ha->flags.fw_started)
3541 qla2x00_abort_isp_cleanup(vha);
3542 } else {
3543 /* Stop currently executing firmware. */
3544 qla2x00_try_to_stop_firmware(vha);
3545 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003546
3547 /* Turn adapter off line */
3548 vha->flags.online = 0;
3549
3550 /* turn-off interrupts on the card */
3551 if (ha->interrupts_on) {
3552 vha->flags.init_done = 0;
3553 ha->isp_ops->disable_intrs(ha);
3554 }
3555
3556 qla2x00_free_irqs(vha);
3557
3558 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003559
Chad Dupuis61d41f62014-09-25 05:17:02 -04003560 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003561 ql_log(ql_log_info, vha, 0xfffe,
3562 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003563}
3564
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003565/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003566static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003567qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003569 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003570 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571
Arun Easi43ebf162011-05-10 11:18:16 -07003572 mutex_lock(&ha->vport_lock);
3573 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003574 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003575
Arun Easi43ebf162011-05-10 11:18:16 -07003576 BUG_ON(base_vha->list.next == &ha->vp_list);
3577 /* This assumes first entry in ha->vp_list is always base vha */
3578 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003579 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003580
Arun Easi43ebf162011-05-10 11:18:16 -07003581 spin_unlock_irqrestore(&ha->vport_slock, flags);
3582 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003583
Himanshu Madhani5e6803b2018-12-10 12:36:23 -08003584 qla_nvme_delete(vha);
3585
Arun Easi43ebf162011-05-10 11:18:16 -07003586 fc_vport_terminate(vha->fc_vport);
3587 scsi_host_put(vha->host);
3588
3589 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003590 }
Arun Easi43ebf162011-05-10 11:18:16 -07003591 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003592}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003593
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003594/* Stops all deferred work threads */
3595static void
3596qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3597{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003598 /* Cancel all work and destroy DPC workqueues */
3599 if (ha->dpc_lp_wq) {
3600 cancel_work_sync(&ha->idc_aen);
3601 destroy_workqueue(ha->dpc_lp_wq);
3602 ha->dpc_lp_wq = NULL;
3603 }
3604
3605 if (ha->dpc_hp_wq) {
3606 cancel_work_sync(&ha->nic_core_reset);
3607 cancel_work_sync(&ha->idc_state_handler);
3608 cancel_work_sync(&ha->nic_core_unrecoverable);
3609 destroy_workqueue(ha->dpc_hp_wq);
3610 ha->dpc_hp_wq = NULL;
3611 }
3612
Andrew Vasquezb9978762009-03-24 09:08:05 -07003613 /* Kill the kernel thread for this host */
3614 if (ha->dpc_thread) {
3615 struct task_struct *t = ha->dpc_thread;
3616
3617 /*
3618 * qla2xxx_wake_dpc checks for ->dpc_thread
3619 * so we need to zero it out.
3620 */
3621 ha->dpc_thread = NULL;
3622 kthread_stop(t);
3623 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003624}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003625
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003626static void
3627qla2x00_unmap_iobases(struct qla_hw_data *ha)
3628{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003629 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003630
Chad Dupuisf73cb692014-02-26 04:15:06 -05003631 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003632 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003633 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003634 } else {
3635 if (ha->iobase)
3636 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003637
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003638 if (ha->cregbase)
3639 iounmap(ha->cregbase);
3640
Giridhar Malavalia9083012010-04-12 17:59:55 -07003641 if (ha->mqiobase)
3642 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003643
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003644 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) &&
3645 ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003646 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003647 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003648}
3649
3650static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003651qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003652{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003653 if (IS_QLA8044(ha)) {
3654 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003655 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003656 qla8044_idc_unlock(ha);
3657 } else if (IS_QLA82XX(ha)) {
3658 qla82xx_idc_lock(ha);
3659 qla82xx_clear_drv_active(ha);
3660 qla82xx_idc_unlock(ha);
3661 }
3662}
3663
3664static void
3665qla2x00_remove_one(struct pci_dev *pdev)
3666{
3667 scsi_qla_host_t *base_vha;
3668 struct qla_hw_data *ha;
3669
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003670 base_vha = pci_get_drvdata(pdev);
3671 ha = base_vha->hw;
Quinn Tran45235022018-07-18 14:29:53 -07003672 ql_log(ql_log_info, base_vha, 0xb079,
3673 "Removing driver\n");
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003674
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003675 /* Indicate device removal to prevent future board_disable and wait
3676 * until any pending board_disable has completed. */
3677 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3678 cancel_work_sync(&ha->board_disable);
3679
3680 /*
3681 * If the PCI device is disabled then there was a PCI-disconnect and
3682 * qla2x00_disable_board_on_pci_error has taken care of most of the
3683 * resources.
3684 */
3685 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003686 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3687 base_vha->gnl.l, base_vha->gnl.ldma);
3688
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003689 scsi_host_put(base_vha->host);
3690 kfree(ha);
3691 pci_set_drvdata(pdev, NULL);
3692 return;
3693 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003694 qla2x00_wait_for_hba_ready(base_vha);
3695
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003696 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3697 IS_QLA28XX(ha)) {
Quinn Tran45235022018-07-18 14:29:53 -07003698 if (ha->flags.fw_started)
3699 qla2x00_abort_isp_cleanup(base_vha);
3700 } else if (!IS_QLAFX00(ha)) {
3701 if (IS_QLA8031(ha)) {
3702 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3703 "Clearing fcoe driver presence.\n");
3704 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3705 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3706 "Error while clearing DRV-Presence.\n");
3707 }
3708
3709 qla2x00_try_to_stop_firmware(base_vha);
3710 }
3711
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003712 qla2x00_wait_for_sess_deletion(base_vha);
3713
Quinn Tran726b8542017-01-19 22:28:00 -08003714 /*
3715 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003716 * where it was set first.
3717 */
3718 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3719 return;
3720
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003721 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003722
3723 qla_nvme_delete(base_vha);
3724
Quinn Tran726b8542017-01-19 22:28:00 -08003725 dma_free_coherent(&ha->pdev->dev,
3726 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003727
Quinn Trana4239942017-12-28 12:33:26 -08003728 vfree(base_vha->scan.l);
3729
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003730 if (IS_QLAFX00(ha))
3731 qlafx00_driver_shutdown(base_vha, 20);
3732
3733 qla2x00_delete_all_vps(ha, base_vha);
3734
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003735 qla2x00_dfs_remove(base_vha);
3736
3737 qla84xx_put_chip(base_vha);
3738
3739 /* Disable timer */
3740 if (base_vha->timer_active)
3741 qla2x00_stop_timer(base_vha);
3742
3743 base_vha->flags.online = 0;
3744
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003745 /* free DMA memory */
3746 if (ha->exlogin_buf)
3747 qla2x00_free_exlogin_buffer(ha);
3748
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003749 /* free DMA memory */
3750 if (ha->exchoffld_buf)
3751 qla2x00_free_exchoffld_buffer(ha);
3752
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003753 qla2x00_destroy_deferred_work(ha);
3754
3755 qlt_remove_target(ha, base_vha);
3756
3757 qla2x00_free_sysfs_attr(base_vha, true);
3758
3759 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003760 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003761
3762 scsi_remove_host(base_vha->host);
3763
3764 qla2x00_free_device(base_vha);
3765
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003766 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003767
Arun Easid2749ff2014-09-25 05:16:51 -04003768 scsi_host_put(base_vha->host);
3769
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003770 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003771
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003772 pci_release_selected_regions(ha->pdev, ha->bars);
3773 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003775 pci_disable_pcie_error_reporting(pdev);
3776
Bernhard Walle665db932007-03-28 00:49:49 +02003777 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779
3780static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003781qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003783 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784
Andrew Vasquez85880802009-12-15 21:29:46 -08003785 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3786
3787 /* Disable timer */
3788 if (vha->timer_active)
3789 qla2x00_stop_timer(vha);
3790
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003791 qla25xx_delete_queues(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003792 vha->flags.online = 0;
3793
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003794 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003795 if (ha->interrupts_on) {
3796 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003797 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003798 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003799
Quinn Tran093df732016-12-12 14:40:09 -08003800 qla2x00_free_fcports(vha);
3801
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003802 qla2x00_free_irqs(vha);
3803
Quinn Tran093df732016-12-12 14:40:09 -08003804 /* Flush the work queue and remove it */
3805 if (ha->wq) {
3806 flush_workqueue(ha->wq);
3807 destroy_workqueue(ha->wq);
3808 ha->wq = NULL;
3809 }
3810
Chad Dupuis88670482010-07-23 15:28:30 +05003811
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003812 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003813
Giridhar Malavali08de2842011-08-16 11:31:44 -07003814 qla82xx_md_free(vha);
3815
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003816 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817}
3818
Chad Dupuis88670482010-07-23 15:28:30 +05003819void qla2x00_free_fcports(struct scsi_qla_host *vha)
3820{
3821 fc_port_t *fcport, *tfcport;
3822
Quinn Tranffbc6472019-04-02 14:24:29 -07003823 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
3824 qla2x00_free_fcport(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003825}
3826
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003827static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003828qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003829 int defer)
3830{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003831 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003832 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003833 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003834
3835 if (!fcport->rport)
3836 return;
3837
3838 rport = fcport->rport;
3839 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003840 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003841 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003842 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003843 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003844 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003845 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3846 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003847 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003848 int now;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07003849
Quinn Tran726b8542017-01-19 22:28:00 -08003850 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003851 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3852 "%s %8phN. rport %p roles %x\n",
3853 __func__, fcport->port_name, rport,
3854 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003855 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003856 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003857 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003858 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003859}
3860
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3863 *
3864 * Input: ha = adapter block pointer. fcport = port structure pointer.
3865 *
3866 * Return: None.
3867 *
3868 * Context:
3869 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003870void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003871 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003873 if (IS_QLAFX00(vha->hw)) {
3874 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3875 qla2x00_schedule_rport_del(vha, fcport, defer);
3876 return;
3877 }
3878
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003879 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003880 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003881 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003882 qla2x00_schedule_rport_del(vha, fcport, defer);
3883 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003884 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 * We may need to retry the login, so don't change the state of the
3886 * port but do the retries.
3887 */
3888 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003889 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890
3891 if (!do_login)
3892 return;
3893
Arun Easia1d02852015-08-04 13:38:02 -04003894 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895}
3896
3897/*
3898 * qla2x00_mark_all_devices_lost
3899 * Updates fcport state when device goes offline.
3900 *
3901 * Input:
3902 * ha = adapter block pointer.
3903 * fcport = port structure pointer.
3904 *
3905 * Return:
3906 * None.
3907 *
3908 * Context:
3909 */
3910void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003911qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912{
3913 fc_port_t *fcport;
3914
Quinn Tran83548fe2017-06-02 09:12:01 -07003915 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3916 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003918 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003919 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08003920 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003921
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003922 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003924
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 /*
3926 * No point in marking the device as lost, if the device is
3927 * already DEAD.
3928 */
3929 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3930 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003931 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003932 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003933 if (defer)
3934 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003935 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003936 qla2x00_schedule_rport_del(vha, fcport, defer);
3937 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 }
3939}
3940
Bart Van Assche0e145a52019-04-17 14:44:12 -07003941static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
3942{
3943 int i;
3944
3945 if (IS_FWI2_CAPABLE(ha))
3946 return;
3947
3948 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
3949 set_bit(i, ha->loop_id_map);
3950 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
3951 set_bit(BROADCAST, ha->loop_id_map);
3952}
3953
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954/*
3955* qla2x00_mem_alloc
3956* Allocates adapter memory.
3957*
3958* Returns:
3959* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003960* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003962static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003963qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3964 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965{
3966 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967
Andrew Vasqueze8711082008-01-31 12:33:48 -08003968 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003969 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003970 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003973 if (qlt_mem_alloc(ha) < 0)
3974 goto fail_free_init_cb;
3975
Chad Dupuis642ef982012-02-09 11:15:57 -08003976 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3977 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003979 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980
Andrew Vasqueze8711082008-01-31 12:33:48 -08003981 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3982 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003983 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003985 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003986 /* Allocate cache for CT6 Ctx. */
3987 if (!ctx_cachep) {
3988 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3989 sizeof(struct ct6_dsd), 0,
3990 SLAB_HWCACHE_ALIGN, NULL);
3991 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003992 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003993 }
3994 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3995 ctx_cachep);
3996 if (!ha->ctx_mempool)
3997 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003998 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3999 "ctx_cachep=%p ctx_mempool=%p.\n",
4000 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004001 }
4002
Andrew Vasqueze8711082008-01-31 12:33:48 -08004003 /* Get memory for cached NVRAM */
4004 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4005 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004006 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4009 ha->pdev->device);
4010 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4011 DMA_POOL_SIZE, 8, 0);
4012 if (!ha->s_dma_pool)
4013 goto fail_free_nvram;
4014
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004015 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4016 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4017 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4018
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004019 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004020 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4021 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4022 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004023 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4024 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004025 goto fail_s_dma_pool;
4026 }
4027
4028 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4029 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4030 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004031 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4032 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004033 goto fail_dl_dma_pool;
4034 }
Giridhar Malavali50b81272018-12-21 09:33:45 -08004035
4036 if (ql2xenabledif) {
4037 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4038 struct dsd_dma *dsd, *nxt;
4039 uint i;
4040 /* Creata a DMA pool of buffers for DIF bundling */
4041 ha->dif_bundl_pool = dma_pool_create(name,
4042 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4043 if (!ha->dif_bundl_pool) {
4044 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4045 "%s: failed create dif_bundl_pool\n",
4046 __func__);
4047 goto fail_dif_bundl_dma_pool;
4048 }
4049
4050 INIT_LIST_HEAD(&ha->pool.good.head);
4051 INIT_LIST_HEAD(&ha->pool.unusable.head);
4052 ha->pool.good.count = 0;
4053 ha->pool.unusable.count = 0;
4054 for (i = 0; i < 128; i++) {
4055 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4056 if (!dsd) {
4057 ql_dbg_pci(ql_dbg_init, ha->pdev,
4058 0xe0ee, "%s: failed alloc dsd\n",
4059 __func__);
4060 return 1;
4061 }
4062 ha->dif_bundle_kallocs++;
4063
4064 dsd->dsd_addr = dma_pool_alloc(
4065 ha->dif_bundl_pool, GFP_ATOMIC,
4066 &dsd->dsd_list_dma);
4067 if (!dsd->dsd_addr) {
4068 ql_dbg_pci(ql_dbg_init, ha->pdev,
4069 0xe0ee,
4070 "%s: failed alloc ->dsd_addr\n",
4071 __func__);
4072 kfree(dsd);
4073 ha->dif_bundle_kallocs--;
4074 continue;
4075 }
4076 ha->dif_bundle_dma_allocs++;
4077
4078 /*
4079 * if DMA buffer crosses 4G boundary,
4080 * put it on bad list
4081 */
4082 if (MSD(dsd->dsd_list_dma) ^
4083 MSD(dsd->dsd_list_dma + bufsize)) {
4084 list_add_tail(&dsd->list,
4085 &ha->pool.unusable.head);
4086 ha->pool.unusable.count++;
4087 } else {
4088 list_add_tail(&dsd->list,
4089 &ha->pool.good.head);
4090 ha->pool.good.count++;
4091 }
4092 }
4093
4094 /* return the good ones back to the pool */
4095 list_for_each_entry_safe(dsd, nxt,
4096 &ha->pool.good.head, list) {
4097 list_del(&dsd->list);
4098 dma_pool_free(ha->dif_bundl_pool,
4099 dsd->dsd_addr, dsd->dsd_list_dma);
4100 ha->dif_bundle_dma_allocs--;
4101 kfree(dsd);
4102 ha->dif_bundle_kallocs--;
4103 }
4104
4105 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4106 "%s: dif dma pool (good=%u unusable=%u)\n",
4107 __func__, ha->pool.good.count,
4108 ha->pool.unusable.count);
4109 }
4110
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004111 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
Giridhar Malavali50b81272018-12-21 09:33:45 -08004112 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4113 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4114 ha->dif_bundl_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004115 }
4116
Andrew Vasqueze8711082008-01-31 12:33:48 -08004117 /* Allocate memory for SNS commands */
4118 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004120 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004121 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004122 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004123 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004124 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08004125 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004126 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004127 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004128 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004129 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004130 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004131 goto fail_dma_pool;
4132 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004133 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004134 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004135 if (!ha->ct_sns)
4136 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004137 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4138 "ms_iocb=%p ct_sns=%p.\n",
4139 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 }
4141
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004142 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004143 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4144 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004145 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4146 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004147 goto fail_req;
4148 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004149 (*req)->length = req_len;
4150 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4151 ((*req)->length + 1) * sizeof(request_t),
4152 &(*req)->dma, GFP_KERNEL);
4153 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004154 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4155 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004156 goto fail_req_ring;
4157 }
4158 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004159 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4160 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004161 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4162 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163 goto fail_rsp;
4164 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004165 (*rsp)->hw = ha;
4166 (*rsp)->length = rsp_len;
4167 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4168 ((*rsp)->length + 1) * sizeof(response_t),
4169 &(*rsp)->dma, GFP_KERNEL);
4170 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004171 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4172 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 goto fail_rsp_ring;
4174 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004175 (*req)->rsp = *rsp;
4176 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004177 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4178 "req=%p req->length=%d req->ring=%p rsp=%p "
4179 "rsp->length=%d rsp->ring=%p.\n",
4180 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4181 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004182 /* Allocate memory for NVRAM data for vports */
4183 if (ha->nvram_npiv_size) {
Kees Cook6396bb22018-06-12 14:03:40 -07004184 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4185 sizeof(struct qla_npiv_entry),
4186 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004187 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004188 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4189 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004190 goto fail_npiv_info;
4191 }
4192 } else
4193 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004194
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004195 /* Get consistent memory allocated for EX-INIT-CB. */
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004196 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4197 IS_QLA28XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004198 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4199 &ha->ex_init_cb_dma);
4200 if (!ha->ex_init_cb)
4201 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004202 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4203 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004204 }
4205
Giridhar Malavalia9083012010-04-12 17:59:55 -07004206 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4207
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004208 /* Get consistent memory allocated for Async Port-Database. */
4209 if (!IS_FWI2_CAPABLE(ha)) {
4210 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4211 &ha->async_pd_dma);
4212 if (!ha->async_pd)
4213 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004214 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4215 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004216 }
4217
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004218 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004219
4220 /* Allocate memory for our loop_id bitmap */
Kees Cook6396bb22018-06-12 14:03:40 -07004221 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4222 sizeof(long),
4223 GFP_KERNEL);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004224 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004225 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004226 else {
4227 qla2x00_set_reserved_loop_ids(ha);
4228 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec32014-01-21 10:00:10 +03004229 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004230 }
4231
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004232 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4233 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4234 if (!ha->sfp_data) {
4235 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4236 "Unable to allocate memory for SFP read-data.\n");
4237 goto fail_sfp_data;
4238 }
4239
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004240 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4241 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4242 GFP_KERNEL);
4243 if (!ha->flt) {
4244 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4245 "Unable to allocate memory for FLT.\n");
4246 goto fail_flt_buffer;
4247 }
4248
Dan Carpenterb2a72ec32014-01-21 10:00:10 +03004249 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004250
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004251fail_flt_buffer:
4252 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4253 ha->sfp_data, ha->sfp_data_dma);
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004254fail_sfp_data:
4255 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004256fail_loop_id_map:
4257 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004258fail_async_pd:
4259 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004260fail_ex_init_cb:
4261 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004262fail_npiv_info:
4263 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4264 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4265 (*rsp)->ring = NULL;
4266 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004267fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004268 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004269 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004270fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004271 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4272 sizeof(request_t), (*req)->ring, (*req)->dma);
4273 (*req)->ring = NULL;
4274 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004275fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004276 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004277 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004278fail_req:
4279 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4280 ha->ct_sns, ha->ct_sns_dma);
4281 ha->ct_sns = NULL;
4282 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004283fail_free_ms_iocb:
4284 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4285 ha->ms_iocb = NULL;
4286 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004287
4288 if (ha->sns_cmd)
4289 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4290 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004291fail_dma_pool:
Giridhar Malavali50b81272018-12-21 09:33:45 -08004292 if (ql2xenabledif) {
4293 struct dsd_dma *dsd, *nxt;
4294
4295 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4296 list) {
4297 list_del(&dsd->list);
4298 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4299 dsd->dsd_list_dma);
4300 ha->dif_bundle_dma_allocs--;
4301 kfree(dsd);
4302 ha->dif_bundle_kallocs--;
4303 ha->pool.unusable.count--;
4304 }
4305 dma_pool_destroy(ha->dif_bundl_pool);
4306 ha->dif_bundl_pool = NULL;
4307 }
4308
4309fail_dif_bundl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004310 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004311 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4312 ha->fcp_cmnd_dma_pool = NULL;
4313 }
4314fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004315 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004316 dma_pool_destroy(ha->dl_dma_pool);
4317 ha->dl_dma_pool = NULL;
4318 }
4319fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004320 dma_pool_destroy(ha->s_dma_pool);
4321 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004322fail_free_nvram:
4323 kfree(ha->nvram);
4324 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004325fail_free_ctx_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004326 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004327 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004328fail_free_srb_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004329 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004330 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004331fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004332 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4333 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004334 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004335 ha->gid_list = NULL;
4336 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004337fail_free_tgt_mem:
4338 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004339fail_free_init_cb:
4340 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4341 ha->init_cb_dma);
4342 ha->init_cb = NULL;
4343 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004344fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004345 ql_log(ql_log_fatal, NULL, 0x0030,
4346 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004347 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348}
4349
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004350int
4351qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4352{
4353 int rval;
4354 uint16_t size, max_cnt, temp;
4355 struct qla_hw_data *ha = vha->hw;
4356
4357 /* Return if we don't need to alloacate any extended logins */
4358 if (!ql2xexlogins)
4359 return QLA_SUCCESS;
4360
Quinn Tran99e1b682017-06-02 09:12:03 -07004361 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4362 return QLA_SUCCESS;
4363
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004364 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4365 max_cnt = 0;
4366 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4367 if (rval != QLA_SUCCESS) {
4368 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4369 "Failed to get exlogin status.\n");
4370 return rval;
4371 }
4372
4373 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004374 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004375
Quinn Tran99e1b682017-06-02 09:12:03 -07004376 if (temp != ha->exlogin_size) {
4377 qla2x00_free_exlogin_buffer(ha);
4378 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004379
Quinn Tran99e1b682017-06-02 09:12:03 -07004380 ql_log(ql_log_info, vha, 0xd024,
4381 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4382 max_cnt, size, temp);
4383
4384 ql_log(ql_log_info, vha, 0xd025,
4385 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4386
4387 /* Get consistent memory for extended logins */
4388 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4389 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4390 if (!ha->exlogin_buf) {
4391 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004392 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004393 return -ENOMEM;
4394 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004395 }
4396
4397 /* Now configure the dma buffer */
4398 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4399 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004400 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004401 "Setup extended login buffer ****FAILED****.\n");
4402 qla2x00_free_exlogin_buffer(ha);
4403 }
4404
4405 return rval;
4406}
4407
4408/*
4409* qla2x00_free_exlogin_buffer
4410*
4411* Input:
4412* ha = adapter block pointer
4413*/
4414void
4415qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4416{
4417 if (ha->exlogin_buf) {
4418 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4419 ha->exlogin_buf, ha->exlogin_buf_dma);
4420 ha->exlogin_buf = NULL;
4421 ha->exlogin_size = 0;
4422 }
4423}
4424
Quinn Tran99e1b682017-06-02 09:12:03 -07004425static void
4426qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4427{
4428 u32 temp;
Quinn Tran0645cb82018-09-11 10:18:18 -07004429 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
Quinn Tran99e1b682017-06-02 09:12:03 -07004430 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4431
Quinn Trand1e36352017-12-28 12:33:12 -08004432 if (max_cnt > vha->hw->max_exchg)
4433 max_cnt = vha->hw->max_exchg;
4434
Quinn Tran99e1b682017-06-02 09:12:03 -07004435 if (qla_ini_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004436 if (vha->ql2xiniexchg > max_cnt)
4437 vha->ql2xiniexchg = max_cnt;
Quinn Tran99e1b682017-06-02 09:12:03 -07004438
Quinn Tran0645cb82018-09-11 10:18:18 -07004439 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4440 *ret_cnt = vha->ql2xiniexchg;
4441
Quinn Tran99e1b682017-06-02 09:12:03 -07004442 } else if (qla_tgt_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004443 if (vha->ql2xexchoffld > max_cnt) {
4444 vha->ql2xexchoffld = max_cnt;
4445 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4446 }
Quinn Tran99e1b682017-06-02 09:12:03 -07004447
Quinn Tran0645cb82018-09-11 10:18:18 -07004448 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4449 *ret_cnt = vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004450 } else if (qla_dual_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004451 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004452 if (temp > max_cnt) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004453 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4454 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
Quinn Tran99e1b682017-06-02 09:12:03 -07004455 temp = max_cnt;
Quinn Tran0645cb82018-09-11 10:18:18 -07004456 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Quinn Tran99e1b682017-06-02 09:12:03 -07004457 }
4458
4459 if (temp > FW_DEF_EXCHANGES_CNT)
4460 *ret_cnt = temp;
4461 }
4462}
4463
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004464int
4465qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4466{
4467 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004468 u16 size, max_cnt;
4469 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004470 struct qla_hw_data *ha = vha->hw;
4471
Quinn Tran99e1b682017-06-02 09:12:03 -07004472 if (!ha->flags.exchoffld_enabled)
4473 return QLA_SUCCESS;
4474
4475 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004476 return QLA_SUCCESS;
4477
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004478 max_cnt = 0;
4479 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4480 if (rval != QLA_SUCCESS) {
4481 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4482 "Failed to get exlogin status.\n");
4483 return rval;
4484 }
4485
Quinn Trand1e36352017-12-28 12:33:12 -08004486 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4487 ql_log(ql_log_info, vha, 0xd014,
4488 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004489
Quinn Trand1e36352017-12-28 12:33:12 -08004490 totsz = actual_cnt * size;
4491
4492 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004493 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran0645cb82018-09-11 10:18:18 -07004494 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4495 ha->exchoffld_size = 0;
4496 ha->flags.exchoffld_enabled = 0;
4497 return QLA_SUCCESS;
4498 }
4499
Quinn Trand1e36352017-12-28 12:33:12 -08004500 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004501
Quinn Tran99e1b682017-06-02 09:12:03 -07004502 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004503 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4504 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004505
4506 ql_log(ql_log_info, vha, 0xd017,
4507 "Exchange Buffers requested size = 0x%x\n",
4508 ha->exchoffld_size);
4509
4510 /* Get consistent memory for extended logins */
4511 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4512 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4513 if (!ha->exchoffld_buf) {
4514 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004515 "Failed to allocate memory for Exchange Offload.\n");
4516
4517 if (ha->max_exchg >
4518 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4519 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4520 } else if (ha->max_exchg >
4521 (FW_DEF_EXCHANGES_CNT + 512)) {
4522 ha->max_exchg -= 512;
4523 } else {
4524 ha->flags.exchoffld_enabled = 0;
4525 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4526 "Disabling Exchange offload due to lack of memory\n");
4527 }
4528 ha->exchoffld_size = 0;
4529
Quinn Tran99e1b682017-06-02 09:12:03 -07004530 return -ENOMEM;
4531 }
Quinn Tran0645cb82018-09-11 10:18:18 -07004532 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4533 /* pathological case */
4534 qla2x00_free_exchoffld_buffer(ha);
4535 ha->exchoffld_size = 0;
4536 ha->flags.exchoffld_enabled = 0;
4537 ql_log(ql_log_info, vha, 0xd016,
4538 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4539 ha->exchoffld_size, actual_cnt, size, totsz);
4540 return 0;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004541 }
4542
4543 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004544 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004545 if (rval) {
4546 ql_log(ql_log_fatal, vha, 0xd02e,
4547 "Setup exchange offload buffer ****FAILED****.\n");
4548 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004549 } else {
4550 /* re-adjust number of target exchange */
4551 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4552
4553 if (qla_ini_mode_enabled(vha))
4554 icb->exchange_count = 0;
4555 else
Quinn Tran0645cb82018-09-11 10:18:18 -07004556 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004557 }
4558
4559 return rval;
4560}
4561
4562/*
4563* qla2x00_free_exchoffld_buffer
4564*
4565* Input:
4566* ha = adapter block pointer
4567*/
4568void
4569qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4570{
4571 if (ha->exchoffld_buf) {
4572 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4573 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4574 ha->exchoffld_buf = NULL;
4575 ha->exchoffld_size = 0;
4576 }
4577}
4578
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004580* qla2x00_free_fw_dump
4581* Frees fw dump stuff.
4582*
4583* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004584* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004585*/
4586static void
4587qla2x00_free_fw_dump(struct qla_hw_data *ha)
4588{
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004589 struct fwdt *fwdt = ha->fwdt;
4590 uint j;
4591
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004592 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004593 dma_free_coherent(&ha->pdev->dev,
4594 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004595
Chad Dupuisf73cb692014-02-26 04:15:06 -05004596 if (ha->eft)
4597 dma_free_coherent(&ha->pdev->dev,
4598 EFT_SIZE, ha->eft, ha->eft_dma);
4599
4600 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004601 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004602
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004603 ha->fce = NULL;
4604 ha->fce_dma = 0;
4605 ha->eft = NULL;
4606 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004607 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004608 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004609 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004610 ha->fw_dump = NULL;
4611 ha->fw_dump_len = 0;
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004612
4613 for (j = 0; j < 2; j++, fwdt++) {
4614 if (fwdt->template)
4615 vfree(fwdt->template);
4616 fwdt->template = NULL;
4617 fwdt->length = 0;
4618 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004619}
4620
4621/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004622* qla2x00_mem_free
4623* Frees all adapter allocated memory.
4624*
4625* Input:
4626* ha = adapter block pointer.
4627*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004628static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004629qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004631 qla2x00_free_fw_dump(ha);
4632
Saurav Kashyap81178772012-08-22 14:21:04 -04004633 if (ha->mctp_dump)
4634 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4635 ha->mctp_dump_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004636 ha->mctp_dump = NULL;
Saurav Kashyap81178772012-08-22 14:21:04 -04004637
Thomas Meyer75c1d482018-12-02 21:52:11 +01004638 mempool_destroy(ha->srb_mempool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004639 ha->srb_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004641 if (ha->dcbx_tlv)
4642 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4643 ha->dcbx_tlv, ha->dcbx_tlv_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004644 ha->dcbx_tlv = NULL;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004645
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004646 if (ha->xgmac_data)
4647 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4648 ha->xgmac_data, ha->xgmac_data_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004649 ha->xgmac_data = NULL;
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004650
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 if (ha->sns_cmd)
4652 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004653 ha->sns_cmd, ha->sns_cmd_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004654 ha->sns_cmd = NULL;
4655 ha->sns_cmd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656
4657 if (ha->ct_sns)
4658 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004659 ha->ct_sns, ha->ct_sns_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004660 ha->ct_sns = NULL;
4661 ha->ct_sns_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662
Andrew Vasquez88729e52006-06-23 16:10:50 -07004663 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004664 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4665 ha->sfp_data_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004666 ha->sfp_data = NULL;
Andrew Vasquez88729e52006-06-23 16:10:50 -07004667
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004668 if (ha->flt)
4669 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4670 ha->flt, ha->flt_dma);
Bart Van Asschedc035d42019-04-17 14:44:23 -07004671 ha->flt = NULL;
4672 ha->flt_dma = 0;
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004673
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 if (ha->ms_iocb)
4675 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004676 ha->ms_iocb = NULL;
4677 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004679 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004680 dma_pool_free(ha->s_dma_pool,
4681 ha->ex_init_cb, ha->ex_init_cb_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004682 ha->ex_init_cb = NULL;
4683 ha->ex_init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004684
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004685 if (ha->async_pd)
4686 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004687 ha->async_pd = NULL;
4688 ha->async_pd_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004689
Thomas Meyer75c1d482018-12-02 21:52:11 +01004690 dma_pool_destroy(ha->s_dma_pool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004691 ha->s_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004694 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4695 ha->gid_list, ha->gid_list_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004696 ha->gid_list = NULL;
4697 ha->gid_list_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698
Giridhar Malavalia9083012010-04-12 17:59:55 -07004699 if (IS_QLA82XX(ha)) {
4700 if (!list_empty(&ha->gbl_dsd_list)) {
4701 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4702
4703 /* clean up allocated prev pool */
4704 list_for_each_entry_safe(dsd_ptr,
4705 tdsd_ptr, &ha->gbl_dsd_list, list) {
4706 dma_pool_free(ha->dl_dma_pool,
4707 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4708 list_del(&dsd_ptr->list);
4709 kfree(dsd_ptr);
4710 }
4711 }
4712 }
4713
Thomas Meyer75c1d482018-12-02 21:52:11 +01004714 dma_pool_destroy(ha->dl_dma_pool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004715 ha->dl_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004716
Thomas Meyer75c1d482018-12-02 21:52:11 +01004717 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004718 ha->fcp_cmnd_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004719
Thomas Meyer75c1d482018-12-02 21:52:11 +01004720 mempool_destroy(ha->ctx_mempool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004721 ha->ctx_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004722
Giridhar Malavali50b81272018-12-21 09:33:45 -08004723 if (ql2xenabledif) {
4724 struct dsd_dma *dsd, *nxt;
4725
4726 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4727 list) {
4728 list_del(&dsd->list);
4729 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4730 dsd->dsd_list_dma);
4731 ha->dif_bundle_dma_allocs--;
4732 kfree(dsd);
4733 ha->dif_bundle_kallocs--;
4734 ha->pool.unusable.count--;
4735 }
4736 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4737 list_del(&dsd->list);
4738 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4739 dsd->dsd_list_dma);
4740 ha->dif_bundle_dma_allocs--;
4741 kfree(dsd);
4742 ha->dif_bundle_kallocs--;
4743 }
4744 }
4745
4746 if (ha->dif_bundl_pool)
4747 dma_pool_destroy(ha->dif_bundl_pool);
Bart Van Asschedc035d42019-04-17 14:44:23 -07004748 ha->dif_bundl_pool = NULL;
Giridhar Malavali50b81272018-12-21 09:33:45 -08004749
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004750 qlt_mem_free(ha);
4751
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004752 if (ha->init_cb)
4753 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004754 ha->init_cb, ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 ha->init_cb = NULL;
4756 ha->init_cb_dma = 0;
Bart Van Assche5365bf92019-04-17 14:44:22 -07004757
4758 vfree(ha->optrom_buffer);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004759 ha->optrom_buffer = NULL;
Bart Van Assche5365bf92019-04-17 14:44:22 -07004760 kfree(ha->nvram);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004761 ha->nvram = NULL;
Bart Van Assche5365bf92019-04-17 14:44:22 -07004762 kfree(ha->npiv_info);
4763 ha->npiv_info = NULL;
4764 kfree(ha->swl);
4765 ha->swl = NULL;
4766 kfree(ha->loop_id_map);
4767 ha->loop_id_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004768}
4769
4770struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4771 struct qla_hw_data *ha)
4772{
4773 struct Scsi_Host *host;
4774 struct scsi_qla_host *vha = NULL;
4775
4776 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004777 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004778 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4779 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004780 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004781 }
4782
4783 /* Clear our data area */
4784 vha = shost_priv(host);
4785 memset(vha, 0, sizeof(scsi_qla_host_t));
4786
4787 vha->host = host;
4788 vha->host_no = host->host_no;
4789 vha->hw = ha;
4790
Quinn Tran0645cb82018-09-11 10:18:18 -07004791 vha->qlini_mode = ql2x_ini_mode;
4792 vha->ql2xexchoffld = ql2xexchoffld;
4793 vha->ql2xiniexchg = ql2xiniexchg;
4794
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004795 INIT_LIST_HEAD(&vha->vp_fcports);
4796 INIT_LIST_HEAD(&vha->work_list);
4797 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004798 INIT_LIST_HEAD(&vha->qla_cmd_list);
4799 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004800 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004801 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004802 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004803 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004804 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004805 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004806 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004807
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004808 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004809 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004810 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004811 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004812
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004813 vha->gnl.size = sizeof(struct get_name_list_extended) *
4814 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004815 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4816 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4817 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004818 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004819 "Alloc failed for name list.\n");
4820 scsi_remove_host(vha->host);
4821 return NULL;
4822 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004823
Quinn Trana4239942017-12-28 12:33:26 -08004824 /* todo: what about ext login? */
4825 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4826 vha->scan.l = vmalloc(vha->scan.size);
4827 if (!vha->scan.l) {
4828 ql_log(ql_log_fatal, vha, 0xd04a,
4829 "Alloc failed for scan database.\n");
4830 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4831 vha->gnl.l, vha->gnl.ldma);
4832 scsi_remove_host(vha->host);
4833 return NULL;
4834 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004835 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004837 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004838 ql_dbg(ql_dbg_init, vha, 0x0041,
4839 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4840 vha->host, vha->hw, vha,
4841 dev_name(&(ha->pdev->dev)));
4842
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004843 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844}
4845
Quinn Tran726b8542017-01-19 22:28:00 -08004846struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004847qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004848{
4849 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004850 uint8_t bail;
4851
4852 QLA_VHA_MARK_BUSY(vha, bail);
4853 if (bail)
4854 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004855
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004856 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004857 if (!e) {
4858 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004859 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004860 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004861
4862 INIT_LIST_HEAD(&e->list);
4863 e->type = type;
4864 e->flags = QLA_EVT_FLAG_FREE;
4865 return e;
4866}
4867
Quinn Tran726b8542017-01-19 22:28:00 -08004868int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004869qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004870{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004871 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004872 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004873
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004874 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004875 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004876
4877 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4878 q = true;
4879
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004880 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004881
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004882 if (q)
4883 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004884
Andrew Vasquez0971de72008-04-03 13:13:18 -07004885 return QLA_SUCCESS;
4886}
4887
4888int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004889qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004890 u32 data)
4891{
4892 struct qla_work_evt *e;
4893
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004894 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004895 if (!e)
4896 return QLA_FUNCTION_FAILED;
4897
4898 e->u.aen.code = code;
4899 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004900 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004901}
4902
Andrew Vasquez8a659572009-02-08 20:50:12 -08004903int
4904qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4905{
4906 struct qla_work_evt *e;
4907
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004908 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004909 if (!e)
4910 return QLA_FUNCTION_FAILED;
4911
4912 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004913 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004914}
4915
Andrew Vasquezac280b62009-08-20 11:06:05 -07004916#define qla2x00_post_async_work(name, type) \
4917int qla2x00_post_async_##name##_work( \
4918 struct scsi_qla_host *vha, \
4919 fc_port_t *fcport, uint16_t *data) \
4920{ \
4921 struct qla_work_evt *e; \
4922 \
4923 e = qla2x00_alloc_work(vha, type); \
4924 if (!e) \
4925 return QLA_FUNCTION_FAILED; \
4926 \
4927 e->u.logio.fcport = fcport; \
4928 if (data) { \
4929 e->u.logio.data[0] = data[0]; \
4930 e->u.logio.data[1] = data[1]; \
4931 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08004932 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07004933 return qla2x00_post_work(vha, e); \
4934}
4935
4936qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004937qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4938qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004939qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
Quinn Tran11aea162017-12-28 12:33:20 -08004940qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4941qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004942
Andrew Vasquez3420d362009-10-13 15:16:45 -07004943int
4944qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4945{
4946 struct qla_work_evt *e;
4947
4948 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4949 if (!e)
4950 return QLA_FUNCTION_FAILED;
4951
4952 e->u.uevent.code = code;
4953 return qla2x00_post_work(vha, e);
4954}
4955
4956static void
4957qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4958{
4959 char event_string[40];
4960 char *envp[] = { event_string, NULL };
4961
4962 switch (code) {
4963 case QLA_UEVENT_CODE_FW_DUMP:
4964 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4965 vha->host_no);
4966 break;
4967 default:
4968 /* do nothing */
4969 break;
4970 }
4971 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4972}
4973
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004974int
4975qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4976 uint32_t *data, int cnt)
4977{
4978 struct qla_work_evt *e;
4979
4980 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4981 if (!e)
4982 return QLA_FUNCTION_FAILED;
4983
4984 e->u.aenfx.evtcode = evtcode;
4985 e->u.aenfx.count = cnt;
4986 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4987 return qla2x00_post_work(vha, e);
4988}
4989
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004990void qla24xx_sched_upd_fcport(fc_port_t *fcport)
Quinn Tran726b8542017-01-19 22:28:00 -08004991{
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004992 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08004993
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004994 if (IS_SW_RESV_ADDR(fcport->d_id))
4995 return;
Quinn Tran726b8542017-01-19 22:28:00 -08004996
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004997 spin_lock_irqsave(&fcport->vha->work_lock, flags);
4998 if (fcport->disc_state == DSC_UPD_FCPORT) {
4999 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5000 return;
5001 }
5002 fcport->jiffies_at_registration = jiffies;
5003 fcport->sec_since_registration = 0;
5004 fcport->next_disc_state = DSC_DELETED;
5005 fcport->disc_state = DSC_UPD_FCPORT;
5006 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5007
5008 queue_work(system_unbound_wq, &fcport->reg_work);
Quinn Tran726b8542017-01-19 22:28:00 -08005009}
5010
5011static
5012void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5013{
5014 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07005015 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08005016 struct qlt_plogi_ack_t *pla =
5017 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07005018 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005019
Quinn Tran9cd883f2017-12-28 12:33:24 -08005020 ql_dbg(ql_dbg_disc, vha, 0xffff,
5021 "%s %d %8phC enter\n",
5022 __func__, __LINE__, e->u.new_sess.port_name);
5023
Quinn Tran726b8542017-01-19 22:28:00 -08005024 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5025 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5026 if (fcport) {
5027 fcport->d_id = e->u.new_sess.id;
5028 if (pla) {
5029 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005030 memcpy(fcport->node_name,
5031 pla->iocb.u.isp24.u.plogi.node_name,
5032 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08005033 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5034 /* we took an extra ref_count to prevent PLOGI ACK when
5035 * fcport/sess has not been created.
5036 */
5037 pla->ref_count--;
5038 }
5039 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07005040 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08005041 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5042 if (fcport) {
5043 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08005044 fcport->flags |= FCF_FABRIC_DEVICE;
5045 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005046 if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08005047 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08005048
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005049 if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08005050 fcport->fc4_type = FC4_TYPE_OTHER;
5051 fcport->fc4f_nvme = FC4_TYPE_NVME;
5052 }
Quinn Tran33b28352018-03-20 23:09:40 -07005053
Quinn Tran726b8542017-01-19 22:28:00 -08005054 memcpy(fcport->port_name, e->u.new_sess.port_name,
5055 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07005056 } else {
5057 ql_dbg(ql_dbg_disc, vha, 0xffff,
5058 "%s %8phC mem alloc fail.\n",
5059 __func__, e->u.new_sess.port_name);
5060
5061 if (pla)
5062 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5063 return;
5064 }
5065
5066 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08005067 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07005068 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5069 e->u.new_sess.port_name, 1);
5070 if (tfcp) {
5071 /* should rarily happen */
5072 ql_dbg(ql_dbg_disc, vha, 0xffff,
5073 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5074 __func__, tfcp->port_name, tfcp->disc_state,
5075 tfcp->fw_login_state);
5076
5077 free_fcport = 1;
5078 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08005079 list_add_tail(&fcport->list, &vha->vp_fcports);
5080
Quinn Tran19759032017-12-04 14:45:15 -08005081 }
5082 if (pla) {
5083 qlt_plogi_ack_link(vha, pla, fcport,
5084 QLT_PLOGI_LINK_SAME_WWN);
5085 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08005086 }
5087 }
5088 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5089
5090 if (fcport) {
Quinn Trana4239942017-12-28 12:33:26 -08005091 fcport->id_changed = 1;
5092 fcport->scan_state = QLA_FCPORT_FOUND;
5093 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5094
Quinn Tran5ef696a2017-12-04 14:45:05 -08005095 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005096 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5097 u16 wd3_lo;
5098
5099 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5100 fcport->local = 0;
5101 fcport->loop_id =
5102 le16_to_cpu(
5103 pla->iocb.u.isp24.nport_handle);
5104 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5105 wd3_lo =
5106 le16_to_cpu(
5107 pla->iocb.u.isp24.u.prli.wd3_lo);
5108
5109 if (wd3_lo & BIT_7)
5110 fcport->conf_compl_supported = 1;
5111
5112 if ((wd3_lo & BIT_4) == 0)
5113 fcport->port_type = FCT_INITIATOR;
5114 else
5115 fcport->port_type = FCT_TARGET;
5116 }
Quinn Tran726b8542017-01-19 22:28:00 -08005117 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08005118 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005119 fc_port_t *dfcp = NULL;
5120
Quinn Tran5ef696a2017-12-04 14:45:05 -08005121 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5122 tfcp = qla2x00_find_fcport_by_nportid(vha,
5123 &e->u.new_sess.id, 1);
5124 if (tfcp && (tfcp != fcport)) {
5125 /*
5126 * We have a conflict fcport with same NportID.
5127 */
5128 ql_dbg(ql_dbg_disc, vha, 0xffff,
5129 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5130 __func__, tfcp->port_name, tfcp->disc_state,
5131 tfcp->fw_login_state);
5132
5133 switch (tfcp->disc_state) {
5134 case DSC_DELETED:
5135 break;
5136 case DSC_DELETE_PEND:
5137 fcport->login_pause = 1;
5138 tfcp->conflict = fcport;
5139 break;
5140 default:
5141 fcport->login_pause = 1;
5142 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005143 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08005144 break;
5145 }
5146 }
5147 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005148 if (dfcp)
5149 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08005150
Quinn Trana4239942017-12-28 12:33:26 -08005151
Quinn Tran8777e432018-08-02 13:16:57 -07005152 if (N2N_TOPO(vha->hw))
5153 fcport->flags &= ~FCF_FABRIC_DEVICE;
5154
5155 if (N2N_TOPO(vha->hw)) {
5156 if (vha->flags.nvme_enabled) {
5157 fcport->fc4f_nvme = 1;
5158 fcport->n2n_flag = 1;
5159 }
5160 fcport->fw_login_state = 0;
5161 /*
5162 * wait link init done before sending login
5163 */
5164 } else {
5165 qla24xx_fcport_handle_login(vha, fcport);
5166 }
Quinn Tran5ef696a2017-12-04 14:45:05 -08005167 }
Quinn Tran726b8542017-01-19 22:28:00 -08005168 }
Quinn Tranb5d15312017-08-30 10:16:49 -07005169
5170 if (free_fcport) {
5171 qla2x00_free_fcport(fcport);
5172 if (pla)
5173 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5174 }
Quinn Tran726b8542017-01-19 22:28:00 -08005175}
5176
Quinn Trane374f9f2017-12-28 12:33:31 -08005177static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5178{
5179 struct srb *sp = e->u.iosb.sp;
5180 int rval;
5181
5182 rval = qla2x00_start_sp(sp);
5183 if (rval != QLA_SUCCESS) {
5184 ql_dbg(ql_dbg_disc, vha, 0x2043,
5185 "%s: %s: Re-issue IOCB failed (%d).\n",
5186 __func__, sp->name, rval);
5187 qla24xx_sp_unmap(vha, sp);
5188 }
5189}
5190
Andrew Vasquezac280b62009-08-20 11:06:05 -07005191void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005192qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07005193{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005194 struct qla_work_evt *e, *tmp;
5195 unsigned long flags;
5196 LIST_HEAD(work);
Quinn Tran80676d02019-01-24 23:23:42 -08005197 int rc;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005198
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005199 spin_lock_irqsave(&vha->work_lock, flags);
5200 list_splice_init(&vha->work_list, &work);
5201 spin_unlock_irqrestore(&vha->work_lock, flags);
5202
5203 list_for_each_entry_safe(e, tmp, &work, list) {
Quinn Tran80676d02019-01-24 23:23:42 -08005204 rc = QLA_SUCCESS;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005205 switch (e->type) {
5206 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005207 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07005208 e->u.aen.code, e->u.aen.data);
5209 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08005210 case QLA_EVT_IDC_ACK:
5211 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5212 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005213 case QLA_EVT_ASYNC_LOGIN:
5214 qla2x00_async_login(vha, e->u.logio.fcport,
5215 e->u.logio.data);
5216 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005217 case QLA_EVT_ASYNC_LOGOUT:
Quinn Tran80676d02019-01-24 23:23:42 -08005218 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07005219 break;
5220 case QLA_EVT_ASYNC_LOGOUT_DONE:
5221 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5222 e->u.logio.data);
5223 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005224 case QLA_EVT_ASYNC_ADISC:
5225 qla2x00_async_adisc(vha, e->u.logio.fcport,
5226 e->u.logio.data);
5227 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005228 case QLA_EVT_UEVENT:
5229 qla2x00_uevent_emit(vha, e->u.uevent.code);
5230 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005231 case QLA_EVT_AENFX:
5232 qlafx00_process_aen(vha, e);
5233 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005234 case QLA_EVT_GPNID:
5235 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5236 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005237 case QLA_EVT_UNMAP:
5238 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005239 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005240 case QLA_EVT_RELOGIN:
5241 qla2x00_relogin(vha);
5242 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005243 case QLA_EVT_NEW_SESS:
5244 qla24xx_create_new_sess(vha, e);
5245 break;
5246 case QLA_EVT_GPDB:
5247 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5248 e->u.fcport.opt);
5249 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005250 case QLA_EVT_PRLI:
5251 qla24xx_async_prli(vha, e->u.fcport.fcport);
5252 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005253 case QLA_EVT_GPSC:
5254 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5255 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005256 case QLA_EVT_GNL:
5257 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5258 break;
5259 case QLA_EVT_NACK:
5260 qla24xx_do_nack_work(vha, e);
5261 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005262 case QLA_EVT_ASYNC_PRLO:
Quinn Tran80676d02019-01-24 23:23:42 -08005263 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
Quinn Tran11aea162017-12-28 12:33:20 -08005264 break;
5265 case QLA_EVT_ASYNC_PRLO_DONE:
5266 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5267 e->u.logio.data);
5268 break;
Quinn Trana4239942017-12-28 12:33:26 -08005269 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005270 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5271 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005272 break;
5273 case QLA_EVT_GPNFT_DONE:
5274 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5275 break;
5276 case QLA_EVT_GNNFT_DONE:
5277 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5278 break;
5279 case QLA_EVT_GNNID:
5280 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5281 break;
5282 case QLA_EVT_GFPNID:
5283 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5284 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005285 case QLA_EVT_SP_RETRY:
5286 qla_sp_retry(vha, e);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005287 break;
5288 case QLA_EVT_IIDMA:
5289 qla_do_iidma_work(vha, e->u.fcport.fcport);
5290 break;
Quinn Tran8777e432018-08-02 13:16:57 -07005291 case QLA_EVT_ELS_PLOGI:
5292 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5293 e->u.fcport.fcport, false);
5294 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005295 }
Quinn Tran80676d02019-01-24 23:23:42 -08005296
5297 if (rc == EAGAIN) {
5298 /* put 'work' at head of 'vha->work_list' */
5299 spin_lock_irqsave(&vha->work_lock, flags);
5300 list_splice(&work, &vha->work_list);
5301 spin_unlock_irqrestore(&vha->work_lock, flags);
5302 break;
5303 }
5304 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005305 if (e->flags & QLA_EVT_FLAG_FREE)
5306 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005307
5308 /* For each work completed decrement vha ref count */
5309 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005310 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005311}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005312
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005313int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5314{
5315 struct qla_work_evt *e;
5316
5317 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5318
5319 if (!e) {
5320 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5321 return QLA_FUNCTION_FAILED;
5322 }
5323
5324 return qla2x00_post_work(vha, e);
5325}
5326
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005327/* Relogins all the fcports of a vport
5328 * Context: dpc thread
5329 */
5330void qla2x00_relogin(struct scsi_qla_host *vha)
5331{
5332 fc_port_t *fcport;
Quinn Tran23dd98a2018-08-02 13:16:45 -07005333 int status, relogin_needed = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005334 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005335
5336 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005337 /*
5338 * If the port is not ONLINE then try to login
5339 * to it if we haven't run out of retries.
5340 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005341 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran23dd98a2018-08-02 13:16:45 -07005342 fcport->login_retry) {
5343 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5344 fcport->disc_state == DSC_LOGIN_COMPLETE)
5345 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005346
Quinn Tran23dd98a2018-08-02 13:16:45 -07005347 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5348 fcport->disc_state == DSC_DELETE_PEND) {
5349 relogin_needed = 1;
5350 } else {
5351 if (vha->hw->current_topology != ISP_CFG_NL) {
5352 memset(&ea, 0, sizeof(ea));
5353 ea.event = FCME_RELOGIN;
5354 ea.fcport = fcport;
5355 qla2x00_fcport_event_handler(vha, &ea);
5356 } else if (vha->hw->current_topology ==
5357 ISP_CFG_NL) {
5358 fcport->login_retry--;
5359 status =
5360 qla2x00_local_device_login(vha,
5361 fcport);
5362 if (status == QLA_SUCCESS) {
5363 fcport->old_loop_id =
5364 fcport->loop_id;
5365 ql_dbg(ql_dbg_disc, vha, 0x2003,
5366 "Port login OK: logged in ID 0x%x.\n",
5367 fcport->loop_id);
5368 qla2x00_update_fcport
5369 (vha, fcport);
5370 } else if (status == 1) {
5371 set_bit(RELOGIN_NEEDED,
5372 &vha->dpc_flags);
5373 /* retry the login again */
5374 ql_dbg(ql_dbg_disc, vha, 0x2007,
5375 "Retrying %d login again loop_id 0x%x.\n",
5376 fcport->login_retry,
5377 fcport->loop_id);
5378 } else {
5379 fcport->login_retry = 0;
5380 }
5381
5382 if (fcport->login_retry == 0 &&
5383 status != QLA_SUCCESS)
5384 qla2x00_clear_loop_id(fcport);
5385 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005386 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005387 }
5388 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5389 break;
5390 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005391
Quinn Tran23dd98a2018-08-02 13:16:45 -07005392 if (relogin_needed)
5393 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5394
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005395 ql_dbg(ql_dbg_disc, vha, 0x400e,
5396 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005397}
5398
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005399/* Schedule work on any of the dpc-workqueues */
5400void
5401qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5402{
5403 struct qla_hw_data *ha = base_vha->hw;
5404
5405 switch (work_code) {
5406 case MBA_IDC_AEN: /* 0x8200 */
5407 if (ha->dpc_lp_wq)
5408 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5409 break;
5410
5411 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5412 if (!ha->flags.nic_core_reset_hdlr_active) {
5413 if (ha->dpc_hp_wq)
5414 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5415 } else
5416 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5417 "NIC Core reset is already active. Skip "
5418 "scheduling it again.\n");
5419 break;
5420 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5421 if (ha->dpc_hp_wq)
5422 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5423 break;
5424 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5425 if (ha->dpc_hp_wq)
5426 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5427 break;
5428 default:
5429 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005430 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005431 }
5432
5433 return;
5434}
5435
5436/* Work: Perform NIC Core Unrecoverable state handling */
5437void
5438qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5439{
5440 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005441 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005442 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5443 uint32_t dev_state = 0;
5444
5445 qla83xx_idc_lock(base_vha, 0);
5446 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5447 qla83xx_reset_ownership(base_vha);
5448 if (ha->flags.nic_core_reset_owner) {
5449 ha->flags.nic_core_reset_owner = 0;
5450 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5451 QLA8XXX_DEV_FAILED);
5452 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5453 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5454 }
5455 qla83xx_idc_unlock(base_vha, 0);
5456}
5457
5458/* Work: Execute IDC state handler */
5459void
5460qla83xx_idc_state_handler_work(struct work_struct *work)
5461{
5462 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005463 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005464 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5465 uint32_t dev_state = 0;
5466
5467 qla83xx_idc_lock(base_vha, 0);
5468 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5469 if (dev_state == QLA8XXX_DEV_FAILED ||
5470 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5471 qla83xx_idc_state_handler(base_vha);
5472 qla83xx_idc_unlock(base_vha, 0);
5473}
5474
Saurav Kashyapfa492632012-11-21 02:40:29 -05005475static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005476qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5477{
5478 int rval = QLA_SUCCESS;
5479 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5480 uint32_t heart_beat_counter1, heart_beat_counter2;
5481
5482 do {
5483 if (time_after(jiffies, heart_beat_wait)) {
5484 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5485 "Nic Core f/w is not alive.\n");
5486 rval = QLA_FUNCTION_FAILED;
5487 break;
5488 }
5489
5490 qla83xx_idc_lock(base_vha, 0);
5491 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5492 &heart_beat_counter1);
5493 qla83xx_idc_unlock(base_vha, 0);
5494 msleep(100);
5495 qla83xx_idc_lock(base_vha, 0);
5496 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5497 &heart_beat_counter2);
5498 qla83xx_idc_unlock(base_vha, 0);
5499 } while (heart_beat_counter1 == heart_beat_counter2);
5500
5501 return rval;
5502}
5503
5504/* Work: Perform NIC Core Reset handling */
5505void
5506qla83xx_nic_core_reset_work(struct work_struct *work)
5507{
5508 struct qla_hw_data *ha =
5509 container_of(work, struct qla_hw_data, nic_core_reset);
5510 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5511 uint32_t dev_state = 0;
5512
Saurav Kashyap81178772012-08-22 14:21:04 -04005513 if (IS_QLA2031(ha)) {
5514 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5515 ql_log(ql_log_warn, base_vha, 0xb081,
5516 "Failed to dump mctp\n");
5517 return;
5518 }
5519
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005520 if (!ha->flags.nic_core_reset_hdlr_active) {
5521 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5522 qla83xx_idc_lock(base_vha, 0);
5523 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5524 &dev_state);
5525 qla83xx_idc_unlock(base_vha, 0);
5526 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5527 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5528 "Nic Core f/w is alive.\n");
5529 return;
5530 }
5531 }
5532
5533 ha->flags.nic_core_reset_hdlr_active = 1;
5534 if (qla83xx_nic_core_reset(base_vha)) {
5535 /* NIC Core reset failed. */
5536 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5537 "NIC Core reset failed.\n");
5538 }
5539 ha->flags.nic_core_reset_hdlr_active = 0;
5540 }
5541}
5542
5543/* Work: Handle 8200 IDC aens */
5544void
5545qla83xx_service_idc_aen(struct work_struct *work)
5546{
5547 struct qla_hw_data *ha =
5548 container_of(work, struct qla_hw_data, idc_aen);
5549 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5550 uint32_t dev_state, idc_control;
5551
5552 qla83xx_idc_lock(base_vha, 0);
5553 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5554 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5555 qla83xx_idc_unlock(base_vha, 0);
5556 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5557 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5558 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5559 "Application requested NIC Core Reset.\n");
5560 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5561 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5562 QLA_SUCCESS) {
5563 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5564 "Other protocol driver requested NIC Core Reset.\n");
5565 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5566 }
5567 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5568 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5569 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5570 }
5571}
5572
5573static void
5574qla83xx_wait_logic(void)
5575{
5576 int i;
5577
5578 /* Yield CPU */
5579 if (!in_interrupt()) {
5580 /*
5581 * Wait about 200ms before retrying again.
5582 * This controls the number of retries for single
5583 * lock operation.
5584 */
5585 msleep(100);
5586 schedule();
5587 } else {
5588 for (i = 0; i < 20; i++)
5589 cpu_relax(); /* This a nop instr on i386 */
5590 }
5591}
5592
Saurav Kashyapfa492632012-11-21 02:40:29 -05005593static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005594qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5595{
5596 int rval;
5597 uint32_t data;
5598 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5599 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5600 struct qla_hw_data *ha = base_vha->hw;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07005601
Saurav Kashyap6c315552013-02-08 01:57:53 -05005602 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5603 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005604
5605 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5606 if (rval)
5607 return rval;
5608
5609 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5610 return QLA_SUCCESS;
5611 } else {
5612 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5613 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5614 data);
5615 if (rval)
5616 return rval;
5617
5618 msleep(200);
5619
5620 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5621 &data);
5622 if (rval)
5623 return rval;
5624
5625 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5626 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5627 ~(idc_lck_rcvry_stage_mask));
5628 rval = qla83xx_wr_reg(base_vha,
5629 QLA83XX_IDC_LOCK_RECOVERY, data);
5630 if (rval)
5631 return rval;
5632
5633 /* Forcefully perform IDC UnLock */
5634 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5635 &data);
5636 if (rval)
5637 return rval;
5638 /* Clear lock-id by setting 0xff */
5639 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5640 0xff);
5641 if (rval)
5642 return rval;
5643 /* Clear lock-recovery by setting 0x0 */
5644 rval = qla83xx_wr_reg(base_vha,
5645 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5646 if (rval)
5647 return rval;
5648 } else
5649 return QLA_SUCCESS;
5650 }
5651
5652 return rval;
5653}
5654
Saurav Kashyapfa492632012-11-21 02:40:29 -05005655static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005656qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5657{
5658 int rval = QLA_SUCCESS;
5659 uint32_t o_drv_lockid, n_drv_lockid;
5660 unsigned long lock_recovery_timeout;
5661
5662 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5663retry_lockid:
5664 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5665 if (rval)
5666 goto exit;
5667
5668 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5669 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5670 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5671 return QLA_SUCCESS;
5672 else
5673 return QLA_FUNCTION_FAILED;
5674 }
5675
5676 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5677 if (rval)
5678 goto exit;
5679
5680 if (o_drv_lockid == n_drv_lockid) {
5681 qla83xx_wait_logic();
5682 goto retry_lockid;
5683 } else
5684 return QLA_SUCCESS;
5685
5686exit:
5687 return rval;
5688}
5689
5690void
5691qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5692{
5693 uint16_t options = (requester_id << 15) | BIT_6;
5694 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005695 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005696 struct qla_hw_data *ha = base_vha->hw;
5697
5698 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5699retry_lock:
5700 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5701 == QLA_SUCCESS) {
5702 if (data) {
5703 /* Setting lock-id to our function-number */
5704 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5705 ha->portnum);
5706 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005707 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5708 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005709 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005710 "Failed to acquire IDC lock, acquired by %d, "
5711 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005712
5713 /* Retry/Perform IDC-Lock recovery */
5714 if (qla83xx_idc_lock_recovery(base_vha)
5715 == QLA_SUCCESS) {
5716 qla83xx_wait_logic();
5717 goto retry_lock;
5718 } else
5719 ql_log(ql_log_warn, base_vha, 0xb075,
5720 "IDC Lock recovery FAILED.\n");
5721 }
5722
5723 }
5724
5725 return;
5726
5727 /* XXX: IDC-lock implementation using access-control mbx */
5728retry_lock2:
5729 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5730 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5731 "Failed to acquire IDC lock. retrying...\n");
5732 /* Retry/Perform IDC-Lock recovery */
5733 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5734 qla83xx_wait_logic();
5735 goto retry_lock2;
5736 } else
5737 ql_log(ql_log_warn, base_vha, 0xb076,
5738 "IDC Lock recovery FAILED.\n");
5739 }
5740
5741 return;
5742}
5743
5744void
5745qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5746{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005747#if 0
5748 uint16_t options = (requester_id << 15) | BIT_7;
5749#endif
5750 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005751 uint32_t data;
5752 struct qla_hw_data *ha = base_vha->hw;
5753
5754 /* IDC-unlock implementation using driver-unlock/lock-id
5755 * remote registers
5756 */
5757 retry = 0;
5758retry_unlock:
5759 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5760 == QLA_SUCCESS) {
5761 if (data == ha->portnum) {
5762 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5763 /* Clearing lock-id by setting 0xff */
5764 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5765 } else if (retry < 10) {
5766 /* SV: XXX: IDC unlock retrying needed here? */
5767
5768 /* Retry for IDC-unlock */
5769 qla83xx_wait_logic();
5770 retry++;
5771 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005772 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005773 goto retry_unlock;
5774 }
5775 } else if (retry < 10) {
5776 /* Retry for IDC-unlock */
5777 qla83xx_wait_logic();
5778 retry++;
5779 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005780 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005781 goto retry_unlock;
5782 }
5783
5784 return;
5785
Bart Van Assche5897cb22015-06-04 15:57:20 -07005786#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005787 /* XXX: IDC-unlock implementation using access-control mbx */
5788 retry = 0;
5789retry_unlock2:
5790 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5791 if (retry < 10) {
5792 /* Retry for IDC-unlock */
5793 qla83xx_wait_logic();
5794 retry++;
5795 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005796 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005797 goto retry_unlock2;
5798 }
5799 }
5800
5801 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005802#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005803}
5804
5805int
5806__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5807{
5808 int rval = QLA_SUCCESS;
5809 struct qla_hw_data *ha = vha->hw;
5810 uint32_t drv_presence;
5811
5812 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5813 if (rval == QLA_SUCCESS) {
5814 drv_presence |= (1 << ha->portnum);
5815 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5816 drv_presence);
5817 }
5818
5819 return rval;
5820}
5821
5822int
5823qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5824{
5825 int rval = QLA_SUCCESS;
5826
5827 qla83xx_idc_lock(vha, 0);
5828 rval = __qla83xx_set_drv_presence(vha);
5829 qla83xx_idc_unlock(vha, 0);
5830
5831 return rval;
5832}
5833
5834int
5835__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5836{
5837 int rval = QLA_SUCCESS;
5838 struct qla_hw_data *ha = vha->hw;
5839 uint32_t drv_presence;
5840
5841 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5842 if (rval == QLA_SUCCESS) {
5843 drv_presence &= ~(1 << ha->portnum);
5844 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5845 drv_presence);
5846 }
5847
5848 return rval;
5849}
5850
5851int
5852qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5853{
5854 int rval = QLA_SUCCESS;
5855
5856 qla83xx_idc_lock(vha, 0);
5857 rval = __qla83xx_clear_drv_presence(vha);
5858 qla83xx_idc_unlock(vha, 0);
5859
5860 return rval;
5861}
5862
Saurav Kashyapfa492632012-11-21 02:40:29 -05005863static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005864qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5865{
5866 struct qla_hw_data *ha = vha->hw;
5867 uint32_t drv_ack, drv_presence;
5868 unsigned long ack_timeout;
5869
5870 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5871 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5872 while (1) {
5873 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5874 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005875 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005876 break;
5877
5878 if (time_after_eq(jiffies, ack_timeout)) {
5879 ql_log(ql_log_warn, vha, 0xb067,
5880 "RESET ACK TIMEOUT! drv_presence=0x%x "
5881 "drv_ack=0x%x\n", drv_presence, drv_ack);
5882 /*
5883 * The function(s) which did not ack in time are forced
5884 * to withdraw any further participation in the IDC
5885 * reset.
5886 */
5887 if (drv_ack != drv_presence)
5888 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5889 drv_ack);
5890 break;
5891 }
5892
5893 qla83xx_idc_unlock(vha, 0);
5894 msleep(1000);
5895 qla83xx_idc_lock(vha, 0);
5896 }
5897
5898 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5899 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5900}
5901
Saurav Kashyapfa492632012-11-21 02:40:29 -05005902static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005903qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5904{
5905 int rval = QLA_SUCCESS;
5906 uint32_t idc_control;
5907
5908 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5909 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5910
5911 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5912 __qla83xx_get_idc_control(vha, &idc_control);
5913 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5914 __qla83xx_set_idc_control(vha, 0);
5915
5916 qla83xx_idc_unlock(vha, 0);
5917 rval = qla83xx_restart_nic_firmware(vha);
5918 qla83xx_idc_lock(vha, 0);
5919
5920 if (rval != QLA_SUCCESS) {
5921 ql_log(ql_log_fatal, vha, 0xb06a,
5922 "Failed to restart NIC f/w.\n");
5923 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5924 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5925 } else {
5926 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5927 "Success in restarting nic f/w.\n");
5928 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5929 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5930 }
5931
5932 return rval;
5933}
5934
5935/* Assumes idc_lock always held on entry */
5936int
5937qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5938{
5939 struct qla_hw_data *ha = base_vha->hw;
5940 int rval = QLA_SUCCESS;
5941 unsigned long dev_init_timeout;
5942 uint32_t dev_state;
5943
5944 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5945 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5946
5947 while (1) {
5948
5949 if (time_after_eq(jiffies, dev_init_timeout)) {
5950 ql_log(ql_log_warn, base_vha, 0xb06e,
5951 "Initialization TIMEOUT!\n");
5952 /* Init timeout. Disable further NIC Core
5953 * communication.
5954 */
5955 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5956 QLA8XXX_DEV_FAILED);
5957 ql_log(ql_log_info, base_vha, 0xb06f,
5958 "HW State: FAILED.\n");
5959 }
5960
5961 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5962 switch (dev_state) {
5963 case QLA8XXX_DEV_READY:
5964 if (ha->flags.nic_core_reset_owner)
5965 qla83xx_idc_audit(base_vha,
5966 IDC_AUDIT_COMPLETION);
5967 ha->flags.nic_core_reset_owner = 0;
5968 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5969 "Reset_owner reset by 0x%x.\n",
5970 ha->portnum);
5971 goto exit;
5972 case QLA8XXX_DEV_COLD:
5973 if (ha->flags.nic_core_reset_owner)
5974 rval = qla83xx_device_bootstrap(base_vha);
5975 else {
5976 /* Wait for AEN to change device-state */
5977 qla83xx_idc_unlock(base_vha, 0);
5978 msleep(1000);
5979 qla83xx_idc_lock(base_vha, 0);
5980 }
5981 break;
5982 case QLA8XXX_DEV_INITIALIZING:
5983 /* Wait for AEN to change device-state */
5984 qla83xx_idc_unlock(base_vha, 0);
5985 msleep(1000);
5986 qla83xx_idc_lock(base_vha, 0);
5987 break;
5988 case QLA8XXX_DEV_NEED_RESET:
5989 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5990 qla83xx_need_reset_handler(base_vha);
5991 else {
5992 /* Wait for AEN to change device-state */
5993 qla83xx_idc_unlock(base_vha, 0);
5994 msleep(1000);
5995 qla83xx_idc_lock(base_vha, 0);
5996 }
5997 /* reset timeout value after need reset handler */
5998 dev_init_timeout = jiffies +
5999 (ha->fcoe_dev_init_timeout * HZ);
6000 break;
6001 case QLA8XXX_DEV_NEED_QUIESCENT:
6002 /* XXX: DEBUG for now */
6003 qla83xx_idc_unlock(base_vha, 0);
6004 msleep(1000);
6005 qla83xx_idc_lock(base_vha, 0);
6006 break;
6007 case QLA8XXX_DEV_QUIESCENT:
6008 /* XXX: DEBUG for now */
6009 if (ha->flags.quiesce_owner)
6010 goto exit;
6011
6012 qla83xx_idc_unlock(base_vha, 0);
6013 msleep(1000);
6014 qla83xx_idc_lock(base_vha, 0);
6015 dev_init_timeout = jiffies +
6016 (ha->fcoe_dev_init_timeout * HZ);
6017 break;
6018 case QLA8XXX_DEV_FAILED:
6019 if (ha->flags.nic_core_reset_owner)
6020 qla83xx_idc_audit(base_vha,
6021 IDC_AUDIT_COMPLETION);
6022 ha->flags.nic_core_reset_owner = 0;
6023 __qla83xx_clear_drv_presence(base_vha);
6024 qla83xx_idc_unlock(base_vha, 0);
6025 qla8xxx_dev_failed_handler(base_vha);
6026 rval = QLA_FUNCTION_FAILED;
6027 qla83xx_idc_lock(base_vha, 0);
6028 goto exit;
6029 case QLA8XXX_BAD_VALUE:
6030 qla83xx_idc_unlock(base_vha, 0);
6031 msleep(1000);
6032 qla83xx_idc_lock(base_vha, 0);
6033 break;
6034 default:
6035 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09006036 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006037 qla83xx_idc_unlock(base_vha, 0);
6038 qla8xxx_dev_failed_handler(base_vha);
6039 rval = QLA_FUNCTION_FAILED;
6040 qla83xx_idc_lock(base_vha, 0);
6041 goto exit;
6042 }
6043 }
6044
6045exit:
6046 return rval;
6047}
6048
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006049void
6050qla2x00_disable_board_on_pci_error(struct work_struct *work)
6051{
6052 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6053 board_disable);
6054 struct pci_dev *pdev = ha->pdev;
6055 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6056
Quinn Tran726b8542017-01-19 22:28:00 -08006057 /*
6058 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04006059 * where it was set first.
6060 */
6061 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6062 return;
6063
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006064 ql_log(ql_log_warn, base_vha, 0x015b,
6065 "Disabling adapter.\n");
6066
Sawan Chandakefdb5762017-08-23 15:05:00 -07006067 if (!atomic_read(&pdev->enable_cnt)) {
6068 ql_log(ql_log_info, base_vha, 0xfffc,
6069 "PCI device disabled, no action req for PCI error=%lx\n",
6070 base_vha->pci_flags);
6071 return;
6072 }
6073
Quinn Tran726b8542017-01-19 22:28:00 -08006074 qla2x00_wait_for_sess_deletion(base_vha);
6075
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006076 set_bit(UNLOADING, &base_vha->dpc_flags);
6077
6078 qla2x00_delete_all_vps(ha, base_vha);
6079
6080 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6081
6082 qla2x00_dfs_remove(base_vha);
6083
6084 qla84xx_put_chip(base_vha);
6085
6086 if (base_vha->timer_active)
6087 qla2x00_stop_timer(base_vha);
6088
6089 base_vha->flags.online = 0;
6090
6091 qla2x00_destroy_deferred_work(ha);
6092
6093 /*
6094 * Do not try to stop beacon blink as it will issue a mailbox
6095 * command.
6096 */
6097 qla2x00_free_sysfs_attr(base_vha, false);
6098
6099 fc_remove_host(base_vha->host);
6100
6101 scsi_remove_host(base_vha->host);
6102
6103 base_vha->flags.init_done = 0;
6104 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006105 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08006106 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006107 qla2x00_mem_free(ha);
6108 qla82xx_md_free(base_vha);
6109 qla2x00_free_queues(ha);
6110
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006111 qla2x00_unmap_iobases(ha);
6112
6113 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006114 pci_disable_pcie_error_reporting(pdev);
6115 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006116
Joe Lawrencebeb9e312014-08-26 17:12:14 -04006117 /*
6118 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6119 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006120}
6121
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122/**************************************************************************
6123* qla2x00_do_dpc
6124* This kernel thread is a task that is schedule by the interrupt handler
6125* to perform the background processing for interrupts.
6126*
6127* Notes:
6128* This task always run in the context of a kernel thread. It
6129* is kick-off by the driver's detect code and starts up
6130* up one per adapter. It immediately goes to sleep and waits for
6131* some fibre event. When either the interrupt handler or
6132* the timer routine detects a event it will one of the task
6133* bits then wake us up.
6134**************************************************************************/
6135static int
6136qla2x00_do_dpc(void *data)
6137{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006138 scsi_qla_host_t *base_vha;
6139 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08006140 uint32_t online;
6141 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08006142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006143 ha = (struct qla_hw_data *)data;
6144 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145
Dongsheng Yang8698a742014-03-11 18:09:12 +08006146 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147
James Bottomley563585e2011-01-27 16:12:37 -05006148 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01006149 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006150 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6151 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152
Christoph Hellwig39a11242006-02-14 18:46:22 +01006153 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006154
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006155 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6156 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157
Andrew Vasquez85880802009-12-15 21:29:46 -08006158 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006159 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6160 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006161 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08006162 }
6163
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 ha->dpc_active = 1;
6165
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04006166 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6167 "DPC handler waking up, dpc_flags=0x%lx.\n",
6168 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04006170 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6171 break;
6172
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006173 if (IS_P3P_TYPE(ha)) {
6174 if (IS_QLA8044(ha)) {
6175 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6176 &base_vha->dpc_flags)) {
6177 qla8044_idc_lock(ha);
6178 qla8044_wr_direct(base_vha,
6179 QLA8044_CRB_DEV_STATE_INDEX,
6180 QLA8XXX_DEV_FAILED);
6181 qla8044_idc_unlock(ha);
6182 ql_log(ql_log_info, base_vha, 0x4004,
6183 "HW State: FAILED.\n");
6184 qla8044_device_state_handler(base_vha);
6185 continue;
6186 }
6187
6188 } else {
6189 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6190 &base_vha->dpc_flags)) {
6191 qla82xx_idc_lock(ha);
6192 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6193 QLA8XXX_DEV_FAILED);
6194 qla82xx_idc_unlock(ha);
6195 ql_log(ql_log_info, base_vha, 0x0151,
6196 "HW State: FAILED.\n");
6197 qla82xx_device_state_handler(base_vha);
6198 continue;
6199 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006200 }
6201
6202 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6203 &base_vha->dpc_flags)) {
6204
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006205 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6206 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006207 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6208 &base_vha->dpc_flags))) {
6209 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6210 /* FCoE-ctx reset failed.
6211 * Escalate to chip-reset
6212 */
6213 set_bit(ISP_ABORT_NEEDED,
6214 &base_vha->dpc_flags);
6215 }
6216 clear_bit(ABORT_ISP_ACTIVE,
6217 &base_vha->dpc_flags);
6218 }
6219
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006220 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6221 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006222 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006223 } else if (IS_QLAFX00(ha)) {
6224 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6225 &base_vha->dpc_flags)) {
6226 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6227 "Firmware Reset Recovery\n");
6228 if (qlafx00_reset_initialize(base_vha)) {
6229 /* Failed. Abort isp later. */
6230 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006231 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006232 set_bit(ISP_UNRECOVERABLE,
6233 &base_vha->dpc_flags);
6234 ql_dbg(ql_dbg_dpc, base_vha,
6235 0x4021,
6236 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006237 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006238 }
6239 }
6240
6241 if (test_and_clear_bit(FX00_TARGET_SCAN,
6242 &base_vha->dpc_flags)) {
6243 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6244 "ISPFx00 Target Scan scheduled\n");
6245 if (qlafx00_rescan_isp(base_vha)) {
6246 if (!test_bit(UNLOADING,
6247 &base_vha->dpc_flags))
6248 set_bit(ISP_UNRECOVERABLE,
6249 &base_vha->dpc_flags);
6250 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6251 "ISPFx00 Target Scan Failed\n");
6252 }
6253 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6254 "ISPFx00 Target Scan End\n");
6255 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006256 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6257 &base_vha->dpc_flags)) {
6258 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6259 "ISPFx00 Host Info resend scheduled\n");
6260 qlafx00_fx_disc(base_vha,
6261 &base_vha->hw->mr.fcport,
6262 FXDISC_REG_HOST_INFO);
6263 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006264 }
6265
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006266 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6267 &base_vha->dpc_flags) &&
6268 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6269 qla24xx_detect_sfp(base_vha);
6270
6271 if (ha->flags.detected_lr_sfp !=
6272 ha->flags.using_lr_setting)
6273 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6274 }
6275
Quinn Tranb08abbd2018-07-18 14:29:54 -07006276 if (test_and_clear_bit
6277 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6278 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran93eca612018-08-31 11:24:37 -07006279 bool do_reset = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280
Quinn Tran0645cb82018-09-11 10:18:18 -07006281 switch (base_vha->qlini_mode) {
Quinn Tran93eca612018-08-31 11:24:37 -07006282 case QLA2XXX_INI_MODE_ENABLED:
6283 break;
6284 case QLA2XXX_INI_MODE_DISABLED:
Quinn Tran0645cb82018-09-11 10:18:18 -07006285 if (!qla_tgt_mode_enabled(base_vha) &&
6286 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006287 do_reset = false;
6288 break;
6289 case QLA2XXX_INI_MODE_DUAL:
Quinn Tran0645cb82018-09-11 10:18:18 -07006290 if (!qla_dual_mode_enabled(base_vha) &&
6291 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006292 do_reset = false;
6293 break;
6294 default:
6295 break;
6296 }
6297
6298 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006299 &base_vha->dpc_flags))) {
Quinn Tran93eca612018-08-31 11:24:37 -07006300 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6301 "ISP abort scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006302 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 /* failed. retry later */
6304 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006305 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006307 clear_bit(ABORT_ISP_ACTIVE,
6308 &base_vha->dpc_flags);
Quinn Tran93eca612018-08-31 11:24:37 -07006309 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6310 "ISP abort end.\n");
Seokmann Ju99363ef2008-01-31 12:33:51 -08006311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 }
6313
David Jefferya394aac2012-11-21 02:39:54 -05006314 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6315 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006316 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006317 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006318
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006319 if (IS_QLAFX00(ha))
6320 goto loop_resync_check;
6321
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006322 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006323 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6324 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006325 if (IS_P3P_TYPE(ha)) {
6326 if (IS_QLA82XX(ha))
6327 qla82xx_device_state_handler(base_vha);
6328 if (IS_QLA8044(ha))
6329 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006330 clear_bit(ISP_QUIESCE_NEEDED,
6331 &base_vha->dpc_flags);
6332 if (!ha->flags.quiesce_owner) {
6333 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006334 if (IS_QLA82XX(ha)) {
6335 qla82xx_idc_lock(ha);
6336 qla82xx_clear_qsnt_ready(
6337 base_vha);
6338 qla82xx_idc_unlock(ha);
6339 } else if (IS_QLA8044(ha)) {
6340 qla8044_idc_lock(ha);
6341 qla8044_clear_qsnt_ready(
6342 base_vha);
6343 qla8044_idc_unlock(ha);
6344 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006345 }
6346 } else {
6347 clear_bit(ISP_QUIESCE_NEEDED,
6348 &base_vha->dpc_flags);
6349 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006350 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006351 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6352 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006353 }
6354
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006355 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006356 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006357 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006359 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6360 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006361 qla2x00_rst_aen(base_vha);
6362 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006363 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6364 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365 }
6366
6367 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006368 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006369 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6370 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371
Quinn Tran4005a992017-12-04 14:45:06 -08006372 if (!base_vha->relogin_jif ||
6373 time_after_eq(jiffies, base_vha->relogin_jif)) {
6374 base_vha->relogin_jif = jiffies + HZ;
6375 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6376
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006377 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006378 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006379 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006382loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006383 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006384 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006386 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6387 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388
6389 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006390 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391
Bart Van Assche52c82822015-07-09 07:23:26 -07006392 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006394 clear_bit(LOOP_RESYNC_ACTIVE,
6395 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396 }
6397
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006398 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6399 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 }
6401
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006402 if (IS_QLAFX00(ha))
6403 goto intr_on_check;
6404
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006405 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6406 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6407 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6408 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006409 }
6410
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006411intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006413 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006415 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006416 &base_vha->dpc_flags)) {
6417 if (ha->beacon_blink_led == 1)
6418 ha->isp_ops->beacon_blink(base_vha);
6419 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006420
Michael Hernandezd7459522016-12-12 14:40:07 -08006421 /* qpair online check */
6422 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6423 &base_vha->dpc_flags)) {
6424 if (ha->flags.eeh_busy ||
6425 ha->flags.pci_channel_io_perm_failure)
6426 online = 0;
6427 else
6428 online = 1;
6429
6430 mutex_lock(&ha->mq_lock);
6431 list_for_each_entry(qpair, &base_vha->qp_list,
6432 qp_list_elem)
6433 qpair->online = online;
6434 mutex_unlock(&ha->mq_lock);
6435 }
6436
Quinn Tran8b4673b2018-09-04 14:19:14 -07006437 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6438 &base_vha->dpc_flags)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006439 ql_log(ql_log_info, base_vha, 0xffffff,
6440 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6441 ha->nvme_last_rptd_aen);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006442 if (qla27xx_set_zio_threshold(base_vha,
6443 ha->nvme_last_rptd_aen)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006444 ql_log(ql_log_info, base_vha, 0xffffff,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006445 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6446 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006447 }
6448 }
6449
Quinn Tran8b4673b2018-09-04 14:19:14 -07006450 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6451 &base_vha->dpc_flags)) {
6452 ql_log(ql_log_info, base_vha, 0xffffff,
6453 "SET ZIO Activity exchange threshold to %d.\n",
6454 ha->last_zio_threshold);
6455 qla27xx_set_zio_threshold(base_vha,
6456 ha->last_zio_threshold);
6457 }
6458
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006459 if (!IS_QLAFX00(ha))
6460 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006461
Quinn Tran48acad02018-08-02 13:16:44 -07006462 if (test_and_clear_bit(N2N_LINK_RESET,
6463 &base_vha->dpc_flags)) {
6464 qla2x00_lip_reset(base_vha);
6465 }
6466
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006468end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006469 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006471 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006473 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6474 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475
6476 /*
6477 * Make sure that nobody tries to wake us up again.
6478 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479 ha->dpc_active = 0;
6480
Andrew Vasquezac280b62009-08-20 11:06:05 -07006481 /* Cleanup any residual CTX SRBs. */
6482 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6483
Christoph Hellwig39a11242006-02-14 18:46:22 +01006484 return 0;
6485}
6486
6487void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006488qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006489{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006490 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006491 struct task_struct *t = ha->dpc_thread;
6492
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006493 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006494 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495}
6496
6497/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498* qla2x00_rst_aen
6499* Processes asynchronous reset.
6500*
6501* Input:
6502* ha = adapter block pointer.
6503*/
6504static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006505qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006507 if (vha->flags.online && !vha->flags.reset_active &&
6508 !atomic_read(&vha->loop_down_timer) &&
6509 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006511 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512
6513 /*
6514 * Issue marker command only when we are going to start
6515 * the I/O.
6516 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006517 vha->marker_needed = 1;
6518 } while (!atomic_read(&vha->loop_down_timer) &&
6519 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 }
6521}
6522
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523/**************************************************************************
6524* qla2x00_timer
6525*
6526* Description:
6527* One second timer
6528*
6529* Context: Interrupt
6530***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006531void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006532qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006534 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 int start_dpc = 0;
6537 int index;
6538 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006539 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006540 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006541 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006542
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006543 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006544 ql_dbg(ql_dbg_timer, vha, 0x6000,
6545 "EEH = %d, restarting timer.\n",
6546 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006547 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6548 return;
6549 }
6550
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006551 /*
6552 * Hardware read to raise pending EEH errors during mailbox waits. If
6553 * the read returns -1 then disable the board.
6554 */
6555 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006556 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006557 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006560 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006561 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006562 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6563 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006564 if (IS_QLA82XX(ha))
6565 qla82xx_watchdog(vha);
6566 else if (IS_QLA8044(ha))
6567 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006568 }
6569
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006570 if (!vha->vp_idx && IS_QLAFX00(ha))
6571 qlafx00_timer_routine(vha);
6572
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006574 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006575 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6576 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006577 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006579 if (atomic_read(&vha->loop_down_timer) ==
6580 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006582 ql_log(ql_log_info, vha, 0x6008,
6583 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006585 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6586 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006588 /*
6589 * Schedule an ISP abort to return any FCP2-device
6590 * commands.
6591 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006592 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006593 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006594 spin_lock_irqsave(&ha->hardware_lock,
6595 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006596 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006597 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006598 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006599 index++) {
6600 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006602 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006603 if (!sp)
6604 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006605 if (sp->cmd_type != TYPE_SRB)
6606 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006607 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006608 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006609 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006610 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006611 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006613 if (IS_QLA82XX(ha))
6614 set_bit(FCOE_CTX_RESET_NEEDED,
6615 &vha->dpc_flags);
6616 else
6617 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006618 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006619 break;
6620 }
6621 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006622 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 start_dpc++;
6625 }
6626
6627 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006628 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006629 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006630 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 "Loop down - aborting ISP.\n");
6632
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006633 if (IS_QLA82XX(ha))
6634 set_bit(FCOE_CTX_RESET_NEEDED,
6635 &vha->dpc_flags);
6636 else
6637 set_bit(ISP_ABORT_NEEDED,
6638 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639 }
6640 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006641 ql_dbg(ql_dbg_timer, vha, 0x600a,
6642 "Loop down - seconds remaining %d.\n",
6643 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006645 /* Check if beacon LED needs to be blinked for physical host only */
6646 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006647 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006648 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006649 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6650 start_dpc++;
6651 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006652 }
6653
Andrew Vasquez550bf572008-04-24 15:21:23 -07006654 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006655 if (!list_empty(&vha->work_list)) {
6656 unsigned long flags;
6657 bool q = false;
6658
6659 spin_lock_irqsave(&vha->work_lock, flags);
6660 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6661 q = true;
6662 spin_unlock_irqrestore(&vha->work_lock, flags);
6663 if (q)
6664 queue_work(vha->hw->wq, &vha->iocb_work);
6665 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006666
Duane Grigsby7401bc12017-06-21 13:48:42 -07006667 /*
6668 * FC-NVME
6669 * see if the active AEN count has changed from what was last reported.
6670 */
Giridhar Malavalib2d1453a2019-04-02 14:24:32 -07006671 if (!vha->vp_idx &&
6672 (atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen) &&
6673 ha->zio_mode == QLA_ZIO_MODE_6 &&
6674 !ha->flags.host_shutting_down) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006675 ql_log(ql_log_info, vha, 0x3002,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006676 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6677 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006678 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006679 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6680 start_dpc++;
6681 }
6682
6683 if (!vha->vp_idx &&
6684 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6685 (ha->zio_mode == QLA_ZIO_MODE_6) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006686 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
Quinn Tran8b4673b2018-09-04 14:19:14 -07006687 ql_log(ql_log_info, vha, 0x3002,
6688 "Sched: Set ZIO exchange threshold to %d.\n",
6689 ha->last_zio_threshold);
6690 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006691 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6692 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006693 }
6694
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006696 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6697 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6698 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006700 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6701 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006702 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6703 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006704 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006705 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006706 ql_dbg(ql_dbg_timer, vha, 0x600b,
6707 "isp_abort_needed=%d loop_resync_needed=%d "
6708 "fcport_update_needed=%d start_dpc=%d "
6709 "reset_marker_needed=%d",
6710 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6711 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6712 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6713 start_dpc,
6714 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6715 ql_dbg(ql_dbg_timer, vha, 0x600c,
6716 "beacon_blink_needed=%d isp_unrecoverable=%d "
6717 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006718 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006719 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6720 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6721 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6722 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006723 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006724 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006727 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728}
6729
Andrew Vasquez54333832005-11-09 15:49:04 -08006730/* Firmware interface routines. */
6731
Andrew Vasquez54333832005-11-09 15:49:04 -08006732#define FW_ISP21XX 0
6733#define FW_ISP22XX 1
6734#define FW_ISP2300 2
6735#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006736#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006737#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006738#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006739#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006740#define FW_ISP2031 8
6741#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006742#define FW_ISP27XX 10
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006743#define FW_ISP28XX 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006744
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006745#define FW_FILE_ISP21XX "ql2100_fw.bin"
6746#define FW_FILE_ISP22XX "ql2200_fw.bin"
6747#define FW_FILE_ISP2300 "ql2300_fw.bin"
6748#define FW_FILE_ISP2322 "ql2322_fw.bin"
6749#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006750#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006751#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006752#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006753#define FW_FILE_ISP2031 "ql2600_fw.bin"
6754#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006755#define FW_FILE_ISP27XX "ql2700_fw.bin"
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006756#define FW_FILE_ISP28XX "ql2800_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006757
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006758
Daniel Walkere1e82b62008-05-12 22:21:10 -07006759static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006760
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006761static struct fw_blob qla_fw_blobs[] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006762 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6763 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6764 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6765 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6766 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006767 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006768 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006769 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006770 { .name = FW_FILE_ISP2031, },
6771 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006772 { .name = FW_FILE_ISP27XX, },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006773 { .name = FW_FILE_ISP28XX, },
6774 { .name = NULL, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006775};
6776
6777struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006778qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006779{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006780 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006781 struct fw_blob *blob;
6782
Andrew Vasquez54333832005-11-09 15:49:04 -08006783 if (IS_QLA2100(ha)) {
6784 blob = &qla_fw_blobs[FW_ISP21XX];
6785 } else if (IS_QLA2200(ha)) {
6786 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006787 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006788 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006789 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006790 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006791 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006792 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006793 } else if (IS_QLA25XX(ha)) {
6794 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006795 } else if (IS_QLA81XX(ha)) {
6796 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006797 } else if (IS_QLA82XX(ha)) {
6798 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006799 } else if (IS_QLA2031(ha)) {
6800 blob = &qla_fw_blobs[FW_ISP2031];
6801 } else if (IS_QLA8031(ha)) {
6802 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006803 } else if (IS_QLA27XX(ha)) {
6804 blob = &qla_fw_blobs[FW_ISP27XX];
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006805 } else if (IS_QLA28XX(ha)) {
6806 blob = &qla_fw_blobs[FW_ISP28XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006807 } else {
6808 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006809 }
6810
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006811 if (!blob->name)
6812 return NULL;
6813
Daniel Walkere1e82b62008-05-12 22:21:10 -07006814 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006815 if (blob->fw)
6816 goto out;
6817
6818 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006819 ql_log(ql_log_warn, vha, 0x0063,
6820 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006821 blob->fw = NULL;
6822 blob = NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006823 }
6824
6825out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006826 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006827 return blob;
6828}
6829
6830static void
6831qla2x00_release_firmware(void)
6832{
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006833 struct fw_blob *blob;
Andrew Vasquez54333832005-11-09 15:49:04 -08006834
Daniel Walkere1e82b62008-05-12 22:21:10 -07006835 mutex_lock(&qla_fw_lock);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006836 for (blob = qla_fw_blobs; blob->name; blob++)
6837 release_firmware(blob->fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006838 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006839}
6840
Seokmann Ju14e660e2007-09-20 14:07:36 -07006841static pci_ers_result_t
6842qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6843{
Andrew Vasquez85880802009-12-15 21:29:46 -08006844 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6845 struct qla_hw_data *ha = vha->hw;
6846
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006847 ql_dbg(ql_dbg_aer, vha, 0x9000,
6848 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006849
Sawan Chandakefdb5762017-08-23 15:05:00 -07006850 if (!atomic_read(&pdev->enable_cnt)) {
6851 ql_log(ql_log_info, vha, 0xffff,
6852 "PCI device is disabled,state %x\n", state);
6853 return PCI_ERS_RESULT_NEED_RESET;
6854 }
6855
Seokmann Ju14e660e2007-09-20 14:07:36 -07006856 switch (state) {
6857 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006858 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006859 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006860 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6861 qla2xxx_wake_dpc(vha);
6862 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006863 return PCI_ERS_RESULT_CAN_RECOVER;
6864 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006865 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006866 /* For ISP82XX complete any pending mailbox cmd */
6867 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006868 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006869 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6870 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006871 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006872 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006873 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006874 /* Return back all IOs */
6875 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006876 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006877 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6878 qla2xxx_wake_dpc(vha);
6879 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006880 return PCI_ERS_RESULT_NEED_RESET;
6881 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006882 ha->flags.pci_channel_io_perm_failure = 1;
6883 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006884 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006885 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6886 qla2xxx_wake_dpc(vha);
6887 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006888 return PCI_ERS_RESULT_DISCONNECT;
6889 }
6890 return PCI_ERS_RESULT_NEED_RESET;
6891}
6892
6893static pci_ers_result_t
6894qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6895{
6896 int risc_paused = 0;
6897 uint32_t stat;
6898 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006899 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6900 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006901 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6902 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6903
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006904 if (IS_QLA82XX(ha))
6905 return PCI_ERS_RESULT_RECOVERED;
6906
Seokmann Ju14e660e2007-09-20 14:07:36 -07006907 spin_lock_irqsave(&ha->hardware_lock, flags);
6908 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6909 stat = RD_REG_DWORD(&reg->hccr);
6910 if (stat & HCCR_RISC_PAUSE)
6911 risc_paused = 1;
6912 } else if (IS_QLA23XX(ha)) {
6913 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6914 if (stat & HSR_RISC_PAUSED)
6915 risc_paused = 1;
6916 } else if (IS_FWI2_CAPABLE(ha)) {
6917 stat = RD_REG_DWORD(&reg24->host_status);
6918 if (stat & HSRX_RISC_PAUSED)
6919 risc_paused = 1;
6920 }
6921 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6922
6923 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006924 ql_log(ql_log_info, base_vha, 0x9003,
6925 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006926 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006927
6928 return PCI_ERS_RESULT_NEED_RESET;
6929 } else
6930 return PCI_ERS_RESULT_RECOVERED;
6931}
6932
Saurav Kashyapfa492632012-11-21 02:40:29 -05006933static uint32_t
6934qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006935{
6936 uint32_t rval = QLA_FUNCTION_FAILED;
6937 uint32_t drv_active = 0;
6938 struct qla_hw_data *ha = base_vha->hw;
6939 int fn;
6940 struct pci_dev *other_pdev = NULL;
6941
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006942 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6943 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006944
6945 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6946
6947 if (base_vha->flags.online) {
6948 /* Abort all outstanding commands,
6949 * so as to be requeued later */
6950 qla2x00_abort_isp_cleanup(base_vha);
6951 }
6952
6953
6954 fn = PCI_FUNC(ha->pdev->devfn);
6955 while (fn > 0) {
6956 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006957 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
6958 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006959 other_pdev =
6960 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
6961 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
6962 fn));
6963
6964 if (!other_pdev)
6965 continue;
6966 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006967 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
6968 "Found PCI func available and enable at 0x%x.\n",
6969 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006970 pci_dev_put(other_pdev);
6971 break;
6972 }
6973 pci_dev_put(other_pdev);
6974 }
6975
6976 if (!fn) {
6977 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006978 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
6979 "This devfn is reset owner = 0x%x.\n",
6980 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006981 qla82xx_idc_lock(ha);
6982
6983 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006984 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006985
6986 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
6987 QLA82XX_IDC_VERSION);
6988
6989 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006990 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
6991 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006992
6993 qla82xx_idc_unlock(ha);
6994 /* Reset if device is not already reset
6995 * drv_active would be 0 if a reset has already been done
6996 */
6997 if (drv_active)
6998 rval = qla82xx_start_firmware(base_vha);
6999 else
7000 rval = QLA_SUCCESS;
7001 qla82xx_idc_lock(ha);
7002
7003 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007004 ql_log(ql_log_info, base_vha, 0x900b,
7005 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007006 qla82xx_clear_drv_active(ha);
7007 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007008 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007009 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007010 ql_log(ql_log_info, base_vha, 0x900c,
7011 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007012 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007013 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007014 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08007015 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007016 rval = qla82xx_restart_isp(base_vha);
7017 qla82xx_idc_lock(ha);
7018 /* Clear driver state register */
7019 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
7020 qla82xx_set_drv_active(base_vha);
7021 }
7022 qla82xx_idc_unlock(ha);
7023 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007024 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
7025 "This devfn is not reset owner = 0x%x.\n",
7026 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007027 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007028 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08007029 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007030 rval = qla82xx_restart_isp(base_vha);
7031 qla82xx_idc_lock(ha);
7032 qla82xx_set_drv_active(base_vha);
7033 qla82xx_idc_unlock(ha);
7034 }
7035 }
7036 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7037
7038 return rval;
7039}
7040
Seokmann Ju14e660e2007-09-20 14:07:36 -07007041static pci_ers_result_t
7042qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7043{
7044 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007045 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7046 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007047 struct rsp_que *rsp;
7048 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007049
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007050 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
7051 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007052
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007053 /* Workaround: qla2xxx driver which access hardware earlier
7054 * needs error state to be pci_channel_io_online.
7055 * Otherwise mailbox command timesout.
7056 */
7057 pdev->error_state = pci_channel_io_normal;
7058
7059 pci_restore_state(pdev);
7060
Richard Lary8c1496b2010-02-18 10:07:29 -08007061 /* pci_restore_state() clears the saved_state flag of the device
7062 * save restored state which resets saved_state flag
7063 */
7064 pci_save_state(pdev);
7065
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11007066 if (ha->mem_only)
7067 rc = pci_enable_device_mem(pdev);
7068 else
7069 rc = pci_enable_device(pdev);
7070
7071 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007072 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007073 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007074 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007075 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007076
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007077 rsp = ha->rsp_q_map[0];
7078 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007079 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007080
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007081 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007082 goto exit_slot_reset;
7083
7084 if (IS_QLA82XX(ha)) {
7085 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
7086 ret = PCI_ERS_RESULT_RECOVERED;
7087 goto exit_slot_reset;
7088 } else
7089 goto exit_slot_reset;
7090 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007091
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007092 while (ha->flags.mbox_busy && retries--)
7093 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08007094
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007095 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007096 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07007097 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007098 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007099
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007100
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007101exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007102 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7103 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08007104
Seokmann Ju14e660e2007-09-20 14:07:36 -07007105 return ret;
7106}
7107
7108static void
7109qla2xxx_pci_resume(struct pci_dev *pdev)
7110{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007111 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7112 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007113 int ret;
7114
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007115 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
7116 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007117
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007118 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007119 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007120 ql_log(ql_log_fatal, base_vha, 0x9002,
7121 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07007122 }
Andrew Vasquez85880802009-12-15 21:29:46 -08007123
7124 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007125}
7126
Quinn Tran590f8062019-01-24 23:23:40 -08007127static void
7128qla_pci_reset_prepare(struct pci_dev *pdev)
7129{
7130 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7131 struct qla_hw_data *ha = base_vha->hw;
7132 struct qla_qpair *qpair;
7133
7134 ql_log(ql_log_warn, base_vha, 0xffff,
7135 "%s.\n", __func__);
7136
7137 /*
7138 * PCI FLR/function reset is about to reset the
7139 * slot. Stop the chip to stop all DMA access.
7140 * It is assumed that pci_reset_done will be called
7141 * after FLR to resume Chip operation.
7142 */
7143 ha->flags.eeh_busy = 1;
7144 mutex_lock(&ha->mq_lock);
7145 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7146 qpair->online = 0;
7147 mutex_unlock(&ha->mq_lock);
7148
7149 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7150 qla2x00_abort_isp_cleanup(base_vha);
7151 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7152}
7153
7154static void
7155qla_pci_reset_done(struct pci_dev *pdev)
7156{
7157 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7158 struct qla_hw_data *ha = base_vha->hw;
7159 struct qla_qpair *qpair;
7160
7161 ql_log(ql_log_warn, base_vha, 0xffff,
7162 "%s.\n", __func__);
7163
7164 /*
7165 * FLR just completed by PCI layer. Resume adapter
7166 */
7167 ha->flags.eeh_busy = 0;
7168 mutex_lock(&ha->mq_lock);
7169 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7170 qpair->online = 1;
7171 mutex_unlock(&ha->mq_lock);
7172
7173 base_vha->flags.online = 1;
7174 ha->isp_ops->abort_isp(base_vha);
7175 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7176}
7177
Michael Hernandez56012362016-12-12 14:40:08 -08007178static int qla2xxx_map_queues(struct Scsi_Host *shost)
7179{
Quinn Trand68b8502017-12-04 14:44:59 -08007180 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007181 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
Dongli Zhang485b0ec2019-03-12 09:00:30 +08007182 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
Michael Hernandez56012362016-12-12 14:40:08 -08007183
Giridhar Malavalif3e02692019-02-15 16:42:55 -08007184 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
Jens Axboeed76e322018-10-29 13:06:14 -06007185 rc = blk_mq_map_queues(qmap);
Quinn Trand68b8502017-12-04 14:44:59 -08007186 else
Ming Leif0783d42019-01-11 09:40:47 -08007187 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
Quinn Trand68b8502017-12-04 14:44:59 -08007188 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007189}
7190
Bart Van Assche6515ad72019-04-04 12:44:43 -07007191struct scsi_host_template qla2xxx_driver_template = {
7192 .module = THIS_MODULE,
7193 .name = QLA2XXX_DRIVER_NAME,
7194 .queuecommand = qla2xxx_queuecommand,
7195
7196 .eh_timed_out = fc_eh_timed_out,
7197 .eh_abort_handler = qla2xxx_eh_abort,
7198 .eh_device_reset_handler = qla2xxx_eh_device_reset,
7199 .eh_target_reset_handler = qla2xxx_eh_target_reset,
7200 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
7201 .eh_host_reset_handler = qla2xxx_eh_host_reset,
7202
7203 .slave_configure = qla2xxx_slave_configure,
7204
7205 .slave_alloc = qla2xxx_slave_alloc,
7206 .slave_destroy = qla2xxx_slave_destroy,
7207 .scan_finished = qla2xxx_scan_finished,
7208 .scan_start = qla2xxx_scan_start,
7209 .change_queue_depth = scsi_change_queue_depth,
7210 .map_queues = qla2xxx_map_queues,
7211 .this_id = -1,
7212 .cmd_per_lun = 3,
7213 .sg_tablesize = SG_ALL,
7214
7215 .max_sectors = 0xFFFF,
7216 .shost_attrs = qla2x00_host_attrs,
7217
7218 .supported_mode = MODE_INITIATOR,
7219 .track_queue_depth = 1,
7220};
7221
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07007222static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07007223 .error_detected = qla2xxx_pci_error_detected,
7224 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7225 .slot_reset = qla2xxx_pci_slot_reset,
7226 .resume = qla2xxx_pci_resume,
Quinn Tran590f8062019-01-24 23:23:40 -08007227 .reset_prepare = qla_pci_reset_prepare,
7228 .reset_done = qla_pci_reset_done,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007229};
7230
Andrew Vasquez54333832005-11-09 15:49:04 -08007231static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007232 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7233 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7234 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7235 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7236 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7237 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7238 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7239 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7240 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007241 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007242 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7243 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07007244 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007245 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007246 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07007247 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04007248 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04007249 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007250 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05007251 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04007252 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04007253 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07007254 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7255 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7256 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7257 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7258 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
Andrew Vasquez54333832005-11-09 15:49:04 -08007259 { 0 },
7260};
7261MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7262
Andrew Vasquezfca29702005-07-06 10:31:47 -07007263static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07007264 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06007265 .driver = {
7266 .owner = THIS_MODULE,
7267 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07007268 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007269 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08007270 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07007271 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007272 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07007273};
7274
Al Viro75ef9de2013-04-04 19:09:41 -04007275static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007276 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02007277 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007278};
7279
Linus Torvalds1da177e2005-04-16 15:20:36 -07007280/**
7281 * qla2x00_module_init - Module initialization.
7282 **/
7283static int __init
7284qla2x00_module_init(void)
7285{
Andrew Vasquezfca29702005-07-06 10:31:47 -07007286 int ret = 0;
7287
Linus Torvalds1da177e2005-04-16 15:20:36 -07007288 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007289 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09007290 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007291 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007292 ql_log(ql_log_fatal, NULL, 0x0001,
7293 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007294 return -ENOMEM;
7295 }
7296
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007297 /* Initialize target kmem_cache and mem_pools */
7298 ret = qlt_init();
7299 if (ret < 0) {
Bart Van Asschec794d242019-04-04 12:44:46 -07007300 goto destroy_cache;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007301 } else if (ret > 0) {
7302 /*
7303 * If initiator mode is explictly disabled by qlt_init(),
7304 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7305 * performing scsi_scan_target() during LOOP UP event.
7306 */
7307 qla2xxx_transport_functions.disable_target_scan = 1;
7308 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7309 }
7310
Linus Torvalds1da177e2005-04-16 15:20:36 -07007311 /* Derive version string. */
7312 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07007313 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07007314 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07007315 if (ql2xextended_error_logging == 1)
7316 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07007317
Quinn Tran0645cb82018-09-11 10:18:18 -07007318 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7319 qla_insert_tgt_attrs();
7320
Andrew Vasquez1c97a122005-04-21 16:13:36 -04007321 qla2xxx_transport_template =
7322 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007323 if (!qla2xxx_transport_template) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007324 ql_log(ql_log_fatal, NULL, 0x0002,
7325 "fc_attach_transport failed...Failing load!.\n");
Bart Van Asschec794d242019-04-04 12:44:46 -07007326 ret = -ENODEV;
7327 goto qlt_exit;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007328 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007329
7330 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7331 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007332 ql_log(ql_log_fatal, NULL, 0x0003,
7333 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007334 }
7335
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007336 qla2xxx_transport_vport_template =
7337 fc_attach_transport(&qla2xxx_transport_vport_functions);
7338 if (!qla2xxx_transport_vport_template) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007339 ql_log(ql_log_fatal, NULL, 0x0004,
7340 "fc_attach_transport vport failed...Failing load!.\n");
Bart Van Asschec794d242019-04-04 12:44:46 -07007341 ret = -ENODEV;
7342 goto unreg_chrdev;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007343 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007344 ql_log(ql_log_info, NULL, 0x0005,
7345 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07007346 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007347 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007348 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007349 ql_log(ql_log_fatal, NULL, 0x0006,
7350 "pci_register_driver failed...ret=%d Failing load!.\n",
7351 ret);
Bart Van Asschec794d242019-04-04 12:44:46 -07007352 goto release_vport_transport;
Andrew Vasquezfca29702005-07-06 10:31:47 -07007353 }
7354 return ret;
Bart Van Asschec794d242019-04-04 12:44:46 -07007355
7356release_vport_transport:
7357 fc_release_transport(qla2xxx_transport_vport_template);
7358
7359unreg_chrdev:
7360 if (apidev_major >= 0)
7361 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7362 fc_release_transport(qla2xxx_transport_template);
7363
7364qlt_exit:
7365 qlt_exit();
7366
7367destroy_cache:
7368 kmem_cache_destroy(srb_cachep);
7369 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007370}
7371
7372/**
7373 * qla2x00_module_exit - Module cleanup.
7374 **/
7375static void __exit
7376qla2x00_module_exit(void)
7377{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007378 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08007379 qla2x00_release_firmware();
Thomas Meyer75c1d482018-12-02 21:52:11 +01007380 kmem_cache_destroy(ctx_cachep);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007381 fc_release_transport(qla2xxx_transport_vport_template);
Bart Van Assche59c209a2019-04-04 12:44:47 -07007382 if (apidev_major >= 0)
7383 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7384 fc_release_transport(qla2xxx_transport_template);
7385 qlt_exit();
7386 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007387}
7388
7389module_init(qla2x00_module_init);
7390module_exit(qla2x00_module_exit);
7391
7392MODULE_AUTHOR("QLogic Corporation");
7393MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7394MODULE_LICENSE("GPL");
7395MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07007396MODULE_FIRMWARE(FW_FILE_ISP21XX);
7397MODULE_FIRMWARE(FW_FILE_ISP22XX);
7398MODULE_FIRMWARE(FW_FILE_ISP2300);
7399MODULE_FIRMWARE(FW_FILE_ISP2322);
7400MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08007401MODULE_FIRMWARE(FW_FILE_ISP25XX);