blob: 769a2ffea79fa1835165961c21568b5f76de5f26 [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 Jonesc3c42392016-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
Bart Van Asschedb4bf822019-04-17 14:44:40 -0700719 if (WARN_ON_ONCE(atomic_read(&sp->ref_count) == 0))
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800720 return;
Bart Van Assche219d27d2019-04-17 14:44:35 -0700721
722 atomic_dec(&sp->ref_count);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800723
Joe Carnucciof3caa992017-08-23 15:05:09 -0700724 sp->free(sp);
Giridhar Malavali740e2932019-04-02 14:24:20 -0700725 cmd->result = res;
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700726 CMD_SP(cmd) = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800727 cmd->scsi_done(cmd);
Bart Van Assche219d27d2019-04-17 14:44:35 -0700728 if (comp)
729 complete(comp);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700730 qla2x00_rel_sp(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700731}
732
Michael Hernandezd7459522016-12-12 14:40:07 -0800733void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800734qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800735{
736 srb_t *sp = (srb_t *)ptr;
737 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
738 struct qla_hw_data *ha = sp->fcport->vha->hw;
739 void *ctx = GET_CMD_CTX_SP(sp);
740
741 if (sp->flags & SRB_DMA_VALID) {
742 scsi_dma_unmap(cmd);
743 sp->flags &= ~SRB_DMA_VALID;
744 }
745
746 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
747 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
748 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
749 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
750 }
751
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700752 if (!ctx)
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700753 return;
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700754
Michael Hernandezd7459522016-12-12 14:40:07 -0800755 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
756 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700757 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800758 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
759 }
760
Giridhar Malavali50b81272018-12-21 09:33:45 -0800761 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
Bart Van Assched8f945b2019-04-17 14:44:25 -0700762 struct crc_context *difctx = ctx;
Giridhar Malavali50b81272018-12-21 09:33:45 -0800763 struct dsd_dma *dif_dsd, *nxt_dsd;
764
765 list_for_each_entry_safe(dif_dsd, nxt_dsd,
766 &difctx->ldif_dma_hndl_list, list) {
767 list_del(&dif_dsd->list);
768 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
769 dif_dsd->dsd_list_dma);
770 kfree(dif_dsd);
771 difctx->no_dif_bundl--;
772 }
773
774 list_for_each_entry_safe(dif_dsd, nxt_dsd,
775 &difctx->ldif_dsd_list, list) {
776 list_del(&dif_dsd->list);
777 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
778 dif_dsd->dsd_list_dma);
779 kfree(dif_dsd);
780 difctx->no_ldif_dsd--;
781 }
782
783 if (difctx->no_ldif_dsd) {
784 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
785 "%s: difctx->no_ldif_dsd=%x\n",
786 __func__, difctx->no_ldif_dsd);
787 }
788
789 if (difctx->no_dif_bundl) {
790 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
791 "%s: difctx->no_dif_bundl=%x\n",
792 __func__, difctx->no_dif_bundl);
793 }
794 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
795 }
Bart Van Assched8f945b2019-04-17 14:44:25 -0700796
797 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
798 struct ct6_dsd *ctx1 = ctx;
799
800 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
801 ctx1->fcp_cmnd_dma);
802 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
803 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
804 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
805 mempool_free(ctx1, ha->ctx_mempool);
806 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
807 }
808
809 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
810 struct crc_context *ctx0 = ctx;
811
812 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
813 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
814 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800815}
816
817void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800818qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800819{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800820 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800821 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Bart Van Assche219d27d2019-04-17 14:44:35 -0700822 struct completion *comp = sp->comp;
Michael Hernandezd7459522016-12-12 14:40:07 -0800823
Bart Van Asschedb4bf822019-04-17 14:44:40 -0700824 if (WARN_ON_ONCE(atomic_read(&sp->ref_count) == 0))
Michael Hernandezd7459522016-12-12 14:40:07 -0800825 return;
Bart Van Assche219d27d2019-04-17 14:44:35 -0700826
827 atomic_dec(&sp->ref_count);
Michael Hernandezd7459522016-12-12 14:40:07 -0800828
Joe Carnucciof3caa992017-08-23 15:05:09 -0700829 sp->free(sp);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700830 cmd->result = res;
831 CMD_SP(cmd) = NULL;
Michael Hernandezd7459522016-12-12 14:40:07 -0800832 cmd->scsi_done(cmd);
Bart Van Assche219d27d2019-04-17 14:44:35 -0700833 if (comp)
834 complete(comp);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700835 qla2xxx_rel_qpair_sp(sp->qpair, sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800836}
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800839qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700840{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700841 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700842 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400843 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800844 struct qla_hw_data *ha = vha->hw;
845 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700846 srb_t *sp;
847 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800848 struct qla_qpair *qpair = NULL;
849 uint32_t tag;
850 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700851
Bart Van Assche2dbb02f2019-04-17 14:44:19 -0700852 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)) ||
853 WARN_ON_ONCE(!rport)) {
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200854 cmd->result = DID_NO_CONNECT << 16;
855 goto qc24_fail_command;
856 }
857
Michael Hernandez56012362016-12-12 14:40:08 -0800858 if (ha->mqenable) {
Jens Axboef664a3c2018-11-01 16:36:27 -0600859 tag = blk_mq_unique_tag(cmd->request);
860 hwq = blk_mq_unique_tag_to_hwq(tag);
861 qpair = ha->queue_pair_map[hwq];
Michael Hernandez56012362016-12-12 14:40:08 -0800862
863 if (qpair)
864 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800865 }
866
Andrew Vasquez85880802009-12-15 21:29:46 -0800867 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700868 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400869 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700870 "PCI Channel IO permanent failure, exiting "
871 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700872 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700873 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400874 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700875 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800876 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700877 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700878 goto qc24_fail_command;
879 }
880
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400881 rval = fc_remote_port_chkready(rport);
882 if (rval) {
883 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400884 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700885 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
886 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700887 goto qc24_fail_command;
888 }
889
Arun Easibad75002010-05-04 15:01:30 -0700890 if (!vha->flags.difdix_supported &&
891 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700892 ql_dbg(ql_dbg_io, vha, 0x3004,
893 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
894 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700895 cmd->result = DID_NO_CONNECT << 16;
896 goto qc24_fail_command;
897 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800898
899 if (!fcport) {
900 cmd->result = DID_NO_CONNECT << 16;
901 goto qc24_fail_command;
902 }
903
Andrew Vasquezfca29702005-07-06 10:31:47 -0700904 if (atomic_read(&fcport->state) != FCS_ONLINE) {
905 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700906 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700907 ql_dbg(ql_dbg_io, vha, 0x3005,
908 "Returning DNC, fcport_state=%d loop_state=%d.\n",
909 atomic_read(&fcport->state),
910 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700911 cmd->result = DID_NO_CONNECT << 16;
912 goto qc24_fail_command;
913 }
Mike Christie7b594132008-08-17 15:24:40 -0500914 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700915 }
916
Chad Dupuise05fe292014-09-25 05:16:59 -0400917 /*
918 * Return target busy if we've received a non-zero retry_delay_timer
919 * in a FCP_RSP.
920 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100921 if (fcport->retry_delay_timestamp == 0) {
922 /* retry delay not set */
923 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400924 fcport->retry_delay_timestamp = 0;
925 else
926 goto qc24_target_busy;
927
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500928 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400929 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800930 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700931
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800932 sp->u.scmd.cmd = cmd;
933 sp->type = SRB_SCSI_CMD;
934 atomic_set(&sp->ref_count, 1);
935 CMD_SP(cmd) = (void *)sp;
936 sp->free = qla2x00_sp_free_dma;
937 sp->done = qla2x00_sp_compl;
938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700940 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500941 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700942 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700943 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700944 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700945
Andrew Vasquezfca29702005-07-06 10:31:47 -0700946 return 0;
947
948qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700949 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700950
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800951qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700952 return SCSI_MLQUEUE_HOST_BUSY;
953
Mike Christie7b594132008-08-17 15:24:40 -0500954qc24_target_busy:
955 return SCSI_MLQUEUE_TARGET_BUSY;
956
Andrew Vasquezfca29702005-07-06 10:31:47 -0700957qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800958 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700959
960 return 0;
961}
962
Michael Hernandezd7459522016-12-12 14:40:07 -0800963/* For MQ supported I/O */
964int
965qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
966 struct qla_qpair *qpair)
967{
968 scsi_qla_host_t *vha = shost_priv(host);
969 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
970 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
971 struct qla_hw_data *ha = vha->hw;
972 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
973 srb_t *sp;
974 int rval;
975
Bart Van Assche2dbb02f2019-04-17 14:44:19 -0700976 rval = rport ? fc_remote_port_chkready(rport) : FC_PORTSTATE_OFFLINE;
Michael Hernandezd7459522016-12-12 14:40:07 -0800977 if (rval) {
978 cmd->result = rval;
979 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
980 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
981 cmd, rval);
982 goto qc24_fail_command;
983 }
984
985 if (!fcport) {
986 cmd->result = DID_NO_CONNECT << 16;
987 goto qc24_fail_command;
988 }
989
990 if (atomic_read(&fcport->state) != FCS_ONLINE) {
991 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
992 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
993 ql_dbg(ql_dbg_io, vha, 0x3077,
994 "Returning DNC, fcport_state=%d loop_state=%d.\n",
995 atomic_read(&fcport->state),
996 atomic_read(&base_vha->loop_state));
997 cmd->result = DID_NO_CONNECT << 16;
998 goto qc24_fail_command;
999 }
1000 goto qc24_target_busy;
1001 }
1002
1003 /*
1004 * Return target busy if we've received a non-zero retry_delay_timer
1005 * in a FCP_RSP.
1006 */
1007 if (fcport->retry_delay_timestamp == 0) {
1008 /* retry delay not set */
1009 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1010 fcport->retry_delay_timestamp = 0;
1011 else
1012 goto qc24_target_busy;
1013
Quinn Tran6a629462018-09-04 14:19:15 -07001014 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
Michael Hernandezd7459522016-12-12 14:40:07 -08001015 if (!sp)
1016 goto qc24_host_busy;
1017
1018 sp->u.scmd.cmd = cmd;
1019 sp->type = SRB_SCSI_CMD;
1020 atomic_set(&sp->ref_count, 1);
1021 CMD_SP(cmd) = (void *)sp;
1022 sp->free = qla2xxx_qpair_sp_free_dma;
1023 sp->done = qla2xxx_qpair_sp_compl;
1024 sp->qpair = qpair;
1025
1026 rval = ha->isp_ops->start_scsi_mq(sp);
1027 if (rval != QLA_SUCCESS) {
1028 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1029 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1030 if (rval == QLA_INTERFACE_ERROR)
1031 goto qc24_fail_command;
1032 goto qc24_host_busy_free_sp;
1033 }
1034
1035 return 0;
1036
1037qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001038 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001039
1040qc24_host_busy:
1041 return SCSI_MLQUEUE_HOST_BUSY;
1042
1043qc24_target_busy:
1044 return SCSI_MLQUEUE_TARGET_BUSY;
1045
1046qc24_fail_command:
1047 cmd->scsi_done(cmd);
1048
1049 return 0;
1050}
1051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052/*
1053 * qla2x00_eh_wait_on_command
1054 * Waits for the command to be returned by the Firmware for some
1055 * max time.
1056 *
1057 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 *
1060 * Return:
1061 * Not Found : 0
1062 * Found : 1
1063 */
1064static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001067#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001068#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001069 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001070 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1071 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001072 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Andrew Vasquez85880802009-12-15 21:29:46 -08001074 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001075 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1076 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001077 return ret;
1078 }
1079
Lalit Chandivaded9704322009-08-25 11:36:18 -07001080 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001081 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001082 }
1083 if (CMD_SP(cmd))
1084 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
f4f051e2005-04-17 15:02:26 -05001086 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
1089/*
1090 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001091 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 * <= MAX_RETRIES_OF_ISP_ABORT or
1093 * finally HBA is disabled ie marked offline
1094 *
1095 * Input:
1096 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001097 *
1098 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 * Does context switching-Release SPIN_LOCK
1100 * (if any) before calling this routine.
1101 *
1102 * Return:
1103 * Success (Adapter is online) : 0
1104 * Failed (Adapter is offline/disabled) : 1
1105 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001106int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001107qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001109 int return_status;
1110 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001111 struct qla_hw_data *ha = vha->hw;
1112 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001114 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001115 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1116 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1117 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1118 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
1120 msleep(1000);
1121 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001122 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001123 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 else
1125 return_status = QLA_FUNCTION_FAILED;
1126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 return (return_status);
1128}
1129
Quinn Tran726b8542017-01-19 22:28:00 -08001130static inline int test_fcport_count(scsi_qla_host_t *vha)
1131{
1132 struct qla_hw_data *ha = vha->hw;
1133 unsigned long flags;
1134 int res;
1135
1136 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001137 ql_dbg(ql_dbg_init, vha, 0x00ec,
1138 "tgt %p, fcport_count=%d\n",
1139 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001140 res = (vha->fcport_count == 0);
1141 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1142
1143 return res;
1144}
1145
1146/*
1147 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1148 * it has dependency on UNLOADING flag to stop device discovery
1149 */
Quinn Tranefa93f42018-07-18 14:29:52 -07001150void
Quinn Tran726b8542017-01-19 22:28:00 -08001151qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1152{
1153 qla2x00_mark_all_devices_lost(vha, 0);
1154
Joe Carnucciob85e0952017-08-23 15:05:11 -07001155 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001156}
1157
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001158/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001159 * qla2x00_wait_for_hba_ready
1160 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001161 *
1162 * Input:
1163 * ha - pointer to host adapter structure
1164 *
1165 * Note:
1166 * Does context switching-Release SPIN_LOCK
1167 * (if any) before calling this routine.
1168 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001169 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001170static void
1171qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001172{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001173 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001174 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001175
Dan Carpenter1d483902016-08-03 21:42:32 +03001176 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1177 ha->flags.mbox_busy) ||
1178 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1179 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1180 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1181 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001182 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001183 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001184}
1185
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001186int
1187qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1188{
1189 int return_status;
1190 unsigned long wait_reset;
1191 struct qla_hw_data *ha = vha->hw;
1192 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1193
1194 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1195 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1196 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1197 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1198 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1199
1200 msleep(1000);
1201
1202 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1203 ha->flags.chip_reset_done)
1204 break;
1205 }
1206 if (ha->flags.chip_reset_done)
1207 return_status = QLA_SUCCESS;
1208 else
1209 return_status = QLA_FUNCTION_FAILED;
1210
1211 return return_status;
1212}
1213
Quinn Tran585def92018-09-04 14:19:20 -07001214static int
Giridhar Malavali083a4692010-05-28 15:08:18 -07001215sp_get(struct srb *sp)
1216{
Bart Van Assche845bbb02019-04-11 14:53:18 -07001217 if (!refcount_inc_not_zero((refcount_t *)&sp->ref_count))
Quinn Tran585def92018-09-04 14:19:20 -07001218 /* kref get fail */
1219 return ENXIO;
1220 else
1221 return 0;
Giridhar Malavali083a4692010-05-28 15:08:18 -07001222}
1223
Sawan Chandaka4655372016-07-06 11:14:32 -04001224#define ISP_REG_DISCONNECT 0xffffffffU
1225/**************************************************************************
1226* qla2x00_isp_reg_stat
1227*
1228* Description:
1229* Read the host status register of ISP before aborting the command.
1230*
1231* Input:
1232* ha = pointer to host adapter structure.
1233*
1234*
1235* Returns:
1236* Either true or false.
1237*
1238* Note: Return true if there is register disconnect.
1239**************************************************************************/
1240static inline
1241uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1242{
1243 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001244 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001245
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001246 if (IS_P3P_TYPE(ha))
1247 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1248 else
1249 return ((RD_REG_DWORD(&reg->host_status)) ==
1250 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001251}
1252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253/**************************************************************************
1254* qla2xxx_eh_abort
1255*
1256* Description:
1257* The abort function will abort the specified command.
1258*
1259* Input:
1260* cmd = Linux SCSI command packet to be aborted.
1261*
1262* Returns:
1263* Either SUCCESS or FAILED.
1264*
1265* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001266* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001268static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1270{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001271 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001272 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001273 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001274 unsigned int id;
1275 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001276 unsigned long flags;
Bart Van Assche219d27d2019-04-17 14:44:35 -07001277 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001278 struct qla_hw_data *ha = vha->hw;
Quinn Tran585def92018-09-04 14:19:20 -07001279 struct qla_qpair *qpair;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Sawan Chandaka4655372016-07-06 11:14:32 -04001281 if (qla2x00_isp_reg_stat(ha)) {
1282 ql_log(ql_log_info, vha, 0x8042,
1283 "PCI/Register disconnect, exiting.\n");
1284 return FAILED;
1285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001287 ret = fc_block_scsi_eh(cmd);
1288 if (ret != 0)
1289 return ret;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001290
Mike Christie170babc2010-10-15 11:27:47 -07001291 sp = (srb_t *) CMD_SP(cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001292 if (!sp)
1293 return SUCCESS;
1294
1295 qpair = sp->qpair;
1296 if (!qpair)
1297 return SUCCESS;
1298
Quinn Tran7f4374e2019-07-26 09:07:31 -07001299 if (sp->fcport && sp->fcport->deleted)
1300 return SUCCESS;
1301
Quinn Tran585def92018-09-04 14:19:20 -07001302 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
Bart Van Assche219d27d2019-04-17 14:44:35 -07001303 if (sp->type != SRB_SCSI_CMD || GET_CMD_SP(sp) != cmd) {
Quinn Tran585def92018-09-04 14:19:20 -07001304 /* there's a chance an interrupt could clear
1305 the ptr as part of done & free */
1306 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001307 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001308 }
Mike Christie170babc2010-10-15 11:27:47 -07001309
Quinn Tran585def92018-09-04 14:19:20 -07001310 if (sp_get(sp)){
1311 /* ref_count is already 0 */
1312 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1313 return SUCCESS;
1314 }
1315 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1316
1317 id = cmd->device->id;
1318 lun = cmd->device->lun;
1319
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001320 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001321 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1322 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001323
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001324 rval = ha->isp_ops->abort_command(sp);
Bart Van Assche219d27d2019-04-17 14:44:35 -07001325 ql_dbg(ql_dbg_taskm, vha, 0x8003,
1326 "Abort command mbx cmd=%p, rval=%x.\n", cmd, rval);
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001327
Bart Van Assche219d27d2019-04-17 14:44:35 -07001328 switch (rval) {
1329 case QLA_SUCCESS:
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001330 /*
Bart Van Assche219d27d2019-04-17 14:44:35 -07001331 * The command has been aborted. That means that the firmware
1332 * won't report a completion.
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001333 */
Bart Van Assche219d27d2019-04-17 14:44:35 -07001334 sp->done(sp, DID_ABORT << 16);
1335 ret = SUCCESS;
1336 break;
1337 default:
1338 /*
1339 * Either abort failed or abort and completion raced. Let
1340 * the SCSI core retry the abort in the former case.
1341 */
1342 ret = FAILED;
1343 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Bart Van Assche219d27d2019-04-17 14:44:35 -07001345
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001346 ql_log(ql_log_info, vha, 0x801c,
Bart Van Assche219d27d2019-04-17 14:44:35 -07001347 "Abort command issued nexus=%ld:%d:%llu -- %x.\n",
1348 vha->host_no, id, lun, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
f4f051e2005-04-17 15:02:26 -05001350 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351}
1352
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001353int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001354qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001355 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001357 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001358 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001360 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001361 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001362 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Andrew Vasquez523ec772008-04-03 13:13:24 -07001364 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001365
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001366 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001367 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001368 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001369 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001370 sp = req->outstanding_cmds[cnt];
1371 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001372 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001373 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001374 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001375 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001376 continue;
1377 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001378 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001379 switch (type) {
1380 case WAIT_HOST:
1381 match = 1;
1382 break;
1383 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001384 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001385 break;
1386 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001387 match = (cmd->device->id == t &&
1388 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001389 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001391 if (!match)
1392 continue;
1393
1394 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001395 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001396 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001398 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001399
1400 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401}
1402
Andrew Vasquez523ec772008-04-03 13:13:24 -07001403static char *reset_errors[] = {
1404 "HBA not online",
1405 "HBA not ready",
1406 "Task management failed",
1407 "Waiting for command completions",
1408};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Andrew Vasquez523ec772008-04-03 13:13:24 -07001410static int
1411__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001412 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001413{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001414 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001415 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1416 int err;
1417
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001418 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001419 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001420 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001421
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001422 err = fc_block_scsi_eh(cmd);
1423 if (err != 0)
1424 return err;
1425
Quinn Tran7f4374e2019-07-26 09:07:31 -07001426 if (fcport->deleted)
1427 return SUCCESS;
1428
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001429 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001430 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001431 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001432
1433 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001434 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1435 ql_log(ql_log_warn, vha, 0x800a,
1436 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001437 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001438 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001439 err = 2;
Himanshu Madhaniac444b42019-03-15 15:04:19 -07001440 if (do_reset(fcport, cmd->device->lun, 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001441 != QLA_SUCCESS) {
1442 ql_log(ql_log_warn, vha, 0x800c,
1443 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001444 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001445 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001446 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001448 cmd->device->lun, type) != QLA_SUCCESS) {
1449 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001450 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001451 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001452 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001453
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001454 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001455 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001456 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001457
1458 return SUCCESS;
1459
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001460eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001461 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001462 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001463 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1464 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001465 return FAILED;
1466}
1467
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001468static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1470{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001471 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1472 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Sawan Chandaka4655372016-07-06 11:14:32 -04001474 if (qla2x00_isp_reg_stat(ha)) {
1475 ql_log(ql_log_info, vha, 0x803e,
1476 "PCI/Register disconnect, exiting.\n");
1477 return FAILED;
1478 }
1479
Andrew Vasquez523ec772008-04-03 13:13:24 -07001480 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1481 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001485qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001487 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1488 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Sawan Chandaka4655372016-07-06 11:14:32 -04001490 if (qla2x00_isp_reg_stat(ha)) {
1491 ql_log(ql_log_info, vha, 0x803f,
1492 "PCI/Register disconnect, exiting.\n");
1493 return FAILED;
1494 }
1495
Andrew Vasquez523ec772008-04-03 13:13:24 -07001496 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1497 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498}
1499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500/**************************************************************************
1501* qla2xxx_eh_bus_reset
1502*
1503* Description:
1504* The bus reset function will reset the bus and abort any executing
1505* commands.
1506*
1507* Input:
1508* cmd = Linux SCSI command packet of the command that cause the
1509* bus reset.
1510*
1511* Returns:
1512* SUCCESS/FAILURE (defined as macro in scsi.h).
1513*
1514**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001515static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1517{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001518 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001519 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001520 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001521 unsigned int id;
1522 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001523 struct qla_hw_data *ha = vha->hw;
1524
1525 if (qla2x00_isp_reg_stat(ha)) {
1526 ql_log(ql_log_info, vha, 0x8040,
1527 "PCI/Register disconnect, exiting.\n");
1528 return FAILED;
1529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
f4f051e2005-04-17 15:02:26 -05001531 id = cmd->device->id;
1532 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001533
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001534 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001535 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001538 ret = fc_block_scsi_eh(cmd);
1539 if (ret != 0)
1540 return ret;
1541 ret = FAILED;
1542
Quinn Tran7f4374e2019-07-26 09:07:31 -07001543 if (qla2x00_chip_is_down(vha))
1544 return ret;
1545
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001546 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001547 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001549 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001550 ql_log(ql_log_fatal, vha, 0x8013,
1551 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001552 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 }
1554
Saurav Kashyapad5376892011-11-18 09:02:09 -08001555 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1556 ret = SUCCESS;
1557
f4f051e2005-04-17 15:02:26 -05001558 if (ret == FAILED)
1559 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001561 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001562 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001563 QLA_SUCCESS) {
1564 ql_log(ql_log_warn, vha, 0x8014,
1565 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001566 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
f4f051e2005-04-17 15:02:26 -05001569eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001570 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001571 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001572 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
f4f051e2005-04-17 15:02:26 -05001574 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575}
1576
1577/**************************************************************************
1578* qla2xxx_eh_host_reset
1579*
1580* Description:
1581* The reset function will reset the Adapter.
1582*
1583* Input:
1584* cmd = Linux SCSI command packet of the command that cause the
1585* adapter reset.
1586*
1587* Returns:
1588* Either SUCCESS or FAILED.
1589*
1590* Note:
1591**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001592static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1594{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001595 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001596 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001597 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001598 unsigned int id;
1599 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001600 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Sawan Chandaka4655372016-07-06 11:14:32 -04001602 if (qla2x00_isp_reg_stat(ha)) {
1603 ql_log(ql_log_info, vha, 0x8041,
1604 "PCI/Register disconnect, exiting.\n");
1605 schedule_work(&ha->board_disable);
1606 return SUCCESS;
1607 }
1608
f4f051e2005-04-17 15:02:26 -05001609 id = cmd->device->id;
1610 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001611
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001612 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001613 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Chad Dupuis63ee7072014-04-11 16:54:46 -04001615 /*
1616 * No point in issuing another reset if one is active. Also do not
1617 * attempt a reset if we are updating flash.
1618 */
1619 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001620 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001622 if (vha != base_vha) {
1623 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001624 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001625 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001626 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001627 if (!qla82xx_fcoe_ctx_reset(vha)) {
1628 /* Ctx reset success */
1629 ret = SUCCESS;
1630 goto eh_host_reset_lock;
1631 }
1632 /* fall thru if ctx reset failed */
1633 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001634 if (ha->wq)
1635 flush_workqueue(ha->wq);
1636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001637 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001638 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001639 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1640 /* failed. schedule dpc to try */
1641 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1642
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001643 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1644 ql_log(ql_log_warn, vha, 0x802a,
1645 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001646 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001647 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001648 }
1649 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001653 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001654 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001655 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
f4f051e2005-04-17 15:02:26 -05001657eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001658 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001659 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001660 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
f4f051e2005-04-17 15:02:26 -05001662 return ret;
1663}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
1665/*
1666* qla2x00_loop_reset
1667* Issue loop reset.
1668*
1669* Input:
1670* ha = adapter block pointer.
1671*
1672* Returns:
1673* 0 = success
1674*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001675int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001678 int ret;
bdf79622005-04-17 15:06:53 -05001679 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001680 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Armen Baloyan58547712013-08-27 01:37:33 -04001682 if (IS_QLAFX00(ha)) {
1683 return qlafx00_loop_reset(vha);
1684 }
1685
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001686 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001687 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1688 if (fcport->port_type != FCT_TARGET)
1689 continue;
1690
1691 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1692 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001693 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001694 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001695 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001696 }
1697 }
1698 }
1699
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001700
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001701 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001702 atomic_set(&vha->loop_state, LOOP_DOWN);
1703 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1704 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001705 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001706 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001707 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1708 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 }
1711
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001712 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001713 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001714 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001715 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1716 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001717 }
1718
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001720 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001722 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723}
1724
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001725static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1726 unsigned long *flags)
1727 __releases(qp->qp_lock_ptr)
1728 __acquires(qp->qp_lock_ptr)
1729{
Bart Van Assche219d27d2019-04-17 14:44:35 -07001730 DECLARE_COMPLETION_ONSTACK(comp);
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001731 scsi_qla_host_t *vha = qp->vha;
1732 struct qla_hw_data *ha = vha->hw;
Bart Van Assche219d27d2019-04-17 14:44:35 -07001733 int rval;
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001734
Bart Van Assche219d27d2019-04-17 14:44:35 -07001735 if (sp_get(sp))
1736 return;
Linus Torvalds938edb82018-12-28 14:48:06 -08001737
Bart Van Assche219d27d2019-04-17 14:44:35 -07001738 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS ||
1739 (sp->type == SRB_SCSI_CMD && !ha->flags.eeh_busy &&
1740 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1741 !qla2x00_isp_reg_stat(ha))) {
1742 sp->comp = &comp;
Bart Van Assche219d27d2019-04-17 14:44:35 -07001743 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
Arun Easi5589b082019-06-14 07:36:27 -07001744 rval = ha->isp_ops->abort_command(sp);
Bart Van Assche219d27d2019-04-17 14:44:35 -07001745
1746 switch (rval) {
1747 case QLA_SUCCESS:
1748 sp->done(sp, res);
1749 break;
1750 case QLA_FUNCTION_PARAMETER_ERROR:
1751 wait_for_completion(&comp);
1752 break;
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001753 }
Bart Van Assche219d27d2019-04-17 14:44:35 -07001754
1755 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1756 sp->comp = NULL;
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001757 }
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001758}
1759
Quinn Tranbbead492017-12-28 12:33:13 -08001760static void
1761__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001762{
Bart Van Asscheeb023222018-10-18 15:45:44 -07001763 int cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001764 unsigned long flags;
1765 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001766 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001767 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001768 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001769 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1770 struct qla_tgt_cmd *cmd;
Arun Easic0cb4492014-09-25 06:14:51 -04001771
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001772 if (!ha->req_q_map)
1773 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001774 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1775 req = qp->req;
1776 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1777 sp = req->outstanding_cmds[cnt];
1778 if (sp) {
1779 req->outstanding_cmds[cnt] = NULL;
Quinn Tran6b0431d2018-09-04 14:19:13 -07001780 switch (sp->cmd_type) {
1781 case TYPE_SRB:
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001782 qla2x00_abort_srb(qp, sp, res, &flags);
Quinn Tran585def92018-09-04 14:19:20 -07001783 break;
1784 case TYPE_TGT_CMD:
Quinn Tranbbead492017-12-28 12:33:13 -08001785 if (!vha->hw->tgt.tgt_ops || !tgt ||
1786 qla_ini_mode_enabled(vha)) {
Quinn Tran585def92018-09-04 14:19:20 -07001787 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1788 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1789 vha->dpc_flags);
Quinn Tranbbead492017-12-28 12:33:13 -08001790 continue;
1791 }
1792 cmd = (struct qla_tgt_cmd *)sp;
Bart Van Asscheaefed3e2019-04-17 14:44:29 -07001793 cmd->aborted = 1;
Quinn Tran585def92018-09-04 14:19:20 -07001794 break;
1795 case TYPE_TGT_TMCMD:
Bart Van Asscheaefed3e2019-04-17 14:44:29 -07001796 /* Skip task management functions. */
Quinn Tran585def92018-09-04 14:19:20 -07001797 break;
1798 default:
1799 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001800 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001801 }
1802 }
Quinn Tranbbead492017-12-28 12:33:13 -08001803 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1804}
1805
1806void
1807qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1808{
1809 int que;
1810 struct qla_hw_data *ha = vha->hw;
1811
1812 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1813
1814 for (que = 0; que < ha->max_qpairs; que++) {
1815 if (!ha->queue_pair_map[que])
1816 continue;
1817
1818 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1819 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001820}
1821
f4f051e2005-04-17 15:02:26 -05001822static int
1823qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824{
bdf79622005-04-17 15:06:53 -05001825 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001827 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001828 return -ENXIO;
1829
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001830 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001831
1832 return 0;
1833}
1834
1835static int
1836qla2xxx_slave_configure(struct scsi_device *sdev)
1837{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001838 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001839 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001840
Arun Easi9e522cd2012-08-22 14:21:31 -04001841 if (IS_T10_PI_CAPABLE(vha->hw))
1842 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1843
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001844 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001845 return 0;
1846}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
f4f051e2005-04-17 15:02:26 -05001848static void
1849qla2xxx_slave_destroy(struct scsi_device *sdev)
1850{
1851 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852}
1853
1854/**
1855 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1856 * @ha: HA context
1857 *
1858 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1859 * supported addressing method.
1860 */
1861static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001862qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001864 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
Yang Hongyang6a355282009-04-06 19:01:13 -07001867 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001868 /* Any upper-dword bits set? */
1869 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001870 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001871 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001873 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1874 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001875 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001878
Yang Hongyang284901a2009-04-06 19:01:15 -07001879 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1880 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881}
1882
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001883static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001884qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001885{
1886 unsigned long flags = 0;
1887 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1888
1889 spin_lock_irqsave(&ha->hardware_lock, flags);
1890 ha->interrupts_on = 1;
1891 /* enable risc and host interrupts */
1892 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1893 RD_REG_WORD(&reg->ictrl);
1894 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1895
1896}
1897
1898static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001900{
1901 unsigned long flags = 0;
1902 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1903
1904 spin_lock_irqsave(&ha->hardware_lock, flags);
1905 ha->interrupts_on = 0;
1906 /* disable risc and host interrupts */
1907 WRT_REG_WORD(&reg->ictrl, 0);
1908 RD_REG_WORD(&reg->ictrl);
1909 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1910}
1911
1912static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001914{
1915 unsigned long flags = 0;
1916 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1917
1918 spin_lock_irqsave(&ha->hardware_lock, flags);
1919 ha->interrupts_on = 1;
1920 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1921 RD_REG_DWORD(&reg->ictrl);
1922 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1923}
1924
1925static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001927{
1928 unsigned long flags = 0;
1929 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1930
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001931 if (IS_NOPOLLING_TYPE(ha))
1932 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001933 spin_lock_irqsave(&ha->hardware_lock, flags);
1934 ha->interrupts_on = 0;
1935 WRT_REG_DWORD(&reg->ictrl, 0);
1936 RD_REG_DWORD(&reg->ictrl);
1937 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1938}
1939
Giridhar Malavali706f4572011-11-18 09:03:16 -08001940static int
1941qla2x00_iospace_config(struct qla_hw_data *ha)
1942{
1943 resource_size_t pio;
1944 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001945
Giridhar Malavali706f4572011-11-18 09:03:16 -08001946 if (pci_request_selected_regions(ha->pdev, ha->bars,
1947 QLA2XXX_DRIVER_NAME)) {
1948 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1949 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1950 pci_name(ha->pdev));
1951 goto iospace_error_exit;
1952 }
1953 if (!(ha->bars & 1))
1954 goto skip_pio;
1955
1956 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1957 pio = pci_resource_start(ha->pdev, 0);
1958 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1959 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1960 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1961 "Invalid pci I/O region size (%s).\n",
1962 pci_name(ha->pdev));
1963 pio = 0;
1964 }
1965 } else {
1966 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1967 "Region #0 no a PIO resource (%s).\n",
1968 pci_name(ha->pdev));
1969 pio = 0;
1970 }
1971 ha->pio_address = pio;
1972 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1973 "PIO address=%llu.\n",
1974 (unsigned long long)ha->pio_address);
1975
1976skip_pio:
1977 /* Use MMIO operations for all accesses. */
1978 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1979 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1980 "Region #1 not an MMIO resource (%s), aborting.\n",
1981 pci_name(ha->pdev));
1982 goto iospace_error_exit;
1983 }
1984 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1985 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1986 "Invalid PCI mem region size (%s), aborting.\n",
1987 pci_name(ha->pdev));
1988 goto iospace_error_exit;
1989 }
1990
1991 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1992 if (!ha->iobase) {
1993 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1994 "Cannot remap MMIO (%s), aborting.\n",
1995 pci_name(ha->pdev));
1996 goto iospace_error_exit;
1997 }
1998
1999 /* Determine queue resources */
2000 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002001 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002002 if (!ql2xmqsupport || !ql2xnvmeenable ||
2003 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08002004 goto mqiobase_exit;
2005
2006 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2007 pci_resource_len(ha->pdev, 3));
2008 if (ha->mqiobase) {
2009 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2010 "MQIO Base=%p.\n", ha->mqiobase);
2011 /* Read MSIX vector size of the board */
2012 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002013 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002014 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002015 /* MB interrupt uses 1 vector */
2016 ha->max_req_queues = ha->msix_count - 1;
2017 ha->max_rsp_queues = ha->max_req_queues;
2018 /* Queue pairs is the max value minus the base queue pair */
2019 ha->max_qpairs = ha->max_rsp_queues - 1;
2020 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2021 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2022
Giridhar Malavali706f4572011-11-18 09:03:16 -08002023 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002024 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002025 } else
2026 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2027 "BAR 3 not enabled.\n");
2028
2029mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002030 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002031 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002032 return (0);
2033
2034iospace_error_exit:
2035 return (-ENOMEM);
2036}
2037
2038
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002039static int
2040qla83xx_iospace_config(struct qla_hw_data *ha)
2041{
2042 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002043
2044 if (pci_request_selected_regions(ha->pdev, ha->bars,
2045 QLA2XXX_DRIVER_NAME)) {
2046 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2047 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2048 pci_name(ha->pdev));
2049
2050 goto iospace_error_exit;
2051 }
2052
2053 /* Use MMIO operations for all accesses. */
2054 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2055 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2056 "Invalid pci I/O region size (%s).\n",
2057 pci_name(ha->pdev));
2058 goto iospace_error_exit;
2059 }
2060 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2061 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2062 "Invalid PCI mem region size (%s), aborting\n",
2063 pci_name(ha->pdev));
2064 goto iospace_error_exit;
2065 }
2066
2067 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2068 if (!ha->iobase) {
2069 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2070 "Cannot remap MMIO (%s), aborting.\n",
2071 pci_name(ha->pdev));
2072 goto iospace_error_exit;
2073 }
2074
2075 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2076 /* 83XX 26XX always use MQ type access for queues
2077 * - mbar 2, a.k.a region 4 */
2078 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002079 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002080 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2081 pci_resource_len(ha->pdev, 4));
2082
2083 if (!ha->mqiobase) {
2084 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2085 "BAR2/region4 not enabled\n");
2086 goto mqiobase_exit;
2087 }
2088
2089 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2090 pci_resource_len(ha->pdev, 2));
2091 if (ha->msixbase) {
2092 /* Read MSIX vector size of the board */
2093 pci_read_config_word(ha->pdev,
2094 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002095 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002096 /*
2097 * By default, driver uses at least two msix vectors
2098 * (default & rspq)
2099 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002100 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002101 /* MB interrupt uses 1 vector */
2102 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002103
2104 /* ATIOQ needs 1 vector. That's 1 less QPair */
2105 if (QLA_TGT_MODE_ENABLED())
2106 ha->max_req_queues--;
2107
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002108 ha->max_rsp_queues = ha->max_req_queues;
2109
Michael Hernandezd7459522016-12-12 14:40:07 -08002110 /* Queue pairs is the max value minus
2111 * the base queue pair */
2112 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002113 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002114 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002115 }
2116 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002117 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002118 } else
2119 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2120 "BAR 1 not enabled.\n");
2121
2122mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002123 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002124 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002125 return 0;
2126
2127iospace_error_exit:
2128 return -ENOMEM;
2129}
2130
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002131static struct isp_operations qla2100_isp_ops = {
2132 .pci_config = qla2100_pci_config,
2133 .reset_chip = qla2x00_reset_chip,
2134 .chip_diag = qla2x00_chip_diag,
2135 .config_rings = qla2x00_config_rings,
2136 .reset_adapter = qla2x00_reset_adapter,
2137 .nvram_config = qla2x00_nvram_config,
2138 .update_fw_options = qla2x00_update_fw_options,
2139 .load_risc = qla2x00_load_risc,
2140 .pci_info_str = qla2x00_pci_info_str,
2141 .fw_version_str = qla2x00_fw_version_str,
2142 .intr_handler = qla2100_intr_handler,
2143 .enable_intrs = qla2x00_enable_intrs,
2144 .disable_intrs = qla2x00_disable_intrs,
2145 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002146 .target_reset = qla2x00_abort_target,
2147 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002148 .fabric_login = qla2x00_login_fabric,
2149 .fabric_logout = qla2x00_fabric_logout,
2150 .calc_req_entries = qla2x00_calc_iocbs_32,
2151 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2152 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2153 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2154 .read_nvram = qla2x00_read_nvram_data,
2155 .write_nvram = qla2x00_write_nvram_data,
2156 .fw_dump = qla2100_fw_dump,
2157 .beacon_on = NULL,
2158 .beacon_off = NULL,
2159 .beacon_blink = NULL,
2160 .read_optrom = qla2x00_read_optrom_data,
2161 .write_optrom = qla2x00_write_optrom_data,
2162 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002163 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002164 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002165 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002166 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002167 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002168};
2169
2170static struct isp_operations qla2300_isp_ops = {
2171 .pci_config = qla2300_pci_config,
2172 .reset_chip = qla2x00_reset_chip,
2173 .chip_diag = qla2x00_chip_diag,
2174 .config_rings = qla2x00_config_rings,
2175 .reset_adapter = qla2x00_reset_adapter,
2176 .nvram_config = qla2x00_nvram_config,
2177 .update_fw_options = qla2x00_update_fw_options,
2178 .load_risc = qla2x00_load_risc,
2179 .pci_info_str = qla2x00_pci_info_str,
2180 .fw_version_str = qla2x00_fw_version_str,
2181 .intr_handler = qla2300_intr_handler,
2182 .enable_intrs = qla2x00_enable_intrs,
2183 .disable_intrs = qla2x00_disable_intrs,
2184 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002185 .target_reset = qla2x00_abort_target,
2186 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002187 .fabric_login = qla2x00_login_fabric,
2188 .fabric_logout = qla2x00_fabric_logout,
2189 .calc_req_entries = qla2x00_calc_iocbs_32,
2190 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2191 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2192 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2193 .read_nvram = qla2x00_read_nvram_data,
2194 .write_nvram = qla2x00_write_nvram_data,
2195 .fw_dump = qla2300_fw_dump,
2196 .beacon_on = qla2x00_beacon_on,
2197 .beacon_off = qla2x00_beacon_off,
2198 .beacon_blink = qla2x00_beacon_blink,
2199 .read_optrom = qla2x00_read_optrom_data,
2200 .write_optrom = qla2x00_write_optrom_data,
2201 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002202 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002203 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002204 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002205 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002206 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002207};
2208
2209static struct isp_operations qla24xx_isp_ops = {
2210 .pci_config = qla24xx_pci_config,
2211 .reset_chip = qla24xx_reset_chip,
2212 .chip_diag = qla24xx_chip_diag,
2213 .config_rings = qla24xx_config_rings,
2214 .reset_adapter = qla24xx_reset_adapter,
2215 .nvram_config = qla24xx_nvram_config,
2216 .update_fw_options = qla24xx_update_fw_options,
2217 .load_risc = qla24xx_load_risc,
2218 .pci_info_str = qla24xx_pci_info_str,
2219 .fw_version_str = qla24xx_fw_version_str,
2220 .intr_handler = qla24xx_intr_handler,
2221 .enable_intrs = qla24xx_enable_intrs,
2222 .disable_intrs = qla24xx_disable_intrs,
2223 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002224 .target_reset = qla24xx_abort_target,
2225 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002226 .fabric_login = qla24xx_login_fabric,
2227 .fabric_logout = qla24xx_fabric_logout,
2228 .calc_req_entries = NULL,
2229 .build_iocbs = NULL,
2230 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2231 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2232 .read_nvram = qla24xx_read_nvram_data,
2233 .write_nvram = qla24xx_write_nvram_data,
2234 .fw_dump = qla24xx_fw_dump,
2235 .beacon_on = qla24xx_beacon_on,
2236 .beacon_off = qla24xx_beacon_off,
2237 .beacon_blink = qla24xx_beacon_blink,
2238 .read_optrom = qla24xx_read_optrom_data,
2239 .write_optrom = qla24xx_write_optrom_data,
2240 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002241 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002242 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002243 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002244 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002245 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002246};
2247
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002248static struct isp_operations qla25xx_isp_ops = {
2249 .pci_config = qla25xx_pci_config,
2250 .reset_chip = qla24xx_reset_chip,
2251 .chip_diag = qla24xx_chip_diag,
2252 .config_rings = qla24xx_config_rings,
2253 .reset_adapter = qla24xx_reset_adapter,
2254 .nvram_config = qla24xx_nvram_config,
2255 .update_fw_options = qla24xx_update_fw_options,
2256 .load_risc = qla24xx_load_risc,
2257 .pci_info_str = qla24xx_pci_info_str,
2258 .fw_version_str = qla24xx_fw_version_str,
2259 .intr_handler = qla24xx_intr_handler,
2260 .enable_intrs = qla24xx_enable_intrs,
2261 .disable_intrs = qla24xx_disable_intrs,
2262 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002263 .target_reset = qla24xx_abort_target,
2264 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002265 .fabric_login = qla24xx_login_fabric,
2266 .fabric_logout = qla24xx_fabric_logout,
2267 .calc_req_entries = NULL,
2268 .build_iocbs = NULL,
2269 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2270 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2271 .read_nvram = qla25xx_read_nvram_data,
2272 .write_nvram = qla25xx_write_nvram_data,
2273 .fw_dump = qla25xx_fw_dump,
2274 .beacon_on = qla24xx_beacon_on,
2275 .beacon_off = qla24xx_beacon_off,
2276 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002277 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002278 .write_optrom = qla24xx_write_optrom_data,
2279 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002280 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002281 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002282 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002283 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002284 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002285};
2286
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002287static struct isp_operations qla81xx_isp_ops = {
2288 .pci_config = qla25xx_pci_config,
2289 .reset_chip = qla24xx_reset_chip,
2290 .chip_diag = qla24xx_chip_diag,
2291 .config_rings = qla24xx_config_rings,
2292 .reset_adapter = qla24xx_reset_adapter,
2293 .nvram_config = qla81xx_nvram_config,
2294 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002295 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002296 .pci_info_str = qla24xx_pci_info_str,
2297 .fw_version_str = qla24xx_fw_version_str,
2298 .intr_handler = qla24xx_intr_handler,
2299 .enable_intrs = qla24xx_enable_intrs,
2300 .disable_intrs = qla24xx_disable_intrs,
2301 .abort_command = qla24xx_abort_command,
2302 .target_reset = qla24xx_abort_target,
2303 .lun_reset = qla24xx_lun_reset,
2304 .fabric_login = qla24xx_login_fabric,
2305 .fabric_logout = qla24xx_fabric_logout,
2306 .calc_req_entries = NULL,
2307 .build_iocbs = NULL,
2308 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2309 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002310 .read_nvram = NULL,
2311 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002312 .fw_dump = qla81xx_fw_dump,
2313 .beacon_on = qla24xx_beacon_on,
2314 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002315 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002316 .read_optrom = qla25xx_read_optrom_data,
2317 .write_optrom = qla24xx_write_optrom_data,
2318 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002319 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002320 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002321 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002322 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002323 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002324};
2325
2326static struct isp_operations qla82xx_isp_ops = {
2327 .pci_config = qla82xx_pci_config,
2328 .reset_chip = qla82xx_reset_chip,
2329 .chip_diag = qla24xx_chip_diag,
2330 .config_rings = qla82xx_config_rings,
2331 .reset_adapter = qla24xx_reset_adapter,
2332 .nvram_config = qla81xx_nvram_config,
2333 .update_fw_options = qla24xx_update_fw_options,
2334 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002335 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002336 .fw_version_str = qla24xx_fw_version_str,
2337 .intr_handler = qla82xx_intr_handler,
2338 .enable_intrs = qla82xx_enable_intrs,
2339 .disable_intrs = qla82xx_disable_intrs,
2340 .abort_command = qla24xx_abort_command,
2341 .target_reset = qla24xx_abort_target,
2342 .lun_reset = qla24xx_lun_reset,
2343 .fabric_login = qla24xx_login_fabric,
2344 .fabric_logout = qla24xx_fabric_logout,
2345 .calc_req_entries = NULL,
2346 .build_iocbs = NULL,
2347 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2348 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2349 .read_nvram = qla24xx_read_nvram_data,
2350 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002351 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002352 .beacon_on = qla82xx_beacon_on,
2353 .beacon_off = qla82xx_beacon_off,
2354 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002355 .read_optrom = qla82xx_read_optrom_data,
2356 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002357 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002358 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002359 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002360 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002361 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002362 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002363};
2364
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002365static struct isp_operations qla8044_isp_ops = {
2366 .pci_config = qla82xx_pci_config,
2367 .reset_chip = qla82xx_reset_chip,
2368 .chip_diag = qla24xx_chip_diag,
2369 .config_rings = qla82xx_config_rings,
2370 .reset_adapter = qla24xx_reset_adapter,
2371 .nvram_config = qla81xx_nvram_config,
2372 .update_fw_options = qla24xx_update_fw_options,
2373 .load_risc = qla82xx_load_risc,
2374 .pci_info_str = qla24xx_pci_info_str,
2375 .fw_version_str = qla24xx_fw_version_str,
2376 .intr_handler = qla8044_intr_handler,
2377 .enable_intrs = qla82xx_enable_intrs,
2378 .disable_intrs = qla82xx_disable_intrs,
2379 .abort_command = qla24xx_abort_command,
2380 .target_reset = qla24xx_abort_target,
2381 .lun_reset = qla24xx_lun_reset,
2382 .fabric_login = qla24xx_login_fabric,
2383 .fabric_logout = qla24xx_fabric_logout,
2384 .calc_req_entries = NULL,
2385 .build_iocbs = NULL,
2386 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2387 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2388 .read_nvram = NULL,
2389 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002390 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002391 .beacon_on = qla82xx_beacon_on,
2392 .beacon_off = qla82xx_beacon_off,
2393 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002394 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002395 .write_optrom = qla8044_write_optrom_data,
2396 .get_flash_version = qla82xx_get_flash_version,
2397 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002398 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002399 .abort_isp = qla8044_abort_isp,
2400 .iospace_config = qla82xx_iospace_config,
2401 .initialize_adapter = qla2x00_initialize_adapter,
2402};
2403
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002404static struct isp_operations qla83xx_isp_ops = {
2405 .pci_config = qla25xx_pci_config,
2406 .reset_chip = qla24xx_reset_chip,
2407 .chip_diag = qla24xx_chip_diag,
2408 .config_rings = qla24xx_config_rings,
2409 .reset_adapter = qla24xx_reset_adapter,
2410 .nvram_config = qla81xx_nvram_config,
2411 .update_fw_options = qla81xx_update_fw_options,
2412 .load_risc = qla81xx_load_risc,
2413 .pci_info_str = qla24xx_pci_info_str,
2414 .fw_version_str = qla24xx_fw_version_str,
2415 .intr_handler = qla24xx_intr_handler,
2416 .enable_intrs = qla24xx_enable_intrs,
2417 .disable_intrs = qla24xx_disable_intrs,
2418 .abort_command = qla24xx_abort_command,
2419 .target_reset = qla24xx_abort_target,
2420 .lun_reset = qla24xx_lun_reset,
2421 .fabric_login = qla24xx_login_fabric,
2422 .fabric_logout = qla24xx_fabric_logout,
2423 .calc_req_entries = NULL,
2424 .build_iocbs = NULL,
2425 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2426 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2427 .read_nvram = NULL,
2428 .write_nvram = NULL,
2429 .fw_dump = qla83xx_fw_dump,
2430 .beacon_on = qla24xx_beacon_on,
2431 .beacon_off = qla24xx_beacon_off,
2432 .beacon_blink = qla83xx_beacon_blink,
2433 .read_optrom = qla25xx_read_optrom_data,
2434 .write_optrom = qla24xx_write_optrom_data,
2435 .get_flash_version = qla24xx_get_flash_version,
2436 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002437 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002438 .abort_isp = qla2x00_abort_isp,
2439 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002440 .initialize_adapter = qla2x00_initialize_adapter,
2441};
2442
2443static struct isp_operations qlafx00_isp_ops = {
2444 .pci_config = qlafx00_pci_config,
2445 .reset_chip = qlafx00_soft_reset,
2446 .chip_diag = qlafx00_chip_diag,
2447 .config_rings = qlafx00_config_rings,
2448 .reset_adapter = qlafx00_soft_reset,
2449 .nvram_config = NULL,
2450 .update_fw_options = NULL,
2451 .load_risc = NULL,
2452 .pci_info_str = qlafx00_pci_info_str,
2453 .fw_version_str = qlafx00_fw_version_str,
2454 .intr_handler = qlafx00_intr_handler,
2455 .enable_intrs = qlafx00_enable_intrs,
2456 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002457 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002458 .target_reset = qlafx00_abort_target,
2459 .lun_reset = qlafx00_lun_reset,
2460 .fabric_login = NULL,
2461 .fabric_logout = NULL,
2462 .calc_req_entries = NULL,
2463 .build_iocbs = NULL,
2464 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2465 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2466 .read_nvram = qla24xx_read_nvram_data,
2467 .write_nvram = qla24xx_write_nvram_data,
2468 .fw_dump = NULL,
2469 .beacon_on = qla24xx_beacon_on,
2470 .beacon_off = qla24xx_beacon_off,
2471 .beacon_blink = NULL,
2472 .read_optrom = qla24xx_read_optrom_data,
2473 .write_optrom = qla24xx_write_optrom_data,
2474 .get_flash_version = qla24xx_get_flash_version,
2475 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002476 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002477 .abort_isp = qlafx00_abort_isp,
2478 .iospace_config = qlafx00_iospace_config,
2479 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002480};
2481
Chad Dupuisf73cb692014-02-26 04:15:06 -05002482static struct isp_operations qla27xx_isp_ops = {
2483 .pci_config = qla25xx_pci_config,
2484 .reset_chip = qla24xx_reset_chip,
2485 .chip_diag = qla24xx_chip_diag,
2486 .config_rings = qla24xx_config_rings,
2487 .reset_adapter = qla24xx_reset_adapter,
2488 .nvram_config = qla81xx_nvram_config,
2489 .update_fw_options = qla81xx_update_fw_options,
2490 .load_risc = qla81xx_load_risc,
2491 .pci_info_str = qla24xx_pci_info_str,
2492 .fw_version_str = qla24xx_fw_version_str,
2493 .intr_handler = qla24xx_intr_handler,
2494 .enable_intrs = qla24xx_enable_intrs,
2495 .disable_intrs = qla24xx_disable_intrs,
2496 .abort_command = qla24xx_abort_command,
2497 .target_reset = qla24xx_abort_target,
2498 .lun_reset = qla24xx_lun_reset,
2499 .fabric_login = qla24xx_login_fabric,
2500 .fabric_logout = qla24xx_fabric_logout,
2501 .calc_req_entries = NULL,
2502 .build_iocbs = NULL,
2503 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2504 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2505 .read_nvram = NULL,
2506 .write_nvram = NULL,
2507 .fw_dump = qla27xx_fwdump,
2508 .beacon_on = qla24xx_beacon_on,
2509 .beacon_off = qla24xx_beacon_off,
2510 .beacon_blink = qla83xx_beacon_blink,
2511 .read_optrom = qla25xx_read_optrom_data,
2512 .write_optrom = qla24xx_write_optrom_data,
2513 .get_flash_version = qla24xx_get_flash_version,
2514 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002515 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002516 .abort_isp = qla2x00_abort_isp,
2517 .iospace_config = qla83xx_iospace_config,
2518 .initialize_adapter = qla2x00_initialize_adapter,
2519};
2520
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002521static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002522qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002523{
2524 ha->device_type = DT_EXTENDED_IDS;
2525 switch (ha->pdev->device) {
2526 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002527 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002528 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002529 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002530 break;
2531 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002532 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002533 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002534 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002535 break;
2536 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002537 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002538 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002539 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002540 break;
2541 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002542 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002543 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002544 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002545 break;
2546 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002547 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002548 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002549 if (ha->pdev->subsystem_vendor == 0x1028 &&
2550 ha->pdev->subsystem_device == 0x0170)
2551 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002552 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002553 break;
2554 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002555 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002556 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002557 break;
2558 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002559 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002560 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002561 break;
2562 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002563 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002564 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002565 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002566 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002567 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002568 break;
2569 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002570 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002571 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002572 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002573 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002574 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002575 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002576 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002577 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002578 ha->device_type |= DT_ZIO_SUPPORTED;
2579 ha->device_type |= DT_FWI2;
2580 ha->device_type |= DT_IIDMA;
2581 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2582 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002583 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002584 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002585 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002586 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002587 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002588 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002589 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002590 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002591 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002592 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002593 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002594 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002595 ha->device_type |= DT_ZIO_SUPPORTED;
2596 ha->device_type |= DT_FWI2;
2597 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002598 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2599 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002600 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002601 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002602 ha->device_type |= DT_ZIO_SUPPORTED;
2603 ha->device_type |= DT_FWI2;
2604 ha->device_type |= DT_IIDMA;
2605 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2606 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002607 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002608 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002609 ha->device_type |= DT_ZIO_SUPPORTED;
2610 ha->device_type |= DT_FWI2;
2611 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2612 /* Initialize 82XX ISP flags */
2613 qla82xx_init_flags(ha);
2614 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002615 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002616 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002617 ha->device_type |= DT_ZIO_SUPPORTED;
2618 ha->device_type |= DT_FWI2;
2619 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2620 /* Initialize 82XX ISP flags */
2621 qla82xx_init_flags(ha);
2622 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002623 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002624 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002625 ha->device_type |= DT_ZIO_SUPPORTED;
2626 ha->device_type |= DT_FWI2;
2627 ha->device_type |= DT_IIDMA;
2628 ha->device_type |= DT_T10_PI;
2629 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2630 break;
2631 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002632 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002633 ha->device_type |= DT_ZIO_SUPPORTED;
2634 ha->device_type |= DT_FWI2;
2635 ha->device_type |= DT_IIDMA;
2636 ha->device_type |= DT_T10_PI;
2637 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2638 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002639 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002640 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002641 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002642 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002643 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002644 ha->device_type |= DT_ZIO_SUPPORTED;
2645 ha->device_type |= DT_FWI2;
2646 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002647 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002648 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2649 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002650 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002651 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002652 ha->device_type |= DT_ZIO_SUPPORTED;
2653 ha->device_type |= DT_FWI2;
2654 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002655 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002656 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2657 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002658 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002659 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002660 ha->device_type |= DT_ZIO_SUPPORTED;
2661 ha->device_type |= DT_FWI2;
2662 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002663 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002664 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2665 break;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002666 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2667 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2668 ha->isp_type |= DT_ISP2081;
2669 ha->device_type |= DT_ZIO_SUPPORTED;
2670 ha->device_type |= DT_FWI2;
2671 ha->device_type |= DT_IIDMA;
2672 ha->device_type |= DT_T10_PI;
2673 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2674 break;
2675 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2676 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2677 ha->isp_type |= DT_ISP2281;
2678 ha->device_type |= DT_ZIO_SUPPORTED;
2679 ha->device_type |= DT_FWI2;
2680 ha->device_type |= DT_IIDMA;
2681 ha->device_type |= DT_T10_PI;
2682 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2683 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002684 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002685
Giridhar Malavalia9083012010-04-12 17:59:55 -07002686 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002687 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002688 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002689 /* Get adapter physical port no from interrupt pin register. */
2690 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002691 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2692 IS_QLA27XX(ha) || IS_QLA28XX(ha))
Chad Dupuisf73cb692014-02-26 04:15:06 -05002693 ha->port_no--;
2694 else
2695 ha->port_no = !(ha->port_no & 1);
2696 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002697
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002698 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002699 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002700 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002701}
2702
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002703static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002704qla2xxx_scan_start(struct Scsi_Host *shost)
2705{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002707
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002708 if (vha->hw->flags.running_gold_fw)
2709 return;
2710
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002711 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2712 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2713 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2714 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002715}
2716
2717static int
2718qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2719{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002721
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002722 if (test_bit(UNLOADING, &vha->dpc_flags))
2723 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002725 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002726 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002727 return 1;
2728
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002729 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002730}
2731
Quinn Tranec7193e2017-03-15 09:48:55 -07002732static void qla2x00_iocb_work_fn(struct work_struct *work)
2733{
2734 struct scsi_qla_host *vha = container_of(work,
2735 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002736 struct qla_hw_data *ha = vha->hw;
2737 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran0aca7782018-09-04 14:19:16 -07002738 int i = 2;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002739 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002740
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002741 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2742 return;
2743
2744 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002745 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002746 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002747 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002748
2749 spin_lock_irqsave(&vha->work_lock, flags);
2750 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2751 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002752}
2753
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754/*
2755 * PCI driver interface
2756 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002757static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002758qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002760 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002762 scsi_qla_host_t *base_vha = NULL;
2763 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002764 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002765 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002766 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002767 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002768 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002769 struct req_que *req = NULL;
2770 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002771 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002772
Andrew Vasquez285d0322007-10-19 15:59:17 -07002773 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002774 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002775 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2776 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002777 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002778 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2779 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002780 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002781 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002782 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2783 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002784 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002785 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002786 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002787 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002788 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002789 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2790 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2791 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2792 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2793 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002794 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002795 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002796 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2797 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002798 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002799 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2800 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002801
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002802 if (mem_only) {
2803 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002804 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002805 } else {
2806 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002807 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002808 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809
Jesse Barnes09276782008-10-18 17:33:19 -07002810 /* This may fail but that's ok */
2811 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002812
Giridhar Malavali5da05a22019-04-02 14:24:24 -07002813 /* Turn off T10-DIF when FC-NVMe is enabled */
2814 if (ql2xnvmeenable)
2815 ql2xenabledif = 0;
2816
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2818 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002819 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2820 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002821 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002823 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2824 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002825 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002826 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2827 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002828 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002829 spin_lock_init(&ha->tgt.atio_lock);
2830
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002831 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
2833 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002834 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002835 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002836 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002837 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002838 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002839 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002841 /* Set ISP-type information. */
2842 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002843
2844 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002845 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002846 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002847 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002848
Chad Dupuiscba1e472011-11-18 09:03:21 -08002849 ha->prev_topology = 0;
2850 ha->init_cb_size = sizeof(init_cb_t);
2851 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2852 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002853 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Quinn Tranb2000802018-08-02 13:16:52 -07002854 atomic_set(&ha->num_pend_mbx_stage1, 0);
2855 atomic_set(&ha->num_pend_mbx_stage2, 0);
2856 atomic_set(&ha->num_pend_mbx_stage3, 0);
Quinn Tran8b4673b2018-09-04 14:19:14 -07002857 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2858 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002859
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002860 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002862 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 req_length = REQUEST_ENTRY_CNT_2100;
2865 rsp_length = RESPONSE_ENTRY_CNT_2100;
2866 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002867 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002868 ha->flash_conf_off = ~0;
2869 ha->flash_data_off = ~0;
2870 ha->nvram_conf_off = ~0;
2871 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002872 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002874 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002875 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876 req_length = REQUEST_ENTRY_CNT_2200;
2877 rsp_length = RESPONSE_ENTRY_CNT_2100;
2878 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002879 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002880 ha->flash_conf_off = ~0;
2881 ha->flash_data_off = ~0;
2882 ha->nvram_conf_off = ~0;
2883 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002884 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002885 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002886 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002888 req_length = REQUEST_ENTRY_CNT_2200;
2889 rsp_length = RESPONSE_ENTRY_CNT_2300;
2890 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002891 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002892 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2893 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002894 ha->flash_conf_off = ~0;
2895 ha->flash_data_off = ~0;
2896 ha->nvram_conf_off = ~0;
2897 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002898 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002899 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002900 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002901 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002902 req_length = REQUEST_ENTRY_CNT_24XX;
2903 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002904 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002906 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002907 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002908 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002909 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002910 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002911 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2912 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2913 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2914 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002915 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002916 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002917 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 req_length = REQUEST_ENTRY_CNT_24XX;
2919 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002920 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002922 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002923 ha->gid_list_info_size = 8;
2924 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002925 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002926 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002927 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2928 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2929 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2930 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2931 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002932 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002933 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2934 req_length = REQUEST_ENTRY_CNT_24XX;
2935 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002936 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002937 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2938 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2939 ha->gid_list_info_size = 8;
2940 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002941 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002942 ha->isp_ops = &qla81xx_isp_ops;
2943 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2944 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2945 ha->nvram_conf_off = ~0;
2946 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002947 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002948 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002949 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2950 req_length = REQUEST_ENTRY_CNT_82XX;
2951 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2952 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2953 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2954 ha->gid_list_info_size = 8;
2955 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08002956 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002957 ha->isp_ops = &qla82xx_isp_ops;
2958 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2959 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2960 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2961 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002962 } else if (IS_QLA8044(ha)) {
2963 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
2964 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2965 req_length = REQUEST_ENTRY_CNT_82XX;
2966 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2967 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2968 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2969 ha->gid_list_info_size = 8;
2970 ha->optrom_size = OPTROM_SIZE_83XX;
2971 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2972 ha->isp_ops = &qla8044_isp_ops;
2973 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2974 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2975 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2976 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002977 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002978 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08002979 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002980 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04002981 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05002982 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05002983 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002984 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2985 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2986 ha->gid_list_info_size = 8;
2987 ha->optrom_size = OPTROM_SIZE_83XX;
2988 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2989 ha->isp_ops = &qla83xx_isp_ops;
2990 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2991 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2992 ha->nvram_conf_off = ~0;
2993 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002994 } else if (IS_QLAFX00(ha)) {
2995 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
2996 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
2997 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
2998 req_length = REQUEST_ENTRY_CNT_FX00;
2999 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003000 ha->isp_ops = &qlafx00_isp_ops;
3001 ha->port_down_retry_count = 30; /* default value */
3002 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3003 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04003004 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003005 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04003006 ha->mr.host_info_resend = false;
3007 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003008 } else if (IS_QLA27XX(ha)) {
3009 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3010 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3011 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05003012 req_length = REQUEST_ENTRY_CNT_83XX;
3013 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04003014 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003015 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3016 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3017 ha->gid_list_info_size = 8;
3018 ha->optrom_size = OPTROM_SIZE_83XX;
3019 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3020 ha->isp_ops = &qla27xx_isp_ops;
3021 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3022 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3023 ha->nvram_conf_off = ~0;
3024 ha->nvram_data_off = ~0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003025 } else if (IS_QLA28XX(ha)) {
3026 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3027 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3028 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3029 req_length = REQUEST_ENTRY_CNT_24XX;
3030 rsp_length = RESPONSE_ENTRY_CNT_2300;
3031 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3032 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3033 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3034 ha->gid_list_info_size = 8;
3035 ha->optrom_size = OPTROM_SIZE_28XX;
3036 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3037 ha->isp_ops = &qla27xx_isp_ops;
3038 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3039 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3040 ha->nvram_conf_off = ~0;
3041 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003043
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003044 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3045 "mbx_count=%d, req_length=%d, "
3046 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08003047 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3048 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003049 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3050 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08003051 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003052 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3053 "isp_ops=%p, flash_conf_off=%d, "
3054 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3055 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3056 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08003057
3058 /* Configure PCI I/O space */
3059 ret = ha->isp_ops->iospace_config(ha);
3060 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003061 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003062
3063 ql_log_pci(ql_log_info, pdev, 0x001d,
3064 "Found an ISP%04X irq %d iobase 0x%p.\n",
3065 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003066 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003067 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003068 init_completion(&ha->mbx_cmd_comp);
3069 complete(&ha->mbx_cmd_comp);
3070 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003071 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003072 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003074 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075
Andrew Vasquez53303c42009-01-22 09:45:37 -08003076 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003077 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3078 "64 Bit addressing is %s.\n",
3079 ha->flags.enable_64bit_addressing ? "enable" :
3080 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003081 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003082 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003083 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3084 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003086 goto probe_hw_failed;
3087 }
3088
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003089 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003090 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003091 req->max_q_depth = ql2xmaxqdepth;
3092
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003093
3094 base_vha = qla2x00_create_host(sht, ha);
3095 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003096 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003097 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 }
3099
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003100 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003101 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003103 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003104 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003105 if (IS_QLA2XXX_MIDTYPE(ha))
Quinn Tranf6602f32018-08-02 13:16:53 -07003106 base_vha->mgmt_svr_loop_id =
3107 qla2x00_reserve_mgmt_server_loop_id(base_vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003108 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003109 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3110 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003111
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003112 /* Setup fcport template structure. */
3113 ha->mr.fcport.vha = base_vha;
3114 ha->mr.fcport.port_type = FCT_UNKNOWN;
3115 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3116 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3117 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3118 ha->mr.fcport.scan_state = 1;
3119
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003120 /* Set the SG table size based on ISP type */
3121 if (!IS_FWI2_CAPABLE(ha)) {
3122 if (IS_QLA2100(ha))
3123 host->sg_tablesize = 32;
3124 } else {
3125 if (!IS_QLA82XX(ha))
3126 host->sg_tablesize = QLA_SG_ALL;
3127 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003128 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003129 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003130 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003131 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003132 host->max_cmd_len = 32;
3133 else
3134 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003135 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003136 /* Older HBAs support only 16-bit LUNs */
3137 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3138 ql2xmaxlun > 0xffff)
3139 host->max_lun = 0xffff;
3140 else
3141 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003142 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003143 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003144
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003145 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3146 "max_id=%d this_id=%d "
3147 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003148 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003149 host->this_id, host->cmd_per_lun, host->unique_id,
3150 host->max_cmd_len, host->max_channel, host->max_lun,
3151 host->transportt, sht->vendor_id);
3152
Himanshu Madhani1010f212017-10-16 11:26:05 -07003153 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3154
Michael Hernandezd7459522016-12-12 14:40:07 -08003155 /* Set up the irqs */
3156 ret = qla2x00_request_irqs(ha, rsp);
3157 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003158 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003159
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003160 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003161 ret = qla2x00_alloc_queues(ha, req, rsp);
3162 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003163 ql_log(ql_log_fatal, base_vha, 0x003d,
3164 "Failed to allocate memory for queue pointers..."
3165 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003166 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003167 }
3168
Jens Axboef664a3c2018-11-01 16:36:27 -06003169 if (ha->mqenable) {
Michael Hernandez56012362016-12-12 14:40:08 -08003170 /* number of hardware queues supported by blk/scsi-mq*/
3171 host->nr_hw_queues = ha->max_qpairs;
3172
3173 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3174 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003175 } else {
3176 if (ql2xnvmeenable) {
3177 host->nr_hw_queues = ha->max_qpairs;
3178 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3179 "FC-NVMe support is enabled, HW queues=%d\n",
3180 host->nr_hw_queues);
3181 } else {
3182 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3183 "blk/scsi-mq disabled.\n");
3184 }
3185 }
Michael Hernandez56012362016-12-12 14:40:08 -08003186
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003187 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003188
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003189 pci_save_state(pdev);
3190
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003191 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003192 rsp->req = req;
3193 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003194
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003195 if (IS_QLAFX00(ha)) {
3196 ha->rsp_q_map[0] = rsp;
3197 ha->req_q_map[0] = req;
3198 set_bit(0, ha->req_qid_map);
3199 set_bit(0, ha->rsp_qid_map);
3200 }
3201
Andrew Vasquez08029992009-03-24 09:07:55 -07003202 /* FWI2-capable only. */
3203 req->req_q_in = &ha->iobase->isp24.req_q_in;
3204 req->req_q_out = &ha->iobase->isp24.req_q_out;
3205 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3206 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003207 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3208 IS_QLA28XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003209 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3210 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3211 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3212 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003213 }
3214
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003215 if (IS_QLAFX00(ha)) {
3216 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3217 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3218 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3219 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3220 }
3221
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003222 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003223 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3224 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3225 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3226 }
3227
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003228 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3229 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3230 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3231 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3232 "req->req_q_in=%p req->req_q_out=%p "
3233 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3234 req->req_q_in, req->req_q_out,
3235 rsp->rsp_q_in, rsp->rsp_q_out);
3236 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3237 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3238 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3239 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3240 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3241 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242
himanshu.madhani@cavium.comd48cc672018-07-02 13:01:59 -07003243 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3244
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003245 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003246 ql_log(ql_log_fatal, base_vha, 0x00d6,
3247 "Failed to initialize adapter - Adapter flags %x.\n",
3248 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249
Giridhar Malavalia9083012010-04-12 17:59:55 -07003250 if (IS_QLA82XX(ha)) {
3251 qla82xx_idc_lock(ha);
3252 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003253 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003254 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003255 ql_log(ql_log_fatal, base_vha, 0x00d7,
3256 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003257 } else if (IS_QLA8044(ha)) {
3258 qla8044_idc_lock(ha);
3259 qla8044_wr_direct(base_vha,
3260 QLA8044_CRB_DEV_STATE_INDEX,
3261 QLA8XXX_DEV_FAILED);
3262 qla8044_idc_unlock(ha);
3263 ql_log(ql_log_fatal, base_vha, 0x0150,
3264 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003265 }
3266
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 ret = -ENODEV;
3268 goto probe_failed;
3269 }
3270
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003271 if (IS_QLAFX00(ha))
3272 host->can_queue = QLAFX00_MAX_CANQUEUE;
3273 else
3274 host->can_queue = req->num_outstanding_cmds - 10;
3275
3276 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3277 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3278 host->can_queue, base_vha->req,
3279 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3280
Quinn Trane326d222017-06-13 20:47:18 -07003281 if (ha->mqenable) {
Quinn Trane326d222017-06-13 20:47:18 -07003282 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003283
Jens Axboef664a3c2018-11-01 16:36:27 -06003284 if (QLA_TGT_MODE_ENABLED())
Quinn Trane326d222017-06-13 20:47:18 -07003285 startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003286
Jens Axboef664a3c2018-11-01 16:36:27 -06003287 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
Quinn Trane326d222017-06-13 20:47:18 -07003288 startit = true;
Quinn Trane326d222017-06-13 20:47:18 -07003289
Jens Axboef664a3c2018-11-01 16:36:27 -06003290 /* Create start of day qpairs for Block MQ */
3291 for (i = 0; i < ha->max_qpairs; i++)
3292 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003293 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003294
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003295 if (ha->flags.running_gold_fw)
3296 goto skip_dpc;
3297
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003298 /*
3299 * Startup the kernel thread for this host adapter
3300 */
3301 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003302 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003303 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003304 ql_log(ql_log_fatal, base_vha, 0x00ed,
3305 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003307 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003308 goto probe_failed;
3309 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003310 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3311 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003313 /*
3314 * If we're not coming up in initiator mode, we might sit for
3315 * a while without waking up the dpc thread, which leads to a
3316 * stuck process warning. So just kick the dpc once here and
3317 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3318 */
3319 qla2xxx_wake_dpc(base_vha);
3320
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003321 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3322
Saurav Kashyap81178772012-08-22 14:21:04 -04003323 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3324 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3325 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3326 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3327
3328 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3329 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3330 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3331 INIT_WORK(&ha->idc_state_handler,
3332 qla83xx_idc_state_handler_work);
3333 INIT_WORK(&ha->nic_core_unrecoverable,
3334 qla83xx_nic_core_unrecoverable_work);
3335 }
3336
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003337skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338 list_add_tail(&base_vha->list, &ha->vp_list);
3339 base_vha->host->irq = ha->pdev->irq;
3340
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003342 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003343 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3344 "Started qla2x00_timer with "
3345 "interval=%d.\n", WATCH_INTERVAL);
3346 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3347 "Detected hba at address=%p.\n",
3348 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349
Arun Easie02587d2011-08-16 11:29:23 -07003350 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003351 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003352 int prot = 0, guard;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07003353
Arun Easibad75002010-05-04 15:01:30 -07003354 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003355 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3356 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003357 if (ql2xenabledif == 1)
3358 prot = SHOST_DIX_TYPE0_PROTECTION;
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003359 if (ql2xprotmask)
3360 scsi_host_set_prot(host, ql2xprotmask);
3361 else
3362 scsi_host_set_prot(host,
3363 prot | SHOST_DIF_TYPE1_PROTECTION
3364 | SHOST_DIF_TYPE2_PROTECTION
3365 | SHOST_DIF_TYPE3_PROTECTION
3366 | SHOST_DIX_TYPE1_PROTECTION
3367 | SHOST_DIX_TYPE2_PROTECTION
3368 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003369
3370 guard = SHOST_DIX_GUARD_CRC;
3371
3372 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3373 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3374 guard |= SHOST_DIX_GUARD_IP;
3375
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003376 if (ql2xprotguard)
3377 scsi_host_set_guard(host, ql2xprotguard);
3378 else
3379 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003380 } else
3381 base_vha->flags.difdix_supported = 0;
3382 }
3383
Giridhar Malavalia9083012010-04-12 17:59:55 -07003384 ha->isp_ops->enable_intrs(ha);
3385
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003386 if (IS_QLAFX00(ha)) {
3387 ret = qlafx00_fx_disc(base_vha,
3388 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3389 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3390 QLA_SG_ALL : 128;
3391 }
3392
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003393 ret = scsi_add_host(host, &pdev->dev);
3394 if (ret)
3395 goto probe_failed;
3396
Michael Reed14864002009-12-02 09:11:16 -06003397 base_vha->flags.init_done = 1;
3398 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003399 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003400
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003401 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3402 "Init done and hba is online.\n");
3403
Quinn Tran726b8542017-01-19 22:28:00 -08003404 if (qla_ini_mode_enabled(base_vha) ||
3405 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003406 scsi_scan_host(host);
3407 else
3408 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3409 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003410
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003412
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003413 if (IS_QLAFX00(ha)) {
3414 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003415 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3416
3417 /* Register system information */
3418 ret = qlafx00_fx_disc(base_vha,
3419 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3420 }
3421
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003422 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003423
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003424 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003425
Armen Baloyan03eb9122013-10-30 03:38:22 -04003426 ql_log(ql_log_info, base_vha, 0x00fb,
3427 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003428 ql_log(ql_log_info, base_vha, 0x00fc,
3429 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3430 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3431 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3432 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003433 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003435 qlt_add_target(ha, base_vha);
3436
Joe Lawrence6b383972014-08-26 17:12:29 -04003437 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003438
3439 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3440 return -ENODEV;
3441
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003442 if (ha->flags.detected_lr_sfp) {
3443 ql_log(ql_log_info, base_vha, 0xffff,
3444 "Reset chip to pick up LR SFP setting\n");
3445 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3446 qla2xxx_wake_dpc(base_vha);
3447 }
3448
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 return 0;
3450
3451probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003452 if (base_vha->timer_active)
3453 qla2x00_stop_timer(base_vha);
3454 base_vha->flags.online = 0;
3455 if (ha->dpc_thread) {
3456 struct task_struct *t = ha->dpc_thread;
3457
3458 ha->dpc_thread = NULL;
3459 kthread_stop(t);
3460 }
3461
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003462 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003463 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003464 /*
3465 * Need to NULL out local req/rsp after
3466 * qla2x00_free_device => qla2x00_free_queues frees
3467 * what these are pointing to. Or else we'll
3468 * fall over below in qla2x00_free_req/rsp_que.
3469 */
3470 req = NULL;
3471 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003474 qla2x00_mem_free(ha);
3475 qla2x00_free_req_que(ha, req);
3476 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003477 qla2x00_clear_drv_active(ha);
3478
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003479iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003480 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003481 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003482 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003483 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003484 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003485 } else {
3486 if (ha->iobase)
3487 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003488 if (ha->cregbase)
3489 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003490 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491 pci_release_selected_regions(ha->pdev, ha->bars);
3492 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003494disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003495 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003496 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
Adrian Bunk4c993f72008-01-14 00:55:16 -08003499static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003500qla2x00_shutdown(struct pci_dev *pdev)
3501{
3502 scsi_qla_host_t *vha;
3503 struct qla_hw_data *ha;
3504
3505 vha = pci_get_drvdata(pdev);
3506 ha = vha->hw;
3507
Sawan Chandakefdb5762017-08-23 15:05:00 -07003508 ql_log(ql_log_info, vha, 0xfffa,
3509 "Adapter shutdown\n");
3510
3511 /*
3512 * Prevent future board_disable and wait
3513 * until any pending board_disable has completed.
3514 */
3515 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3516 cancel_work_sync(&ha->board_disable);
3517
3518 if (!atomic_read(&pdev->enable_cnt))
3519 return;
3520
Armen Baloyan42479342013-08-27 01:37:37 -04003521 /* Notify ISPFX00 firmware */
3522 if (IS_QLAFX00(ha))
3523 qlafx00_driver_shutdown(vha, 20);
3524
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003525 /* Turn-off FCE trace */
3526 if (ha->flags.fce_enabled) {
3527 qla2x00_disable_fce_trace(vha, NULL, NULL);
3528 ha->flags.fce_enabled = 0;
3529 }
3530
3531 /* Turn-off EFT trace */
3532 if (ha->eft)
3533 qla2x00_disable_eft_trace(vha);
3534
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003535 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3536 IS_QLA28XX(ha)) {
Quinn Tran3407fc32017-12-28 12:33:11 -08003537 if (ha->flags.fw_started)
3538 qla2x00_abort_isp_cleanup(vha);
3539 } else {
3540 /* Stop currently executing firmware. */
3541 qla2x00_try_to_stop_firmware(vha);
3542 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003543
3544 /* Turn adapter off line */
3545 vha->flags.online = 0;
3546
3547 /* turn-off interrupts on the card */
3548 if (ha->interrupts_on) {
3549 vha->flags.init_done = 0;
3550 ha->isp_ops->disable_intrs(ha);
3551 }
3552
3553 qla2x00_free_irqs(vha);
3554
3555 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003556
Chad Dupuis61d41f62014-09-25 05:17:02 -04003557 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003558 ql_log(ql_log_info, vha, 0xfffe,
3559 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003560}
3561
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003562/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003563static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003564qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003566 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003567 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568
Arun Easi43ebf162011-05-10 11:18:16 -07003569 mutex_lock(&ha->vport_lock);
3570 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003571 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003572
Arun Easi43ebf162011-05-10 11:18:16 -07003573 BUG_ON(base_vha->list.next == &ha->vp_list);
3574 /* This assumes first entry in ha->vp_list is always base vha */
3575 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003576 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003577
Arun Easi43ebf162011-05-10 11:18:16 -07003578 spin_unlock_irqrestore(&ha->vport_slock, flags);
3579 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003580
Himanshu Madhani5e6803b2018-12-10 12:36:23 -08003581 qla_nvme_delete(vha);
3582
Arun Easi43ebf162011-05-10 11:18:16 -07003583 fc_vport_terminate(vha->fc_vport);
3584 scsi_host_put(vha->host);
3585
3586 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003587 }
Arun Easi43ebf162011-05-10 11:18:16 -07003588 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003589}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003590
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003591/* Stops all deferred work threads */
3592static void
3593qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3594{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003595 /* Cancel all work and destroy DPC workqueues */
3596 if (ha->dpc_lp_wq) {
3597 cancel_work_sync(&ha->idc_aen);
3598 destroy_workqueue(ha->dpc_lp_wq);
3599 ha->dpc_lp_wq = NULL;
3600 }
3601
3602 if (ha->dpc_hp_wq) {
3603 cancel_work_sync(&ha->nic_core_reset);
3604 cancel_work_sync(&ha->idc_state_handler);
3605 cancel_work_sync(&ha->nic_core_unrecoverable);
3606 destroy_workqueue(ha->dpc_hp_wq);
3607 ha->dpc_hp_wq = NULL;
3608 }
3609
Andrew Vasquezb9978762009-03-24 09:08:05 -07003610 /* Kill the kernel thread for this host */
3611 if (ha->dpc_thread) {
3612 struct task_struct *t = ha->dpc_thread;
3613
3614 /*
3615 * qla2xxx_wake_dpc checks for ->dpc_thread
3616 * so we need to zero it out.
3617 */
3618 ha->dpc_thread = NULL;
3619 kthread_stop(t);
3620 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003621}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003622
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003623static void
3624qla2x00_unmap_iobases(struct qla_hw_data *ha)
3625{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003626 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003627
Chad Dupuisf73cb692014-02-26 04:15:06 -05003628 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003629 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003630 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003631 } else {
3632 if (ha->iobase)
3633 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003634
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003635 if (ha->cregbase)
3636 iounmap(ha->cregbase);
3637
Giridhar Malavalia9083012010-04-12 17:59:55 -07003638 if (ha->mqiobase)
3639 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003640
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003641 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) &&
3642 ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003643 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003644 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003645}
3646
3647static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003648qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003649{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003650 if (IS_QLA8044(ha)) {
3651 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003652 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003653 qla8044_idc_unlock(ha);
3654 } else if (IS_QLA82XX(ha)) {
3655 qla82xx_idc_lock(ha);
3656 qla82xx_clear_drv_active(ha);
3657 qla82xx_idc_unlock(ha);
3658 }
3659}
3660
3661static void
3662qla2x00_remove_one(struct pci_dev *pdev)
3663{
3664 scsi_qla_host_t *base_vha;
3665 struct qla_hw_data *ha;
3666
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003667 base_vha = pci_get_drvdata(pdev);
3668 ha = base_vha->hw;
Quinn Tran45235022018-07-18 14:29:53 -07003669 ql_log(ql_log_info, base_vha, 0xb079,
3670 "Removing driver\n");
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003671
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003672 /* Indicate device removal to prevent future board_disable and wait
3673 * until any pending board_disable has completed. */
3674 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3675 cancel_work_sync(&ha->board_disable);
3676
3677 /*
3678 * If the PCI device is disabled then there was a PCI-disconnect and
3679 * qla2x00_disable_board_on_pci_error has taken care of most of the
3680 * resources.
3681 */
3682 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003683 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3684 base_vha->gnl.l, base_vha->gnl.ldma);
3685
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003686 scsi_host_put(base_vha->host);
3687 kfree(ha);
3688 pci_set_drvdata(pdev, NULL);
3689 return;
3690 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003691 qla2x00_wait_for_hba_ready(base_vha);
3692
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003693 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3694 IS_QLA28XX(ha)) {
Quinn Tran45235022018-07-18 14:29:53 -07003695 if (ha->flags.fw_started)
3696 qla2x00_abort_isp_cleanup(base_vha);
3697 } else if (!IS_QLAFX00(ha)) {
3698 if (IS_QLA8031(ha)) {
3699 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3700 "Clearing fcoe driver presence.\n");
3701 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3702 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3703 "Error while clearing DRV-Presence.\n");
3704 }
3705
3706 qla2x00_try_to_stop_firmware(base_vha);
3707 }
3708
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003709 qla2x00_wait_for_sess_deletion(base_vha);
3710
Quinn Tran726b8542017-01-19 22:28:00 -08003711 /*
3712 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003713 * where it was set first.
3714 */
3715 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3716 return;
3717
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003718 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003719
3720 qla_nvme_delete(base_vha);
3721
Quinn Tran726b8542017-01-19 22:28:00 -08003722 dma_free_coherent(&ha->pdev->dev,
3723 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003724
Quinn Trana4239942017-12-28 12:33:26 -08003725 vfree(base_vha->scan.l);
3726
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003727 if (IS_QLAFX00(ha))
3728 qlafx00_driver_shutdown(base_vha, 20);
3729
3730 qla2x00_delete_all_vps(ha, base_vha);
3731
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003732 qla2x00_dfs_remove(base_vha);
3733
3734 qla84xx_put_chip(base_vha);
3735
3736 /* Disable timer */
3737 if (base_vha->timer_active)
3738 qla2x00_stop_timer(base_vha);
3739
3740 base_vha->flags.online = 0;
3741
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003742 /* free DMA memory */
3743 if (ha->exlogin_buf)
3744 qla2x00_free_exlogin_buffer(ha);
3745
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003746 /* free DMA memory */
3747 if (ha->exchoffld_buf)
3748 qla2x00_free_exchoffld_buffer(ha);
3749
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003750 qla2x00_destroy_deferred_work(ha);
3751
3752 qlt_remove_target(ha, base_vha);
3753
3754 qla2x00_free_sysfs_attr(base_vha, true);
3755
3756 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003757 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003758
3759 scsi_remove_host(base_vha->host);
3760
3761 qla2x00_free_device(base_vha);
3762
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003763 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003764
Arun Easid2749ff2014-09-25 05:16:51 -04003765 scsi_host_put(base_vha->host);
3766
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003767 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003768
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003769 pci_release_selected_regions(ha->pdev, ha->bars);
3770 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003772 pci_disable_pcie_error_reporting(pdev);
3773
Bernhard Walle665db932007-03-28 00:49:49 +02003774 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
3777static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003778qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003780 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781
Andrew Vasquez85880802009-12-15 21:29:46 -08003782 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3783
3784 /* Disable timer */
3785 if (vha->timer_active)
3786 qla2x00_stop_timer(vha);
3787
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003788 qla25xx_delete_queues(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003789 vha->flags.online = 0;
3790
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003791 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003792 if (ha->interrupts_on) {
3793 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003794 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003795 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003796
Quinn Tran093df732016-12-12 14:40:09 -08003797 qla2x00_free_fcports(vha);
3798
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003799 qla2x00_free_irqs(vha);
3800
Quinn Tran093df732016-12-12 14:40:09 -08003801 /* Flush the work queue and remove it */
3802 if (ha->wq) {
3803 flush_workqueue(ha->wq);
3804 destroy_workqueue(ha->wq);
3805 ha->wq = NULL;
3806 }
3807
Chad Dupuis88670482010-07-23 15:28:30 +05003808
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003809 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003810
Giridhar Malavali08de2842011-08-16 11:31:44 -07003811 qla82xx_md_free(vha);
3812
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003813 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814}
3815
Chad Dupuis88670482010-07-23 15:28:30 +05003816void qla2x00_free_fcports(struct scsi_qla_host *vha)
3817{
3818 fc_port_t *fcport, *tfcport;
3819
Quinn Tranffbc6472019-04-02 14:24:29 -07003820 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
3821 qla2x00_free_fcport(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003822}
3823
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003824static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003825qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003826 int defer)
3827{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003828 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003829 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003830 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003831
3832 if (!fcport->rport)
3833 return;
3834
3835 rport = fcport->rport;
3836 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003837 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003838 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003839 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003840 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003841 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003842 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3843 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003844 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003845 int now;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07003846
Quinn Tran726b8542017-01-19 22:28:00 -08003847 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003848 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3849 "%s %8phN. rport %p roles %x\n",
3850 __func__, fcport->port_name, rport,
3851 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003852 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003853 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003854 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003855 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003856}
3857
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3860 *
3861 * Input: ha = adapter block pointer. fcport = port structure pointer.
3862 *
3863 * Return: None.
3864 *
3865 * Context:
3866 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003867void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003868 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003870 if (IS_QLAFX00(vha->hw)) {
3871 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3872 qla2x00_schedule_rport_del(vha, fcport, defer);
3873 return;
3874 }
3875
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003876 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003877 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003878 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003879 qla2x00_schedule_rport_del(vha, fcport, defer);
3880 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003881 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 * We may need to retry the login, so don't change the state of the
3883 * port but do the retries.
3884 */
3885 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003886 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887
3888 if (!do_login)
3889 return;
3890
Arun Easia1d02852015-08-04 13:38:02 -04003891 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892}
3893
3894/*
3895 * qla2x00_mark_all_devices_lost
3896 * Updates fcport state when device goes offline.
3897 *
3898 * Input:
3899 * ha = adapter block pointer.
3900 * fcport = port structure pointer.
3901 *
3902 * Return:
3903 * None.
3904 *
3905 * Context:
3906 */
3907void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003908qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909{
3910 fc_port_t *fcport;
3911
Quinn Tran83548fe2017-06-02 09:12:01 -07003912 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3913 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003914
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003915 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003916 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08003917 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003918
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003919 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003921
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 /*
3923 * No point in marking the device as lost, if the device is
3924 * already DEAD.
3925 */
3926 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3927 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003928 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003929 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003930 if (defer)
3931 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003932 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003933 qla2x00_schedule_rport_del(vha, fcport, defer);
3934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 }
3936}
3937
Bart Van Assche0e145a52019-04-17 14:44:12 -07003938static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
3939{
3940 int i;
3941
3942 if (IS_FWI2_CAPABLE(ha))
3943 return;
3944
3945 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
3946 set_bit(i, ha->loop_id_map);
3947 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
3948 set_bit(BROADCAST, ha->loop_id_map);
3949}
3950
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951/*
3952* qla2x00_mem_alloc
3953* Allocates adapter memory.
3954*
3955* Returns:
3956* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08003957* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08003959static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003960qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
3961 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962{
3963 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964
Andrew Vasqueze8711082008-01-31 12:33:48 -08003965 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003966 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08003967 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003970 if (qlt_mem_alloc(ha) < 0)
3971 goto fail_free_init_cb;
3972
Chad Dupuis642ef982012-02-09 11:15:57 -08003973 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
3974 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003975 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003976 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977
Andrew Vasqueze8711082008-01-31 12:33:48 -08003978 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
3979 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003980 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003982 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003983 /* Allocate cache for CT6 Ctx. */
3984 if (!ctx_cachep) {
3985 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
3986 sizeof(struct ct6_dsd), 0,
3987 SLAB_HWCACHE_ALIGN, NULL);
3988 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08003989 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003990 }
3991 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
3992 ctx_cachep);
3993 if (!ha->ctx_mempool)
3994 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003995 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
3996 "ctx_cachep=%p ctx_mempool=%p.\n",
3997 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003998 }
3999
Andrew Vasqueze8711082008-01-31 12:33:48 -08004000 /* Get memory for cached NVRAM */
4001 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4002 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004003 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4006 ha->pdev->device);
4007 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4008 DMA_POOL_SIZE, 8, 0);
4009 if (!ha->s_dma_pool)
4010 goto fail_free_nvram;
4011
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004012 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4013 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4014 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4015
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004016 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004017 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4018 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4019 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004020 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4021 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004022 goto fail_s_dma_pool;
4023 }
4024
4025 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4026 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4027 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004028 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4029 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004030 goto fail_dl_dma_pool;
4031 }
Giridhar Malavali50b81272018-12-21 09:33:45 -08004032
4033 if (ql2xenabledif) {
4034 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4035 struct dsd_dma *dsd, *nxt;
4036 uint i;
4037 /* Creata a DMA pool of buffers for DIF bundling */
4038 ha->dif_bundl_pool = dma_pool_create(name,
4039 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4040 if (!ha->dif_bundl_pool) {
4041 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4042 "%s: failed create dif_bundl_pool\n",
4043 __func__);
4044 goto fail_dif_bundl_dma_pool;
4045 }
4046
4047 INIT_LIST_HEAD(&ha->pool.good.head);
4048 INIT_LIST_HEAD(&ha->pool.unusable.head);
4049 ha->pool.good.count = 0;
4050 ha->pool.unusable.count = 0;
4051 for (i = 0; i < 128; i++) {
4052 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4053 if (!dsd) {
4054 ql_dbg_pci(ql_dbg_init, ha->pdev,
4055 0xe0ee, "%s: failed alloc dsd\n",
4056 __func__);
4057 return 1;
4058 }
4059 ha->dif_bundle_kallocs++;
4060
4061 dsd->dsd_addr = dma_pool_alloc(
4062 ha->dif_bundl_pool, GFP_ATOMIC,
4063 &dsd->dsd_list_dma);
4064 if (!dsd->dsd_addr) {
4065 ql_dbg_pci(ql_dbg_init, ha->pdev,
4066 0xe0ee,
4067 "%s: failed alloc ->dsd_addr\n",
4068 __func__);
4069 kfree(dsd);
4070 ha->dif_bundle_kallocs--;
4071 continue;
4072 }
4073 ha->dif_bundle_dma_allocs++;
4074
4075 /*
4076 * if DMA buffer crosses 4G boundary,
4077 * put it on bad list
4078 */
4079 if (MSD(dsd->dsd_list_dma) ^
4080 MSD(dsd->dsd_list_dma + bufsize)) {
4081 list_add_tail(&dsd->list,
4082 &ha->pool.unusable.head);
4083 ha->pool.unusable.count++;
4084 } else {
4085 list_add_tail(&dsd->list,
4086 &ha->pool.good.head);
4087 ha->pool.good.count++;
4088 }
4089 }
4090
4091 /* return the good ones back to the pool */
4092 list_for_each_entry_safe(dsd, nxt,
4093 &ha->pool.good.head, list) {
4094 list_del(&dsd->list);
4095 dma_pool_free(ha->dif_bundl_pool,
4096 dsd->dsd_addr, dsd->dsd_list_dma);
4097 ha->dif_bundle_dma_allocs--;
4098 kfree(dsd);
4099 ha->dif_bundle_kallocs--;
4100 }
4101
4102 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4103 "%s: dif dma pool (good=%u unusable=%u)\n",
4104 __func__, ha->pool.good.count,
4105 ha->pool.unusable.count);
4106 }
4107
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004108 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
Giridhar Malavali50b81272018-12-21 09:33:45 -08004109 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4110 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4111 ha->dif_bundl_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004112 }
4113
Andrew Vasqueze8711082008-01-31 12:33:48 -08004114 /* Allocate memory for SNS commands */
4115 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004116 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004117 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004118 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004119 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004120 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004121 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08004122 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004123 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004124 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004125 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004126 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004127 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004128 goto fail_dma_pool;
4129 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004130 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004131 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004132 if (!ha->ct_sns)
4133 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004134 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4135 "ms_iocb=%p ct_sns=%p.\n",
4136 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 }
4138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004139 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004140 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4141 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004142 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4143 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004144 goto fail_req;
4145 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004146 (*req)->length = req_len;
4147 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4148 ((*req)->length + 1) * sizeof(request_t),
4149 &(*req)->dma, GFP_KERNEL);
4150 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004151 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4152 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004153 goto fail_req_ring;
4154 }
4155 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004156 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4157 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004158 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4159 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004160 goto fail_rsp;
4161 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004162 (*rsp)->hw = ha;
4163 (*rsp)->length = rsp_len;
4164 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4165 ((*rsp)->length + 1) * sizeof(response_t),
4166 &(*rsp)->dma, GFP_KERNEL);
4167 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004168 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4169 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004170 goto fail_rsp_ring;
4171 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004172 (*req)->rsp = *rsp;
4173 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004174 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4175 "req=%p req->length=%d req->ring=%p rsp=%p "
4176 "rsp->length=%d rsp->ring=%p.\n",
4177 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4178 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004179 /* Allocate memory for NVRAM data for vports */
4180 if (ha->nvram_npiv_size) {
Kees Cook6396bb22018-06-12 14:03:40 -07004181 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4182 sizeof(struct qla_npiv_entry),
4183 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004184 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004185 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4186 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004187 goto fail_npiv_info;
4188 }
4189 } else
4190 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004191
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004192 /* Get consistent memory allocated for EX-INIT-CB. */
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004193 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4194 IS_QLA28XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004195 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4196 &ha->ex_init_cb_dma);
4197 if (!ha->ex_init_cb)
4198 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004199 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4200 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004201 }
4202
Giridhar Malavalia9083012010-04-12 17:59:55 -07004203 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4204
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004205 /* Get consistent memory allocated for Async Port-Database. */
4206 if (!IS_FWI2_CAPABLE(ha)) {
4207 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4208 &ha->async_pd_dma);
4209 if (!ha->async_pd)
4210 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004211 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4212 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004213 }
4214
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004215 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004216
4217 /* Allocate memory for our loop_id bitmap */
Kees Cook6396bb22018-06-12 14:03:40 -07004218 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4219 sizeof(long),
4220 GFP_KERNEL);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004221 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004222 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004223 else {
4224 qla2x00_set_reserved_loop_ids(ha);
4225 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004226 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004227 }
4228
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004229 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4230 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4231 if (!ha->sfp_data) {
4232 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4233 "Unable to allocate memory for SFP read-data.\n");
4234 goto fail_sfp_data;
4235 }
4236
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004237 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4238 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4239 GFP_KERNEL);
4240 if (!ha->flt) {
4241 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4242 "Unable to allocate memory for FLT.\n");
4243 goto fail_flt_buffer;
4244 }
4245
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004246 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004247
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004248fail_flt_buffer:
4249 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4250 ha->sfp_data, ha->sfp_data_dma);
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004251fail_sfp_data:
4252 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004253fail_loop_id_map:
4254 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004255fail_async_pd:
4256 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004257fail_ex_init_cb:
4258 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004259fail_npiv_info:
4260 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4261 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4262 (*rsp)->ring = NULL;
4263 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004264fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004265 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004266 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004267fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004268 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4269 sizeof(request_t), (*req)->ring, (*req)->dma);
4270 (*req)->ring = NULL;
4271 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004272fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004273 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004274 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004275fail_req:
4276 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4277 ha->ct_sns, ha->ct_sns_dma);
4278 ha->ct_sns = NULL;
4279 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004280fail_free_ms_iocb:
4281 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4282 ha->ms_iocb = NULL;
4283 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004284
4285 if (ha->sns_cmd)
4286 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4287 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004288fail_dma_pool:
Giridhar Malavali50b81272018-12-21 09:33:45 -08004289 if (ql2xenabledif) {
4290 struct dsd_dma *dsd, *nxt;
4291
4292 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4293 list) {
4294 list_del(&dsd->list);
4295 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4296 dsd->dsd_list_dma);
4297 ha->dif_bundle_dma_allocs--;
4298 kfree(dsd);
4299 ha->dif_bundle_kallocs--;
4300 ha->pool.unusable.count--;
4301 }
4302 dma_pool_destroy(ha->dif_bundl_pool);
4303 ha->dif_bundl_pool = NULL;
4304 }
4305
4306fail_dif_bundl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004307 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004308 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4309 ha->fcp_cmnd_dma_pool = NULL;
4310 }
4311fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004312 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004313 dma_pool_destroy(ha->dl_dma_pool);
4314 ha->dl_dma_pool = NULL;
4315 }
4316fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004317 dma_pool_destroy(ha->s_dma_pool);
4318 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004319fail_free_nvram:
4320 kfree(ha->nvram);
4321 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004322fail_free_ctx_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004323 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004324 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004325fail_free_srb_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004326 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004327 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004328fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004329 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4330 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004331 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004332 ha->gid_list = NULL;
4333 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004334fail_free_tgt_mem:
4335 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004336fail_free_init_cb:
4337 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4338 ha->init_cb_dma);
4339 ha->init_cb = NULL;
4340 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004341fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004342 ql_log(ql_log_fatal, NULL, 0x0030,
4343 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004344 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345}
4346
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004347int
4348qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4349{
4350 int rval;
4351 uint16_t size, max_cnt, temp;
4352 struct qla_hw_data *ha = vha->hw;
4353
4354 /* Return if we don't need to alloacate any extended logins */
4355 if (!ql2xexlogins)
4356 return QLA_SUCCESS;
4357
Quinn Tran99e1b682017-06-02 09:12:03 -07004358 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4359 return QLA_SUCCESS;
4360
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004361 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4362 max_cnt = 0;
4363 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4364 if (rval != QLA_SUCCESS) {
4365 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4366 "Failed to get exlogin status.\n");
4367 return rval;
4368 }
4369
4370 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004371 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004372
Quinn Tran99e1b682017-06-02 09:12:03 -07004373 if (temp != ha->exlogin_size) {
4374 qla2x00_free_exlogin_buffer(ha);
4375 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004376
Quinn Tran99e1b682017-06-02 09:12:03 -07004377 ql_log(ql_log_info, vha, 0xd024,
4378 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4379 max_cnt, size, temp);
4380
4381 ql_log(ql_log_info, vha, 0xd025,
4382 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4383
4384 /* Get consistent memory for extended logins */
4385 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4386 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4387 if (!ha->exlogin_buf) {
4388 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004389 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004390 return -ENOMEM;
4391 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004392 }
4393
4394 /* Now configure the dma buffer */
4395 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4396 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004397 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004398 "Setup extended login buffer ****FAILED****.\n");
4399 qla2x00_free_exlogin_buffer(ha);
4400 }
4401
4402 return rval;
4403}
4404
4405/*
4406* qla2x00_free_exlogin_buffer
4407*
4408* Input:
4409* ha = adapter block pointer
4410*/
4411void
4412qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4413{
4414 if (ha->exlogin_buf) {
4415 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4416 ha->exlogin_buf, ha->exlogin_buf_dma);
4417 ha->exlogin_buf = NULL;
4418 ha->exlogin_size = 0;
4419 }
4420}
4421
Quinn Tran99e1b682017-06-02 09:12:03 -07004422static void
4423qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4424{
4425 u32 temp;
Quinn Tran0645cb82018-09-11 10:18:18 -07004426 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
Quinn Tran99e1b682017-06-02 09:12:03 -07004427 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4428
Quinn Trand1e36352017-12-28 12:33:12 -08004429 if (max_cnt > vha->hw->max_exchg)
4430 max_cnt = vha->hw->max_exchg;
4431
Quinn Tran99e1b682017-06-02 09:12:03 -07004432 if (qla_ini_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004433 if (vha->ql2xiniexchg > max_cnt)
4434 vha->ql2xiniexchg = max_cnt;
Quinn Tran99e1b682017-06-02 09:12:03 -07004435
Quinn Tran0645cb82018-09-11 10:18:18 -07004436 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4437 *ret_cnt = vha->ql2xiniexchg;
4438
Quinn Tran99e1b682017-06-02 09:12:03 -07004439 } else if (qla_tgt_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004440 if (vha->ql2xexchoffld > max_cnt) {
4441 vha->ql2xexchoffld = max_cnt;
4442 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4443 }
Quinn Tran99e1b682017-06-02 09:12:03 -07004444
Quinn Tran0645cb82018-09-11 10:18:18 -07004445 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4446 *ret_cnt = vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004447 } else if (qla_dual_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004448 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004449 if (temp > max_cnt) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004450 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4451 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
Quinn Tran99e1b682017-06-02 09:12:03 -07004452 temp = max_cnt;
Quinn Tran0645cb82018-09-11 10:18:18 -07004453 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Quinn Tran99e1b682017-06-02 09:12:03 -07004454 }
4455
4456 if (temp > FW_DEF_EXCHANGES_CNT)
4457 *ret_cnt = temp;
4458 }
4459}
4460
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004461int
4462qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4463{
4464 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004465 u16 size, max_cnt;
4466 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004467 struct qla_hw_data *ha = vha->hw;
4468
Quinn Tran99e1b682017-06-02 09:12:03 -07004469 if (!ha->flags.exchoffld_enabled)
4470 return QLA_SUCCESS;
4471
4472 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004473 return QLA_SUCCESS;
4474
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004475 max_cnt = 0;
4476 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4477 if (rval != QLA_SUCCESS) {
4478 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4479 "Failed to get exlogin status.\n");
4480 return rval;
4481 }
4482
Quinn Trand1e36352017-12-28 12:33:12 -08004483 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4484 ql_log(ql_log_info, vha, 0xd014,
4485 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004486
Quinn Trand1e36352017-12-28 12:33:12 -08004487 totsz = actual_cnt * size;
4488
4489 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004490 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran0645cb82018-09-11 10:18:18 -07004491 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4492 ha->exchoffld_size = 0;
4493 ha->flags.exchoffld_enabled = 0;
4494 return QLA_SUCCESS;
4495 }
4496
Quinn Trand1e36352017-12-28 12:33:12 -08004497 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004498
Quinn Tran99e1b682017-06-02 09:12:03 -07004499 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004500 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4501 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004502
4503 ql_log(ql_log_info, vha, 0xd017,
4504 "Exchange Buffers requested size = 0x%x\n",
4505 ha->exchoffld_size);
4506
4507 /* Get consistent memory for extended logins */
4508 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4509 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4510 if (!ha->exchoffld_buf) {
4511 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004512 "Failed to allocate memory for Exchange Offload.\n");
4513
4514 if (ha->max_exchg >
4515 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4516 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4517 } else if (ha->max_exchg >
4518 (FW_DEF_EXCHANGES_CNT + 512)) {
4519 ha->max_exchg -= 512;
4520 } else {
4521 ha->flags.exchoffld_enabled = 0;
4522 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4523 "Disabling Exchange offload due to lack of memory\n");
4524 }
4525 ha->exchoffld_size = 0;
4526
Quinn Tran99e1b682017-06-02 09:12:03 -07004527 return -ENOMEM;
4528 }
Quinn Tran0645cb82018-09-11 10:18:18 -07004529 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4530 /* pathological case */
4531 qla2x00_free_exchoffld_buffer(ha);
4532 ha->exchoffld_size = 0;
4533 ha->flags.exchoffld_enabled = 0;
4534 ql_log(ql_log_info, vha, 0xd016,
4535 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4536 ha->exchoffld_size, actual_cnt, size, totsz);
4537 return 0;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004538 }
4539
4540 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004541 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004542 if (rval) {
4543 ql_log(ql_log_fatal, vha, 0xd02e,
4544 "Setup exchange offload buffer ****FAILED****.\n");
4545 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004546 } else {
4547 /* re-adjust number of target exchange */
4548 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4549
4550 if (qla_ini_mode_enabled(vha))
4551 icb->exchange_count = 0;
4552 else
Quinn Tran0645cb82018-09-11 10:18:18 -07004553 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004554 }
4555
4556 return rval;
4557}
4558
4559/*
4560* qla2x00_free_exchoffld_buffer
4561*
4562* Input:
4563* ha = adapter block pointer
4564*/
4565void
4566qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4567{
4568 if (ha->exchoffld_buf) {
4569 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4570 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4571 ha->exchoffld_buf = NULL;
4572 ha->exchoffld_size = 0;
4573 }
4574}
4575
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004577* qla2x00_free_fw_dump
4578* Frees fw dump stuff.
4579*
4580* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004581* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004582*/
4583static void
4584qla2x00_free_fw_dump(struct qla_hw_data *ha)
4585{
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004586 struct fwdt *fwdt = ha->fwdt;
4587 uint j;
4588
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004589 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004590 dma_free_coherent(&ha->pdev->dev,
4591 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004592
Chad Dupuisf73cb692014-02-26 04:15:06 -05004593 if (ha->eft)
4594 dma_free_coherent(&ha->pdev->dev,
4595 EFT_SIZE, ha->eft, ha->eft_dma);
4596
4597 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004598 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004599
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004600 ha->fce = NULL;
4601 ha->fce_dma = 0;
4602 ha->eft = NULL;
4603 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004604 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004605 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004606 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004607 ha->fw_dump = NULL;
4608 ha->fw_dump_len = 0;
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004609
4610 for (j = 0; j < 2; j++, fwdt++) {
4611 if (fwdt->template)
4612 vfree(fwdt->template);
4613 fwdt->template = NULL;
4614 fwdt->length = 0;
4615 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004616}
4617
4618/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619* qla2x00_mem_free
4620* Frees all adapter allocated memory.
4621*
4622* Input:
4623* ha = adapter block pointer.
4624*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004625static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004626qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004628 qla2x00_free_fw_dump(ha);
4629
Saurav Kashyap81178772012-08-22 14:21:04 -04004630 if (ha->mctp_dump)
4631 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4632 ha->mctp_dump_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004633 ha->mctp_dump = NULL;
Saurav Kashyap81178772012-08-22 14:21:04 -04004634
Thomas Meyer75c1d482018-12-02 21:52:11 +01004635 mempool_destroy(ha->srb_mempool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004636 ha->srb_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004638 if (ha->dcbx_tlv)
4639 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4640 ha->dcbx_tlv, ha->dcbx_tlv_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004641 ha->dcbx_tlv = NULL;
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004642
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004643 if (ha->xgmac_data)
4644 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4645 ha->xgmac_data, ha->xgmac_data_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004646 ha->xgmac_data = NULL;
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004647
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 if (ha->sns_cmd)
4649 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004650 ha->sns_cmd, ha->sns_cmd_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004651 ha->sns_cmd = NULL;
4652 ha->sns_cmd_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653
4654 if (ha->ct_sns)
4655 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004656 ha->ct_sns, ha->ct_sns_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004657 ha->ct_sns = NULL;
4658 ha->ct_sns_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659
Andrew Vasquez88729e52006-06-23 16:10:50 -07004660 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004661 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4662 ha->sfp_data_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004663 ha->sfp_data = NULL;
Andrew Vasquez88729e52006-06-23 16:10:50 -07004664
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004665 if (ha->flt)
4666 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4667 ha->flt, ha->flt_dma);
Bart Van Asschedc035d42019-04-17 14:44:23 -07004668 ha->flt = NULL;
4669 ha->flt_dma = 0;
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004670
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671 if (ha->ms_iocb)
4672 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004673 ha->ms_iocb = NULL;
4674 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004676 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004677 dma_pool_free(ha->s_dma_pool,
4678 ha->ex_init_cb, ha->ex_init_cb_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004679 ha->ex_init_cb = NULL;
4680 ha->ex_init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004681
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004682 if (ha->async_pd)
4683 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004684 ha->async_pd = NULL;
4685 ha->async_pd_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004686
Thomas Meyer75c1d482018-12-02 21:52:11 +01004687 dma_pool_destroy(ha->s_dma_pool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004688 ha->s_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004691 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4692 ha->gid_list, ha->gid_list_dma);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004693 ha->gid_list = NULL;
4694 ha->gid_list_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695
Giridhar Malavalia9083012010-04-12 17:59:55 -07004696 if (IS_QLA82XX(ha)) {
4697 if (!list_empty(&ha->gbl_dsd_list)) {
4698 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4699
4700 /* clean up allocated prev pool */
4701 list_for_each_entry_safe(dsd_ptr,
4702 tdsd_ptr, &ha->gbl_dsd_list, list) {
4703 dma_pool_free(ha->dl_dma_pool,
4704 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4705 list_del(&dsd_ptr->list);
4706 kfree(dsd_ptr);
4707 }
4708 }
4709 }
4710
Thomas Meyer75c1d482018-12-02 21:52:11 +01004711 dma_pool_destroy(ha->dl_dma_pool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004712 ha->dl_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004713
Thomas Meyer75c1d482018-12-02 21:52:11 +01004714 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004715 ha->fcp_cmnd_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004716
Thomas Meyer75c1d482018-12-02 21:52:11 +01004717 mempool_destroy(ha->ctx_mempool);
Bart Van Assche5365bf92019-04-17 14:44:22 -07004718 ha->ctx_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004719
Giridhar Malavali50b81272018-12-21 09:33:45 -08004720 if (ql2xenabledif) {
4721 struct dsd_dma *dsd, *nxt;
4722
4723 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4724 list) {
4725 list_del(&dsd->list);
4726 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4727 dsd->dsd_list_dma);
4728 ha->dif_bundle_dma_allocs--;
4729 kfree(dsd);
4730 ha->dif_bundle_kallocs--;
4731 ha->pool.unusable.count--;
4732 }
4733 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4734 list_del(&dsd->list);
4735 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4736 dsd->dsd_list_dma);
4737 ha->dif_bundle_dma_allocs--;
4738 kfree(dsd);
4739 ha->dif_bundle_kallocs--;
4740 }
4741 }
4742
YueHaibing0b3b6fe2019-07-11 22:13:17 +08004743 dma_pool_destroy(ha->dif_bundl_pool);
Bart Van Asschedc035d42019-04-17 14:44:23 -07004744 ha->dif_bundl_pool = NULL;
Giridhar Malavali50b81272018-12-21 09:33:45 -08004745
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004746 qlt_mem_free(ha);
4747
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004748 if (ha->init_cb)
4749 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004750 ha->init_cb, ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 ha->init_cb = NULL;
4752 ha->init_cb_dma = 0;
Bart Van Assche5365bf92019-04-17 14:44:22 -07004753
4754 vfree(ha->optrom_buffer);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004755 ha->optrom_buffer = NULL;
Bart Van Assche5365bf92019-04-17 14:44:22 -07004756 kfree(ha->nvram);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004757 ha->nvram = NULL;
Bart Van Assche5365bf92019-04-17 14:44:22 -07004758 kfree(ha->npiv_info);
4759 ha->npiv_info = NULL;
4760 kfree(ha->swl);
4761 ha->swl = NULL;
4762 kfree(ha->loop_id_map);
4763 ha->loop_id_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004764}
4765
4766struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4767 struct qla_hw_data *ha)
4768{
4769 struct Scsi_Host *host;
4770 struct scsi_qla_host *vha = NULL;
4771
4772 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004773 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004774 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4775 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004776 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004777 }
4778
4779 /* Clear our data area */
4780 vha = shost_priv(host);
4781 memset(vha, 0, sizeof(scsi_qla_host_t));
4782
4783 vha->host = host;
4784 vha->host_no = host->host_no;
4785 vha->hw = ha;
4786
Quinn Tran0645cb82018-09-11 10:18:18 -07004787 vha->qlini_mode = ql2x_ini_mode;
4788 vha->ql2xexchoffld = ql2xexchoffld;
4789 vha->ql2xiniexchg = ql2xiniexchg;
4790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004791 INIT_LIST_HEAD(&vha->vp_fcports);
4792 INIT_LIST_HEAD(&vha->work_list);
4793 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004794 INIT_LIST_HEAD(&vha->qla_cmd_list);
4795 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004796 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004797 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004798 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004799 INIT_LIST_HEAD(&vha->gnl.fcports);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004800 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004801 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004802
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004803 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004804 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004805 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004806 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004807
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004808 vha->gnl.size = sizeof(struct get_name_list_extended) *
4809 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004810 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4811 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4812 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004813 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004814 "Alloc failed for name list.\n");
4815 scsi_remove_host(vha->host);
4816 return NULL;
4817 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004818
Quinn Trana4239942017-12-28 12:33:26 -08004819 /* todo: what about ext login? */
4820 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4821 vha->scan.l = vmalloc(vha->scan.size);
4822 if (!vha->scan.l) {
4823 ql_log(ql_log_fatal, vha, 0xd04a,
4824 "Alloc failed for scan database.\n");
4825 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4826 vha->gnl.l, vha->gnl.ldma);
4827 scsi_remove_host(vha->host);
4828 return NULL;
4829 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004830 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004831
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004832 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004833 ql_dbg(ql_dbg_init, vha, 0x0041,
4834 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4835 vha->host, vha->hw, vha,
4836 dev_name(&(ha->pdev->dev)));
4837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004838 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839}
4840
Quinn Tran726b8542017-01-19 22:28:00 -08004841struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004842qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004843{
4844 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004845 uint8_t bail;
4846
4847 QLA_VHA_MARK_BUSY(vha, bail);
4848 if (bail)
4849 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004850
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004851 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004852 if (!e) {
4853 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004854 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004855 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004856
4857 INIT_LIST_HEAD(&e->list);
4858 e->type = type;
4859 e->flags = QLA_EVT_FLAG_FREE;
4860 return e;
4861}
4862
Quinn Tran726b8542017-01-19 22:28:00 -08004863int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004864qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004865{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004866 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004867 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004868
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004869 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004870 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004871
4872 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4873 q = true;
4874
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004875 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004876
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004877 if (q)
4878 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004879
Andrew Vasquez0971de72008-04-03 13:13:18 -07004880 return QLA_SUCCESS;
4881}
4882
4883int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004884qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004885 u32 data)
4886{
4887 struct qla_work_evt *e;
4888
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004889 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004890 if (!e)
4891 return QLA_FUNCTION_FAILED;
4892
4893 e->u.aen.code = code;
4894 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004895 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004896}
4897
Andrew Vasquez8a659572009-02-08 20:50:12 -08004898int
4899qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4900{
4901 struct qla_work_evt *e;
4902
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004903 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004904 if (!e)
4905 return QLA_FUNCTION_FAILED;
4906
4907 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004908 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004909}
4910
Andrew Vasquezac280b62009-08-20 11:06:05 -07004911#define qla2x00_post_async_work(name, type) \
4912int qla2x00_post_async_##name##_work( \
4913 struct scsi_qla_host *vha, \
4914 fc_port_t *fcport, uint16_t *data) \
4915{ \
4916 struct qla_work_evt *e; \
4917 \
4918 e = qla2x00_alloc_work(vha, type); \
4919 if (!e) \
4920 return QLA_FUNCTION_FAILED; \
4921 \
4922 e->u.logio.fcport = fcport; \
4923 if (data) { \
4924 e->u.logio.data[0] = data[0]; \
4925 e->u.logio.data[1] = data[1]; \
4926 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08004927 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07004928 return qla2x00_post_work(vha, e); \
4929}
4930
4931qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004932qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4933qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004934qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
Quinn Tran11aea162017-12-28 12:33:20 -08004935qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4936qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004937
Andrew Vasquez3420d362009-10-13 15:16:45 -07004938int
4939qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4940{
4941 struct qla_work_evt *e;
4942
4943 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4944 if (!e)
4945 return QLA_FUNCTION_FAILED;
4946
4947 e->u.uevent.code = code;
4948 return qla2x00_post_work(vha, e);
4949}
4950
4951static void
4952qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
4953{
4954 char event_string[40];
4955 char *envp[] = { event_string, NULL };
4956
4957 switch (code) {
4958 case QLA_UEVENT_CODE_FW_DUMP:
4959 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
4960 vha->host_no);
4961 break;
4962 default:
4963 /* do nothing */
4964 break;
4965 }
4966 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
4967}
4968
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004969int
4970qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
4971 uint32_t *data, int cnt)
4972{
4973 struct qla_work_evt *e;
4974
4975 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
4976 if (!e)
4977 return QLA_FUNCTION_FAILED;
4978
4979 e->u.aenfx.evtcode = evtcode;
4980 e->u.aenfx.count = cnt;
4981 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
4982 return qla2x00_post_work(vha, e);
4983}
4984
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004985void qla24xx_sched_upd_fcport(fc_port_t *fcport)
Quinn Tran726b8542017-01-19 22:28:00 -08004986{
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004987 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08004988
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004989 if (IS_SW_RESV_ADDR(fcport->d_id))
4990 return;
Quinn Tran726b8542017-01-19 22:28:00 -08004991
Quinn Trancd4ed6b2018-08-31 11:24:31 -07004992 spin_lock_irqsave(&fcport->vha->work_lock, flags);
4993 if (fcport->disc_state == DSC_UPD_FCPORT) {
4994 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
4995 return;
4996 }
4997 fcport->jiffies_at_registration = jiffies;
4998 fcport->sec_since_registration = 0;
4999 fcport->next_disc_state = DSC_DELETED;
5000 fcport->disc_state = DSC_UPD_FCPORT;
5001 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5002
5003 queue_work(system_unbound_wq, &fcport->reg_work);
Quinn Tran726b8542017-01-19 22:28:00 -08005004}
5005
5006static
5007void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5008{
5009 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07005010 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08005011 struct qlt_plogi_ack_t *pla =
5012 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07005013 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005014
Quinn Tran9cd883f2017-12-28 12:33:24 -08005015 ql_dbg(ql_dbg_disc, vha, 0xffff,
5016 "%s %d %8phC enter\n",
5017 __func__, __LINE__, e->u.new_sess.port_name);
5018
Quinn Tran726b8542017-01-19 22:28:00 -08005019 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5020 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5021 if (fcport) {
5022 fcport->d_id = e->u.new_sess.id;
5023 if (pla) {
5024 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005025 memcpy(fcport->node_name,
5026 pla->iocb.u.isp24.u.plogi.node_name,
5027 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08005028 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5029 /* we took an extra ref_count to prevent PLOGI ACK when
5030 * fcport/sess has not been created.
5031 */
5032 pla->ref_count--;
5033 }
5034 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07005035 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08005036 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5037 if (fcport) {
5038 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08005039 fcport->flags |= FCF_FABRIC_DEVICE;
5040 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005041 if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08005042 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08005043
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005044 if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08005045 fcport->fc4_type = FC4_TYPE_OTHER;
5046 fcport->fc4f_nvme = FC4_TYPE_NVME;
5047 }
Quinn Tran33b28352018-03-20 23:09:40 -07005048
Quinn Tran726b8542017-01-19 22:28:00 -08005049 memcpy(fcport->port_name, e->u.new_sess.port_name,
5050 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07005051 } else {
5052 ql_dbg(ql_dbg_disc, vha, 0xffff,
5053 "%s %8phC mem alloc fail.\n",
5054 __func__, e->u.new_sess.port_name);
5055
5056 if (pla)
5057 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5058 return;
5059 }
5060
5061 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08005062 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07005063 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5064 e->u.new_sess.port_name, 1);
5065 if (tfcp) {
5066 /* should rarily happen */
5067 ql_dbg(ql_dbg_disc, vha, 0xffff,
5068 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5069 __func__, tfcp->port_name, tfcp->disc_state,
5070 tfcp->fw_login_state);
5071
5072 free_fcport = 1;
5073 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08005074 list_add_tail(&fcport->list, &vha->vp_fcports);
5075
Quinn Tran19759032017-12-04 14:45:15 -08005076 }
5077 if (pla) {
5078 qlt_plogi_ack_link(vha, pla, fcport,
5079 QLT_PLOGI_LINK_SAME_WWN);
5080 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08005081 }
5082 }
5083 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5084
5085 if (fcport) {
Quinn Trana4239942017-12-28 12:33:26 -08005086 fcport->id_changed = 1;
5087 fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran8b5292bc2019-07-26 09:07:32 -07005088 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
Quinn Trana4239942017-12-28 12:33:26 -08005089 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5090
Quinn Tran5ef696a2017-12-04 14:45:05 -08005091 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005092 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5093 u16 wd3_lo;
5094
5095 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5096 fcport->local = 0;
5097 fcport->loop_id =
5098 le16_to_cpu(
5099 pla->iocb.u.isp24.nport_handle);
5100 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5101 wd3_lo =
5102 le16_to_cpu(
5103 pla->iocb.u.isp24.u.prli.wd3_lo);
5104
5105 if (wd3_lo & BIT_7)
5106 fcport->conf_compl_supported = 1;
5107
5108 if ((wd3_lo & BIT_4) == 0)
5109 fcport->port_type = FCT_INITIATOR;
5110 else
5111 fcport->port_type = FCT_TARGET;
5112 }
Quinn Tran726b8542017-01-19 22:28:00 -08005113 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08005114 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005115 fc_port_t *dfcp = NULL;
5116
Quinn Tran5ef696a2017-12-04 14:45:05 -08005117 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5118 tfcp = qla2x00_find_fcport_by_nportid(vha,
5119 &e->u.new_sess.id, 1);
5120 if (tfcp && (tfcp != fcport)) {
5121 /*
5122 * We have a conflict fcport with same NportID.
5123 */
5124 ql_dbg(ql_dbg_disc, vha, 0xffff,
5125 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5126 __func__, tfcp->port_name, tfcp->disc_state,
5127 tfcp->fw_login_state);
5128
5129 switch (tfcp->disc_state) {
5130 case DSC_DELETED:
5131 break;
5132 case DSC_DELETE_PEND:
5133 fcport->login_pause = 1;
5134 tfcp->conflict = fcport;
5135 break;
5136 default:
5137 fcport->login_pause = 1;
5138 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005139 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08005140 break;
5141 }
5142 }
5143 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005144 if (dfcp)
5145 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08005146
Quinn Trana4239942017-12-28 12:33:26 -08005147
Quinn Tran8777e432018-08-02 13:16:57 -07005148 if (N2N_TOPO(vha->hw))
5149 fcport->flags &= ~FCF_FABRIC_DEVICE;
5150
5151 if (N2N_TOPO(vha->hw)) {
5152 if (vha->flags.nvme_enabled) {
5153 fcport->fc4f_nvme = 1;
5154 fcport->n2n_flag = 1;
5155 }
5156 fcport->fw_login_state = 0;
5157 /*
5158 * wait link init done before sending login
5159 */
5160 } else {
5161 qla24xx_fcport_handle_login(vha, fcport);
5162 }
Quinn Tran5ef696a2017-12-04 14:45:05 -08005163 }
Quinn Tran726b8542017-01-19 22:28:00 -08005164 }
Quinn Tranb5d15312017-08-30 10:16:49 -07005165
5166 if (free_fcport) {
5167 qla2x00_free_fcport(fcport);
5168 if (pla)
5169 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5170 }
Quinn Tran726b8542017-01-19 22:28:00 -08005171}
5172
Quinn Trane374f9f2017-12-28 12:33:31 -08005173static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5174{
5175 struct srb *sp = e->u.iosb.sp;
5176 int rval;
5177
5178 rval = qla2x00_start_sp(sp);
5179 if (rval != QLA_SUCCESS) {
5180 ql_dbg(ql_dbg_disc, vha, 0x2043,
5181 "%s: %s: Re-issue IOCB failed (%d).\n",
5182 __func__, sp->name, rval);
5183 qla24xx_sp_unmap(vha, sp);
5184 }
5185}
5186
Andrew Vasquezac280b62009-08-20 11:06:05 -07005187void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005188qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07005189{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005190 struct qla_work_evt *e, *tmp;
5191 unsigned long flags;
5192 LIST_HEAD(work);
Quinn Tran80676d02019-01-24 23:23:42 -08005193 int rc;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005194
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005195 spin_lock_irqsave(&vha->work_lock, flags);
5196 list_splice_init(&vha->work_list, &work);
5197 spin_unlock_irqrestore(&vha->work_lock, flags);
5198
5199 list_for_each_entry_safe(e, tmp, &work, list) {
Quinn Tran80676d02019-01-24 23:23:42 -08005200 rc = QLA_SUCCESS;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005201 switch (e->type) {
5202 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005203 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07005204 e->u.aen.code, e->u.aen.data);
5205 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08005206 case QLA_EVT_IDC_ACK:
5207 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5208 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005209 case QLA_EVT_ASYNC_LOGIN:
5210 qla2x00_async_login(vha, e->u.logio.fcport,
5211 e->u.logio.data);
5212 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005213 case QLA_EVT_ASYNC_LOGOUT:
Quinn Tran80676d02019-01-24 23:23:42 -08005214 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07005215 break;
5216 case QLA_EVT_ASYNC_LOGOUT_DONE:
5217 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5218 e->u.logio.data);
5219 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005220 case QLA_EVT_ASYNC_ADISC:
5221 qla2x00_async_adisc(vha, e->u.logio.fcport,
5222 e->u.logio.data);
5223 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005224 case QLA_EVT_UEVENT:
5225 qla2x00_uevent_emit(vha, e->u.uevent.code);
5226 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005227 case QLA_EVT_AENFX:
5228 qlafx00_process_aen(vha, e);
5229 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005230 case QLA_EVT_GPNID:
5231 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5232 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005233 case QLA_EVT_UNMAP:
5234 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005235 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005236 case QLA_EVT_RELOGIN:
5237 qla2x00_relogin(vha);
5238 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005239 case QLA_EVT_NEW_SESS:
5240 qla24xx_create_new_sess(vha, e);
5241 break;
5242 case QLA_EVT_GPDB:
5243 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5244 e->u.fcport.opt);
5245 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005246 case QLA_EVT_PRLI:
5247 qla24xx_async_prli(vha, e->u.fcport.fcport);
5248 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005249 case QLA_EVT_GPSC:
5250 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5251 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005252 case QLA_EVT_GNL:
5253 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5254 break;
5255 case QLA_EVT_NACK:
5256 qla24xx_do_nack_work(vha, e);
5257 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005258 case QLA_EVT_ASYNC_PRLO:
Quinn Tran80676d02019-01-24 23:23:42 -08005259 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
Quinn Tran11aea162017-12-28 12:33:20 -08005260 break;
5261 case QLA_EVT_ASYNC_PRLO_DONE:
5262 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5263 e->u.logio.data);
5264 break;
Quinn Trana4239942017-12-28 12:33:26 -08005265 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005266 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5267 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005268 break;
5269 case QLA_EVT_GPNFT_DONE:
5270 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5271 break;
5272 case QLA_EVT_GNNFT_DONE:
5273 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5274 break;
5275 case QLA_EVT_GNNID:
5276 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5277 break;
5278 case QLA_EVT_GFPNID:
5279 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5280 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005281 case QLA_EVT_SP_RETRY:
5282 qla_sp_retry(vha, e);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005283 break;
5284 case QLA_EVT_IIDMA:
5285 qla_do_iidma_work(vha, e->u.fcport.fcport);
5286 break;
Quinn Tran8777e432018-08-02 13:16:57 -07005287 case QLA_EVT_ELS_PLOGI:
5288 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5289 e->u.fcport.fcport, false);
5290 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005291 }
Quinn Tran80676d02019-01-24 23:23:42 -08005292
5293 if (rc == EAGAIN) {
5294 /* put 'work' at head of 'vha->work_list' */
5295 spin_lock_irqsave(&vha->work_lock, flags);
5296 list_splice(&work, &vha->work_list);
5297 spin_unlock_irqrestore(&vha->work_lock, flags);
5298 break;
5299 }
5300 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005301 if (e->flags & QLA_EVT_FLAG_FREE)
5302 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005303
5304 /* For each work completed decrement vha ref count */
5305 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005306 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005307}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005308
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005309int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5310{
5311 struct qla_work_evt *e;
5312
5313 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5314
5315 if (!e) {
5316 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5317 return QLA_FUNCTION_FAILED;
5318 }
5319
5320 return qla2x00_post_work(vha, e);
5321}
5322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005323/* Relogins all the fcports of a vport
5324 * Context: dpc thread
5325 */
5326void qla2x00_relogin(struct scsi_qla_host *vha)
5327{
5328 fc_port_t *fcport;
Quinn Tran23dd98a2018-08-02 13:16:45 -07005329 int status, relogin_needed = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005330 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005331
5332 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005333 /*
5334 * If the port is not ONLINE then try to login
5335 * to it if we haven't run out of retries.
5336 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005337 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran23dd98a2018-08-02 13:16:45 -07005338 fcport->login_retry) {
5339 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5340 fcport->disc_state == DSC_LOGIN_COMPLETE)
5341 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005342
Quinn Tran23dd98a2018-08-02 13:16:45 -07005343 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5344 fcport->disc_state == DSC_DELETE_PEND) {
5345 relogin_needed = 1;
5346 } else {
5347 if (vha->hw->current_topology != ISP_CFG_NL) {
5348 memset(&ea, 0, sizeof(ea));
5349 ea.event = FCME_RELOGIN;
5350 ea.fcport = fcport;
5351 qla2x00_fcport_event_handler(vha, &ea);
5352 } else if (vha->hw->current_topology ==
5353 ISP_CFG_NL) {
5354 fcport->login_retry--;
5355 status =
5356 qla2x00_local_device_login(vha,
5357 fcport);
5358 if (status == QLA_SUCCESS) {
5359 fcport->old_loop_id =
5360 fcport->loop_id;
5361 ql_dbg(ql_dbg_disc, vha, 0x2003,
5362 "Port login OK: logged in ID 0x%x.\n",
5363 fcport->loop_id);
5364 qla2x00_update_fcport
5365 (vha, fcport);
5366 } else if (status == 1) {
5367 set_bit(RELOGIN_NEEDED,
5368 &vha->dpc_flags);
5369 /* retry the login again */
5370 ql_dbg(ql_dbg_disc, vha, 0x2007,
5371 "Retrying %d login again loop_id 0x%x.\n",
5372 fcport->login_retry,
5373 fcport->loop_id);
5374 } else {
5375 fcport->login_retry = 0;
5376 }
5377
5378 if (fcport->login_retry == 0 &&
5379 status != QLA_SUCCESS)
5380 qla2x00_clear_loop_id(fcport);
5381 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005382 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005383 }
5384 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5385 break;
5386 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005387
Quinn Tran23dd98a2018-08-02 13:16:45 -07005388 if (relogin_needed)
5389 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5390
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005391 ql_dbg(ql_dbg_disc, vha, 0x400e,
5392 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005393}
5394
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005395/* Schedule work on any of the dpc-workqueues */
5396void
5397qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5398{
5399 struct qla_hw_data *ha = base_vha->hw;
5400
5401 switch (work_code) {
5402 case MBA_IDC_AEN: /* 0x8200 */
5403 if (ha->dpc_lp_wq)
5404 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5405 break;
5406
5407 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5408 if (!ha->flags.nic_core_reset_hdlr_active) {
5409 if (ha->dpc_hp_wq)
5410 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5411 } else
5412 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5413 "NIC Core reset is already active. Skip "
5414 "scheduling it again.\n");
5415 break;
5416 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5417 if (ha->dpc_hp_wq)
5418 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5419 break;
5420 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5421 if (ha->dpc_hp_wq)
5422 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5423 break;
5424 default:
5425 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005426 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005427 }
5428
5429 return;
5430}
5431
5432/* Work: Perform NIC Core Unrecoverable state handling */
5433void
5434qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5435{
5436 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005437 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005438 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5439 uint32_t dev_state = 0;
5440
5441 qla83xx_idc_lock(base_vha, 0);
5442 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5443 qla83xx_reset_ownership(base_vha);
5444 if (ha->flags.nic_core_reset_owner) {
5445 ha->flags.nic_core_reset_owner = 0;
5446 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5447 QLA8XXX_DEV_FAILED);
5448 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5449 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5450 }
5451 qla83xx_idc_unlock(base_vha, 0);
5452}
5453
5454/* Work: Execute IDC state handler */
5455void
5456qla83xx_idc_state_handler_work(struct work_struct *work)
5457{
5458 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005459 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005460 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5461 uint32_t dev_state = 0;
5462
5463 qla83xx_idc_lock(base_vha, 0);
5464 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5465 if (dev_state == QLA8XXX_DEV_FAILED ||
5466 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5467 qla83xx_idc_state_handler(base_vha);
5468 qla83xx_idc_unlock(base_vha, 0);
5469}
5470
Saurav Kashyapfa492632012-11-21 02:40:29 -05005471static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005472qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5473{
5474 int rval = QLA_SUCCESS;
5475 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5476 uint32_t heart_beat_counter1, heart_beat_counter2;
5477
5478 do {
5479 if (time_after(jiffies, heart_beat_wait)) {
5480 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5481 "Nic Core f/w is not alive.\n");
5482 rval = QLA_FUNCTION_FAILED;
5483 break;
5484 }
5485
5486 qla83xx_idc_lock(base_vha, 0);
5487 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5488 &heart_beat_counter1);
5489 qla83xx_idc_unlock(base_vha, 0);
5490 msleep(100);
5491 qla83xx_idc_lock(base_vha, 0);
5492 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5493 &heart_beat_counter2);
5494 qla83xx_idc_unlock(base_vha, 0);
5495 } while (heart_beat_counter1 == heart_beat_counter2);
5496
5497 return rval;
5498}
5499
5500/* Work: Perform NIC Core Reset handling */
5501void
5502qla83xx_nic_core_reset_work(struct work_struct *work)
5503{
5504 struct qla_hw_data *ha =
5505 container_of(work, struct qla_hw_data, nic_core_reset);
5506 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5507 uint32_t dev_state = 0;
5508
Saurav Kashyap81178772012-08-22 14:21:04 -04005509 if (IS_QLA2031(ha)) {
5510 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5511 ql_log(ql_log_warn, base_vha, 0xb081,
5512 "Failed to dump mctp\n");
5513 return;
5514 }
5515
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005516 if (!ha->flags.nic_core_reset_hdlr_active) {
5517 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5518 qla83xx_idc_lock(base_vha, 0);
5519 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5520 &dev_state);
5521 qla83xx_idc_unlock(base_vha, 0);
5522 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5523 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5524 "Nic Core f/w is alive.\n");
5525 return;
5526 }
5527 }
5528
5529 ha->flags.nic_core_reset_hdlr_active = 1;
5530 if (qla83xx_nic_core_reset(base_vha)) {
5531 /* NIC Core reset failed. */
5532 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5533 "NIC Core reset failed.\n");
5534 }
5535 ha->flags.nic_core_reset_hdlr_active = 0;
5536 }
5537}
5538
5539/* Work: Handle 8200 IDC aens */
5540void
5541qla83xx_service_idc_aen(struct work_struct *work)
5542{
5543 struct qla_hw_data *ha =
5544 container_of(work, struct qla_hw_data, idc_aen);
5545 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5546 uint32_t dev_state, idc_control;
5547
5548 qla83xx_idc_lock(base_vha, 0);
5549 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5550 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5551 qla83xx_idc_unlock(base_vha, 0);
5552 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5553 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5554 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5555 "Application requested NIC Core Reset.\n");
5556 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5557 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5558 QLA_SUCCESS) {
5559 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5560 "Other protocol driver requested NIC Core Reset.\n");
5561 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5562 }
5563 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5564 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5565 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5566 }
5567}
5568
5569static void
5570qla83xx_wait_logic(void)
5571{
5572 int i;
5573
5574 /* Yield CPU */
5575 if (!in_interrupt()) {
5576 /*
5577 * Wait about 200ms before retrying again.
5578 * This controls the number of retries for single
5579 * lock operation.
5580 */
5581 msleep(100);
5582 schedule();
5583 } else {
5584 for (i = 0; i < 20; i++)
5585 cpu_relax(); /* This a nop instr on i386 */
5586 }
5587}
5588
Saurav Kashyapfa492632012-11-21 02:40:29 -05005589static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005590qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5591{
5592 int rval;
5593 uint32_t data;
5594 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5595 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5596 struct qla_hw_data *ha = base_vha->hw;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07005597
Saurav Kashyap6c315552013-02-08 01:57:53 -05005598 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5599 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005600
5601 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5602 if (rval)
5603 return rval;
5604
5605 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5606 return QLA_SUCCESS;
5607 } else {
5608 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5609 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5610 data);
5611 if (rval)
5612 return rval;
5613
5614 msleep(200);
5615
5616 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5617 &data);
5618 if (rval)
5619 return rval;
5620
5621 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5622 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5623 ~(idc_lck_rcvry_stage_mask));
5624 rval = qla83xx_wr_reg(base_vha,
5625 QLA83XX_IDC_LOCK_RECOVERY, data);
5626 if (rval)
5627 return rval;
5628
5629 /* Forcefully perform IDC UnLock */
5630 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5631 &data);
5632 if (rval)
5633 return rval;
5634 /* Clear lock-id by setting 0xff */
5635 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5636 0xff);
5637 if (rval)
5638 return rval;
5639 /* Clear lock-recovery by setting 0x0 */
5640 rval = qla83xx_wr_reg(base_vha,
5641 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5642 if (rval)
5643 return rval;
5644 } else
5645 return QLA_SUCCESS;
5646 }
5647
5648 return rval;
5649}
5650
Saurav Kashyapfa492632012-11-21 02:40:29 -05005651static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005652qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5653{
5654 int rval = QLA_SUCCESS;
5655 uint32_t o_drv_lockid, n_drv_lockid;
5656 unsigned long lock_recovery_timeout;
5657
5658 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5659retry_lockid:
5660 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5661 if (rval)
5662 goto exit;
5663
5664 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5665 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5666 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5667 return QLA_SUCCESS;
5668 else
5669 return QLA_FUNCTION_FAILED;
5670 }
5671
5672 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5673 if (rval)
5674 goto exit;
5675
5676 if (o_drv_lockid == n_drv_lockid) {
5677 qla83xx_wait_logic();
5678 goto retry_lockid;
5679 } else
5680 return QLA_SUCCESS;
5681
5682exit:
5683 return rval;
5684}
5685
5686void
5687qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5688{
5689 uint16_t options = (requester_id << 15) | BIT_6;
5690 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005691 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005692 struct qla_hw_data *ha = base_vha->hw;
5693
5694 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5695retry_lock:
5696 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5697 == QLA_SUCCESS) {
5698 if (data) {
5699 /* Setting lock-id to our function-number */
5700 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5701 ha->portnum);
5702 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005703 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5704 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005705 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005706 "Failed to acquire IDC lock, acquired by %d, "
5707 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005708
5709 /* Retry/Perform IDC-Lock recovery */
5710 if (qla83xx_idc_lock_recovery(base_vha)
5711 == QLA_SUCCESS) {
5712 qla83xx_wait_logic();
5713 goto retry_lock;
5714 } else
5715 ql_log(ql_log_warn, base_vha, 0xb075,
5716 "IDC Lock recovery FAILED.\n");
5717 }
5718
5719 }
5720
5721 return;
5722
5723 /* XXX: IDC-lock implementation using access-control mbx */
5724retry_lock2:
5725 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5726 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5727 "Failed to acquire IDC lock. retrying...\n");
5728 /* Retry/Perform IDC-Lock recovery */
5729 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5730 qla83xx_wait_logic();
5731 goto retry_lock2;
5732 } else
5733 ql_log(ql_log_warn, base_vha, 0xb076,
5734 "IDC Lock recovery FAILED.\n");
5735 }
5736
5737 return;
5738}
5739
5740void
5741qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5742{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005743#if 0
5744 uint16_t options = (requester_id << 15) | BIT_7;
5745#endif
5746 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005747 uint32_t data;
5748 struct qla_hw_data *ha = base_vha->hw;
5749
5750 /* IDC-unlock implementation using driver-unlock/lock-id
5751 * remote registers
5752 */
5753 retry = 0;
5754retry_unlock:
5755 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5756 == QLA_SUCCESS) {
5757 if (data == ha->portnum) {
5758 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5759 /* Clearing lock-id by setting 0xff */
5760 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5761 } else if (retry < 10) {
5762 /* SV: XXX: IDC unlock retrying needed here? */
5763
5764 /* Retry for IDC-unlock */
5765 qla83xx_wait_logic();
5766 retry++;
5767 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005768 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005769 goto retry_unlock;
5770 }
5771 } else if (retry < 10) {
5772 /* Retry for IDC-unlock */
5773 qla83xx_wait_logic();
5774 retry++;
5775 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005776 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005777 goto retry_unlock;
5778 }
5779
5780 return;
5781
Bart Van Assche5897cb22015-06-04 15:57:20 -07005782#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005783 /* XXX: IDC-unlock implementation using access-control mbx */
5784 retry = 0;
5785retry_unlock2:
5786 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5787 if (retry < 10) {
5788 /* Retry for IDC-unlock */
5789 qla83xx_wait_logic();
5790 retry++;
5791 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005792 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005793 goto retry_unlock2;
5794 }
5795 }
5796
5797 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005798#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005799}
5800
5801int
5802__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5803{
5804 int rval = QLA_SUCCESS;
5805 struct qla_hw_data *ha = vha->hw;
5806 uint32_t drv_presence;
5807
5808 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5809 if (rval == QLA_SUCCESS) {
5810 drv_presence |= (1 << ha->portnum);
5811 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5812 drv_presence);
5813 }
5814
5815 return rval;
5816}
5817
5818int
5819qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5820{
5821 int rval = QLA_SUCCESS;
5822
5823 qla83xx_idc_lock(vha, 0);
5824 rval = __qla83xx_set_drv_presence(vha);
5825 qla83xx_idc_unlock(vha, 0);
5826
5827 return rval;
5828}
5829
5830int
5831__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5832{
5833 int rval = QLA_SUCCESS;
5834 struct qla_hw_data *ha = vha->hw;
5835 uint32_t drv_presence;
5836
5837 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5838 if (rval == QLA_SUCCESS) {
5839 drv_presence &= ~(1 << ha->portnum);
5840 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5841 drv_presence);
5842 }
5843
5844 return rval;
5845}
5846
5847int
5848qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5849{
5850 int rval = QLA_SUCCESS;
5851
5852 qla83xx_idc_lock(vha, 0);
5853 rval = __qla83xx_clear_drv_presence(vha);
5854 qla83xx_idc_unlock(vha, 0);
5855
5856 return rval;
5857}
5858
Saurav Kashyapfa492632012-11-21 02:40:29 -05005859static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005860qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5861{
5862 struct qla_hw_data *ha = vha->hw;
5863 uint32_t drv_ack, drv_presence;
5864 unsigned long ack_timeout;
5865
5866 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5867 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5868 while (1) {
5869 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5870 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005871 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005872 break;
5873
5874 if (time_after_eq(jiffies, ack_timeout)) {
5875 ql_log(ql_log_warn, vha, 0xb067,
5876 "RESET ACK TIMEOUT! drv_presence=0x%x "
5877 "drv_ack=0x%x\n", drv_presence, drv_ack);
5878 /*
5879 * The function(s) which did not ack in time are forced
5880 * to withdraw any further participation in the IDC
5881 * reset.
5882 */
5883 if (drv_ack != drv_presence)
5884 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5885 drv_ack);
5886 break;
5887 }
5888
5889 qla83xx_idc_unlock(vha, 0);
5890 msleep(1000);
5891 qla83xx_idc_lock(vha, 0);
5892 }
5893
5894 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5895 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5896}
5897
Saurav Kashyapfa492632012-11-21 02:40:29 -05005898static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005899qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5900{
5901 int rval = QLA_SUCCESS;
5902 uint32_t idc_control;
5903
5904 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5905 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5906
5907 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5908 __qla83xx_get_idc_control(vha, &idc_control);
5909 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5910 __qla83xx_set_idc_control(vha, 0);
5911
5912 qla83xx_idc_unlock(vha, 0);
5913 rval = qla83xx_restart_nic_firmware(vha);
5914 qla83xx_idc_lock(vha, 0);
5915
5916 if (rval != QLA_SUCCESS) {
5917 ql_log(ql_log_fatal, vha, 0xb06a,
5918 "Failed to restart NIC f/w.\n");
5919 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5920 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5921 } else {
5922 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5923 "Success in restarting nic f/w.\n");
5924 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5925 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5926 }
5927
5928 return rval;
5929}
5930
5931/* Assumes idc_lock always held on entry */
5932int
5933qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5934{
5935 struct qla_hw_data *ha = base_vha->hw;
5936 int rval = QLA_SUCCESS;
5937 unsigned long dev_init_timeout;
5938 uint32_t dev_state;
5939
5940 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5941 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5942
5943 while (1) {
5944
5945 if (time_after_eq(jiffies, dev_init_timeout)) {
5946 ql_log(ql_log_warn, base_vha, 0xb06e,
5947 "Initialization TIMEOUT!\n");
5948 /* Init timeout. Disable further NIC Core
5949 * communication.
5950 */
5951 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5952 QLA8XXX_DEV_FAILED);
5953 ql_log(ql_log_info, base_vha, 0xb06f,
5954 "HW State: FAILED.\n");
5955 }
5956
5957 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5958 switch (dev_state) {
5959 case QLA8XXX_DEV_READY:
5960 if (ha->flags.nic_core_reset_owner)
5961 qla83xx_idc_audit(base_vha,
5962 IDC_AUDIT_COMPLETION);
5963 ha->flags.nic_core_reset_owner = 0;
5964 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
5965 "Reset_owner reset by 0x%x.\n",
5966 ha->portnum);
5967 goto exit;
5968 case QLA8XXX_DEV_COLD:
5969 if (ha->flags.nic_core_reset_owner)
5970 rval = qla83xx_device_bootstrap(base_vha);
5971 else {
5972 /* Wait for AEN to change device-state */
5973 qla83xx_idc_unlock(base_vha, 0);
5974 msleep(1000);
5975 qla83xx_idc_lock(base_vha, 0);
5976 }
5977 break;
5978 case QLA8XXX_DEV_INITIALIZING:
5979 /* Wait for AEN to change device-state */
5980 qla83xx_idc_unlock(base_vha, 0);
5981 msleep(1000);
5982 qla83xx_idc_lock(base_vha, 0);
5983 break;
5984 case QLA8XXX_DEV_NEED_RESET:
5985 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
5986 qla83xx_need_reset_handler(base_vha);
5987 else {
5988 /* Wait for AEN to change device-state */
5989 qla83xx_idc_unlock(base_vha, 0);
5990 msleep(1000);
5991 qla83xx_idc_lock(base_vha, 0);
5992 }
5993 /* reset timeout value after need reset handler */
5994 dev_init_timeout = jiffies +
5995 (ha->fcoe_dev_init_timeout * HZ);
5996 break;
5997 case QLA8XXX_DEV_NEED_QUIESCENT:
5998 /* XXX: DEBUG for now */
5999 qla83xx_idc_unlock(base_vha, 0);
6000 msleep(1000);
6001 qla83xx_idc_lock(base_vha, 0);
6002 break;
6003 case QLA8XXX_DEV_QUIESCENT:
6004 /* XXX: DEBUG for now */
6005 if (ha->flags.quiesce_owner)
6006 goto exit;
6007
6008 qla83xx_idc_unlock(base_vha, 0);
6009 msleep(1000);
6010 qla83xx_idc_lock(base_vha, 0);
6011 dev_init_timeout = jiffies +
6012 (ha->fcoe_dev_init_timeout * HZ);
6013 break;
6014 case QLA8XXX_DEV_FAILED:
6015 if (ha->flags.nic_core_reset_owner)
6016 qla83xx_idc_audit(base_vha,
6017 IDC_AUDIT_COMPLETION);
6018 ha->flags.nic_core_reset_owner = 0;
6019 __qla83xx_clear_drv_presence(base_vha);
6020 qla83xx_idc_unlock(base_vha, 0);
6021 qla8xxx_dev_failed_handler(base_vha);
6022 rval = QLA_FUNCTION_FAILED;
6023 qla83xx_idc_lock(base_vha, 0);
6024 goto exit;
6025 case QLA8XXX_BAD_VALUE:
6026 qla83xx_idc_unlock(base_vha, 0);
6027 msleep(1000);
6028 qla83xx_idc_lock(base_vha, 0);
6029 break;
6030 default:
6031 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09006032 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006033 qla83xx_idc_unlock(base_vha, 0);
6034 qla8xxx_dev_failed_handler(base_vha);
6035 rval = QLA_FUNCTION_FAILED;
6036 qla83xx_idc_lock(base_vha, 0);
6037 goto exit;
6038 }
6039 }
6040
6041exit:
6042 return rval;
6043}
6044
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006045void
6046qla2x00_disable_board_on_pci_error(struct work_struct *work)
6047{
6048 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6049 board_disable);
6050 struct pci_dev *pdev = ha->pdev;
6051 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6052
Quinn Tran726b8542017-01-19 22:28:00 -08006053 /*
6054 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04006055 * where it was set first.
6056 */
6057 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6058 return;
6059
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006060 ql_log(ql_log_warn, base_vha, 0x015b,
6061 "Disabling adapter.\n");
6062
Sawan Chandakefdb5762017-08-23 15:05:00 -07006063 if (!atomic_read(&pdev->enable_cnt)) {
6064 ql_log(ql_log_info, base_vha, 0xfffc,
6065 "PCI device disabled, no action req for PCI error=%lx\n",
6066 base_vha->pci_flags);
6067 return;
6068 }
6069
Quinn Tran726b8542017-01-19 22:28:00 -08006070 qla2x00_wait_for_sess_deletion(base_vha);
6071
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006072 set_bit(UNLOADING, &base_vha->dpc_flags);
6073
6074 qla2x00_delete_all_vps(ha, base_vha);
6075
6076 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6077
6078 qla2x00_dfs_remove(base_vha);
6079
6080 qla84xx_put_chip(base_vha);
6081
6082 if (base_vha->timer_active)
6083 qla2x00_stop_timer(base_vha);
6084
6085 base_vha->flags.online = 0;
6086
6087 qla2x00_destroy_deferred_work(ha);
6088
6089 /*
6090 * Do not try to stop beacon blink as it will issue a mailbox
6091 * command.
6092 */
6093 qla2x00_free_sysfs_attr(base_vha, false);
6094
6095 fc_remove_host(base_vha->host);
6096
6097 scsi_remove_host(base_vha->host);
6098
6099 base_vha->flags.init_done = 0;
6100 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006101 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08006102 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006103 qla2x00_mem_free(ha);
6104 qla82xx_md_free(base_vha);
6105 qla2x00_free_queues(ha);
6106
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006107 qla2x00_unmap_iobases(ha);
6108
6109 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006110 pci_disable_pcie_error_reporting(pdev);
6111 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006112
Joe Lawrencebeb9e312014-08-26 17:12:14 -04006113 /*
6114 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6115 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006116}
6117
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118/**************************************************************************
6119* qla2x00_do_dpc
6120* This kernel thread is a task that is schedule by the interrupt handler
6121* to perform the background processing for interrupts.
6122*
6123* Notes:
6124* This task always run in the context of a kernel thread. It
6125* is kick-off by the driver's detect code and starts up
6126* up one per adapter. It immediately goes to sleep and waits for
6127* some fibre event. When either the interrupt handler or
6128* the timer routine detects a event it will one of the task
6129* bits then wake us up.
6130**************************************************************************/
6131static int
6132qla2x00_do_dpc(void *data)
6133{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006134 scsi_qla_host_t *base_vha;
6135 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08006136 uint32_t online;
6137 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08006138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006139 ha = (struct qla_hw_data *)data;
6140 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141
Dongsheng Yang8698a742014-03-11 18:09:12 +08006142 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143
James Bottomley563585e2011-01-27 16:12:37 -05006144 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01006145 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006146 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6147 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148
Christoph Hellwig39a11242006-02-14 18:46:22 +01006149 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006151 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6152 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153
Andrew Vasquez85880802009-12-15 21:29:46 -08006154 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006155 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6156 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006157 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08006158 }
6159
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 ha->dpc_active = 1;
6161
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04006162 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6163 "DPC handler waking up, dpc_flags=0x%lx.\n",
6164 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04006166 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6167 break;
6168
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006169 if (IS_P3P_TYPE(ha)) {
6170 if (IS_QLA8044(ha)) {
6171 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6172 &base_vha->dpc_flags)) {
6173 qla8044_idc_lock(ha);
6174 qla8044_wr_direct(base_vha,
6175 QLA8044_CRB_DEV_STATE_INDEX,
6176 QLA8XXX_DEV_FAILED);
6177 qla8044_idc_unlock(ha);
6178 ql_log(ql_log_info, base_vha, 0x4004,
6179 "HW State: FAILED.\n");
6180 qla8044_device_state_handler(base_vha);
6181 continue;
6182 }
6183
6184 } else {
6185 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6186 &base_vha->dpc_flags)) {
6187 qla82xx_idc_lock(ha);
6188 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6189 QLA8XXX_DEV_FAILED);
6190 qla82xx_idc_unlock(ha);
6191 ql_log(ql_log_info, base_vha, 0x0151,
6192 "HW State: FAILED.\n");
6193 qla82xx_device_state_handler(base_vha);
6194 continue;
6195 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006196 }
6197
6198 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6199 &base_vha->dpc_flags)) {
6200
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006201 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6202 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006203 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6204 &base_vha->dpc_flags))) {
6205 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6206 /* FCoE-ctx reset failed.
6207 * Escalate to chip-reset
6208 */
6209 set_bit(ISP_ABORT_NEEDED,
6210 &base_vha->dpc_flags);
6211 }
6212 clear_bit(ABORT_ISP_ACTIVE,
6213 &base_vha->dpc_flags);
6214 }
6215
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006216 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6217 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006218 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006219 } else if (IS_QLAFX00(ha)) {
6220 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6221 &base_vha->dpc_flags)) {
6222 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6223 "Firmware Reset Recovery\n");
6224 if (qlafx00_reset_initialize(base_vha)) {
6225 /* Failed. Abort isp later. */
6226 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006227 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006228 set_bit(ISP_UNRECOVERABLE,
6229 &base_vha->dpc_flags);
6230 ql_dbg(ql_dbg_dpc, base_vha,
6231 0x4021,
6232 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006233 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006234 }
6235 }
6236
6237 if (test_and_clear_bit(FX00_TARGET_SCAN,
6238 &base_vha->dpc_flags)) {
6239 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6240 "ISPFx00 Target Scan scheduled\n");
6241 if (qlafx00_rescan_isp(base_vha)) {
6242 if (!test_bit(UNLOADING,
6243 &base_vha->dpc_flags))
6244 set_bit(ISP_UNRECOVERABLE,
6245 &base_vha->dpc_flags);
6246 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6247 "ISPFx00 Target Scan Failed\n");
6248 }
6249 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6250 "ISPFx00 Target Scan End\n");
6251 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006252 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6253 &base_vha->dpc_flags)) {
6254 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6255 "ISPFx00 Host Info resend scheduled\n");
6256 qlafx00_fx_disc(base_vha,
6257 &base_vha->hw->mr.fcport,
6258 FXDISC_REG_HOST_INFO);
6259 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006260 }
6261
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006262 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6263 &base_vha->dpc_flags) &&
6264 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6265 qla24xx_detect_sfp(base_vha);
6266
6267 if (ha->flags.detected_lr_sfp !=
6268 ha->flags.using_lr_setting)
6269 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6270 }
6271
Quinn Tranb08abbd2018-07-18 14:29:54 -07006272 if (test_and_clear_bit
6273 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6274 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran93eca612018-08-31 11:24:37 -07006275 bool do_reset = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276
Quinn Tran0645cb82018-09-11 10:18:18 -07006277 switch (base_vha->qlini_mode) {
Quinn Tran93eca612018-08-31 11:24:37 -07006278 case QLA2XXX_INI_MODE_ENABLED:
6279 break;
6280 case QLA2XXX_INI_MODE_DISABLED:
Quinn Tran0645cb82018-09-11 10:18:18 -07006281 if (!qla_tgt_mode_enabled(base_vha) &&
6282 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006283 do_reset = false;
6284 break;
6285 case QLA2XXX_INI_MODE_DUAL:
Quinn Tran0645cb82018-09-11 10:18:18 -07006286 if (!qla_dual_mode_enabled(base_vha) &&
6287 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006288 do_reset = false;
6289 break;
6290 default:
6291 break;
6292 }
6293
6294 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006295 &base_vha->dpc_flags))) {
Quinn Tran93eca612018-08-31 11:24:37 -07006296 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6297 "ISP abort scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006298 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 /* failed. retry later */
6300 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006301 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006303 clear_bit(ABORT_ISP_ACTIVE,
6304 &base_vha->dpc_flags);
Quinn Tran93eca612018-08-31 11:24:37 -07006305 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6306 "ISP abort end.\n");
Seokmann Ju99363ef2008-01-31 12:33:51 -08006307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308 }
6309
David Jefferya394aac2012-11-21 02:39:54 -05006310 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6311 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006312 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006313 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006314
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006315 if (IS_QLAFX00(ha))
6316 goto loop_resync_check;
6317
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006318 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006319 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6320 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006321 if (IS_P3P_TYPE(ha)) {
6322 if (IS_QLA82XX(ha))
6323 qla82xx_device_state_handler(base_vha);
6324 if (IS_QLA8044(ha))
6325 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006326 clear_bit(ISP_QUIESCE_NEEDED,
6327 &base_vha->dpc_flags);
6328 if (!ha->flags.quiesce_owner) {
6329 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006330 if (IS_QLA82XX(ha)) {
6331 qla82xx_idc_lock(ha);
6332 qla82xx_clear_qsnt_ready(
6333 base_vha);
6334 qla82xx_idc_unlock(ha);
6335 } else if (IS_QLA8044(ha)) {
6336 qla8044_idc_lock(ha);
6337 qla8044_clear_qsnt_ready(
6338 base_vha);
6339 qla8044_idc_unlock(ha);
6340 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006341 }
6342 } else {
6343 clear_bit(ISP_QUIESCE_NEEDED,
6344 &base_vha->dpc_flags);
6345 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006346 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006347 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6348 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006349 }
6350
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006351 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006352 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006353 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006355 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6356 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006357 qla2x00_rst_aen(base_vha);
6358 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006359 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6360 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361 }
6362
6363 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006364 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006365 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6366 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367
Quinn Tran4005a992017-12-04 14:45:06 -08006368 if (!base_vha->relogin_jif ||
6369 time_after_eq(jiffies, base_vha->relogin_jif)) {
6370 base_vha->relogin_jif = jiffies + HZ;
6371 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6372
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006373 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006374 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006375 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006378loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006379 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006380 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006382 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6383 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384
6385 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006386 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387
Bart Van Assche52c82822015-07-09 07:23:26 -07006388 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006390 clear_bit(LOOP_RESYNC_ACTIVE,
6391 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392 }
6393
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006394 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6395 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396 }
6397
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006398 if (IS_QLAFX00(ha))
6399 goto intr_on_check;
6400
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006401 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6402 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6403 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6404 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006405 }
6406
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006407intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006409 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006411 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006412 &base_vha->dpc_flags)) {
6413 if (ha->beacon_blink_led == 1)
6414 ha->isp_ops->beacon_blink(base_vha);
6415 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006416
Michael Hernandezd7459522016-12-12 14:40:07 -08006417 /* qpair online check */
6418 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6419 &base_vha->dpc_flags)) {
6420 if (ha->flags.eeh_busy ||
6421 ha->flags.pci_channel_io_perm_failure)
6422 online = 0;
6423 else
6424 online = 1;
6425
6426 mutex_lock(&ha->mq_lock);
6427 list_for_each_entry(qpair, &base_vha->qp_list,
6428 qp_list_elem)
6429 qpair->online = online;
6430 mutex_unlock(&ha->mq_lock);
6431 }
6432
Quinn Tran8b4673b2018-09-04 14:19:14 -07006433 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6434 &base_vha->dpc_flags)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006435 ql_log(ql_log_info, base_vha, 0xffffff,
6436 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6437 ha->nvme_last_rptd_aen);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006438 if (qla27xx_set_zio_threshold(base_vha,
6439 ha->nvme_last_rptd_aen)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006440 ql_log(ql_log_info, base_vha, 0xffffff,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006441 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6442 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006443 }
6444 }
6445
Quinn Tran8b4673b2018-09-04 14:19:14 -07006446 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6447 &base_vha->dpc_flags)) {
6448 ql_log(ql_log_info, base_vha, 0xffffff,
6449 "SET ZIO Activity exchange threshold to %d.\n",
6450 ha->last_zio_threshold);
6451 qla27xx_set_zio_threshold(base_vha,
6452 ha->last_zio_threshold);
6453 }
6454
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006455 if (!IS_QLAFX00(ha))
6456 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006457
Quinn Tran48acad02018-08-02 13:16:44 -07006458 if (test_and_clear_bit(N2N_LINK_RESET,
6459 &base_vha->dpc_flags)) {
6460 qla2x00_lip_reset(base_vha);
6461 }
6462
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006464end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006465 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006467 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006469 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6470 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471
6472 /*
6473 * Make sure that nobody tries to wake us up again.
6474 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475 ha->dpc_active = 0;
6476
Andrew Vasquezac280b62009-08-20 11:06:05 -07006477 /* Cleanup any residual CTX SRBs. */
6478 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6479
Christoph Hellwig39a11242006-02-14 18:46:22 +01006480 return 0;
6481}
6482
6483void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006484qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006485{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006486 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006487 struct task_struct *t = ha->dpc_thread;
6488
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006489 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006490 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491}
6492
6493/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494* qla2x00_rst_aen
6495* Processes asynchronous reset.
6496*
6497* Input:
6498* ha = adapter block pointer.
6499*/
6500static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006501qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006503 if (vha->flags.online && !vha->flags.reset_active &&
6504 !atomic_read(&vha->loop_down_timer) &&
6505 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006507 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508
6509 /*
6510 * Issue marker command only when we are going to start
6511 * the I/O.
6512 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006513 vha->marker_needed = 1;
6514 } while (!atomic_read(&vha->loop_down_timer) &&
6515 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 }
6517}
6518
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519/**************************************************************************
6520* qla2x00_timer
6521*
6522* Description:
6523* One second timer
6524*
6525* Context: Interrupt
6526***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006527void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006528qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006530 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 int start_dpc = 0;
6533 int index;
6534 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006535 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006536 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006537 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006538
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006539 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006540 ql_dbg(ql_dbg_timer, vha, 0x6000,
6541 "EEH = %d, restarting timer.\n",
6542 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006543 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6544 return;
6545 }
6546
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006547 /*
6548 * Hardware read to raise pending EEH errors during mailbox waits. If
6549 * the read returns -1 then disable the board.
6550 */
6551 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006552 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006553 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006556 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006557 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006558 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6559 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006560 if (IS_QLA82XX(ha))
6561 qla82xx_watchdog(vha);
6562 else if (IS_QLA8044(ha))
6563 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006564 }
6565
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006566 if (!vha->vp_idx && IS_QLAFX00(ha))
6567 qlafx00_timer_routine(vha);
6568
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006570 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006571 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6572 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006573 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006575 if (atomic_read(&vha->loop_down_timer) ==
6576 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006578 ql_log(ql_log_info, vha, 0x6008,
6579 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006581 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6582 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006584 /*
6585 * Schedule an ISP abort to return any FCP2-device
6586 * commands.
6587 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006588 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006589 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006590 spin_lock_irqsave(&ha->hardware_lock,
6591 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006592 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006593 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006594 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006595 index++) {
6596 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006597
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006598 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006599 if (!sp)
6600 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006601 if (sp->cmd_type != TYPE_SRB)
6602 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006603 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006604 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006605 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006606 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006607 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006609 if (IS_QLA82XX(ha))
6610 set_bit(FCOE_CTX_RESET_NEEDED,
6611 &vha->dpc_flags);
6612 else
6613 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006614 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006615 break;
6616 }
6617 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006618 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620 start_dpc++;
6621 }
6622
6623 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006624 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006625 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006626 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 "Loop down - aborting ISP.\n");
6628
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006629 if (IS_QLA82XX(ha))
6630 set_bit(FCOE_CTX_RESET_NEEDED,
6631 &vha->dpc_flags);
6632 else
6633 set_bit(ISP_ABORT_NEEDED,
6634 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635 }
6636 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006637 ql_dbg(ql_dbg_timer, vha, 0x600a,
6638 "Loop down - seconds remaining %d.\n",
6639 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006641 /* Check if beacon LED needs to be blinked for physical host only */
6642 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006643 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006644 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006645 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6646 start_dpc++;
6647 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006648 }
6649
Andrew Vasquez550bf572008-04-24 15:21:23 -07006650 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006651 if (!list_empty(&vha->work_list)) {
6652 unsigned long flags;
6653 bool q = false;
6654
6655 spin_lock_irqsave(&vha->work_lock, flags);
6656 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6657 q = true;
6658 spin_unlock_irqrestore(&vha->work_lock, flags);
6659 if (q)
6660 queue_work(vha->hw->wq, &vha->iocb_work);
6661 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006662
Duane Grigsby7401bc12017-06-21 13:48:42 -07006663 /*
6664 * FC-NVME
6665 * see if the active AEN count has changed from what was last reported.
6666 */
Giridhar Malavalib2d1453a2019-04-02 14:24:32 -07006667 if (!vha->vp_idx &&
6668 (atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen) &&
6669 ha->zio_mode == QLA_ZIO_MODE_6 &&
6670 !ha->flags.host_shutting_down) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006671 ql_log(ql_log_info, vha, 0x3002,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006672 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6673 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006674 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006675 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6676 start_dpc++;
6677 }
6678
6679 if (!vha->vp_idx &&
6680 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6681 (ha->zio_mode == QLA_ZIO_MODE_6) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006682 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
Quinn Tran8b4673b2018-09-04 14:19:14 -07006683 ql_log(ql_log_info, vha, 0x3002,
6684 "Sched: Set ZIO exchange threshold to %d.\n",
6685 ha->last_zio_threshold);
6686 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006687 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6688 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006689 }
6690
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006692 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6693 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6694 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006696 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6697 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006698 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6699 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006700 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006701 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006702 ql_dbg(ql_dbg_timer, vha, 0x600b,
6703 "isp_abort_needed=%d loop_resync_needed=%d "
6704 "fcport_update_needed=%d start_dpc=%d "
6705 "reset_marker_needed=%d",
6706 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6707 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6708 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6709 start_dpc,
6710 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6711 ql_dbg(ql_dbg_timer, vha, 0x600c,
6712 "beacon_blink_needed=%d isp_unrecoverable=%d "
6713 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006714 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006715 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6716 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6717 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6718 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006719 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006720 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006723 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724}
6725
Andrew Vasquez54333832005-11-09 15:49:04 -08006726/* Firmware interface routines. */
6727
Andrew Vasquez54333832005-11-09 15:49:04 -08006728#define FW_ISP21XX 0
6729#define FW_ISP22XX 1
6730#define FW_ISP2300 2
6731#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006732#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006733#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006734#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006735#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006736#define FW_ISP2031 8
6737#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006738#define FW_ISP27XX 10
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006739#define FW_ISP28XX 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006740
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006741#define FW_FILE_ISP21XX "ql2100_fw.bin"
6742#define FW_FILE_ISP22XX "ql2200_fw.bin"
6743#define FW_FILE_ISP2300 "ql2300_fw.bin"
6744#define FW_FILE_ISP2322 "ql2322_fw.bin"
6745#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006746#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006747#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006748#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006749#define FW_FILE_ISP2031 "ql2600_fw.bin"
6750#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006751#define FW_FILE_ISP27XX "ql2700_fw.bin"
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006752#define FW_FILE_ISP28XX "ql2800_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006753
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006754
Daniel Walkere1e82b62008-05-12 22:21:10 -07006755static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006756
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006757static struct fw_blob qla_fw_blobs[] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006758 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6759 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6760 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6761 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6762 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006763 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006764 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006765 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006766 { .name = FW_FILE_ISP2031, },
6767 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006768 { .name = FW_FILE_ISP27XX, },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006769 { .name = FW_FILE_ISP28XX, },
6770 { .name = NULL, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006771};
6772
6773struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006774qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006775{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006776 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006777 struct fw_blob *blob;
6778
Andrew Vasquez54333832005-11-09 15:49:04 -08006779 if (IS_QLA2100(ha)) {
6780 blob = &qla_fw_blobs[FW_ISP21XX];
6781 } else if (IS_QLA2200(ha)) {
6782 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006783 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006784 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006785 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006786 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006787 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006788 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006789 } else if (IS_QLA25XX(ha)) {
6790 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006791 } else if (IS_QLA81XX(ha)) {
6792 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006793 } else if (IS_QLA82XX(ha)) {
6794 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006795 } else if (IS_QLA2031(ha)) {
6796 blob = &qla_fw_blobs[FW_ISP2031];
6797 } else if (IS_QLA8031(ha)) {
6798 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006799 } else if (IS_QLA27XX(ha)) {
6800 blob = &qla_fw_blobs[FW_ISP27XX];
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006801 } else if (IS_QLA28XX(ha)) {
6802 blob = &qla_fw_blobs[FW_ISP28XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006803 } else {
6804 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006805 }
6806
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006807 if (!blob->name)
6808 return NULL;
6809
Daniel Walkere1e82b62008-05-12 22:21:10 -07006810 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006811 if (blob->fw)
6812 goto out;
6813
6814 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006815 ql_log(ql_log_warn, vha, 0x0063,
6816 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006817 blob->fw = NULL;
6818 blob = NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006819 }
6820
6821out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006822 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006823 return blob;
6824}
6825
6826static void
6827qla2x00_release_firmware(void)
6828{
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006829 struct fw_blob *blob;
Andrew Vasquez54333832005-11-09 15:49:04 -08006830
Daniel Walkere1e82b62008-05-12 22:21:10 -07006831 mutex_lock(&qla_fw_lock);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006832 for (blob = qla_fw_blobs; blob->name; blob++)
6833 release_firmware(blob->fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006834 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006835}
6836
Quinn Tran5386a4e2019-05-06 13:52:19 -07006837static void qla_pci_error_cleanup(scsi_qla_host_t *vha)
6838{
6839 struct qla_hw_data *ha = vha->hw;
6840 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6841 struct qla_qpair *qpair = NULL;
6842 struct scsi_qla_host *vp;
6843 fc_port_t *fcport;
6844 int i;
6845 unsigned long flags;
6846
6847 ha->chip_reset++;
6848
6849 ha->base_qpair->chip_reset = ha->chip_reset;
6850 for (i = 0; i < ha->max_qpairs; i++) {
6851 if (ha->queue_pair_map[i])
6852 ha->queue_pair_map[i]->chip_reset =
6853 ha->base_qpair->chip_reset;
6854 }
6855
6856 /* purge MBox commands */
6857 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6858 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6859 complete(&ha->mbx_intr_comp);
6860 }
6861
6862 i = 0;
6863
6864 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6865 atomic_read(&ha->num_pend_mbx_stage2) ||
6866 atomic_read(&ha->num_pend_mbx_stage1)) {
6867 msleep(20);
6868 i++;
6869 if (i > 50)
6870 break;
6871 }
6872
6873 ha->flags.purge_mbox = 0;
6874
6875 mutex_lock(&ha->mq_lock);
6876 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
6877 qpair->online = 0;
6878 mutex_unlock(&ha->mq_lock);
6879
6880 qla2x00_mark_all_devices_lost(vha, 0);
6881
6882 spin_lock_irqsave(&ha->vport_slock, flags);
6883 list_for_each_entry(vp, &ha->vp_list, list) {
6884 atomic_inc(&vp->vref_count);
6885 spin_unlock_irqrestore(&ha->vport_slock, flags);
6886 qla2x00_mark_all_devices_lost(vp, 0);
6887 spin_lock_irqsave(&ha->vport_slock, flags);
6888 atomic_dec(&vp->vref_count);
6889 }
6890 spin_unlock_irqrestore(&ha->vport_slock, flags);
6891
6892 /* Clear all async request states across all VPs. */
6893 list_for_each_entry(fcport, &vha->vp_fcports, list)
6894 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6895
6896 spin_lock_irqsave(&ha->vport_slock, flags);
6897 list_for_each_entry(vp, &ha->vp_list, list) {
6898 atomic_inc(&vp->vref_count);
6899 spin_unlock_irqrestore(&ha->vport_slock, flags);
6900 list_for_each_entry(fcport, &vp->vp_fcports, list)
6901 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6902 spin_lock_irqsave(&ha->vport_slock, flags);
6903 atomic_dec(&vp->vref_count);
6904 }
6905 spin_unlock_irqrestore(&ha->vport_slock, flags);
6906}
6907
6908
Seokmann Ju14e660e2007-09-20 14:07:36 -07006909static pci_ers_result_t
6910qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6911{
Andrew Vasquez85880802009-12-15 21:29:46 -08006912 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6913 struct qla_hw_data *ha = vha->hw;
6914
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006915 ql_dbg(ql_dbg_aer, vha, 0x9000,
6916 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006917
Sawan Chandakefdb5762017-08-23 15:05:00 -07006918 if (!atomic_read(&pdev->enable_cnt)) {
6919 ql_log(ql_log_info, vha, 0xffff,
6920 "PCI device is disabled,state %x\n", state);
6921 return PCI_ERS_RESULT_NEED_RESET;
6922 }
6923
Seokmann Ju14e660e2007-09-20 14:07:36 -07006924 switch (state) {
6925 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006926 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006927 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006928 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6929 qla2xxx_wake_dpc(vha);
6930 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006931 return PCI_ERS_RESULT_CAN_RECOVER;
6932 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006933 ha->flags.eeh_busy = 1;
Quinn Tran5386a4e2019-05-06 13:52:19 -07006934 qla_pci_error_cleanup(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006935 return PCI_ERS_RESULT_NEED_RESET;
6936 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006937 ha->flags.pci_channel_io_perm_failure = 1;
6938 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006939 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006940 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6941 qla2xxx_wake_dpc(vha);
6942 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006943 return PCI_ERS_RESULT_DISCONNECT;
6944 }
6945 return PCI_ERS_RESULT_NEED_RESET;
6946}
6947
6948static pci_ers_result_t
6949qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6950{
6951 int risc_paused = 0;
6952 uint32_t stat;
6953 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006954 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6955 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006956 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6957 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6958
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006959 if (IS_QLA82XX(ha))
6960 return PCI_ERS_RESULT_RECOVERED;
6961
Seokmann Ju14e660e2007-09-20 14:07:36 -07006962 spin_lock_irqsave(&ha->hardware_lock, flags);
6963 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6964 stat = RD_REG_DWORD(&reg->hccr);
6965 if (stat & HCCR_RISC_PAUSE)
6966 risc_paused = 1;
6967 } else if (IS_QLA23XX(ha)) {
6968 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6969 if (stat & HSR_RISC_PAUSED)
6970 risc_paused = 1;
6971 } else if (IS_FWI2_CAPABLE(ha)) {
6972 stat = RD_REG_DWORD(&reg24->host_status);
6973 if (stat & HSRX_RISC_PAUSED)
6974 risc_paused = 1;
6975 }
6976 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6977
6978 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006979 ql_log(ql_log_info, base_vha, 0x9003,
6980 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006981 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006982
6983 return PCI_ERS_RESULT_NEED_RESET;
6984 } else
6985 return PCI_ERS_RESULT_RECOVERED;
6986}
6987
6988static pci_ers_result_t
6989qla2xxx_pci_slot_reset(struct pci_dev *pdev)
6990{
6991 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006992 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6993 struct qla_hw_data *ha = base_vha->hw;
Quinn Tran5386a4e2019-05-06 13:52:19 -07006994 int rc;
6995 struct qla_qpair *qpair = NULL;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006996
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006997 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
6998 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08006999
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007000 /* Workaround: qla2xxx driver which access hardware earlier
7001 * needs error state to be pci_channel_io_online.
7002 * Otherwise mailbox command timesout.
7003 */
7004 pdev->error_state = pci_channel_io_normal;
7005
7006 pci_restore_state(pdev);
7007
Richard Lary8c1496b2010-02-18 10:07:29 -08007008 /* pci_restore_state() clears the saved_state flag of the device
7009 * save restored state which resets saved_state flag
7010 */
7011 pci_save_state(pdev);
7012
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11007013 if (ha->mem_only)
7014 rc = pci_enable_device_mem(pdev);
7015 else
7016 rc = pci_enable_device(pdev);
7017
7018 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007019 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007020 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007021 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007022 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007023
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007024
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007025 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007026 goto exit_slot_reset;
7027
Quinn Tran5386a4e2019-05-06 13:52:19 -07007028 mutex_lock(&ha->mq_lock);
7029 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7030 qpair->online = 1;
7031 mutex_unlock(&ha->mq_lock);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007032
Quinn Tran5386a4e2019-05-06 13:52:19 -07007033 base_vha->flags.online = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007034 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007035 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07007036 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007037 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007038
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007039
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007040exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007041 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7042 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08007043
Seokmann Ju14e660e2007-09-20 14:07:36 -07007044 return ret;
7045}
7046
7047static void
7048qla2xxx_pci_resume(struct pci_dev *pdev)
7049{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007050 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7051 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007052 int ret;
7053
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007054 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
7055 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007056
Quinn Tran5386a4e2019-05-06 13:52:19 -07007057 ha->flags.eeh_busy = 0;
7058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007059 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007060 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007061 ql_log(ql_log_fatal, base_vha, 0x9002,
7062 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07007063 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007064}
7065
Quinn Tran590f8062019-01-24 23:23:40 -08007066static void
7067qla_pci_reset_prepare(struct pci_dev *pdev)
7068{
7069 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7070 struct qla_hw_data *ha = base_vha->hw;
7071 struct qla_qpair *qpair;
7072
7073 ql_log(ql_log_warn, base_vha, 0xffff,
7074 "%s.\n", __func__);
7075
7076 /*
7077 * PCI FLR/function reset is about to reset the
7078 * slot. Stop the chip to stop all DMA access.
7079 * It is assumed that pci_reset_done will be called
7080 * after FLR to resume Chip operation.
7081 */
7082 ha->flags.eeh_busy = 1;
7083 mutex_lock(&ha->mq_lock);
7084 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7085 qpair->online = 0;
7086 mutex_unlock(&ha->mq_lock);
7087
7088 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7089 qla2x00_abort_isp_cleanup(base_vha);
7090 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7091}
7092
7093static void
7094qla_pci_reset_done(struct pci_dev *pdev)
7095{
7096 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7097 struct qla_hw_data *ha = base_vha->hw;
7098 struct qla_qpair *qpair;
7099
7100 ql_log(ql_log_warn, base_vha, 0xffff,
7101 "%s.\n", __func__);
7102
7103 /*
7104 * FLR just completed by PCI layer. Resume adapter
7105 */
7106 ha->flags.eeh_busy = 0;
7107 mutex_lock(&ha->mq_lock);
7108 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7109 qpair->online = 1;
7110 mutex_unlock(&ha->mq_lock);
7111
7112 base_vha->flags.online = 1;
7113 ha->isp_ops->abort_isp(base_vha);
7114 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7115}
7116
Michael Hernandez56012362016-12-12 14:40:08 -08007117static int qla2xxx_map_queues(struct Scsi_Host *shost)
7118{
Quinn Trand68b8502017-12-04 14:44:59 -08007119 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007120 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
Dongli Zhang485b0ec2019-03-12 09:00:30 +08007121 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
Michael Hernandez56012362016-12-12 14:40:08 -08007122
Giridhar Malavalif3e02692019-02-15 16:42:55 -08007123 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
Jens Axboeed76e322018-10-29 13:06:14 -06007124 rc = blk_mq_map_queues(qmap);
Quinn Trand68b8502017-12-04 14:44:59 -08007125 else
Ming Leif0783d42019-01-11 09:40:47 -08007126 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
Quinn Trand68b8502017-12-04 14:44:59 -08007127 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007128}
7129
Bart Van Assche6515ad72019-04-04 12:44:43 -07007130struct scsi_host_template qla2xxx_driver_template = {
7131 .module = THIS_MODULE,
7132 .name = QLA2XXX_DRIVER_NAME,
7133 .queuecommand = qla2xxx_queuecommand,
7134
7135 .eh_timed_out = fc_eh_timed_out,
7136 .eh_abort_handler = qla2xxx_eh_abort,
7137 .eh_device_reset_handler = qla2xxx_eh_device_reset,
7138 .eh_target_reset_handler = qla2xxx_eh_target_reset,
7139 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
7140 .eh_host_reset_handler = qla2xxx_eh_host_reset,
7141
7142 .slave_configure = qla2xxx_slave_configure,
7143
7144 .slave_alloc = qla2xxx_slave_alloc,
7145 .slave_destroy = qla2xxx_slave_destroy,
7146 .scan_finished = qla2xxx_scan_finished,
7147 .scan_start = qla2xxx_scan_start,
7148 .change_queue_depth = scsi_change_queue_depth,
7149 .map_queues = qla2xxx_map_queues,
7150 .this_id = -1,
7151 .cmd_per_lun = 3,
7152 .sg_tablesize = SG_ALL,
7153
7154 .max_sectors = 0xFFFF,
7155 .shost_attrs = qla2x00_host_attrs,
7156
7157 .supported_mode = MODE_INITIATOR,
7158 .track_queue_depth = 1,
7159};
7160
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07007161static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07007162 .error_detected = qla2xxx_pci_error_detected,
7163 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7164 .slot_reset = qla2xxx_pci_slot_reset,
7165 .resume = qla2xxx_pci_resume,
Quinn Tran590f8062019-01-24 23:23:40 -08007166 .reset_prepare = qla_pci_reset_prepare,
7167 .reset_done = qla_pci_reset_done,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007168};
7169
Andrew Vasquez54333832005-11-09 15:49:04 -08007170static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007171 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7172 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7173 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7174 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7175 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7176 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7177 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7178 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7179 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007180 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007181 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7182 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07007183 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007184 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007185 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07007186 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04007187 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04007188 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007189 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05007190 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04007191 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04007192 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07007193 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7194 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7195 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7196 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7197 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
Andrew Vasquez54333832005-11-09 15:49:04 -08007198 { 0 },
7199};
7200MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7201
Andrew Vasquezfca29702005-07-06 10:31:47 -07007202static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07007203 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06007204 .driver = {
7205 .owner = THIS_MODULE,
7206 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07007207 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007208 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08007209 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07007210 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007211 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07007212};
7213
Al Viro75ef9de2013-04-04 19:09:41 -04007214static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007215 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02007216 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007217};
7218
Linus Torvalds1da177e2005-04-16 15:20:36 -07007219/**
7220 * qla2x00_module_init - Module initialization.
7221 **/
7222static int __init
7223qla2x00_module_init(void)
7224{
Andrew Vasquezfca29702005-07-06 10:31:47 -07007225 int ret = 0;
7226
Bart Van Asschebc044592019-04-17 14:44:37 -07007227 BUILD_BUG_ON(sizeof(cmd_entry_t) != 64);
7228 BUILD_BUG_ON(sizeof(cont_a64_entry_t) != 64);
7229 BUILD_BUG_ON(sizeof(cont_entry_t) != 64);
7230 BUILD_BUG_ON(sizeof(init_cb_t) != 96);
7231 BUILD_BUG_ON(sizeof(ms_iocb_entry_t) != 64);
7232 BUILD_BUG_ON(sizeof(request_t) != 64);
7233 BUILD_BUG_ON(sizeof(struct access_chip_84xx) != 64);
7234 BUILD_BUG_ON(sizeof(struct cmd_bidir) != 64);
7235 BUILD_BUG_ON(sizeof(struct cmd_nvme) != 64);
7236 BUILD_BUG_ON(sizeof(struct cmd_type_6) != 64);
7237 BUILD_BUG_ON(sizeof(struct cmd_type_7) != 64);
7238 BUILD_BUG_ON(sizeof(struct cmd_type_7_fx00) != 64);
7239 BUILD_BUG_ON(sizeof(struct cmd_type_crc_2) != 64);
7240 BUILD_BUG_ON(sizeof(struct ct_entry_24xx) != 64);
7241 BUILD_BUG_ON(sizeof(struct ctio_crc2_to_fw) != 64);
7242 BUILD_BUG_ON(sizeof(struct els_entry_24xx) != 64);
7243 BUILD_BUG_ON(sizeof(struct fxdisc_entry_fx00) != 64);
7244 BUILD_BUG_ON(sizeof(struct init_cb_24xx) != 128);
7245 BUILD_BUG_ON(sizeof(struct init_cb_81xx) != 128);
7246 BUILD_BUG_ON(sizeof(struct pt_ls4_request) != 64);
7247 BUILD_BUG_ON(sizeof(struct sns_cmd_pkt) != 2064);
7248 BUILD_BUG_ON(sizeof(struct verify_chip_entry_84xx) != 64);
7249 BUILD_BUG_ON(sizeof(struct vf_evfp_entry_24xx) != 56);
7250
Linus Torvalds1da177e2005-04-16 15:20:36 -07007251 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007252 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09007253 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007254 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007255 ql_log(ql_log_fatal, NULL, 0x0001,
7256 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007257 return -ENOMEM;
7258 }
7259
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007260 /* Initialize target kmem_cache and mem_pools */
7261 ret = qlt_init();
7262 if (ret < 0) {
Bart Van Asschec794d242019-04-04 12:44:46 -07007263 goto destroy_cache;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007264 } else if (ret > 0) {
7265 /*
7266 * If initiator mode is explictly disabled by qlt_init(),
7267 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7268 * performing scsi_scan_target() during LOOP UP event.
7269 */
7270 qla2xxx_transport_functions.disable_target_scan = 1;
7271 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7272 }
7273
Linus Torvalds1da177e2005-04-16 15:20:36 -07007274 /* Derive version string. */
7275 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07007276 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07007277 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07007278 if (ql2xextended_error_logging == 1)
7279 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07007280
Quinn Tran0645cb82018-09-11 10:18:18 -07007281 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7282 qla_insert_tgt_attrs();
7283
Andrew Vasquez1c97a122005-04-21 16:13:36 -04007284 qla2xxx_transport_template =
7285 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007286 if (!qla2xxx_transport_template) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007287 ql_log(ql_log_fatal, NULL, 0x0002,
7288 "fc_attach_transport failed...Failing load!.\n");
Bart Van Asschec794d242019-04-04 12:44:46 -07007289 ret = -ENODEV;
7290 goto qlt_exit;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007291 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007292
7293 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7294 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007295 ql_log(ql_log_fatal, NULL, 0x0003,
7296 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007297 }
7298
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007299 qla2xxx_transport_vport_template =
7300 fc_attach_transport(&qla2xxx_transport_vport_functions);
7301 if (!qla2xxx_transport_vport_template) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007302 ql_log(ql_log_fatal, NULL, 0x0004,
7303 "fc_attach_transport vport failed...Failing load!.\n");
Bart Van Asschec794d242019-04-04 12:44:46 -07007304 ret = -ENODEV;
7305 goto unreg_chrdev;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007306 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007307 ql_log(ql_log_info, NULL, 0x0005,
7308 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07007309 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007310 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007311 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007312 ql_log(ql_log_fatal, NULL, 0x0006,
7313 "pci_register_driver failed...ret=%d Failing load!.\n",
7314 ret);
Bart Van Asschec794d242019-04-04 12:44:46 -07007315 goto release_vport_transport;
Andrew Vasquezfca29702005-07-06 10:31:47 -07007316 }
7317 return ret;
Bart Van Asschec794d242019-04-04 12:44:46 -07007318
7319release_vport_transport:
7320 fc_release_transport(qla2xxx_transport_vport_template);
7321
7322unreg_chrdev:
7323 if (apidev_major >= 0)
7324 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7325 fc_release_transport(qla2xxx_transport_template);
7326
7327qlt_exit:
7328 qlt_exit();
7329
7330destroy_cache:
7331 kmem_cache_destroy(srb_cachep);
7332 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007333}
7334
7335/**
7336 * qla2x00_module_exit - Module cleanup.
7337 **/
7338static void __exit
7339qla2x00_module_exit(void)
7340{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007341 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08007342 qla2x00_release_firmware();
Thomas Meyer75c1d482018-12-02 21:52:11 +01007343 kmem_cache_destroy(ctx_cachep);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007344 fc_release_transport(qla2xxx_transport_vport_template);
Bart Van Assche59c209a2019-04-04 12:44:47 -07007345 if (apidev_major >= 0)
7346 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7347 fc_release_transport(qla2xxx_transport_template);
7348 qlt_exit();
7349 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007350}
7351
7352module_init(qla2x00_module_init);
7353module_exit(qla2x00_module_exit);
7354
7355MODULE_AUTHOR("QLogic Corporation");
7356MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7357MODULE_LICENSE("GPL");
7358MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07007359MODULE_FIRMWARE(FW_FILE_ISP21XX);
7360MODULE_FIRMWARE(FW_FILE_ISP22XX);
7361MODULE_FIRMWARE(FW_FILE_ISP2300);
7362MODULE_FIRMWARE(FW_FILE_ISP2322);
7363MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08007364MODULE_FIRMWARE(FW_FILE_ISP25XX);