blob: a3561e461aa555076fb7be007b1d401fdca50907 [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);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700717 wait_queue_head_t *cwaitq = sp->cwaitq;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800718
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800719 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800720 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800721 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
722 sp, GET_CMD_SP(sp));
723 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400724 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800725 return;
726 }
727 if (!atomic_dec_and_test(&sp->ref_count))
728 return;
729
Joe Carnucciof3caa992017-08-23 15:05:09 -0700730 sp->free(sp);
Giridhar Malavali740e2932019-04-02 14:24:20 -0700731 cmd->result = res;
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700732 CMD_SP(cmd) = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800733 cmd->scsi_done(cmd);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700734 if (cwaitq)
735 wake_up(cwaitq);
736 qla2x00_rel_sp(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700737}
738
Michael Hernandezd7459522016-12-12 14:40:07 -0800739void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800740qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800741{
742 srb_t *sp = (srb_t *)ptr;
743 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
744 struct qla_hw_data *ha = sp->fcport->vha->hw;
745 void *ctx = GET_CMD_CTX_SP(sp);
746
747 if (sp->flags & SRB_DMA_VALID) {
748 scsi_dma_unmap(cmd);
749 sp->flags &= ~SRB_DMA_VALID;
750 }
751
752 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
753 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
754 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
755 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
756 }
757
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700758 if (!ctx)
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700759 return;
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700760
Michael Hernandezd7459522016-12-12 14:40:07 -0800761 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
762 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700763 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800764 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
765 }
766
767 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700768 struct crc_context *ctx0 = ctx;
769
770 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800771 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
772 }
773
774 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700775 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800776 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
777 ctx1->fcp_cmnd_dma);
778 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
779 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
780 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
781 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali50b81272018-12-21 09:33:45 -0800782 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
Michael Hernandezd7459522016-12-12 14:40:07 -0800783 }
Giridhar Malavali50b81272018-12-21 09:33:45 -0800784 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
785 struct crc_context *difctx = sp->u.scmd.ctx;
786 struct dsd_dma *dif_dsd, *nxt_dsd;
787
788 list_for_each_entry_safe(dif_dsd, nxt_dsd,
789 &difctx->ldif_dma_hndl_list, list) {
790 list_del(&dif_dsd->list);
791 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
792 dif_dsd->dsd_list_dma);
793 kfree(dif_dsd);
794 difctx->no_dif_bundl--;
795 }
796
797 list_for_each_entry_safe(dif_dsd, nxt_dsd,
798 &difctx->ldif_dsd_list, list) {
799 list_del(&dif_dsd->list);
800 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
801 dif_dsd->dsd_list_dma);
802 kfree(dif_dsd);
803 difctx->no_ldif_dsd--;
804 }
805
806 if (difctx->no_ldif_dsd) {
807 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
808 "%s: difctx->no_ldif_dsd=%x\n",
809 __func__, difctx->no_ldif_dsd);
810 }
811
812 if (difctx->no_dif_bundl) {
813 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
814 "%s: difctx->no_dif_bundl=%x\n",
815 __func__, difctx->no_dif_bundl);
816 }
817 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
818 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800819}
820
821void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800822qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800823{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800824 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800825 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700826 wait_queue_head_t *cwaitq = sp->cwaitq;
Michael Hernandezd7459522016-12-12 14:40:07 -0800827
828 if (atomic_read(&sp->ref_count) == 0) {
829 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
830 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
831 sp, GET_CMD_SP(sp));
832 if (ql2xextended_error_logging & ql_dbg_io)
833 WARN_ON(atomic_read(&sp->ref_count) == 0);
834 return;
835 }
836 if (!atomic_dec_and_test(&sp->ref_count))
837 return;
838
Joe Carnucciof3caa992017-08-23 15:05:09 -0700839 sp->free(sp);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700840 cmd->result = res;
841 CMD_SP(cmd) = NULL;
Michael Hernandezd7459522016-12-12 14:40:07 -0800842 cmd->scsi_done(cmd);
Giridhar Malavali711a08d2019-04-02 14:24:33 -0700843 if (cwaitq)
844 wake_up(cwaitq);
845 qla2xxx_rel_qpair_sp(sp->qpair, sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800846}
847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800849qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700850{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700851 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700852 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400853 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800854 struct qla_hw_data *ha = vha->hw;
855 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700856 srb_t *sp;
857 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800858 struct qla_qpair *qpair = NULL;
859 uint32_t tag;
860 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700861
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200862 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
863 cmd->result = DID_NO_CONNECT << 16;
864 goto qc24_fail_command;
865 }
866
Michael Hernandez56012362016-12-12 14:40:08 -0800867 if (ha->mqenable) {
Jens Axboef664a3c2018-11-01 16:36:27 -0600868 tag = blk_mq_unique_tag(cmd->request);
869 hwq = blk_mq_unique_tag_to_hwq(tag);
870 qpair = ha->queue_pair_map[hwq];
Michael Hernandez56012362016-12-12 14:40:08 -0800871
872 if (qpair)
873 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800874 }
875
Andrew Vasquez85880802009-12-15 21:29:46 -0800876 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700877 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400878 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700879 "PCI Channel IO permanent failure, exiting "
880 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700881 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700882 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400883 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700884 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800885 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700886 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700887 goto qc24_fail_command;
888 }
889
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400890 rval = fc_remote_port_chkready(rport);
891 if (rval) {
892 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400893 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700894 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
895 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700896 goto qc24_fail_command;
897 }
898
Arun Easibad75002010-05-04 15:01:30 -0700899 if (!vha->flags.difdix_supported &&
900 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700901 ql_dbg(ql_dbg_io, vha, 0x3004,
902 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
903 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700904 cmd->result = DID_NO_CONNECT << 16;
905 goto qc24_fail_command;
906 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800907
908 if (!fcport) {
909 cmd->result = DID_NO_CONNECT << 16;
910 goto qc24_fail_command;
911 }
912
Andrew Vasquezfca29702005-07-06 10:31:47 -0700913 if (atomic_read(&fcport->state) != FCS_ONLINE) {
914 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700915 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700916 ql_dbg(ql_dbg_io, vha, 0x3005,
917 "Returning DNC, fcport_state=%d loop_state=%d.\n",
918 atomic_read(&fcport->state),
919 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700920 cmd->result = DID_NO_CONNECT << 16;
921 goto qc24_fail_command;
922 }
Mike Christie7b594132008-08-17 15:24:40 -0500923 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700924 }
925
Chad Dupuise05fe292014-09-25 05:16:59 -0400926 /*
927 * Return target busy if we've received a non-zero retry_delay_timer
928 * in a FCP_RSP.
929 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100930 if (fcport->retry_delay_timestamp == 0) {
931 /* retry delay not set */
932 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400933 fcport->retry_delay_timestamp = 0;
934 else
935 goto qc24_target_busy;
936
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500937 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400938 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800939 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700940
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800941 sp->u.scmd.cmd = cmd;
942 sp->type = SRB_SCSI_CMD;
943 atomic_set(&sp->ref_count, 1);
944 CMD_SP(cmd) = (void *)sp;
945 sp->free = qla2x00_sp_free_dma;
946 sp->done = qla2x00_sp_compl;
947
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800948 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700949 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500950 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700951 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700952 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700953 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700954
Andrew Vasquezfca29702005-07-06 10:31:47 -0700955 return 0;
956
957qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -0700958 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700959
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800960qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700961 return SCSI_MLQUEUE_HOST_BUSY;
962
Mike Christie7b594132008-08-17 15:24:40 -0500963qc24_target_busy:
964 return SCSI_MLQUEUE_TARGET_BUSY;
965
Andrew Vasquezfca29702005-07-06 10:31:47 -0700966qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800967 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700968
969 return 0;
970}
971
Michael Hernandezd7459522016-12-12 14:40:07 -0800972/* For MQ supported I/O */
973int
974qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
975 struct qla_qpair *qpair)
976{
977 scsi_qla_host_t *vha = shost_priv(host);
978 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
979 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
980 struct qla_hw_data *ha = vha->hw;
981 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
982 srb_t *sp;
983 int rval;
984
985 rval = fc_remote_port_chkready(rport);
986 if (rval) {
987 cmd->result = rval;
988 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
989 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
990 cmd, rval);
991 goto qc24_fail_command;
992 }
993
994 if (!fcport) {
995 cmd->result = DID_NO_CONNECT << 16;
996 goto qc24_fail_command;
997 }
998
999 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1000 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
1001 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1002 ql_dbg(ql_dbg_io, vha, 0x3077,
1003 "Returning DNC, fcport_state=%d loop_state=%d.\n",
1004 atomic_read(&fcport->state),
1005 atomic_read(&base_vha->loop_state));
1006 cmd->result = DID_NO_CONNECT << 16;
1007 goto qc24_fail_command;
1008 }
1009 goto qc24_target_busy;
1010 }
1011
1012 /*
1013 * Return target busy if we've received a non-zero retry_delay_timer
1014 * in a FCP_RSP.
1015 */
1016 if (fcport->retry_delay_timestamp == 0) {
1017 /* retry delay not set */
1018 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1019 fcport->retry_delay_timestamp = 0;
1020 else
1021 goto qc24_target_busy;
1022
Quinn Tran6a629462018-09-04 14:19:15 -07001023 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
Michael Hernandezd7459522016-12-12 14:40:07 -08001024 if (!sp)
1025 goto qc24_host_busy;
1026
1027 sp->u.scmd.cmd = cmd;
1028 sp->type = SRB_SCSI_CMD;
1029 atomic_set(&sp->ref_count, 1);
1030 CMD_SP(cmd) = (void *)sp;
1031 sp->free = qla2xxx_qpair_sp_free_dma;
1032 sp->done = qla2xxx_qpair_sp_compl;
1033 sp->qpair = qpair;
1034
1035 rval = ha->isp_ops->start_scsi_mq(sp);
1036 if (rval != QLA_SUCCESS) {
1037 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1038 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1039 if (rval == QLA_INTERFACE_ERROR)
1040 goto qc24_fail_command;
1041 goto qc24_host_busy_free_sp;
1042 }
1043
1044 return 0;
1045
1046qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001047 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001048
1049qc24_host_busy:
1050 return SCSI_MLQUEUE_HOST_BUSY;
1051
1052qc24_target_busy:
1053 return SCSI_MLQUEUE_TARGET_BUSY;
1054
1055qc24_fail_command:
1056 cmd->scsi_done(cmd);
1057
1058 return 0;
1059}
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061/*
1062 * qla2x00_eh_wait_on_command
1063 * Waits for the command to be returned by the Firmware for some
1064 * max time.
1065 *
1066 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 *
1069 * Return:
1070 * Not Found : 0
1071 * Found : 1
1072 */
1073static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001074qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001076#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001077#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001078 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001079 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1080 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001081 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Andrew Vasquez85880802009-12-15 21:29:46 -08001083 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1085 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001086 return ret;
1087 }
1088
Lalit Chandivaded9704322009-08-25 11:36:18 -07001089 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001090 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001091 }
1092 if (CMD_SP(cmd))
1093 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
f4f051e2005-04-17 15:02:26 -05001095 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096}
1097
1098/*
1099 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001100 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 * <= MAX_RETRIES_OF_ISP_ABORT or
1102 * finally HBA is disabled ie marked offline
1103 *
1104 * Input:
1105 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001106 *
1107 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 * Does context switching-Release SPIN_LOCK
1109 * (if any) before calling this routine.
1110 *
1111 * Return:
1112 * Success (Adapter is online) : 0
1113 * Failed (Adapter is offline/disabled) : 1
1114 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001115int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001116qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001118 int return_status;
1119 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001120 struct qla_hw_data *ha = vha->hw;
1121 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001123 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001124 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1125 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1126 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1127 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 msleep(1000);
1130 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001131 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001132 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 else
1134 return_status = QLA_FUNCTION_FAILED;
1135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 return (return_status);
1137}
1138
Quinn Tran726b8542017-01-19 22:28:00 -08001139static inline int test_fcport_count(scsi_qla_host_t *vha)
1140{
1141 struct qla_hw_data *ha = vha->hw;
1142 unsigned long flags;
1143 int res;
1144
1145 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001146 ql_dbg(ql_dbg_init, vha, 0x00ec,
1147 "tgt %p, fcport_count=%d\n",
1148 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001149 res = (vha->fcport_count == 0);
1150 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1151
1152 return res;
1153}
1154
1155/*
1156 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1157 * it has dependency on UNLOADING flag to stop device discovery
1158 */
Quinn Tranefa93f42018-07-18 14:29:52 -07001159void
Quinn Tran726b8542017-01-19 22:28:00 -08001160qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1161{
1162 qla2x00_mark_all_devices_lost(vha, 0);
1163
Joe Carnucciob85e0952017-08-23 15:05:11 -07001164 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001165}
1166
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001167/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001168 * qla2x00_wait_for_hba_ready
1169 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001170 *
1171 * Input:
1172 * ha - pointer to host adapter structure
1173 *
1174 * Note:
1175 * Does context switching-Release SPIN_LOCK
1176 * (if any) before calling this routine.
1177 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001178 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001179static void
1180qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001181{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001182 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001183 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001184
Dan Carpenter1d483902016-08-03 21:42:32 +03001185 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1186 ha->flags.mbox_busy) ||
1187 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1188 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1189 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1190 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001191 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001192 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001193}
1194
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001195int
1196qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1197{
1198 int return_status;
1199 unsigned long wait_reset;
1200 struct qla_hw_data *ha = vha->hw;
1201 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1202
1203 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1204 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1205 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1206 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1207 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1208
1209 msleep(1000);
1210
1211 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1212 ha->flags.chip_reset_done)
1213 break;
1214 }
1215 if (ha->flags.chip_reset_done)
1216 return_status = QLA_SUCCESS;
1217 else
1218 return_status = QLA_FUNCTION_FAILED;
1219
1220 return return_status;
1221}
1222
Quinn Tran585def92018-09-04 14:19:20 -07001223static int
Giridhar Malavali083a4692010-05-28 15:08:18 -07001224sp_get(struct srb *sp)
1225{
Bart Van Assche845bbb02019-04-11 14:53:18 -07001226 if (!refcount_inc_not_zero((refcount_t *)&sp->ref_count))
Quinn Tran585def92018-09-04 14:19:20 -07001227 /* kref get fail */
1228 return ENXIO;
1229 else
1230 return 0;
Giridhar Malavali083a4692010-05-28 15:08:18 -07001231}
1232
Sawan Chandaka4655372016-07-06 11:14:32 -04001233#define ISP_REG_DISCONNECT 0xffffffffU
1234/**************************************************************************
1235* qla2x00_isp_reg_stat
1236*
1237* Description:
1238* Read the host status register of ISP before aborting the command.
1239*
1240* Input:
1241* ha = pointer to host adapter structure.
1242*
1243*
1244* Returns:
1245* Either true or false.
1246*
1247* Note: Return true if there is register disconnect.
1248**************************************************************************/
1249static inline
1250uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1251{
1252 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001253 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001254
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001255 if (IS_P3P_TYPE(ha))
1256 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1257 else
1258 return ((RD_REG_DWORD(&reg->host_status)) ==
1259 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001260}
1261
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262/**************************************************************************
1263* qla2xxx_eh_abort
1264*
1265* Description:
1266* The abort function will abort the specified command.
1267*
1268* Input:
1269* cmd = Linux SCSI command packet to be aborted.
1270*
1271* Returns:
1272* Either SUCCESS or FAILED.
1273*
1274* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001275* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001277static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1279{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001280 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001281 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001282 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001283 unsigned int id;
1284 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001285 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001286 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001287 struct qla_hw_data *ha = vha->hw;
Quinn Tran585def92018-09-04 14:19:20 -07001288 struct qla_qpair *qpair;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Sawan Chandaka4655372016-07-06 11:14:32 -04001290 if (qla2x00_isp_reg_stat(ha)) {
1291 ql_log(ql_log_info, vha, 0x8042,
1292 "PCI/Register disconnect, exiting.\n");
1293 return FAILED;
1294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001296 ret = fc_block_scsi_eh(cmd);
1297 if (ret != 0)
1298 return ret;
1299 ret = SUCCESS;
1300
Mike Christie170babc2010-10-15 11:27:47 -07001301 sp = (srb_t *) CMD_SP(cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001302 if (!sp)
1303 return SUCCESS;
1304
1305 qpair = sp->qpair;
1306 if (!qpair)
1307 return SUCCESS;
1308
1309 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1310 if (!CMD_SP(cmd)) {
1311 /* there's a chance an interrupt could clear
1312 the ptr as part of done & free */
1313 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001314 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001315 }
Mike Christie170babc2010-10-15 11:27:47 -07001316
Quinn Tran585def92018-09-04 14:19:20 -07001317 if (sp_get(sp)){
1318 /* ref_count is already 0 */
1319 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1320 return SUCCESS;
1321 }
1322 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1323
1324 id = cmd->device->id;
1325 lun = cmd->device->lun;
1326
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001327 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001328 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1329 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001330
1331 /* Get a reference to the sp and drop the lock.*/
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001332 rval = ha->isp_ops->abort_command(sp);
1333 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001334 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001335 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001336 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001337 ret = FAILED;
1338
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001339 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001340 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001341 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001342 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001343 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001344 wait = 1;
1345 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001346
Quinn Tran585def92018-09-04 14:19:20 -07001347 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
Quinn Tran585def92018-09-04 14:19:20 -07001348
1349 /*
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001350 * Releasing of the SRB and associated command resources
1351 * is managed through ref_count.
1352 * Whether we need to wait for the abort completion or complete
1353 * the abort handler should be based on the ref_count.
Quinn Tran585def92018-09-04 14:19:20 -07001354 */
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001355 if (atomic_read(&sp->ref_count) > 1) {
1356 /*
1357 * The command is not yet completed. We need to wait for either
1358 * command completion or abort completion.
1359 */
1360 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(eh_waitq);
1361 uint32_t ratov = ha->r_a_tov/10;
f4f051e2005-04-17 15:02:26 -05001362
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001363 /* Go ahead and release the extra ref_count obtained earlier */
1364 sp->done(sp, DID_RESET << 16);
1365 sp->cwaitq = &eh_waitq;
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001366
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001367 if (!wait_event_lock_irq_timeout(eh_waitq,
1368 CMD_SP(cmd) == NULL, *qpair->qp_lock_ptr,
1369 msecs_to_jiffies(4 * ratov * 1000))) {
1370 /*
1371 * The abort got dropped, LOGO will be sent and the
1372 * original command will be completed with CS_TIMEOUT
1373 * completion
1374 */
1375 ql_dbg(ql_dbg_taskm, vha, 0xffff,
1376 "%s: Abort wait timer (4 * R_A_TOV[%d]) expired\n",
1377 __func__, ha->r_a_tov);
1378 sp->cwaitq = NULL;
Michael Reed2ea00202006-04-27 16:25:30 -07001379 ret = FAILED;
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001380 goto end;
f4f051e2005-04-17 15:02:26 -05001381 }
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001382 } else {
1383 /* Command completed while processing the abort */
1384 sp->done(sp, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 }
Giridhar Malavali711a08d2019-04-02 14:24:33 -07001386end:
1387 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001388 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001389 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001390 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
f4f051e2005-04-17 15:02:26 -05001392 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393}
1394
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001395int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001396qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001397 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001399 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001400 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001401 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001402 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001403 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001404 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Andrew Vasquez523ec772008-04-03 13:13:24 -07001406 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001407
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001408 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001409 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001410 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001411 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001412 sp = req->outstanding_cmds[cnt];
1413 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001414 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001415 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001416 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001417 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001418 continue;
1419 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001420 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001421 switch (type) {
1422 case WAIT_HOST:
1423 match = 1;
1424 break;
1425 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001426 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001427 break;
1428 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001429 match = (cmd->device->id == t &&
1430 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001431 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001433 if (!match)
1434 continue;
1435
1436 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001437 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001438 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001440 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001441
1442 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443}
1444
Andrew Vasquez523ec772008-04-03 13:13:24 -07001445static char *reset_errors[] = {
1446 "HBA not online",
1447 "HBA not ready",
1448 "Task management failed",
1449 "Waiting for command completions",
1450};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Andrew Vasquez523ec772008-04-03 13:13:24 -07001452static int
1453__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001454 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001455{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001456 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001457 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1458 int err;
1459
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001460 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001461 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001462 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001463
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001464 err = fc_block_scsi_eh(cmd);
1465 if (err != 0)
1466 return err;
1467
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001468 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001469 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001470 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001471
1472 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001473 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1474 ql_log(ql_log_warn, vha, 0x800a,
1475 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001476 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001477 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001478 err = 2;
Himanshu Madhaniac444b42019-03-15 15:04:19 -07001479 if (do_reset(fcport, cmd->device->lun, 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001480 != QLA_SUCCESS) {
1481 ql_log(ql_log_warn, vha, 0x800c,
1482 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001483 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001484 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001485 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001486 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001487 cmd->device->lun, type) != QLA_SUCCESS) {
1488 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001489 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001490 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001491 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001492
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001493 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001494 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001495 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001496
1497 return SUCCESS;
1498
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001499eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001500 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001501 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001502 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1503 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001504 return FAILED;
1505}
1506
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001507static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1509{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001510 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1511 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Sawan Chandaka4655372016-07-06 11:14:32 -04001513 if (qla2x00_isp_reg_stat(ha)) {
1514 ql_log(ql_log_info, vha, 0x803e,
1515 "PCI/Register disconnect, exiting.\n");
1516 return FAILED;
1517 }
1518
Andrew Vasquez523ec772008-04-03 13:13:24 -07001519 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1520 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001524qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1527 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Sawan Chandaka4655372016-07-06 11:14:32 -04001529 if (qla2x00_isp_reg_stat(ha)) {
1530 ql_log(ql_log_info, vha, 0x803f,
1531 "PCI/Register disconnect, exiting.\n");
1532 return FAILED;
1533 }
1534
Andrew Vasquez523ec772008-04-03 13:13:24 -07001535 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1536 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537}
1538
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539/**************************************************************************
1540* qla2xxx_eh_bus_reset
1541*
1542* Description:
1543* The bus reset function will reset the bus and abort any executing
1544* commands.
1545*
1546* Input:
1547* cmd = Linux SCSI command packet of the command that cause the
1548* bus reset.
1549*
1550* Returns:
1551* SUCCESS/FAILURE (defined as macro in scsi.h).
1552*
1553**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001554static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1556{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001557 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001558 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001559 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001560 unsigned int id;
1561 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001562 struct qla_hw_data *ha = vha->hw;
1563
1564 if (qla2x00_isp_reg_stat(ha)) {
1565 ql_log(ql_log_info, vha, 0x8040,
1566 "PCI/Register disconnect, exiting.\n");
1567 return FAILED;
1568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
f4f051e2005-04-17 15:02:26 -05001570 id = cmd->device->id;
1571 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001572
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001573 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001574 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001577 ret = fc_block_scsi_eh(cmd);
1578 if (ret != 0)
1579 return ret;
1580 ret = FAILED;
1581
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001582 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001583 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001585 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001586 ql_log(ql_log_fatal, vha, 0x8013,
1587 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001588 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 }
1590
Saurav Kashyapad5376892011-11-18 09:02:09 -08001591 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1592 ret = SUCCESS;
1593
f4f051e2005-04-17 15:02:26 -05001594 if (ret == FAILED)
1595 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001597 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001598 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001599 QLA_SUCCESS) {
1600 ql_log(ql_log_warn, vha, 0x8014,
1601 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001602 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
f4f051e2005-04-17 15:02:26 -05001605eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001606 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001607 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001608 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
f4f051e2005-04-17 15:02:26 -05001610 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611}
1612
1613/**************************************************************************
1614* qla2xxx_eh_host_reset
1615*
1616* Description:
1617* The reset function will reset the Adapter.
1618*
1619* Input:
1620* cmd = Linux SCSI command packet of the command that cause the
1621* adapter reset.
1622*
1623* Returns:
1624* Either SUCCESS or FAILED.
1625*
1626* Note:
1627**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001628static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1630{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001631 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001632 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001633 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001634 unsigned int id;
1635 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001636 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Sawan Chandaka4655372016-07-06 11:14:32 -04001638 if (qla2x00_isp_reg_stat(ha)) {
1639 ql_log(ql_log_info, vha, 0x8041,
1640 "PCI/Register disconnect, exiting.\n");
1641 schedule_work(&ha->board_disable);
1642 return SUCCESS;
1643 }
1644
f4f051e2005-04-17 15:02:26 -05001645 id = cmd->device->id;
1646 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001647
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001648 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001649 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Chad Dupuis63ee7072014-04-11 16:54:46 -04001651 /*
1652 * No point in issuing another reset if one is active. Also do not
1653 * attempt a reset if we are updating flash.
1654 */
1655 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001656 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001658 if (vha != base_vha) {
1659 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001660 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001661 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001662 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001663 if (!qla82xx_fcoe_ctx_reset(vha)) {
1664 /* Ctx reset success */
1665 ret = SUCCESS;
1666 goto eh_host_reset_lock;
1667 }
1668 /* fall thru if ctx reset failed */
1669 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001670 if (ha->wq)
1671 flush_workqueue(ha->wq);
1672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001673 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001674 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001675 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1676 /* failed. schedule dpc to try */
1677 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1678
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001679 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1680 ql_log(ql_log_warn, vha, 0x802a,
1681 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001682 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001683 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001684 }
1685 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001688 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001689 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001690 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001691 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
f4f051e2005-04-17 15:02:26 -05001693eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001694 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001695 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001696 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
f4f051e2005-04-17 15:02:26 -05001698 return ret;
1699}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
1701/*
1702* qla2x00_loop_reset
1703* Issue loop reset.
1704*
1705* Input:
1706* ha = adapter block pointer.
1707*
1708* Returns:
1709* 0 = success
1710*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001711int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001712qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001714 int ret;
bdf79622005-04-17 15:06:53 -05001715 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Armen Baloyan58547712013-08-27 01:37:33 -04001718 if (IS_QLAFX00(ha)) {
1719 return qlafx00_loop_reset(vha);
1720 }
1721
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001722 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001723 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1724 if (fcport->port_type != FCT_TARGET)
1725 continue;
1726
1727 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1728 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001729 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001730 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001731 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001732 }
1733 }
1734 }
1735
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001736
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001737 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001738 atomic_set(&vha->loop_state, LOOP_DOWN);
1739 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1740 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001741 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001742 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001743 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1744 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 }
1747
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001748 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001749 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001750 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001751 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1752 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001753 }
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001758 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759}
1760
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001761static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1762 unsigned long *flags)
1763 __releases(qp->qp_lock_ptr)
1764 __acquires(qp->qp_lock_ptr)
1765{
1766 scsi_qla_host_t *vha = qp->vha;
1767 struct qla_hw_data *ha = vha->hw;
1768
1769 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS) {
1770 if (!sp_get(sp)) {
1771 /* got sp */
1772 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1773 qla_nvme_abort(ha, sp, res);
1774 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1775 }
1776 } else if (GET_CMD_SP(sp) && !ha->flags.eeh_busy &&
1777 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1778 !qla2x00_isp_reg_stat(ha) && sp->type == SRB_SCSI_CMD) {
1779 /*
1780 * Don't abort commands in adapter during EEH recovery as it's
1781 * not accessible/responding.
1782 *
1783 * Get a reference to the sp and drop the lock. The reference
1784 * ensures this sp->done() call and not the call in
1785 * qla2xxx_eh_abort() ends the SCSI cmd (with result 'res').
1786 */
1787 if (!sp_get(sp)) {
Linus Torvalds938edb82018-12-28 14:48:06 -08001788 int status;
1789
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001790 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
Linus Torvalds938edb82018-12-28 14:48:06 -08001791 status = qla2xxx_eh_abort(GET_CMD_SP(sp));
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001792 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
Linus Torvalds938edb82018-12-28 14:48:06 -08001793 /*
1794 * Get rid of extra reference caused
1795 * by early exit from qla2xxx_eh_abort
1796 */
1797 if (status == FAST_IO_FAIL)
1798 atomic_dec(&sp->ref_count);
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001799 }
1800 }
1801 sp->done(sp, res);
1802}
1803
Quinn Tranbbead492017-12-28 12:33:13 -08001804static void
1805__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001806{
Bart Van Asscheeb023222018-10-18 15:45:44 -07001807 int cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001808 unsigned long flags;
1809 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001810 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001811 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001812 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001813 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1814 struct qla_tgt_cmd *cmd;
Arun Easic0cb4492014-09-25 06:14:51 -04001815
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001816 if (!ha->req_q_map)
1817 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001818 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1819 req = qp->req;
1820 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1821 sp = req->outstanding_cmds[cnt];
1822 if (sp) {
1823 req->outstanding_cmds[cnt] = NULL;
Quinn Tran6b0431d2018-09-04 14:19:13 -07001824 switch (sp->cmd_type) {
1825 case TYPE_SRB:
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001826 qla2x00_abort_srb(qp, sp, res, &flags);
Quinn Tran585def92018-09-04 14:19:20 -07001827 break;
1828 case TYPE_TGT_CMD:
Quinn Tranbbead492017-12-28 12:33:13 -08001829 if (!vha->hw->tgt.tgt_ops || !tgt ||
1830 qla_ini_mode_enabled(vha)) {
Quinn Tran585def92018-09-04 14:19:20 -07001831 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1832 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1833 vha->dpc_flags);
Quinn Tranbbead492017-12-28 12:33:13 -08001834 continue;
1835 }
1836 cmd = (struct qla_tgt_cmd *)sp;
1837 qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001838 break;
1839 case TYPE_TGT_TMCMD:
1840 /*
1841 * Currently, only ABTS response gets on the
1842 * outstanding_cmds[]
1843 */
1844 ha->tgt.tgt_ops->free_mcmd(
1845 (struct qla_tgt_mgmt_cmd *)sp);
1846 break;
1847 default:
1848 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001849 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001850 }
1851 }
Quinn Tranbbead492017-12-28 12:33:13 -08001852 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1853}
1854
1855void
1856qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1857{
1858 int que;
1859 struct qla_hw_data *ha = vha->hw;
1860
1861 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1862
1863 for (que = 0; que < ha->max_qpairs; que++) {
1864 if (!ha->queue_pair_map[que])
1865 continue;
1866
1867 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1868 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001869}
1870
f4f051e2005-04-17 15:02:26 -05001871static int
1872qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
bdf79622005-04-17 15:06:53 -05001874 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001876 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001877 return -ENXIO;
1878
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001879 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001880
1881 return 0;
1882}
1883
1884static int
1885qla2xxx_slave_configure(struct scsi_device *sdev)
1886{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001888 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001889
Arun Easi9e522cd2012-08-22 14:21:31 -04001890 if (IS_T10_PI_CAPABLE(vha->hw))
1891 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1892
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001893 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001894 return 0;
1895}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
f4f051e2005-04-17 15:02:26 -05001897static void
1898qla2xxx_slave_destroy(struct scsi_device *sdev)
1899{
1900 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
1903/**
1904 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1905 * @ha: HA context
1906 *
1907 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1908 * supported addressing method.
1909 */
1910static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001911qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001913 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
Yang Hongyang6a355282009-04-06 19:01:13 -07001916 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001917 /* Any upper-dword bits set? */
1918 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001919 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001920 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001922 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1923 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001924 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001927
Yang Hongyang284901a2009-04-06 19:01:15 -07001928 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1929 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930}
1931
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001932static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001933qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001934{
1935 unsigned long flags = 0;
1936 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1937
1938 spin_lock_irqsave(&ha->hardware_lock, flags);
1939 ha->interrupts_on = 1;
1940 /* enable risc and host interrupts */
1941 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1942 RD_REG_WORD(&reg->ictrl);
1943 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1944
1945}
1946
1947static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001948qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001949{
1950 unsigned long flags = 0;
1951 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1952
1953 spin_lock_irqsave(&ha->hardware_lock, flags);
1954 ha->interrupts_on = 0;
1955 /* disable risc and host interrupts */
1956 WRT_REG_WORD(&reg->ictrl, 0);
1957 RD_REG_WORD(&reg->ictrl);
1958 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1959}
1960
1961static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001963{
1964 unsigned long flags = 0;
1965 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1966
1967 spin_lock_irqsave(&ha->hardware_lock, flags);
1968 ha->interrupts_on = 1;
1969 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1970 RD_REG_DWORD(&reg->ictrl);
1971 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1972}
1973
1974static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001975qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001976{
1977 unsigned long flags = 0;
1978 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1979
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001980 if (IS_NOPOLLING_TYPE(ha))
1981 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001982 spin_lock_irqsave(&ha->hardware_lock, flags);
1983 ha->interrupts_on = 0;
1984 WRT_REG_DWORD(&reg->ictrl, 0);
1985 RD_REG_DWORD(&reg->ictrl);
1986 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1987}
1988
Giridhar Malavali706f4572011-11-18 09:03:16 -08001989static int
1990qla2x00_iospace_config(struct qla_hw_data *ha)
1991{
1992 resource_size_t pio;
1993 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08001994
Giridhar Malavali706f4572011-11-18 09:03:16 -08001995 if (pci_request_selected_regions(ha->pdev, ha->bars,
1996 QLA2XXX_DRIVER_NAME)) {
1997 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1998 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1999 pci_name(ha->pdev));
2000 goto iospace_error_exit;
2001 }
2002 if (!(ha->bars & 1))
2003 goto skip_pio;
2004
2005 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
2006 pio = pci_resource_start(ha->pdev, 0);
2007 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
2008 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2009 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
2010 "Invalid pci I/O region size (%s).\n",
2011 pci_name(ha->pdev));
2012 pio = 0;
2013 }
2014 } else {
2015 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
2016 "Region #0 no a PIO resource (%s).\n",
2017 pci_name(ha->pdev));
2018 pio = 0;
2019 }
2020 ha->pio_address = pio;
2021 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2022 "PIO address=%llu.\n",
2023 (unsigned long long)ha->pio_address);
2024
2025skip_pio:
2026 /* Use MMIO operations for all accesses. */
2027 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2028 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2029 "Region #1 not an MMIO resource (%s), aborting.\n",
2030 pci_name(ha->pdev));
2031 goto iospace_error_exit;
2032 }
2033 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2034 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2035 "Invalid PCI mem region size (%s), aborting.\n",
2036 pci_name(ha->pdev));
2037 goto iospace_error_exit;
2038 }
2039
2040 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2041 if (!ha->iobase) {
2042 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2043 "Cannot remap MMIO (%s), aborting.\n",
2044 pci_name(ha->pdev));
2045 goto iospace_error_exit;
2046 }
2047
2048 /* Determine queue resources */
2049 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002050 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002051 if (!ql2xmqsupport || !ql2xnvmeenable ||
2052 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08002053 goto mqiobase_exit;
2054
2055 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2056 pci_resource_len(ha->pdev, 3));
2057 if (ha->mqiobase) {
2058 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2059 "MQIO Base=%p.\n", ha->mqiobase);
2060 /* Read MSIX vector size of the board */
2061 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002062 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002063 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002064 /* MB interrupt uses 1 vector */
2065 ha->max_req_queues = ha->msix_count - 1;
2066 ha->max_rsp_queues = ha->max_req_queues;
2067 /* Queue pairs is the max value minus the base queue pair */
2068 ha->max_qpairs = ha->max_rsp_queues - 1;
2069 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2070 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2071
Giridhar Malavali706f4572011-11-18 09:03:16 -08002072 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002073 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002074 } else
2075 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2076 "BAR 3 not enabled.\n");
2077
2078mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002079 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002080 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002081 return (0);
2082
2083iospace_error_exit:
2084 return (-ENOMEM);
2085}
2086
2087
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002088static int
2089qla83xx_iospace_config(struct qla_hw_data *ha)
2090{
2091 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002092
2093 if (pci_request_selected_regions(ha->pdev, ha->bars,
2094 QLA2XXX_DRIVER_NAME)) {
2095 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2096 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2097 pci_name(ha->pdev));
2098
2099 goto iospace_error_exit;
2100 }
2101
2102 /* Use MMIO operations for all accesses. */
2103 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2104 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2105 "Invalid pci I/O region size (%s).\n",
2106 pci_name(ha->pdev));
2107 goto iospace_error_exit;
2108 }
2109 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2110 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2111 "Invalid PCI mem region size (%s), aborting\n",
2112 pci_name(ha->pdev));
2113 goto iospace_error_exit;
2114 }
2115
2116 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2117 if (!ha->iobase) {
2118 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2119 "Cannot remap MMIO (%s), aborting.\n",
2120 pci_name(ha->pdev));
2121 goto iospace_error_exit;
2122 }
2123
2124 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2125 /* 83XX 26XX always use MQ type access for queues
2126 * - mbar 2, a.k.a region 4 */
2127 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002128 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002129 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2130 pci_resource_len(ha->pdev, 4));
2131
2132 if (!ha->mqiobase) {
2133 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2134 "BAR2/region4 not enabled\n");
2135 goto mqiobase_exit;
2136 }
2137
2138 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2139 pci_resource_len(ha->pdev, 2));
2140 if (ha->msixbase) {
2141 /* Read MSIX vector size of the board */
2142 pci_read_config_word(ha->pdev,
2143 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002144 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002145 /*
2146 * By default, driver uses at least two msix vectors
2147 * (default & rspq)
2148 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002149 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002150 /* MB interrupt uses 1 vector */
2151 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002152
2153 /* ATIOQ needs 1 vector. That's 1 less QPair */
2154 if (QLA_TGT_MODE_ENABLED())
2155 ha->max_req_queues--;
2156
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002157 ha->max_rsp_queues = ha->max_req_queues;
2158
Michael Hernandezd7459522016-12-12 14:40:07 -08002159 /* Queue pairs is the max value minus
2160 * the base queue pair */
2161 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002162 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002163 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002164 }
2165 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002166 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002167 } else
2168 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2169 "BAR 1 not enabled.\n");
2170
2171mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002172 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002173 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002174 return 0;
2175
2176iospace_error_exit:
2177 return -ENOMEM;
2178}
2179
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002180static struct isp_operations qla2100_isp_ops = {
2181 .pci_config = qla2100_pci_config,
2182 .reset_chip = qla2x00_reset_chip,
2183 .chip_diag = qla2x00_chip_diag,
2184 .config_rings = qla2x00_config_rings,
2185 .reset_adapter = qla2x00_reset_adapter,
2186 .nvram_config = qla2x00_nvram_config,
2187 .update_fw_options = qla2x00_update_fw_options,
2188 .load_risc = qla2x00_load_risc,
2189 .pci_info_str = qla2x00_pci_info_str,
2190 .fw_version_str = qla2x00_fw_version_str,
2191 .intr_handler = qla2100_intr_handler,
2192 .enable_intrs = qla2x00_enable_intrs,
2193 .disable_intrs = qla2x00_disable_intrs,
2194 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002195 .target_reset = qla2x00_abort_target,
2196 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002197 .fabric_login = qla2x00_login_fabric,
2198 .fabric_logout = qla2x00_fabric_logout,
2199 .calc_req_entries = qla2x00_calc_iocbs_32,
2200 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2201 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2202 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2203 .read_nvram = qla2x00_read_nvram_data,
2204 .write_nvram = qla2x00_write_nvram_data,
2205 .fw_dump = qla2100_fw_dump,
2206 .beacon_on = NULL,
2207 .beacon_off = NULL,
2208 .beacon_blink = NULL,
2209 .read_optrom = qla2x00_read_optrom_data,
2210 .write_optrom = qla2x00_write_optrom_data,
2211 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002212 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002213 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002214 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002215 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002216 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002217};
2218
2219static struct isp_operations qla2300_isp_ops = {
2220 .pci_config = qla2300_pci_config,
2221 .reset_chip = qla2x00_reset_chip,
2222 .chip_diag = qla2x00_chip_diag,
2223 .config_rings = qla2x00_config_rings,
2224 .reset_adapter = qla2x00_reset_adapter,
2225 .nvram_config = qla2x00_nvram_config,
2226 .update_fw_options = qla2x00_update_fw_options,
2227 .load_risc = qla2x00_load_risc,
2228 .pci_info_str = qla2x00_pci_info_str,
2229 .fw_version_str = qla2x00_fw_version_str,
2230 .intr_handler = qla2300_intr_handler,
2231 .enable_intrs = qla2x00_enable_intrs,
2232 .disable_intrs = qla2x00_disable_intrs,
2233 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002234 .target_reset = qla2x00_abort_target,
2235 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002236 .fabric_login = qla2x00_login_fabric,
2237 .fabric_logout = qla2x00_fabric_logout,
2238 .calc_req_entries = qla2x00_calc_iocbs_32,
2239 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2240 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2241 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2242 .read_nvram = qla2x00_read_nvram_data,
2243 .write_nvram = qla2x00_write_nvram_data,
2244 .fw_dump = qla2300_fw_dump,
2245 .beacon_on = qla2x00_beacon_on,
2246 .beacon_off = qla2x00_beacon_off,
2247 .beacon_blink = qla2x00_beacon_blink,
2248 .read_optrom = qla2x00_read_optrom_data,
2249 .write_optrom = qla2x00_write_optrom_data,
2250 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002251 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002252 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002253 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002254 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002255 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002256};
2257
2258static struct isp_operations qla24xx_isp_ops = {
2259 .pci_config = qla24xx_pci_config,
2260 .reset_chip = qla24xx_reset_chip,
2261 .chip_diag = qla24xx_chip_diag,
2262 .config_rings = qla24xx_config_rings,
2263 .reset_adapter = qla24xx_reset_adapter,
2264 .nvram_config = qla24xx_nvram_config,
2265 .update_fw_options = qla24xx_update_fw_options,
2266 .load_risc = qla24xx_load_risc,
2267 .pci_info_str = qla24xx_pci_info_str,
2268 .fw_version_str = qla24xx_fw_version_str,
2269 .intr_handler = qla24xx_intr_handler,
2270 .enable_intrs = qla24xx_enable_intrs,
2271 .disable_intrs = qla24xx_disable_intrs,
2272 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002273 .target_reset = qla24xx_abort_target,
2274 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002275 .fabric_login = qla24xx_login_fabric,
2276 .fabric_logout = qla24xx_fabric_logout,
2277 .calc_req_entries = NULL,
2278 .build_iocbs = NULL,
2279 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2280 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2281 .read_nvram = qla24xx_read_nvram_data,
2282 .write_nvram = qla24xx_write_nvram_data,
2283 .fw_dump = qla24xx_fw_dump,
2284 .beacon_on = qla24xx_beacon_on,
2285 .beacon_off = qla24xx_beacon_off,
2286 .beacon_blink = qla24xx_beacon_blink,
2287 .read_optrom = qla24xx_read_optrom_data,
2288 .write_optrom = qla24xx_write_optrom_data,
2289 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002291 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002292 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002293 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002294 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002295};
2296
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002297static struct isp_operations qla25xx_isp_ops = {
2298 .pci_config = qla25xx_pci_config,
2299 .reset_chip = qla24xx_reset_chip,
2300 .chip_diag = qla24xx_chip_diag,
2301 .config_rings = qla24xx_config_rings,
2302 .reset_adapter = qla24xx_reset_adapter,
2303 .nvram_config = qla24xx_nvram_config,
2304 .update_fw_options = qla24xx_update_fw_options,
2305 .load_risc = qla24xx_load_risc,
2306 .pci_info_str = qla24xx_pci_info_str,
2307 .fw_version_str = qla24xx_fw_version_str,
2308 .intr_handler = qla24xx_intr_handler,
2309 .enable_intrs = qla24xx_enable_intrs,
2310 .disable_intrs = qla24xx_disable_intrs,
2311 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002312 .target_reset = qla24xx_abort_target,
2313 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002314 .fabric_login = qla24xx_login_fabric,
2315 .fabric_logout = qla24xx_fabric_logout,
2316 .calc_req_entries = NULL,
2317 .build_iocbs = NULL,
2318 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2319 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2320 .read_nvram = qla25xx_read_nvram_data,
2321 .write_nvram = qla25xx_write_nvram_data,
2322 .fw_dump = qla25xx_fw_dump,
2323 .beacon_on = qla24xx_beacon_on,
2324 .beacon_off = qla24xx_beacon_off,
2325 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002326 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002327 .write_optrom = qla24xx_write_optrom_data,
2328 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002329 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002330 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002331 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002332 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002333 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002334};
2335
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002336static struct isp_operations qla81xx_isp_ops = {
2337 .pci_config = qla25xx_pci_config,
2338 .reset_chip = qla24xx_reset_chip,
2339 .chip_diag = qla24xx_chip_diag,
2340 .config_rings = qla24xx_config_rings,
2341 .reset_adapter = qla24xx_reset_adapter,
2342 .nvram_config = qla81xx_nvram_config,
2343 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002344 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002345 .pci_info_str = qla24xx_pci_info_str,
2346 .fw_version_str = qla24xx_fw_version_str,
2347 .intr_handler = qla24xx_intr_handler,
2348 .enable_intrs = qla24xx_enable_intrs,
2349 .disable_intrs = qla24xx_disable_intrs,
2350 .abort_command = qla24xx_abort_command,
2351 .target_reset = qla24xx_abort_target,
2352 .lun_reset = qla24xx_lun_reset,
2353 .fabric_login = qla24xx_login_fabric,
2354 .fabric_logout = qla24xx_fabric_logout,
2355 .calc_req_entries = NULL,
2356 .build_iocbs = NULL,
2357 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2358 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002359 .read_nvram = NULL,
2360 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002361 .fw_dump = qla81xx_fw_dump,
2362 .beacon_on = qla24xx_beacon_on,
2363 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002364 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002365 .read_optrom = qla25xx_read_optrom_data,
2366 .write_optrom = qla24xx_write_optrom_data,
2367 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002368 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002369 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002370 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002371 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002372 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002373};
2374
2375static struct isp_operations qla82xx_isp_ops = {
2376 .pci_config = qla82xx_pci_config,
2377 .reset_chip = qla82xx_reset_chip,
2378 .chip_diag = qla24xx_chip_diag,
2379 .config_rings = qla82xx_config_rings,
2380 .reset_adapter = qla24xx_reset_adapter,
2381 .nvram_config = qla81xx_nvram_config,
2382 .update_fw_options = qla24xx_update_fw_options,
2383 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002384 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002385 .fw_version_str = qla24xx_fw_version_str,
2386 .intr_handler = qla82xx_intr_handler,
2387 .enable_intrs = qla82xx_enable_intrs,
2388 .disable_intrs = qla82xx_disable_intrs,
2389 .abort_command = qla24xx_abort_command,
2390 .target_reset = qla24xx_abort_target,
2391 .lun_reset = qla24xx_lun_reset,
2392 .fabric_login = qla24xx_login_fabric,
2393 .fabric_logout = qla24xx_fabric_logout,
2394 .calc_req_entries = NULL,
2395 .build_iocbs = NULL,
2396 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2397 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2398 .read_nvram = qla24xx_read_nvram_data,
2399 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002400 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002401 .beacon_on = qla82xx_beacon_on,
2402 .beacon_off = qla82xx_beacon_off,
2403 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002404 .read_optrom = qla82xx_read_optrom_data,
2405 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002406 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002407 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002408 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002409 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002410 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002411 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002412};
2413
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002414static struct isp_operations qla8044_isp_ops = {
2415 .pci_config = qla82xx_pci_config,
2416 .reset_chip = qla82xx_reset_chip,
2417 .chip_diag = qla24xx_chip_diag,
2418 .config_rings = qla82xx_config_rings,
2419 .reset_adapter = qla24xx_reset_adapter,
2420 .nvram_config = qla81xx_nvram_config,
2421 .update_fw_options = qla24xx_update_fw_options,
2422 .load_risc = qla82xx_load_risc,
2423 .pci_info_str = qla24xx_pci_info_str,
2424 .fw_version_str = qla24xx_fw_version_str,
2425 .intr_handler = qla8044_intr_handler,
2426 .enable_intrs = qla82xx_enable_intrs,
2427 .disable_intrs = qla82xx_disable_intrs,
2428 .abort_command = qla24xx_abort_command,
2429 .target_reset = qla24xx_abort_target,
2430 .lun_reset = qla24xx_lun_reset,
2431 .fabric_login = qla24xx_login_fabric,
2432 .fabric_logout = qla24xx_fabric_logout,
2433 .calc_req_entries = NULL,
2434 .build_iocbs = NULL,
2435 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2436 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2437 .read_nvram = NULL,
2438 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002439 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002440 .beacon_on = qla82xx_beacon_on,
2441 .beacon_off = qla82xx_beacon_off,
2442 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002443 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002444 .write_optrom = qla8044_write_optrom_data,
2445 .get_flash_version = qla82xx_get_flash_version,
2446 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002447 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002448 .abort_isp = qla8044_abort_isp,
2449 .iospace_config = qla82xx_iospace_config,
2450 .initialize_adapter = qla2x00_initialize_adapter,
2451};
2452
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002453static struct isp_operations qla83xx_isp_ops = {
2454 .pci_config = qla25xx_pci_config,
2455 .reset_chip = qla24xx_reset_chip,
2456 .chip_diag = qla24xx_chip_diag,
2457 .config_rings = qla24xx_config_rings,
2458 .reset_adapter = qla24xx_reset_adapter,
2459 .nvram_config = qla81xx_nvram_config,
2460 .update_fw_options = qla81xx_update_fw_options,
2461 .load_risc = qla81xx_load_risc,
2462 .pci_info_str = qla24xx_pci_info_str,
2463 .fw_version_str = qla24xx_fw_version_str,
2464 .intr_handler = qla24xx_intr_handler,
2465 .enable_intrs = qla24xx_enable_intrs,
2466 .disable_intrs = qla24xx_disable_intrs,
2467 .abort_command = qla24xx_abort_command,
2468 .target_reset = qla24xx_abort_target,
2469 .lun_reset = qla24xx_lun_reset,
2470 .fabric_login = qla24xx_login_fabric,
2471 .fabric_logout = qla24xx_fabric_logout,
2472 .calc_req_entries = NULL,
2473 .build_iocbs = NULL,
2474 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2475 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2476 .read_nvram = NULL,
2477 .write_nvram = NULL,
2478 .fw_dump = qla83xx_fw_dump,
2479 .beacon_on = qla24xx_beacon_on,
2480 .beacon_off = qla24xx_beacon_off,
2481 .beacon_blink = qla83xx_beacon_blink,
2482 .read_optrom = qla25xx_read_optrom_data,
2483 .write_optrom = qla24xx_write_optrom_data,
2484 .get_flash_version = qla24xx_get_flash_version,
2485 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002486 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002487 .abort_isp = qla2x00_abort_isp,
2488 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002489 .initialize_adapter = qla2x00_initialize_adapter,
2490};
2491
2492static struct isp_operations qlafx00_isp_ops = {
2493 .pci_config = qlafx00_pci_config,
2494 .reset_chip = qlafx00_soft_reset,
2495 .chip_diag = qlafx00_chip_diag,
2496 .config_rings = qlafx00_config_rings,
2497 .reset_adapter = qlafx00_soft_reset,
2498 .nvram_config = NULL,
2499 .update_fw_options = NULL,
2500 .load_risc = NULL,
2501 .pci_info_str = qlafx00_pci_info_str,
2502 .fw_version_str = qlafx00_fw_version_str,
2503 .intr_handler = qlafx00_intr_handler,
2504 .enable_intrs = qlafx00_enable_intrs,
2505 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002506 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002507 .target_reset = qlafx00_abort_target,
2508 .lun_reset = qlafx00_lun_reset,
2509 .fabric_login = NULL,
2510 .fabric_logout = NULL,
2511 .calc_req_entries = NULL,
2512 .build_iocbs = NULL,
2513 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2514 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2515 .read_nvram = qla24xx_read_nvram_data,
2516 .write_nvram = qla24xx_write_nvram_data,
2517 .fw_dump = NULL,
2518 .beacon_on = qla24xx_beacon_on,
2519 .beacon_off = qla24xx_beacon_off,
2520 .beacon_blink = NULL,
2521 .read_optrom = qla24xx_read_optrom_data,
2522 .write_optrom = qla24xx_write_optrom_data,
2523 .get_flash_version = qla24xx_get_flash_version,
2524 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002525 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002526 .abort_isp = qlafx00_abort_isp,
2527 .iospace_config = qlafx00_iospace_config,
2528 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002529};
2530
Chad Dupuisf73cb692014-02-26 04:15:06 -05002531static struct isp_operations qla27xx_isp_ops = {
2532 .pci_config = qla25xx_pci_config,
2533 .reset_chip = qla24xx_reset_chip,
2534 .chip_diag = qla24xx_chip_diag,
2535 .config_rings = qla24xx_config_rings,
2536 .reset_adapter = qla24xx_reset_adapter,
2537 .nvram_config = qla81xx_nvram_config,
2538 .update_fw_options = qla81xx_update_fw_options,
2539 .load_risc = qla81xx_load_risc,
2540 .pci_info_str = qla24xx_pci_info_str,
2541 .fw_version_str = qla24xx_fw_version_str,
2542 .intr_handler = qla24xx_intr_handler,
2543 .enable_intrs = qla24xx_enable_intrs,
2544 .disable_intrs = qla24xx_disable_intrs,
2545 .abort_command = qla24xx_abort_command,
2546 .target_reset = qla24xx_abort_target,
2547 .lun_reset = qla24xx_lun_reset,
2548 .fabric_login = qla24xx_login_fabric,
2549 .fabric_logout = qla24xx_fabric_logout,
2550 .calc_req_entries = NULL,
2551 .build_iocbs = NULL,
2552 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2553 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2554 .read_nvram = NULL,
2555 .write_nvram = NULL,
2556 .fw_dump = qla27xx_fwdump,
2557 .beacon_on = qla24xx_beacon_on,
2558 .beacon_off = qla24xx_beacon_off,
2559 .beacon_blink = qla83xx_beacon_blink,
2560 .read_optrom = qla25xx_read_optrom_data,
2561 .write_optrom = qla24xx_write_optrom_data,
2562 .get_flash_version = qla24xx_get_flash_version,
2563 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002564 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002565 .abort_isp = qla2x00_abort_isp,
2566 .iospace_config = qla83xx_iospace_config,
2567 .initialize_adapter = qla2x00_initialize_adapter,
2568};
2569
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002570static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002571qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002572{
2573 ha->device_type = DT_EXTENDED_IDS;
2574 switch (ha->pdev->device) {
2575 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002576 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002577 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002578 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002579 break;
2580 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002581 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002582 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002583 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002584 break;
2585 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002586 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002587 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002588 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002589 break;
2590 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002591 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002592 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002593 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002594 break;
2595 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002596 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002597 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002598 if (ha->pdev->subsystem_vendor == 0x1028 &&
2599 ha->pdev->subsystem_device == 0x0170)
2600 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002601 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002602 break;
2603 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002604 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002605 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002606 break;
2607 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002608 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002609 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002610 break;
2611 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002612 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002613 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002614 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002615 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002616 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002617 break;
2618 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002619 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002620 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002621 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002622 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002623 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002624 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002625 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002626 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002627 ha->device_type |= DT_ZIO_SUPPORTED;
2628 ha->device_type |= DT_FWI2;
2629 ha->device_type |= DT_IIDMA;
2630 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2631 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002632 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002633 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002634 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002635 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002636 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002637 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002638 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002639 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002640 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002641 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002642 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002643 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002644 ha->device_type |= DT_ZIO_SUPPORTED;
2645 ha->device_type |= DT_FWI2;
2646 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002647 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2648 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002649 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002650 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002651 ha->device_type |= DT_ZIO_SUPPORTED;
2652 ha->device_type |= DT_FWI2;
2653 ha->device_type |= DT_IIDMA;
2654 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2655 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002656 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002657 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002658 ha->device_type |= DT_ZIO_SUPPORTED;
2659 ha->device_type |= DT_FWI2;
2660 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2661 /* Initialize 82XX ISP flags */
2662 qla82xx_init_flags(ha);
2663 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002664 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002665 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002666 ha->device_type |= DT_ZIO_SUPPORTED;
2667 ha->device_type |= DT_FWI2;
2668 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2669 /* Initialize 82XX ISP flags */
2670 qla82xx_init_flags(ha);
2671 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002672 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002673 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002674 ha->device_type |= DT_ZIO_SUPPORTED;
2675 ha->device_type |= DT_FWI2;
2676 ha->device_type |= DT_IIDMA;
2677 ha->device_type |= DT_T10_PI;
2678 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2679 break;
2680 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002681 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002682 ha->device_type |= DT_ZIO_SUPPORTED;
2683 ha->device_type |= DT_FWI2;
2684 ha->device_type |= DT_IIDMA;
2685 ha->device_type |= DT_T10_PI;
2686 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2687 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002688 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002689 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002690 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002691 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002692 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002693 ha->device_type |= DT_ZIO_SUPPORTED;
2694 ha->device_type |= DT_FWI2;
2695 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002696 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002697 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2698 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002699 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002700 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002701 ha->device_type |= DT_ZIO_SUPPORTED;
2702 ha->device_type |= DT_FWI2;
2703 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002704 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002705 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2706 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002707 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002708 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002709 ha->device_type |= DT_ZIO_SUPPORTED;
2710 ha->device_type |= DT_FWI2;
2711 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002712 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002713 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2714 break;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002715 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2716 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2717 ha->isp_type |= DT_ISP2081;
2718 ha->device_type |= DT_ZIO_SUPPORTED;
2719 ha->device_type |= DT_FWI2;
2720 ha->device_type |= DT_IIDMA;
2721 ha->device_type |= DT_T10_PI;
2722 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2723 break;
2724 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2725 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2726 ha->isp_type |= DT_ISP2281;
2727 ha->device_type |= DT_ZIO_SUPPORTED;
2728 ha->device_type |= DT_FWI2;
2729 ha->device_type |= DT_IIDMA;
2730 ha->device_type |= DT_T10_PI;
2731 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2732 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002733 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002734
Giridhar Malavalia9083012010-04-12 17:59:55 -07002735 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002736 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002737 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002738 /* Get adapter physical port no from interrupt pin register. */
2739 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002740 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2741 IS_QLA27XX(ha) || IS_QLA28XX(ha))
Chad Dupuisf73cb692014-02-26 04:15:06 -05002742 ha->port_no--;
2743 else
2744 ha->port_no = !(ha->port_no & 1);
2745 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002746
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002747 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002748 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002749 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002750}
2751
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002752static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002753qla2xxx_scan_start(struct Scsi_Host *shost)
2754{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002755 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002756
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002757 if (vha->hw->flags.running_gold_fw)
2758 return;
2759
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2761 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2762 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2763 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002764}
2765
2766static int
2767qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2768{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002769 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002770
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002771 if (test_bit(UNLOADING, &vha->dpc_flags))
2772 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002773 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002774 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002775 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002776 return 1;
2777
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002778 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002779}
2780
Quinn Tranec7193e2017-03-15 09:48:55 -07002781static void qla2x00_iocb_work_fn(struct work_struct *work)
2782{
2783 struct scsi_qla_host *vha = container_of(work,
2784 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002785 struct qla_hw_data *ha = vha->hw;
2786 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran0aca7782018-09-04 14:19:16 -07002787 int i = 2;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002788 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002789
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002790 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2791 return;
2792
2793 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002794 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002795 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002796 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002797
2798 spin_lock_irqsave(&vha->work_lock, flags);
2799 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2800 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002801}
2802
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803/*
2804 * PCI driver interface
2805 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002806static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002807qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002809 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811 scsi_qla_host_t *base_vha = NULL;
2812 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002813 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002814 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002815 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002816 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002818 struct req_que *req = NULL;
2819 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002820 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002821
Andrew Vasquez285d0322007-10-19 15:59:17 -07002822 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002823 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002824 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2825 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002826 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002827 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2828 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002829 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002830 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002831 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2832 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002833 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002834 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002835 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002836 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002837 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002838 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2839 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2840 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2841 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2842 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002843 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002844 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002845 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2846 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002847 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002848 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2849 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002850
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002851 if (mem_only) {
2852 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002853 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002854 } else {
2855 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002856 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858
Jesse Barnes09276782008-10-18 17:33:19 -07002859 /* This may fail but that's ok */
2860 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002861
Giridhar Malavali5da05a22019-04-02 14:24:24 -07002862 /* Turn off T10-DIF when FC-NVMe is enabled */
2863 if (ql2xnvmeenable)
2864 ql2xenabledif = 0;
2865
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002866 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2867 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002868 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2869 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002870 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002872 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2873 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002874 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002875 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2876 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002877 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002878 spin_lock_init(&ha->tgt.atio_lock);
2879
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002880 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881
2882 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002883 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002884 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002885 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002886 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002887 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002888 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002890 /* Set ISP-type information. */
2891 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002892
2893 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002894 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002895 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002896 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002897
Chad Dupuiscba1e472011-11-18 09:03:21 -08002898 ha->prev_topology = 0;
2899 ha->init_cb_size = sizeof(init_cb_t);
2900 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2901 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002902 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Quinn Tranb2000802018-08-02 13:16:52 -07002903 atomic_set(&ha->num_pend_mbx_stage1, 0);
2904 atomic_set(&ha->num_pend_mbx_stage2, 0);
2905 atomic_set(&ha->num_pend_mbx_stage3, 0);
Quinn Tran8b4673b2018-09-04 14:19:14 -07002906 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2907 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002908
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002909 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002911 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 req_length = REQUEST_ENTRY_CNT_2100;
2914 rsp_length = RESPONSE_ENTRY_CNT_2100;
2915 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002916 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002917 ha->flash_conf_off = ~0;
2918 ha->flash_data_off = ~0;
2919 ha->nvram_conf_off = ~0;
2920 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002921 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002923 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002924 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 req_length = REQUEST_ENTRY_CNT_2200;
2926 rsp_length = RESPONSE_ENTRY_CNT_2100;
2927 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002928 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002929 ha->flash_conf_off = ~0;
2930 ha->flash_data_off = ~0;
2931 ha->nvram_conf_off = ~0;
2932 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002933 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002934 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002935 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002937 req_length = REQUEST_ENTRY_CNT_2200;
2938 rsp_length = RESPONSE_ENTRY_CNT_2300;
2939 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002940 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002941 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2942 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002943 ha->flash_conf_off = ~0;
2944 ha->flash_data_off = ~0;
2945 ha->nvram_conf_off = ~0;
2946 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002947 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002948 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002949 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002950 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 req_length = REQUEST_ENTRY_CNT_24XX;
2952 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002953 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002954 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002955 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002956 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002957 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002958 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002959 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002960 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2961 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2962 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2963 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002964 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002965 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002966 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002967 req_length = REQUEST_ENTRY_CNT_24XX;
2968 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002969 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002971 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002972 ha->gid_list_info_size = 8;
2973 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002974 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002975 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002976 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2977 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2978 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2979 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2980 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002981 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002982 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2983 req_length = REQUEST_ENTRY_CNT_24XX;
2984 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05002985 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002986 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2987 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2988 ha->gid_list_info_size = 8;
2989 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07002990 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002991 ha->isp_ops = &qla81xx_isp_ops;
2992 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2993 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2994 ha->nvram_conf_off = ~0;
2995 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002996 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002997 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002998 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2999 req_length = REQUEST_ENTRY_CNT_82XX;
3000 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3001 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3002 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3003 ha->gid_list_info_size = 8;
3004 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08003005 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003006 ha->isp_ops = &qla82xx_isp_ops;
3007 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3008 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3009 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3010 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003011 } else if (IS_QLA8044(ha)) {
3012 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3013 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3014 req_length = REQUEST_ENTRY_CNT_82XX;
3015 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3016 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3017 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3018 ha->gid_list_info_size = 8;
3019 ha->optrom_size = OPTROM_SIZE_83XX;
3020 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3021 ha->isp_ops = &qla8044_isp_ops;
3022 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3023 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3024 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3025 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003026 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003027 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08003028 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003029 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04003030 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05003031 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05003032 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003033 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3034 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3035 ha->gid_list_info_size = 8;
3036 ha->optrom_size = OPTROM_SIZE_83XX;
3037 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3038 ha->isp_ops = &qla83xx_isp_ops;
3039 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3040 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3041 ha->nvram_conf_off = ~0;
3042 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003043 } else if (IS_QLAFX00(ha)) {
3044 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
3045 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3046 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3047 req_length = REQUEST_ENTRY_CNT_FX00;
3048 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003049 ha->isp_ops = &qlafx00_isp_ops;
3050 ha->port_down_retry_count = 30; /* default value */
3051 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3052 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04003053 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003054 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04003055 ha->mr.host_info_resend = false;
3056 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003057 } else if (IS_QLA27XX(ha)) {
3058 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3059 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3060 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05003061 req_length = REQUEST_ENTRY_CNT_83XX;
3062 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04003063 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003064 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3065 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3066 ha->gid_list_info_size = 8;
3067 ha->optrom_size = OPTROM_SIZE_83XX;
3068 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3069 ha->isp_ops = &qla27xx_isp_ops;
3070 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3071 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3072 ha->nvram_conf_off = ~0;
3073 ha->nvram_data_off = ~0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003074 } else if (IS_QLA28XX(ha)) {
3075 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3076 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3077 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3078 req_length = REQUEST_ENTRY_CNT_24XX;
3079 rsp_length = RESPONSE_ENTRY_CNT_2300;
3080 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3081 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3082 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3083 ha->gid_list_info_size = 8;
3084 ha->optrom_size = OPTROM_SIZE_28XX;
3085 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3086 ha->isp_ops = &qla27xx_isp_ops;
3087 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3088 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3089 ha->nvram_conf_off = ~0;
3090 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003092
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003093 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3094 "mbx_count=%d, req_length=%d, "
3095 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08003096 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3097 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003098 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3099 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08003100 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003101 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3102 "isp_ops=%p, flash_conf_off=%d, "
3103 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3104 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3105 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08003106
3107 /* Configure PCI I/O space */
3108 ret = ha->isp_ops->iospace_config(ha);
3109 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003110 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003111
3112 ql_log_pci(ql_log_info, pdev, 0x001d,
3113 "Found an ISP%04X irq %d iobase 0x%p.\n",
3114 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003115 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003116 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003117 init_completion(&ha->mbx_cmd_comp);
3118 complete(&ha->mbx_cmd_comp);
3119 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003120 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003121 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003123 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
Andrew Vasquez53303c42009-01-22 09:45:37 -08003125 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003126 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3127 "64 Bit addressing is %s.\n",
3128 ha->flags.enable_64bit_addressing ? "enable" :
3129 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003130 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003131 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003132 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3133 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003135 goto probe_hw_failed;
3136 }
3137
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003138 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003139 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003140 req->max_q_depth = ql2xmaxqdepth;
3141
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003142
3143 base_vha = qla2x00_create_host(sht, ha);
3144 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003145 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 }
3148
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003149 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003150 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003153 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003154 if (IS_QLA2XXX_MIDTYPE(ha))
Quinn Tranf6602f32018-08-02 13:16:53 -07003155 base_vha->mgmt_svr_loop_id =
3156 qla2x00_reserve_mgmt_server_loop_id(base_vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003157 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003158 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3159 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003160
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003161 /* Setup fcport template structure. */
3162 ha->mr.fcport.vha = base_vha;
3163 ha->mr.fcport.port_type = FCT_UNKNOWN;
3164 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3165 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3166 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3167 ha->mr.fcport.scan_state = 1;
3168
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003169 /* Set the SG table size based on ISP type */
3170 if (!IS_FWI2_CAPABLE(ha)) {
3171 if (IS_QLA2100(ha))
3172 host->sg_tablesize = 32;
3173 } else {
3174 if (!IS_QLA82XX(ha))
3175 host->sg_tablesize = QLA_SG_ALL;
3176 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003177 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003178 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003179 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003180 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003181 host->max_cmd_len = 32;
3182 else
3183 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003184 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003185 /* Older HBAs support only 16-bit LUNs */
3186 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3187 ql2xmaxlun > 0xffff)
3188 host->max_lun = 0xffff;
3189 else
3190 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003191 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003192 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003193
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003194 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3195 "max_id=%d this_id=%d "
3196 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003197 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003198 host->this_id, host->cmd_per_lun, host->unique_id,
3199 host->max_cmd_len, host->max_channel, host->max_lun,
3200 host->transportt, sht->vendor_id);
3201
Himanshu Madhani1010f212017-10-16 11:26:05 -07003202 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3203
Michael Hernandezd7459522016-12-12 14:40:07 -08003204 /* Set up the irqs */
3205 ret = qla2x00_request_irqs(ha, rsp);
3206 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003207 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003208
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003209 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003210 ret = qla2x00_alloc_queues(ha, req, rsp);
3211 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003212 ql_log(ql_log_fatal, base_vha, 0x003d,
3213 "Failed to allocate memory for queue pointers..."
3214 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003215 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003216 }
3217
Jens Axboef664a3c2018-11-01 16:36:27 -06003218 if (ha->mqenable) {
Michael Hernandez56012362016-12-12 14:40:08 -08003219 /* number of hardware queues supported by blk/scsi-mq*/
3220 host->nr_hw_queues = ha->max_qpairs;
3221
3222 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3223 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003224 } else {
3225 if (ql2xnvmeenable) {
3226 host->nr_hw_queues = ha->max_qpairs;
3227 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3228 "FC-NVMe support is enabled, HW queues=%d\n",
3229 host->nr_hw_queues);
3230 } else {
3231 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3232 "blk/scsi-mq disabled.\n");
3233 }
3234 }
Michael Hernandez56012362016-12-12 14:40:08 -08003235
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003236 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003237
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003238 pci_save_state(pdev);
3239
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003240 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003241 rsp->req = req;
3242 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003243
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003244 if (IS_QLAFX00(ha)) {
3245 ha->rsp_q_map[0] = rsp;
3246 ha->req_q_map[0] = req;
3247 set_bit(0, ha->req_qid_map);
3248 set_bit(0, ha->rsp_qid_map);
3249 }
3250
Andrew Vasquez08029992009-03-24 09:07:55 -07003251 /* FWI2-capable only. */
3252 req->req_q_in = &ha->iobase->isp24.req_q_in;
3253 req->req_q_out = &ha->iobase->isp24.req_q_out;
3254 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3255 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003256 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3257 IS_QLA28XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003258 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3259 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3260 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3261 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003262 }
3263
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003264 if (IS_QLAFX00(ha)) {
3265 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3266 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3267 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3268 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3269 }
3270
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003271 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003272 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3273 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3274 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3275 }
3276
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003277 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3278 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3279 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3280 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3281 "req->req_q_in=%p req->req_q_out=%p "
3282 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3283 req->req_q_in, req->req_q_out,
3284 rsp->rsp_q_in, rsp->rsp_q_out);
3285 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3286 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3287 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3288 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3289 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3290 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291
himanshu.madhani@cavium.comd48cc672018-07-02 13:01:59 -07003292 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3293
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003294 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003295 ql_log(ql_log_fatal, base_vha, 0x00d6,
3296 "Failed to initialize adapter - Adapter flags %x.\n",
3297 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003298
Giridhar Malavalia9083012010-04-12 17:59:55 -07003299 if (IS_QLA82XX(ha)) {
3300 qla82xx_idc_lock(ha);
3301 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003302 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003303 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003304 ql_log(ql_log_fatal, base_vha, 0x00d7,
3305 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003306 } else if (IS_QLA8044(ha)) {
3307 qla8044_idc_lock(ha);
3308 qla8044_wr_direct(base_vha,
3309 QLA8044_CRB_DEV_STATE_INDEX,
3310 QLA8XXX_DEV_FAILED);
3311 qla8044_idc_unlock(ha);
3312 ql_log(ql_log_fatal, base_vha, 0x0150,
3313 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003314 }
3315
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 ret = -ENODEV;
3317 goto probe_failed;
3318 }
3319
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003320 if (IS_QLAFX00(ha))
3321 host->can_queue = QLAFX00_MAX_CANQUEUE;
3322 else
3323 host->can_queue = req->num_outstanding_cmds - 10;
3324
3325 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3326 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3327 host->can_queue, base_vha->req,
3328 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3329
Quinn Trane326d222017-06-13 20:47:18 -07003330 if (ha->mqenable) {
Quinn Trane326d222017-06-13 20:47:18 -07003331 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003332
Jens Axboef664a3c2018-11-01 16:36:27 -06003333 if (QLA_TGT_MODE_ENABLED())
Quinn Trane326d222017-06-13 20:47:18 -07003334 startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003335
Jens Axboef664a3c2018-11-01 16:36:27 -06003336 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
Quinn Trane326d222017-06-13 20:47:18 -07003337 startit = true;
Quinn Trane326d222017-06-13 20:47:18 -07003338
Jens Axboef664a3c2018-11-01 16:36:27 -06003339 /* Create start of day qpairs for Block MQ */
3340 for (i = 0; i < ha->max_qpairs; i++)
3341 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003342 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003343
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003344 if (ha->flags.running_gold_fw)
3345 goto skip_dpc;
3346
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 /*
3348 * Startup the kernel thread for this host adapter
3349 */
3350 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003351 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003352 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003353 ql_log(ql_log_fatal, base_vha, 0x00ed,
3354 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003355 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003356 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003357 goto probe_failed;
3358 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003359 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3360 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003362 /*
3363 * If we're not coming up in initiator mode, we might sit for
3364 * a while without waking up the dpc thread, which leads to a
3365 * stuck process warning. So just kick the dpc once here and
3366 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3367 */
3368 qla2xxx_wake_dpc(base_vha);
3369
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003370 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3371
Saurav Kashyap81178772012-08-22 14:21:04 -04003372 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3373 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3374 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3375 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3376
3377 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3378 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3379 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3380 INIT_WORK(&ha->idc_state_handler,
3381 qla83xx_idc_state_handler_work);
3382 INIT_WORK(&ha->nic_core_unrecoverable,
3383 qla83xx_nic_core_unrecoverable_work);
3384 }
3385
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003386skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 list_add_tail(&base_vha->list, &ha->vp_list);
3388 base_vha->host->irq = ha->pdev->irq;
3389
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003391 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003392 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3393 "Started qla2x00_timer with "
3394 "interval=%d.\n", WATCH_INTERVAL);
3395 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3396 "Detected hba at address=%p.\n",
3397 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398
Arun Easie02587d2011-08-16 11:29:23 -07003399 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003400 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003401 int prot = 0, guard;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07003402
Arun Easibad75002010-05-04 15:01:30 -07003403 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003404 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3405 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003406 if (ql2xenabledif == 1)
3407 prot = SHOST_DIX_TYPE0_PROTECTION;
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003408 if (ql2xprotmask)
3409 scsi_host_set_prot(host, ql2xprotmask);
3410 else
3411 scsi_host_set_prot(host,
3412 prot | SHOST_DIF_TYPE1_PROTECTION
3413 | SHOST_DIF_TYPE2_PROTECTION
3414 | SHOST_DIF_TYPE3_PROTECTION
3415 | SHOST_DIX_TYPE1_PROTECTION
3416 | SHOST_DIX_TYPE2_PROTECTION
3417 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003418
3419 guard = SHOST_DIX_GUARD_CRC;
3420
3421 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3422 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3423 guard |= SHOST_DIX_GUARD_IP;
3424
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003425 if (ql2xprotguard)
3426 scsi_host_set_guard(host, ql2xprotguard);
3427 else
3428 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003429 } else
3430 base_vha->flags.difdix_supported = 0;
3431 }
3432
Giridhar Malavalia9083012010-04-12 17:59:55 -07003433 ha->isp_ops->enable_intrs(ha);
3434
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003435 if (IS_QLAFX00(ha)) {
3436 ret = qlafx00_fx_disc(base_vha,
3437 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3438 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3439 QLA_SG_ALL : 128;
3440 }
3441
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003442 ret = scsi_add_host(host, &pdev->dev);
3443 if (ret)
3444 goto probe_failed;
3445
Michael Reed14864002009-12-02 09:11:16 -06003446 base_vha->flags.init_done = 1;
3447 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003448 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003449
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003450 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3451 "Init done and hba is online.\n");
3452
Quinn Tran726b8542017-01-19 22:28:00 -08003453 if (qla_ini_mode_enabled(base_vha) ||
3454 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003455 scsi_scan_host(host);
3456 else
3457 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3458 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003461
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003462 if (IS_QLAFX00(ha)) {
3463 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003464 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3465
3466 /* Register system information */
3467 ret = qlafx00_fx_disc(base_vha,
3468 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3469 }
3470
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003471 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003472
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003474
Armen Baloyan03eb9122013-10-30 03:38:22 -04003475 ql_log(ql_log_info, base_vha, 0x00fb,
3476 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003477 ql_log(ql_log_info, base_vha, 0x00fc,
3478 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3479 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3480 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3481 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003482 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003484 qlt_add_target(ha, base_vha);
3485
Joe Lawrence6b383972014-08-26 17:12:29 -04003486 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003487
3488 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3489 return -ENODEV;
3490
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003491 if (ha->flags.detected_lr_sfp) {
3492 ql_log(ql_log_info, base_vha, 0xffff,
3493 "Reset chip to pick up LR SFP setting\n");
3494 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3495 qla2xxx_wake_dpc(base_vha);
3496 }
3497
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 return 0;
3499
3500probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003501 if (base_vha->timer_active)
3502 qla2x00_stop_timer(base_vha);
3503 base_vha->flags.online = 0;
3504 if (ha->dpc_thread) {
3505 struct task_struct *t = ha->dpc_thread;
3506
3507 ha->dpc_thread = NULL;
3508 kthread_stop(t);
3509 }
3510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003511 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003512 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003513 /*
3514 * Need to NULL out local req/rsp after
3515 * qla2x00_free_device => qla2x00_free_queues frees
3516 * what these are pointing to. Or else we'll
3517 * fall over below in qla2x00_free_req/rsp_que.
3518 */
3519 req = NULL;
3520 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003523 qla2x00_mem_free(ha);
3524 qla2x00_free_req_que(ha, req);
3525 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003526 qla2x00_clear_drv_active(ha);
3527
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003528iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003529 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003530 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003531 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003532 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003533 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003534 } else {
3535 if (ha->iobase)
3536 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003537 if (ha->cregbase)
3538 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003539 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003540 pci_release_selected_regions(ha->pdev, ha->bars);
3541 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003543disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003544 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003545 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547
Adrian Bunk4c993f72008-01-14 00:55:16 -08003548static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003549qla2x00_shutdown(struct pci_dev *pdev)
3550{
3551 scsi_qla_host_t *vha;
3552 struct qla_hw_data *ha;
3553
3554 vha = pci_get_drvdata(pdev);
3555 ha = vha->hw;
3556
Sawan Chandakefdb5762017-08-23 15:05:00 -07003557 ql_log(ql_log_info, vha, 0xfffa,
3558 "Adapter shutdown\n");
3559
3560 /*
3561 * Prevent future board_disable and wait
3562 * until any pending board_disable has completed.
3563 */
3564 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3565 cancel_work_sync(&ha->board_disable);
3566
3567 if (!atomic_read(&pdev->enable_cnt))
3568 return;
3569
Armen Baloyan42479342013-08-27 01:37:37 -04003570 /* Notify ISPFX00 firmware */
3571 if (IS_QLAFX00(ha))
3572 qlafx00_driver_shutdown(vha, 20);
3573
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003574 /* Turn-off FCE trace */
3575 if (ha->flags.fce_enabled) {
3576 qla2x00_disable_fce_trace(vha, NULL, NULL);
3577 ha->flags.fce_enabled = 0;
3578 }
3579
3580 /* Turn-off EFT trace */
3581 if (ha->eft)
3582 qla2x00_disable_eft_trace(vha);
3583
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003584 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3585 IS_QLA28XX(ha)) {
Quinn Tran3407fc32017-12-28 12:33:11 -08003586 if (ha->flags.fw_started)
3587 qla2x00_abort_isp_cleanup(vha);
3588 } else {
3589 /* Stop currently executing firmware. */
3590 qla2x00_try_to_stop_firmware(vha);
3591 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003592
3593 /* Turn adapter off line */
3594 vha->flags.online = 0;
3595
3596 /* turn-off interrupts on the card */
3597 if (ha->interrupts_on) {
3598 vha->flags.init_done = 0;
3599 ha->isp_ops->disable_intrs(ha);
3600 }
3601
3602 qla2x00_free_irqs(vha);
3603
3604 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003605
Chad Dupuis61d41f62014-09-25 05:17:02 -04003606 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003607 ql_log(ql_log_info, vha, 0xfffe,
3608 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003609}
3610
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003611/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003612static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003613qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003615 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003616 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617
Arun Easi43ebf162011-05-10 11:18:16 -07003618 mutex_lock(&ha->vport_lock);
3619 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003620 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003621
Arun Easi43ebf162011-05-10 11:18:16 -07003622 BUG_ON(base_vha->list.next == &ha->vp_list);
3623 /* This assumes first entry in ha->vp_list is always base vha */
3624 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003625 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003626
Arun Easi43ebf162011-05-10 11:18:16 -07003627 spin_unlock_irqrestore(&ha->vport_slock, flags);
3628 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003629
Himanshu Madhani5e6803b2018-12-10 12:36:23 -08003630 qla_nvme_delete(vha);
3631
Arun Easi43ebf162011-05-10 11:18:16 -07003632 fc_vport_terminate(vha->fc_vport);
3633 scsi_host_put(vha->host);
3634
3635 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003636 }
Arun Easi43ebf162011-05-10 11:18:16 -07003637 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003638}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003639
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003640/* Stops all deferred work threads */
3641static void
3642qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3643{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003644 /* Cancel all work and destroy DPC workqueues */
3645 if (ha->dpc_lp_wq) {
3646 cancel_work_sync(&ha->idc_aen);
3647 destroy_workqueue(ha->dpc_lp_wq);
3648 ha->dpc_lp_wq = NULL;
3649 }
3650
3651 if (ha->dpc_hp_wq) {
3652 cancel_work_sync(&ha->nic_core_reset);
3653 cancel_work_sync(&ha->idc_state_handler);
3654 cancel_work_sync(&ha->nic_core_unrecoverable);
3655 destroy_workqueue(ha->dpc_hp_wq);
3656 ha->dpc_hp_wq = NULL;
3657 }
3658
Andrew Vasquezb9978762009-03-24 09:08:05 -07003659 /* Kill the kernel thread for this host */
3660 if (ha->dpc_thread) {
3661 struct task_struct *t = ha->dpc_thread;
3662
3663 /*
3664 * qla2xxx_wake_dpc checks for ->dpc_thread
3665 * so we need to zero it out.
3666 */
3667 ha->dpc_thread = NULL;
3668 kthread_stop(t);
3669 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003670}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003671
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003672static void
3673qla2x00_unmap_iobases(struct qla_hw_data *ha)
3674{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003675 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003676
Chad Dupuisf73cb692014-02-26 04:15:06 -05003677 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003678 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003679 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003680 } else {
3681 if (ha->iobase)
3682 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003683
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003684 if (ha->cregbase)
3685 iounmap(ha->cregbase);
3686
Giridhar Malavalia9083012010-04-12 17:59:55 -07003687 if (ha->mqiobase)
3688 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003689
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003690 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) &&
3691 ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003692 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003693 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003694}
3695
3696static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003697qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003698{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003699 if (IS_QLA8044(ha)) {
3700 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003701 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003702 qla8044_idc_unlock(ha);
3703 } else if (IS_QLA82XX(ha)) {
3704 qla82xx_idc_lock(ha);
3705 qla82xx_clear_drv_active(ha);
3706 qla82xx_idc_unlock(ha);
3707 }
3708}
3709
3710static void
3711qla2x00_remove_one(struct pci_dev *pdev)
3712{
3713 scsi_qla_host_t *base_vha;
3714 struct qla_hw_data *ha;
3715
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003716 base_vha = pci_get_drvdata(pdev);
3717 ha = base_vha->hw;
Quinn Tran45235022018-07-18 14:29:53 -07003718 ql_log(ql_log_info, base_vha, 0xb079,
3719 "Removing driver\n");
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003720
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003721 /* Indicate device removal to prevent future board_disable and wait
3722 * until any pending board_disable has completed. */
3723 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3724 cancel_work_sync(&ha->board_disable);
3725
3726 /*
3727 * If the PCI device is disabled then there was a PCI-disconnect and
3728 * qla2x00_disable_board_on_pci_error has taken care of most of the
3729 * resources.
3730 */
3731 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003732 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3733 base_vha->gnl.l, base_vha->gnl.ldma);
3734
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003735 scsi_host_put(base_vha->host);
3736 kfree(ha);
3737 pci_set_drvdata(pdev, NULL);
3738 return;
3739 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003740 qla2x00_wait_for_hba_ready(base_vha);
3741
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003742 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3743 IS_QLA28XX(ha)) {
Quinn Tran45235022018-07-18 14:29:53 -07003744 if (ha->flags.fw_started)
3745 qla2x00_abort_isp_cleanup(base_vha);
3746 } else if (!IS_QLAFX00(ha)) {
3747 if (IS_QLA8031(ha)) {
3748 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3749 "Clearing fcoe driver presence.\n");
3750 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3751 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3752 "Error while clearing DRV-Presence.\n");
3753 }
3754
3755 qla2x00_try_to_stop_firmware(base_vha);
3756 }
3757
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003758 qla2x00_wait_for_sess_deletion(base_vha);
3759
Quinn Tran726b8542017-01-19 22:28:00 -08003760 /*
3761 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003762 * where it was set first.
3763 */
3764 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3765 return;
3766
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003767 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003768
3769 qla_nvme_delete(base_vha);
3770
Quinn Tran726b8542017-01-19 22:28:00 -08003771 dma_free_coherent(&ha->pdev->dev,
3772 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003773
Quinn Trana4239942017-12-28 12:33:26 -08003774 vfree(base_vha->scan.l);
3775
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003776 if (IS_QLAFX00(ha))
3777 qlafx00_driver_shutdown(base_vha, 20);
3778
3779 qla2x00_delete_all_vps(ha, base_vha);
3780
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003781 qla2x00_dfs_remove(base_vha);
3782
3783 qla84xx_put_chip(base_vha);
3784
3785 /* Disable timer */
3786 if (base_vha->timer_active)
3787 qla2x00_stop_timer(base_vha);
3788
3789 base_vha->flags.online = 0;
3790
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003791 /* free DMA memory */
3792 if (ha->exlogin_buf)
3793 qla2x00_free_exlogin_buffer(ha);
3794
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003795 /* free DMA memory */
3796 if (ha->exchoffld_buf)
3797 qla2x00_free_exchoffld_buffer(ha);
3798
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003799 qla2x00_destroy_deferred_work(ha);
3800
3801 qlt_remove_target(ha, base_vha);
3802
3803 qla2x00_free_sysfs_attr(base_vha, true);
3804
3805 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003806 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003807
3808 scsi_remove_host(base_vha->host);
3809
3810 qla2x00_free_device(base_vha);
3811
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003812 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003813
Arun Easid2749ff2014-09-25 05:16:51 -04003814 scsi_host_put(base_vha->host);
3815
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003816 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003817
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003818 pci_release_selected_regions(ha->pdev, ha->bars);
3819 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003821 pci_disable_pcie_error_reporting(pdev);
3822
Bernhard Walle665db932007-03-28 00:49:49 +02003823 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825
3826static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003827qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003829 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830
Andrew Vasquez85880802009-12-15 21:29:46 -08003831 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3832
3833 /* Disable timer */
3834 if (vha->timer_active)
3835 qla2x00_stop_timer(vha);
3836
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003837 qla25xx_delete_queues(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003838 vha->flags.online = 0;
3839
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003840 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003841 if (ha->interrupts_on) {
3842 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003843 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003844 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003845
Quinn Tran093df732016-12-12 14:40:09 -08003846 qla2x00_free_fcports(vha);
3847
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003848 qla2x00_free_irqs(vha);
3849
Quinn Tran093df732016-12-12 14:40:09 -08003850 /* Flush the work queue and remove it */
3851 if (ha->wq) {
3852 flush_workqueue(ha->wq);
3853 destroy_workqueue(ha->wq);
3854 ha->wq = NULL;
3855 }
3856
Chad Dupuis88670482010-07-23 15:28:30 +05003857
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003858 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003859
Giridhar Malavali08de2842011-08-16 11:31:44 -07003860 qla82xx_md_free(vha);
3861
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003862 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863}
3864
Chad Dupuis88670482010-07-23 15:28:30 +05003865void qla2x00_free_fcports(struct scsi_qla_host *vha)
3866{
3867 fc_port_t *fcport, *tfcport;
3868
Quinn Tranffbc6472019-04-02 14:24:29 -07003869 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list)
3870 qla2x00_free_fcport(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003871}
3872
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003873static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003874qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003875 int defer)
3876{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003877 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003878 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003879 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003880
3881 if (!fcport->rport)
3882 return;
3883
3884 rport = fcport->rport;
3885 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003886 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003887 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003888 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003889 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003890 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003891 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3892 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003893 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003894 int now;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07003895
Quinn Tran726b8542017-01-19 22:28:00 -08003896 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003897 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3898 "%s %8phN. rport %p roles %x\n",
3899 __func__, fcport->port_name, rport,
3900 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003901 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003902 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003903 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003904 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003905}
3906
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3909 *
3910 * Input: ha = adapter block pointer. fcport = port structure pointer.
3911 *
3912 * Return: None.
3913 *
3914 * Context:
3915 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003916void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003917 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003919 if (IS_QLAFX00(vha->hw)) {
3920 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3921 qla2x00_schedule_rport_del(vha, fcport, defer);
3922 return;
3923 }
3924
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003925 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003926 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003927 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003928 qla2x00_schedule_rport_del(vha, fcport, defer);
3929 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003930 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 * We may need to retry the login, so don't change the state of the
3932 * port but do the retries.
3933 */
3934 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003935 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936
3937 if (!do_login)
3938 return;
3939
Arun Easia1d02852015-08-04 13:38:02 -04003940 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941}
3942
3943/*
3944 * qla2x00_mark_all_devices_lost
3945 * Updates fcport state when device goes offline.
3946 *
3947 * Input:
3948 * ha = adapter block pointer.
3949 * fcport = port structure pointer.
3950 *
3951 * Return:
3952 * None.
3953 *
3954 * Context:
3955 */
3956void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003957qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958{
3959 fc_port_t *fcport;
3960
Quinn Tran83548fe2017-06-02 09:12:01 -07003961 ql_dbg(ql_dbg_disc, vha, 0x20f1,
3962 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08003963
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003964 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08003965 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08003966 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08003967
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003968 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003970
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 /*
3972 * No point in marking the device as lost, if the device is
3973 * already DEAD.
3974 */
3975 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
3976 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003977 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003978 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003979 if (defer)
3980 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003981 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07003982 qla2x00_schedule_rport_del(vha, fcport, defer);
3983 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 }
3985}
3986
Bart Van Assche0e145a52019-04-17 14:44:12 -07003987static void qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha)
3988{
3989 int i;
3990
3991 if (IS_FWI2_CAPABLE(ha))
3992 return;
3993
3994 for (i = 0; i < SNS_FIRST_LOOP_ID; i++)
3995 set_bit(i, ha->loop_id_map);
3996 set_bit(MANAGEMENT_SERVER, ha->loop_id_map);
3997 set_bit(BROADCAST, ha->loop_id_map);
3998}
3999
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000/*
4001* qla2x00_mem_alloc
4002* Allocates adapter memory.
4003*
4004* Returns:
4005* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08004006* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08004008static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004009qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
4010 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011{
4012 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013
Andrew Vasqueze8711082008-01-31 12:33:48 -08004014 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004015 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004016 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004017 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004019 if (qlt_mem_alloc(ha) < 0)
4020 goto fail_free_init_cb;
4021
Chad Dupuis642ef982012-02-09 11:15:57 -08004022 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
4023 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004024 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004025 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026
Andrew Vasqueze8711082008-01-31 12:33:48 -08004027 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
4028 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004029 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004031 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004032 /* Allocate cache for CT6 Ctx. */
4033 if (!ctx_cachep) {
4034 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
4035 sizeof(struct ct6_dsd), 0,
4036 SLAB_HWCACHE_ALIGN, NULL);
4037 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004038 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004039 }
4040 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4041 ctx_cachep);
4042 if (!ha->ctx_mempool)
4043 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004044 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4045 "ctx_cachep=%p ctx_mempool=%p.\n",
4046 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004047 }
4048
Andrew Vasqueze8711082008-01-31 12:33:48 -08004049 /* Get memory for cached NVRAM */
4050 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4051 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004052 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004054 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4055 ha->pdev->device);
4056 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4057 DMA_POOL_SIZE, 8, 0);
4058 if (!ha->s_dma_pool)
4059 goto fail_free_nvram;
4060
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004061 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4062 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4063 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4064
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004065 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004066 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4067 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4068 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004069 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4070 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004071 goto fail_s_dma_pool;
4072 }
4073
4074 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4075 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4076 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004077 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4078 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004079 goto fail_dl_dma_pool;
4080 }
Giridhar Malavali50b81272018-12-21 09:33:45 -08004081
4082 if (ql2xenabledif) {
4083 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4084 struct dsd_dma *dsd, *nxt;
4085 uint i;
4086 /* Creata a DMA pool of buffers for DIF bundling */
4087 ha->dif_bundl_pool = dma_pool_create(name,
4088 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4089 if (!ha->dif_bundl_pool) {
4090 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4091 "%s: failed create dif_bundl_pool\n",
4092 __func__);
4093 goto fail_dif_bundl_dma_pool;
4094 }
4095
4096 INIT_LIST_HEAD(&ha->pool.good.head);
4097 INIT_LIST_HEAD(&ha->pool.unusable.head);
4098 ha->pool.good.count = 0;
4099 ha->pool.unusable.count = 0;
4100 for (i = 0; i < 128; i++) {
4101 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4102 if (!dsd) {
4103 ql_dbg_pci(ql_dbg_init, ha->pdev,
4104 0xe0ee, "%s: failed alloc dsd\n",
4105 __func__);
4106 return 1;
4107 }
4108 ha->dif_bundle_kallocs++;
4109
4110 dsd->dsd_addr = dma_pool_alloc(
4111 ha->dif_bundl_pool, GFP_ATOMIC,
4112 &dsd->dsd_list_dma);
4113 if (!dsd->dsd_addr) {
4114 ql_dbg_pci(ql_dbg_init, ha->pdev,
4115 0xe0ee,
4116 "%s: failed alloc ->dsd_addr\n",
4117 __func__);
4118 kfree(dsd);
4119 ha->dif_bundle_kallocs--;
4120 continue;
4121 }
4122 ha->dif_bundle_dma_allocs++;
4123
4124 /*
4125 * if DMA buffer crosses 4G boundary,
4126 * put it on bad list
4127 */
4128 if (MSD(dsd->dsd_list_dma) ^
4129 MSD(dsd->dsd_list_dma + bufsize)) {
4130 list_add_tail(&dsd->list,
4131 &ha->pool.unusable.head);
4132 ha->pool.unusable.count++;
4133 } else {
4134 list_add_tail(&dsd->list,
4135 &ha->pool.good.head);
4136 ha->pool.good.count++;
4137 }
4138 }
4139
4140 /* return the good ones back to the pool */
4141 list_for_each_entry_safe(dsd, nxt,
4142 &ha->pool.good.head, list) {
4143 list_del(&dsd->list);
4144 dma_pool_free(ha->dif_bundl_pool,
4145 dsd->dsd_addr, dsd->dsd_list_dma);
4146 ha->dif_bundle_dma_allocs--;
4147 kfree(dsd);
4148 ha->dif_bundle_kallocs--;
4149 }
4150
4151 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4152 "%s: dif dma pool (good=%u unusable=%u)\n",
4153 __func__, ha->pool.good.count,
4154 ha->pool.unusable.count);
4155 }
4156
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004157 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
Giridhar Malavali50b81272018-12-21 09:33:45 -08004158 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4159 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4160 ha->dif_bundl_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004161 }
4162
Andrew Vasqueze8711082008-01-31 12:33:48 -08004163 /* Allocate memory for SNS commands */
4164 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004165 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004166 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004167 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004168 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004169 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004170 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08004171 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004172 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004174 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004175 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004176 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004177 goto fail_dma_pool;
4178 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004179 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004180 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004181 if (!ha->ct_sns)
4182 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004183 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4184 "ms_iocb=%p ct_sns=%p.\n",
4185 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 }
4187
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004188 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004189 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4190 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004191 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4192 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193 goto fail_req;
4194 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004195 (*req)->length = req_len;
4196 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4197 ((*req)->length + 1) * sizeof(request_t),
4198 &(*req)->dma, GFP_KERNEL);
4199 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004200 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4201 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004202 goto fail_req_ring;
4203 }
4204 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004205 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4206 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004207 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4208 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004209 goto fail_rsp;
4210 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004211 (*rsp)->hw = ha;
4212 (*rsp)->length = rsp_len;
4213 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4214 ((*rsp)->length + 1) * sizeof(response_t),
4215 &(*rsp)->dma, GFP_KERNEL);
4216 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004217 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4218 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004219 goto fail_rsp_ring;
4220 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004221 (*req)->rsp = *rsp;
4222 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004223 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4224 "req=%p req->length=%d req->ring=%p rsp=%p "
4225 "rsp->length=%d rsp->ring=%p.\n",
4226 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4227 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004228 /* Allocate memory for NVRAM data for vports */
4229 if (ha->nvram_npiv_size) {
Kees Cook6396bb22018-06-12 14:03:40 -07004230 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4231 sizeof(struct qla_npiv_entry),
4232 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004233 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004234 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4235 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004236 goto fail_npiv_info;
4237 }
4238 } else
4239 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004240
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004241 /* Get consistent memory allocated for EX-INIT-CB. */
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004242 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4243 IS_QLA28XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004244 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4245 &ha->ex_init_cb_dma);
4246 if (!ha->ex_init_cb)
4247 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004248 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4249 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004250 }
4251
Giridhar Malavalia9083012010-04-12 17:59:55 -07004252 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4253
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004254 /* Get consistent memory allocated for Async Port-Database. */
4255 if (!IS_FWI2_CAPABLE(ha)) {
4256 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4257 &ha->async_pd_dma);
4258 if (!ha->async_pd)
4259 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004260 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4261 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004262 }
4263
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004264 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004265
4266 /* Allocate memory for our loop_id bitmap */
Kees Cook6396bb22018-06-12 14:03:40 -07004267 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4268 sizeof(long),
4269 GFP_KERNEL);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004270 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004271 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004272 else {
4273 qla2x00_set_reserved_loop_ids(ha);
4274 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004275 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004276 }
4277
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004278 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4279 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4280 if (!ha->sfp_data) {
4281 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4282 "Unable to allocate memory for SFP read-data.\n");
4283 goto fail_sfp_data;
4284 }
4285
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004286 ha->flt = dma_alloc_coherent(&ha->pdev->dev,
4287 sizeof(struct qla_flt_header) + FLT_REGIONS_SIZE, &ha->flt_dma,
4288 GFP_KERNEL);
4289 if (!ha->flt) {
4290 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4291 "Unable to allocate memory for FLT.\n");
4292 goto fail_flt_buffer;
4293 }
4294
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004295 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004296
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004297fail_flt_buffer:
4298 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4299 ha->sfp_data, ha->sfp_data_dma);
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004300fail_sfp_data:
4301 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004302fail_loop_id_map:
4303 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004304fail_async_pd:
4305 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004306fail_ex_init_cb:
4307 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004308fail_npiv_info:
4309 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4310 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4311 (*rsp)->ring = NULL;
4312 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004313fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004314 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004315 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004316fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004317 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4318 sizeof(request_t), (*req)->ring, (*req)->dma);
4319 (*req)->ring = NULL;
4320 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004321fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004322 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004323 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004324fail_req:
4325 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4326 ha->ct_sns, ha->ct_sns_dma);
4327 ha->ct_sns = NULL;
4328 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004329fail_free_ms_iocb:
4330 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4331 ha->ms_iocb = NULL;
4332 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004333
4334 if (ha->sns_cmd)
4335 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4336 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004337fail_dma_pool:
Giridhar Malavali50b81272018-12-21 09:33:45 -08004338 if (ql2xenabledif) {
4339 struct dsd_dma *dsd, *nxt;
4340
4341 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4342 list) {
4343 list_del(&dsd->list);
4344 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4345 dsd->dsd_list_dma);
4346 ha->dif_bundle_dma_allocs--;
4347 kfree(dsd);
4348 ha->dif_bundle_kallocs--;
4349 ha->pool.unusable.count--;
4350 }
4351 dma_pool_destroy(ha->dif_bundl_pool);
4352 ha->dif_bundl_pool = NULL;
4353 }
4354
4355fail_dif_bundl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004356 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004357 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4358 ha->fcp_cmnd_dma_pool = NULL;
4359 }
4360fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004361 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004362 dma_pool_destroy(ha->dl_dma_pool);
4363 ha->dl_dma_pool = NULL;
4364 }
4365fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004366 dma_pool_destroy(ha->s_dma_pool);
4367 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004368fail_free_nvram:
4369 kfree(ha->nvram);
4370 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004371fail_free_ctx_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004372 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004373 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004374fail_free_srb_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004375 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004376 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004377fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004378 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4379 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004380 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004381 ha->gid_list = NULL;
4382 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004383fail_free_tgt_mem:
4384 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004385fail_free_init_cb:
4386 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4387 ha->init_cb_dma);
4388 ha->init_cb = NULL;
4389 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004390fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004391 ql_log(ql_log_fatal, NULL, 0x0030,
4392 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004393 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394}
4395
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004396int
4397qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4398{
4399 int rval;
4400 uint16_t size, max_cnt, temp;
4401 struct qla_hw_data *ha = vha->hw;
4402
4403 /* Return if we don't need to alloacate any extended logins */
4404 if (!ql2xexlogins)
4405 return QLA_SUCCESS;
4406
Quinn Tran99e1b682017-06-02 09:12:03 -07004407 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4408 return QLA_SUCCESS;
4409
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004410 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4411 max_cnt = 0;
4412 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4413 if (rval != QLA_SUCCESS) {
4414 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4415 "Failed to get exlogin status.\n");
4416 return rval;
4417 }
4418
4419 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004420 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004421
Quinn Tran99e1b682017-06-02 09:12:03 -07004422 if (temp != ha->exlogin_size) {
4423 qla2x00_free_exlogin_buffer(ha);
4424 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004425
Quinn Tran99e1b682017-06-02 09:12:03 -07004426 ql_log(ql_log_info, vha, 0xd024,
4427 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4428 max_cnt, size, temp);
4429
4430 ql_log(ql_log_info, vha, 0xd025,
4431 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4432
4433 /* Get consistent memory for extended logins */
4434 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4435 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4436 if (!ha->exlogin_buf) {
4437 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004438 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004439 return -ENOMEM;
4440 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004441 }
4442
4443 /* Now configure the dma buffer */
4444 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4445 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004446 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004447 "Setup extended login buffer ****FAILED****.\n");
4448 qla2x00_free_exlogin_buffer(ha);
4449 }
4450
4451 return rval;
4452}
4453
4454/*
4455* qla2x00_free_exlogin_buffer
4456*
4457* Input:
4458* ha = adapter block pointer
4459*/
4460void
4461qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4462{
4463 if (ha->exlogin_buf) {
4464 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4465 ha->exlogin_buf, ha->exlogin_buf_dma);
4466 ha->exlogin_buf = NULL;
4467 ha->exlogin_size = 0;
4468 }
4469}
4470
Quinn Tran99e1b682017-06-02 09:12:03 -07004471static void
4472qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4473{
4474 u32 temp;
Quinn Tran0645cb82018-09-11 10:18:18 -07004475 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
Quinn Tran99e1b682017-06-02 09:12:03 -07004476 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4477
Quinn Trand1e36352017-12-28 12:33:12 -08004478 if (max_cnt > vha->hw->max_exchg)
4479 max_cnt = vha->hw->max_exchg;
4480
Quinn Tran99e1b682017-06-02 09:12:03 -07004481 if (qla_ini_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004482 if (vha->ql2xiniexchg > max_cnt)
4483 vha->ql2xiniexchg = max_cnt;
Quinn Tran99e1b682017-06-02 09:12:03 -07004484
Quinn Tran0645cb82018-09-11 10:18:18 -07004485 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4486 *ret_cnt = vha->ql2xiniexchg;
4487
Quinn Tran99e1b682017-06-02 09:12:03 -07004488 } else if (qla_tgt_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004489 if (vha->ql2xexchoffld > max_cnt) {
4490 vha->ql2xexchoffld = max_cnt;
4491 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4492 }
Quinn Tran99e1b682017-06-02 09:12:03 -07004493
Quinn Tran0645cb82018-09-11 10:18:18 -07004494 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4495 *ret_cnt = vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004496 } else if (qla_dual_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004497 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004498 if (temp > max_cnt) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004499 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4500 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
Quinn Tran99e1b682017-06-02 09:12:03 -07004501 temp = max_cnt;
Quinn Tran0645cb82018-09-11 10:18:18 -07004502 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Quinn Tran99e1b682017-06-02 09:12:03 -07004503 }
4504
4505 if (temp > FW_DEF_EXCHANGES_CNT)
4506 *ret_cnt = temp;
4507 }
4508}
4509
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004510int
4511qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4512{
4513 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004514 u16 size, max_cnt;
4515 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004516 struct qla_hw_data *ha = vha->hw;
4517
Quinn Tran99e1b682017-06-02 09:12:03 -07004518 if (!ha->flags.exchoffld_enabled)
4519 return QLA_SUCCESS;
4520
4521 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004522 return QLA_SUCCESS;
4523
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004524 max_cnt = 0;
4525 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4526 if (rval != QLA_SUCCESS) {
4527 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4528 "Failed to get exlogin status.\n");
4529 return rval;
4530 }
4531
Quinn Trand1e36352017-12-28 12:33:12 -08004532 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4533 ql_log(ql_log_info, vha, 0xd014,
4534 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004535
Quinn Trand1e36352017-12-28 12:33:12 -08004536 totsz = actual_cnt * size;
4537
4538 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004539 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran0645cb82018-09-11 10:18:18 -07004540 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4541 ha->exchoffld_size = 0;
4542 ha->flags.exchoffld_enabled = 0;
4543 return QLA_SUCCESS;
4544 }
4545
Quinn Trand1e36352017-12-28 12:33:12 -08004546 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004547
Quinn Tran99e1b682017-06-02 09:12:03 -07004548 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004549 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4550 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004551
4552 ql_log(ql_log_info, vha, 0xd017,
4553 "Exchange Buffers requested size = 0x%x\n",
4554 ha->exchoffld_size);
4555
4556 /* Get consistent memory for extended logins */
4557 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4558 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4559 if (!ha->exchoffld_buf) {
4560 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004561 "Failed to allocate memory for Exchange Offload.\n");
4562
4563 if (ha->max_exchg >
4564 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4565 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4566 } else if (ha->max_exchg >
4567 (FW_DEF_EXCHANGES_CNT + 512)) {
4568 ha->max_exchg -= 512;
4569 } else {
4570 ha->flags.exchoffld_enabled = 0;
4571 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4572 "Disabling Exchange offload due to lack of memory\n");
4573 }
4574 ha->exchoffld_size = 0;
4575
Quinn Tran99e1b682017-06-02 09:12:03 -07004576 return -ENOMEM;
4577 }
Quinn Tran0645cb82018-09-11 10:18:18 -07004578 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4579 /* pathological case */
4580 qla2x00_free_exchoffld_buffer(ha);
4581 ha->exchoffld_size = 0;
4582 ha->flags.exchoffld_enabled = 0;
4583 ql_log(ql_log_info, vha, 0xd016,
4584 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4585 ha->exchoffld_size, actual_cnt, size, totsz);
4586 return 0;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004587 }
4588
4589 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004590 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004591 if (rval) {
4592 ql_log(ql_log_fatal, vha, 0xd02e,
4593 "Setup exchange offload buffer ****FAILED****.\n");
4594 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004595 } else {
4596 /* re-adjust number of target exchange */
4597 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4598
4599 if (qla_ini_mode_enabled(vha))
4600 icb->exchange_count = 0;
4601 else
Quinn Tran0645cb82018-09-11 10:18:18 -07004602 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004603 }
4604
4605 return rval;
4606}
4607
4608/*
4609* qla2x00_free_exchoffld_buffer
4610*
4611* Input:
4612* ha = adapter block pointer
4613*/
4614void
4615qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4616{
4617 if (ha->exchoffld_buf) {
4618 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4619 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4620 ha->exchoffld_buf = NULL;
4621 ha->exchoffld_size = 0;
4622 }
4623}
4624
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004626* qla2x00_free_fw_dump
4627* Frees fw dump stuff.
4628*
4629* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004630* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004631*/
4632static void
4633qla2x00_free_fw_dump(struct qla_hw_data *ha)
4634{
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004635 struct fwdt *fwdt = ha->fwdt;
4636 uint j;
4637
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004638 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004639 dma_free_coherent(&ha->pdev->dev,
4640 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004641
Chad Dupuisf73cb692014-02-26 04:15:06 -05004642 if (ha->eft)
4643 dma_free_coherent(&ha->pdev->dev,
4644 EFT_SIZE, ha->eft, ha->eft_dma);
4645
4646 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004647 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004648
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004649 ha->fce = NULL;
4650 ha->fce_dma = 0;
4651 ha->eft = NULL;
4652 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004653 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004654 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004655 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004656 ha->fw_dump = NULL;
4657 ha->fw_dump_len = 0;
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004658
4659 for (j = 0; j < 2; j++, fwdt++) {
4660 if (fwdt->template)
4661 vfree(fwdt->template);
4662 fwdt->template = NULL;
4663 fwdt->length = 0;
4664 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004665}
4666
4667/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668* qla2x00_mem_free
4669* Frees all adapter allocated memory.
4670*
4671* Input:
4672* ha = adapter block pointer.
4673*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004674static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004675qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004677 qla2x00_free_fw_dump(ha);
4678
Saurav Kashyap81178772012-08-22 14:21:04 -04004679 if (ha->mctp_dump)
4680 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4681 ha->mctp_dump_dma);
4682
Thomas Meyer75c1d482018-12-02 21:52:11 +01004683 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004685 if (ha->dcbx_tlv)
4686 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4687 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4688
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004689 if (ha->xgmac_data)
4690 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4691 ha->xgmac_data, ha->xgmac_data_dma);
4692
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 if (ha->sns_cmd)
4694 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004695 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696
4697 if (ha->ct_sns)
4698 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004699 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700
Andrew Vasquez88729e52006-06-23 16:10:50 -07004701 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004702 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4703 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004704
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004705 if (ha->flt)
4706 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE,
4707 ha->flt, ha->flt_dma);
4708
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709 if (ha->ms_iocb)
4710 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4711
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004712 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004713 dma_pool_free(ha->s_dma_pool,
4714 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004715
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004716 if (ha->async_pd)
4717 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4718
Thomas Meyer75c1d482018-12-02 21:52:11 +01004719 dma_pool_destroy(ha->s_dma_pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004722 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4723 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724
Giridhar Malavalia9083012010-04-12 17:59:55 -07004725 if (IS_QLA82XX(ha)) {
4726 if (!list_empty(&ha->gbl_dsd_list)) {
4727 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4728
4729 /* clean up allocated prev pool */
4730 list_for_each_entry_safe(dsd_ptr,
4731 tdsd_ptr, &ha->gbl_dsd_list, list) {
4732 dma_pool_free(ha->dl_dma_pool,
4733 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4734 list_del(&dsd_ptr->list);
4735 kfree(dsd_ptr);
4736 }
4737 }
4738 }
4739
Thomas Meyer75c1d482018-12-02 21:52:11 +01004740 dma_pool_destroy(ha->dl_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004741
Thomas Meyer75c1d482018-12-02 21:52:11 +01004742 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004743
Thomas Meyer75c1d482018-12-02 21:52:11 +01004744 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004745
Giridhar Malavali50b81272018-12-21 09:33:45 -08004746 if (ql2xenabledif) {
4747 struct dsd_dma *dsd, *nxt;
4748
4749 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4750 list) {
4751 list_del(&dsd->list);
4752 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4753 dsd->dsd_list_dma);
4754 ha->dif_bundle_dma_allocs--;
4755 kfree(dsd);
4756 ha->dif_bundle_kallocs--;
4757 ha->pool.unusable.count--;
4758 }
4759 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4760 list_del(&dsd->list);
4761 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4762 dsd->dsd_list_dma);
4763 ha->dif_bundle_dma_allocs--;
4764 kfree(dsd);
4765 ha->dif_bundle_kallocs--;
4766 }
4767 }
4768
4769 if (ha->dif_bundl_pool)
4770 dma_pool_destroy(ha->dif_bundl_pool);
4771
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004772 qlt_mem_free(ha);
4773
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004774 if (ha->init_cb)
4775 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004776 ha->init_cb, ha->init_cb_dma);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004777
Bill Kuzeja6d634062018-03-23 10:37:25 -04004778 vfree(ha->optrom_buffer);
4779 kfree(ha->nvram);
4780 kfree(ha->npiv_info);
4781 kfree(ha->swl);
4782 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783
Andrew Vasqueze8711082008-01-31 12:33:48 -08004784 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004785 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 ha->sns_cmd = NULL;
4787 ha->sns_cmd_dma = 0;
4788 ha->ct_sns = NULL;
4789 ha->ct_sns_dma = 0;
4790 ha->ms_iocb = NULL;
4791 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792 ha->init_cb = NULL;
4793 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004794 ha->ex_init_cb = NULL;
4795 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004796 ha->async_pd = NULL;
4797 ha->async_pd_dma = 0;
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004798 ha->loop_id_map = NULL;
4799 ha->npiv_info = NULL;
4800 ha->optrom_buffer = NULL;
4801 ha->swl = NULL;
4802 ha->nvram = NULL;
4803 ha->mctp_dump = NULL;
4804 ha->dcbx_tlv = NULL;
4805 ha->xgmac_data = NULL;
4806 ha->sfp_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807
4808 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004809 ha->dl_dma_pool = NULL;
4810 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 ha->gid_list = NULL;
4813 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004814
4815 ha->tgt.atio_ring = NULL;
4816 ha->tgt.atio_dma = 0;
4817 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004818}
4819
4820struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4821 struct qla_hw_data *ha)
4822{
4823 struct Scsi_Host *host;
4824 struct scsi_qla_host *vha = NULL;
4825
4826 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004827 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004828 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4829 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004830 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004831 }
4832
4833 /* Clear our data area */
4834 vha = shost_priv(host);
4835 memset(vha, 0, sizeof(scsi_qla_host_t));
4836
4837 vha->host = host;
4838 vha->host_no = host->host_no;
4839 vha->hw = ha;
4840
Quinn Tran0645cb82018-09-11 10:18:18 -07004841 vha->qlini_mode = ql2x_ini_mode;
4842 vha->ql2xexchoffld = ql2xexchoffld;
4843 vha->ql2xiniexchg = ql2xiniexchg;
4844
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004845 INIT_LIST_HEAD(&vha->vp_fcports);
4846 INIT_LIST_HEAD(&vha->work_list);
4847 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004848 INIT_LIST_HEAD(&vha->qla_cmd_list);
4849 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004850 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004851 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004852 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004853 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004854 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004855 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004856 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004857
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004858 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004859 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004860 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004861 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004862
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004863 vha->gnl.size = sizeof(struct get_name_list_extended) *
4864 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004865 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4866 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4867 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004868 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004869 "Alloc failed for name list.\n");
4870 scsi_remove_host(vha->host);
4871 return NULL;
4872 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004873
Quinn Trana4239942017-12-28 12:33:26 -08004874 /* todo: what about ext login? */
4875 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4876 vha->scan.l = vmalloc(vha->scan.size);
4877 if (!vha->scan.l) {
4878 ql_log(ql_log_fatal, vha, 0xd04a,
4879 "Alloc failed for scan database.\n");
4880 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4881 vha->gnl.l, vha->gnl.ldma);
4882 scsi_remove_host(vha->host);
4883 return NULL;
4884 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004885 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004887 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004888 ql_dbg(ql_dbg_init, vha, 0x0041,
4889 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4890 vha->host, vha->hw, vha,
4891 dev_name(&(ha->pdev->dev)));
4892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004893 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894}
4895
Quinn Tran726b8542017-01-19 22:28:00 -08004896struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004897qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004898{
4899 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004900 uint8_t bail;
4901
4902 QLA_VHA_MARK_BUSY(vha, bail);
4903 if (bail)
4904 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004905
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004906 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004907 if (!e) {
4908 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004909 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004910 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004911
4912 INIT_LIST_HEAD(&e->list);
4913 e->type = type;
4914 e->flags = QLA_EVT_FLAG_FREE;
4915 return e;
4916}
4917
Quinn Tran726b8542017-01-19 22:28:00 -08004918int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004919qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004920{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004921 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004922 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004923
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004924 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004925 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004926
4927 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4928 q = true;
4929
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004930 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004931
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004932 if (q)
4933 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004934
Andrew Vasquez0971de72008-04-03 13:13:18 -07004935 return QLA_SUCCESS;
4936}
4937
4938int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004939qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004940 u32 data)
4941{
4942 struct qla_work_evt *e;
4943
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004944 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004945 if (!e)
4946 return QLA_FUNCTION_FAILED;
4947
4948 e->u.aen.code = code;
4949 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004950 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004951}
4952
Andrew Vasquez8a659572009-02-08 20:50:12 -08004953int
4954qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4955{
4956 struct qla_work_evt *e;
4957
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004958 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004959 if (!e)
4960 return QLA_FUNCTION_FAILED;
4961
4962 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004963 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004964}
4965
Andrew Vasquezac280b62009-08-20 11:06:05 -07004966#define qla2x00_post_async_work(name, type) \
4967int qla2x00_post_async_##name##_work( \
4968 struct scsi_qla_host *vha, \
4969 fc_port_t *fcport, uint16_t *data) \
4970{ \
4971 struct qla_work_evt *e; \
4972 \
4973 e = qla2x00_alloc_work(vha, type); \
4974 if (!e) \
4975 return QLA_FUNCTION_FAILED; \
4976 \
4977 e->u.logio.fcport = fcport; \
4978 if (data) { \
4979 e->u.logio.data[0] = data[0]; \
4980 e->u.logio.data[1] = data[1]; \
4981 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08004982 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07004983 return qla2x00_post_work(vha, e); \
4984}
4985
4986qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004987qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4988qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004989qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
Quinn Tran11aea162017-12-28 12:33:20 -08004990qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
4991qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004992
Andrew Vasquez3420d362009-10-13 15:16:45 -07004993int
4994qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
4995{
4996 struct qla_work_evt *e;
4997
4998 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
4999 if (!e)
5000 return QLA_FUNCTION_FAILED;
5001
5002 e->u.uevent.code = code;
5003 return qla2x00_post_work(vha, e);
5004}
5005
5006static void
5007qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
5008{
5009 char event_string[40];
5010 char *envp[] = { event_string, NULL };
5011
5012 switch (code) {
5013 case QLA_UEVENT_CODE_FW_DUMP:
5014 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
5015 vha->host_no);
5016 break;
5017 default:
5018 /* do nothing */
5019 break;
5020 }
5021 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
5022}
5023
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005024int
5025qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
5026 uint32_t *data, int cnt)
5027{
5028 struct qla_work_evt *e;
5029
5030 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
5031 if (!e)
5032 return QLA_FUNCTION_FAILED;
5033
5034 e->u.aenfx.evtcode = evtcode;
5035 e->u.aenfx.count = cnt;
5036 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
5037 return qla2x00_post_work(vha, e);
5038}
5039
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005040void qla24xx_sched_upd_fcport(fc_port_t *fcport)
Quinn Tran726b8542017-01-19 22:28:00 -08005041{
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005042 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08005043
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005044 if (IS_SW_RESV_ADDR(fcport->d_id))
5045 return;
Quinn Tran726b8542017-01-19 22:28:00 -08005046
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005047 spin_lock_irqsave(&fcport->vha->work_lock, flags);
5048 if (fcport->disc_state == DSC_UPD_FCPORT) {
5049 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5050 return;
5051 }
5052 fcport->jiffies_at_registration = jiffies;
5053 fcport->sec_since_registration = 0;
5054 fcport->next_disc_state = DSC_DELETED;
5055 fcport->disc_state = DSC_UPD_FCPORT;
5056 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5057
5058 queue_work(system_unbound_wq, &fcport->reg_work);
Quinn Tran726b8542017-01-19 22:28:00 -08005059}
5060
5061static
5062void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5063{
5064 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07005065 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08005066 struct qlt_plogi_ack_t *pla =
5067 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07005068 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005069
Quinn Tran9cd883f2017-12-28 12:33:24 -08005070 ql_dbg(ql_dbg_disc, vha, 0xffff,
5071 "%s %d %8phC enter\n",
5072 __func__, __LINE__, e->u.new_sess.port_name);
5073
Quinn Tran726b8542017-01-19 22:28:00 -08005074 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5075 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5076 if (fcport) {
5077 fcport->d_id = e->u.new_sess.id;
5078 if (pla) {
5079 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005080 memcpy(fcport->node_name,
5081 pla->iocb.u.isp24.u.plogi.node_name,
5082 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08005083 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5084 /* we took an extra ref_count to prevent PLOGI ACK when
5085 * fcport/sess has not been created.
5086 */
5087 pla->ref_count--;
5088 }
5089 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07005090 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08005091 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5092 if (fcport) {
5093 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08005094 fcport->flags |= FCF_FABRIC_DEVICE;
5095 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005096 if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08005097 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08005098
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005099 if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08005100 fcport->fc4_type = FC4_TYPE_OTHER;
5101 fcport->fc4f_nvme = FC4_TYPE_NVME;
5102 }
Quinn Tran33b28352018-03-20 23:09:40 -07005103
Quinn Tran726b8542017-01-19 22:28:00 -08005104 memcpy(fcport->port_name, e->u.new_sess.port_name,
5105 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07005106 } else {
5107 ql_dbg(ql_dbg_disc, vha, 0xffff,
5108 "%s %8phC mem alloc fail.\n",
5109 __func__, e->u.new_sess.port_name);
5110
5111 if (pla)
5112 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5113 return;
5114 }
5115
5116 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08005117 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07005118 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5119 e->u.new_sess.port_name, 1);
5120 if (tfcp) {
5121 /* should rarily happen */
5122 ql_dbg(ql_dbg_disc, vha, 0xffff,
5123 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5124 __func__, tfcp->port_name, tfcp->disc_state,
5125 tfcp->fw_login_state);
5126
5127 free_fcport = 1;
5128 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08005129 list_add_tail(&fcport->list, &vha->vp_fcports);
5130
Quinn Tran19759032017-12-04 14:45:15 -08005131 }
5132 if (pla) {
5133 qlt_plogi_ack_link(vha, pla, fcport,
5134 QLT_PLOGI_LINK_SAME_WWN);
5135 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08005136 }
5137 }
5138 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5139
5140 if (fcport) {
Quinn Trana4239942017-12-28 12:33:26 -08005141 fcport->id_changed = 1;
5142 fcport->scan_state = QLA_FCPORT_FOUND;
5143 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5144
Quinn Tran5ef696a2017-12-04 14:45:05 -08005145 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005146 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5147 u16 wd3_lo;
5148
5149 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5150 fcport->local = 0;
5151 fcport->loop_id =
5152 le16_to_cpu(
5153 pla->iocb.u.isp24.nport_handle);
5154 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5155 wd3_lo =
5156 le16_to_cpu(
5157 pla->iocb.u.isp24.u.prli.wd3_lo);
5158
5159 if (wd3_lo & BIT_7)
5160 fcport->conf_compl_supported = 1;
5161
5162 if ((wd3_lo & BIT_4) == 0)
5163 fcport->port_type = FCT_INITIATOR;
5164 else
5165 fcport->port_type = FCT_TARGET;
5166 }
Quinn Tran726b8542017-01-19 22:28:00 -08005167 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08005168 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005169 fc_port_t *dfcp = NULL;
5170
Quinn Tran5ef696a2017-12-04 14:45:05 -08005171 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5172 tfcp = qla2x00_find_fcport_by_nportid(vha,
5173 &e->u.new_sess.id, 1);
5174 if (tfcp && (tfcp != fcport)) {
5175 /*
5176 * We have a conflict fcport with same NportID.
5177 */
5178 ql_dbg(ql_dbg_disc, vha, 0xffff,
5179 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5180 __func__, tfcp->port_name, tfcp->disc_state,
5181 tfcp->fw_login_state);
5182
5183 switch (tfcp->disc_state) {
5184 case DSC_DELETED:
5185 break;
5186 case DSC_DELETE_PEND:
5187 fcport->login_pause = 1;
5188 tfcp->conflict = fcport;
5189 break;
5190 default:
5191 fcport->login_pause = 1;
5192 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005193 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08005194 break;
5195 }
5196 }
5197 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005198 if (dfcp)
5199 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08005200
Quinn Trana4239942017-12-28 12:33:26 -08005201
Quinn Tran8777e432018-08-02 13:16:57 -07005202 if (N2N_TOPO(vha->hw))
5203 fcport->flags &= ~FCF_FABRIC_DEVICE;
5204
5205 if (N2N_TOPO(vha->hw)) {
5206 if (vha->flags.nvme_enabled) {
5207 fcport->fc4f_nvme = 1;
5208 fcport->n2n_flag = 1;
5209 }
5210 fcport->fw_login_state = 0;
5211 /*
5212 * wait link init done before sending login
5213 */
5214 } else {
5215 qla24xx_fcport_handle_login(vha, fcport);
5216 }
Quinn Tran5ef696a2017-12-04 14:45:05 -08005217 }
Quinn Tran726b8542017-01-19 22:28:00 -08005218 }
Quinn Tranb5d15312017-08-30 10:16:49 -07005219
5220 if (free_fcport) {
5221 qla2x00_free_fcport(fcport);
5222 if (pla)
5223 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5224 }
Quinn Tran726b8542017-01-19 22:28:00 -08005225}
5226
Quinn Trane374f9f2017-12-28 12:33:31 -08005227static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5228{
5229 struct srb *sp = e->u.iosb.sp;
5230 int rval;
5231
5232 rval = qla2x00_start_sp(sp);
5233 if (rval != QLA_SUCCESS) {
5234 ql_dbg(ql_dbg_disc, vha, 0x2043,
5235 "%s: %s: Re-issue IOCB failed (%d).\n",
5236 __func__, sp->name, rval);
5237 qla24xx_sp_unmap(vha, sp);
5238 }
5239}
5240
Andrew Vasquezac280b62009-08-20 11:06:05 -07005241void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005242qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07005243{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005244 struct qla_work_evt *e, *tmp;
5245 unsigned long flags;
5246 LIST_HEAD(work);
Quinn Tran80676d02019-01-24 23:23:42 -08005247 int rc;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005248
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005249 spin_lock_irqsave(&vha->work_lock, flags);
5250 list_splice_init(&vha->work_list, &work);
5251 spin_unlock_irqrestore(&vha->work_lock, flags);
5252
5253 list_for_each_entry_safe(e, tmp, &work, list) {
Quinn Tran80676d02019-01-24 23:23:42 -08005254 rc = QLA_SUCCESS;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005255 switch (e->type) {
5256 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005257 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07005258 e->u.aen.code, e->u.aen.data);
5259 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08005260 case QLA_EVT_IDC_ACK:
5261 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5262 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005263 case QLA_EVT_ASYNC_LOGIN:
5264 qla2x00_async_login(vha, e->u.logio.fcport,
5265 e->u.logio.data);
5266 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005267 case QLA_EVT_ASYNC_LOGOUT:
Quinn Tran80676d02019-01-24 23:23:42 -08005268 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07005269 break;
5270 case QLA_EVT_ASYNC_LOGOUT_DONE:
5271 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5272 e->u.logio.data);
5273 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005274 case QLA_EVT_ASYNC_ADISC:
5275 qla2x00_async_adisc(vha, e->u.logio.fcport,
5276 e->u.logio.data);
5277 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005278 case QLA_EVT_UEVENT:
5279 qla2x00_uevent_emit(vha, e->u.uevent.code);
5280 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005281 case QLA_EVT_AENFX:
5282 qlafx00_process_aen(vha, e);
5283 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005284 case QLA_EVT_GPNID:
5285 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5286 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005287 case QLA_EVT_UNMAP:
5288 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005289 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005290 case QLA_EVT_RELOGIN:
5291 qla2x00_relogin(vha);
5292 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005293 case QLA_EVT_NEW_SESS:
5294 qla24xx_create_new_sess(vha, e);
5295 break;
5296 case QLA_EVT_GPDB:
5297 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5298 e->u.fcport.opt);
5299 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005300 case QLA_EVT_PRLI:
5301 qla24xx_async_prli(vha, e->u.fcport.fcport);
5302 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005303 case QLA_EVT_GPSC:
5304 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5305 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005306 case QLA_EVT_GNL:
5307 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5308 break;
5309 case QLA_EVT_NACK:
5310 qla24xx_do_nack_work(vha, e);
5311 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005312 case QLA_EVT_ASYNC_PRLO:
Quinn Tran80676d02019-01-24 23:23:42 -08005313 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
Quinn Tran11aea162017-12-28 12:33:20 -08005314 break;
5315 case QLA_EVT_ASYNC_PRLO_DONE:
5316 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5317 e->u.logio.data);
5318 break;
Quinn Trana4239942017-12-28 12:33:26 -08005319 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005320 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5321 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005322 break;
5323 case QLA_EVT_GPNFT_DONE:
5324 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5325 break;
5326 case QLA_EVT_GNNFT_DONE:
5327 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5328 break;
5329 case QLA_EVT_GNNID:
5330 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5331 break;
5332 case QLA_EVT_GFPNID:
5333 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5334 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005335 case QLA_EVT_SP_RETRY:
5336 qla_sp_retry(vha, e);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005337 break;
5338 case QLA_EVT_IIDMA:
5339 qla_do_iidma_work(vha, e->u.fcport.fcport);
5340 break;
Quinn Tran8777e432018-08-02 13:16:57 -07005341 case QLA_EVT_ELS_PLOGI:
5342 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5343 e->u.fcport.fcport, false);
5344 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005345 }
Quinn Tran80676d02019-01-24 23:23:42 -08005346
5347 if (rc == EAGAIN) {
5348 /* put 'work' at head of 'vha->work_list' */
5349 spin_lock_irqsave(&vha->work_lock, flags);
5350 list_splice(&work, &vha->work_list);
5351 spin_unlock_irqrestore(&vha->work_lock, flags);
5352 break;
5353 }
5354 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005355 if (e->flags & QLA_EVT_FLAG_FREE)
5356 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005357
5358 /* For each work completed decrement vha ref count */
5359 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005360 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005361}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005362
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005363int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5364{
5365 struct qla_work_evt *e;
5366
5367 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5368
5369 if (!e) {
5370 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5371 return QLA_FUNCTION_FAILED;
5372 }
5373
5374 return qla2x00_post_work(vha, e);
5375}
5376
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005377/* Relogins all the fcports of a vport
5378 * Context: dpc thread
5379 */
5380void qla2x00_relogin(struct scsi_qla_host *vha)
5381{
5382 fc_port_t *fcport;
Quinn Tran23dd98a2018-08-02 13:16:45 -07005383 int status, relogin_needed = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005384 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005385
5386 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005387 /*
5388 * If the port is not ONLINE then try to login
5389 * to it if we haven't run out of retries.
5390 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005391 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran23dd98a2018-08-02 13:16:45 -07005392 fcport->login_retry) {
5393 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5394 fcport->disc_state == DSC_LOGIN_COMPLETE)
5395 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005396
Quinn Tran23dd98a2018-08-02 13:16:45 -07005397 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5398 fcport->disc_state == DSC_DELETE_PEND) {
5399 relogin_needed = 1;
5400 } else {
5401 if (vha->hw->current_topology != ISP_CFG_NL) {
5402 memset(&ea, 0, sizeof(ea));
5403 ea.event = FCME_RELOGIN;
5404 ea.fcport = fcport;
5405 qla2x00_fcport_event_handler(vha, &ea);
5406 } else if (vha->hw->current_topology ==
5407 ISP_CFG_NL) {
5408 fcport->login_retry--;
5409 status =
5410 qla2x00_local_device_login(vha,
5411 fcport);
5412 if (status == QLA_SUCCESS) {
5413 fcport->old_loop_id =
5414 fcport->loop_id;
5415 ql_dbg(ql_dbg_disc, vha, 0x2003,
5416 "Port login OK: logged in ID 0x%x.\n",
5417 fcport->loop_id);
5418 qla2x00_update_fcport
5419 (vha, fcport);
5420 } else if (status == 1) {
5421 set_bit(RELOGIN_NEEDED,
5422 &vha->dpc_flags);
5423 /* retry the login again */
5424 ql_dbg(ql_dbg_disc, vha, 0x2007,
5425 "Retrying %d login again loop_id 0x%x.\n",
5426 fcport->login_retry,
5427 fcport->loop_id);
5428 } else {
5429 fcport->login_retry = 0;
5430 }
5431
5432 if (fcport->login_retry == 0 &&
5433 status != QLA_SUCCESS)
5434 qla2x00_clear_loop_id(fcport);
5435 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005436 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005437 }
5438 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5439 break;
5440 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005441
Quinn Tran23dd98a2018-08-02 13:16:45 -07005442 if (relogin_needed)
5443 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5444
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005445 ql_dbg(ql_dbg_disc, vha, 0x400e,
5446 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005447}
5448
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005449/* Schedule work on any of the dpc-workqueues */
5450void
5451qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5452{
5453 struct qla_hw_data *ha = base_vha->hw;
5454
5455 switch (work_code) {
5456 case MBA_IDC_AEN: /* 0x8200 */
5457 if (ha->dpc_lp_wq)
5458 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5459 break;
5460
5461 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5462 if (!ha->flags.nic_core_reset_hdlr_active) {
5463 if (ha->dpc_hp_wq)
5464 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5465 } else
5466 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5467 "NIC Core reset is already active. Skip "
5468 "scheduling it again.\n");
5469 break;
5470 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5471 if (ha->dpc_hp_wq)
5472 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5473 break;
5474 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5475 if (ha->dpc_hp_wq)
5476 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5477 break;
5478 default:
5479 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005480 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005481 }
5482
5483 return;
5484}
5485
5486/* Work: Perform NIC Core Unrecoverable state handling */
5487void
5488qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5489{
5490 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005491 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005492 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5493 uint32_t dev_state = 0;
5494
5495 qla83xx_idc_lock(base_vha, 0);
5496 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5497 qla83xx_reset_ownership(base_vha);
5498 if (ha->flags.nic_core_reset_owner) {
5499 ha->flags.nic_core_reset_owner = 0;
5500 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5501 QLA8XXX_DEV_FAILED);
5502 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5503 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5504 }
5505 qla83xx_idc_unlock(base_vha, 0);
5506}
5507
5508/* Work: Execute IDC state handler */
5509void
5510qla83xx_idc_state_handler_work(struct work_struct *work)
5511{
5512 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005513 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005514 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5515 uint32_t dev_state = 0;
5516
5517 qla83xx_idc_lock(base_vha, 0);
5518 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5519 if (dev_state == QLA8XXX_DEV_FAILED ||
5520 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5521 qla83xx_idc_state_handler(base_vha);
5522 qla83xx_idc_unlock(base_vha, 0);
5523}
5524
Saurav Kashyapfa492632012-11-21 02:40:29 -05005525static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005526qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5527{
5528 int rval = QLA_SUCCESS;
5529 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5530 uint32_t heart_beat_counter1, heart_beat_counter2;
5531
5532 do {
5533 if (time_after(jiffies, heart_beat_wait)) {
5534 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5535 "Nic Core f/w is not alive.\n");
5536 rval = QLA_FUNCTION_FAILED;
5537 break;
5538 }
5539
5540 qla83xx_idc_lock(base_vha, 0);
5541 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5542 &heart_beat_counter1);
5543 qla83xx_idc_unlock(base_vha, 0);
5544 msleep(100);
5545 qla83xx_idc_lock(base_vha, 0);
5546 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5547 &heart_beat_counter2);
5548 qla83xx_idc_unlock(base_vha, 0);
5549 } while (heart_beat_counter1 == heart_beat_counter2);
5550
5551 return rval;
5552}
5553
5554/* Work: Perform NIC Core Reset handling */
5555void
5556qla83xx_nic_core_reset_work(struct work_struct *work)
5557{
5558 struct qla_hw_data *ha =
5559 container_of(work, struct qla_hw_data, nic_core_reset);
5560 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5561 uint32_t dev_state = 0;
5562
Saurav Kashyap81178772012-08-22 14:21:04 -04005563 if (IS_QLA2031(ha)) {
5564 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5565 ql_log(ql_log_warn, base_vha, 0xb081,
5566 "Failed to dump mctp\n");
5567 return;
5568 }
5569
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005570 if (!ha->flags.nic_core_reset_hdlr_active) {
5571 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5572 qla83xx_idc_lock(base_vha, 0);
5573 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5574 &dev_state);
5575 qla83xx_idc_unlock(base_vha, 0);
5576 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5577 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5578 "Nic Core f/w is alive.\n");
5579 return;
5580 }
5581 }
5582
5583 ha->flags.nic_core_reset_hdlr_active = 1;
5584 if (qla83xx_nic_core_reset(base_vha)) {
5585 /* NIC Core reset failed. */
5586 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5587 "NIC Core reset failed.\n");
5588 }
5589 ha->flags.nic_core_reset_hdlr_active = 0;
5590 }
5591}
5592
5593/* Work: Handle 8200 IDC aens */
5594void
5595qla83xx_service_idc_aen(struct work_struct *work)
5596{
5597 struct qla_hw_data *ha =
5598 container_of(work, struct qla_hw_data, idc_aen);
5599 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5600 uint32_t dev_state, idc_control;
5601
5602 qla83xx_idc_lock(base_vha, 0);
5603 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5604 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5605 qla83xx_idc_unlock(base_vha, 0);
5606 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5607 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5608 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5609 "Application requested NIC Core Reset.\n");
5610 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5611 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5612 QLA_SUCCESS) {
5613 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5614 "Other protocol driver requested NIC Core Reset.\n");
5615 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5616 }
5617 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5618 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5619 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5620 }
5621}
5622
5623static void
5624qla83xx_wait_logic(void)
5625{
5626 int i;
5627
5628 /* Yield CPU */
5629 if (!in_interrupt()) {
5630 /*
5631 * Wait about 200ms before retrying again.
5632 * This controls the number of retries for single
5633 * lock operation.
5634 */
5635 msleep(100);
5636 schedule();
5637 } else {
5638 for (i = 0; i < 20; i++)
5639 cpu_relax(); /* This a nop instr on i386 */
5640 }
5641}
5642
Saurav Kashyapfa492632012-11-21 02:40:29 -05005643static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005644qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5645{
5646 int rval;
5647 uint32_t data;
5648 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5649 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5650 struct qla_hw_data *ha = base_vha->hw;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07005651
Saurav Kashyap6c315552013-02-08 01:57:53 -05005652 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5653 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005654
5655 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5656 if (rval)
5657 return rval;
5658
5659 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5660 return QLA_SUCCESS;
5661 } else {
5662 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5663 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5664 data);
5665 if (rval)
5666 return rval;
5667
5668 msleep(200);
5669
5670 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5671 &data);
5672 if (rval)
5673 return rval;
5674
5675 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5676 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5677 ~(idc_lck_rcvry_stage_mask));
5678 rval = qla83xx_wr_reg(base_vha,
5679 QLA83XX_IDC_LOCK_RECOVERY, data);
5680 if (rval)
5681 return rval;
5682
5683 /* Forcefully perform IDC UnLock */
5684 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5685 &data);
5686 if (rval)
5687 return rval;
5688 /* Clear lock-id by setting 0xff */
5689 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5690 0xff);
5691 if (rval)
5692 return rval;
5693 /* Clear lock-recovery by setting 0x0 */
5694 rval = qla83xx_wr_reg(base_vha,
5695 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5696 if (rval)
5697 return rval;
5698 } else
5699 return QLA_SUCCESS;
5700 }
5701
5702 return rval;
5703}
5704
Saurav Kashyapfa492632012-11-21 02:40:29 -05005705static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005706qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5707{
5708 int rval = QLA_SUCCESS;
5709 uint32_t o_drv_lockid, n_drv_lockid;
5710 unsigned long lock_recovery_timeout;
5711
5712 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5713retry_lockid:
5714 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5715 if (rval)
5716 goto exit;
5717
5718 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5719 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5720 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5721 return QLA_SUCCESS;
5722 else
5723 return QLA_FUNCTION_FAILED;
5724 }
5725
5726 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5727 if (rval)
5728 goto exit;
5729
5730 if (o_drv_lockid == n_drv_lockid) {
5731 qla83xx_wait_logic();
5732 goto retry_lockid;
5733 } else
5734 return QLA_SUCCESS;
5735
5736exit:
5737 return rval;
5738}
5739
5740void
5741qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5742{
5743 uint16_t options = (requester_id << 15) | BIT_6;
5744 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005745 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005746 struct qla_hw_data *ha = base_vha->hw;
5747
5748 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5749retry_lock:
5750 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5751 == QLA_SUCCESS) {
5752 if (data) {
5753 /* Setting lock-id to our function-number */
5754 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5755 ha->portnum);
5756 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005757 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5758 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005759 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005760 "Failed to acquire IDC lock, acquired by %d, "
5761 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005762
5763 /* Retry/Perform IDC-Lock recovery */
5764 if (qla83xx_idc_lock_recovery(base_vha)
5765 == QLA_SUCCESS) {
5766 qla83xx_wait_logic();
5767 goto retry_lock;
5768 } else
5769 ql_log(ql_log_warn, base_vha, 0xb075,
5770 "IDC Lock recovery FAILED.\n");
5771 }
5772
5773 }
5774
5775 return;
5776
5777 /* XXX: IDC-lock implementation using access-control mbx */
5778retry_lock2:
5779 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5780 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5781 "Failed to acquire IDC lock. retrying...\n");
5782 /* Retry/Perform IDC-Lock recovery */
5783 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5784 qla83xx_wait_logic();
5785 goto retry_lock2;
5786 } else
5787 ql_log(ql_log_warn, base_vha, 0xb076,
5788 "IDC Lock recovery FAILED.\n");
5789 }
5790
5791 return;
5792}
5793
5794void
5795qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5796{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005797#if 0
5798 uint16_t options = (requester_id << 15) | BIT_7;
5799#endif
5800 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005801 uint32_t data;
5802 struct qla_hw_data *ha = base_vha->hw;
5803
5804 /* IDC-unlock implementation using driver-unlock/lock-id
5805 * remote registers
5806 */
5807 retry = 0;
5808retry_unlock:
5809 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5810 == QLA_SUCCESS) {
5811 if (data == ha->portnum) {
5812 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5813 /* Clearing lock-id by setting 0xff */
5814 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5815 } else if (retry < 10) {
5816 /* SV: XXX: IDC unlock retrying needed here? */
5817
5818 /* Retry for IDC-unlock */
5819 qla83xx_wait_logic();
5820 retry++;
5821 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005822 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005823 goto retry_unlock;
5824 }
5825 } else if (retry < 10) {
5826 /* Retry for IDC-unlock */
5827 qla83xx_wait_logic();
5828 retry++;
5829 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005830 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005831 goto retry_unlock;
5832 }
5833
5834 return;
5835
Bart Van Assche5897cb22015-06-04 15:57:20 -07005836#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005837 /* XXX: IDC-unlock implementation using access-control mbx */
5838 retry = 0;
5839retry_unlock2:
5840 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5841 if (retry < 10) {
5842 /* Retry for IDC-unlock */
5843 qla83xx_wait_logic();
5844 retry++;
5845 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005846 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005847 goto retry_unlock2;
5848 }
5849 }
5850
5851 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005852#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005853}
5854
5855int
5856__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5857{
5858 int rval = QLA_SUCCESS;
5859 struct qla_hw_data *ha = vha->hw;
5860 uint32_t drv_presence;
5861
5862 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5863 if (rval == QLA_SUCCESS) {
5864 drv_presence |= (1 << ha->portnum);
5865 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5866 drv_presence);
5867 }
5868
5869 return rval;
5870}
5871
5872int
5873qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5874{
5875 int rval = QLA_SUCCESS;
5876
5877 qla83xx_idc_lock(vha, 0);
5878 rval = __qla83xx_set_drv_presence(vha);
5879 qla83xx_idc_unlock(vha, 0);
5880
5881 return rval;
5882}
5883
5884int
5885__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5886{
5887 int rval = QLA_SUCCESS;
5888 struct qla_hw_data *ha = vha->hw;
5889 uint32_t drv_presence;
5890
5891 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5892 if (rval == QLA_SUCCESS) {
5893 drv_presence &= ~(1 << ha->portnum);
5894 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5895 drv_presence);
5896 }
5897
5898 return rval;
5899}
5900
5901int
5902qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5903{
5904 int rval = QLA_SUCCESS;
5905
5906 qla83xx_idc_lock(vha, 0);
5907 rval = __qla83xx_clear_drv_presence(vha);
5908 qla83xx_idc_unlock(vha, 0);
5909
5910 return rval;
5911}
5912
Saurav Kashyapfa492632012-11-21 02:40:29 -05005913static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005914qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5915{
5916 struct qla_hw_data *ha = vha->hw;
5917 uint32_t drv_ack, drv_presence;
5918 unsigned long ack_timeout;
5919
5920 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5921 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5922 while (1) {
5923 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5924 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005925 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005926 break;
5927
5928 if (time_after_eq(jiffies, ack_timeout)) {
5929 ql_log(ql_log_warn, vha, 0xb067,
5930 "RESET ACK TIMEOUT! drv_presence=0x%x "
5931 "drv_ack=0x%x\n", drv_presence, drv_ack);
5932 /*
5933 * The function(s) which did not ack in time are forced
5934 * to withdraw any further participation in the IDC
5935 * reset.
5936 */
5937 if (drv_ack != drv_presence)
5938 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5939 drv_ack);
5940 break;
5941 }
5942
5943 qla83xx_idc_unlock(vha, 0);
5944 msleep(1000);
5945 qla83xx_idc_lock(vha, 0);
5946 }
5947
5948 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5949 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5950}
5951
Saurav Kashyapfa492632012-11-21 02:40:29 -05005952static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005953qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5954{
5955 int rval = QLA_SUCCESS;
5956 uint32_t idc_control;
5957
5958 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5959 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5960
5961 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5962 __qla83xx_get_idc_control(vha, &idc_control);
5963 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5964 __qla83xx_set_idc_control(vha, 0);
5965
5966 qla83xx_idc_unlock(vha, 0);
5967 rval = qla83xx_restart_nic_firmware(vha);
5968 qla83xx_idc_lock(vha, 0);
5969
5970 if (rval != QLA_SUCCESS) {
5971 ql_log(ql_log_fatal, vha, 0xb06a,
5972 "Failed to restart NIC f/w.\n");
5973 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5974 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5975 } else {
5976 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5977 "Success in restarting nic f/w.\n");
5978 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5979 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5980 }
5981
5982 return rval;
5983}
5984
5985/* Assumes idc_lock always held on entry */
5986int
5987qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5988{
5989 struct qla_hw_data *ha = base_vha->hw;
5990 int rval = QLA_SUCCESS;
5991 unsigned long dev_init_timeout;
5992 uint32_t dev_state;
5993
5994 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
5995 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
5996
5997 while (1) {
5998
5999 if (time_after_eq(jiffies, dev_init_timeout)) {
6000 ql_log(ql_log_warn, base_vha, 0xb06e,
6001 "Initialization TIMEOUT!\n");
6002 /* Init timeout. Disable further NIC Core
6003 * communication.
6004 */
6005 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
6006 QLA8XXX_DEV_FAILED);
6007 ql_log(ql_log_info, base_vha, 0xb06f,
6008 "HW State: FAILED.\n");
6009 }
6010
6011 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6012 switch (dev_state) {
6013 case QLA8XXX_DEV_READY:
6014 if (ha->flags.nic_core_reset_owner)
6015 qla83xx_idc_audit(base_vha,
6016 IDC_AUDIT_COMPLETION);
6017 ha->flags.nic_core_reset_owner = 0;
6018 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
6019 "Reset_owner reset by 0x%x.\n",
6020 ha->portnum);
6021 goto exit;
6022 case QLA8XXX_DEV_COLD:
6023 if (ha->flags.nic_core_reset_owner)
6024 rval = qla83xx_device_bootstrap(base_vha);
6025 else {
6026 /* Wait for AEN to change device-state */
6027 qla83xx_idc_unlock(base_vha, 0);
6028 msleep(1000);
6029 qla83xx_idc_lock(base_vha, 0);
6030 }
6031 break;
6032 case QLA8XXX_DEV_INITIALIZING:
6033 /* Wait for AEN to change device-state */
6034 qla83xx_idc_unlock(base_vha, 0);
6035 msleep(1000);
6036 qla83xx_idc_lock(base_vha, 0);
6037 break;
6038 case QLA8XXX_DEV_NEED_RESET:
6039 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
6040 qla83xx_need_reset_handler(base_vha);
6041 else {
6042 /* Wait for AEN to change device-state */
6043 qla83xx_idc_unlock(base_vha, 0);
6044 msleep(1000);
6045 qla83xx_idc_lock(base_vha, 0);
6046 }
6047 /* reset timeout value after need reset handler */
6048 dev_init_timeout = jiffies +
6049 (ha->fcoe_dev_init_timeout * HZ);
6050 break;
6051 case QLA8XXX_DEV_NEED_QUIESCENT:
6052 /* XXX: DEBUG for now */
6053 qla83xx_idc_unlock(base_vha, 0);
6054 msleep(1000);
6055 qla83xx_idc_lock(base_vha, 0);
6056 break;
6057 case QLA8XXX_DEV_QUIESCENT:
6058 /* XXX: DEBUG for now */
6059 if (ha->flags.quiesce_owner)
6060 goto exit;
6061
6062 qla83xx_idc_unlock(base_vha, 0);
6063 msleep(1000);
6064 qla83xx_idc_lock(base_vha, 0);
6065 dev_init_timeout = jiffies +
6066 (ha->fcoe_dev_init_timeout * HZ);
6067 break;
6068 case QLA8XXX_DEV_FAILED:
6069 if (ha->flags.nic_core_reset_owner)
6070 qla83xx_idc_audit(base_vha,
6071 IDC_AUDIT_COMPLETION);
6072 ha->flags.nic_core_reset_owner = 0;
6073 __qla83xx_clear_drv_presence(base_vha);
6074 qla83xx_idc_unlock(base_vha, 0);
6075 qla8xxx_dev_failed_handler(base_vha);
6076 rval = QLA_FUNCTION_FAILED;
6077 qla83xx_idc_lock(base_vha, 0);
6078 goto exit;
6079 case QLA8XXX_BAD_VALUE:
6080 qla83xx_idc_unlock(base_vha, 0);
6081 msleep(1000);
6082 qla83xx_idc_lock(base_vha, 0);
6083 break;
6084 default:
6085 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09006086 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006087 qla83xx_idc_unlock(base_vha, 0);
6088 qla8xxx_dev_failed_handler(base_vha);
6089 rval = QLA_FUNCTION_FAILED;
6090 qla83xx_idc_lock(base_vha, 0);
6091 goto exit;
6092 }
6093 }
6094
6095exit:
6096 return rval;
6097}
6098
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006099void
6100qla2x00_disable_board_on_pci_error(struct work_struct *work)
6101{
6102 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6103 board_disable);
6104 struct pci_dev *pdev = ha->pdev;
6105 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6106
Quinn Tran726b8542017-01-19 22:28:00 -08006107 /*
6108 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04006109 * where it was set first.
6110 */
6111 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6112 return;
6113
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006114 ql_log(ql_log_warn, base_vha, 0x015b,
6115 "Disabling adapter.\n");
6116
Sawan Chandakefdb5762017-08-23 15:05:00 -07006117 if (!atomic_read(&pdev->enable_cnt)) {
6118 ql_log(ql_log_info, base_vha, 0xfffc,
6119 "PCI device disabled, no action req for PCI error=%lx\n",
6120 base_vha->pci_flags);
6121 return;
6122 }
6123
Quinn Tran726b8542017-01-19 22:28:00 -08006124 qla2x00_wait_for_sess_deletion(base_vha);
6125
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006126 set_bit(UNLOADING, &base_vha->dpc_flags);
6127
6128 qla2x00_delete_all_vps(ha, base_vha);
6129
6130 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6131
6132 qla2x00_dfs_remove(base_vha);
6133
6134 qla84xx_put_chip(base_vha);
6135
6136 if (base_vha->timer_active)
6137 qla2x00_stop_timer(base_vha);
6138
6139 base_vha->flags.online = 0;
6140
6141 qla2x00_destroy_deferred_work(ha);
6142
6143 /*
6144 * Do not try to stop beacon blink as it will issue a mailbox
6145 * command.
6146 */
6147 qla2x00_free_sysfs_attr(base_vha, false);
6148
6149 fc_remove_host(base_vha->host);
6150
6151 scsi_remove_host(base_vha->host);
6152
6153 base_vha->flags.init_done = 0;
6154 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006155 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08006156 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006157 qla2x00_mem_free(ha);
6158 qla82xx_md_free(base_vha);
6159 qla2x00_free_queues(ha);
6160
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006161 qla2x00_unmap_iobases(ha);
6162
6163 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006164 pci_disable_pcie_error_reporting(pdev);
6165 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006166
Joe Lawrencebeb9e312014-08-26 17:12:14 -04006167 /*
6168 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6169 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006170}
6171
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172/**************************************************************************
6173* qla2x00_do_dpc
6174* This kernel thread is a task that is schedule by the interrupt handler
6175* to perform the background processing for interrupts.
6176*
6177* Notes:
6178* This task always run in the context of a kernel thread. It
6179* is kick-off by the driver's detect code and starts up
6180* up one per adapter. It immediately goes to sleep and waits for
6181* some fibre event. When either the interrupt handler or
6182* the timer routine detects a event it will one of the task
6183* bits then wake us up.
6184**************************************************************************/
6185static int
6186qla2x00_do_dpc(void *data)
6187{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006188 scsi_qla_host_t *base_vha;
6189 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08006190 uint32_t online;
6191 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08006192
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006193 ha = (struct qla_hw_data *)data;
6194 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195
Dongsheng Yang8698a742014-03-11 18:09:12 +08006196 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197
James Bottomley563585e2011-01-27 16:12:37 -05006198 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01006199 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006200 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6201 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202
Christoph Hellwig39a11242006-02-14 18:46:22 +01006203 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006205 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6206 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207
Andrew Vasquez85880802009-12-15 21:29:46 -08006208 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006209 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6210 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006211 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08006212 }
6213
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214 ha->dpc_active = 1;
6215
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04006216 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6217 "DPC handler waking up, dpc_flags=0x%lx.\n",
6218 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04006220 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6221 break;
6222
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006223 if (IS_P3P_TYPE(ha)) {
6224 if (IS_QLA8044(ha)) {
6225 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6226 &base_vha->dpc_flags)) {
6227 qla8044_idc_lock(ha);
6228 qla8044_wr_direct(base_vha,
6229 QLA8044_CRB_DEV_STATE_INDEX,
6230 QLA8XXX_DEV_FAILED);
6231 qla8044_idc_unlock(ha);
6232 ql_log(ql_log_info, base_vha, 0x4004,
6233 "HW State: FAILED.\n");
6234 qla8044_device_state_handler(base_vha);
6235 continue;
6236 }
6237
6238 } else {
6239 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6240 &base_vha->dpc_flags)) {
6241 qla82xx_idc_lock(ha);
6242 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6243 QLA8XXX_DEV_FAILED);
6244 qla82xx_idc_unlock(ha);
6245 ql_log(ql_log_info, base_vha, 0x0151,
6246 "HW State: FAILED.\n");
6247 qla82xx_device_state_handler(base_vha);
6248 continue;
6249 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006250 }
6251
6252 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6253 &base_vha->dpc_flags)) {
6254
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006255 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6256 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006257 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6258 &base_vha->dpc_flags))) {
6259 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6260 /* FCoE-ctx reset failed.
6261 * Escalate to chip-reset
6262 */
6263 set_bit(ISP_ABORT_NEEDED,
6264 &base_vha->dpc_flags);
6265 }
6266 clear_bit(ABORT_ISP_ACTIVE,
6267 &base_vha->dpc_flags);
6268 }
6269
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006270 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6271 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006272 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006273 } else if (IS_QLAFX00(ha)) {
6274 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6275 &base_vha->dpc_flags)) {
6276 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6277 "Firmware Reset Recovery\n");
6278 if (qlafx00_reset_initialize(base_vha)) {
6279 /* Failed. Abort isp later. */
6280 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006281 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006282 set_bit(ISP_UNRECOVERABLE,
6283 &base_vha->dpc_flags);
6284 ql_dbg(ql_dbg_dpc, base_vha,
6285 0x4021,
6286 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006287 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006288 }
6289 }
6290
6291 if (test_and_clear_bit(FX00_TARGET_SCAN,
6292 &base_vha->dpc_flags)) {
6293 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6294 "ISPFx00 Target Scan scheduled\n");
6295 if (qlafx00_rescan_isp(base_vha)) {
6296 if (!test_bit(UNLOADING,
6297 &base_vha->dpc_flags))
6298 set_bit(ISP_UNRECOVERABLE,
6299 &base_vha->dpc_flags);
6300 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6301 "ISPFx00 Target Scan Failed\n");
6302 }
6303 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6304 "ISPFx00 Target Scan End\n");
6305 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006306 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6307 &base_vha->dpc_flags)) {
6308 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6309 "ISPFx00 Host Info resend scheduled\n");
6310 qlafx00_fx_disc(base_vha,
6311 &base_vha->hw->mr.fcport,
6312 FXDISC_REG_HOST_INFO);
6313 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006314 }
6315
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006316 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6317 &base_vha->dpc_flags) &&
6318 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6319 qla24xx_detect_sfp(base_vha);
6320
6321 if (ha->flags.detected_lr_sfp !=
6322 ha->flags.using_lr_setting)
6323 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6324 }
6325
Quinn Tranb08abbd2018-07-18 14:29:54 -07006326 if (test_and_clear_bit
6327 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6328 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran93eca612018-08-31 11:24:37 -07006329 bool do_reset = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330
Quinn Tran0645cb82018-09-11 10:18:18 -07006331 switch (base_vha->qlini_mode) {
Quinn Tran93eca612018-08-31 11:24:37 -07006332 case QLA2XXX_INI_MODE_ENABLED:
6333 break;
6334 case QLA2XXX_INI_MODE_DISABLED:
Quinn Tran0645cb82018-09-11 10:18:18 -07006335 if (!qla_tgt_mode_enabled(base_vha) &&
6336 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006337 do_reset = false;
6338 break;
6339 case QLA2XXX_INI_MODE_DUAL:
Quinn Tran0645cb82018-09-11 10:18:18 -07006340 if (!qla_dual_mode_enabled(base_vha) &&
6341 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006342 do_reset = false;
6343 break;
6344 default:
6345 break;
6346 }
6347
6348 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006349 &base_vha->dpc_flags))) {
Quinn Tran93eca612018-08-31 11:24:37 -07006350 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6351 "ISP abort scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006352 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353 /* failed. retry later */
6354 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006355 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006357 clear_bit(ABORT_ISP_ACTIVE,
6358 &base_vha->dpc_flags);
Quinn Tran93eca612018-08-31 11:24:37 -07006359 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6360 "ISP abort end.\n");
Seokmann Ju99363ef2008-01-31 12:33:51 -08006361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 }
6363
David Jefferya394aac2012-11-21 02:39:54 -05006364 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6365 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006366 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006367 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006368
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006369 if (IS_QLAFX00(ha))
6370 goto loop_resync_check;
6371
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006372 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006373 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6374 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006375 if (IS_P3P_TYPE(ha)) {
6376 if (IS_QLA82XX(ha))
6377 qla82xx_device_state_handler(base_vha);
6378 if (IS_QLA8044(ha))
6379 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006380 clear_bit(ISP_QUIESCE_NEEDED,
6381 &base_vha->dpc_flags);
6382 if (!ha->flags.quiesce_owner) {
6383 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006384 if (IS_QLA82XX(ha)) {
6385 qla82xx_idc_lock(ha);
6386 qla82xx_clear_qsnt_ready(
6387 base_vha);
6388 qla82xx_idc_unlock(ha);
6389 } else if (IS_QLA8044(ha)) {
6390 qla8044_idc_lock(ha);
6391 qla8044_clear_qsnt_ready(
6392 base_vha);
6393 qla8044_idc_unlock(ha);
6394 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006395 }
6396 } else {
6397 clear_bit(ISP_QUIESCE_NEEDED,
6398 &base_vha->dpc_flags);
6399 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006400 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006401 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6402 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006403 }
6404
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006405 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006406 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006407 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006409 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6410 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006411 qla2x00_rst_aen(base_vha);
6412 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006413 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6414 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415 }
6416
6417 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006418 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006419 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6420 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421
Quinn Tran4005a992017-12-04 14:45:06 -08006422 if (!base_vha->relogin_jif ||
6423 time_after_eq(jiffies, base_vha->relogin_jif)) {
6424 base_vha->relogin_jif = jiffies + HZ;
6425 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6426
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006427 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006428 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006429 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006432loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006433 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006434 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006436 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6437 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438
6439 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006440 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441
Bart Van Assche52c82822015-07-09 07:23:26 -07006442 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006444 clear_bit(LOOP_RESYNC_ACTIVE,
6445 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 }
6447
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006448 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6449 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 }
6451
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006452 if (IS_QLAFX00(ha))
6453 goto intr_on_check;
6454
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006455 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6456 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6457 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6458 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006459 }
6460
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006461intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006463 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006465 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006466 &base_vha->dpc_flags)) {
6467 if (ha->beacon_blink_led == 1)
6468 ha->isp_ops->beacon_blink(base_vha);
6469 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006470
Michael Hernandezd7459522016-12-12 14:40:07 -08006471 /* qpair online check */
6472 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6473 &base_vha->dpc_flags)) {
6474 if (ha->flags.eeh_busy ||
6475 ha->flags.pci_channel_io_perm_failure)
6476 online = 0;
6477 else
6478 online = 1;
6479
6480 mutex_lock(&ha->mq_lock);
6481 list_for_each_entry(qpair, &base_vha->qp_list,
6482 qp_list_elem)
6483 qpair->online = online;
6484 mutex_unlock(&ha->mq_lock);
6485 }
6486
Quinn Tran8b4673b2018-09-04 14:19:14 -07006487 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6488 &base_vha->dpc_flags)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006489 ql_log(ql_log_info, base_vha, 0xffffff,
6490 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6491 ha->nvme_last_rptd_aen);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006492 if (qla27xx_set_zio_threshold(base_vha,
6493 ha->nvme_last_rptd_aen)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006494 ql_log(ql_log_info, base_vha, 0xffffff,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006495 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6496 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006497 }
6498 }
6499
Quinn Tran8b4673b2018-09-04 14:19:14 -07006500 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6501 &base_vha->dpc_flags)) {
6502 ql_log(ql_log_info, base_vha, 0xffffff,
6503 "SET ZIO Activity exchange threshold to %d.\n",
6504 ha->last_zio_threshold);
6505 qla27xx_set_zio_threshold(base_vha,
6506 ha->last_zio_threshold);
6507 }
6508
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006509 if (!IS_QLAFX00(ha))
6510 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006511
Quinn Tran48acad02018-08-02 13:16:44 -07006512 if (test_and_clear_bit(N2N_LINK_RESET,
6513 &base_vha->dpc_flags)) {
6514 qla2x00_lip_reset(base_vha);
6515 }
6516
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006518end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006519 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006521 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006523 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6524 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525
6526 /*
6527 * Make sure that nobody tries to wake us up again.
6528 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 ha->dpc_active = 0;
6530
Andrew Vasquezac280b62009-08-20 11:06:05 -07006531 /* Cleanup any residual CTX SRBs. */
6532 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6533
Christoph Hellwig39a11242006-02-14 18:46:22 +01006534 return 0;
6535}
6536
6537void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006538qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006539{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006540 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006541 struct task_struct *t = ha->dpc_thread;
6542
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006543 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006544 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545}
6546
6547/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548* qla2x00_rst_aen
6549* Processes asynchronous reset.
6550*
6551* Input:
6552* ha = adapter block pointer.
6553*/
6554static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006555qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006557 if (vha->flags.online && !vha->flags.reset_active &&
6558 !atomic_read(&vha->loop_down_timer) &&
6559 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006561 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562
6563 /*
6564 * Issue marker command only when we are going to start
6565 * the I/O.
6566 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006567 vha->marker_needed = 1;
6568 } while (!atomic_read(&vha->loop_down_timer) &&
6569 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 }
6571}
6572
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573/**************************************************************************
6574* qla2x00_timer
6575*
6576* Description:
6577* One second timer
6578*
6579* Context: Interrupt
6580***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006581void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006582qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006584 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586 int start_dpc = 0;
6587 int index;
6588 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006589 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006590 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006591 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006592
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006593 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006594 ql_dbg(ql_dbg_timer, vha, 0x6000,
6595 "EEH = %d, restarting timer.\n",
6596 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006597 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6598 return;
6599 }
6600
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006601 /*
6602 * Hardware read to raise pending EEH errors during mailbox waits. If
6603 * the read returns -1 then disable the board.
6604 */
6605 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006606 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006607 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006610 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006611 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006612 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6613 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006614 if (IS_QLA82XX(ha))
6615 qla82xx_watchdog(vha);
6616 else if (IS_QLA8044(ha))
6617 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006618 }
6619
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006620 if (!vha->vp_idx && IS_QLAFX00(ha))
6621 qlafx00_timer_routine(vha);
6622
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006624 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006625 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6626 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006627 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006629 if (atomic_read(&vha->loop_down_timer) ==
6630 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006632 ql_log(ql_log_info, vha, 0x6008,
6633 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006635 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6636 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006638 /*
6639 * Schedule an ISP abort to return any FCP2-device
6640 * commands.
6641 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006642 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006643 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006644 spin_lock_irqsave(&ha->hardware_lock,
6645 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006646 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006647 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006648 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006649 index++) {
6650 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006651
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006652 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006653 if (!sp)
6654 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006655 if (sp->cmd_type != TYPE_SRB)
6656 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006657 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006658 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006659 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006660 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006661 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006663 if (IS_QLA82XX(ha))
6664 set_bit(FCOE_CTX_RESET_NEEDED,
6665 &vha->dpc_flags);
6666 else
6667 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006668 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006669 break;
6670 }
6671 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006672 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 start_dpc++;
6675 }
6676
6677 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006678 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006679 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006680 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681 "Loop down - aborting ISP.\n");
6682
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006683 if (IS_QLA82XX(ha))
6684 set_bit(FCOE_CTX_RESET_NEEDED,
6685 &vha->dpc_flags);
6686 else
6687 set_bit(ISP_ABORT_NEEDED,
6688 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 }
6690 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006691 ql_dbg(ql_dbg_timer, vha, 0x600a,
6692 "Loop down - seconds remaining %d.\n",
6693 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006694 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006695 /* Check if beacon LED needs to be blinked for physical host only */
6696 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006697 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006698 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006699 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6700 start_dpc++;
6701 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006702 }
6703
Andrew Vasquez550bf572008-04-24 15:21:23 -07006704 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006705 if (!list_empty(&vha->work_list)) {
6706 unsigned long flags;
6707 bool q = false;
6708
6709 spin_lock_irqsave(&vha->work_lock, flags);
6710 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6711 q = true;
6712 spin_unlock_irqrestore(&vha->work_lock, flags);
6713 if (q)
6714 queue_work(vha->hw->wq, &vha->iocb_work);
6715 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006716
Duane Grigsby7401bc12017-06-21 13:48:42 -07006717 /*
6718 * FC-NVME
6719 * see if the active AEN count has changed from what was last reported.
6720 */
Giridhar Malavalib2d1453a2019-04-02 14:24:32 -07006721 if (!vha->vp_idx &&
6722 (atomic_read(&ha->nvme_active_aen_cnt) != ha->nvme_last_rptd_aen) &&
6723 ha->zio_mode == QLA_ZIO_MODE_6 &&
6724 !ha->flags.host_shutting_down) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006725 ql_log(ql_log_info, vha, 0x3002,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006726 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6727 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006728 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006729 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6730 start_dpc++;
6731 }
6732
6733 if (!vha->vp_idx &&
6734 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6735 (ha->zio_mode == QLA_ZIO_MODE_6) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006736 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
Quinn Tran8b4673b2018-09-04 14:19:14 -07006737 ql_log(ql_log_info, vha, 0x3002,
6738 "Sched: Set ZIO exchange threshold to %d.\n",
6739 ha->last_zio_threshold);
6740 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006741 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6742 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006743 }
6744
Linus Torvalds1da177e2005-04-16 15:20:36 -07006745 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006746 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6747 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6748 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006750 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6751 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006752 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6753 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006754 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006755 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006756 ql_dbg(ql_dbg_timer, vha, 0x600b,
6757 "isp_abort_needed=%d loop_resync_needed=%d "
6758 "fcport_update_needed=%d start_dpc=%d "
6759 "reset_marker_needed=%d",
6760 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6761 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6762 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6763 start_dpc,
6764 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6765 ql_dbg(ql_dbg_timer, vha, 0x600c,
6766 "beacon_blink_needed=%d isp_unrecoverable=%d "
6767 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006768 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006769 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6770 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6771 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6772 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006773 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006774 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006776
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006777 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778}
6779
Andrew Vasquez54333832005-11-09 15:49:04 -08006780/* Firmware interface routines. */
6781
Andrew Vasquez54333832005-11-09 15:49:04 -08006782#define FW_ISP21XX 0
6783#define FW_ISP22XX 1
6784#define FW_ISP2300 2
6785#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006786#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006787#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006788#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006789#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006790#define FW_ISP2031 8
6791#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006792#define FW_ISP27XX 10
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006793#define FW_ISP28XX 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006794
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006795#define FW_FILE_ISP21XX "ql2100_fw.bin"
6796#define FW_FILE_ISP22XX "ql2200_fw.bin"
6797#define FW_FILE_ISP2300 "ql2300_fw.bin"
6798#define FW_FILE_ISP2322 "ql2322_fw.bin"
6799#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006800#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006801#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006802#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006803#define FW_FILE_ISP2031 "ql2600_fw.bin"
6804#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006805#define FW_FILE_ISP27XX "ql2700_fw.bin"
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006806#define FW_FILE_ISP28XX "ql2800_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006807
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006808
Daniel Walkere1e82b62008-05-12 22:21:10 -07006809static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006810
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006811static struct fw_blob qla_fw_blobs[] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006812 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6813 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6814 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6815 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6816 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006817 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006818 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006819 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006820 { .name = FW_FILE_ISP2031, },
6821 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006822 { .name = FW_FILE_ISP27XX, },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006823 { .name = FW_FILE_ISP28XX, },
6824 { .name = NULL, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006825};
6826
6827struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006828qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006829{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006830 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006831 struct fw_blob *blob;
6832
Andrew Vasquez54333832005-11-09 15:49:04 -08006833 if (IS_QLA2100(ha)) {
6834 blob = &qla_fw_blobs[FW_ISP21XX];
6835 } else if (IS_QLA2200(ha)) {
6836 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006837 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006838 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006839 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006840 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006841 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006842 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006843 } else if (IS_QLA25XX(ha)) {
6844 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006845 } else if (IS_QLA81XX(ha)) {
6846 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006847 } else if (IS_QLA82XX(ha)) {
6848 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006849 } else if (IS_QLA2031(ha)) {
6850 blob = &qla_fw_blobs[FW_ISP2031];
6851 } else if (IS_QLA8031(ha)) {
6852 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006853 } else if (IS_QLA27XX(ha)) {
6854 blob = &qla_fw_blobs[FW_ISP27XX];
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006855 } else if (IS_QLA28XX(ha)) {
6856 blob = &qla_fw_blobs[FW_ISP28XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006857 } else {
6858 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006859 }
6860
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006861 if (!blob->name)
6862 return NULL;
6863
Daniel Walkere1e82b62008-05-12 22:21:10 -07006864 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006865 if (blob->fw)
6866 goto out;
6867
6868 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006869 ql_log(ql_log_warn, vha, 0x0063,
6870 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006871 blob->fw = NULL;
6872 blob = NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006873 }
6874
6875out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006876 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006877 return blob;
6878}
6879
6880static void
6881qla2x00_release_firmware(void)
6882{
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006883 struct fw_blob *blob;
Andrew Vasquez54333832005-11-09 15:49:04 -08006884
Daniel Walkere1e82b62008-05-12 22:21:10 -07006885 mutex_lock(&qla_fw_lock);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006886 for (blob = qla_fw_blobs; blob->name; blob++)
6887 release_firmware(blob->fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006888 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006889}
6890
Seokmann Ju14e660e2007-09-20 14:07:36 -07006891static pci_ers_result_t
6892qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6893{
Andrew Vasquez85880802009-12-15 21:29:46 -08006894 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6895 struct qla_hw_data *ha = vha->hw;
6896
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006897 ql_dbg(ql_dbg_aer, vha, 0x9000,
6898 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006899
Sawan Chandakefdb5762017-08-23 15:05:00 -07006900 if (!atomic_read(&pdev->enable_cnt)) {
6901 ql_log(ql_log_info, vha, 0xffff,
6902 "PCI device is disabled,state %x\n", state);
6903 return PCI_ERS_RESULT_NEED_RESET;
6904 }
6905
Seokmann Ju14e660e2007-09-20 14:07:36 -07006906 switch (state) {
6907 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006908 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006909 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006910 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6911 qla2xxx_wake_dpc(vha);
6912 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006913 return PCI_ERS_RESULT_CAN_RECOVER;
6914 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006915 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006916 /* For ISP82XX complete any pending mailbox cmd */
6917 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006918 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006919 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6920 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006921 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006922 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006923 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006924 /* Return back all IOs */
6925 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006926 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006927 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6928 qla2xxx_wake_dpc(vha);
6929 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006930 return PCI_ERS_RESULT_NEED_RESET;
6931 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006932 ha->flags.pci_channel_io_perm_failure = 1;
6933 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006934 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006935 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6936 qla2xxx_wake_dpc(vha);
6937 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006938 return PCI_ERS_RESULT_DISCONNECT;
6939 }
6940 return PCI_ERS_RESULT_NEED_RESET;
6941}
6942
6943static pci_ers_result_t
6944qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6945{
6946 int risc_paused = 0;
6947 uint32_t stat;
6948 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006949 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6950 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006951 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6952 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6953
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006954 if (IS_QLA82XX(ha))
6955 return PCI_ERS_RESULT_RECOVERED;
6956
Seokmann Ju14e660e2007-09-20 14:07:36 -07006957 spin_lock_irqsave(&ha->hardware_lock, flags);
6958 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6959 stat = RD_REG_DWORD(&reg->hccr);
6960 if (stat & HCCR_RISC_PAUSE)
6961 risc_paused = 1;
6962 } else if (IS_QLA23XX(ha)) {
6963 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6964 if (stat & HSR_RISC_PAUSED)
6965 risc_paused = 1;
6966 } else if (IS_FWI2_CAPABLE(ha)) {
6967 stat = RD_REG_DWORD(&reg24->host_status);
6968 if (stat & HSRX_RISC_PAUSED)
6969 risc_paused = 1;
6970 }
6971 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6972
6973 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006974 ql_log(ql_log_info, base_vha, 0x9003,
6975 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006976 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006977
6978 return PCI_ERS_RESULT_NEED_RESET;
6979 } else
6980 return PCI_ERS_RESULT_RECOVERED;
6981}
6982
Saurav Kashyapfa492632012-11-21 02:40:29 -05006983static uint32_t
6984qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006985{
6986 uint32_t rval = QLA_FUNCTION_FAILED;
6987 uint32_t drv_active = 0;
6988 struct qla_hw_data *ha = base_vha->hw;
6989 int fn;
6990 struct pci_dev *other_pdev = NULL;
6991
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006992 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
6993 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006994
6995 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
6996
6997 if (base_vha->flags.online) {
6998 /* Abort all outstanding commands,
6999 * so as to be requeued later */
7000 qla2x00_abort_isp_cleanup(base_vha);
7001 }
7002
7003
7004 fn = PCI_FUNC(ha->pdev->devfn);
7005 while (fn > 0) {
7006 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007007 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
7008 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007009 other_pdev =
7010 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
7011 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
7012 fn));
7013
7014 if (!other_pdev)
7015 continue;
7016 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007017 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
7018 "Found PCI func available and enable at 0x%x.\n",
7019 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007020 pci_dev_put(other_pdev);
7021 break;
7022 }
7023 pci_dev_put(other_pdev);
7024 }
7025
7026 if (!fn) {
7027 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007028 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
7029 "This devfn is reset owner = 0x%x.\n",
7030 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007031 qla82xx_idc_lock(ha);
7032
7033 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007034 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007035
7036 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
7037 QLA82XX_IDC_VERSION);
7038
7039 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007040 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
7041 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007042
7043 qla82xx_idc_unlock(ha);
7044 /* Reset if device is not already reset
7045 * drv_active would be 0 if a reset has already been done
7046 */
7047 if (drv_active)
7048 rval = qla82xx_start_firmware(base_vha);
7049 else
7050 rval = QLA_SUCCESS;
7051 qla82xx_idc_lock(ha);
7052
7053 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007054 ql_log(ql_log_info, base_vha, 0x900b,
7055 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007056 qla82xx_clear_drv_active(ha);
7057 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007058 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007059 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007060 ql_log(ql_log_info, base_vha, 0x900c,
7061 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007062 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007063 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007064 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08007065 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007066 rval = qla82xx_restart_isp(base_vha);
7067 qla82xx_idc_lock(ha);
7068 /* Clear driver state register */
7069 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
7070 qla82xx_set_drv_active(base_vha);
7071 }
7072 qla82xx_idc_unlock(ha);
7073 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007074 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
7075 "This devfn is not reset owner = 0x%x.\n",
7076 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007077 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007078 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08007079 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007080 rval = qla82xx_restart_isp(base_vha);
7081 qla82xx_idc_lock(ha);
7082 qla82xx_set_drv_active(base_vha);
7083 qla82xx_idc_unlock(ha);
7084 }
7085 }
7086 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7087
7088 return rval;
7089}
7090
Seokmann Ju14e660e2007-09-20 14:07:36 -07007091static pci_ers_result_t
7092qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7093{
7094 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007095 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7096 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007097 struct rsp_que *rsp;
7098 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007099
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007100 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
7101 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007102
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007103 /* Workaround: qla2xxx driver which access hardware earlier
7104 * needs error state to be pci_channel_io_online.
7105 * Otherwise mailbox command timesout.
7106 */
7107 pdev->error_state = pci_channel_io_normal;
7108
7109 pci_restore_state(pdev);
7110
Richard Lary8c1496b2010-02-18 10:07:29 -08007111 /* pci_restore_state() clears the saved_state flag of the device
7112 * save restored state which resets saved_state flag
7113 */
7114 pci_save_state(pdev);
7115
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11007116 if (ha->mem_only)
7117 rc = pci_enable_device_mem(pdev);
7118 else
7119 rc = pci_enable_device(pdev);
7120
7121 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007122 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007123 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007124 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007125 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007126
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007127 rsp = ha->rsp_q_map[0];
7128 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007129 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007130
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007131 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007132 goto exit_slot_reset;
7133
7134 if (IS_QLA82XX(ha)) {
7135 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
7136 ret = PCI_ERS_RESULT_RECOVERED;
7137 goto exit_slot_reset;
7138 } else
7139 goto exit_slot_reset;
7140 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007141
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007142 while (ha->flags.mbox_busy && retries--)
7143 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08007144
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007145 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007146 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07007147 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007148 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007149
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007150
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007151exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007152 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7153 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08007154
Seokmann Ju14e660e2007-09-20 14:07:36 -07007155 return ret;
7156}
7157
7158static void
7159qla2xxx_pci_resume(struct pci_dev *pdev)
7160{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007161 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7162 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007163 int ret;
7164
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007165 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
7166 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007168 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007169 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007170 ql_log(ql_log_fatal, base_vha, 0x9002,
7171 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07007172 }
Andrew Vasquez85880802009-12-15 21:29:46 -08007173
7174 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007175}
7176
Quinn Tran590f8062019-01-24 23:23:40 -08007177static void
7178qla_pci_reset_prepare(struct pci_dev *pdev)
7179{
7180 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7181 struct qla_hw_data *ha = base_vha->hw;
7182 struct qla_qpair *qpair;
7183
7184 ql_log(ql_log_warn, base_vha, 0xffff,
7185 "%s.\n", __func__);
7186
7187 /*
7188 * PCI FLR/function reset is about to reset the
7189 * slot. Stop the chip to stop all DMA access.
7190 * It is assumed that pci_reset_done will be called
7191 * after FLR to resume Chip operation.
7192 */
7193 ha->flags.eeh_busy = 1;
7194 mutex_lock(&ha->mq_lock);
7195 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7196 qpair->online = 0;
7197 mutex_unlock(&ha->mq_lock);
7198
7199 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7200 qla2x00_abort_isp_cleanup(base_vha);
7201 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7202}
7203
7204static void
7205qla_pci_reset_done(struct pci_dev *pdev)
7206{
7207 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7208 struct qla_hw_data *ha = base_vha->hw;
7209 struct qla_qpair *qpair;
7210
7211 ql_log(ql_log_warn, base_vha, 0xffff,
7212 "%s.\n", __func__);
7213
7214 /*
7215 * FLR just completed by PCI layer. Resume adapter
7216 */
7217 ha->flags.eeh_busy = 0;
7218 mutex_lock(&ha->mq_lock);
7219 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7220 qpair->online = 1;
7221 mutex_unlock(&ha->mq_lock);
7222
7223 base_vha->flags.online = 1;
7224 ha->isp_ops->abort_isp(base_vha);
7225 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7226}
7227
Michael Hernandez56012362016-12-12 14:40:08 -08007228static int qla2xxx_map_queues(struct Scsi_Host *shost)
7229{
Quinn Trand68b8502017-12-04 14:44:59 -08007230 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007231 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
Dongli Zhang485b0ec2019-03-12 09:00:30 +08007232 struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT];
Michael Hernandez56012362016-12-12 14:40:08 -08007233
Giridhar Malavalif3e02692019-02-15 16:42:55 -08007234 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
Jens Axboeed76e322018-10-29 13:06:14 -06007235 rc = blk_mq_map_queues(qmap);
Quinn Trand68b8502017-12-04 14:44:59 -08007236 else
Ming Leif0783d42019-01-11 09:40:47 -08007237 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
Quinn Trand68b8502017-12-04 14:44:59 -08007238 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007239}
7240
Bart Van Assche6515ad72019-04-04 12:44:43 -07007241struct scsi_host_template qla2xxx_driver_template = {
7242 .module = THIS_MODULE,
7243 .name = QLA2XXX_DRIVER_NAME,
7244 .queuecommand = qla2xxx_queuecommand,
7245
7246 .eh_timed_out = fc_eh_timed_out,
7247 .eh_abort_handler = qla2xxx_eh_abort,
7248 .eh_device_reset_handler = qla2xxx_eh_device_reset,
7249 .eh_target_reset_handler = qla2xxx_eh_target_reset,
7250 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
7251 .eh_host_reset_handler = qla2xxx_eh_host_reset,
7252
7253 .slave_configure = qla2xxx_slave_configure,
7254
7255 .slave_alloc = qla2xxx_slave_alloc,
7256 .slave_destroy = qla2xxx_slave_destroy,
7257 .scan_finished = qla2xxx_scan_finished,
7258 .scan_start = qla2xxx_scan_start,
7259 .change_queue_depth = scsi_change_queue_depth,
7260 .map_queues = qla2xxx_map_queues,
7261 .this_id = -1,
7262 .cmd_per_lun = 3,
7263 .sg_tablesize = SG_ALL,
7264
7265 .max_sectors = 0xFFFF,
7266 .shost_attrs = qla2x00_host_attrs,
7267
7268 .supported_mode = MODE_INITIATOR,
7269 .track_queue_depth = 1,
7270};
7271
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07007272static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07007273 .error_detected = qla2xxx_pci_error_detected,
7274 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7275 .slot_reset = qla2xxx_pci_slot_reset,
7276 .resume = qla2xxx_pci_resume,
Quinn Tran590f8062019-01-24 23:23:40 -08007277 .reset_prepare = qla_pci_reset_prepare,
7278 .reset_done = qla_pci_reset_done,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007279};
7280
Andrew Vasquez54333832005-11-09 15:49:04 -08007281static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007282 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7283 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7284 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7285 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7286 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7287 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7288 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7289 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7290 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007291 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007292 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7293 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07007294 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007295 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007296 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07007297 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04007298 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04007299 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007300 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05007301 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04007302 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04007303 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07007304 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7305 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7306 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7307 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7308 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
Andrew Vasquez54333832005-11-09 15:49:04 -08007309 { 0 },
7310};
7311MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7312
Andrew Vasquezfca29702005-07-06 10:31:47 -07007313static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07007314 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06007315 .driver = {
7316 .owner = THIS_MODULE,
7317 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07007318 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007319 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08007320 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07007321 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007322 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07007323};
7324
Al Viro75ef9de2013-04-04 19:09:41 -04007325static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007326 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02007327 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007328};
7329
Linus Torvalds1da177e2005-04-16 15:20:36 -07007330/**
7331 * qla2x00_module_init - Module initialization.
7332 **/
7333static int __init
7334qla2x00_module_init(void)
7335{
Andrew Vasquezfca29702005-07-06 10:31:47 -07007336 int ret = 0;
7337
Linus Torvalds1da177e2005-04-16 15:20:36 -07007338 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007339 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09007340 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007341 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007342 ql_log(ql_log_fatal, NULL, 0x0001,
7343 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007344 return -ENOMEM;
7345 }
7346
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007347 /* Initialize target kmem_cache and mem_pools */
7348 ret = qlt_init();
7349 if (ret < 0) {
Bart Van Asschec794d242019-04-04 12:44:46 -07007350 goto destroy_cache;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007351 } else if (ret > 0) {
7352 /*
7353 * If initiator mode is explictly disabled by qlt_init(),
7354 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7355 * performing scsi_scan_target() during LOOP UP event.
7356 */
7357 qla2xxx_transport_functions.disable_target_scan = 1;
7358 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7359 }
7360
Linus Torvalds1da177e2005-04-16 15:20:36 -07007361 /* Derive version string. */
7362 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07007363 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07007364 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07007365 if (ql2xextended_error_logging == 1)
7366 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07007367
Quinn Tran0645cb82018-09-11 10:18:18 -07007368 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7369 qla_insert_tgt_attrs();
7370
Andrew Vasquez1c97a122005-04-21 16:13:36 -04007371 qla2xxx_transport_template =
7372 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007373 if (!qla2xxx_transport_template) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007374 ql_log(ql_log_fatal, NULL, 0x0002,
7375 "fc_attach_transport failed...Failing load!.\n");
Bart Van Asschec794d242019-04-04 12:44:46 -07007376 ret = -ENODEV;
7377 goto qlt_exit;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007378 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007379
7380 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7381 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007382 ql_log(ql_log_fatal, NULL, 0x0003,
7383 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007384 }
7385
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007386 qla2xxx_transport_vport_template =
7387 fc_attach_transport(&qla2xxx_transport_vport_functions);
7388 if (!qla2xxx_transport_vport_template) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007389 ql_log(ql_log_fatal, NULL, 0x0004,
7390 "fc_attach_transport vport failed...Failing load!.\n");
Bart Van Asschec794d242019-04-04 12:44:46 -07007391 ret = -ENODEV;
7392 goto unreg_chrdev;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007393 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007394 ql_log(ql_log_info, NULL, 0x0005,
7395 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07007396 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007397 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007398 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007399 ql_log(ql_log_fatal, NULL, 0x0006,
7400 "pci_register_driver failed...ret=%d Failing load!.\n",
7401 ret);
Bart Van Asschec794d242019-04-04 12:44:46 -07007402 goto release_vport_transport;
Andrew Vasquezfca29702005-07-06 10:31:47 -07007403 }
7404 return ret;
Bart Van Asschec794d242019-04-04 12:44:46 -07007405
7406release_vport_transport:
7407 fc_release_transport(qla2xxx_transport_vport_template);
7408
7409unreg_chrdev:
7410 if (apidev_major >= 0)
7411 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7412 fc_release_transport(qla2xxx_transport_template);
7413
7414qlt_exit:
7415 qlt_exit();
7416
7417destroy_cache:
7418 kmem_cache_destroy(srb_cachep);
7419 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007420}
7421
7422/**
7423 * qla2x00_module_exit - Module cleanup.
7424 **/
7425static void __exit
7426qla2x00_module_exit(void)
7427{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007428 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08007429 qla2x00_release_firmware();
Thomas Meyer75c1d482018-12-02 21:52:11 +01007430 kmem_cache_destroy(ctx_cachep);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007431 fc_release_transport(qla2xxx_transport_vport_template);
Bart Van Assche59c209a2019-04-04 12:44:47 -07007432 if (apidev_major >= 0)
7433 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
7434 fc_release_transport(qla2xxx_transport_template);
7435 qlt_exit();
7436 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007437}
7438
7439module_init(qla2x00_module_init);
7440module_exit(qla2x00_module_exit);
7441
7442MODULE_AUTHOR("QLogic Corporation");
7443MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7444MODULE_LICENSE("GPL");
7445MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07007446MODULE_FIRMWARE(FW_FILE_ISP21XX);
7447MODULE_FIRMWARE(FW_FILE_ISP22XX);
7448MODULE_FIRMWARE(FW_FILE_ISP2300);
7449MODULE_FIRMWARE(FW_FILE_ISP2322);
7450MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08007451MODULE_FIRMWARE(FW_FILE_ISP25XX);