blob: 012125e2d6cf438552e1b0bbf0a8e4c15fbf7e3a [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 */
Joe Carnucciof8f97b02019-03-12 11:08:16 -070045uint ql_errlev = ql_log_all;
Giridhar Malavalia9083012010-04-12 17:59:55 -070046
Saurav Kashyapfa492632012-11-21 02:40:29 -050047static int ql2xenableclass2;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040048module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
49MODULE_PARM_DESC(ql2xenableclass2,
50 "Specify if Class 2 operations are supported from the very "
51 "beginning. Default is 0 - class 2 not supported.");
52
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054int ql2xlogintimeout = 20;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080055module_param(ql2xlogintimeout, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056MODULE_PARM_DESC(ql2xlogintimeout,
57 "Login timeout value in seconds.");
58
Andrew Vasqueza7b61842007-05-07 07:42:59 -070059int qlport_down_retry;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080060module_param(qlport_down_retry, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070062 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 "a PORT-DOWN status.");
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065int ql2xplogiabsentdevice;
66module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
67MODULE_PARM_DESC(ql2xplogiabsentdevice,
68 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070069 "a Fabric scan. This is needed for several broken switches. "
Masanari Iida0d52e642018-10-28 14:05:48 +090070 "Default is 0 - no PLOGI. 1 - perform PLOGI.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072int ql2xloginretrycount = 0;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080073module_param(ql2xloginretrycount, int, S_IRUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074MODULE_PARM_DESC(ql2xloginretrycount,
75 "Specify an alternate value for the NVRAM login retry count.");
76
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070077int ql2xallocfwdump = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -080078module_param(ql2xallocfwdump, int, S_IRUGO);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070079MODULE_PARM_DESC(ql2xallocfwdump,
80 "Option to enable allocation of memory for a firmware dump "
81 "during HBA initialization. Memory allocation requirements "
82 "vary by ISP type. Default is 1 - allocate memory.");
83
Andrew Vasquez11010fe2006-10-06 09:54:59 -070084int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070085module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -040086module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070087MODULE_PARM_DESC(ql2xextended_error_logging,
Saurav Kashyap3ce88662011-07-14 12:00:12 -070088 "Option to enable extended error logging,\n"
89 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
90 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
91 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
92 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
93 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
94 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
95 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
96 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
Chad Dupuis29f9f902012-11-21 02:40:41 -050097 "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
98 "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -070099 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
Chad Dupuiscfb09192011-11-18 09:03:07 -0800100 "\t\t0x1e400000 - Preferred value for capturing essential "
101 "debug information (equivalent to old "
102 "ql2xextended_error_logging=1).\n"
Saurav Kashyap3ce88662011-07-14 12:00:12 -0700103 "\t\tDo LOGICAL OR of the value to enable more than one level");
Andrew Vasquez01819442006-06-23 16:11:10 -0700104
Giridhar Malavalia9083012010-04-12 17:59:55 -0700105int ql2xshiftctondsd = 6;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800106module_param(ql2xshiftctondsd, int, S_IRUGO);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700107MODULE_PARM_DESC(ql2xshiftctondsd,
108 "Set to control shifting of command type processing "
109 "based on total number of SG elements.");
110
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -0700111int ql2xfdmienable=1;
Himanshu Madhanide187df2014-09-25 05:16:50 -0400112module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400113module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
Andrew Vasquezcca53352005-08-26 19:08:30 -0700114MODULE_PARM_DESC(ql2xfdmienable,
Ferenc Wagner7794a5a2010-03-23 18:14:59 +0100115 "Enables FDMI registrations. "
116 "0 - no FDMI. Default is 1 - perform FDMI.");
Andrew Vasquezcca53352005-08-26 19:08:30 -0700117
Michael Hernandezd213a4b2017-08-23 15:05:20 -0700118#define MAX_Q_DEPTH 64
Chad Dupuis50280c02013-10-30 03:38:14 -0400119static int ql2xmaxqdepth = MAX_Q_DEPTH;
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700120module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
121MODULE_PARM_DESC(ql2xmaxqdepth,
Chad Dupuise92e4a82012-08-22 14:21:23 -0400122 "Maximum queue depth to set for each LUN. "
Michael Hernandezd213a4b2017-08-23 15:05:20 -0700123 "Default is 64.");
Andrew Vasquezdf7baa52006-10-13 09:33:39 -0700124
Duane Grigsbye84067d2017-06-21 13:48:43 -0700125#if (IS_ENABLED(CONFIG_NVME_FC))
126int ql2xenabledif;
127#else
Arun Easi9e522cd2012-08-22 14:21:31 -0400128int ql2xenabledif = 2;
Duane Grigsbye84067d2017-06-21 13:48:43 -0700129#endif
Arun Easi9e522cd2012-08-22 14:21:31 -0400130module_param(ql2xenabledif, int, S_IRUGO);
Arun Easibad75002010-05-04 15:01:30 -0700131MODULE_PARM_DESC(ql2xenabledif,
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600132 " Enable T10-CRC-DIF:\n"
133 " Default is 2.\n"
134 " 0 -- No DIF Support\n"
135 " 1 -- Enable DIF for all types\n"
136 " 2 -- Enable DIF for all types, except Type 0.\n");
Arun Easibad75002010-05-04 15:01:30 -0700137
Duane Grigsbye84067d2017-06-21 13:48:43 -0700138#if (IS_ENABLED(CONFIG_NVME_FC))
139int ql2xnvmeenable = 1;
140#else
141int ql2xnvmeenable;
142#endif
143module_param(ql2xnvmeenable, int, 0644);
144MODULE_PARM_DESC(ql2xnvmeenable,
145 "Enables NVME support. "
146 "0 - no NVMe. Default is Y");
147
Arun Easi8cb20492011-08-16 11:29:22 -0700148int ql2xenablehba_err_chk = 2;
Arun Easibad75002010-05-04 15:01:30 -0700149module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
150MODULE_PARM_DESC(ql2xenablehba_err_chk,
Arun Easi8cb20492011-08-16 11:29:22 -0700151 " Enable T10-CRC-DIF Error isolation by HBA:\n"
Steven J. Magnanib97f5d02014-02-04 12:50:35 -0600152 " Default is 2.\n"
Arun Easi8cb20492011-08-16 11:29:22 -0700153 " 0 -- Error isolation disabled\n"
154 " 1 -- Error isolation enabled only for DIX Type 0\n"
155 " 2 -- Error isolation enabled for all Types\n");
Arun Easibad75002010-05-04 15:01:30 -0700156
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700157int ql2xiidmaenable=1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800158module_param(ql2xiidmaenable, int, S_IRUGO);
Andrew Vasqueze5896bd2008-07-10 16:55:52 -0700159MODULE_PARM_DESC(ql2xiidmaenable,
160 "Enables iIDMA settings "
161 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
162
Michael Hernandezd7459522016-12-12 14:40:07 -0800163int ql2xmqsupport = 1;
164module_param(ql2xmqsupport, int, S_IRUGO);
165MODULE_PARM_DESC(ql2xmqsupport,
166 "Enable on demand multiple queue pairs support "
167 "Default is 1 for supported. "
168 "Set it to 0 to turn off mq qpair support.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700169
170int ql2xfwloadbin;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700171module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Joe Carnuccioa2b3e012016-07-06 11:14:21 -0400172module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
Andrew Vasqueze337d902009-04-06 22:33:49 -0700173MODULE_PARM_DESC(ql2xfwloadbin,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700174 "Option to specify location from which to load ISP firmware:.\n"
175 " 2 -- load firmware via the request_firmware() (hotplug).\n"
Andrew Vasqueze337d902009-04-06 22:33:49 -0700176 " interface.\n"
177 " 1 -- load firmware from flash.\n"
178 " 0 -- use default semantics.\n");
179
Andrew Vasquezae97c912010-02-18 10:07:28 -0800180int ql2xetsenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800181module_param(ql2xetsenable, int, S_IRUGO);
Andrew Vasquezae97c912010-02-18 10:07:28 -0800182MODULE_PARM_DESC(ql2xetsenable,
183 "Enables firmware ETS burst."
184 "Default is 0 - skip ETS enablement.");
185
Giridhar Malavali69078692010-05-28 15:08:28 -0700186int ql2xdbwr = 1;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700187module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
Giridhar Malavalia9083012010-04-12 17:59:55 -0700188MODULE_PARM_DESC(ql2xdbwr,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700189 "Option to specify scheme for request queue posting.\n"
190 " 0 -- Regular doorbell.\n"
191 " 1 -- CAMRAM doorbell (faster).\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700192
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700193int ql2xtargetreset = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800194module_param(ql2xtargetreset, int, S_IRUGO);
Giridhar Malavalif4c496c2010-05-04 15:01:33 -0700195MODULE_PARM_DESC(ql2xtargetreset,
196 "Enable target reset."
197 "Default is 1 - use hw defaults.");
198
Chad Dupuis4da26e12010-10-15 11:27:40 -0700199int ql2xgffidenable;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800200module_param(ql2xgffidenable, int, S_IRUGO);
Chad Dupuis4da26e12010-10-15 11:27:40 -0700201MODULE_PARM_DESC(ql2xgffidenable,
202 "Enables GFF_ID checks of port type. "
203 "Default is 0 - Do not use GFF_ID information.");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700204
himanshu.madhani@cavium.com043dc1d2017-08-23 15:05:19 -0700205int ql2xasynctmfenable = 1;
Joe Carnucciof2019cb2010-12-21 16:00:22 -0800206module_param(ql2xasynctmfenable, int, S_IRUGO);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700207MODULE_PARM_DESC(ql2xasynctmfenable,
208 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
Masanari Iida84e13c42018-09-11 18:48:11 +0900209 "Default is 1 - Issue TM IOCBs via mailbox mechanism.");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700210
211int ql2xdontresethba;
Chad Dupuis86e45bf2011-08-16 11:31:47 -0700212module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
Giridhar Malavalied0de872011-03-30 11:46:29 -0700213MODULE_PARM_DESC(ql2xdontresethba,
Giridhar Malavali08de2842011-08-16 11:31:44 -0700214 "Option to specify reset behaviour.\n"
215 " 0 (Default) -- Reset on failure.\n"
216 " 1 -- Do not reset on failure.\n");
Giridhar Malavalied0de872011-03-30 11:46:29 -0700217
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200218uint64_t ql2xmaxlun = MAX_LUNS;
219module_param(ql2xmaxlun, ullong, S_IRUGO);
Andrew Vasquez82515922011-05-10 11:30:13 -0700220MODULE_PARM_DESC(ql2xmaxlun,
221 "Defines the maximum LU number to register with the SCSI "
222 "midlayer. Default is 65535.");
223
Giridhar Malavali08de2842011-08-16 11:31:44 -0700224int ql2xmdcapmask = 0x1F;
225module_param(ql2xmdcapmask, int, S_IRUGO);
226MODULE_PARM_DESC(ql2xmdcapmask,
227 "Set the Minidump driver capture mask level. "
Giridhar Malavali6e96fa72011-11-18 09:03:14 -0800228 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700229
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800230int ql2xmdenable = 1;
Giridhar Malavali08de2842011-08-16 11:31:44 -0700231module_param(ql2xmdenable, int, S_IRUGO);
232MODULE_PARM_DESC(ql2xmdenable,
233 "Enable/disable MiniDump. "
Giridhar Malavali3aadff32011-11-18 09:02:14 -0800234 "0 - MiniDump disabled. "
235 "1 (Default) - MiniDump enabled.");
Giridhar Malavali08de2842011-08-16 11:31:44 -0700236
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500237int ql2xexlogins = 0;
238module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
239MODULE_PARM_DESC(ql2xexlogins,
240 "Number of extended Logins. "
241 "0 (Default)- Disabled.");
242
Quinn Tran99e1b682017-06-02 09:12:03 -0700243int ql2xexchoffld = 1024;
244module_param(ql2xexchoffld, uint, 0644);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500245MODULE_PARM_DESC(ql2xexchoffld,
Quinn Tran99e1b682017-06-02 09:12:03 -0700246 "Number of target exchanges.");
247
248int ql2xiniexchg = 1024;
249module_param(ql2xiniexchg, uint, 0644);
250MODULE_PARM_DESC(ql2xiniexchg,
251 "Number of initiator exchanges.");
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500252
Himanshu Madhanif198caf2016-01-27 12:03:30 -0500253int ql2xfwholdabts = 0;
254module_param(ql2xfwholdabts, int, S_IRUGO);
255MODULE_PARM_DESC(ql2xfwholdabts,
256 "Allow FW to hold status IOCB until ABTS rsp received. "
257 "0 (Default) Do not set fw option. "
258 "1 - Set fw option to hold ABTS.");
259
Quinn Tran41dc5292017-01-19 22:28:03 -0800260int ql2xmvasynctoatio = 1;
261module_param(ql2xmvasynctoatio, int, S_IRUGO|S_IWUSR);
262MODULE_PARM_DESC(ql2xmvasynctoatio,
263 "Move PUREX, ABTS RX and RIDA IOCBs to ATIOQ"
264 "0 (Default). Do not move IOCBs"
265 "1 - Move IOCBs.");
266
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700267int ql2xautodetectsfp = 1;
268module_param(ql2xautodetectsfp, int, 0444);
269MODULE_PARM_DESC(ql2xautodetectsfp,
270 "Detect SFP range and set appropriate distance.\n"
271 "1 (Default): Enable\n");
272
Himanshu Madhanie7240af2017-10-13 09:34:03 -0700273int ql2xenablemsix = 1;
274module_param(ql2xenablemsix, int, 0444);
275MODULE_PARM_DESC(ql2xenablemsix,
276 "Set to enable MSI or MSI-X interrupt mechanism.\n"
277 " Default is 1, enable MSI-X interrupt mechanism.\n"
278 " 0 -- enable traditional pin-based mechanism.\n"
279 " 1 -- enable MSI-X interrupt mechanism.\n"
280 " 2 -- enable MSI interrupt mechanism.\n");
281
Quinn Tran9ecf0b02017-12-28 12:33:19 -0800282int qla2xuseresexchforels;
283module_param(qla2xuseresexchforels, int, 0444);
284MODULE_PARM_DESC(qla2xuseresexchforels,
285 "Reserve 1/2 of emergency exchanges for ELS.\n"
286 " 0 (default): disabled");
287
Martin K. Petersen7855d2b2018-12-21 09:33:44 -0800288int ql2xprotmask;
289module_param(ql2xprotmask, int, 0644);
290MODULE_PARM_DESC(ql2xprotmask,
291 "Override DIF/DIX protection capabilities mask\n"
292 "Default is 0 which sets protection mask based on "
293 "capabilities reported by HBA firmware.\n");
294
295int ql2xprotguard;
296module_param(ql2xprotguard, int, 0644);
297MODULE_PARM_DESC(ql2xprotguard, "Override choice of DIX checksum\n"
298 " 0 -- Let HBA firmware decide\n"
299 " 1 -- Force T10 CRC\n"
300 " 2 -- Force IP checksum\n");
301
Giridhar Malavali50b81272018-12-21 09:33:45 -0800302int ql2xdifbundlinginternalbuffers;
303module_param(ql2xdifbundlinginternalbuffers, int, 0644);
304MODULE_PARM_DESC(ql2xdifbundlinginternalbuffers,
305 "Force using internal buffers for DIF information\n"
306 "0 (Default). Based on check.\n"
307 "1 Force using internal buffers\n");
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700310 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 */
312static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500313static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800314static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
315static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500316static void qla2xxx_slave_destroy(struct scsi_device *);
Jeff Garzikf2812332010-11-16 02:10:29 -0500317static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318static int qla2xxx_eh_abort(struct scsi_cmnd *);
319static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700320static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
322static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Joe Lawrence1a2fbf12014-08-26 17:11:18 -0400324static void qla2x00_clear_drv_active(struct qla_hw_data *);
Saurav Kashyap34912552013-06-25 11:27:18 -0400325static void qla2x00_free_device(scsi_qla_host_t *);
Michael Hernandez56012362016-12-12 14:40:08 -0800326static int qla2xxx_map_queues(struct Scsi_Host *shost);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700327static void qla2x00_destroy_deferred_work(struct qla_hw_data *);
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700328
Quinn Tran45235022018-07-18 14:29:53 -0700329
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700330struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700332 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700333 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700334
Christoph Hellwigb6a05c82017-01-30 13:18:58 +0100335 .eh_timed_out = fc_eh_timed_out,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700336 .eh_abort_handler = qla2xxx_eh_abort,
337 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700338 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700339 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
340 .eh_host_reset_handler = qla2xxx_eh_host_reset,
341
342 .slave_configure = qla2xxx_slave_configure,
343
344 .slave_alloc = qla2xxx_slave_alloc,
345 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700346 .scan_finished = qla2xxx_scan_finished,
347 .scan_start = qla2xxx_scan_start,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100348 .change_queue_depth = scsi_change_queue_depth,
Michael Hernandez56012362016-12-12 14:40:08 -0800349 .map_queues = qla2xxx_map_queues,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700350 .this_id = -1,
351 .cmd_per_lun = 3,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700352 .sg_tablesize = SG_ALL,
353
354 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700355 .shost_attrs = qla2x00_host_attrs,
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400356
357 .supported_mode = MODE_INITIATOR,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100358 .track_queue_depth = 1,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700359};
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700362struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364/* TODO Convert to inlines
365 *
366 * Timer routines
367 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700369__inline__ void
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700370qla2x00_start_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Kees Cook8e5f4ba2017-09-03 13:23:32 -0700372 timer_setup(&vha->timer, qla2x00_timer, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800373 vha->timer.expires = jiffies + interval * HZ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800374 add_timer(&vha->timer);
375 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800379qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Giridhar Malavalia9083012010-04-12 17:59:55 -0700381 /* Currently used for 82XX only. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700382 if (vha->device_flags & DFLG_DEV_FAILED) {
383 ql_dbg(ql_dbg_timer, vha, 0x600d,
384 "Device in a failed state, returning.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700385 return;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700386 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700387
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800388 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
Adrian Bunka824ebb2008-01-17 09:02:15 -0800391static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800392qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800394 del_timer_sync(&vha->timer);
395 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398static int qla2x00_do_dpc(void *data);
399
400static void qla2x00_rst_aen(scsi_qla_host_t *);
401
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800402static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
403 struct req_que **, struct rsp_que **);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -0700404static void qla2x00_free_fw_dump(struct qla_hw_data *);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800405static void qla2x00_mem_free(struct qla_hw_data *);
Michael Hernandezd7459522016-12-12 14:40:07 -0800406int qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
407 struct qla_qpair *qpair);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409/* -------------------------------------------------------------------------- */
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700410static void qla_init_base_qpair(struct scsi_qla_host *vha, struct req_que *req,
411 struct rsp_que *rsp)
412{
413 struct qla_hw_data *ha = vha->hw;
414 rsp->qpair = ha->base_qpair;
415 rsp->req = req;
Quinn Tran06910942018-09-04 14:19:12 -0700416 ha->base_qpair->hw = ha;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700417 ha->base_qpair->req = req;
418 ha->base_qpair->rsp = rsp;
419 ha->base_qpair->vha = vha;
420 ha->base_qpair->qp_lock_ptr = &ha->hardware_lock;
421 ha->base_qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
422 ha->base_qpair->msix = &ha->msix_entries[QLA_MSIX_RSP_Q];
Quinn Tran6a629462018-09-04 14:19:15 -0700423 ha->base_qpair->srb_mempool = ha->srb_mempool;
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700424 INIT_LIST_HEAD(&ha->base_qpair->hints_list);
425 ha->base_qpair->enable_class_2 = ql2xenableclass2;
426 /* init qpair to this cpu. Will adjust at run time. */
Bart Van Assche86531882017-11-06 11:59:05 -0800427 qla_cpu_update(rsp->qpair, raw_smp_processor_id());
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700428 ha->base_qpair->pdev = ha->pdev;
429
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700430 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700431 ha->base_qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
432}
433
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400434static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
435 struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800436{
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700437 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
Kees Cook6396bb22018-06-12 14:03:40 -0700438 ha->req_q_map = kcalloc(ha->max_req_queues, sizeof(struct req_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800439 GFP_KERNEL);
440 if (!ha->req_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700441 ql_log(ql_log_fatal, vha, 0x003b,
442 "Unable to allocate memory for request queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800443 goto fail_req_map;
444 }
445
Kees Cook6396bb22018-06-12 14:03:40 -0700446 ha->rsp_q_map = kcalloc(ha->max_rsp_queues, sizeof(struct rsp_que *),
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800447 GFP_KERNEL);
448 if (!ha->rsp_q_map) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700449 ql_log(ql_log_fatal, vha, 0x003c,
450 "Unable to allocate memory for response queue ptrs.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800451 goto fail_rsp_map;
452 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800453
Quinn Trane326d222017-06-13 20:47:18 -0700454 ha->base_qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
455 if (ha->base_qpair == NULL) {
456 ql_log(ql_log_warn, vha, 0x00e0,
457 "Failed to allocate base queue pair memory.\n");
458 goto fail_base_qpair;
459 }
460
Quinn Tran8abfa9e2017-06-13 20:47:24 -0700461 qla_init_base_qpair(vha, req, rsp);
Quinn Trane326d222017-06-13 20:47:18 -0700462
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -0700463 if ((ql2xmqsupport || ql2xnvmeenable) && ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -0800464 ha->queue_pair_map = kcalloc(ha->max_qpairs, sizeof(struct qla_qpair *),
465 GFP_KERNEL);
466 if (!ha->queue_pair_map) {
467 ql_log(ql_log_fatal, vha, 0x0180,
468 "Unable to allocate memory for queue pair ptrs.\n");
469 goto fail_qpair_map;
470 }
Michael Hernandezd7459522016-12-12 14:40:07 -0800471 }
472
Chad Dupuis9a347ff2012-05-15 14:34:14 -0400473 /*
474 * Make sure we record at least the request and response queue zero in
475 * case we need to free them if part of the probe fails.
476 */
477 ha->rsp_q_map[0] = rsp;
478 ha->req_q_map[0] = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800479 set_bit(0, ha->rsp_qid_map);
480 set_bit(0, ha->req_qid_map);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -0500481 return 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800482
Michael Hernandezd7459522016-12-12 14:40:07 -0800483fail_qpair_map:
Quinn Tran82de8022017-06-13 20:47:17 -0700484 kfree(ha->base_qpair);
485 ha->base_qpair = NULL;
486fail_base_qpair:
Michael Hernandezd7459522016-12-12 14:40:07 -0800487 kfree(ha->rsp_q_map);
488 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800489fail_rsp_map:
490 kfree(ha->req_q_map);
491 ha->req_q_map = NULL;
492fail_req_map:
493 return -ENOMEM;
494}
495
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700496static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800497{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400498 if (IS_QLAFX00(ha)) {
499 if (req && req->ring_fx00)
500 dma_free_coherent(&ha->pdev->dev,
501 (req->length_fx00 + 1) * sizeof(request_t),
502 req->ring_fx00, req->dma_fx00);
503 } else if (req && req->ring)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800504 dma_free_coherent(&ha->pdev->dev,
505 (req->length + 1) * sizeof(request_t),
506 req->ring, req->dma);
507
Bill Kuzeja6d634062018-03-23 10:37:25 -0400508 if (req)
Chad Dupuis8d93f552013-01-30 03:34:37 -0500509 kfree(req->outstanding_cmds);
Bill Kuzeja6d634062018-03-23 10:37:25 -0400510
511 kfree(req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800512}
513
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700514static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
515{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400516 if (IS_QLAFX00(ha)) {
Meelis Roos3f6c9be2018-03-08 15:44:37 +0200517 if (rsp && rsp->ring_fx00)
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400518 dma_free_coherent(&ha->pdev->dev,
519 (rsp->length_fx00 + 1) * sizeof(request_t),
520 rsp->ring_fx00, rsp->dma_fx00);
521 } else if (rsp && rsp->ring) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700522 dma_free_coherent(&ha->pdev->dev,
523 (rsp->length + 1) * sizeof(response_t),
524 rsp->ring, rsp->dma);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400525 }
Bill Kuzeja6d634062018-03-23 10:37:25 -0400526 kfree(rsp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700527}
528
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800529static void qla2x00_free_queues(struct qla_hw_data *ha)
530{
531 struct req_que *req;
532 struct rsp_que *rsp;
533 int cnt;
Quinn Tran093df732016-12-12 14:40:09 -0800534 unsigned long flags;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800535
Quinn Tran82de8022017-06-13 20:47:17 -0700536 if (ha->queue_pair_map) {
537 kfree(ha->queue_pair_map);
538 ha->queue_pair_map = NULL;
539 }
540 if (ha->base_qpair) {
541 kfree(ha->base_qpair);
542 ha->base_qpair = NULL;
543 }
544
Quinn Tran093df732016-12-12 14:40:09 -0800545 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700546 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500547 if (!test_bit(cnt, ha->req_qid_map))
548 continue;
549
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800550 req = ha->req_q_map[cnt];
Quinn Tran093df732016-12-12 14:40:09 -0800551 clear_bit(cnt, ha->req_qid_map);
552 ha->req_q_map[cnt] = NULL;
553
554 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700555 qla2x00_free_req_que(ha, req);
Quinn Tran093df732016-12-12 14:40:09 -0800556 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700557 }
Quinn Tran093df732016-12-12 14:40:09 -0800558 spin_unlock_irqrestore(&ha->hardware_lock, flags);
559
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700560 kfree(ha->req_q_map);
561 ha->req_q_map = NULL;
562
Quinn Tran093df732016-12-12 14:40:09 -0800563
564 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700565 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
Quinn Trancb432852016-02-04 11:45:16 -0500566 if (!test_bit(cnt, ha->rsp_qid_map))
567 continue;
568
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700569 rsp = ha->rsp_q_map[cnt];
Dave Jonesc3c42392016-12-27 13:13:21 -0500570 clear_bit(cnt, ha->rsp_qid_map);
Quinn Tran093df732016-12-12 14:40:09 -0800571 ha->rsp_q_map[cnt] = NULL;
572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700573 qla2x00_free_rsp_que(ha, rsp);
Quinn Tran093df732016-12-12 14:40:09 -0800574 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800575 }
Quinn Tran093df732016-12-12 14:40:09 -0800576 spin_unlock_irqrestore(&ha->hardware_lock, flags);
577
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800578 kfree(ha->rsp_q_map);
579 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800580}
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 static char *pci_bus_modes[] = {
587 "33", "66", "100", "133",
588 };
589 uint16_t pci_bus;
590
591 strcpy(str, "PCI");
592 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
593 if (pci_bus) {
594 strcat(str, "-X (");
595 strcat(str, pci_bus_modes[pci_bus]);
596 } else {
597 pci_bus = (ha->pci_attr & BIT_8) >> 8;
598 strcat(str, " (");
599 strcat(str, pci_bus_modes[pci_bus]);
600 }
601 strcat(str, " MHz)");
602
603 return (str);
604}
605
Andrew Vasquezfca29702005-07-06 10:31:47 -0700606static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800607qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700608{
609 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800610 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700611 uint32_t pci_bus;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700612
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600613 if (pci_is_pcie(ha->pdev)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700614 char lwstr[6];
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600615 uint32_t lstat, lspeed, lwidth;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700616
Bjorn Helgaas62a276f2013-09-06 11:26:24 -0600617 pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
618 lspeed = lstat & PCI_EXP_LNKCAP_SLS;
619 lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700620
621 strcpy(str, "PCIe (");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500622 switch (lspeed) {
623 case 1:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700624 strcat(str, "2.5GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500625 break;
626 case 2:
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700627 strcat(str, "5.0GT/s ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500628 break;
629 case 3:
630 strcat(str, "8.0GT/s ");
631 break;
632 default:
Andrew Vasquezfca29702005-07-06 10:31:47 -0700633 strcat(str, "<unknown> ");
Saurav Kashyap49300af2012-11-21 02:40:34 -0500634 break;
635 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700636 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
637 strcat(str, lwstr);
638
639 return str;
640 }
641
642 strcpy(str, "PCI");
643 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
644 if (pci_bus == 0 || pci_bus == 8) {
645 strcat(str, " (");
646 strcat(str, pci_bus_modes[pci_bus >> 3]);
647 } else {
648 strcat(str, "-X ");
649 if (pci_bus & BIT_2)
650 strcat(str, "Mode 2");
651 else
652 strcat(str, "Mode 1");
653 strcat(str, " (");
654 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
655 }
656 strcat(str, " MHz)");
657
658 return str;
659}
660
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800661static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400662qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
664 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800665 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700666
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400667 snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
668 ha->fw_minor_version, ha->fw_subminor_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 if (ha->fw_attributes & BIT_9) {
671 strcat(str, "FLX");
672 return (str);
673 }
674
675 switch (ha->fw_attributes & 0xFF) {
676 case 0x7:
677 strcat(str, "EF");
678 break;
679 case 0x17:
680 strcat(str, "TP");
681 break;
682 case 0x37:
683 strcat(str, "IP");
684 break;
685 case 0x77:
686 strcat(str, "VI");
687 break;
688 default:
689 sprintf(un_str, "(%x)", ha->fw_attributes);
690 strcat(str, un_str);
691 break;
692 }
693 if (ha->fw_attributes & 0x100)
694 strcat(str, "X");
695
696 return (str);
697}
698
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800699static char *
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400700qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700701{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800702 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700703
Himanshu Madhanidf57cab2014-09-25 05:16:46 -0400704 snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800705 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700706 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700707}
708
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800709void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800710qla2x00_sp_free_dma(void *ptr)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700711{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800712 srb_t *sp = ptr;
713 struct qla_hw_data *ha = sp->vha->hw;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800714 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800715 void *ctx = GET_CMD_CTX_SP(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700716
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800717 if (sp->flags & SRB_DMA_VALID) {
718 scsi_dma_unmap(cmd);
719 sp->flags &= ~SRB_DMA_VALID;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700720 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700721
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800722 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
723 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
724 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
725 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
726 }
Andrew Vasquezfca29702005-07-06 10:31:47 -0700727
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700728 if (!ctx)
729 goto end;
730
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800731 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
732 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700733 qla2x00_clean_dsd_pool(ha, ctx);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800734 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
735 }
736
737 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700738 struct crc_context *ctx0 = ctx;
739
740 dma_pool_free(ha->dl_dma_pool, ctx0, ctx0->crc_ctx_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800741 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
742 }
743
744 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700745 struct ct6_dsd *ctx1 = ctx;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800746
747 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700748 ctx1->fcp_cmnd_dma);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800749 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
750 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
751 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
752 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800753 }
754
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700755end:
himanshu.madhani@cavium.com6fcd98f2017-07-21 09:32:23 -0700756 if (sp->type != SRB_NVME_CMD && sp->type != SRB_NVME_LS) {
Duane Grigsby7401bc12017-06-21 13:48:42 -0700757 CMD_SP(cmd) = NULL;
758 qla2x00_rel_sp(sp);
759 }
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800760}
761
Michael Hernandezd7459522016-12-12 14:40:07 -0800762void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800763qla2x00_sp_compl(void *ptr, int res)
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800764{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800765 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800766 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
767
768 cmd->result = res;
769
770 if (atomic_read(&sp->ref_count) == 0) {
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800771 ql_dbg(ql_dbg_io, sp->vha, 0x3015,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800772 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
773 sp, GET_CMD_SP(sp));
774 if (ql2xextended_error_logging & ql_dbg_io)
Hiral Patel8fbdac82015-08-04 13:37:56 -0400775 WARN_ON(atomic_read(&sp->ref_count) == 0);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800776 return;
777 }
778 if (!atomic_dec_and_test(&sp->ref_count))
779 return;
780
Joe Carnucciof3caa992017-08-23 15:05:09 -0700781 sp->free(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800782 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700783}
784
Michael Hernandezd7459522016-12-12 14:40:07 -0800785void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800786qla2xxx_qpair_sp_free_dma(void *ptr)
Michael Hernandezd7459522016-12-12 14:40:07 -0800787{
788 srb_t *sp = (srb_t *)ptr;
789 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
790 struct qla_hw_data *ha = sp->fcport->vha->hw;
791 void *ctx = GET_CMD_CTX_SP(sp);
792
793 if (sp->flags & SRB_DMA_VALID) {
794 scsi_dma_unmap(cmd);
795 sp->flags &= ~SRB_DMA_VALID;
796 }
797
798 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
799 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
800 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
801 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
802 }
803
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700804 if (!ctx)
805 goto end;
806
Michael Hernandezd7459522016-12-12 14:40:07 -0800807 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
808 /* List assured to be having elements */
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700809 qla2x00_clean_dsd_pool(ha, ctx);
Michael Hernandezd7459522016-12-12 14:40:07 -0800810 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
811 }
812
813 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700814 struct crc_context *ctx0 = ctx;
815
816 dma_pool_free(ha->dl_dma_pool, ctx, ctx0->crc_ctx_dma);
Michael Hernandezd7459522016-12-12 14:40:07 -0800817 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
818 }
819
820 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700821 struct ct6_dsd *ctx1 = ctx;
Michael Hernandezd7459522016-12-12 14:40:07 -0800822 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
823 ctx1->fcp_cmnd_dma);
824 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
825 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
826 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
827 mempool_free(ctx1, ha->ctx_mempool);
Giridhar Malavali50b81272018-12-21 09:33:45 -0800828 sp->flags &= ~SRB_FCP_CMND_DMA_VALID;
Michael Hernandezd7459522016-12-12 14:40:07 -0800829 }
Giridhar Malavali50b81272018-12-21 09:33:45 -0800830 if (sp->flags & SRB_DIF_BUNDL_DMA_VALID) {
831 struct crc_context *difctx = sp->u.scmd.ctx;
832 struct dsd_dma *dif_dsd, *nxt_dsd;
833
834 list_for_each_entry_safe(dif_dsd, nxt_dsd,
835 &difctx->ldif_dma_hndl_list, list) {
836 list_del(&dif_dsd->list);
837 dma_pool_free(ha->dif_bundl_pool, dif_dsd->dsd_addr,
838 dif_dsd->dsd_list_dma);
839 kfree(dif_dsd);
840 difctx->no_dif_bundl--;
841 }
842
843 list_for_each_entry_safe(dif_dsd, nxt_dsd,
844 &difctx->ldif_dsd_list, list) {
845 list_del(&dif_dsd->list);
846 dma_pool_free(ha->dl_dma_pool, dif_dsd->dsd_addr,
847 dif_dsd->dsd_list_dma);
848 kfree(dif_dsd);
849 difctx->no_ldif_dsd--;
850 }
851
852 if (difctx->no_ldif_dsd) {
853 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
854 "%s: difctx->no_ldif_dsd=%x\n",
855 __func__, difctx->no_ldif_dsd);
856 }
857
858 if (difctx->no_dif_bundl) {
859 ql_dbg(ql_dbg_tgt+ql_dbg_verbose, sp->vha, 0xe022,
860 "%s: difctx->no_dif_bundl=%x\n",
861 __func__, difctx->no_dif_bundl);
862 }
863 sp->flags &= ~SRB_DIF_BUNDL_DMA_VALID;
864 }
865
Joe Carnucciod5ff0ee2017-05-24 18:06:24 -0700866end:
Michael Hernandezd7459522016-12-12 14:40:07 -0800867 CMD_SP(cmd) = NULL;
868 qla2xxx_rel_qpair_sp(sp->qpair, sp);
869}
870
871void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800872qla2xxx_qpair_sp_compl(void *ptr, int res)
Michael Hernandezd7459522016-12-12 14:40:07 -0800873{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800874 srb_t *sp = ptr;
Michael Hernandezd7459522016-12-12 14:40:07 -0800875 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
876
877 cmd->result = res;
878
879 if (atomic_read(&sp->ref_count) == 0) {
880 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3079,
881 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
882 sp, GET_CMD_SP(sp));
883 if (ql2xextended_error_logging & ql_dbg_io)
884 WARN_ON(atomic_read(&sp->ref_count) == 0);
885 return;
886 }
887 if (!atomic_dec_and_test(&sp->ref_count))
888 return;
889
Joe Carnucciof3caa992017-08-23 15:05:09 -0700890 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -0800891 cmd->scsi_done(cmd);
892}
893
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -0400894/* If we are SP1 here, we need to still take and release the host_lock as SP1
895 * does not have the changes necessary to avoid taking host->host_lock.
896 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897static int
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800898qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700899{
Madhuranath Iyengar134ae072011-05-10 11:30:08 -0700900 scsi_qla_host_t *vha = shost_priv(host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700901 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400902 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903 struct qla_hw_data *ha = vha->hw;
904 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700905 srb_t *sp;
906 int rval;
Michael Hernandez56012362016-12-12 14:40:08 -0800907 struct qla_qpair *qpair = NULL;
908 uint32_t tag;
909 uint16_t hwq;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700910
Mauricio Faria de Oliveira04dfaa52016-11-07 17:53:30 -0200911 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
912 cmd->result = DID_NO_CONNECT << 16;
913 goto qc24_fail_command;
914 }
915
Michael Hernandez56012362016-12-12 14:40:08 -0800916 if (ha->mqenable) {
Jens Axboef664a3c2018-11-01 16:36:27 -0600917 tag = blk_mq_unique_tag(cmd->request);
918 hwq = blk_mq_unique_tag_to_hwq(tag);
919 qpair = ha->queue_pair_map[hwq];
Michael Hernandez56012362016-12-12 14:40:08 -0800920
921 if (qpair)
922 return qla2xxx_mqueuecommand(host, cmd, qpair);
Michael Hernandezd7459522016-12-12 14:40:07 -0800923 }
924
Andrew Vasquez85880802009-12-15 21:29:46 -0800925 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700926 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400927 ql_dbg(ql_dbg_aer, vha, 0x9010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700928 "PCI Channel IO permanent failure, exiting "
929 "cmd=%p.\n", cmd);
Seokmann Jub9b12f72009-03-24 09:08:18 -0700930 cmd->result = DID_NO_CONNECT << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700931 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400932 ql_dbg(ql_dbg_aer, vha, 0x9011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700933 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
Andrew Vasquez85880802009-12-15 21:29:46 -0800934 cmd->result = DID_REQUEUE << 16;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700935 }
Seokmann Ju14e660e2007-09-20 14:07:36 -0700936 goto qc24_fail_command;
937 }
938
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400939 rval = fc_remote_port_chkready(rport);
940 if (rval) {
941 cmd->result = rval;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400942 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700943 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
944 cmd, rval);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700945 goto qc24_fail_command;
946 }
947
Arun Easibad75002010-05-04 15:01:30 -0700948 if (!vha->flags.difdix_supported &&
949 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700950 ql_dbg(ql_dbg_io, vha, 0x3004,
951 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
952 cmd);
Arun Easibad75002010-05-04 15:01:30 -0700953 cmd->result = DID_NO_CONNECT << 16;
954 goto qc24_fail_command;
955 }
Chad Dupuisaa651be2012-02-09 11:14:04 -0800956
957 if (!fcport) {
958 cmd->result = DID_NO_CONNECT << 16;
959 goto qc24_fail_command;
960 }
961
Andrew Vasquezfca29702005-07-06 10:31:47 -0700962 if (atomic_read(&fcport->state) != FCS_ONLINE) {
963 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Giridhar Malavali38170fa2010-10-15 11:27:49 -0700964 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700965 ql_dbg(ql_dbg_io, vha, 0x3005,
966 "Returning DNC, fcport_state=%d loop_state=%d.\n",
967 atomic_read(&fcport->state),
968 atomic_read(&base_vha->loop_state));
Andrew Vasquezfca29702005-07-06 10:31:47 -0700969 cmd->result = DID_NO_CONNECT << 16;
970 goto qc24_fail_command;
971 }
Mike Christie7b594132008-08-17 15:24:40 -0500972 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700973 }
974
Chad Dupuise05fe292014-09-25 05:16:59 -0400975 /*
976 * Return target busy if we've received a non-zero retry_delay_timer
977 * in a FCP_RSP.
978 */
Bruno Prémont975f7d42014-12-19 10:29:16 +0100979 if (fcport->retry_delay_timestamp == 0) {
980 /* retry delay not set */
981 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
Chad Dupuise05fe292014-09-25 05:16:59 -0400982 fcport->retry_delay_timestamp = 0;
983 else
984 goto qc24_target_busy;
985
Chad Dupuisb00ee7d2013-02-08 01:57:50 -0500986 sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
Chad Dupuis50280c02013-10-30 03:38:14 -0400987 if (!sp)
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -0800988 goto qc24_host_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700989
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800990 sp->u.scmd.cmd = cmd;
991 sp->type = SRB_SCSI_CMD;
992 atomic_set(&sp->ref_count, 1);
993 CMD_SP(cmd) = (void *)sp;
994 sp->free = qla2x00_sp_free_dma;
995 sp->done = qla2x00_sp_compl;
996
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800997 rval = ha->isp_ops->start_scsi(sp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700998 if (rval != QLA_SUCCESS) {
Chad Dupuis53016ed2012-11-21 02:40:32 -0500999 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001000 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001001 goto qc24_host_busy_free_sp;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07001003
Andrew Vasquezfca29702005-07-06 10:31:47 -07001004 return 0;
1005
1006qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001007 sp->free(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001008
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -08001009qc24_host_busy:
Andrew Vasquezfca29702005-07-06 10:31:47 -07001010 return SCSI_MLQUEUE_HOST_BUSY;
1011
Mike Christie7b594132008-08-17 15:24:40 -05001012qc24_target_busy:
1013 return SCSI_MLQUEUE_TARGET_BUSY;
1014
Andrew Vasquezfca29702005-07-06 10:31:47 -07001015qc24_fail_command:
Madhuranath Iyengarf5e3e402011-02-23 15:27:06 -08001016 cmd->scsi_done(cmd);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001017
1018 return 0;
1019}
1020
Michael Hernandezd7459522016-12-12 14:40:07 -08001021/* For MQ supported I/O */
1022int
1023qla2xxx_mqueuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd,
1024 struct qla_qpair *qpair)
1025{
1026 scsi_qla_host_t *vha = shost_priv(host);
1027 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1028 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
1029 struct qla_hw_data *ha = vha->hw;
1030 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1031 srb_t *sp;
1032 int rval;
1033
1034 rval = fc_remote_port_chkready(rport);
1035 if (rval) {
1036 cmd->result = rval;
1037 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3076,
1038 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
1039 cmd, rval);
1040 goto qc24_fail_command;
1041 }
1042
1043 if (!fcport) {
1044 cmd->result = DID_NO_CONNECT << 16;
1045 goto qc24_fail_command;
1046 }
1047
1048 if (atomic_read(&fcport->state) != FCS_ONLINE) {
1049 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
1050 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1051 ql_dbg(ql_dbg_io, vha, 0x3077,
1052 "Returning DNC, fcport_state=%d loop_state=%d.\n",
1053 atomic_read(&fcport->state),
1054 atomic_read(&base_vha->loop_state));
1055 cmd->result = DID_NO_CONNECT << 16;
1056 goto qc24_fail_command;
1057 }
1058 goto qc24_target_busy;
1059 }
1060
1061 /*
1062 * Return target busy if we've received a non-zero retry_delay_timer
1063 * in a FCP_RSP.
1064 */
1065 if (fcport->retry_delay_timestamp == 0) {
1066 /* retry delay not set */
1067 } else if (time_after(jiffies, fcport->retry_delay_timestamp))
1068 fcport->retry_delay_timestamp = 0;
1069 else
1070 goto qc24_target_busy;
1071
Quinn Tran6a629462018-09-04 14:19:15 -07001072 sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
Michael Hernandezd7459522016-12-12 14:40:07 -08001073 if (!sp)
1074 goto qc24_host_busy;
1075
1076 sp->u.scmd.cmd = cmd;
1077 sp->type = SRB_SCSI_CMD;
1078 atomic_set(&sp->ref_count, 1);
1079 CMD_SP(cmd) = (void *)sp;
1080 sp->free = qla2xxx_qpair_sp_free_dma;
1081 sp->done = qla2xxx_qpair_sp_compl;
1082 sp->qpair = qpair;
1083
1084 rval = ha->isp_ops->start_scsi_mq(sp);
1085 if (rval != QLA_SUCCESS) {
1086 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3078,
1087 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
1088 if (rval == QLA_INTERFACE_ERROR)
1089 goto qc24_fail_command;
1090 goto qc24_host_busy_free_sp;
1091 }
1092
1093 return 0;
1094
1095qc24_host_busy_free_sp:
Joe Carnucciof3caa992017-08-23 15:05:09 -07001096 sp->free(sp);
Michael Hernandezd7459522016-12-12 14:40:07 -08001097
1098qc24_host_busy:
1099 return SCSI_MLQUEUE_HOST_BUSY;
1100
1101qc24_target_busy:
1102 return SCSI_MLQUEUE_TARGET_BUSY;
1103
1104qc24_fail_command:
1105 cmd->scsi_done(cmd);
1106
1107 return 0;
1108}
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110/*
1111 * qla2x00_eh_wait_on_command
1112 * Waits for the command to be returned by the Firmware for some
1113 * max time.
1114 *
1115 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 *
1118 * Return:
1119 * Not Found : 0
1120 * Found : 1
1121 */
1122static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001123qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124{
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001125#define ABORT_POLLING_PERIOD 1000
Chad Dupuis478c3b02014-04-11 16:54:35 -04001126#define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -05001127 unsigned long wait_iter = ABORT_WAIT_ITER;
Andrew Vasquez85880802009-12-15 21:29:46 -08001128 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1129 struct qla_hw_data *ha = vha->hw;
f4f051e2005-04-17 15:02:26 -05001130 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Andrew Vasquez85880802009-12-15 21:29:46 -08001132 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001133 ql_dbg(ql_dbg_taskm, vha, 0x8005,
1134 "Return:eh_wait.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08001135 return ret;
1136 }
1137
Lalit Chandivaded9704322009-08-25 11:36:18 -07001138 while (CMD_SP(cmd) && wait_iter--) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -07001139 msleep(ABORT_POLLING_PERIOD);
f4f051e2005-04-17 15:02:26 -05001140 }
1141 if (CMD_SP(cmd))
1142 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
f4f051e2005-04-17 15:02:26 -05001144 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
1147/*
1148 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001149 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 * <= MAX_RETRIES_OF_ISP_ABORT or
1151 * finally HBA is disabled ie marked offline
1152 *
1153 * Input:
1154 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001155 *
1156 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 * Does context switching-Release SPIN_LOCK
1158 * (if any) before calling this routine.
1159 *
1160 * Return:
1161 * Success (Adapter is online) : 0
1162 * Failed (Adapter is offline/disabled) : 1
1163 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001164int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001165qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
Andrew Vasquezfca29702005-07-06 10:31:47 -07001167 int return_status;
1168 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001169 struct qla_hw_data *ha = vha->hw;
1170 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001172 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001173 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1174 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1175 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1176 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 msleep(1000);
1179 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001180 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001181 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 else
1183 return_status = QLA_FUNCTION_FAILED;
1184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 return (return_status);
1186}
1187
Quinn Tran726b8542017-01-19 22:28:00 -08001188static inline int test_fcport_count(scsi_qla_host_t *vha)
1189{
1190 struct qla_hw_data *ha = vha->hw;
1191 unsigned long flags;
1192 int res;
1193
1194 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
Quinn Tran83548fe2017-06-02 09:12:01 -07001195 ql_dbg(ql_dbg_init, vha, 0x00ec,
1196 "tgt %p, fcport_count=%d\n",
1197 vha, vha->fcport_count);
Quinn Tran726b8542017-01-19 22:28:00 -08001198 res = (vha->fcport_count == 0);
1199 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
1200
1201 return res;
1202}
1203
1204/*
1205 * qla2x00_wait_for_sess_deletion can only be called from remove_one.
1206 * it has dependency on UNLOADING flag to stop device discovery
1207 */
Quinn Tranefa93f42018-07-18 14:29:52 -07001208void
Quinn Tran726b8542017-01-19 22:28:00 -08001209qla2x00_wait_for_sess_deletion(scsi_qla_host_t *vha)
1210{
1211 qla2x00_mark_all_devices_lost(vha, 0);
1212
Joe Carnucciob85e0952017-08-23 15:05:11 -07001213 wait_event_timeout(vha->fcport_waitQ, test_fcport_count(vha), 10*HZ);
Quinn Tran726b8542017-01-19 22:28:00 -08001214}
1215
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001216/*
Sawan Chandak638a1a02014-04-11 16:54:38 -04001217 * qla2x00_wait_for_hba_ready
1218 * Wait till the HBA is ready before doing driver unload
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001219 *
1220 * Input:
1221 * ha - pointer to host adapter structure
1222 *
1223 * Note:
1224 * Does context switching-Release SPIN_LOCK
1225 * (if any) before calling this routine.
1226 *
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001227 */
Sawan Chandak638a1a02014-04-11 16:54:38 -04001228static void
1229qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001230{
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001231 struct qla_hw_data *ha = vha->hw;
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001232 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001233
Dan Carpenter1d483902016-08-03 21:42:32 +03001234 while ((qla2x00_reset_active(vha) || ha->dpc_active ||
1235 ha->flags.mbox_busy) ||
1236 test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
1237 test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
1238 if (test_bit(UNLOADING, &base_vha->dpc_flags))
1239 break;
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001240 msleep(1000);
Sawan Chandak783e0dc2016-07-06 11:14:25 -04001241 }
Lalit Chandivade86fbee82010-05-04 15:01:32 -07001242}
1243
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001244int
1245qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
1246{
1247 int return_status;
1248 unsigned long wait_reset;
1249 struct qla_hw_data *ha = vha->hw;
1250 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1251
1252 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
1253 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
1254 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
1255 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
1256 ha->dpc_active) && time_before(jiffies, wait_reset)) {
1257
1258 msleep(1000);
1259
1260 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1261 ha->flags.chip_reset_done)
1262 break;
1263 }
1264 if (ha->flags.chip_reset_done)
1265 return_status = QLA_SUCCESS;
1266 else
1267 return_status = QLA_FUNCTION_FAILED;
1268
1269 return return_status;
1270}
1271
Quinn Tran585def92018-09-04 14:19:20 -07001272static int
Giridhar Malavali083a4692010-05-28 15:08:18 -07001273sp_get(struct srb *sp)
1274{
Quinn Tran585def92018-09-04 14:19:20 -07001275 if (!refcount_inc_not_zero((refcount_t*)&sp->ref_count))
1276 /* kref get fail */
1277 return ENXIO;
1278 else
1279 return 0;
Giridhar Malavali083a4692010-05-28 15:08:18 -07001280}
1281
Sawan Chandaka4655372016-07-06 11:14:32 -04001282#define ISP_REG_DISCONNECT 0xffffffffU
1283/**************************************************************************
1284* qla2x00_isp_reg_stat
1285*
1286* Description:
1287* Read the host status register of ISP before aborting the command.
1288*
1289* Input:
1290* ha = pointer to host adapter structure.
1291*
1292*
1293* Returns:
1294* Either true or false.
1295*
1296* Note: Return true if there is register disconnect.
1297**************************************************************************/
1298static inline
1299uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
1300{
1301 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001302 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
Sawan Chandaka4655372016-07-06 11:14:32 -04001303
Sawan Chandakbf6061b12017-03-31 14:37:03 -07001304 if (IS_P3P_TYPE(ha))
1305 return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
1306 else
1307 return ((RD_REG_DWORD(&reg->host_status)) ==
1308 ISP_REG_DISCONNECT);
Sawan Chandaka4655372016-07-06 11:14:32 -04001309}
1310
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311/**************************************************************************
1312* qla2xxx_eh_abort
1313*
1314* Description:
1315* The abort function will abort the specified command.
1316*
1317* Input:
1318* cmd = Linux SCSI command packet to be aborted.
1319*
1320* Returns:
1321* Either SUCCESS or FAILED.
1322*
1323* Note:
Michael Reed2ea00202006-04-27 16:25:30 -07001324* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001326static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327qla2xxx_eh_abort(struct scsi_cmnd *cmd)
1328{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001329 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -05001330 srb_t *sp;
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001331 int ret;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001332 unsigned int id;
1333 uint64_t lun;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001334 unsigned long flags;
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001335 int rval, wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001336 struct qla_hw_data *ha = vha->hw;
Quinn Tran585def92018-09-04 14:19:20 -07001337 struct qla_qpair *qpair;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Sawan Chandaka4655372016-07-06 11:14:32 -04001339 if (qla2x00_isp_reg_stat(ha)) {
1340 ql_log(ql_log_info, vha, 0x8042,
1341 "PCI/Register disconnect, exiting.\n");
1342 return FAILED;
1343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001345 ret = fc_block_scsi_eh(cmd);
1346 if (ret != 0)
1347 return ret;
1348 ret = SUCCESS;
1349
Mike Christie170babc2010-10-15 11:27:47 -07001350 sp = (srb_t *) CMD_SP(cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001351 if (!sp)
1352 return SUCCESS;
1353
1354 qpair = sp->qpair;
1355 if (!qpair)
1356 return SUCCESS;
1357
1358 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1359 if (!CMD_SP(cmd)) {
1360 /* there's a chance an interrupt could clear
1361 the ptr as part of done & free */
1362 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Mike Christie170babc2010-10-15 11:27:47 -07001363 return SUCCESS;
f4f051e2005-04-17 15:02:26 -05001364 }
Mike Christie170babc2010-10-15 11:27:47 -07001365
Quinn Tran585def92018-09-04 14:19:20 -07001366 if (sp_get(sp)){
1367 /* ref_count is already 0 */
1368 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1369 return SUCCESS;
1370 }
1371 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1372
1373 id = cmd->device->id;
1374 lun = cmd->device->lun;
1375
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001376 ql_dbg(ql_dbg_taskm, vha, 0x8002,
Chad Dupuisc7bc4ca2015-08-04 13:37:57 -04001377 "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
1378 vha->host_no, id, lun, sp, cmd, sp->handle);
Mike Christie170babc2010-10-15 11:27:47 -07001379
1380 /* Get a reference to the sp and drop the lock.*/
Mike Christie170babc2010-10-15 11:27:47 -07001381
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001382 rval = ha->isp_ops->abort_command(sp);
1383 if (rval) {
Chad Dupuis96219422015-08-04 13:38:00 -04001384 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001385 ret = SUCCESS;
Chad Dupuis96219422015-08-04 13:38:00 -04001386 else
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001387 ret = FAILED;
1388
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001389 ql_dbg(ql_dbg_taskm, vha, 0x8003,
Chad Dupuisf934c9d2014-04-11 16:54:31 -04001390 "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
Mike Christie170babc2010-10-15 11:27:47 -07001391 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001392 ql_dbg(ql_dbg_taskm, vha, 0x8004,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001393 "Abort command mbx success cmd=%p.\n", cmd);
Mike Christie170babc2010-10-15 11:27:47 -07001394 wait = 1;
1395 }
Saurav Kashyap75942062011-08-16 11:29:25 -07001396
Quinn Tran585def92018-09-04 14:19:20 -07001397 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1398 /*
1399 * Clear the slot in the oustanding_cmds array if we can't find the
1400 * command to reclaim the resources.
1401 */
1402 if (rval == QLA_FUNCTION_PARAMETER_ERROR)
1403 vha->req->outstanding_cmds[sp->handle] = NULL;
1404
1405 /*
1406 * sp->done will do ref_count--
1407 * sp_get() took an extra count above
1408 */
1409 sp->done(sp, DID_RESET << 16);
f4f051e2005-04-17 15:02:26 -05001410
Chad Dupuisbc91ade2011-08-16 11:29:26 -07001411 /* Did the command return during mailbox execution? */
1412 if (ret == FAILED && !CMD_SP(cmd))
1413 ret = SUCCESS;
1414
Quinn Tran585def92018-09-04 14:19:20 -07001415 if (!CMD_SP(cmd))
1416 wait = 0;
1417
1418 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1419
f4f051e2005-04-17 15:02:26 -05001420 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -07001421 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001422 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001423 ql_log(ql_log_warn, vha, 0x8006,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001424 "Abort handler timed out cmd=%p.\n", cmd);
Michael Reed2ea00202006-04-27 16:25:30 -07001425 ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001429 ql_log(ql_log_info, vha, 0x801c,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001430 "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001431 vha->host_no, id, lun, wait, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
f4f051e2005-04-17 15:02:26 -05001433 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434}
1435
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001436int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001437qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001438 uint64_t l, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001440 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -07001441 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001442 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001443 struct req_que *req;
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001444 srb_t *sp;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001445 struct scsi_cmnd *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Andrew Vasquez523ec772008-04-03 13:13:24 -07001447 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001448
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07001450 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001451 for (cnt = 1; status == QLA_SUCCESS &&
Chad Dupuis8d93f552013-01-30 03:34:37 -05001452 cnt < req->num_outstanding_cmds; cnt++) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001453 sp = req->outstanding_cmds[cnt];
1454 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001455 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001456 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07001457 continue;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001458 if (vha->vp_idx != sp->vha->vp_idx)
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001459 continue;
1460 match = 0;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001461 cmd = GET_CMD_SP(sp);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001462 switch (type) {
1463 case WAIT_HOST:
1464 match = 1;
1465 break;
1466 case WAIT_TARGET:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001467 match = cmd->device->id == t;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001468 break;
1469 case WAIT_LUN:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001470 match = (cmd->device->id == t &&
1471 cmd->device->lun == l);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001472 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001474 if (!match)
1475 continue;
1476
1477 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001478 status = qla2x00_eh_wait_on_command(cmd);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001479 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001482
1483 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484}
1485
Andrew Vasquez523ec772008-04-03 13:13:24 -07001486static char *reset_errors[] = {
1487 "HBA not online",
1488 "HBA not ready",
1489 "Task management failed",
1490 "Waiting for command completions",
1491};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Andrew Vasquez523ec772008-04-03 13:13:24 -07001493static int
1494__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001495 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001496{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001497 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001498 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1499 int err;
1500
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001501 if (!fcport) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07001502 return FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001503 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001504
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001505 err = fc_block_scsi_eh(cmd);
1506 if (err != 0)
1507 return err;
1508
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001509 ql_log(ql_log_info, vha, 0x8009,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001510 "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001511 cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001512
1513 err = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001514 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1515 ql_log(ql_log_warn, vha, 0x800a,
1516 "Wait for hba online failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001517 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001518 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001519 err = 2;
Jens Axboe9cf2bab2018-10-31 17:01:22 -06001520 if (do_reset(fcport, cmd->device->lun, blk_mq_rq_cpu(cmd->request) + 1)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001521 != QLA_SUCCESS) {
1522 ql_log(ql_log_warn, vha, 0x800c,
1523 "do_reset failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001524 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001525 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001526 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001527 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001528 cmd->device->lun, type) != QLA_SUCCESS) {
1529 ql_log(ql_log_warn, vha, 0x800d,
Masanari Iidad6a03582012-08-22 14:20:58 -04001530 "wait for pending cmds failed for cmd=%p.\n", cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001531 goto eh_reset_failed;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001532 }
Andrew Vasquez523ec772008-04-03 13:13:24 -07001533
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001534 ql_log(ql_log_info, vha, 0x800e,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001535 "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001536 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001537
1538 return SUCCESS;
1539
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001540eh_reset_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001541 ql_log(ql_log_info, vha, 0x800f,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001542 "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001543 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1544 cmd);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001545 return FAILED;
1546}
1547
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001548static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1550{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001551 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1552 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Sawan Chandaka4655372016-07-06 11:14:32 -04001554 if (qla2x00_isp_reg_stat(ha)) {
1555 ql_log(ql_log_info, vha, 0x803e,
1556 "PCI/Register disconnect, exiting.\n");
1557 return FAILED;
1558 }
1559
Andrew Vasquez523ec772008-04-03 13:13:24 -07001560 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1561 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564static int
Andrew Vasquez523ec772008-04-03 13:13:24 -07001565qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001567 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1568 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Sawan Chandaka4655372016-07-06 11:14:32 -04001570 if (qla2x00_isp_reg_stat(ha)) {
1571 ql_log(ql_log_info, vha, 0x803f,
1572 "PCI/Register disconnect, exiting.\n");
1573 return FAILED;
1574 }
1575
Andrew Vasquez523ec772008-04-03 13:13:24 -07001576 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1577 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580/**************************************************************************
1581* qla2xxx_eh_bus_reset
1582*
1583* Description:
1584* The bus reset function will reset the bus and abort any executing
1585* commands.
1586*
1587* Input:
1588* cmd = Linux SCSI command packet of the command that cause the
1589* bus reset.
1590*
1591* Returns:
1592* SUCCESS/FAILURE (defined as macro in scsi.h).
1593*
1594**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001595static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1597{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001598 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001599 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001600 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001601 unsigned int id;
1602 uint64_t lun;
Sawan Chandaka4655372016-07-06 11:14:32 -04001603 struct qla_hw_data *ha = vha->hw;
1604
1605 if (qla2x00_isp_reg_stat(ha)) {
1606 ql_log(ql_log_info, vha, 0x8040,
1607 "PCI/Register disconnect, exiting.\n");
1608 return FAILED;
1609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
f4f051e2005-04-17 15:02:26 -05001611 id = cmd->device->id;
1612 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001613
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001614 if (!fcport) {
f4f051e2005-04-17 15:02:26 -05001615 return ret;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001616 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Andrew Vasquez4e98d3b2011-02-23 15:27:17 -08001618 ret = fc_block_scsi_eh(cmd);
1619 if (ret != 0)
1620 return ret;
1621 ret = FAILED;
1622
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001623 ql_log(ql_log_info, vha, 0x8012,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001624 "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001626 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001627 ql_log(ql_log_fatal, vha, 0x8013,
1628 "Wait for hba online failed board disabled.\n");
f4f051e2005-04-17 15:02:26 -05001629 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 }
1631
Saurav Kashyapad5376892011-11-18 09:02:09 -08001632 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1633 ret = SUCCESS;
1634
f4f051e2005-04-17 15:02:26 -05001635 if (ret == FAILED)
1636 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001638 /* Flush outstanding commands. */
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001639 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001640 QLA_SUCCESS) {
1641 ql_log(ql_log_warn, vha, 0x8014,
1642 "Wait for pending commands failed.\n");
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001643 ret = FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
f4f051e2005-04-17 15:02:26 -05001646eh_bus_reset_done:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001647 ql_log(ql_log_warn, vha, 0x802b,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001648 "BUS RESET %s nexus=%ld:%d:%llu.\n",
Masanari Iidad6a03582012-08-22 14:20:58 -04001649 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
f4f051e2005-04-17 15:02:26 -05001651 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652}
1653
1654/**************************************************************************
1655* qla2xxx_eh_host_reset
1656*
1657* Description:
1658* The reset function will reset the Adapter.
1659*
1660* Input:
1661* cmd = Linux SCSI command packet of the command that cause the
1662* adapter reset.
1663*
1664* Returns:
1665* Either SUCCESS or FAILED.
1666*
1667* Note:
1668**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001669static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1671{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001673 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001674 int ret = FAILED;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001675 unsigned int id;
1676 uint64_t lun;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001677 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Sawan Chandaka4655372016-07-06 11:14:32 -04001679 if (qla2x00_isp_reg_stat(ha)) {
1680 ql_log(ql_log_info, vha, 0x8041,
1681 "PCI/Register disconnect, exiting.\n");
1682 schedule_work(&ha->board_disable);
1683 return SUCCESS;
1684 }
1685
f4f051e2005-04-17 15:02:26 -05001686 id = cmd->device->id;
1687 lun = cmd->device->lun;
f4f051e2005-04-17 15:02:26 -05001688
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001689 ql_log(ql_log_info, vha, 0x8018,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001690 "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Chad Dupuis63ee7072014-04-11 16:54:46 -04001692 /*
1693 * No point in issuing another reset if one is active. Also do not
1694 * attempt a reset if we are updating flash.
1695 */
1696 if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
f4f051e2005-04-17 15:02:26 -05001697 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001699 if (vha != base_vha) {
1700 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001701 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001702 } else {
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001703 if (IS_P3P_TYPE(vha->hw)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001704 if (!qla82xx_fcoe_ctx_reset(vha)) {
1705 /* Ctx reset success */
1706 ret = SUCCESS;
1707 goto eh_host_reset_lock;
1708 }
1709 /* fall thru if ctx reset failed */
1710 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001711 if (ha->wq)
1712 flush_workqueue(ha->wq);
1713
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001714 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001715 if (ha->isp_ops->abort_isp(base_vha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1717 /* failed. schedule dpc to try */
1718 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1719
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001720 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1721 ql_log(ql_log_warn, vha, 0x802a,
1722 "wait for hba online failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001723 goto eh_host_reset_lock;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001724 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001725 }
1726 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001729 /* Waiting for command to be returned to OS.*/
Giridhar Malavali4d78c972010-07-23 15:28:35 +05001730 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001731 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001732 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
f4f051e2005-04-17 15:02:26 -05001734eh_host_reset_lock:
Chad Dupuiscfb09192011-11-18 09:03:07 -08001735 ql_log(ql_log_info, vha, 0x8017,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001736 "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -08001737 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
f4f051e2005-04-17 15:02:26 -05001739 return ret;
1740}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
1742/*
1743* qla2x00_loop_reset
1744* Issue loop reset.
1745*
1746* Input:
1747* ha = adapter block pointer.
1748*
1749* Returns:
1750* 0 = success
1751*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001752int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001753qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001755 int ret;
bdf79622005-04-17 15:06:53 -05001756 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001757 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Armen Baloyan58547712013-08-27 01:37:33 -04001759 if (IS_QLAFX00(ha)) {
1760 return qlafx00_loop_reset(vha);
1761 }
1762
Giridhar Malavalif4c496c2010-05-04 15:01:33 -07001763 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001764 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1765 if (fcport->port_type != FCT_TARGET)
1766 continue;
1767
1768 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1769 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001770 ql_dbg(ql_dbg_taskm, vha, 0x802c,
Armen Baloyan58547712013-08-27 01:37:33 -04001771 "Bus Reset failed: Reset=%d "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001772 "d_id=%x.\n", ret, fcport->d_id.b24);
Andrew Vasquez55e5ed22010-02-18 10:07:25 -08001773 }
1774 }
1775 }
1776
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04001777
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001778 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
Andrew Vasquez0b7e7c52013-02-08 01:57:42 -05001779 atomic_set(&vha->loop_state, LOOP_DOWN);
1780 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1781 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001782 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001783 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001784 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1785 "full_login_lip=%d.\n", ret);
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 }
1788
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07001789 if (ha->flags.enable_lip_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001790 ret = qla2x00_lip_reset(vha);
Saurav Kashyapad5376892011-11-18 09:02:09 -08001791 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001792 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1793 "lip_reset failed (%d).\n", ret);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001794 }
1795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001797 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001799 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
1801
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001802static void qla2x00_abort_srb(struct qla_qpair *qp, srb_t *sp, const int res,
1803 unsigned long *flags)
1804 __releases(qp->qp_lock_ptr)
1805 __acquires(qp->qp_lock_ptr)
1806{
1807 scsi_qla_host_t *vha = qp->vha;
1808 struct qla_hw_data *ha = vha->hw;
1809
1810 if (sp->type == SRB_NVME_CMD || sp->type == SRB_NVME_LS) {
1811 if (!sp_get(sp)) {
1812 /* got sp */
1813 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
1814 qla_nvme_abort(ha, sp, res);
1815 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
1816 }
1817 } else if (GET_CMD_SP(sp) && !ha->flags.eeh_busy &&
1818 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
1819 !qla2x00_isp_reg_stat(ha) && sp->type == SRB_SCSI_CMD) {
1820 /*
1821 * Don't abort commands in adapter during EEH recovery as it's
1822 * not accessible/responding.
1823 *
1824 * Get a reference to the sp and drop the lock. The reference
1825 * ensures this sp->done() call and not the call in
1826 * qla2xxx_eh_abort() ends the SCSI cmd (with result 'res').
1827 */
1828 if (!sp_get(sp)) {
Linus Torvalds938edb82018-12-28 14:48:06 -08001829 int status;
1830
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001831 spin_unlock_irqrestore(qp->qp_lock_ptr, *flags);
Linus Torvalds938edb82018-12-28 14:48:06 -08001832 status = qla2xxx_eh_abort(GET_CMD_SP(sp));
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001833 spin_lock_irqsave(qp->qp_lock_ptr, *flags);
Linus Torvalds938edb82018-12-28 14:48:06 -08001834 /*
1835 * Get rid of extra reference caused
1836 * by early exit from qla2xxx_eh_abort
1837 */
1838 if (status == FAST_IO_FAIL)
1839 atomic_dec(&sp->ref_count);
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001840 }
1841 }
1842 sp->done(sp, res);
1843}
1844
Quinn Tranbbead492017-12-28 12:33:13 -08001845static void
1846__qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001847{
Bart Van Asscheeb023222018-10-18 15:45:44 -07001848 int cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001849 unsigned long flags;
1850 srb_t *sp;
Quinn Tranbbead492017-12-28 12:33:13 -08001851 scsi_qla_host_t *vha = qp->vha;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001852 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001853 struct req_que *req;
Quinn Tranc5419e22017-06-13 20:47:16 -07001854 struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
1855 struct qla_tgt_cmd *cmd;
Arun Easic0cb4492014-09-25 06:14:51 -04001856
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05001857 if (!ha->req_q_map)
1858 return;
Quinn Tranbbead492017-12-28 12:33:13 -08001859 spin_lock_irqsave(qp->qp_lock_ptr, flags);
1860 req = qp->req;
1861 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1862 sp = req->outstanding_cmds[cnt];
1863 if (sp) {
1864 req->outstanding_cmds[cnt] = NULL;
Quinn Tran6b0431d2018-09-04 14:19:13 -07001865 switch (sp->cmd_type) {
1866 case TYPE_SRB:
Bart Van Asschec4e521b2018-11-29 10:25:11 -08001867 qla2x00_abort_srb(qp, sp, res, &flags);
Quinn Tran585def92018-09-04 14:19:20 -07001868 break;
1869 case TYPE_TGT_CMD:
Quinn Tranbbead492017-12-28 12:33:13 -08001870 if (!vha->hw->tgt.tgt_ops || !tgt ||
1871 qla_ini_mode_enabled(vha)) {
Quinn Tran585def92018-09-04 14:19:20 -07001872 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf003,
1873 "HOST-ABORT-HNDLR: dpc_flags=%lx. Target mode disabled\n",
1874 vha->dpc_flags);
Quinn Tranbbead492017-12-28 12:33:13 -08001875 continue;
1876 }
1877 cmd = (struct qla_tgt_cmd *)sp;
1878 qlt_abort_cmd_on_host_reset(cmd->vha, cmd);
Quinn Tran585def92018-09-04 14:19:20 -07001879 break;
1880 case TYPE_TGT_TMCMD:
1881 /*
1882 * Currently, only ABTS response gets on the
1883 * outstanding_cmds[]
1884 */
1885 ha->tgt.tgt_ops->free_mcmd(
1886 (struct qla_tgt_mgmt_cmd *)sp);
1887 break;
1888 default:
1889 break;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001890 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001891 }
1892 }
Quinn Tranbbead492017-12-28 12:33:13 -08001893 spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
1894}
1895
1896void
1897qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1898{
1899 int que;
1900 struct qla_hw_data *ha = vha->hw;
1901
1902 __qla2x00_abort_all_cmds(ha->base_qpair, res);
1903
1904 for (que = 0; que < ha->max_qpairs; que++) {
1905 if (!ha->queue_pair_map[que])
1906 continue;
1907
1908 __qla2x00_abort_all_cmds(ha->queue_pair_map[que], res);
1909 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001910}
1911
f4f051e2005-04-17 15:02:26 -05001912static int
1913qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914{
bdf79622005-04-17 15:06:53 -05001915 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001917 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001918 return -ENXIO;
1919
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001920 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001921
1922 return 0;
1923}
1924
1925static int
1926qla2xxx_slave_configure(struct scsi_device *sdev)
1927{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 scsi_qla_host_t *vha = shost_priv(sdev->host);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001929 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001930
Arun Easi9e522cd2012-08-22 14:21:31 -04001931 if (IS_T10_PI_CAPABLE(vha->hw))
1932 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1933
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01001934 scsi_change_queue_depth(sdev, req->max_q_depth);
f4f051e2005-04-17 15:02:26 -05001935 return 0;
1936}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
f4f051e2005-04-17 15:02:26 -05001938static void
1939qla2xxx_slave_destroy(struct scsi_device *sdev)
1940{
1941 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942}
1943
1944/**
1945 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1946 * @ha: HA context
1947 *
1948 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1949 * supported addressing method.
1950 */
1951static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001952qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001954 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Yang Hongyang6a355282009-04-06 19:01:13 -07001957 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001958 /* Any upper-dword bits set? */
1959 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001960 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001961 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001963 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1964 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001965 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001968
Yang Hongyang284901a2009-04-06 19:01:15 -07001969 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1970 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971}
1972
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001973static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001974qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001975{
1976 unsigned long flags = 0;
1977 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1978
1979 spin_lock_irqsave(&ha->hardware_lock, flags);
1980 ha->interrupts_on = 1;
1981 /* enable risc and host interrupts */
1982 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1983 RD_REG_WORD(&reg->ictrl);
1984 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1985
1986}
1987
1988static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001990{
1991 unsigned long flags = 0;
1992 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1993
1994 spin_lock_irqsave(&ha->hardware_lock, flags);
1995 ha->interrupts_on = 0;
1996 /* disable risc and host interrupts */
1997 WRT_REG_WORD(&reg->ictrl, 0);
1998 RD_REG_WORD(&reg->ictrl);
1999 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2000}
2001
2002static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002004{
2005 unsigned long flags = 0;
2006 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2007
2008 spin_lock_irqsave(&ha->hardware_lock, flags);
2009 ha->interrupts_on = 1;
2010 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
2011 RD_REG_DWORD(&reg->ictrl);
2012 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2013}
2014
2015static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002016qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002017{
2018 unsigned long flags = 0;
2019 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2020
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002021 if (IS_NOPOLLING_TYPE(ha))
2022 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002023 spin_lock_irqsave(&ha->hardware_lock, flags);
2024 ha->interrupts_on = 0;
2025 WRT_REG_DWORD(&reg->ictrl, 0);
2026 RD_REG_DWORD(&reg->ictrl);
2027 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2028}
2029
Giridhar Malavali706f4572011-11-18 09:03:16 -08002030static int
2031qla2x00_iospace_config(struct qla_hw_data *ha)
2032{
2033 resource_size_t pio;
2034 uint16_t msix;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002035
Giridhar Malavali706f4572011-11-18 09:03:16 -08002036 if (pci_request_selected_regions(ha->pdev, ha->bars,
2037 QLA2XXX_DRIVER_NAME)) {
2038 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
2039 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2040 pci_name(ha->pdev));
2041 goto iospace_error_exit;
2042 }
2043 if (!(ha->bars & 1))
2044 goto skip_pio;
2045
2046 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
2047 pio = pci_resource_start(ha->pdev, 0);
2048 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
2049 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2050 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
2051 "Invalid pci I/O region size (%s).\n",
2052 pci_name(ha->pdev));
2053 pio = 0;
2054 }
2055 } else {
2056 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
2057 "Region #0 no a PIO resource (%s).\n",
2058 pci_name(ha->pdev));
2059 pio = 0;
2060 }
2061 ha->pio_address = pio;
2062 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
2063 "PIO address=%llu.\n",
2064 (unsigned long long)ha->pio_address);
2065
2066skip_pio:
2067 /* Use MMIO operations for all accesses. */
2068 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
2069 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
2070 "Region #1 not an MMIO resource (%s), aborting.\n",
2071 pci_name(ha->pdev));
2072 goto iospace_error_exit;
2073 }
2074 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
2075 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
2076 "Invalid PCI mem region size (%s), aborting.\n",
2077 pci_name(ha->pdev));
2078 goto iospace_error_exit;
2079 }
2080
2081 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
2082 if (!ha->iobase) {
2083 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
2084 "Cannot remap MMIO (%s), aborting.\n",
2085 pci_name(ha->pdev));
2086 goto iospace_error_exit;
2087 }
2088
2089 /* Determine queue resources */
2090 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002091 ha->msix_count = QLA_BASE_VECTORS;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002092 if (!ql2xmqsupport || !ql2xnvmeenable ||
2093 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Giridhar Malavali706f4572011-11-18 09:03:16 -08002094 goto mqiobase_exit;
2095
2096 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
2097 pci_resource_len(ha->pdev, 3));
2098 if (ha->mqiobase) {
2099 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
2100 "MQIO Base=%p.\n", ha->mqiobase);
2101 /* Read MSIX vector size of the board */
2102 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
Michael Hernandezd7459522016-12-12 14:40:07 -08002103 ha->msix_count = msix + 1;
Giridhar Malavali706f4572011-11-18 09:03:16 -08002104 /* Max queues are bounded by available msix vectors */
Michael Hernandezd7459522016-12-12 14:40:07 -08002105 /* MB interrupt uses 1 vector */
2106 ha->max_req_queues = ha->msix_count - 1;
2107 ha->max_rsp_queues = ha->max_req_queues;
2108 /* Queue pairs is the max value minus the base queue pair */
2109 ha->max_qpairs = ha->max_rsp_queues - 1;
2110 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0188,
2111 "Max no of queues pairs: %d.\n", ha->max_qpairs);
2112
Giridhar Malavali706f4572011-11-18 09:03:16 -08002113 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
Michael Hernandezd7459522016-12-12 14:40:07 -08002114 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002115 } else
2116 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
2117 "BAR 3 not enabled.\n");
2118
2119mqiobase_exit:
Giridhar Malavali706f4572011-11-18 09:03:16 -08002120 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002121 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali706f4572011-11-18 09:03:16 -08002122 return (0);
2123
2124iospace_error_exit:
2125 return (-ENOMEM);
2126}
2127
2128
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002129static int
2130qla83xx_iospace_config(struct qla_hw_data *ha)
2131{
2132 uint16_t msix;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002133
2134 if (pci_request_selected_regions(ha->pdev, ha->bars,
2135 QLA2XXX_DRIVER_NAME)) {
2136 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
2137 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
2138 pci_name(ha->pdev));
2139
2140 goto iospace_error_exit;
2141 }
2142
2143 /* Use MMIO operations for all accesses. */
2144 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
2145 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
2146 "Invalid pci I/O region size (%s).\n",
2147 pci_name(ha->pdev));
2148 goto iospace_error_exit;
2149 }
2150 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
2151 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
2152 "Invalid PCI mem region size (%s), aborting\n",
2153 pci_name(ha->pdev));
2154 goto iospace_error_exit;
2155 }
2156
2157 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
2158 if (!ha->iobase) {
2159 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
2160 "Cannot remap MMIO (%s), aborting.\n",
2161 pci_name(ha->pdev));
2162 goto iospace_error_exit;
2163 }
2164
2165 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
2166 /* 83XX 26XX always use MQ type access for queues
2167 * - mbar 2, a.k.a region 4 */
2168 ha->max_req_queues = ha->max_rsp_queues = 1;
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002169 ha->msix_count = QLA_BASE_VECTORS;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002170 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
2171 pci_resource_len(ha->pdev, 4));
2172
2173 if (!ha->mqiobase) {
2174 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
2175 "BAR2/region4 not enabled\n");
2176 goto mqiobase_exit;
2177 }
2178
2179 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
2180 pci_resource_len(ha->pdev, 2));
2181 if (ha->msixbase) {
2182 /* Read MSIX vector size of the board */
2183 pci_read_config_word(ha->pdev,
2184 QLA_83XX_PCI_MSIX_CONTROL, &msix);
Quinn Trane326d222017-06-13 20:47:18 -07002185 ha->msix_count = (msix & PCI_MSIX_FLAGS_QSIZE) + 1;
Quinn Tran093df732016-12-12 14:40:09 -08002186 /*
2187 * By default, driver uses at least two msix vectors
2188 * (default & rspq)
2189 */
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07002190 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08002191 /* MB interrupt uses 1 vector */
2192 ha->max_req_queues = ha->msix_count - 1;
Quinn Tran093df732016-12-12 14:40:09 -08002193
2194 /* ATIOQ needs 1 vector. That's 1 less QPair */
2195 if (QLA_TGT_MODE_ENABLED())
2196 ha->max_req_queues--;
2197
Michael Hernandezd0d2c682017-02-15 15:37:20 -08002198 ha->max_rsp_queues = ha->max_req_queues;
2199
Michael Hernandezd7459522016-12-12 14:40:07 -08002200 /* Queue pairs is the max value minus
2201 * the base queue pair */
2202 ha->max_qpairs = ha->max_req_queues - 1;
Quinn Tran83548fe2017-06-02 09:12:01 -07002203 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x00e3,
Michael Hernandezd7459522016-12-12 14:40:07 -08002204 "Max no of queues pairs: %d.\n", ha->max_qpairs);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002205 }
2206 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
Michael Hernandezd7459522016-12-12 14:40:07 -08002207 "MSI-X vector count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002208 } else
2209 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
2210 "BAR 1 not enabled.\n");
2211
2212mqiobase_exit:
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002213 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
Michael Hernandezf54f2cb2017-02-15 15:37:19 -08002214 "MSIX Count: %d.\n", ha->msix_count);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002215 return 0;
2216
2217iospace_error_exit:
2218 return -ENOMEM;
2219}
2220
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002221static struct isp_operations qla2100_isp_ops = {
2222 .pci_config = qla2100_pci_config,
2223 .reset_chip = qla2x00_reset_chip,
2224 .chip_diag = qla2x00_chip_diag,
2225 .config_rings = qla2x00_config_rings,
2226 .reset_adapter = qla2x00_reset_adapter,
2227 .nvram_config = qla2x00_nvram_config,
2228 .update_fw_options = qla2x00_update_fw_options,
2229 .load_risc = qla2x00_load_risc,
2230 .pci_info_str = qla2x00_pci_info_str,
2231 .fw_version_str = qla2x00_fw_version_str,
2232 .intr_handler = qla2100_intr_handler,
2233 .enable_intrs = qla2x00_enable_intrs,
2234 .disable_intrs = qla2x00_disable_intrs,
2235 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002236 .target_reset = qla2x00_abort_target,
2237 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002238 .fabric_login = qla2x00_login_fabric,
2239 .fabric_logout = qla2x00_fabric_logout,
2240 .calc_req_entries = qla2x00_calc_iocbs_32,
2241 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2242 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2243 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2244 .read_nvram = qla2x00_read_nvram_data,
2245 .write_nvram = qla2x00_write_nvram_data,
2246 .fw_dump = qla2100_fw_dump,
2247 .beacon_on = NULL,
2248 .beacon_off = NULL,
2249 .beacon_blink = NULL,
2250 .read_optrom = qla2x00_read_optrom_data,
2251 .write_optrom = qla2x00_write_optrom_data,
2252 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002254 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002255 .abort_isp = qla2x00_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002256 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002257 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002258};
2259
2260static struct isp_operations qla2300_isp_ops = {
2261 .pci_config = qla2300_pci_config,
2262 .reset_chip = qla2x00_reset_chip,
2263 .chip_diag = qla2x00_chip_diag,
2264 .config_rings = qla2x00_config_rings,
2265 .reset_adapter = qla2x00_reset_adapter,
2266 .nvram_config = qla2x00_nvram_config,
2267 .update_fw_options = qla2x00_update_fw_options,
2268 .load_risc = qla2x00_load_risc,
2269 .pci_info_str = qla2x00_pci_info_str,
2270 .fw_version_str = qla2x00_fw_version_str,
2271 .intr_handler = qla2300_intr_handler,
2272 .enable_intrs = qla2x00_enable_intrs,
2273 .disable_intrs = qla2x00_disable_intrs,
2274 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002275 .target_reset = qla2x00_abort_target,
2276 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002277 .fabric_login = qla2x00_login_fabric,
2278 .fabric_logout = qla2x00_fabric_logout,
2279 .calc_req_entries = qla2x00_calc_iocbs_32,
2280 .build_iocbs = qla2x00_build_scsi_iocbs_32,
2281 .prep_ms_iocb = qla2x00_prep_ms_iocb,
2282 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
2283 .read_nvram = qla2x00_read_nvram_data,
2284 .write_nvram = qla2x00_write_nvram_data,
2285 .fw_dump = qla2300_fw_dump,
2286 .beacon_on = qla2x00_beacon_on,
2287 .beacon_off = qla2x00_beacon_off,
2288 .beacon_blink = qla2x00_beacon_blink,
2289 .read_optrom = qla2x00_read_optrom_data,
2290 .write_optrom = qla2x00_write_optrom_data,
2291 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002292 .start_scsi = qla2x00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002293 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002294 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002295 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002296 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002297};
2298
2299static struct isp_operations qla24xx_isp_ops = {
2300 .pci_config = qla24xx_pci_config,
2301 .reset_chip = qla24xx_reset_chip,
2302 .chip_diag = qla24xx_chip_diag,
2303 .config_rings = qla24xx_config_rings,
2304 .reset_adapter = qla24xx_reset_adapter,
2305 .nvram_config = qla24xx_nvram_config,
2306 .update_fw_options = qla24xx_update_fw_options,
2307 .load_risc = qla24xx_load_risc,
2308 .pci_info_str = qla24xx_pci_info_str,
2309 .fw_version_str = qla24xx_fw_version_str,
2310 .intr_handler = qla24xx_intr_handler,
2311 .enable_intrs = qla24xx_enable_intrs,
2312 .disable_intrs = qla24xx_disable_intrs,
2313 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002314 .target_reset = qla24xx_abort_target,
2315 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002316 .fabric_login = qla24xx_login_fabric,
2317 .fabric_logout = qla24xx_fabric_logout,
2318 .calc_req_entries = NULL,
2319 .build_iocbs = NULL,
2320 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2321 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2322 .read_nvram = qla24xx_read_nvram_data,
2323 .write_nvram = qla24xx_write_nvram_data,
2324 .fw_dump = qla24xx_fw_dump,
2325 .beacon_on = qla24xx_beacon_on,
2326 .beacon_off = qla24xx_beacon_off,
2327 .beacon_blink = qla24xx_beacon_blink,
2328 .read_optrom = qla24xx_read_optrom_data,
2329 .write_optrom = qla24xx_write_optrom_data,
2330 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 .start_scsi = qla24xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002332 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002333 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002334 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002335 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002336};
2337
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002338static struct isp_operations qla25xx_isp_ops = {
2339 .pci_config = qla25xx_pci_config,
2340 .reset_chip = qla24xx_reset_chip,
2341 .chip_diag = qla24xx_chip_diag,
2342 .config_rings = qla24xx_config_rings,
2343 .reset_adapter = qla24xx_reset_adapter,
2344 .nvram_config = qla24xx_nvram_config,
2345 .update_fw_options = qla24xx_update_fw_options,
2346 .load_risc = qla24xx_load_risc,
2347 .pci_info_str = qla24xx_pci_info_str,
2348 .fw_version_str = qla24xx_fw_version_str,
2349 .intr_handler = qla24xx_intr_handler,
2350 .enable_intrs = qla24xx_enable_intrs,
2351 .disable_intrs = qla24xx_disable_intrs,
2352 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002353 .target_reset = qla24xx_abort_target,
2354 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002355 .fabric_login = qla24xx_login_fabric,
2356 .fabric_logout = qla24xx_fabric_logout,
2357 .calc_req_entries = NULL,
2358 .build_iocbs = NULL,
2359 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2360 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2361 .read_nvram = qla25xx_read_nvram_data,
2362 .write_nvram = qla25xx_write_nvram_data,
2363 .fw_dump = qla25xx_fw_dump,
2364 .beacon_on = qla24xx_beacon_on,
2365 .beacon_off = qla24xx_beacon_off,
2366 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002367 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002368 .write_optrom = qla24xx_write_optrom_data,
2369 .get_flash_version = qla24xx_get_flash_version,
Arun Easibad75002010-05-04 15:01:30 -07002370 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002371 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002372 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002373 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002374 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002375};
2376
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002377static struct isp_operations qla81xx_isp_ops = {
2378 .pci_config = qla25xx_pci_config,
2379 .reset_chip = qla24xx_reset_chip,
2380 .chip_diag = qla24xx_chip_diag,
2381 .config_rings = qla24xx_config_rings,
2382 .reset_adapter = qla24xx_reset_adapter,
2383 .nvram_config = qla81xx_nvram_config,
2384 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08002385 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002386 .pci_info_str = qla24xx_pci_info_str,
2387 .fw_version_str = qla24xx_fw_version_str,
2388 .intr_handler = qla24xx_intr_handler,
2389 .enable_intrs = qla24xx_enable_intrs,
2390 .disable_intrs = qla24xx_disable_intrs,
2391 .abort_command = qla24xx_abort_command,
2392 .target_reset = qla24xx_abort_target,
2393 .lun_reset = qla24xx_lun_reset,
2394 .fabric_login = qla24xx_login_fabric,
2395 .fabric_logout = qla24xx_fabric_logout,
2396 .calc_req_entries = NULL,
2397 .build_iocbs = NULL,
2398 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2399 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07002400 .read_nvram = NULL,
2401 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002402 .fw_dump = qla81xx_fw_dump,
2403 .beacon_on = qla24xx_beacon_on,
2404 .beacon_off = qla24xx_beacon_off,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002405 .beacon_blink = qla83xx_beacon_blink,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002406 .read_optrom = qla25xx_read_optrom_data,
2407 .write_optrom = qla24xx_write_optrom_data,
2408 .get_flash_version = qla24xx_get_flash_version,
Arun Easiba77ef52010-05-28 15:08:27 -07002409 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002410 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002411 .abort_isp = qla2x00_abort_isp,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002412 .iospace_config = qla2x00_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002413 .initialize_adapter = qla2x00_initialize_adapter,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002414};
2415
2416static struct isp_operations qla82xx_isp_ops = {
2417 .pci_config = qla82xx_pci_config,
2418 .reset_chip = qla82xx_reset_chip,
2419 .chip_diag = qla24xx_chip_diag,
2420 .config_rings = qla82xx_config_rings,
2421 .reset_adapter = qla24xx_reset_adapter,
2422 .nvram_config = qla81xx_nvram_config,
2423 .update_fw_options = qla24xx_update_fw_options,
2424 .load_risc = qla82xx_load_risc,
Atul Deshmukh9d55ca62012-08-22 14:21:14 -04002425 .pci_info_str = qla24xx_pci_info_str,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002426 .fw_version_str = qla24xx_fw_version_str,
2427 .intr_handler = qla82xx_intr_handler,
2428 .enable_intrs = qla82xx_enable_intrs,
2429 .disable_intrs = qla82xx_disable_intrs,
2430 .abort_command = qla24xx_abort_command,
2431 .target_reset = qla24xx_abort_target,
2432 .lun_reset = qla24xx_lun_reset,
2433 .fabric_login = qla24xx_login_fabric,
2434 .fabric_logout = qla24xx_fabric_logout,
2435 .calc_req_entries = NULL,
2436 .build_iocbs = NULL,
2437 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2438 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2439 .read_nvram = qla24xx_read_nvram_data,
2440 .write_nvram = qla24xx_write_nvram_data,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002441 .fw_dump = qla82xx_fw_dump,
Saurav Kashyap999916d2011-08-16 11:31:45 -07002442 .beacon_on = qla82xx_beacon_on,
2443 .beacon_off = qla82xx_beacon_off,
2444 .beacon_blink = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002445 .read_optrom = qla82xx_read_optrom_data,
2446 .write_optrom = qla82xx_write_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002447 .get_flash_version = qla82xx_get_flash_version,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002448 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002449 .start_scsi_mq = NULL,
Giridhar Malavalia9083012010-04-12 17:59:55 -07002450 .abort_isp = qla82xx_abort_isp,
Giridhar Malavali706f4572011-11-18 09:03:16 -08002451 .iospace_config = qla82xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002452 .initialize_adapter = qla2x00_initialize_adapter,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002453};
2454
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002455static struct isp_operations qla8044_isp_ops = {
2456 .pci_config = qla82xx_pci_config,
2457 .reset_chip = qla82xx_reset_chip,
2458 .chip_diag = qla24xx_chip_diag,
2459 .config_rings = qla82xx_config_rings,
2460 .reset_adapter = qla24xx_reset_adapter,
2461 .nvram_config = qla81xx_nvram_config,
2462 .update_fw_options = qla24xx_update_fw_options,
2463 .load_risc = qla82xx_load_risc,
2464 .pci_info_str = qla24xx_pci_info_str,
2465 .fw_version_str = qla24xx_fw_version_str,
2466 .intr_handler = qla8044_intr_handler,
2467 .enable_intrs = qla82xx_enable_intrs,
2468 .disable_intrs = qla82xx_disable_intrs,
2469 .abort_command = qla24xx_abort_command,
2470 .target_reset = qla24xx_abort_target,
2471 .lun_reset = qla24xx_lun_reset,
2472 .fabric_login = qla24xx_login_fabric,
2473 .fabric_logout = qla24xx_fabric_logout,
2474 .calc_req_entries = NULL,
2475 .build_iocbs = NULL,
2476 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2477 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2478 .read_nvram = NULL,
2479 .write_nvram = NULL,
Chad Dupuisa1b23c52014-02-26 04:15:12 -05002480 .fw_dump = qla8044_fw_dump,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002481 .beacon_on = qla82xx_beacon_on,
2482 .beacon_off = qla82xx_beacon_off,
2483 .beacon_blink = NULL,
Saurav Kashyap888e6392014-02-26 04:15:13 -05002484 .read_optrom = qla8044_read_optrom_data,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002485 .write_optrom = qla8044_write_optrom_data,
2486 .get_flash_version = qla82xx_get_flash_version,
2487 .start_scsi = qla82xx_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002488 .start_scsi_mq = NULL,
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002489 .abort_isp = qla8044_abort_isp,
2490 .iospace_config = qla82xx_iospace_config,
2491 .initialize_adapter = qla2x00_initialize_adapter,
2492};
2493
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002494static struct isp_operations qla83xx_isp_ops = {
2495 .pci_config = qla25xx_pci_config,
2496 .reset_chip = qla24xx_reset_chip,
2497 .chip_diag = qla24xx_chip_diag,
2498 .config_rings = qla24xx_config_rings,
2499 .reset_adapter = qla24xx_reset_adapter,
2500 .nvram_config = qla81xx_nvram_config,
2501 .update_fw_options = qla81xx_update_fw_options,
2502 .load_risc = qla81xx_load_risc,
2503 .pci_info_str = qla24xx_pci_info_str,
2504 .fw_version_str = qla24xx_fw_version_str,
2505 .intr_handler = qla24xx_intr_handler,
2506 .enable_intrs = qla24xx_enable_intrs,
2507 .disable_intrs = qla24xx_disable_intrs,
2508 .abort_command = qla24xx_abort_command,
2509 .target_reset = qla24xx_abort_target,
2510 .lun_reset = qla24xx_lun_reset,
2511 .fabric_login = qla24xx_login_fabric,
2512 .fabric_logout = qla24xx_fabric_logout,
2513 .calc_req_entries = NULL,
2514 .build_iocbs = NULL,
2515 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2516 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2517 .read_nvram = NULL,
2518 .write_nvram = NULL,
2519 .fw_dump = qla83xx_fw_dump,
2520 .beacon_on = qla24xx_beacon_on,
2521 .beacon_off = qla24xx_beacon_off,
2522 .beacon_blink = qla83xx_beacon_blink,
2523 .read_optrom = qla25xx_read_optrom_data,
2524 .write_optrom = qla24xx_write_optrom_data,
2525 .get_flash_version = qla24xx_get_flash_version,
2526 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002527 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002528 .abort_isp = qla2x00_abort_isp,
2529 .iospace_config = qla83xx_iospace_config,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002530 .initialize_adapter = qla2x00_initialize_adapter,
2531};
2532
2533static struct isp_operations qlafx00_isp_ops = {
2534 .pci_config = qlafx00_pci_config,
2535 .reset_chip = qlafx00_soft_reset,
2536 .chip_diag = qlafx00_chip_diag,
2537 .config_rings = qlafx00_config_rings,
2538 .reset_adapter = qlafx00_soft_reset,
2539 .nvram_config = NULL,
2540 .update_fw_options = NULL,
2541 .load_risc = NULL,
2542 .pci_info_str = qlafx00_pci_info_str,
2543 .fw_version_str = qlafx00_fw_version_str,
2544 .intr_handler = qlafx00_intr_handler,
2545 .enable_intrs = qlafx00_enable_intrs,
2546 .disable_intrs = qlafx00_disable_intrs,
Armen Baloyan4440e462014-02-26 04:15:18 -05002547 .abort_command = qla24xx_async_abort_command,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002548 .target_reset = qlafx00_abort_target,
2549 .lun_reset = qlafx00_lun_reset,
2550 .fabric_login = NULL,
2551 .fabric_logout = NULL,
2552 .calc_req_entries = NULL,
2553 .build_iocbs = NULL,
2554 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2555 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2556 .read_nvram = qla24xx_read_nvram_data,
2557 .write_nvram = qla24xx_write_nvram_data,
2558 .fw_dump = NULL,
2559 .beacon_on = qla24xx_beacon_on,
2560 .beacon_off = qla24xx_beacon_off,
2561 .beacon_blink = NULL,
2562 .read_optrom = qla24xx_read_optrom_data,
2563 .write_optrom = qla24xx_write_optrom_data,
2564 .get_flash_version = qla24xx_get_flash_version,
2565 .start_scsi = qlafx00_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002566 .start_scsi_mq = NULL,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002567 .abort_isp = qlafx00_abort_isp,
2568 .iospace_config = qlafx00_iospace_config,
2569 .initialize_adapter = qlafx00_initialize_adapter,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002570};
2571
Chad Dupuisf73cb692014-02-26 04:15:06 -05002572static struct isp_operations qla27xx_isp_ops = {
2573 .pci_config = qla25xx_pci_config,
2574 .reset_chip = qla24xx_reset_chip,
2575 .chip_diag = qla24xx_chip_diag,
2576 .config_rings = qla24xx_config_rings,
2577 .reset_adapter = qla24xx_reset_adapter,
2578 .nvram_config = qla81xx_nvram_config,
2579 .update_fw_options = qla81xx_update_fw_options,
2580 .load_risc = qla81xx_load_risc,
2581 .pci_info_str = qla24xx_pci_info_str,
2582 .fw_version_str = qla24xx_fw_version_str,
2583 .intr_handler = qla24xx_intr_handler,
2584 .enable_intrs = qla24xx_enable_intrs,
2585 .disable_intrs = qla24xx_disable_intrs,
2586 .abort_command = qla24xx_abort_command,
2587 .target_reset = qla24xx_abort_target,
2588 .lun_reset = qla24xx_lun_reset,
2589 .fabric_login = qla24xx_login_fabric,
2590 .fabric_logout = qla24xx_fabric_logout,
2591 .calc_req_entries = NULL,
2592 .build_iocbs = NULL,
2593 .prep_ms_iocb = qla24xx_prep_ms_iocb,
2594 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
2595 .read_nvram = NULL,
2596 .write_nvram = NULL,
2597 .fw_dump = qla27xx_fwdump,
2598 .beacon_on = qla24xx_beacon_on,
2599 .beacon_off = qla24xx_beacon_off,
2600 .beacon_blink = qla83xx_beacon_blink,
2601 .read_optrom = qla25xx_read_optrom_data,
2602 .write_optrom = qla24xx_write_optrom_data,
2603 .get_flash_version = qla24xx_get_flash_version,
2604 .start_scsi = qla24xx_dif_start_scsi,
Michael Hernandezd7459522016-12-12 14:40:07 -08002605 .start_scsi_mq = qla2xxx_dif_start_scsi_mq,
Chad Dupuisf73cb692014-02-26 04:15:06 -05002606 .abort_isp = qla2x00_abort_isp,
2607 .iospace_config = qla83xx_iospace_config,
2608 .initialize_adapter = qla2x00_initialize_adapter,
2609};
2610
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002611static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002613{
2614 ha->device_type = DT_EXTENDED_IDS;
2615 switch (ha->pdev->device) {
2616 case PCI_DEVICE_ID_QLOGIC_ISP2100:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002617 ha->isp_type |= DT_ISP2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002618 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002619 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002620 break;
2621 case PCI_DEVICE_ID_QLOGIC_ISP2200:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002622 ha->isp_type |= DT_ISP2200;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002623 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002624 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002625 break;
2626 case PCI_DEVICE_ID_QLOGIC_ISP2300:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002627 ha->isp_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002628 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002629 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002630 break;
2631 case PCI_DEVICE_ID_QLOGIC_ISP2312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002632 ha->isp_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002633 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002634 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002635 break;
2636 case PCI_DEVICE_ID_QLOGIC_ISP2322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002637 ha->isp_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002638 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002639 if (ha->pdev->subsystem_vendor == 0x1028 &&
2640 ha->pdev->subsystem_device == 0x0170)
2641 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002642 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002643 break;
2644 case PCI_DEVICE_ID_QLOGIC_ISP6312:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002645 ha->isp_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002646 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002647 break;
2648 case PCI_DEVICE_ID_QLOGIC_ISP6322:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002649 ha->isp_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002650 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002651 break;
2652 case PCI_DEVICE_ID_QLOGIC_ISP2422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002653 ha->isp_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002654 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002655 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002656 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002657 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002658 break;
2659 case PCI_DEVICE_ID_QLOGIC_ISP2432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002660 ha->isp_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002661 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002662 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002663 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002664 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002665 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002666 case PCI_DEVICE_ID_QLOGIC_ISP8432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002667 ha->isp_type |= DT_ISP8432;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002668 ha->device_type |= DT_ZIO_SUPPORTED;
2669 ha->device_type |= DT_FWI2;
2670 ha->device_type |= DT_IIDMA;
2671 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2672 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002673 case PCI_DEVICE_ID_QLOGIC_ISP5422:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002674 ha->isp_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002675 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002676 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002677 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002678 case PCI_DEVICE_ID_QLOGIC_ISP5432:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002679 ha->isp_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002680 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07002681 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002682 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002683 case PCI_DEVICE_ID_QLOGIC_ISP2532:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002684 ha->isp_type |= DT_ISP2532;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002685 ha->device_type |= DT_ZIO_SUPPORTED;
2686 ha->device_type |= DT_FWI2;
2687 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002688 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2689 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002690 case PCI_DEVICE_ID_QLOGIC_ISP8001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002691 ha->isp_type |= DT_ISP8001;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002692 ha->device_type |= DT_ZIO_SUPPORTED;
2693 ha->device_type |= DT_FWI2;
2694 ha->device_type |= DT_IIDMA;
2695 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2696 break;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002697 case PCI_DEVICE_ID_QLOGIC_ISP8021:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002698 ha->isp_type |= DT_ISP8021;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002699 ha->device_type |= DT_ZIO_SUPPORTED;
2700 ha->device_type |= DT_FWI2;
2701 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2702 /* Initialize 82XX ISP flags */
2703 qla82xx_init_flags(ha);
2704 break;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002705 case PCI_DEVICE_ID_QLOGIC_ISP8044:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002706 ha->isp_type |= DT_ISP8044;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002707 ha->device_type |= DT_ZIO_SUPPORTED;
2708 ha->device_type |= DT_FWI2;
2709 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2710 /* Initialize 82XX ISP flags */
2711 qla82xx_init_flags(ha);
2712 break;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002713 case PCI_DEVICE_ID_QLOGIC_ISP2031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002714 ha->isp_type |= DT_ISP2031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002715 ha->device_type |= DT_ZIO_SUPPORTED;
2716 ha->device_type |= DT_FWI2;
2717 ha->device_type |= DT_IIDMA;
2718 ha->device_type |= DT_T10_PI;
2719 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2720 break;
2721 case PCI_DEVICE_ID_QLOGIC_ISP8031:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002722 ha->isp_type |= DT_ISP8031;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002723 ha->device_type |= DT_ZIO_SUPPORTED;
2724 ha->device_type |= DT_FWI2;
2725 ha->device_type |= DT_IIDMA;
2726 ha->device_type |= DT_T10_PI;
2727 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2728 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002729 case PCI_DEVICE_ID_QLOGIC_ISPF001:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002730 ha->isp_type |= DT_ISPFX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002731 break;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002732 case PCI_DEVICE_ID_QLOGIC_ISP2071:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002733 ha->isp_type |= DT_ISP2071;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002734 ha->device_type |= DT_ZIO_SUPPORTED;
2735 ha->device_type |= DT_FWI2;
2736 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002737 ha->device_type |= DT_T10_PI;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002738 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2739 break;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002740 case PCI_DEVICE_ID_QLOGIC_ISP2271:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002741 ha->isp_type |= DT_ISP2271;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002742 ha->device_type |= DT_ZIO_SUPPORTED;
2743 ha->device_type |= DT_FWI2;
2744 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002745 ha->device_type |= DT_T10_PI;
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002746 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2747 break;
Sawan Chandak2b489922015-08-04 13:38:03 -04002748 case PCI_DEVICE_ID_QLOGIC_ISP2261:
Joe Carnuccio9e052e22016-07-06 11:14:31 -04002749 ha->isp_type |= DT_ISP2261;
Sawan Chandak2b489922015-08-04 13:38:03 -04002750 ha->device_type |= DT_ZIO_SUPPORTED;
2751 ha->device_type |= DT_FWI2;
2752 ha->device_type |= DT_IIDMA;
Himanshu Madhani8ce3f572016-01-27 12:03:36 -05002753 ha->device_type |= DT_T10_PI;
Sawan Chandak2b489922015-08-04 13:38:03 -04002754 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2755 break;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002756 case PCI_DEVICE_ID_QLOGIC_ISP2081:
2757 case PCI_DEVICE_ID_QLOGIC_ISP2089:
2758 ha->isp_type |= DT_ISP2081;
2759 ha->device_type |= DT_ZIO_SUPPORTED;
2760 ha->device_type |= DT_FWI2;
2761 ha->device_type |= DT_IIDMA;
2762 ha->device_type |= DT_T10_PI;
2763 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2764 break;
2765 case PCI_DEVICE_ID_QLOGIC_ISP2281:
2766 case PCI_DEVICE_ID_QLOGIC_ISP2289:
2767 ha->isp_type |= DT_ISP2281;
2768 ha->device_type |= DT_ZIO_SUPPORTED;
2769 ha->device_type |= DT_FWI2;
2770 ha->device_type |= DT_IIDMA;
2771 ha->device_type |= DT_T10_PI;
2772 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2773 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002774 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07002775
Giridhar Malavalia9083012010-04-12 17:59:55 -07002776 if (IS_QLA82XX(ha))
Saurav Kashyap43a9c382014-02-26 04:15:16 -05002777 ha->port_no = ha->portnum & 1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002778 else {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002779 /* Get adapter physical port no from interrupt pin register. */
2780 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002781 if (IS_QLA25XX(ha) || IS_QLA2031(ha) ||
2782 IS_QLA27XX(ha) || IS_QLA28XX(ha))
Chad Dupuisf73cb692014-02-26 04:15:06 -05002783 ha->port_no--;
2784 else
2785 ha->port_no = !(ha->port_no & 1);
2786 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07002787
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002788 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
Joe Perchesd8424f62011-11-18 09:03:06 -08002789 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
Chad Dupuisf73cb692014-02-26 04:15:06 -05002790 ha->device_type, ha->port_no, ha->fw_srisc_address);
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002791}
2792
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002793static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002794qla2xxx_scan_start(struct Scsi_Host *shost)
2795{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002796 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002797
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07002798 if (vha->hw->flags.running_gold_fw)
2799 return;
2800
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002801 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2802 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2803 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2804 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002805}
2806
2807static int
2808qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2809{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002810 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002811
Bill Kuzejaa5dd506e2016-10-21 16:45:27 -04002812 if (test_bit(UNLOADING, &vha->dpc_flags))
2813 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002815 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002817 return 1;
2818
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002819 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08002820}
2821
Quinn Tranec7193e2017-03-15 09:48:55 -07002822static void qla2x00_iocb_work_fn(struct work_struct *work)
2823{
2824 struct scsi_qla_host *vha = container_of(work,
2825 struct scsi_qla_host, iocb_work);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002826 struct qla_hw_data *ha = vha->hw;
2827 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran0aca7782018-09-04 14:19:16 -07002828 int i = 2;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002829 unsigned long flags;
Quinn Tranec7193e2017-03-15 09:48:55 -07002830
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002831 if (test_bit(UNLOADING, &base_vha->dpc_flags))
2832 return;
2833
2834 while (!list_empty(&vha->work_list) && i > 0) {
Quinn Tranec7193e2017-03-15 09:48:55 -07002835 qla2x00_do_work(vha);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002836 i--;
Quinn Tranec7193e2017-03-15 09:48:55 -07002837 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08002838
2839 spin_lock_irqsave(&vha->work_lock, flags);
2840 clear_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags);
2841 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07002842}
2843
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844/*
2845 * PCI driver interface
2846 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08002847static int
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002848qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002850 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 scsi_qla_host_t *base_vha = NULL;
2853 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07002854 char pci_info[30];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002855 char fw_str[30], wq_name[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08002856 struct scsi_host_template *sht;
Chad Dupuis642ef982012-02-09 11:15:57 -08002857 int bars, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002858 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002859 struct req_que *req = NULL;
2860 struct rsp_que *rsp = NULL;
Michael Hernandez56012362016-12-12 14:40:08 -08002861 int i;
Michael Hernandezd7459522016-12-12 14:40:07 -08002862
Andrew Vasquez285d0322007-10-19 15:59:17 -07002863 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07002864 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07002865 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2866 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002867 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07002868 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2869 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002870 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07002871 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002872 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2873 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002874 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002875 pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
Chad Dupuisf73cb692014-02-26 04:15:06 -05002876 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04002877 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
Sawan Chandak2b489922015-08-04 13:38:03 -04002878 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002879 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261 ||
2880 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2081 ||
2881 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2281 ||
2882 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2089 ||
2883 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2289) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07002884 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002885 mem_only = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002886 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2887 "Mem only adapter.\n");
Andrew Vasquez285d0322007-10-19 15:59:17 -07002888 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002889 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2890 "Bars=%d.\n", bars);
Andrew Vasquez285d0322007-10-19 15:59:17 -07002891
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002892 if (mem_only) {
2893 if (pci_enable_device_mem(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002894 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002895 } else {
2896 if (pci_enable_device(pdev))
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002897 return ret;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
Jesse Barnes09276782008-10-18 17:33:19 -07002900 /* This may fail but that's ok */
2901 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07002902
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2904 if (!ha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002905 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2906 "Unable to allocate memory for ha.\n");
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02002907 goto disable_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002909 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2910 "Memory allocated for ha=%p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002911 ha->pdev = pdev;
Quinn Tran33e79972014-09-25 06:14:55 -04002912 INIT_LIST_HEAD(&ha->tgt.q_full_list);
2913 spin_lock_init(&ha->tgt.q_full_lock);
Quinn Tran75601512015-12-17 14:57:04 -05002914 spin_lock_init(&ha->tgt.sess_lock);
Quinn Tran2f424b92015-12-17 14:57:07 -05002915 spin_lock_init(&ha->tgt.atio_lock);
2916
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07002917 atomic_set(&ha->nvme_active_aen_cnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918
2919 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07002920 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11002921 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08002922 spin_lock_init(&ha->hardware_lock);
Andrew Vasquez339aa702010-10-15 11:27:45 -07002923 spin_lock_init(&ha->vport_slock);
Saurav Kashyapa9b6f722012-08-22 14:21:01 -04002924 mutex_init(&ha->selflogin_lock);
Chad Dupuis7a8ab9c2014-02-26 04:14:56 -05002925 mutex_init(&ha->optrom_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002927 /* Set ISP-type information. */
2928 qla2x00_set_isp_flags(ha);
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002929
2930 /* Set EEH reset type to fundamental if required by hba */
Joe Carnuccio95676112012-08-22 14:21:20 -04002931 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002932 IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002933 pdev->needs_freset = 1;
Duane Grigsbyca79cf62009-12-15 21:29:47 -08002934
Chad Dupuiscba1e472011-11-18 09:03:21 -08002935 ha->prev_topology = 0;
2936 ha->init_cb_size = sizeof(init_cb_t);
2937 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2938 ha->optrom_size = OPTROM_SIZE_2300;
Quinn Trand1e36352017-12-28 12:33:12 -08002939 ha->max_exchg = FW_MAX_EXCHANGES_CNT;
Quinn Tranb2000802018-08-02 13:16:52 -07002940 atomic_set(&ha->num_pend_mbx_stage1, 0);
2941 atomic_set(&ha->num_pend_mbx_stage2, 0);
2942 atomic_set(&ha->num_pend_mbx_stage3, 0);
Quinn Tran8b4673b2018-09-04 14:19:14 -07002943 atomic_set(&ha->zio_threshold, DEFAULT_ZIO_THRESHOLD);
2944 ha->last_zio_threshold = DEFAULT_ZIO_THRESHOLD;
Chad Dupuiscba1e472011-11-18 09:03:21 -08002945
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002946 /* Assign ISP specific operations. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 if (IS_QLA2100(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002948 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002950 req_length = REQUEST_ENTRY_CNT_2100;
2951 rsp_length = RESPONSE_ENTRY_CNT_2100;
2952 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002953 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002954 ha->flash_conf_off = ~0;
2955 ha->flash_data_off = ~0;
2956 ha->nvram_conf_off = ~0;
2957 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002958 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 } else if (IS_QLA2200(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002960 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Andrew Vasquez67ddda32012-02-09 11:14:08 -08002961 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002962 req_length = REQUEST_ENTRY_CNT_2200;
2963 rsp_length = RESPONSE_ENTRY_CNT_2100;
2964 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002965 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002966 ha->flash_conf_off = ~0;
2967 ha->flash_data_off = ~0;
2968 ha->nvram_conf_off = ~0;
2969 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002970 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002971 } else if (IS_QLA23XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002972 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002974 req_length = REQUEST_ENTRY_CNT_2200;
2975 rsp_length = RESPONSE_ENTRY_CNT_2300;
2976 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002977 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002978 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2979 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002980 ha->flash_conf_off = ~0;
2981 ha->flash_data_off = ~0;
2982 ha->nvram_conf_off = ~0;
2983 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002984 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002985 } else if (IS_QLA24XX_TYPE(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08002986 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002987 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002988 req_length = REQUEST_ENTRY_CNT_24XX;
2989 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002990 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002992 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07002993 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08002994 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002995 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002996 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002997 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2998 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2999 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3000 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003001 } else if (IS_QLA25XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08003002 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003003 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 req_length = REQUEST_ENTRY_CNT_24XX;
3005 rsp_length = RESPONSE_ENTRY_CNT_2300;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003006 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003008 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003009 ha->gid_list_info_size = 8;
3010 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003011 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003012 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003013 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3014 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3015 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3016 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
3017 } else if (IS_QLA81XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08003018 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003019 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3020 req_length = REQUEST_ENTRY_CNT_24XX;
3021 rsp_length = RESPONSE_ENTRY_CNT_2300;
Arun Easiaa230bc2013-01-30 03:34:39 -05003022 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003023 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3024 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3025 ha->gid_list_info_size = 8;
3026 ha->optrom_size = OPTROM_SIZE_81XX;
Anirban Chakraborty40859ae2009-06-03 09:55:16 -07003027 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003028 ha->isp_ops = &qla81xx_isp_ops;
3029 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3030 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3031 ha->nvram_conf_off = ~0;
3032 ha->nvram_data_off = ~0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003033 } else if (IS_QLA82XX(ha)) {
Chad Dupuis642ef982012-02-09 11:15:57 -08003034 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003035 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3036 req_length = REQUEST_ENTRY_CNT_82XX;
3037 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3038 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3039 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3040 ha->gid_list_info_size = 8;
3041 ha->optrom_size = OPTROM_SIZE_82XX;
Andrew Vasquez087c6212010-11-23 16:52:48 -08003042 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003043 ha->isp_ops = &qla82xx_isp_ops;
3044 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3045 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3046 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3047 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003048 } else if (IS_QLA8044(ha)) {
3049 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3050 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3051 req_length = REQUEST_ENTRY_CNT_82XX;
3052 rsp_length = RESPONSE_ENTRY_CNT_82XX;
3053 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3054 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3055 ha->gid_list_info_size = 8;
3056 ha->optrom_size = OPTROM_SIZE_83XX;
3057 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3058 ha->isp_ops = &qla8044_isp_ops;
3059 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
3060 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
3061 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
3062 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003063 } else if (IS_QLA83XX(ha)) {
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003064 ha->portnum = PCI_FUNC(ha->pdev->devfn);
Chad Dupuis642ef982012-02-09 11:15:57 -08003065 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003066 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Saurav Kashyapf2ea6532014-09-25 06:14:54 -04003067 req_length = REQUEST_ENTRY_CNT_83XX;
Quinn Trane7b42e32015-12-17 14:57:09 -05003068 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Arun Easib8aa4bd2013-01-30 03:34:40 -05003069 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003070 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3071 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3072 ha->gid_list_info_size = 8;
3073 ha->optrom_size = OPTROM_SIZE_83XX;
3074 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3075 ha->isp_ops = &qla83xx_isp_ops;
3076 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3077 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3078 ha->nvram_conf_off = ~0;
3079 ha->nvram_data_off = ~0;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003080 } else if (IS_QLAFX00(ha)) {
3081 ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
3082 ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
3083 ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
3084 req_length = REQUEST_ENTRY_CNT_FX00;
3085 rsp_length = RESPONSE_ENTRY_CNT_FX00;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003086 ha->isp_ops = &qlafx00_isp_ops;
3087 ha->port_down_retry_count = 30; /* default value */
3088 ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
3089 ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
Armen Baloyan71e56002013-08-27 01:37:38 -04003090 ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003091 ha->mr.fw_hbt_en = 1;
Armen Baloyane8f5e952013-10-30 03:38:17 -04003092 ha->mr.host_info_resend = false;
3093 ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003094 } else if (IS_QLA27XX(ha)) {
3095 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3096 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3097 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Quinn Trane7b42e32015-12-17 14:57:09 -05003098 req_length = REQUEST_ENTRY_CNT_83XX;
3099 rsp_length = RESPONSE_ENTRY_CNT_83XX;
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04003100 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003101 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3102 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3103 ha->gid_list_info_size = 8;
3104 ha->optrom_size = OPTROM_SIZE_83XX;
3105 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3106 ha->isp_ops = &qla27xx_isp_ops;
3107 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
3108 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
3109 ha->nvram_conf_off = ~0;
3110 ha->nvram_data_off = ~0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003111 } else if (IS_QLA28XX(ha)) {
3112 ha->portnum = PCI_FUNC(ha->pdev->devfn);
3113 ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
3114 ha->mbx_count = MAILBOX_REGISTER_COUNT;
3115 req_length = REQUEST_ENTRY_CNT_24XX;
3116 rsp_length = RESPONSE_ENTRY_CNT_2300;
3117 ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
3118 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
3119 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
3120 ha->gid_list_info_size = 8;
3121 ha->optrom_size = OPTROM_SIZE_28XX;
3122 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
3123 ha->isp_ops = &qla27xx_isp_ops;
3124 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_28XX;
3125 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_28XX;
3126 ha->nvram_conf_off = ~0;
3127 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003129
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003130 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
3131 "mbx_count=%d, req_length=%d, "
3132 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
Chad Dupuis642ef982012-02-09 11:15:57 -08003133 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
3134 "max_fibre_devices=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003135 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
3136 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
Chad Dupuis642ef982012-02-09 11:15:57 -08003137 ha->nvram_npiv_size, ha->max_fibre_devices);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003138 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
3139 "isp_ops=%p, flash_conf_off=%d, "
3140 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
3141 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
3142 ha->nvram_conf_off, ha->nvram_data_off);
Giridhar Malavali706f4572011-11-18 09:03:16 -08003143
3144 /* Configure PCI I/O space */
3145 ret = ha->isp_ops->iospace_config(ha);
3146 if (ret)
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003147 goto iospace_config_failed;
Giridhar Malavali706f4572011-11-18 09:03:16 -08003148
3149 ql_log_pci(ql_log_info, pdev, 0x001d,
3150 "Found an ISP%04X irq %d iobase 0x%p.\n",
3151 pdev->device, pdev->irq, ha->iobase);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003152 mutex_init(&ha->vport_lock);
Michael Hernandezd7459522016-12-12 14:40:07 -08003153 mutex_init(&ha->mq_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08003154 init_completion(&ha->mbx_cmd_comp);
3155 complete(&ha->mbx_cmd_comp);
3156 init_completion(&ha->mbx_intr_comp);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003157 init_completion(&ha->dcbx_comp);
Chad Dupuisf356bef2013-02-08 01:58:04 -05003158 init_completion(&ha->lb_portup_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003160 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
Andrew Vasquez53303c42009-01-22 09:45:37 -08003162 qla2x00_config_dma_addressing(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003163 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
3164 "64 Bit addressing is %s.\n",
3165 ha->flags.enable_64bit_addressing ? "enable" :
3166 "disable");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003167 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03003168 if (ret) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003169 ql_log_pci(ql_log_fatal, pdev, 0x0031,
3170 "Failed to allocate memory for adapter, aborting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003172 goto probe_hw_failed;
3173 }
3174
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003175 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003177 req->max_q_depth = ql2xmaxqdepth;
3178
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003179
3180 base_vha = qla2x00_create_host(sht, ha);
3181 if (!base_vha) {
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003182 ret = -ENOMEM;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 }
3185
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 pci_set_drvdata(pdev, base_vha);
Joe Lawrence6b383972014-08-26 17:12:29 -04003187 set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003189 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003190 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003191 if (IS_QLA2XXX_MIDTYPE(ha))
Quinn Tranf6602f32018-08-02 13:16:53 -07003192 base_vha->mgmt_svr_loop_id =
3193 qla2x00_reserve_mgmt_server_loop_id(base_vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003194 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003195 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
3196 base_vha->vp_idx;
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003197
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003198 /* Setup fcport template structure. */
3199 ha->mr.fcport.vha = base_vha;
3200 ha->mr.fcport.port_type = FCT_UNKNOWN;
3201 ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
3202 qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
3203 ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
3204 ha->mr.fcport.scan_state = 1;
3205
Giridhar Malavali58548cb2010-09-03 15:20:56 -07003206 /* Set the SG table size based on ISP type */
3207 if (!IS_FWI2_CAPABLE(ha)) {
3208 if (IS_QLA2100(ha))
3209 host->sg_tablesize = 32;
3210 } else {
3211 if (!IS_QLA82XX(ha))
3212 host->sg_tablesize = QLA_SG_ALL;
3213 }
Chad Dupuis642ef982012-02-09 11:15:57 -08003214 host->max_id = ha->max_fibre_devices;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003215 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07003216 host->unique_id = host->host_no;
Arun Easie02587d2011-08-16 11:29:23 -07003217 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +05003218 host->max_cmd_len = 32;
3219 else
3220 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07003221 host->max_channel = MAX_BUSES - 1;
Hannes Reinecke755f5162014-06-03 10:58:54 +02003222 /* Older HBAs support only 16-bit LUNs */
3223 if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
3224 ql2xmaxlun > 0xffff)
3225 host->max_lun = 0xffff;
3226 else
3227 host->max_lun = ql2xmaxlun;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003228 host->transportt = qla2xxx_transport_template;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003229 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003230
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003231 ql_dbg(ql_dbg_init, base_vha, 0x0033,
3232 "max_id=%d this_id=%d "
3233 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
Hannes Reinecke1abf6352014-06-25 15:27:38 +02003234 "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003235 host->this_id, host->cmd_per_lun, host->unique_id,
3236 host->max_cmd_len, host->max_channel, host->max_lun,
3237 host->transportt, sht->vendor_id);
3238
Himanshu Madhani1010f212017-10-16 11:26:05 -07003239 INIT_WORK(&base_vha->iocb_work, qla2x00_iocb_work_fn);
3240
Michael Hernandezd7459522016-12-12 14:40:07 -08003241 /* Set up the irqs */
3242 ret = qla2x00_request_irqs(ha, rsp);
3243 if (ret)
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003244 goto probe_failed;
Michael Hernandezd7459522016-12-12 14:40:07 -08003245
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003246 /* Alloc arrays of request and response ring ptrs */
Bill Kuzeja6d634062018-03-23 10:37:25 -04003247 ret = qla2x00_alloc_queues(ha, req, rsp);
3248 if (ret) {
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003249 ql_log(ql_log_fatal, base_vha, 0x003d,
3250 "Failed to allocate memory for queue pointers..."
3251 "aborting.\n");
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05003252 goto probe_failed;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003253 }
3254
Jens Axboef664a3c2018-11-01 16:36:27 -06003255 if (ha->mqenable) {
Michael Hernandez56012362016-12-12 14:40:08 -08003256 /* number of hardware queues supported by blk/scsi-mq*/
3257 host->nr_hw_queues = ha->max_qpairs;
3258
3259 ql_dbg(ql_dbg_init, base_vha, 0x0192,
3260 "blk/scsi-mq enabled, HW queues = %d.\n", host->nr_hw_queues);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07003261 } else {
3262 if (ql2xnvmeenable) {
3263 host->nr_hw_queues = ha->max_qpairs;
3264 ql_dbg(ql_dbg_init, base_vha, 0x0194,
3265 "FC-NVMe support is enabled, HW queues=%d\n",
3266 host->nr_hw_queues);
3267 } else {
3268 ql_dbg(ql_dbg_init, base_vha, 0x0193,
3269 "blk/scsi-mq disabled.\n");
3270 }
3271 }
Michael Hernandez56012362016-12-12 14:40:08 -08003272
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003273 qlt_probe_one_stage1(base_vha, ha);
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003274
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003275 pci_save_state(pdev);
3276
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003277 /* Assign back pointers */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003278 rsp->req = req;
3279 req->rsp = rsp;
Chad Dupuis9a347ff2012-05-15 14:34:14 -04003280
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003281 if (IS_QLAFX00(ha)) {
3282 ha->rsp_q_map[0] = rsp;
3283 ha->req_q_map[0] = req;
3284 set_bit(0, ha->req_qid_map);
3285 set_bit(0, ha->rsp_qid_map);
3286 }
3287
Andrew Vasquez08029992009-03-24 09:07:55 -07003288 /* FWI2-capable only. */
3289 req->req_q_in = &ha->iobase->isp24.req_q_in;
3290 req->req_q_out = &ha->iobase->isp24.req_q_out;
3291 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
3292 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003293 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3294 IS_QLA28XX(ha)) {
Andrew Vasquez08029992009-03-24 09:07:55 -07003295 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
3296 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
3297 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
3298 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003299 }
3300
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003301 if (IS_QLAFX00(ha)) {
3302 req->req_q_in = &ha->iobase->ispfx00.req_q_in;
3303 req->req_q_out = &ha->iobase->ispfx00.req_q_out;
3304 rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
3305 rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
3306 }
3307
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003308 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003309 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
3310 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
3311 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
3312 }
3313
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003314 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
3315 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3316 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3317 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
3318 "req->req_q_in=%p req->req_q_out=%p "
3319 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3320 req->req_q_in, req->req_q_out,
3321 rsp->rsp_q_in, rsp->rsp_q_out);
3322 ql_dbg(ql_dbg_init, base_vha, 0x003e,
3323 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
3324 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
3325 ql_dbg(ql_dbg_init, base_vha, 0x003f,
3326 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
3327 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003328
himanshu.madhani@cavium.comd48cc672018-07-02 13:01:59 -07003329 ha->wq = alloc_workqueue("qla2xxx_wq", 0, 0);
3330
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003331 if (ha->isp_ops->initialize_adapter(base_vha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003332 ql_log(ql_log_fatal, base_vha, 0x00d6,
3333 "Failed to initialize adapter - Adapter flags %x.\n",
3334 base_vha->device_flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003335
Giridhar Malavalia9083012010-04-12 17:59:55 -07003336 if (IS_QLA82XX(ha)) {
3337 qla82xx_idc_lock(ha);
3338 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003339 QLA8XXX_DEV_FAILED);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003340 qla82xx_idc_unlock(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003341 ql_log(ql_log_fatal, base_vha, 0x00d7,
3342 "HW State: FAILED.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003343 } else if (IS_QLA8044(ha)) {
3344 qla8044_idc_lock(ha);
3345 qla8044_wr_direct(base_vha,
3346 QLA8044_CRB_DEV_STATE_INDEX,
3347 QLA8XXX_DEV_FAILED);
3348 qla8044_idc_unlock(ha);
3349 ql_log(ql_log_fatal, base_vha, 0x0150,
3350 "HW State: FAILED.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003351 }
3352
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 ret = -ENODEV;
3354 goto probe_failed;
3355 }
3356
Chad Dupuis3b1bef62014-02-26 04:15:04 -05003357 if (IS_QLAFX00(ha))
3358 host->can_queue = QLAFX00_MAX_CANQUEUE;
3359 else
3360 host->can_queue = req->num_outstanding_cmds - 10;
3361
3362 ql_dbg(ql_dbg_init, base_vha, 0x0032,
3363 "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
3364 host->can_queue, base_vha->req,
3365 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
3366
Quinn Trane326d222017-06-13 20:47:18 -07003367 if (ha->mqenable) {
Quinn Trane326d222017-06-13 20:47:18 -07003368 bool startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003369
Jens Axboef664a3c2018-11-01 16:36:27 -06003370 if (QLA_TGT_MODE_ENABLED())
Quinn Trane326d222017-06-13 20:47:18 -07003371 startit = false;
Quinn Trane326d222017-06-13 20:47:18 -07003372
Jens Axboef664a3c2018-11-01 16:36:27 -06003373 if (ql2x_ini_mode == QLA2XXX_INI_MODE_ENABLED)
Quinn Trane326d222017-06-13 20:47:18 -07003374 startit = true;
Quinn Trane326d222017-06-13 20:47:18 -07003375
Jens Axboef664a3c2018-11-01 16:36:27 -06003376 /* Create start of day qpairs for Block MQ */
3377 for (i = 0; i < ha->max_qpairs; i++)
3378 qla2xxx_create_qpair(base_vha, 5, 0, startit);
Michael Hernandez56012362016-12-12 14:40:08 -08003379 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003380
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003381 if (ha->flags.running_gold_fw)
3382 goto skip_dpc;
3383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 /*
3385 * Startup the kernel thread for this host adapter
3386 */
3387 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003388 "%s_dpc", base_vha->host_str);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 if (IS_ERR(ha->dpc_thread)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003390 ql_log(ql_log_fatal, base_vha, 0x00ed,
3391 "Failed to start DPC thread.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 ret = PTR_ERR(ha->dpc_thread);
Douglas Millere2532b42017-10-20 08:17:22 -05003393 ha->dpc_thread = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394 goto probe_failed;
3395 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003396 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
3397 "DPC thread started successfully.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003398
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003399 /*
3400 * If we're not coming up in initiator mode, we might sit for
3401 * a while without waking up the dpc thread, which leads to a
3402 * stuck process warning. So just kick the dpc once here and
3403 * let the kthread start (and go back to sleep in qla2x00_do_dpc).
3404 */
3405 qla2xxx_wake_dpc(base_vha);
3406
Chad Dupuisf3ddac12013-10-30 03:38:16 -04003407 INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
3408
Saurav Kashyap81178772012-08-22 14:21:04 -04003409 if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
3410 sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
3411 ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
3412 INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
3413
3414 sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
3415 ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
3416 INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
3417 INIT_WORK(&ha->idc_state_handler,
3418 qla83xx_idc_state_handler_work);
3419 INIT_WORK(&ha->nic_core_unrecoverable,
3420 qla83xx_nic_core_unrecoverable_work);
3421 }
3422
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003423skip_dpc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003424 list_add_tail(&base_vha->list, &ha->vp_list);
3425 base_vha->host->irq = ha->pdev->irq;
3426
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 /* Initialized the timer */
Kees Cook8e5f4ba2017-09-03 13:23:32 -07003428 qla2x00_start_timer(base_vha, WATCH_INTERVAL);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003429 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
3430 "Started qla2x00_timer with "
3431 "interval=%d.\n", WATCH_INTERVAL);
3432 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
3433 "Detected hba at address=%p.\n",
3434 ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435
Arun Easie02587d2011-08-16 11:29:23 -07003436 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
Arun Easibad75002010-05-04 15:01:30 -07003437 if (ha->fw_attributes & BIT_4) {
Arun Easi9e522cd2012-08-22 14:21:31 -04003438 int prot = 0, guard;
Arun Easibad75002010-05-04 15:01:30 -07003439 base_vha->flags.difdix_supported = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003440 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
3441 "Registering for DIF/DIX type 1 and 3 protection.\n");
Arun Easi8cb20492011-08-16 11:29:22 -07003442 if (ql2xenabledif == 1)
3443 prot = SHOST_DIX_TYPE0_PROTECTION;
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003444 if (ql2xprotmask)
3445 scsi_host_set_prot(host, ql2xprotmask);
3446 else
3447 scsi_host_set_prot(host,
3448 prot | SHOST_DIF_TYPE1_PROTECTION
3449 | SHOST_DIF_TYPE2_PROTECTION
3450 | SHOST_DIF_TYPE3_PROTECTION
3451 | SHOST_DIX_TYPE1_PROTECTION
3452 | SHOST_DIX_TYPE2_PROTECTION
3453 | SHOST_DIX_TYPE3_PROTECTION);
Arun Easi9e522cd2012-08-22 14:21:31 -04003454
3455 guard = SHOST_DIX_GUARD_CRC;
3456
3457 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3458 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3459 guard |= SHOST_DIX_GUARD_IP;
3460
Martin K. Petersen7855d2b2018-12-21 09:33:44 -08003461 if (ql2xprotguard)
3462 scsi_host_set_guard(host, ql2xprotguard);
3463 else
3464 scsi_host_set_guard(host, guard);
Arun Easibad75002010-05-04 15:01:30 -07003465 } else
3466 base_vha->flags.difdix_supported = 0;
3467 }
3468
Giridhar Malavalia9083012010-04-12 17:59:55 -07003469 ha->isp_ops->enable_intrs(ha);
3470
Armen Baloyan1fe19ee2013-08-27 01:37:41 -04003471 if (IS_QLAFX00(ha)) {
3472 ret = qlafx00_fx_disc(base_vha,
3473 &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
3474 host->sg_tablesize = (ha->mr.extended_io_enabled) ?
3475 QLA_SG_ALL : 128;
3476 }
3477
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003478 ret = scsi_add_host(host, &pdev->dev);
3479 if (ret)
3480 goto probe_failed;
3481
Michael Reed14864002009-12-02 09:11:16 -06003482 base_vha->flags.init_done = 1;
3483 base_vha->flags.online = 1;
Saurav Kashyapedaa5c72014-04-11 16:54:14 -04003484 ha->prev_minidump_failed = 0;
Michael Reed14864002009-12-02 09:11:16 -06003485
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003486 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
3487 "Init done and hba is online.\n");
3488
Quinn Tran726b8542017-01-19 22:28:00 -08003489 if (qla_ini_mode_enabled(base_vha) ||
3490 qla_dual_mode_enabled(base_vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003491 scsi_scan_host(host);
3492 else
3493 ql_dbg(ql_dbg_init, base_vha, 0x0122,
3494 "skipping scsi_scan_host() for non-initiator port\n");
Andrew Vasquez1e99e332006-11-22 08:24:48 -08003495
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003496 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003497
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003498 if (IS_QLAFX00(ha)) {
3499 ret = qlafx00_fx_disc(base_vha,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003500 &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
3501
3502 /* Register system information */
3503 ret = qlafx00_fx_disc(base_vha,
3504 &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
3505 }
3506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003507 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003508
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003509 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003510
Armen Baloyan03eb9122013-10-30 03:38:22 -04003511 ql_log(ql_log_info, base_vha, 0x00fb,
3512 "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003513 ql_log(ql_log_info, base_vha, 0x00fc,
3514 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
3515 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
3516 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
3517 base_vha->host_no,
Himanshu Madhanidf57cab2014-09-25 05:16:46 -04003518 ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003520 qlt_add_target(ha, base_vha);
3521
Joe Lawrence6b383972014-08-26 17:12:29 -04003522 clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04003523
3524 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3525 return -ENODEV;
3526
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003527 if (ha->flags.detected_lr_sfp) {
3528 ql_log(ql_log_info, base_vha, 0xffff,
3529 "Reset chip to pick up LR SFP setting\n");
3530 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
3531 qla2xxx_wake_dpc(base_vha);
3532 }
3533
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 return 0;
3535
3536probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07003537 if (base_vha->timer_active)
3538 qla2x00_stop_timer(base_vha);
3539 base_vha->flags.online = 0;
3540 if (ha->dpc_thread) {
3541 struct task_struct *t = ha->dpc_thread;
3542
3543 ha->dpc_thread = NULL;
3544 kthread_stop(t);
3545 }
3546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547 qla2x00_free_device(base_vha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003548 scsi_host_put(base_vha->host);
Bill Kuzeja6d634062018-03-23 10:37:25 -04003549 /*
3550 * Need to NULL out local req/rsp after
3551 * qla2x00_free_device => qla2x00_free_queues frees
3552 * what these are pointing to. Or else we'll
3553 * fall over below in qla2x00_free_req/rsp_que.
3554 */
3555 req = NULL;
3556 rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558probe_hw_failed:
himanshu.madhani@cavium.comd64d6c52018-01-15 20:46:46 -08003559 qla2x00_mem_free(ha);
3560 qla2x00_free_req_que(ha, req);
3561 qla2x00_free_rsp_que(ha, rsp);
Joe Lawrence1a2fbf12014-08-26 17:11:18 -04003562 qla2x00_clear_drv_active(ha);
3563
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003564iospace_config_failed:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003565 if (IS_P3P_TYPE(ha)) {
Saurav Kashyap0a63ad12012-11-21 02:40:43 -05003566 if (!ha->nx_pcibase)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003567 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003568 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003569 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003570 } else {
3571 if (ha->iobase)
3572 iounmap(ha->iobase);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003573 if (ha->cregbase)
3574 iounmap(ha->cregbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003575 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003576 pci_release_selected_regions(ha->pdev, ha->bars);
3577 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578
Johannes Thumshirnddff7ed2017-05-23 16:50:47 +02003579disable_device:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003580 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07003581 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583
Adrian Bunk4c993f72008-01-14 00:55:16 -08003584static void
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003585qla2x00_shutdown(struct pci_dev *pdev)
3586{
3587 scsi_qla_host_t *vha;
3588 struct qla_hw_data *ha;
3589
3590 vha = pci_get_drvdata(pdev);
3591 ha = vha->hw;
3592
Sawan Chandakefdb5762017-08-23 15:05:00 -07003593 ql_log(ql_log_info, vha, 0xfffa,
3594 "Adapter shutdown\n");
3595
3596 /*
3597 * Prevent future board_disable and wait
3598 * until any pending board_disable has completed.
3599 */
3600 set_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags);
3601 cancel_work_sync(&ha->board_disable);
3602
3603 if (!atomic_read(&pdev->enable_cnt))
3604 return;
3605
Armen Baloyan42479342013-08-27 01:37:37 -04003606 /* Notify ISPFX00 firmware */
3607 if (IS_QLAFX00(ha))
3608 qlafx00_driver_shutdown(vha, 20);
3609
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003610 /* Turn-off FCE trace */
3611 if (ha->flags.fce_enabled) {
3612 qla2x00_disable_fce_trace(vha, NULL, NULL);
3613 ha->flags.fce_enabled = 0;
3614 }
3615
3616 /* Turn-off EFT trace */
3617 if (ha->eft)
3618 qla2x00_disable_eft_trace(vha);
3619
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003620 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3621 IS_QLA28XX(ha)) {
Quinn Tran3407fc32017-12-28 12:33:11 -08003622 if (ha->flags.fw_started)
3623 qla2x00_abort_isp_cleanup(vha);
3624 } else {
3625 /* Stop currently executing firmware. */
3626 qla2x00_try_to_stop_firmware(vha);
3627 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003628
3629 /* Turn adapter off line */
3630 vha->flags.online = 0;
3631
3632 /* turn-off interrupts on the card */
3633 if (ha->interrupts_on) {
3634 vha->flags.init_done = 0;
3635 ha->isp_ops->disable_intrs(ha);
3636 }
3637
3638 qla2x00_free_irqs(vha);
3639
3640 qla2x00_free_fw_dump(ha);
Chad Dupuis61d41f62014-09-25 05:17:02 -04003641
Chad Dupuis61d41f62014-09-25 05:17:02 -04003642 pci_disable_device(pdev);
Sawan Chandakefdb5762017-08-23 15:05:00 -07003643 ql_log(ql_log_info, vha, 0xfffe,
3644 "Adapter shutdown successfully.\n");
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003645}
3646
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003647/* Deletes all the virtual ports for a given ha */
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003648static void
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003649qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003651 scsi_qla_host_t *vha;
Arun Easifeafb7b2010-09-03 14:57:00 -07003652 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653
Arun Easi43ebf162011-05-10 11:18:16 -07003654 mutex_lock(&ha->vport_lock);
3655 while (ha->cur_vport_count) {
Arun Easi43ebf162011-05-10 11:18:16 -07003656 spin_lock_irqsave(&ha->vport_slock, flags);
Arun Easifeafb7b2010-09-03 14:57:00 -07003657
Arun Easi43ebf162011-05-10 11:18:16 -07003658 BUG_ON(base_vha->list.next == &ha->vp_list);
3659 /* This assumes first entry in ha->vp_list is always base vha */
3660 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
Bart Van Assche52c82822015-07-09 07:23:26 -07003661 scsi_host_get(vha->host);
Arun Easifeafb7b2010-09-03 14:57:00 -07003662
Arun Easi43ebf162011-05-10 11:18:16 -07003663 spin_unlock_irqrestore(&ha->vport_slock, flags);
3664 mutex_unlock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -07003665
Himanshu Madhani5e6803b2018-12-10 12:36:23 -08003666 qla_nvme_delete(vha);
3667
Arun Easi43ebf162011-05-10 11:18:16 -07003668 fc_vport_terminate(vha->fc_vport);
3669 scsi_host_put(vha->host);
3670
3671 mutex_lock(&ha->vport_lock);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003672 }
Arun Easi43ebf162011-05-10 11:18:16 -07003673 mutex_unlock(&ha->vport_lock);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003674}
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07003675
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003676/* Stops all deferred work threads */
3677static void
3678qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
3679{
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003680 /* Cancel all work and destroy DPC workqueues */
3681 if (ha->dpc_lp_wq) {
3682 cancel_work_sync(&ha->idc_aen);
3683 destroy_workqueue(ha->dpc_lp_wq);
3684 ha->dpc_lp_wq = NULL;
3685 }
3686
3687 if (ha->dpc_hp_wq) {
3688 cancel_work_sync(&ha->nic_core_reset);
3689 cancel_work_sync(&ha->idc_state_handler);
3690 cancel_work_sync(&ha->nic_core_unrecoverable);
3691 destroy_workqueue(ha->dpc_hp_wq);
3692 ha->dpc_hp_wq = NULL;
3693 }
3694
Andrew Vasquezb9978762009-03-24 09:08:05 -07003695 /* Kill the kernel thread for this host */
3696 if (ha->dpc_thread) {
3697 struct task_struct *t = ha->dpc_thread;
3698
3699 /*
3700 * qla2xxx_wake_dpc checks for ->dpc_thread
3701 * so we need to zero it out.
3702 */
3703 ha->dpc_thread = NULL;
3704 kthread_stop(t);
3705 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003706}
Andrew Vasquezb9978762009-03-24 09:08:05 -07003707
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003708static void
3709qla2x00_unmap_iobases(struct qla_hw_data *ha)
3710{
Giridhar Malavalia9083012010-04-12 17:59:55 -07003711 if (IS_QLA82XX(ha)) {
Giridhar Malavalib9637522010-05-28 15:08:15 -07003712
Chad Dupuisf73cb692014-02-26 04:15:06 -05003713 iounmap((device_reg_t *)ha->nx_pcibase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003714 if (!ql2xdbwr)
Chad Dupuisf73cb692014-02-26 04:15:06 -05003715 iounmap((device_reg_t *)ha->nxdb_wr_ptr);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003716 } else {
3717 if (ha->iobase)
3718 iounmap(ha->iobase);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003719
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003720 if (ha->cregbase)
3721 iounmap(ha->cregbase);
3722
Giridhar Malavalia9083012010-04-12 17:59:55 -07003723 if (ha->mqiobase)
3724 iounmap(ha->mqiobase);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003725
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003726 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) &&
3727 ha->msixbase)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003728 iounmap(ha->msixbase);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003729 }
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003730}
3731
3732static void
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003733qla2x00_clear_drv_active(struct qla_hw_data *ha)
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003734{
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003735 if (IS_QLA8044(ha)) {
3736 qla8044_idc_lock(ha);
Saurav Kashyapc41afc92013-11-07 02:54:56 -05003737 qla8044_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003738 qla8044_idc_unlock(ha);
3739 } else if (IS_QLA82XX(ha)) {
3740 qla82xx_idc_lock(ha);
3741 qla82xx_clear_drv_active(ha);
3742 qla82xx_idc_unlock(ha);
3743 }
3744}
3745
3746static void
3747qla2x00_remove_one(struct pci_dev *pdev)
3748{
3749 scsi_qla_host_t *base_vha;
3750 struct qla_hw_data *ha;
3751
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003752 base_vha = pci_get_drvdata(pdev);
3753 ha = base_vha->hw;
Quinn Tran45235022018-07-18 14:29:53 -07003754 ql_log(ql_log_info, base_vha, 0xb079,
3755 "Removing driver\n");
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003756
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003757 /* Indicate device removal to prevent future board_disable and wait
3758 * until any pending board_disable has completed. */
3759 set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
3760 cancel_work_sync(&ha->board_disable);
3761
3762 /*
3763 * If the PCI device is disabled then there was a PCI-disconnect and
3764 * qla2x00_disable_board_on_pci_error has taken care of most of the
3765 * resources.
3766 */
3767 if (!atomic_read(&pdev->enable_cnt)) {
Quinn Tran726b8542017-01-19 22:28:00 -08003768 dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3769 base_vha->gnl.l, base_vha->gnl.ldma);
3770
Joe Lawrencebeb9e312014-08-26 17:12:14 -04003771 scsi_host_put(base_vha->host);
3772 kfree(ha);
3773 pci_set_drvdata(pdev, NULL);
3774 return;
3775 }
Sawan Chandak638a1a02014-04-11 16:54:38 -04003776 qla2x00_wait_for_hba_ready(base_vha);
3777
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003778 if (IS_QLA25XX(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
3779 IS_QLA28XX(ha)) {
Quinn Tran45235022018-07-18 14:29:53 -07003780 if (ha->flags.fw_started)
3781 qla2x00_abort_isp_cleanup(base_vha);
3782 } else if (!IS_QLAFX00(ha)) {
3783 if (IS_QLA8031(ha)) {
3784 ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
3785 "Clearing fcoe driver presence.\n");
3786 if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
3787 ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
3788 "Error while clearing DRV-Presence.\n");
3789 }
3790
3791 qla2x00_try_to_stop_firmware(base_vha);
3792 }
3793
Quinn Tran2ce87cc2018-01-23 11:05:21 -08003794 qla2x00_wait_for_sess_deletion(base_vha);
3795
Quinn Tran726b8542017-01-19 22:28:00 -08003796 /*
3797 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04003798 * where it was set first.
3799 */
3800 if (test_bit(UNLOADING, &base_vha->dpc_flags))
3801 return;
3802
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003803 set_bit(UNLOADING, &base_vha->dpc_flags);
Duane Grigsbye84067d2017-06-21 13:48:43 -07003804
3805 qla_nvme_delete(base_vha);
3806
Quinn Tran726b8542017-01-19 22:28:00 -08003807 dma_free_coherent(&ha->pdev->dev,
3808 base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003809
Quinn Trana4239942017-12-28 12:33:26 -08003810 vfree(base_vha->scan.l);
3811
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003812 if (IS_QLAFX00(ha))
3813 qlafx00_driver_shutdown(base_vha, 20);
3814
3815 qla2x00_delete_all_vps(ha, base_vha);
3816
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003817 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3818
3819 qla2x00_dfs_remove(base_vha);
3820
3821 qla84xx_put_chip(base_vha);
3822
3823 /* Disable timer */
3824 if (base_vha->timer_active)
3825 qla2x00_stop_timer(base_vha);
3826
3827 base_vha->flags.online = 0;
3828
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003829 /* free DMA memory */
3830 if (ha->exlogin_buf)
3831 qla2x00_free_exlogin_buffer(ha);
3832
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003833 /* free DMA memory */
3834 if (ha->exchoffld_buf)
3835 qla2x00_free_exchoffld_buffer(ha);
3836
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003837 qla2x00_destroy_deferred_work(ha);
3838
3839 qlt_remove_target(ha, base_vha);
3840
3841 qla2x00_free_sysfs_attr(base_vha, true);
3842
3843 fc_remove_host(base_vha->host);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003844 qlt_remove_target_resources(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003845
3846 scsi_remove_host(base_vha->host);
3847
3848 qla2x00_free_device(base_vha);
3849
Joe Lawrencedb7157d2014-08-26 17:10:41 -04003850 qla2x00_clear_drv_active(ha);
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003851
Arun Easid2749ff2014-09-25 05:16:51 -04003852 scsi_host_put(base_vha->host);
3853
Chad Dupuisfe1b8062013-10-30 03:38:15 -04003854 qla2x00_unmap_iobases(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 pci_release_selected_regions(ha->pdev, ha->bars);
3857 kfree(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08003859 pci_disable_pcie_error_reporting(pdev);
3860
Bernhard Walle665db932007-03-28 00:49:49 +02003861 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863
3864static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003867 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868
Andrew Vasquez85880802009-12-15 21:29:46 -08003869 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3870
3871 /* Disable timer */
3872 if (vha->timer_active)
3873 qla2x00_stop_timer(vha);
3874
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003875 qla25xx_delete_queues(vha);
Andrew Vasquez85880802009-12-15 21:29:46 -08003876 vha->flags.online = 0;
3877
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003878 /* turn-off interrupts on the card */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003879 if (ha->interrupts_on) {
3880 vha->flags.init_done = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003881 ha->isp_ops->disable_intrs(ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003882 }
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003883
Quinn Tran093df732016-12-12 14:40:09 -08003884 qla2x00_free_fcports(vha);
3885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003886 qla2x00_free_irqs(vha);
3887
Quinn Tran093df732016-12-12 14:40:09 -08003888 /* Flush the work queue and remove it */
3889 if (ha->wq) {
3890 flush_workqueue(ha->wq);
3891 destroy_workqueue(ha->wq);
3892 ha->wq = NULL;
3893 }
3894
Chad Dupuis88670482010-07-23 15:28:30 +05003895
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003896 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003897
Giridhar Malavali08de2842011-08-16 11:31:44 -07003898 qla82xx_md_free(vha);
3899
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003900 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901}
3902
Chad Dupuis88670482010-07-23 15:28:30 +05003903void qla2x00_free_fcports(struct scsi_qla_host *vha)
3904{
3905 fc_port_t *fcport, *tfcport;
3906
3907 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
3908 list_del(&fcport->list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003909 qla2x00_clear_loop_id(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003910 kfree(fcport);
Chad Dupuis88670482010-07-23 15:28:30 +05003911 }
3912}
3913
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003914static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003915qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003916 int defer)
3917{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003918 struct fc_rport *rport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003919 scsi_qla_host_t *base_vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003920 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003921
3922 if (!fcport->rport)
3923 return;
3924
3925 rport = fcport->rport;
3926 if (defer) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003927 base_vha = pci_get_drvdata(vha->hw->pdev);
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003928 spin_lock_irqsave(vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003929 fcport->drport = rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003930 spin_unlock_irqrestore(vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003931 qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
Andrew Vasquez67becc02009-08-25 11:36:20 -07003932 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3933 qla2xxx_wake_dpc(base_vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003934 } else {
Alexei Potashnikdf673272015-07-14 16:00:46 -04003935 int now;
Quinn Tran726b8542017-01-19 22:28:00 -08003936 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003937 ql_dbg(ql_dbg_disc, fcport->vha, 0x2109,
3938 "%s %8phN. rport %p roles %x\n",
3939 __func__, fcport->port_name, rport,
3940 rport->roles);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003941 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003942 }
Alexei Potashnikdf673272015-07-14 16:00:46 -04003943 qlt_do_generation_tick(vha, &now);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003944 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003945}
3946
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
3949 *
3950 * Input: ha = adapter block pointer. fcport = port structure pointer.
3951 *
3952 * Return: None.
3953 *
3954 * Context:
3955 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003956void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003957 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958{
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003959 if (IS_QLAFX00(vha->hw)) {
3960 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
3961 qla2x00_schedule_rport_del(vha, fcport, defer);
3962 return;
3963 }
3964
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003965 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003966 vha->vp_idx == fcport->vha->vp_idx) {
Chad Dupuisec426e12011-03-30 11:46:32 -07003967 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 qla2x00_schedule_rport_del(vha, fcport, defer);
3969 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003970 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 * We may need to retry the login, so don't change the state of the
3972 * port but do the retries.
3973 */
3974 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
Chad Dupuisec426e12011-03-30 11:46:32 -07003975 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976
3977 if (!do_login)
3978 return;
3979
Arun Easia1d02852015-08-04 13:38:02 -04003980 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981}
3982
3983/*
3984 * qla2x00_mark_all_devices_lost
3985 * Updates fcport state when device goes offline.
3986 *
3987 * Input:
3988 * ha = adapter block pointer.
3989 * fcport = port structure pointer.
3990 *
3991 * Return:
3992 * None.
3993 *
3994 * Context:
3995 */
3996void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003997qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998{
3999 fc_port_t *fcport;
4000
Quinn Tran83548fe2017-06-02 09:12:01 -07004001 ql_dbg(ql_dbg_disc, vha, 0x20f1,
4002 "Mark all dev lost\n");
Quinn Tran726b8542017-01-19 22:28:00 -08004003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran726b8542017-01-19 22:28:00 -08004005 fcport->scan_state = 0;
Quinn Trand8630bb2017-12-28 12:33:43 -08004006 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004007
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04004008 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 continue;
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004010
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 /*
4012 * No point in marking the device as lost, if the device is
4013 * already DEAD.
4014 */
4015 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
4016 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004017 if (atomic_read(&fcport->state) == FCS_ONLINE) {
Chad Dupuisec426e12011-03-30 11:46:32 -07004018 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004019 if (defer)
4020 qla2x00_schedule_rport_del(vha, fcport, defer);
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04004021 else if (vha->vp_idx == fcport->vha->vp_idx)
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07004022 qla2x00_schedule_rport_del(vha, fcport, defer);
4023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 }
4025}
4026
4027/*
4028* qla2x00_mem_alloc
4029* Allocates adapter memory.
4030*
4031* Returns:
4032* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08004033* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08004035static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004036qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
4037 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038{
4039 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040
Andrew Vasqueze8711082008-01-31 12:33:48 -08004041 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004042 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004043 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004044 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004046 if (qlt_mem_alloc(ha) < 0)
4047 goto fail_free_init_cb;
4048
Chad Dupuis642ef982012-02-09 11:15:57 -08004049 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
4050 qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004051 if (!ha->gid_list)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004052 goto fail_free_tgt_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053
Andrew Vasqueze8711082008-01-31 12:33:48 -08004054 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
4055 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004058 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004059 /* Allocate cache for CT6 Ctx. */
4060 if (!ctx_cachep) {
4061 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
4062 sizeof(struct ct6_dsd), 0,
4063 SLAB_HWCACHE_ALIGN, NULL);
4064 if (!ctx_cachep)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004065 goto fail_free_srb_mempool;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004066 }
4067 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
4068 ctx_cachep);
4069 if (!ha->ctx_mempool)
4070 goto fail_free_srb_mempool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004071 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
4072 "ctx_cachep=%p ctx_mempool=%p.\n",
4073 ctx_cachep, ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004074 }
4075
Andrew Vasqueze8711082008-01-31 12:33:48 -08004076 /* Get memory for cached NVRAM */
4077 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
4078 if (!ha->nvram)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004079 goto fail_free_ctx_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004081 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
4082 ha->pdev->device);
4083 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4084 DMA_POOL_SIZE, 8, 0);
4085 if (!ha->s_dma_pool)
4086 goto fail_free_nvram;
4087
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004088 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
4089 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
4090 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
4091
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004092 if (IS_P3P_TYPE(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004093 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4094 DSD_LIST_DMA_POOL_SIZE, 8, 0);
4095 if (!ha->dl_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004096 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
4097 "Failed to allocate memory for dl_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004098 goto fail_s_dma_pool;
4099 }
4100
4101 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
4102 FCP_CMND_DMA_POOL_SIZE, 8, 0);
4103 if (!ha->fcp_cmnd_dma_pool) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004104 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
4105 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004106 goto fail_dl_dma_pool;
4107 }
Giridhar Malavali50b81272018-12-21 09:33:45 -08004108
4109 if (ql2xenabledif) {
4110 u64 bufsize = DIF_BUNDLING_DMA_POOL_SIZE;
4111 struct dsd_dma *dsd, *nxt;
4112 uint i;
4113 /* Creata a DMA pool of buffers for DIF bundling */
4114 ha->dif_bundl_pool = dma_pool_create(name,
4115 &ha->pdev->dev, DIF_BUNDLING_DMA_POOL_SIZE, 8, 0);
4116 if (!ha->dif_bundl_pool) {
4117 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4118 "%s: failed create dif_bundl_pool\n",
4119 __func__);
4120 goto fail_dif_bundl_dma_pool;
4121 }
4122
4123 INIT_LIST_HEAD(&ha->pool.good.head);
4124 INIT_LIST_HEAD(&ha->pool.unusable.head);
4125 ha->pool.good.count = 0;
4126 ha->pool.unusable.count = 0;
4127 for (i = 0; i < 128; i++) {
4128 dsd = kzalloc(sizeof(*dsd), GFP_ATOMIC);
4129 if (!dsd) {
4130 ql_dbg_pci(ql_dbg_init, ha->pdev,
4131 0xe0ee, "%s: failed alloc dsd\n",
4132 __func__);
4133 return 1;
4134 }
4135 ha->dif_bundle_kallocs++;
4136
4137 dsd->dsd_addr = dma_pool_alloc(
4138 ha->dif_bundl_pool, GFP_ATOMIC,
4139 &dsd->dsd_list_dma);
4140 if (!dsd->dsd_addr) {
4141 ql_dbg_pci(ql_dbg_init, ha->pdev,
4142 0xe0ee,
4143 "%s: failed alloc ->dsd_addr\n",
4144 __func__);
4145 kfree(dsd);
4146 ha->dif_bundle_kallocs--;
4147 continue;
4148 }
4149 ha->dif_bundle_dma_allocs++;
4150
4151 /*
4152 * if DMA buffer crosses 4G boundary,
4153 * put it on bad list
4154 */
4155 if (MSD(dsd->dsd_list_dma) ^
4156 MSD(dsd->dsd_list_dma + bufsize)) {
4157 list_add_tail(&dsd->list,
4158 &ha->pool.unusable.head);
4159 ha->pool.unusable.count++;
4160 } else {
4161 list_add_tail(&dsd->list,
4162 &ha->pool.good.head);
4163 ha->pool.good.count++;
4164 }
4165 }
4166
4167 /* return the good ones back to the pool */
4168 list_for_each_entry_safe(dsd, nxt,
4169 &ha->pool.good.head, list) {
4170 list_del(&dsd->list);
4171 dma_pool_free(ha->dif_bundl_pool,
4172 dsd->dsd_addr, dsd->dsd_list_dma);
4173 ha->dif_bundle_dma_allocs--;
4174 kfree(dsd);
4175 ha->dif_bundle_kallocs--;
4176 }
4177
4178 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0024,
4179 "%s: dif dma pool (good=%u unusable=%u)\n",
4180 __func__, ha->pool.good.count,
4181 ha->pool.unusable.count);
4182 }
4183
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004184 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
Giridhar Malavali50b81272018-12-21 09:33:45 -08004185 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p dif_bundl_pool=%p.\n",
4186 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool,
4187 ha->dif_bundl_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004188 }
4189
Andrew Vasqueze8711082008-01-31 12:33:48 -08004190 /* Allocate memory for SNS commands */
4191 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004192 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004193 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004194 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004195 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004196 goto fail_dma_pool;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004197 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
Joe Perchesd8424f62011-11-18 09:03:06 -08004198 "sns_cmd: %p.\n", ha->sns_cmd);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004199 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004200 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004201 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004202 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004203 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004204 goto fail_dma_pool;
4205 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08004206 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004207 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004208 if (!ha->ct_sns)
4209 goto fail_free_ms_iocb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004210 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
4211 "ms_iocb=%p ct_sns=%p.\n",
4212 ha->ms_iocb, ha->ct_sns);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 }
4214
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004215 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004216 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
4217 if (!*req) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004218 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
4219 "Failed to allocate memory for req.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004220 goto fail_req;
4221 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004222 (*req)->length = req_len;
4223 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
4224 ((*req)->length + 1) * sizeof(request_t),
4225 &(*req)->dma, GFP_KERNEL);
4226 if (!(*req)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004227 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
4228 "Failed to allocate memory for req_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004229 goto fail_req_ring;
4230 }
4231 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004232 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
4233 if (!*rsp) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004234 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
4235 "Failed to allocate memory for rsp.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004236 goto fail_rsp;
4237 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004238 (*rsp)->hw = ha;
4239 (*rsp)->length = rsp_len;
4240 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
4241 ((*rsp)->length + 1) * sizeof(response_t),
4242 &(*rsp)->dma, GFP_KERNEL);
4243 if (!(*rsp)->ring) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004244 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
4245 "Failed to allocate memory for rsp_ring.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004246 goto fail_rsp_ring;
4247 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004248 (*req)->rsp = *rsp;
4249 (*rsp)->req = *req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004250 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
4251 "req=%p req->length=%d req->ring=%p rsp=%p "
4252 "rsp->length=%d rsp->ring=%p.\n",
4253 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
4254 (*rsp)->ring);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004255 /* Allocate memory for NVRAM data for vports */
4256 if (ha->nvram_npiv_size) {
Kees Cook6396bb22018-06-12 14:03:40 -07004257 ha->npiv_info = kcalloc(ha->nvram_npiv_size,
4258 sizeof(struct qla_npiv_entry),
4259 GFP_KERNEL);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004260 if (!ha->npiv_info) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004261 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
4262 "Failed to allocate memory for npiv_info.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004263 goto fail_npiv_info;
4264 }
4265 } else
4266 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004267
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004268 /* Get consistent memory allocated for EX-INIT-CB. */
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004269 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
4270 IS_QLA28XX(ha)) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004271 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4272 &ha->ex_init_cb_dma);
4273 if (!ha->ex_init_cb)
4274 goto fail_ex_init_cb;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004275 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
4276 "ex_init_cb=%p.\n", ha->ex_init_cb);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004277 }
4278
Giridhar Malavalia9083012010-04-12 17:59:55 -07004279 INIT_LIST_HEAD(&ha->gbl_dsd_list);
4280
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004281 /* Get consistent memory allocated for Async Port-Database. */
4282 if (!IS_FWI2_CAPABLE(ha)) {
4283 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
4284 &ha->async_pd_dma);
4285 if (!ha->async_pd)
4286 goto fail_async_pd;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004287 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
4288 "async_pd=%p.\n", ha->async_pd);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004289 }
4290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004291 INIT_LIST_HEAD(&ha->vp_list);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004292
4293 /* Allocate memory for our loop_id bitmap */
Kees Cook6396bb22018-06-12 14:03:40 -07004294 ha->loop_id_map = kcalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE),
4295 sizeof(long),
4296 GFP_KERNEL);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004297 if (!ha->loop_id_map)
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004298 goto fail_loop_id_map;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004299 else {
4300 qla2x00_set_reserved_loop_ids(ha);
4301 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004302 "loop_id_map=%p.\n", ha->loop_id_map);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004303 }
4304
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004305 ha->sfp_data = dma_alloc_coherent(&ha->pdev->dev,
4306 SFP_DEV_SIZE, &ha->sfp_data_dma, GFP_KERNEL);
4307 if (!ha->sfp_data) {
4308 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
4309 "Unable to allocate memory for SFP read-data.\n");
4310 goto fail_sfp_data;
4311 }
4312
Dan Carpenterb2a72ec2014-01-21 10:00:10 +03004313 return 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004314
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004315fail_sfp_data:
4316 kfree(ha->loop_id_map);
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004317fail_loop_id_map:
4318 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004319fail_async_pd:
4320 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004321fail_ex_init_cb:
4322 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004323fail_npiv_info:
4324 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
4325 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
4326 (*rsp)->ring = NULL;
4327 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004328fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004329 kfree(*rsp);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004330 *rsp = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004331fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004332 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
4333 sizeof(request_t), (*req)->ring, (*req)->dma);
4334 (*req)->ring = NULL;
4335 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004336fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004337 kfree(*req);
Bill Kuzeja6d634062018-03-23 10:37:25 -04004338 *req = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004339fail_req:
4340 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
4341 ha->ct_sns, ha->ct_sns_dma);
4342 ha->ct_sns = NULL;
4343 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004344fail_free_ms_iocb:
4345 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4346 ha->ms_iocb = NULL;
4347 ha->ms_iocb_dma = 0;
Quinn Tranfc1ffd62016-12-23 18:06:10 -08004348
4349 if (ha->sns_cmd)
4350 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
4351 ha->sns_cmd, ha->sns_cmd_dma);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004352fail_dma_pool:
Giridhar Malavali50b81272018-12-21 09:33:45 -08004353 if (ql2xenabledif) {
4354 struct dsd_dma *dsd, *nxt;
4355
4356 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4357 list) {
4358 list_del(&dsd->list);
4359 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4360 dsd->dsd_list_dma);
4361 ha->dif_bundle_dma_allocs--;
4362 kfree(dsd);
4363 ha->dif_bundle_kallocs--;
4364 ha->pool.unusable.count--;
4365 }
4366 dma_pool_destroy(ha->dif_bundl_pool);
4367 ha->dif_bundl_pool = NULL;
4368 }
4369
4370fail_dif_bundl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004371 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004372 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
4373 ha->fcp_cmnd_dma_pool = NULL;
4374 }
4375fail_dl_dma_pool:
Arun Easibad75002010-05-04 15:01:30 -07004376 if (IS_QLA82XX(ha) || ql2xenabledif) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004377 dma_pool_destroy(ha->dl_dma_pool);
4378 ha->dl_dma_pool = NULL;
4379 }
4380fail_s_dma_pool:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004381 dma_pool_destroy(ha->s_dma_pool);
4382 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004383fail_free_nvram:
4384 kfree(ha->nvram);
4385 ha->nvram = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004386fail_free_ctx_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004387 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004388 ha->ctx_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004389fail_free_srb_mempool:
Thomas Meyer75c1d482018-12-02 21:52:11 +01004390 mempool_destroy(ha->srb_mempool);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004391 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004392fail_free_gid_list:
Chad Dupuis642ef982012-02-09 11:15:57 -08004393 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4394 ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004395 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08004396 ha->gid_list = NULL;
4397 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004398fail_free_tgt_mem:
4399 qlt_mem_free(ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004400fail_free_init_cb:
4401 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
4402 ha->init_cb_dma);
4403 ha->init_cb = NULL;
4404 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08004405fail:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004406 ql_log(ql_log_fatal, NULL, 0x0030,
4407 "Memory allocation failure.\n");
Andrew Vasqueze8711082008-01-31 12:33:48 -08004408 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409}
4410
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004411int
4412qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
4413{
4414 int rval;
4415 uint16_t size, max_cnt, temp;
4416 struct qla_hw_data *ha = vha->hw;
4417
4418 /* Return if we don't need to alloacate any extended logins */
4419 if (!ql2xexlogins)
4420 return QLA_SUCCESS;
4421
Quinn Tran99e1b682017-06-02 09:12:03 -07004422 if (!IS_EXLOGIN_OFFLD_CAPABLE(ha))
4423 return QLA_SUCCESS;
4424
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004425 ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
4426 max_cnt = 0;
4427 rval = qla_get_exlogin_status(vha, &size, &max_cnt);
4428 if (rval != QLA_SUCCESS) {
4429 ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
4430 "Failed to get exlogin status.\n");
4431 return rval;
4432 }
4433
4434 temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
Quinn Tran99e1b682017-06-02 09:12:03 -07004435 temp *= size;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004436
Quinn Tran99e1b682017-06-02 09:12:03 -07004437 if (temp != ha->exlogin_size) {
4438 qla2x00_free_exlogin_buffer(ha);
4439 ha->exlogin_size = temp;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004440
Quinn Tran99e1b682017-06-02 09:12:03 -07004441 ql_log(ql_log_info, vha, 0xd024,
4442 "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
4443 max_cnt, size, temp);
4444
4445 ql_log(ql_log_info, vha, 0xd025,
4446 "EXLOGIN: requested size=0x%x\n", ha->exlogin_size);
4447
4448 /* Get consistent memory for extended logins */
4449 ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
4450 ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
4451 if (!ha->exlogin_buf) {
4452 ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004453 "Failed to allocate memory for exlogin_buf_dma.\n");
Quinn Tran99e1b682017-06-02 09:12:03 -07004454 return -ENOMEM;
4455 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004456 }
4457
4458 /* Now configure the dma buffer */
4459 rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
4460 if (rval) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004461 ql_log(ql_log_fatal, vha, 0xd033,
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05004462 "Setup extended login buffer ****FAILED****.\n");
4463 qla2x00_free_exlogin_buffer(ha);
4464 }
4465
4466 return rval;
4467}
4468
4469/*
4470* qla2x00_free_exlogin_buffer
4471*
4472* Input:
4473* ha = adapter block pointer
4474*/
4475void
4476qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
4477{
4478 if (ha->exlogin_buf) {
4479 dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
4480 ha->exlogin_buf, ha->exlogin_buf_dma);
4481 ha->exlogin_buf = NULL;
4482 ha->exlogin_size = 0;
4483 }
4484}
4485
Quinn Tran99e1b682017-06-02 09:12:03 -07004486static void
4487qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
4488{
4489 u32 temp;
Quinn Tran0645cb82018-09-11 10:18:18 -07004490 struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
Quinn Tran99e1b682017-06-02 09:12:03 -07004491 *ret_cnt = FW_DEF_EXCHANGES_CNT;
4492
Quinn Trand1e36352017-12-28 12:33:12 -08004493 if (max_cnt > vha->hw->max_exchg)
4494 max_cnt = vha->hw->max_exchg;
4495
Quinn Tran99e1b682017-06-02 09:12:03 -07004496 if (qla_ini_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004497 if (vha->ql2xiniexchg > max_cnt)
4498 vha->ql2xiniexchg = max_cnt;
Quinn Tran99e1b682017-06-02 09:12:03 -07004499
Quinn Tran0645cb82018-09-11 10:18:18 -07004500 if (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)
4501 *ret_cnt = vha->ql2xiniexchg;
4502
Quinn Tran99e1b682017-06-02 09:12:03 -07004503 } else if (qla_tgt_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004504 if (vha->ql2xexchoffld > max_cnt) {
4505 vha->ql2xexchoffld = max_cnt;
4506 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
4507 }
Quinn Tran99e1b682017-06-02 09:12:03 -07004508
Quinn Tran0645cb82018-09-11 10:18:18 -07004509 if (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)
4510 *ret_cnt = vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004511 } else if (qla_dual_mode_enabled(vha)) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004512 temp = vha->ql2xiniexchg + vha->ql2xexchoffld;
Quinn Tran99e1b682017-06-02 09:12:03 -07004513 if (temp > max_cnt) {
Quinn Tran0645cb82018-09-11 10:18:18 -07004514 vha->ql2xiniexchg -= (temp - max_cnt)/2;
4515 vha->ql2xexchoffld -= (((temp - max_cnt)/2) + 1);
Quinn Tran99e1b682017-06-02 09:12:03 -07004516 temp = max_cnt;
Quinn Tran0645cb82018-09-11 10:18:18 -07004517 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Quinn Tran99e1b682017-06-02 09:12:03 -07004518 }
4519
4520 if (temp > FW_DEF_EXCHANGES_CNT)
4521 *ret_cnt = temp;
4522 }
4523}
4524
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004525int
4526qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
4527{
4528 int rval;
Quinn Trand1e36352017-12-28 12:33:12 -08004529 u16 size, max_cnt;
4530 u32 actual_cnt, totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004531 struct qla_hw_data *ha = vha->hw;
4532
Quinn Tran99e1b682017-06-02 09:12:03 -07004533 if (!ha->flags.exchoffld_enabled)
4534 return QLA_SUCCESS;
4535
4536 if (!IS_EXCHG_OFFLD_CAPABLE(ha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004537 return QLA_SUCCESS;
4538
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004539 max_cnt = 0;
4540 rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
4541 if (rval != QLA_SUCCESS) {
4542 ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
4543 "Failed to get exlogin status.\n");
4544 return rval;
4545 }
4546
Quinn Trand1e36352017-12-28 12:33:12 -08004547 qla2x00_number_of_exch(vha, &actual_cnt, max_cnt);
4548 ql_log(ql_log_info, vha, 0xd014,
4549 "Actual exchange offload count: %d.\n", actual_cnt);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004550
Quinn Trand1e36352017-12-28 12:33:12 -08004551 totsz = actual_cnt * size;
4552
4553 if (totsz != ha->exchoffld_size) {
Quinn Tran99e1b682017-06-02 09:12:03 -07004554 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran0645cb82018-09-11 10:18:18 -07004555 if (actual_cnt <= FW_DEF_EXCHANGES_CNT) {
4556 ha->exchoffld_size = 0;
4557 ha->flags.exchoffld_enabled = 0;
4558 return QLA_SUCCESS;
4559 }
4560
Quinn Trand1e36352017-12-28 12:33:12 -08004561 ha->exchoffld_size = totsz;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004562
Quinn Tran99e1b682017-06-02 09:12:03 -07004563 ql_log(ql_log_info, vha, 0xd016,
Quinn Trand1e36352017-12-28 12:33:12 -08004564 "Exchange offload: max_count=%d, actual count=%d entry sz=0x%x, total sz=0x%x\n",
4565 max_cnt, actual_cnt, size, totsz);
Quinn Tran99e1b682017-06-02 09:12:03 -07004566
4567 ql_log(ql_log_info, vha, 0xd017,
4568 "Exchange Buffers requested size = 0x%x\n",
4569 ha->exchoffld_size);
4570
4571 /* Get consistent memory for extended logins */
4572 ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
4573 ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
4574 if (!ha->exchoffld_buf) {
4575 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
Quinn Trand1e36352017-12-28 12:33:12 -08004576 "Failed to allocate memory for Exchange Offload.\n");
4577
4578 if (ha->max_exchg >
4579 (FW_DEF_EXCHANGES_CNT + REDUCE_EXCHANGES_CNT)) {
4580 ha->max_exchg -= REDUCE_EXCHANGES_CNT;
4581 } else if (ha->max_exchg >
4582 (FW_DEF_EXCHANGES_CNT + 512)) {
4583 ha->max_exchg -= 512;
4584 } else {
4585 ha->flags.exchoffld_enabled = 0;
4586 ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
4587 "Disabling Exchange offload due to lack of memory\n");
4588 }
4589 ha->exchoffld_size = 0;
4590
Quinn Tran99e1b682017-06-02 09:12:03 -07004591 return -ENOMEM;
4592 }
Quinn Tran0645cb82018-09-11 10:18:18 -07004593 } else if (!ha->exchoffld_buf || (actual_cnt <= FW_DEF_EXCHANGES_CNT)) {
4594 /* pathological case */
4595 qla2x00_free_exchoffld_buffer(ha);
4596 ha->exchoffld_size = 0;
4597 ha->flags.exchoffld_enabled = 0;
4598 ql_log(ql_log_info, vha, 0xd016,
4599 "Exchange offload not enable: offld size=%d, actual count=%d entry sz=0x%x, total sz=0x%x.\n",
4600 ha->exchoffld_size, actual_cnt, size, totsz);
4601 return 0;
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004602 }
4603
4604 /* Now configure the dma buffer */
Quinn Tran99e1b682017-06-02 09:12:03 -07004605 rval = qla_set_exchoffld_mem_cfg(vha);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004606 if (rval) {
4607 ql_log(ql_log_fatal, vha, 0xd02e,
4608 "Setup exchange offload buffer ****FAILED****.\n");
4609 qla2x00_free_exchoffld_buffer(ha);
Quinn Tran99e1b682017-06-02 09:12:03 -07004610 } else {
4611 /* re-adjust number of target exchange */
4612 struct init_cb_81xx *icb = (struct init_cb_81xx *)ha->init_cb;
4613
4614 if (qla_ini_mode_enabled(vha))
4615 icb->exchange_count = 0;
4616 else
Quinn Tran0645cb82018-09-11 10:18:18 -07004617 icb->exchange_count = cpu_to_le16(vha->ql2xexchoffld);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05004618 }
4619
4620 return rval;
4621}
4622
4623/*
4624* qla2x00_free_exchoffld_buffer
4625*
4626* Input:
4627* ha = adapter block pointer
4628*/
4629void
4630qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
4631{
4632 if (ha->exchoffld_buf) {
4633 dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
4634 ha->exchoffld_buf, ha->exchoffld_buf_dma);
4635 ha->exchoffld_buf = NULL;
4636 ha->exchoffld_size = 0;
4637 }
4638}
4639
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640/*
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004641* qla2x00_free_fw_dump
4642* Frees fw dump stuff.
4643*
4644* Input:
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004645* ha = adapter block pointer
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004646*/
4647static void
4648qla2x00_free_fw_dump(struct qla_hw_data *ha)
4649{
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004650 struct fwdt *fwdt = ha->fwdt;
4651 uint j;
4652
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004653 if (ha->fce)
Chad Dupuisf73cb692014-02-26 04:15:06 -05004654 dma_free_coherent(&ha->pdev->dev,
4655 FCE_SIZE, ha->fce, ha->fce_dma);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004656
Chad Dupuisf73cb692014-02-26 04:15:06 -05004657 if (ha->eft)
4658 dma_free_coherent(&ha->pdev->dev,
4659 EFT_SIZE, ha->eft, ha->eft_dma);
4660
4661 if (ha->fw_dump)
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004662 vfree(ha->fw_dump);
Chad Dupuisf73cb692014-02-26 04:15:06 -05004663
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004664 ha->fce = NULL;
4665 ha->fce_dma = 0;
4666 ha->eft = NULL;
4667 ha->eft_dma = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004668 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04004669 ha->fw_dump_cap_flags = 0;
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004670 ha->fw_dump_reading = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004671 ha->fw_dump = NULL;
4672 ha->fw_dump_len = 0;
Joe Carnuccioa28d9e42019-03-12 11:08:17 -07004673
4674 for (j = 0; j < 2; j++, fwdt++) {
4675 if (fwdt->template)
4676 vfree(fwdt->template);
4677 fwdt->template = NULL;
4678 fwdt->length = 0;
4679 }
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004680}
4681
4682/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683* qla2x00_mem_free
4684* Frees all adapter allocated memory.
4685*
4686* Input:
4687* ha = adapter block pointer.
4688*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08004689static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004690qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691{
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07004692 qla2x00_free_fw_dump(ha);
4693
Saurav Kashyap81178772012-08-22 14:21:04 -04004694 if (ha->mctp_dump)
4695 dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
4696 ha->mctp_dump_dma);
4697
Thomas Meyer75c1d482018-12-02 21:52:11 +01004698 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004700 if (ha->dcbx_tlv)
4701 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
4702 ha->dcbx_tlv, ha->dcbx_tlv_dma);
4703
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004704 if (ha->xgmac_data)
4705 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
4706 ha->xgmac_data, ha->xgmac_data_dma);
4707
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 if (ha->sns_cmd)
4709 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004710 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711
4712 if (ha->ct_sns)
4713 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004714 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715
Andrew Vasquez88729e52006-06-23 16:10:50 -07004716 if (ha->sfp_data)
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004717 dma_free_coherent(&ha->pdev->dev, SFP_DEV_SIZE, ha->sfp_data,
4718 ha->sfp_data_dma);
Andrew Vasquez88729e52006-06-23 16:10:50 -07004719
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 if (ha->ms_iocb)
4721 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
4722
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004723 if (ha->ex_init_cb)
Giridhar Malavalia9083012010-04-12 17:59:55 -07004724 dma_pool_free(ha->s_dma_pool,
4725 ha->ex_init_cb, ha->ex_init_cb_dma);
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004726
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004727 if (ha->async_pd)
4728 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
4729
Thomas Meyer75c1d482018-12-02 21:52:11 +01004730 dma_pool_destroy(ha->s_dma_pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 if (ha->gid_list)
Chad Dupuis642ef982012-02-09 11:15:57 -08004733 dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
4734 ha->gid_list, ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735
Giridhar Malavalia9083012010-04-12 17:59:55 -07004736 if (IS_QLA82XX(ha)) {
4737 if (!list_empty(&ha->gbl_dsd_list)) {
4738 struct dsd_dma *dsd_ptr, *tdsd_ptr;
4739
4740 /* clean up allocated prev pool */
4741 list_for_each_entry_safe(dsd_ptr,
4742 tdsd_ptr, &ha->gbl_dsd_list, list) {
4743 dma_pool_free(ha->dl_dma_pool,
4744 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
4745 list_del(&dsd_ptr->list);
4746 kfree(dsd_ptr);
4747 }
4748 }
4749 }
4750
Thomas Meyer75c1d482018-12-02 21:52:11 +01004751 dma_pool_destroy(ha->dl_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004752
Thomas Meyer75c1d482018-12-02 21:52:11 +01004753 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004754
Thomas Meyer75c1d482018-12-02 21:52:11 +01004755 mempool_destroy(ha->ctx_mempool);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004756
Giridhar Malavali50b81272018-12-21 09:33:45 -08004757 if (ql2xenabledif) {
4758 struct dsd_dma *dsd, *nxt;
4759
4760 list_for_each_entry_safe(dsd, nxt, &ha->pool.unusable.head,
4761 list) {
4762 list_del(&dsd->list);
4763 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4764 dsd->dsd_list_dma);
4765 ha->dif_bundle_dma_allocs--;
4766 kfree(dsd);
4767 ha->dif_bundle_kallocs--;
4768 ha->pool.unusable.count--;
4769 }
4770 list_for_each_entry_safe(dsd, nxt, &ha->pool.good.head, list) {
4771 list_del(&dsd->list);
4772 dma_pool_free(ha->dif_bundl_pool, dsd->dsd_addr,
4773 dsd->dsd_list_dma);
4774 ha->dif_bundle_dma_allocs--;
4775 kfree(dsd);
4776 ha->dif_bundle_kallocs--;
4777 }
4778 }
4779
4780 if (ha->dif_bundl_pool)
4781 dma_pool_destroy(ha->dif_bundl_pool);
4782
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004783 qlt_mem_free(ha);
4784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004785 if (ha->init_cb)
4786 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
Giridhar Malavalia9083012010-04-12 17:59:55 -07004787 ha->init_cb, ha->init_cb_dma);
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004788
Bill Kuzeja6d634062018-03-23 10:37:25 -04004789 vfree(ha->optrom_buffer);
4790 kfree(ha->nvram);
4791 kfree(ha->npiv_info);
4792 kfree(ha->swl);
4793 kfree(ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794
Andrew Vasqueze8711082008-01-31 12:33:48 -08004795 ha->srb_mempool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004796 ha->ctx_mempool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 ha->sns_cmd = NULL;
4798 ha->sns_cmd_dma = 0;
4799 ha->ct_sns = NULL;
4800 ha->ct_sns_dma = 0;
4801 ha->ms_iocb = NULL;
4802 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 ha->init_cb = NULL;
4804 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004805 ha->ex_init_cb = NULL;
4806 ha->ex_init_cb_dma = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004807 ha->async_pd = NULL;
4808 ha->async_pd_dma = 0;
Bill Kuzeja6a2cf8d2018-03-05 00:02:55 -05004809 ha->loop_id_map = NULL;
4810 ha->npiv_info = NULL;
4811 ha->optrom_buffer = NULL;
4812 ha->swl = NULL;
4813 ha->nvram = NULL;
4814 ha->mctp_dump = NULL;
4815 ha->dcbx_tlv = NULL;
4816 ha->xgmac_data = NULL;
4817 ha->sfp_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818
4819 ha->s_dma_pool = NULL;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004820 ha->dl_dma_pool = NULL;
4821 ha->fcp_cmnd_dma_pool = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822
Linus Torvalds1da177e2005-04-16 15:20:36 -07004823 ha->gid_list = NULL;
4824 ha->gid_list_dma = 0;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004825
4826 ha->tgt.atio_ring = NULL;
4827 ha->tgt.atio_dma = 0;
4828 ha->tgt.tgt_vp_map = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004829}
4830
4831struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
4832 struct qla_hw_data *ha)
4833{
4834 struct Scsi_Host *host;
4835 struct scsi_qla_host *vha = NULL;
4836
4837 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
Quinn Tran41dc5292017-01-19 22:28:03 -08004838 if (!host) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004839 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
4840 "Failed to allocate host from the scsi layer, aborting.\n");
Quinn Tran41dc5292017-01-19 22:28:03 -08004841 return NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004842 }
4843
4844 /* Clear our data area */
4845 vha = shost_priv(host);
4846 memset(vha, 0, sizeof(scsi_qla_host_t));
4847
4848 vha->host = host;
4849 vha->host_no = host->host_no;
4850 vha->hw = ha;
4851
Quinn Tran0645cb82018-09-11 10:18:18 -07004852 vha->qlini_mode = ql2x_ini_mode;
4853 vha->ql2xexchoffld = ql2xexchoffld;
4854 vha->ql2xiniexchg = ql2xiniexchg;
4855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004856 INIT_LIST_HEAD(&vha->vp_fcports);
4857 INIT_LIST_HEAD(&vha->work_list);
4858 INIT_LIST_HEAD(&vha->list);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004859 INIT_LIST_HEAD(&vha->qla_cmd_list);
4860 INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
Alexei Potashnik71cdc072015-12-17 14:57:01 -05004861 INIT_LIST_HEAD(&vha->logo_list);
Alexei Potashnikb7bd1042015-12-17 14:57:02 -05004862 INIT_LIST_HEAD(&vha->plogi_ack_list);
Michael Hernandezd7459522016-12-12 14:40:07 -08004863 INIT_LIST_HEAD(&vha->qp_list);
Quinn Tran41dc5292017-01-19 22:28:03 -08004864 INIT_LIST_HEAD(&vha->gnl.fcports);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004865 INIT_LIST_HEAD(&vha->nvme_rport_list);
Quinn Tran2d73ac62017-12-04 14:45:02 -08004866 INIT_LIST_HEAD(&vha->gpnid_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004867 INIT_WORK(&vha->iocb_work, qla2x00_iocb_work_fn);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004868
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004869 spin_lock_init(&vha->work_lock);
Swapnil Nagle8b2f5ff2015-07-14 16:00:43 -04004870 spin_lock_init(&vha->cmd_list_lock);
Quinn Tran726b8542017-01-19 22:28:00 -08004871 init_waitqueue_head(&vha->fcport_waitQ);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07004872 init_waitqueue_head(&vha->vref_waitq);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004873
Bart Van Assche2fdbc652017-01-20 13:31:13 -08004874 vha->gnl.size = sizeof(struct get_name_list_extended) *
4875 (ha->max_loop_id + 1);
Quinn Tran41dc5292017-01-19 22:28:03 -08004876 vha->gnl.l = dma_alloc_coherent(&ha->pdev->dev,
4877 vha->gnl.size, &vha->gnl.ldma, GFP_KERNEL);
4878 if (!vha->gnl.l) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004879 ql_log(ql_log_fatal, vha, 0xd04a,
Quinn Tran41dc5292017-01-19 22:28:03 -08004880 "Alloc failed for name list.\n");
4881 scsi_remove_host(vha->host);
4882 return NULL;
4883 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004884
Quinn Trana4239942017-12-28 12:33:26 -08004885 /* todo: what about ext login? */
4886 vha->scan.size = ha->max_fibre_devices * sizeof(struct fab_scan_rp);
4887 vha->scan.l = vmalloc(vha->scan.size);
4888 if (!vha->scan.l) {
4889 ql_log(ql_log_fatal, vha, 0xd04a,
4890 "Alloc failed for scan database.\n");
4891 dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
4892 vha->gnl.l, vha->gnl.ldma);
4893 scsi_remove_host(vha->host);
4894 return NULL;
4895 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08004896 INIT_DELAYED_WORK(&vha->scan.scan_work, qla_scan_work_fn);
Quinn Trana4239942017-12-28 12:33:26 -08004897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004898 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004899 ql_dbg(ql_dbg_init, vha, 0x0041,
4900 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
4901 vha->host, vha->hw, vha,
4902 dev_name(&(ha->pdev->dev)));
4903
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004904 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905}
4906
Quinn Tran726b8542017-01-19 22:28:00 -08004907struct qla_work_evt *
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004908qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004909{
4910 struct qla_work_evt *e;
Arun Easifeafb7b2010-09-03 14:57:00 -07004911 uint8_t bail;
4912
4913 QLA_VHA_MARK_BUSY(vha, bail);
4914 if (bail)
4915 return NULL;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004916
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004917 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
Arun Easifeafb7b2010-09-03 14:57:00 -07004918 if (!e) {
4919 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004920 return NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07004921 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07004922
4923 INIT_LIST_HEAD(&e->list);
4924 e->type = type;
4925 e->flags = QLA_EVT_FLAG_FREE;
4926 return e;
4927}
4928
Quinn Tran726b8542017-01-19 22:28:00 -08004929int
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004930qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
Andrew Vasquez0971de72008-04-03 13:13:18 -07004931{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004932 unsigned long flags;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004933 bool q = false;
Andrew Vasquez0971de72008-04-03 13:13:18 -07004934
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004935 spin_lock_irqsave(&vha->work_lock, flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004936 list_add_tail(&e->list, &vha->work_list);
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004937
4938 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
4939 q = true;
4940
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004941 spin_unlock_irqrestore(&vha->work_lock, flags);
Quinn Tranec7193e2017-03-15 09:48:55 -07004942
Quinn Tran9b3e0f42017-12-28 12:33:16 -08004943 if (q)
4944 queue_work(vha->hw->wq, &vha->iocb_work);
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004945
Andrew Vasquez0971de72008-04-03 13:13:18 -07004946 return QLA_SUCCESS;
4947}
4948
4949int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004950qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07004951 u32 data)
4952{
4953 struct qla_work_evt *e;
4954
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004955 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004956 if (!e)
4957 return QLA_FUNCTION_FAILED;
4958
4959 e->u.aen.code = code;
4960 e->u.aen.data = data;
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004961 return qla2x00_post_work(vha, e);
Andrew Vasquez0971de72008-04-03 13:13:18 -07004962}
4963
Andrew Vasquez8a659572009-02-08 20:50:12 -08004964int
4965qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
4966{
4967 struct qla_work_evt *e;
4968
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004969 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004970 if (!e)
4971 return QLA_FUNCTION_FAILED;
4972
4973 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07004974 return qla2x00_post_work(vha, e);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004975}
4976
Andrew Vasquezac280b62009-08-20 11:06:05 -07004977#define qla2x00_post_async_work(name, type) \
4978int qla2x00_post_async_##name##_work( \
4979 struct scsi_qla_host *vha, \
4980 fc_port_t *fcport, uint16_t *data) \
4981{ \
4982 struct qla_work_evt *e; \
4983 \
4984 e = qla2x00_alloc_work(vha, type); \
4985 if (!e) \
4986 return QLA_FUNCTION_FAILED; \
4987 \
4988 e->u.logio.fcport = fcport; \
4989 if (data) { \
4990 e->u.logio.data[0] = data[0]; \
4991 e->u.logio.data[1] = data[1]; \
4992 } \
Quinn Tran6d6749272017-12-28 12:33:41 -08004993 fcport->flags |= FCF_ASYNC_ACTIVE; \
Andrew Vasquezac280b62009-08-20 11:06:05 -07004994 return qla2x00_post_work(vha, e); \
4995}
4996
4997qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004998qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
4999qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005000qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
Quinn Tran11aea162017-12-28 12:33:20 -08005001qla2x00_post_async_work(prlo, QLA_EVT_ASYNC_PRLO);
5002qla2x00_post_async_work(prlo_done, QLA_EVT_ASYNC_PRLO_DONE);
Andrew Vasquezac280b62009-08-20 11:06:05 -07005003
Andrew Vasquez3420d362009-10-13 15:16:45 -07005004int
5005qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
5006{
5007 struct qla_work_evt *e;
5008
5009 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
5010 if (!e)
5011 return QLA_FUNCTION_FAILED;
5012
5013 e->u.uevent.code = code;
5014 return qla2x00_post_work(vha, e);
5015}
5016
5017static void
5018qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
5019{
5020 char event_string[40];
5021 char *envp[] = { event_string, NULL };
5022
5023 switch (code) {
5024 case QLA_UEVENT_CODE_FW_DUMP:
5025 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
5026 vha->host_no);
5027 break;
5028 default:
5029 /* do nothing */
5030 break;
5031 }
5032 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
5033}
5034
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005035int
5036qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
5037 uint32_t *data, int cnt)
5038{
5039 struct qla_work_evt *e;
5040
5041 e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
5042 if (!e)
5043 return QLA_FUNCTION_FAILED;
5044
5045 e->u.aenfx.evtcode = evtcode;
5046 e->u.aenfx.count = cnt;
5047 memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
5048 return qla2x00_post_work(vha, e);
5049}
5050
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005051void qla24xx_sched_upd_fcport(fc_port_t *fcport)
Quinn Tran726b8542017-01-19 22:28:00 -08005052{
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005053 unsigned long flags;
Quinn Tran726b8542017-01-19 22:28:00 -08005054
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005055 if (IS_SW_RESV_ADDR(fcport->d_id))
5056 return;
Quinn Tran726b8542017-01-19 22:28:00 -08005057
Quinn Trancd4ed6b2018-08-31 11:24:31 -07005058 spin_lock_irqsave(&fcport->vha->work_lock, flags);
5059 if (fcport->disc_state == DSC_UPD_FCPORT) {
5060 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5061 return;
5062 }
5063 fcport->jiffies_at_registration = jiffies;
5064 fcport->sec_since_registration = 0;
5065 fcport->next_disc_state = DSC_DELETED;
5066 fcport->disc_state = DSC_UPD_FCPORT;
5067 spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
5068
5069 queue_work(system_unbound_wq, &fcport->reg_work);
Quinn Tran726b8542017-01-19 22:28:00 -08005070}
5071
5072static
5073void qla24xx_create_new_sess(struct scsi_qla_host *vha, struct qla_work_evt *e)
5074{
5075 unsigned long flags;
Quinn Tranb5d15312017-08-30 10:16:49 -07005076 fc_port_t *fcport = NULL, *tfcp;
Quinn Tran726b8542017-01-19 22:28:00 -08005077 struct qlt_plogi_ack_t *pla =
5078 (struct qlt_plogi_ack_t *)e->u.new_sess.pla;
Quinn Tranb5d15312017-08-30 10:16:49 -07005079 uint8_t free_fcport = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005080
Quinn Tran9cd883f2017-12-28 12:33:24 -08005081 ql_dbg(ql_dbg_disc, vha, 0xffff,
5082 "%s %d %8phC enter\n",
5083 __func__, __LINE__, e->u.new_sess.port_name);
5084
Quinn Tran726b8542017-01-19 22:28:00 -08005085 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5086 fcport = qla2x00_find_fcport_by_wwpn(vha, e->u.new_sess.port_name, 1);
5087 if (fcport) {
5088 fcport->d_id = e->u.new_sess.id;
5089 if (pla) {
5090 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005091 memcpy(fcport->node_name,
5092 pla->iocb.u.isp24.u.plogi.node_name,
5093 WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08005094 qlt_plogi_ack_link(vha, pla, fcport, QLT_PLOGI_LINK_SAME_WWN);
5095 /* we took an extra ref_count to prevent PLOGI ACK when
5096 * fcport/sess has not been created.
5097 */
5098 pla->ref_count--;
5099 }
5100 } else {
Quinn Tranb5d15312017-08-30 10:16:49 -07005101 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08005102 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5103 if (fcport) {
5104 fcport->d_id = e->u.new_sess.id;
Quinn Tran726b8542017-01-19 22:28:00 -08005105 fcport->flags |= FCF_FABRIC_DEVICE;
5106 fcport->fw_login_state = DSC_LS_PLOGI_PEND;
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005107 if (e->u.new_sess.fc4_type == FS_FC4TYPE_FCP)
Quinn Trana4239942017-12-28 12:33:26 -08005108 fcport->fc4_type = FC4_TYPE_FCP_SCSI;
Quinn Tran726b8542017-01-19 22:28:00 -08005109
Himanshu Madhanic64a87f2018-12-06 21:49:42 -08005110 if (e->u.new_sess.fc4_type == FS_FC4TYPE_NVME) {
Darren Trapp2b5b9642018-02-27 16:31:12 -08005111 fcport->fc4_type = FC4_TYPE_OTHER;
5112 fcport->fc4f_nvme = FC4_TYPE_NVME;
5113 }
Quinn Tran33b28352018-03-20 23:09:40 -07005114
Quinn Tran726b8542017-01-19 22:28:00 -08005115 memcpy(fcport->port_name, e->u.new_sess.port_name,
5116 WWN_SIZE);
Quinn Tranb5d15312017-08-30 10:16:49 -07005117 } else {
5118 ql_dbg(ql_dbg_disc, vha, 0xffff,
5119 "%s %8phC mem alloc fail.\n",
5120 __func__, e->u.new_sess.port_name);
5121
5122 if (pla)
5123 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5124 return;
5125 }
5126
5127 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08005128 /* search again to make sure no one else got ahead */
Quinn Tranb5d15312017-08-30 10:16:49 -07005129 tfcp = qla2x00_find_fcport_by_wwpn(vha,
5130 e->u.new_sess.port_name, 1);
5131 if (tfcp) {
5132 /* should rarily happen */
5133 ql_dbg(ql_dbg_disc, vha, 0xffff,
5134 "%s %8phC found existing fcport b4 add. DS %d LS %d\n",
5135 __func__, tfcp->port_name, tfcp->disc_state,
5136 tfcp->fw_login_state);
5137
5138 free_fcport = 1;
5139 } else {
Quinn Tran726b8542017-01-19 22:28:00 -08005140 list_add_tail(&fcport->list, &vha->vp_fcports);
5141
Quinn Tran19759032017-12-04 14:45:15 -08005142 }
5143 if (pla) {
5144 qlt_plogi_ack_link(vha, pla, fcport,
5145 QLT_PLOGI_LINK_SAME_WWN);
5146 pla->ref_count--;
Quinn Tran726b8542017-01-19 22:28:00 -08005147 }
5148 }
5149 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5150
5151 if (fcport) {
Quinn Trana4239942017-12-28 12:33:26 -08005152 fcport->id_changed = 1;
5153 fcport->scan_state = QLA_FCPORT_FOUND;
5154 memcpy(fcport->node_name, e->u.new_sess.node_name, WWN_SIZE);
5155
Quinn Tran5ef696a2017-12-04 14:45:05 -08005156 if (pla) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005157 if (pla->iocb.u.isp24.status_subcode == ELS_PRLI) {
5158 u16 wd3_lo;
5159
5160 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5161 fcport->local = 0;
5162 fcport->loop_id =
5163 le16_to_cpu(
5164 pla->iocb.u.isp24.nport_handle);
5165 fcport->fw_login_state = DSC_LS_PRLI_PEND;
5166 wd3_lo =
5167 le16_to_cpu(
5168 pla->iocb.u.isp24.u.prli.wd3_lo);
5169
5170 if (wd3_lo & BIT_7)
5171 fcport->conf_compl_supported = 1;
5172
5173 if ((wd3_lo & BIT_4) == 0)
5174 fcport->port_type = FCT_INITIATOR;
5175 else
5176 fcport->port_type = FCT_TARGET;
5177 }
Quinn Tran726b8542017-01-19 22:28:00 -08005178 qlt_plogi_ack_unref(vha, pla);
Quinn Tran5ef696a2017-12-04 14:45:05 -08005179 } else {
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005180 fc_port_t *dfcp = NULL;
5181
Quinn Tran5ef696a2017-12-04 14:45:05 -08005182 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5183 tfcp = qla2x00_find_fcport_by_nportid(vha,
5184 &e->u.new_sess.id, 1);
5185 if (tfcp && (tfcp != fcport)) {
5186 /*
5187 * We have a conflict fcport with same NportID.
5188 */
5189 ql_dbg(ql_dbg_disc, vha, 0xffff,
5190 "%s %8phC found conflict b4 add. DS %d LS %d\n",
5191 __func__, tfcp->port_name, tfcp->disc_state,
5192 tfcp->fw_login_state);
5193
5194 switch (tfcp->disc_state) {
5195 case DSC_DELETED:
5196 break;
5197 case DSC_DELETE_PEND:
5198 fcport->login_pause = 1;
5199 tfcp->conflict = fcport;
5200 break;
5201 default:
5202 fcport->login_pause = 1;
5203 tfcp->conflict = fcport;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005204 dfcp = tfcp;
Quinn Tran5ef696a2017-12-04 14:45:05 -08005205 break;
5206 }
5207 }
5208 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +01005209 if (dfcp)
5210 qlt_schedule_sess_for_deletion(tfcp);
Quinn Trana4239942017-12-28 12:33:26 -08005211
Quinn Trana4239942017-12-28 12:33:26 -08005212
Quinn Tran8777e432018-08-02 13:16:57 -07005213 if (N2N_TOPO(vha->hw))
5214 fcport->flags &= ~FCF_FABRIC_DEVICE;
5215
5216 if (N2N_TOPO(vha->hw)) {
5217 if (vha->flags.nvme_enabled) {
5218 fcport->fc4f_nvme = 1;
5219 fcport->n2n_flag = 1;
5220 }
5221 fcport->fw_login_state = 0;
5222 /*
5223 * wait link init done before sending login
5224 */
5225 } else {
5226 qla24xx_fcport_handle_login(vha, fcport);
5227 }
Quinn Tran5ef696a2017-12-04 14:45:05 -08005228 }
Quinn Tran726b8542017-01-19 22:28:00 -08005229 }
Quinn Tranb5d15312017-08-30 10:16:49 -07005230
5231 if (free_fcport) {
5232 qla2x00_free_fcport(fcport);
5233 if (pla)
5234 kmem_cache_free(qla_tgt_plogi_cachep, pla);
5235 }
Quinn Tran726b8542017-01-19 22:28:00 -08005236}
5237
Quinn Trane374f9f2017-12-28 12:33:31 -08005238static void qla_sp_retry(struct scsi_qla_host *vha, struct qla_work_evt *e)
5239{
5240 struct srb *sp = e->u.iosb.sp;
5241 int rval;
5242
5243 rval = qla2x00_start_sp(sp);
5244 if (rval != QLA_SUCCESS) {
5245 ql_dbg(ql_dbg_disc, vha, 0x2043,
5246 "%s: %s: Re-issue IOCB failed (%d).\n",
5247 __func__, sp->name, rval);
5248 qla24xx_sp_unmap(vha, sp);
5249 }
5250}
5251
Andrew Vasquezac280b62009-08-20 11:06:05 -07005252void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005253qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07005254{
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005255 struct qla_work_evt *e, *tmp;
5256 unsigned long flags;
5257 LIST_HEAD(work);
Quinn Tran80676d02019-01-24 23:23:42 -08005258 int rc;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005259
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005260 spin_lock_irqsave(&vha->work_lock, flags);
5261 list_splice_init(&vha->work_list, &work);
5262 spin_unlock_irqrestore(&vha->work_lock, flags);
5263
5264 list_for_each_entry_safe(e, tmp, &work, list) {
Quinn Tran80676d02019-01-24 23:23:42 -08005265 rc = QLA_SUCCESS;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005266 switch (e->type) {
5267 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005268 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07005269 e->u.aen.code, e->u.aen.data);
5270 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08005271 case QLA_EVT_IDC_ACK:
5272 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
5273 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005274 case QLA_EVT_ASYNC_LOGIN:
5275 qla2x00_async_login(vha, e->u.logio.fcport,
5276 e->u.logio.data);
5277 break;
Andrew Vasquezac280b62009-08-20 11:06:05 -07005278 case QLA_EVT_ASYNC_LOGOUT:
Quinn Tran80676d02019-01-24 23:23:42 -08005279 rc = qla2x00_async_logout(vha, e->u.logio.fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07005280 break;
5281 case QLA_EVT_ASYNC_LOGOUT_DONE:
5282 qla2x00_async_logout_done(vha, e->u.logio.fcport,
5283 e->u.logio.data);
5284 break;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005285 case QLA_EVT_ASYNC_ADISC:
5286 qla2x00_async_adisc(vha, e->u.logio.fcport,
5287 e->u.logio.data);
5288 break;
Andrew Vasquez3420d362009-10-13 15:16:45 -07005289 case QLA_EVT_UEVENT:
5290 qla2x00_uevent_emit(vha, e->u.uevent.code);
5291 break;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005292 case QLA_EVT_AENFX:
5293 qlafx00_process_aen(vha, e);
5294 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005295 case QLA_EVT_GPNID:
5296 qla24xx_async_gpnid(vha, &e->u.gpnid.id);
5297 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005298 case QLA_EVT_UNMAP:
5299 qla24xx_sp_unmap(vha, e->u.iosb.sp);
Quinn Tran726b8542017-01-19 22:28:00 -08005300 break;
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005301 case QLA_EVT_RELOGIN:
5302 qla2x00_relogin(vha);
5303 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005304 case QLA_EVT_NEW_SESS:
5305 qla24xx_create_new_sess(vha, e);
5306 break;
5307 case QLA_EVT_GPDB:
5308 qla24xx_async_gpdb(vha, e->u.fcport.fcport,
5309 e->u.fcport.opt);
5310 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005311 case QLA_EVT_PRLI:
5312 qla24xx_async_prli(vha, e->u.fcport.fcport);
5313 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005314 case QLA_EVT_GPSC:
5315 qla24xx_async_gpsc(vha, e->u.fcport.fcport);
5316 break;
Quinn Tran726b8542017-01-19 22:28:00 -08005317 case QLA_EVT_GNL:
5318 qla24xx_async_gnl(vha, e->u.fcport.fcport);
5319 break;
5320 case QLA_EVT_NACK:
5321 qla24xx_do_nack_work(vha, e);
5322 break;
Quinn Tran11aea162017-12-28 12:33:20 -08005323 case QLA_EVT_ASYNC_PRLO:
Quinn Tran80676d02019-01-24 23:23:42 -08005324 rc = qla2x00_async_prlo(vha, e->u.logio.fcport);
Quinn Tran11aea162017-12-28 12:33:20 -08005325 break;
5326 case QLA_EVT_ASYNC_PRLO_DONE:
5327 qla2x00_async_prlo_done(vha, e->u.logio.fcport,
5328 e->u.logio.data);
5329 break;
Quinn Trana4239942017-12-28 12:33:26 -08005330 case QLA_EVT_GPNFT:
Quinn Tran33b28352018-03-20 23:09:40 -07005331 qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
5332 e->u.gpnft.sp);
Quinn Trana4239942017-12-28 12:33:26 -08005333 break;
5334 case QLA_EVT_GPNFT_DONE:
5335 qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
5336 break;
5337 case QLA_EVT_GNNFT_DONE:
5338 qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
5339 break;
5340 case QLA_EVT_GNNID:
5341 qla24xx_async_gnnid(vha, e->u.fcport.fcport);
5342 break;
5343 case QLA_EVT_GFPNID:
5344 qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
5345 break;
Quinn Trane374f9f2017-12-28 12:33:31 -08005346 case QLA_EVT_SP_RETRY:
5347 qla_sp_retry(vha, e);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005348 break;
5349 case QLA_EVT_IIDMA:
5350 qla_do_iidma_work(vha, e->u.fcport.fcport);
5351 break;
Quinn Tran8777e432018-08-02 13:16:57 -07005352 case QLA_EVT_ELS_PLOGI:
5353 qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
5354 e->u.fcport.fcport, false);
5355 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07005356 }
Quinn Tran80676d02019-01-24 23:23:42 -08005357
5358 if (rc == EAGAIN) {
5359 /* put 'work' at head of 'vha->work_list' */
5360 spin_lock_irqsave(&vha->work_lock, flags);
5361 list_splice(&work, &vha->work_list);
5362 spin_unlock_irqrestore(&vha->work_lock, flags);
5363 break;
5364 }
5365 list_del_init(&e->list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005366 if (e->flags & QLA_EVT_FLAG_FREE)
5367 kfree(e);
Arun Easifeafb7b2010-09-03 14:57:00 -07005368
5369 /* For each work completed decrement vha ref count */
5370 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07005371 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005372}
Andrew Vasquezf999f4c12009-06-03 09:55:28 -07005373
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005374int qla24xx_post_relogin_work(struct scsi_qla_host *vha)
5375{
5376 struct qla_work_evt *e;
5377
5378 e = qla2x00_alloc_work(vha, QLA_EVT_RELOGIN);
5379
5380 if (!e) {
5381 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5382 return QLA_FUNCTION_FAILED;
5383 }
5384
5385 return qla2x00_post_work(vha, e);
5386}
5387
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005388/* Relogins all the fcports of a vport
5389 * Context: dpc thread
5390 */
5391void qla2x00_relogin(struct scsi_qla_host *vha)
5392{
5393 fc_port_t *fcport;
Quinn Tran23dd98a2018-08-02 13:16:45 -07005394 int status, relogin_needed = 0;
Quinn Tran726b8542017-01-19 22:28:00 -08005395 struct event_arg ea;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005396
5397 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08005398 /*
5399 * If the port is not ONLINE then try to login
5400 * to it if we haven't run out of retries.
5401 */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07005402 if (atomic_read(&fcport->state) != FCS_ONLINE &&
Quinn Tran23dd98a2018-08-02 13:16:45 -07005403 fcport->login_retry) {
5404 if (fcport->scan_state != QLA_FCPORT_FOUND ||
5405 fcport->disc_state == DSC_LOGIN_COMPLETE)
5406 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005407
Quinn Tran23dd98a2018-08-02 13:16:45 -07005408 if (fcport->flags & (FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE) ||
5409 fcport->disc_state == DSC_DELETE_PEND) {
5410 relogin_needed = 1;
5411 } else {
5412 if (vha->hw->current_topology != ISP_CFG_NL) {
5413 memset(&ea, 0, sizeof(ea));
5414 ea.event = FCME_RELOGIN;
5415 ea.fcport = fcport;
5416 qla2x00_fcport_event_handler(vha, &ea);
5417 } else if (vha->hw->current_topology ==
5418 ISP_CFG_NL) {
5419 fcport->login_retry--;
5420 status =
5421 qla2x00_local_device_login(vha,
5422 fcport);
5423 if (status == QLA_SUCCESS) {
5424 fcport->old_loop_id =
5425 fcport->loop_id;
5426 ql_dbg(ql_dbg_disc, vha, 0x2003,
5427 "Port login OK: logged in ID 0x%x.\n",
5428 fcport->loop_id);
5429 qla2x00_update_fcport
5430 (vha, fcport);
5431 } else if (status == 1) {
5432 set_bit(RELOGIN_NEEDED,
5433 &vha->dpc_flags);
5434 /* retry the login again */
5435 ql_dbg(ql_dbg_disc, vha, 0x2007,
5436 "Retrying %d login again loop_id 0x%x.\n",
5437 fcport->login_retry,
5438 fcport->loop_id);
5439 } else {
5440 fcport->login_retry = 0;
5441 }
5442
5443 if (fcport->login_retry == 0 &&
5444 status != QLA_SUCCESS)
5445 qla2x00_clear_loop_id(fcport);
5446 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005447 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005448 }
5449 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5450 break;
5451 }
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005452
Quinn Tran23dd98a2018-08-02 13:16:45 -07005453 if (relogin_needed)
5454 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5455
Quinn Tran9b3e0f42017-12-28 12:33:16 -08005456 ql_dbg(ql_dbg_disc, vha, 0x400e,
5457 "Relogin end.\n");
Andrew Vasquez0971de72008-04-03 13:13:18 -07005458}
5459
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005460/* Schedule work on any of the dpc-workqueues */
5461void
5462qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
5463{
5464 struct qla_hw_data *ha = base_vha->hw;
5465
5466 switch (work_code) {
5467 case MBA_IDC_AEN: /* 0x8200 */
5468 if (ha->dpc_lp_wq)
5469 queue_work(ha->dpc_lp_wq, &ha->idc_aen);
5470 break;
5471
5472 case QLA83XX_NIC_CORE_RESET: /* 0x1 */
5473 if (!ha->flags.nic_core_reset_hdlr_active) {
5474 if (ha->dpc_hp_wq)
5475 queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
5476 } else
5477 ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
5478 "NIC Core reset is already active. Skip "
5479 "scheduling it again.\n");
5480 break;
5481 case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
5482 if (ha->dpc_hp_wq)
5483 queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
5484 break;
5485 case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
5486 if (ha->dpc_hp_wq)
5487 queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
5488 break;
5489 default:
5490 ql_log(ql_log_warn, base_vha, 0xb05f,
Masanari Iidad939be32015-02-27 23:52:31 +09005491 "Unknown work-code=0x%x.\n", work_code);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005492 }
5493
5494 return;
5495}
5496
5497/* Work: Perform NIC Core Unrecoverable state handling */
5498void
5499qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
5500{
5501 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005502 container_of(work, struct qla_hw_data, nic_core_unrecoverable);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005503 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5504 uint32_t dev_state = 0;
5505
5506 qla83xx_idc_lock(base_vha, 0);
5507 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5508 qla83xx_reset_ownership(base_vha);
5509 if (ha->flags.nic_core_reset_owner) {
5510 ha->flags.nic_core_reset_owner = 0;
5511 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5512 QLA8XXX_DEV_FAILED);
5513 ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
5514 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5515 }
5516 qla83xx_idc_unlock(base_vha, 0);
5517}
5518
5519/* Work: Execute IDC state handler */
5520void
5521qla83xx_idc_state_handler_work(struct work_struct *work)
5522{
5523 struct qla_hw_data *ha =
Arun Easi2ad1b672012-08-22 14:21:35 -04005524 container_of(work, struct qla_hw_data, idc_state_handler);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005525 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5526 uint32_t dev_state = 0;
5527
5528 qla83xx_idc_lock(base_vha, 0);
5529 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5530 if (dev_state == QLA8XXX_DEV_FAILED ||
5531 dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
5532 qla83xx_idc_state_handler(base_vha);
5533 qla83xx_idc_unlock(base_vha, 0);
5534}
5535
Saurav Kashyapfa492632012-11-21 02:40:29 -05005536static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005537qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
5538{
5539 int rval = QLA_SUCCESS;
5540 unsigned long heart_beat_wait = jiffies + (1 * HZ);
5541 uint32_t heart_beat_counter1, heart_beat_counter2;
5542
5543 do {
5544 if (time_after(jiffies, heart_beat_wait)) {
5545 ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
5546 "Nic Core f/w is not alive.\n");
5547 rval = QLA_FUNCTION_FAILED;
5548 break;
5549 }
5550
5551 qla83xx_idc_lock(base_vha, 0);
5552 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5553 &heart_beat_counter1);
5554 qla83xx_idc_unlock(base_vha, 0);
5555 msleep(100);
5556 qla83xx_idc_lock(base_vha, 0);
5557 qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
5558 &heart_beat_counter2);
5559 qla83xx_idc_unlock(base_vha, 0);
5560 } while (heart_beat_counter1 == heart_beat_counter2);
5561
5562 return rval;
5563}
5564
5565/* Work: Perform NIC Core Reset handling */
5566void
5567qla83xx_nic_core_reset_work(struct work_struct *work)
5568{
5569 struct qla_hw_data *ha =
5570 container_of(work, struct qla_hw_data, nic_core_reset);
5571 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5572 uint32_t dev_state = 0;
5573
Saurav Kashyap81178772012-08-22 14:21:04 -04005574 if (IS_QLA2031(ha)) {
5575 if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
5576 ql_log(ql_log_warn, base_vha, 0xb081,
5577 "Failed to dump mctp\n");
5578 return;
5579 }
5580
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005581 if (!ha->flags.nic_core_reset_hdlr_active) {
5582 if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
5583 qla83xx_idc_lock(base_vha, 0);
5584 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
5585 &dev_state);
5586 qla83xx_idc_unlock(base_vha, 0);
5587 if (dev_state != QLA8XXX_DEV_NEED_RESET) {
5588 ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
5589 "Nic Core f/w is alive.\n");
5590 return;
5591 }
5592 }
5593
5594 ha->flags.nic_core_reset_hdlr_active = 1;
5595 if (qla83xx_nic_core_reset(base_vha)) {
5596 /* NIC Core reset failed. */
5597 ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
5598 "NIC Core reset failed.\n");
5599 }
5600 ha->flags.nic_core_reset_hdlr_active = 0;
5601 }
5602}
5603
5604/* Work: Handle 8200 IDC aens */
5605void
5606qla83xx_service_idc_aen(struct work_struct *work)
5607{
5608 struct qla_hw_data *ha =
5609 container_of(work, struct qla_hw_data, idc_aen);
5610 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
5611 uint32_t dev_state, idc_control;
5612
5613 qla83xx_idc_lock(base_vha, 0);
5614 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5615 qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
5616 qla83xx_idc_unlock(base_vha, 0);
5617 if (dev_state == QLA8XXX_DEV_NEED_RESET) {
5618 if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
5619 ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
5620 "Application requested NIC Core Reset.\n");
5621 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5622 } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
5623 QLA_SUCCESS) {
5624 ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
5625 "Other protocol driver requested NIC Core Reset.\n");
5626 qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
5627 }
5628 } else if (dev_state == QLA8XXX_DEV_FAILED ||
5629 dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
5630 qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
5631 }
5632}
5633
5634static void
5635qla83xx_wait_logic(void)
5636{
5637 int i;
5638
5639 /* Yield CPU */
5640 if (!in_interrupt()) {
5641 /*
5642 * Wait about 200ms before retrying again.
5643 * This controls the number of retries for single
5644 * lock operation.
5645 */
5646 msleep(100);
5647 schedule();
5648 } else {
5649 for (i = 0; i < 20; i++)
5650 cpu_relax(); /* This a nop instr on i386 */
5651 }
5652}
5653
Saurav Kashyapfa492632012-11-21 02:40:29 -05005654static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005655qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
5656{
5657 int rval;
5658 uint32_t data;
5659 uint32_t idc_lck_rcvry_stage_mask = 0x3;
5660 uint32_t idc_lck_rcvry_owner_mask = 0x3c;
5661 struct qla_hw_data *ha = base_vha->hw;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005662 ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
5663 "Trying force recovery of the IDC lock.\n");
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005664
5665 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
5666 if (rval)
5667 return rval;
5668
5669 if ((data & idc_lck_rcvry_stage_mask) > 0) {
5670 return QLA_SUCCESS;
5671 } else {
5672 data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
5673 rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5674 data);
5675 if (rval)
5676 return rval;
5677
5678 msleep(200);
5679
5680 rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
5681 &data);
5682 if (rval)
5683 return rval;
5684
5685 if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
5686 data &= (IDC_LOCK_RECOVERY_STAGE2 |
5687 ~(idc_lck_rcvry_stage_mask));
5688 rval = qla83xx_wr_reg(base_vha,
5689 QLA83XX_IDC_LOCK_RECOVERY, data);
5690 if (rval)
5691 return rval;
5692
5693 /* Forcefully perform IDC UnLock */
5694 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
5695 &data);
5696 if (rval)
5697 return rval;
5698 /* Clear lock-id by setting 0xff */
5699 rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5700 0xff);
5701 if (rval)
5702 return rval;
5703 /* Clear lock-recovery by setting 0x0 */
5704 rval = qla83xx_wr_reg(base_vha,
5705 QLA83XX_IDC_LOCK_RECOVERY, 0x0);
5706 if (rval)
5707 return rval;
5708 } else
5709 return QLA_SUCCESS;
5710 }
5711
5712 return rval;
5713}
5714
Saurav Kashyapfa492632012-11-21 02:40:29 -05005715static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005716qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
5717{
5718 int rval = QLA_SUCCESS;
5719 uint32_t o_drv_lockid, n_drv_lockid;
5720 unsigned long lock_recovery_timeout;
5721
5722 lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
5723retry_lockid:
5724 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
5725 if (rval)
5726 goto exit;
5727
5728 /* MAX wait time before forcing IDC Lock recovery = 2 secs */
5729 if (time_after_eq(jiffies, lock_recovery_timeout)) {
5730 if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
5731 return QLA_SUCCESS;
5732 else
5733 return QLA_FUNCTION_FAILED;
5734 }
5735
5736 rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
5737 if (rval)
5738 goto exit;
5739
5740 if (o_drv_lockid == n_drv_lockid) {
5741 qla83xx_wait_logic();
5742 goto retry_lockid;
5743 } else
5744 return QLA_SUCCESS;
5745
5746exit:
5747 return rval;
5748}
5749
5750void
5751qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5752{
5753 uint16_t options = (requester_id << 15) | BIT_6;
5754 uint32_t data;
Saurav Kashyap6c315552013-02-08 01:57:53 -05005755 uint32_t lock_owner;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005756 struct qla_hw_data *ha = base_vha->hw;
5757
5758 /* IDC-lock implementation using driver-lock/lock-id remote registers */
5759retry_lock:
5760 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
5761 == QLA_SUCCESS) {
5762 if (data) {
5763 /* Setting lock-id to our function-number */
5764 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5765 ha->portnum);
5766 } else {
Saurav Kashyap6c315552013-02-08 01:57:53 -05005767 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
5768 &lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005769 ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
Saurav Kashyap6c315552013-02-08 01:57:53 -05005770 "Failed to acquire IDC lock, acquired by %d, "
5771 "retrying...\n", lock_owner);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005772
5773 /* Retry/Perform IDC-Lock recovery */
5774 if (qla83xx_idc_lock_recovery(base_vha)
5775 == QLA_SUCCESS) {
5776 qla83xx_wait_logic();
5777 goto retry_lock;
5778 } else
5779 ql_log(ql_log_warn, base_vha, 0xb075,
5780 "IDC Lock recovery FAILED.\n");
5781 }
5782
5783 }
5784
5785 return;
5786
5787 /* XXX: IDC-lock implementation using access-control mbx */
5788retry_lock2:
5789 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5790 ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
5791 "Failed to acquire IDC lock. retrying...\n");
5792 /* Retry/Perform IDC-Lock recovery */
5793 if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
5794 qla83xx_wait_logic();
5795 goto retry_lock2;
5796 } else
5797 ql_log(ql_log_warn, base_vha, 0xb076,
5798 "IDC Lock recovery FAILED.\n");
5799 }
5800
5801 return;
5802}
5803
5804void
5805qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
5806{
Bart Van Assche5897cb22015-06-04 15:57:20 -07005807#if 0
5808 uint16_t options = (requester_id << 15) | BIT_7;
5809#endif
5810 uint16_t retry;
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005811 uint32_t data;
5812 struct qla_hw_data *ha = base_vha->hw;
5813
5814 /* IDC-unlock implementation using driver-unlock/lock-id
5815 * remote registers
5816 */
5817 retry = 0;
5818retry_unlock:
5819 if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
5820 == QLA_SUCCESS) {
5821 if (data == ha->portnum) {
5822 qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
5823 /* Clearing lock-id by setting 0xff */
5824 qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
5825 } else if (retry < 10) {
5826 /* SV: XXX: IDC unlock retrying needed here? */
5827
5828 /* Retry for IDC-unlock */
5829 qla83xx_wait_logic();
5830 retry++;
5831 ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005832 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005833 goto retry_unlock;
5834 }
5835 } else if (retry < 10) {
5836 /* Retry for IDC-unlock */
5837 qla83xx_wait_logic();
5838 retry++;
5839 ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005840 "Failed to read drv-lockid, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005841 goto retry_unlock;
5842 }
5843
5844 return;
5845
Bart Van Assche5897cb22015-06-04 15:57:20 -07005846#if 0
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005847 /* XXX: IDC-unlock implementation using access-control mbx */
5848 retry = 0;
5849retry_unlock2:
5850 if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
5851 if (retry < 10) {
5852 /* Retry for IDC-unlock */
5853 qla83xx_wait_logic();
5854 retry++;
5855 ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
Colin Ian Kingee6a8772016-08-28 12:24:48 +01005856 "Failed to release IDC lock, retrying=%d\n", retry);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005857 goto retry_unlock2;
5858 }
5859 }
5860
5861 return;
Bart Van Assche5897cb22015-06-04 15:57:20 -07005862#endif
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005863}
5864
5865int
5866__qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5867{
5868 int rval = QLA_SUCCESS;
5869 struct qla_hw_data *ha = vha->hw;
5870 uint32_t drv_presence;
5871
5872 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5873 if (rval == QLA_SUCCESS) {
5874 drv_presence |= (1 << ha->portnum);
5875 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5876 drv_presence);
5877 }
5878
5879 return rval;
5880}
5881
5882int
5883qla83xx_set_drv_presence(scsi_qla_host_t *vha)
5884{
5885 int rval = QLA_SUCCESS;
5886
5887 qla83xx_idc_lock(vha, 0);
5888 rval = __qla83xx_set_drv_presence(vha);
5889 qla83xx_idc_unlock(vha, 0);
5890
5891 return rval;
5892}
5893
5894int
5895__qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5896{
5897 int rval = QLA_SUCCESS;
5898 struct qla_hw_data *ha = vha->hw;
5899 uint32_t drv_presence;
5900
5901 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5902 if (rval == QLA_SUCCESS) {
5903 drv_presence &= ~(1 << ha->portnum);
5904 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5905 drv_presence);
5906 }
5907
5908 return rval;
5909}
5910
5911int
5912qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
5913{
5914 int rval = QLA_SUCCESS;
5915
5916 qla83xx_idc_lock(vha, 0);
5917 rval = __qla83xx_clear_drv_presence(vha);
5918 qla83xx_idc_unlock(vha, 0);
5919
5920 return rval;
5921}
5922
Saurav Kashyapfa492632012-11-21 02:40:29 -05005923static void
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005924qla83xx_need_reset_handler(scsi_qla_host_t *vha)
5925{
5926 struct qla_hw_data *ha = vha->hw;
5927 uint32_t drv_ack, drv_presence;
5928 unsigned long ack_timeout;
5929
5930 /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
5931 ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
5932 while (1) {
5933 qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5934 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
Saurav Kashyap807fb6d2012-11-21 02:40:36 -05005935 if ((drv_ack & drv_presence) == drv_presence)
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005936 break;
5937
5938 if (time_after_eq(jiffies, ack_timeout)) {
5939 ql_log(ql_log_warn, vha, 0xb067,
5940 "RESET ACK TIMEOUT! drv_presence=0x%x "
5941 "drv_ack=0x%x\n", drv_presence, drv_ack);
5942 /*
5943 * The function(s) which did not ack in time are forced
5944 * to withdraw any further participation in the IDC
5945 * reset.
5946 */
5947 if (drv_ack != drv_presence)
5948 qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
5949 drv_ack);
5950 break;
5951 }
5952
5953 qla83xx_idc_unlock(vha, 0);
5954 msleep(1000);
5955 qla83xx_idc_lock(vha, 0);
5956 }
5957
5958 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
5959 ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
5960}
5961
Saurav Kashyapfa492632012-11-21 02:40:29 -05005962static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005963qla83xx_device_bootstrap(scsi_qla_host_t *vha)
5964{
5965 int rval = QLA_SUCCESS;
5966 uint32_t idc_control;
5967
5968 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
5969 ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
5970
5971 /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
5972 __qla83xx_get_idc_control(vha, &idc_control);
5973 idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
5974 __qla83xx_set_idc_control(vha, 0);
5975
5976 qla83xx_idc_unlock(vha, 0);
5977 rval = qla83xx_restart_nic_firmware(vha);
5978 qla83xx_idc_lock(vha, 0);
5979
5980 if (rval != QLA_SUCCESS) {
5981 ql_log(ql_log_fatal, vha, 0xb06a,
5982 "Failed to restart NIC f/w.\n");
5983 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
5984 ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
5985 } else {
5986 ql_dbg(ql_dbg_p3p, vha, 0xb06c,
5987 "Success in restarting nic f/w.\n");
5988 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
5989 ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
5990 }
5991
5992 return rval;
5993}
5994
5995/* Assumes idc_lock always held on entry */
5996int
5997qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
5998{
5999 struct qla_hw_data *ha = base_vha->hw;
6000 int rval = QLA_SUCCESS;
6001 unsigned long dev_init_timeout;
6002 uint32_t dev_state;
6003
6004 /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
6005 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
6006
6007 while (1) {
6008
6009 if (time_after_eq(jiffies, dev_init_timeout)) {
6010 ql_log(ql_log_warn, base_vha, 0xb06e,
6011 "Initialization TIMEOUT!\n");
6012 /* Init timeout. Disable further NIC Core
6013 * communication.
6014 */
6015 qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
6016 QLA8XXX_DEV_FAILED);
6017 ql_log(ql_log_info, base_vha, 0xb06f,
6018 "HW State: FAILED.\n");
6019 }
6020
6021 qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6022 switch (dev_state) {
6023 case QLA8XXX_DEV_READY:
6024 if (ha->flags.nic_core_reset_owner)
6025 qla83xx_idc_audit(base_vha,
6026 IDC_AUDIT_COMPLETION);
6027 ha->flags.nic_core_reset_owner = 0;
6028 ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
6029 "Reset_owner reset by 0x%x.\n",
6030 ha->portnum);
6031 goto exit;
6032 case QLA8XXX_DEV_COLD:
6033 if (ha->flags.nic_core_reset_owner)
6034 rval = qla83xx_device_bootstrap(base_vha);
6035 else {
6036 /* Wait for AEN to change device-state */
6037 qla83xx_idc_unlock(base_vha, 0);
6038 msleep(1000);
6039 qla83xx_idc_lock(base_vha, 0);
6040 }
6041 break;
6042 case QLA8XXX_DEV_INITIALIZING:
6043 /* Wait for AEN to change device-state */
6044 qla83xx_idc_unlock(base_vha, 0);
6045 msleep(1000);
6046 qla83xx_idc_lock(base_vha, 0);
6047 break;
6048 case QLA8XXX_DEV_NEED_RESET:
6049 if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
6050 qla83xx_need_reset_handler(base_vha);
6051 else {
6052 /* Wait for AEN to change device-state */
6053 qla83xx_idc_unlock(base_vha, 0);
6054 msleep(1000);
6055 qla83xx_idc_lock(base_vha, 0);
6056 }
6057 /* reset timeout value after need reset handler */
6058 dev_init_timeout = jiffies +
6059 (ha->fcoe_dev_init_timeout * HZ);
6060 break;
6061 case QLA8XXX_DEV_NEED_QUIESCENT:
6062 /* XXX: DEBUG for now */
6063 qla83xx_idc_unlock(base_vha, 0);
6064 msleep(1000);
6065 qla83xx_idc_lock(base_vha, 0);
6066 break;
6067 case QLA8XXX_DEV_QUIESCENT:
6068 /* XXX: DEBUG for now */
6069 if (ha->flags.quiesce_owner)
6070 goto exit;
6071
6072 qla83xx_idc_unlock(base_vha, 0);
6073 msleep(1000);
6074 qla83xx_idc_lock(base_vha, 0);
6075 dev_init_timeout = jiffies +
6076 (ha->fcoe_dev_init_timeout * HZ);
6077 break;
6078 case QLA8XXX_DEV_FAILED:
6079 if (ha->flags.nic_core_reset_owner)
6080 qla83xx_idc_audit(base_vha,
6081 IDC_AUDIT_COMPLETION);
6082 ha->flags.nic_core_reset_owner = 0;
6083 __qla83xx_clear_drv_presence(base_vha);
6084 qla83xx_idc_unlock(base_vha, 0);
6085 qla8xxx_dev_failed_handler(base_vha);
6086 rval = QLA_FUNCTION_FAILED;
6087 qla83xx_idc_lock(base_vha, 0);
6088 goto exit;
6089 case QLA8XXX_BAD_VALUE:
6090 qla83xx_idc_unlock(base_vha, 0);
6091 msleep(1000);
6092 qla83xx_idc_lock(base_vha, 0);
6093 break;
6094 default:
6095 ql_log(ql_log_warn, base_vha, 0xb071,
Masanari Iidad939be32015-02-27 23:52:31 +09006096 "Unknown Device State: %x.\n", dev_state);
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006097 qla83xx_idc_unlock(base_vha, 0);
6098 qla8xxx_dev_failed_handler(base_vha);
6099 rval = QLA_FUNCTION_FAILED;
6100 qla83xx_idc_lock(base_vha, 0);
6101 goto exit;
6102 }
6103 }
6104
6105exit:
6106 return rval;
6107}
6108
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006109void
6110qla2x00_disable_board_on_pci_error(struct work_struct *work)
6111{
6112 struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
6113 board_disable);
6114 struct pci_dev *pdev = ha->pdev;
6115 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
6116
Quinn Tran726b8542017-01-19 22:28:00 -08006117 /*
6118 * if UNLOAD flag is already set, then continue unload,
Sawan Chandak783e0dc2016-07-06 11:14:25 -04006119 * where it was set first.
6120 */
6121 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6122 return;
6123
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006124 ql_log(ql_log_warn, base_vha, 0x015b,
6125 "Disabling adapter.\n");
6126
Sawan Chandakefdb5762017-08-23 15:05:00 -07006127 if (!atomic_read(&pdev->enable_cnt)) {
6128 ql_log(ql_log_info, base_vha, 0xfffc,
6129 "PCI device disabled, no action req for PCI error=%lx\n",
6130 base_vha->pci_flags);
6131 return;
6132 }
6133
Quinn Tran726b8542017-01-19 22:28:00 -08006134 qla2x00_wait_for_sess_deletion(base_vha);
6135
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006136 set_bit(UNLOADING, &base_vha->dpc_flags);
6137
6138 qla2x00_delete_all_vps(ha, base_vha);
6139
6140 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6141
6142 qla2x00_dfs_remove(base_vha);
6143
6144 qla84xx_put_chip(base_vha);
6145
6146 if (base_vha->timer_active)
6147 qla2x00_stop_timer(base_vha);
6148
6149 base_vha->flags.online = 0;
6150
6151 qla2x00_destroy_deferred_work(ha);
6152
6153 /*
6154 * Do not try to stop beacon blink as it will issue a mailbox
6155 * command.
6156 */
6157 qla2x00_free_sysfs_attr(base_vha, false);
6158
6159 fc_remove_host(base_vha->host);
6160
6161 scsi_remove_host(base_vha->host);
6162
6163 base_vha->flags.init_done = 0;
6164 qla25xx_delete_queues(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006165 qla2x00_free_fcports(base_vha);
Quinn Tran093df732016-12-12 14:40:09 -08006166 qla2x00_free_irqs(base_vha);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006167 qla2x00_mem_free(ha);
6168 qla82xx_md_free(base_vha);
6169 qla2x00_free_queues(ha);
6170
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006171 qla2x00_unmap_iobases(ha);
6172
6173 pci_release_selected_regions(ha->pdev, ha->bars);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006174 pci_disable_pcie_error_reporting(pdev);
6175 pci_disable_device(pdev);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006176
Joe Lawrencebeb9e312014-08-26 17:12:14 -04006177 /*
6178 * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
6179 */
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006180}
6181
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182/**************************************************************************
6183* qla2x00_do_dpc
6184* This kernel thread is a task that is schedule by the interrupt handler
6185* to perform the background processing for interrupts.
6186*
6187* Notes:
6188* This task always run in the context of a kernel thread. It
6189* is kick-off by the driver's detect code and starts up
6190* up one per adapter. It immediately goes to sleep and waits for
6191* some fibre event. When either the interrupt handler or
6192* the timer routine detects a event it will one of the task
6193* bits then wake us up.
6194**************************************************************************/
6195static int
6196qla2x00_do_dpc(void *data)
6197{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006198 scsi_qla_host_t *base_vha;
6199 struct qla_hw_data *ha;
Michael Hernandezd7459522016-12-12 14:40:07 -08006200 uint32_t online;
6201 struct qla_qpair *qpair;
Seokmann Ju99363ef2008-01-31 12:33:51 -08006202
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006203 ha = (struct qla_hw_data *)data;
6204 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205
Dongsheng Yang8698a742014-03-11 18:09:12 +08006206 set_user_nice(current, MIN_NICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207
James Bottomley563585e2011-01-27 16:12:37 -05006208 set_current_state(TASK_INTERRUPTIBLE);
Christoph Hellwig39a11242006-02-14 18:46:22 +01006209 while (!kthread_should_stop()) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006210 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
6211 "DPC handler sleeping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212
Christoph Hellwig39a11242006-02-14 18:46:22 +01006213 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006215 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
6216 goto end_loop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217
Andrew Vasquez85880802009-12-15 21:29:46 -08006218 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006219 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
6220 "eeh_busy=%d.\n", ha->flags.eeh_busy);
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006221 goto end_loop;
Andrew Vasquez85880802009-12-15 21:29:46 -08006222 }
6223
Linus Torvalds1da177e2005-04-16 15:20:36 -07006224 ha->dpc_active = 1;
6225
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04006226 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
6227 "DPC handler waking up, dpc_flags=0x%lx.\n",
6228 base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -04006230 if (test_bit(UNLOADING, &base_vha->dpc_flags))
6231 break;
6232
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006233 if (IS_P3P_TYPE(ha)) {
6234 if (IS_QLA8044(ha)) {
6235 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6236 &base_vha->dpc_flags)) {
6237 qla8044_idc_lock(ha);
6238 qla8044_wr_direct(base_vha,
6239 QLA8044_CRB_DEV_STATE_INDEX,
6240 QLA8XXX_DEV_FAILED);
6241 qla8044_idc_unlock(ha);
6242 ql_log(ql_log_info, base_vha, 0x4004,
6243 "HW State: FAILED.\n");
6244 qla8044_device_state_handler(base_vha);
6245 continue;
6246 }
6247
6248 } else {
6249 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6250 &base_vha->dpc_flags)) {
6251 qla82xx_idc_lock(ha);
6252 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
6253 QLA8XXX_DEV_FAILED);
6254 qla82xx_idc_unlock(ha);
6255 ql_log(ql_log_info, base_vha, 0x0151,
6256 "HW State: FAILED.\n");
6257 qla82xx_device_state_handler(base_vha);
6258 continue;
6259 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006260 }
6261
6262 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
6263 &base_vha->dpc_flags)) {
6264
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006265 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
6266 "FCoE context reset scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006267 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
6268 &base_vha->dpc_flags))) {
6269 if (qla82xx_fcoe_ctx_reset(base_vha)) {
6270 /* FCoE-ctx reset failed.
6271 * Escalate to chip-reset
6272 */
6273 set_bit(ISP_ABORT_NEEDED,
6274 &base_vha->dpc_flags);
6275 }
6276 clear_bit(ABORT_ISP_ACTIVE,
6277 &base_vha->dpc_flags);
6278 }
6279
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006280 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
6281 "FCoE context reset end.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006282 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006283 } else if (IS_QLAFX00(ha)) {
6284 if (test_and_clear_bit(ISP_UNRECOVERABLE,
6285 &base_vha->dpc_flags)) {
6286 ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
6287 "Firmware Reset Recovery\n");
6288 if (qlafx00_reset_initialize(base_vha)) {
6289 /* Failed. Abort isp later. */
6290 if (!test_bit(UNLOADING,
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006291 &base_vha->dpc_flags)) {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006292 set_bit(ISP_UNRECOVERABLE,
6293 &base_vha->dpc_flags);
6294 ql_dbg(ql_dbg_dpc, base_vha,
6295 0x4021,
6296 "Reset Recovery Failed\n");
Dan Carpenterf92f82d2014-05-05 12:47:57 +03006297 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006298 }
6299 }
6300
6301 if (test_and_clear_bit(FX00_TARGET_SCAN,
6302 &base_vha->dpc_flags)) {
6303 ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
6304 "ISPFx00 Target Scan scheduled\n");
6305 if (qlafx00_rescan_isp(base_vha)) {
6306 if (!test_bit(UNLOADING,
6307 &base_vha->dpc_flags))
6308 set_bit(ISP_UNRECOVERABLE,
6309 &base_vha->dpc_flags);
6310 ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
6311 "ISPFx00 Target Scan Failed\n");
6312 }
6313 ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
6314 "ISPFx00 Target Scan End\n");
6315 }
Armen Baloyane8f5e952013-10-30 03:38:17 -04006316 if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
6317 &base_vha->dpc_flags)) {
6318 ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
6319 "ISPFx00 Host Info resend scheduled\n");
6320 qlafx00_fx_disc(base_vha,
6321 &base_vha->hw->mr.fcport,
6322 FXDISC_REG_HOST_INFO);
6323 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006324 }
6325
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006326 if (test_and_clear_bit(DETECT_SFP_CHANGE,
6327 &base_vha->dpc_flags) &&
6328 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) {
6329 qla24xx_detect_sfp(base_vha);
6330
6331 if (ha->flags.detected_lr_sfp !=
6332 ha->flags.using_lr_setting)
6333 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
6334 }
6335
Quinn Tranb08abbd2018-07-18 14:29:54 -07006336 if (test_and_clear_bit
6337 (ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
6338 !test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran93eca612018-08-31 11:24:37 -07006339 bool do_reset = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340
Quinn Tran0645cb82018-09-11 10:18:18 -07006341 switch (base_vha->qlini_mode) {
Quinn Tran93eca612018-08-31 11:24:37 -07006342 case QLA2XXX_INI_MODE_ENABLED:
6343 break;
6344 case QLA2XXX_INI_MODE_DISABLED:
Quinn Tran0645cb82018-09-11 10:18:18 -07006345 if (!qla_tgt_mode_enabled(base_vha) &&
6346 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006347 do_reset = false;
6348 break;
6349 case QLA2XXX_INI_MODE_DUAL:
Quinn Tran0645cb82018-09-11 10:18:18 -07006350 if (!qla_dual_mode_enabled(base_vha) &&
6351 !ha->flags.fw_started)
Quinn Tran93eca612018-08-31 11:24:37 -07006352 do_reset = false;
6353 break;
6354 default:
6355 break;
6356 }
6357
6358 if (do_reset && !(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006359 &base_vha->dpc_flags))) {
Quinn Tran93eca612018-08-31 11:24:37 -07006360 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
6361 "ISP abort scheduled.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006362 if (ha->isp_ops->abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363 /* failed. retry later */
6364 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006365 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006367 clear_bit(ABORT_ISP_ACTIVE,
6368 &base_vha->dpc_flags);
Quinn Tran93eca612018-08-31 11:24:37 -07006369 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
6370 "ISP abort end.\n");
Seokmann Ju99363ef2008-01-31 12:33:51 -08006371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 }
6373
David Jefferya394aac2012-11-21 02:39:54 -05006374 if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
6375 &base_vha->dpc_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006376 qla2x00_update_fcports(base_vha);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07006377 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08006378
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006379 if (IS_QLAFX00(ha))
6380 goto loop_resync_check;
6381
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006382 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006383 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
6384 "Quiescence mode scheduled.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006385 if (IS_P3P_TYPE(ha)) {
6386 if (IS_QLA82XX(ha))
6387 qla82xx_device_state_handler(base_vha);
6388 if (IS_QLA8044(ha))
6389 qla8044_device_state_handler(base_vha);
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006390 clear_bit(ISP_QUIESCE_NEEDED,
6391 &base_vha->dpc_flags);
6392 if (!ha->flags.quiesce_owner) {
6393 qla2x00_perform_loop_resync(base_vha);
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006394 if (IS_QLA82XX(ha)) {
6395 qla82xx_idc_lock(ha);
6396 qla82xx_clear_qsnt_ready(
6397 base_vha);
6398 qla82xx_idc_unlock(ha);
6399 } else if (IS_QLA8044(ha)) {
6400 qla8044_idc_lock(ha);
6401 qla8044_clear_qsnt_ready(
6402 base_vha);
6403 qla8044_idc_unlock(ha);
6404 }
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006405 }
6406 } else {
6407 clear_bit(ISP_QUIESCE_NEEDED,
6408 &base_vha->dpc_flags);
6409 qla2x00_quiesce_io(base_vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006410 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006411 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
6412 "Quiescence mode end.\n");
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006413 }
6414
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006415 if (test_and_clear_bit(RESET_MARKER_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006416 &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006417 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006419 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
6420 "Reset marker scheduled.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006421 qla2x00_rst_aen(base_vha);
6422 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006423 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
6424 "Reset marker end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425 }
6426
6427 /* Retry each device up to login retry count */
Quinn Tran4005a992017-12-04 14:45:06 -08006428 if (test_bit(RELOGIN_NEEDED, &base_vha->dpc_flags) &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006429 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
6430 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431
Quinn Tran4005a992017-12-04 14:45:06 -08006432 if (!base_vha->relogin_jif ||
6433 time_after_eq(jiffies, base_vha->relogin_jif)) {
6434 base_vha->relogin_jif = jiffies + HZ;
6435 clear_bit(RELOGIN_NEEDED, &base_vha->dpc_flags);
6436
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006437 ql_dbg(ql_dbg_disc, base_vha, 0x400d,
Quinn Tran4005a992017-12-04 14:45:06 -08006438 "Relogin scheduled.\n");
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006439 qla24xx_post_relogin_work(base_vha);
Quinn Tran4005a992017-12-04 14:45:06 -08006440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441 }
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006442loop_resync_check:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006443 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006444 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006446 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
6447 "Loop resync scheduled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448
6449 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006450 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451
Bart Van Assche52c82822015-07-09 07:23:26 -07006452 qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006454 clear_bit(LOOP_RESYNC_ACTIVE,
6455 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456 }
6457
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006458 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
6459 "Loop resync end.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 }
6461
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006462 if (IS_QLAFX00(ha))
6463 goto intr_on_check;
6464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006465 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
6466 atomic_read(&base_vha->loop_state) == LOOP_READY) {
6467 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
6468 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07006469 }
6470
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006471intr_on_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006473 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006475 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
Himanshu Madani90b604f2014-04-11 16:54:40 -04006476 &base_vha->dpc_flags)) {
6477 if (ha->beacon_blink_led == 1)
6478 ha->isp_ops->beacon_blink(base_vha);
6479 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006480
Michael Hernandezd7459522016-12-12 14:40:07 -08006481 /* qpair online check */
6482 if (test_and_clear_bit(QPAIR_ONLINE_CHECK_NEEDED,
6483 &base_vha->dpc_flags)) {
6484 if (ha->flags.eeh_busy ||
6485 ha->flags.pci_channel_io_perm_failure)
6486 online = 0;
6487 else
6488 online = 1;
6489
6490 mutex_lock(&ha->mq_lock);
6491 list_for_each_entry(qpair, &base_vha->qp_list,
6492 qp_list_elem)
6493 qpair->online = online;
6494 mutex_unlock(&ha->mq_lock);
6495 }
6496
Quinn Tran8b4673b2018-09-04 14:19:14 -07006497 if (test_and_clear_bit(SET_NVME_ZIO_THRESHOLD_NEEDED,
6498 &base_vha->dpc_flags)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006499 ql_log(ql_log_info, base_vha, 0xffffff,
6500 "nvme: SET ZIO Activity exchange threshold to %d.\n",
6501 ha->nvme_last_rptd_aen);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006502 if (qla27xx_set_zio_threshold(base_vha,
6503 ha->nvme_last_rptd_aen)) {
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006504 ql_log(ql_log_info, base_vha, 0xffffff,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006505 "nvme: Unable to SET ZIO Activity exchange threshold to %d.\n",
6506 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006507 }
6508 }
6509
Quinn Tran8b4673b2018-09-04 14:19:14 -07006510 if (test_and_clear_bit(SET_ZIO_THRESHOLD_NEEDED,
6511 &base_vha->dpc_flags)) {
6512 ql_log(ql_log_info, base_vha, 0xffffff,
6513 "SET ZIO Activity exchange threshold to %d.\n",
6514 ha->last_zio_threshold);
6515 qla27xx_set_zio_threshold(base_vha,
6516 ha->last_zio_threshold);
6517 }
6518
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006519 if (!IS_QLAFX00(ha))
6520 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006521
Quinn Tran48acad02018-08-02 13:16:44 -07006522 if (test_and_clear_bit(N2N_LINK_RESET,
6523 &base_vha->dpc_flags)) {
6524 qla2x00_lip_reset(base_vha);
6525 }
6526
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 ha->dpc_active = 0;
Andrew Vasquezc142caf2011-11-18 09:03:10 -08006528end_loop:
James Bottomley563585e2011-01-27 16:12:37 -05006529 set_current_state(TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 } /* End of while(1) */
James Bottomley563585e2011-01-27 16:12:37 -05006531 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006533 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
6534 "DPC handler exiting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535
6536 /*
6537 * Make sure that nobody tries to wake us up again.
6538 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 ha->dpc_active = 0;
6540
Andrew Vasquezac280b62009-08-20 11:06:05 -07006541 /* Cleanup any residual CTX SRBs. */
6542 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
6543
Christoph Hellwig39a11242006-02-14 18:46:22 +01006544 return 0;
6545}
6546
6547void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006548qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01006549{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006550 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006551 struct task_struct *t = ha->dpc_thread;
6552
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006553 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07006554 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555}
6556
6557/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558* qla2x00_rst_aen
6559* Processes asynchronous reset.
6560*
6561* Input:
6562* ha = adapter block pointer.
6563*/
6564static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006565qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006567 if (vha->flags.online && !vha->flags.reset_active &&
6568 !atomic_read(&vha->loop_down_timer) &&
6569 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006571 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572
6573 /*
6574 * Issue marker command only when we are going to start
6575 * the I/O.
6576 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006577 vha->marker_needed = 1;
6578 } while (!atomic_read(&vha->loop_down_timer) &&
6579 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580 }
6581}
6582
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583/**************************************************************************
6584* qla2x00_timer
6585*
6586* Description:
6587* One second timer
6588*
6589* Context: Interrupt
6590***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006591void
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006592qla2x00_timer(struct timer_list *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593{
Kees Cook8e5f4ba2017-09-03 13:23:32 -07006594 scsi_qla_host_t *vha = from_timer(vha, t, timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 unsigned long cpu_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006596 int start_dpc = 0;
6597 int index;
6598 srb_t *sp;
Andrew Vasquez85880802009-12-15 21:29:46 -08006599 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006600 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006601 struct req_que *req;
Andrew Vasquez85880802009-12-15 21:29:46 -08006602
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006603 if (ha->flags.eeh_busy) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006604 ql_dbg(ql_dbg_timer, vha, 0x6000,
6605 "EEH = %d, restarting timer.\n",
6606 ha->flags.eeh_busy);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006607 qla2x00_restart_timer(vha, WATCH_INTERVAL);
6608 return;
6609 }
6610
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006611 /*
6612 * Hardware read to raise pending EEH errors during mailbox waits. If
6613 * the read returns -1 then disable the board.
6614 */
6615 if (!pci_channel_offline(ha->pdev)) {
Andrew Vasquez85880802009-12-15 21:29:46 -08006616 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Joe Lawrencec821e0d2014-08-26 17:11:41 -04006617 qla2x00_check_reg16_for_disconnect(vha, w);
Chad Dupuisf3ddac12013-10-30 03:38:16 -04006618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006620 /* Make sure qla82xx_watchdog is run only for physical port */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006621 if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006622 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
6623 start_dpc++;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006624 if (IS_QLA82XX(ha))
6625 qla82xx_watchdog(vha);
6626 else if (IS_QLA8044(ha))
6627 qla8044_watchdog(vha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006628 }
6629
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04006630 if (!vha->vp_idx && IS_QLAFX00(ha))
6631 qlafx00_timer_routine(vha);
6632
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006634 if (atomic_read(&vha->loop_down_timer) > 0 &&
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006635 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
6636 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006637 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006639 if (atomic_read(&vha->loop_down_timer) ==
6640 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006642 ql_log(ql_log_info, vha, 0x6008,
6643 "Loop down - aborting the queues before time expires.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006645 if (!IS_QLA2100(ha) && vha->link_down_timeout)
6646 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006648 /*
6649 * Schedule an ISP abort to return any FCP2-device
6650 * commands.
6651 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006652 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006653 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006654 spin_lock_irqsave(&ha->hardware_lock,
6655 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006656 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006657 for (index = 1;
Chad Dupuis8d93f552013-01-30 03:34:37 -05006658 index < req->num_outstanding_cmds;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006659 index++) {
6660 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05006661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006662 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006663 if (!sp)
6664 continue;
Quinn Tranc5419e22017-06-13 20:47:16 -07006665 if (sp->cmd_type != TYPE_SRB)
6666 continue;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08006667 if (sp->type != SRB_SCSI_CMD)
Andrew Vasquezcf53b062009-08-20 11:06:04 -07006668 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006669 sfcp = sp->fcport;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08006670 if (!(sfcp->flags & FCF_FCP2_DEVICE))
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006671 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006673 if (IS_QLA82XX(ha))
6674 set_bit(FCOE_CTX_RESET_NEEDED,
6675 &vha->dpc_flags);
6676 else
6677 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006678 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006679 break;
6680 }
6681 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006682 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684 start_dpc++;
6685 }
6686
6687 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006688 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -07006689 if (!(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006690 ql_log(ql_log_warn, vha, 0x6009,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691 "Loop down - aborting ISP.\n");
6692
Giridhar Malavali8f7daea2011-03-30 11:46:26 -07006693 if (IS_QLA82XX(ha))
6694 set_bit(FCOE_CTX_RESET_NEEDED,
6695 &vha->dpc_flags);
6696 else
6697 set_bit(ISP_ABORT_NEEDED,
6698 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 }
6700 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006701 ql_dbg(ql_dbg_timer, vha, 0x600a,
6702 "Loop down - seconds remaining %d.\n",
6703 atomic_read(&vha->loop_down_timer));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006704 }
Saurav Kashyapcefcaba2011-05-10 11:18:18 -07006705 /* Check if beacon LED needs to be blinked for physical host only */
6706 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006707 /* There is no beacon_blink function for ISP82xx */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006708 if (!IS_P3P_TYPE(ha)) {
Saurav Kashyap999916d2011-08-16 11:31:45 -07006709 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
6710 start_dpc++;
6711 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08006712 }
6713
Andrew Vasquez550bf572008-04-24 15:21:23 -07006714 /* Process any deferred work. */
Quinn Tran9b3e0f42017-12-28 12:33:16 -08006715 if (!list_empty(&vha->work_list)) {
6716 unsigned long flags;
6717 bool q = false;
6718
6719 spin_lock_irqsave(&vha->work_lock, flags);
6720 if (!test_and_set_bit(IOCB_WORK_ACTIVE, &vha->dpc_flags))
6721 q = true;
6722 spin_unlock_irqrestore(&vha->work_lock, flags);
6723 if (q)
6724 queue_work(vha->hw->wq, &vha->iocb_work);
6725 }
Andrew Vasquez550bf572008-04-24 15:21:23 -07006726
Duane Grigsby7401bc12017-06-21 13:48:42 -07006727 /*
6728 * FC-NVME
6729 * see if the active AEN count has changed from what was last reported.
6730 */
Quinn Tran8b4673b2018-09-04 14:19:14 -07006731 if (!vha->vp_idx && (atomic_read(&ha->nvme_active_aen_cnt) !=
6732 ha->nvme_last_rptd_aen) && ha->zio_mode == QLA_ZIO_MODE_6) {
Duane Grigsby7401bc12017-06-21 13:48:42 -07006733 ql_log(ql_log_info, vha, 0x3002,
Quinn Tran8b4673b2018-09-04 14:19:14 -07006734 "nvme: Sched: Set ZIO exchange threshold to %d.\n",
6735 ha->nvme_last_rptd_aen);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006736 ha->nvme_last_rptd_aen = atomic_read(&ha->nvme_active_aen_cnt);
Quinn Tran8b4673b2018-09-04 14:19:14 -07006737 set_bit(SET_NVME_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6738 start_dpc++;
6739 }
6740
6741 if (!vha->vp_idx &&
6742 (atomic_read(&ha->zio_threshold) != ha->last_zio_threshold) &&
6743 (ha->zio_mode == QLA_ZIO_MODE_6) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006744 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
Quinn Tran8b4673b2018-09-04 14:19:14 -07006745 ql_log(ql_log_info, vha, 0x3002,
6746 "Sched: Set ZIO exchange threshold to %d.\n",
6747 ha->last_zio_threshold);
6748 ha->last_zio_threshold = atomic_read(&ha->zio_threshold);
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006749 set_bit(SET_ZIO_THRESHOLD_NEEDED, &vha->dpc_flags);
6750 start_dpc++;
Duane Grigsby7401bc12017-06-21 13:48:42 -07006751 }
6752
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006754 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
6755 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
6756 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006758 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
6759 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
Giridhar Malavalia9083012010-04-12 17:59:55 -07006760 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
6761 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006762 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
Chad Dupuis50280c02013-10-30 03:38:14 -04006763 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006764 ql_dbg(ql_dbg_timer, vha, 0x600b,
6765 "isp_abort_needed=%d loop_resync_needed=%d "
6766 "fcport_update_needed=%d start_dpc=%d "
6767 "reset_marker_needed=%d",
6768 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
6769 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
6770 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
6771 start_dpc,
6772 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
6773 ql_dbg(ql_dbg_timer, vha, 0x600c,
6774 "beacon_blink_needed=%d isp_unrecoverable=%d "
6775 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
Chad Dupuis50280c02013-10-30 03:38:14 -04006776 "relogin_needed=%d.\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006777 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
6778 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
6779 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
6780 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
Chad Dupuis50280c02013-10-30 03:38:14 -04006781 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006782 qla2xxx_wake_dpc(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006785 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786}
6787
Andrew Vasquez54333832005-11-09 15:49:04 -08006788/* Firmware interface routines. */
6789
Andrew Vasquez54333832005-11-09 15:49:04 -08006790#define FW_ISP21XX 0
6791#define FW_ISP22XX 1
6792#define FW_ISP2300 2
6793#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006794#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006795#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006796#define FW_ISP81XX 6
Giridhar Malavalia9083012010-04-12 17:59:55 -07006797#define FW_ISP82XX 7
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006798#define FW_ISP2031 8
6799#define FW_ISP8031 9
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006800#define FW_ISP27XX 10
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006801#define FW_ISP28XX 11
Andrew Vasquez54333832005-11-09 15:49:04 -08006802
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006803#define FW_FILE_ISP21XX "ql2100_fw.bin"
6804#define FW_FILE_ISP22XX "ql2200_fw.bin"
6805#define FW_FILE_ISP2300 "ql2300_fw.bin"
6806#define FW_FILE_ISP2322 "ql2322_fw.bin"
6807#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006808#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006809#define FW_FILE_ISP81XX "ql8100_fw.bin"
Giridhar Malavalia9083012010-04-12 17:59:55 -07006810#define FW_FILE_ISP82XX "ql8200_fw.bin"
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006811#define FW_FILE_ISP2031 "ql2600_fw.bin"
6812#define FW_FILE_ISP8031 "ql8300_fw.bin"
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006813#define FW_FILE_ISP27XX "ql2700_fw.bin"
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006814#define FW_FILE_ISP28XX "ql2800_fw.bin"
Chad Dupuisf73cb692014-02-26 04:15:06 -05006815
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006816
Daniel Walkere1e82b62008-05-12 22:21:10 -07006817static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006818
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006819static struct fw_blob qla_fw_blobs[] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07006820 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
6821 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
6822 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
6823 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
6824 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006825 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006826 { .name = FW_FILE_ISP81XX, },
Giridhar Malavalia9083012010-04-12 17:59:55 -07006827 { .name = FW_FILE_ISP82XX, },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006828 { .name = FW_FILE_ISP2031, },
6829 { .name = FW_FILE_ISP8031, },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006830 { .name = FW_FILE_ISP27XX, },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006831 { .name = FW_FILE_ISP28XX, },
6832 { .name = NULL, },
Andrew Vasquez54333832005-11-09 15:49:04 -08006833};
6834
6835struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006836qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08006837{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006838 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08006839 struct fw_blob *blob;
6840
Andrew Vasquez54333832005-11-09 15:49:04 -08006841 if (IS_QLA2100(ha)) {
6842 blob = &qla_fw_blobs[FW_ISP21XX];
6843 } else if (IS_QLA2200(ha)) {
6844 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006845 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006846 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08006847 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006848 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006849 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08006850 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07006851 } else if (IS_QLA25XX(ha)) {
6852 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006853 } else if (IS_QLA81XX(ha)) {
6854 blob = &qla_fw_blobs[FW_ISP81XX];
Giridhar Malavalia9083012010-04-12 17:59:55 -07006855 } else if (IS_QLA82XX(ha)) {
6856 blob = &qla_fw_blobs[FW_ISP82XX];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006857 } else if (IS_QLA2031(ha)) {
6858 blob = &qla_fw_blobs[FW_ISP2031];
6859 } else if (IS_QLA8031(ha)) {
6860 blob = &qla_fw_blobs[FW_ISP8031];
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04006861 } else if (IS_QLA27XX(ha)) {
6862 blob = &qla_fw_blobs[FW_ISP27XX];
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006863 } else if (IS_QLA28XX(ha)) {
6864 blob = &qla_fw_blobs[FW_ISP28XX];
Dan Carpenter8a655222012-02-21 10:29:40 +03006865 } else {
6866 return NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006867 }
6868
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006869 if (!blob->name)
6870 return NULL;
6871
Daniel Walkere1e82b62008-05-12 22:21:10 -07006872 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006873 if (blob->fw)
6874 goto out;
6875
6876 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006877 ql_log(ql_log_warn, vha, 0x0063,
6878 "Failed to load firmware image (%s).\n", blob->name);
Andrew Vasquez54333832005-11-09 15:49:04 -08006879 blob->fw = NULL;
6880 blob = NULL;
Andrew Vasquez54333832005-11-09 15:49:04 -08006881 }
6882
6883out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07006884 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006885 return blob;
6886}
6887
6888static void
6889qla2x00_release_firmware(void)
6890{
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006891 struct fw_blob *blob;
Andrew Vasquez54333832005-11-09 15:49:04 -08006892
Daniel Walkere1e82b62008-05-12 22:21:10 -07006893 mutex_lock(&qla_fw_lock);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006894 for (blob = qla_fw_blobs; blob->name; blob++)
6895 release_firmware(blob->fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07006896 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08006897}
6898
Seokmann Ju14e660e2007-09-20 14:07:36 -07006899static pci_ers_result_t
6900qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
6901{
Andrew Vasquez85880802009-12-15 21:29:46 -08006902 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
6903 struct qla_hw_data *ha = vha->hw;
6904
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006905 ql_dbg(ql_dbg_aer, vha, 0x9000,
6906 "PCI error detected, state %x.\n", state);
Seokmann Jub9b12f72009-03-24 09:08:18 -07006907
Sawan Chandakefdb5762017-08-23 15:05:00 -07006908 if (!atomic_read(&pdev->enable_cnt)) {
6909 ql_log(ql_log_info, vha, 0xffff,
6910 "PCI device is disabled,state %x\n", state);
6911 return PCI_ERS_RESULT_NEED_RESET;
6912 }
6913
Seokmann Ju14e660e2007-09-20 14:07:36 -07006914 switch (state) {
6915 case pci_channel_io_normal:
Andrew Vasquez85880802009-12-15 21:29:46 -08006916 ha->flags.eeh_busy = 0;
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006917 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006918 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6919 qla2xxx_wake_dpc(vha);
6920 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006921 return PCI_ERS_RESULT_CAN_RECOVER;
6922 case pci_channel_io_frozen:
Andrew Vasquez85880802009-12-15 21:29:46 -08006923 ha->flags.eeh_busy = 1;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006924 /* For ISP82XX complete any pending mailbox cmd */
6925 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006926 ha->flags.isp82xx_fw_hung = 1;
Chad Dupuisc8f65442011-11-18 09:02:17 -08006927 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
6928 qla82xx_clear_pending_mbx(vha);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006929 }
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08006930 qla2x00_free_irqs(vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006931 pci_disable_device(pdev);
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006932 /* Return back all IOs */
6933 qla2x00_abort_all_cmds(vha, DID_RESET << 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_NEED_RESET;
6939 case pci_channel_io_perm_failure:
Andrew Vasquez85880802009-12-15 21:29:46 -08006940 ha->flags.pci_channel_io_perm_failure = 1;
6941 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07006942 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08006943 set_bit(QPAIR_ONLINE_CHECK_NEEDED, &vha->dpc_flags);
6944 qla2xxx_wake_dpc(vha);
6945 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07006946 return PCI_ERS_RESULT_DISCONNECT;
6947 }
6948 return PCI_ERS_RESULT_NEED_RESET;
6949}
6950
6951static pci_ers_result_t
6952qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
6953{
6954 int risc_paused = 0;
6955 uint32_t stat;
6956 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006957 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
6958 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07006959 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6960 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
6961
Saurav Kashyapbcc5b6d2010-09-03 15:20:57 -07006962 if (IS_QLA82XX(ha))
6963 return PCI_ERS_RESULT_RECOVERED;
6964
Seokmann Ju14e660e2007-09-20 14:07:36 -07006965 spin_lock_irqsave(&ha->hardware_lock, flags);
6966 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
6967 stat = RD_REG_DWORD(&reg->hccr);
6968 if (stat & HCCR_RISC_PAUSE)
6969 risc_paused = 1;
6970 } else if (IS_QLA23XX(ha)) {
6971 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
6972 if (stat & HSR_RISC_PAUSED)
6973 risc_paused = 1;
6974 } else if (IS_FWI2_CAPABLE(ha)) {
6975 stat = RD_REG_DWORD(&reg24->host_status);
6976 if (stat & HSRX_RISC_PAUSED)
6977 risc_paused = 1;
6978 }
6979 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6980
6981 if (risc_paused) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006982 ql_log(ql_log_info, base_vha, 0x9003,
6983 "RISC paused -- mmio_enabled, Dumping firmware.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006984 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07006985
6986 return PCI_ERS_RESULT_NEED_RESET;
6987 } else
6988 return PCI_ERS_RESULT_RECOVERED;
6989}
6990
Saurav Kashyapfa492632012-11-21 02:40:29 -05006991static uint32_t
6992qla82xx_error_recovery(scsi_qla_host_t *base_vha)
Lalit Chandivadea5b36322010-09-03 15:20:50 -07006993{
6994 uint32_t rval = QLA_FUNCTION_FAILED;
6995 uint32_t drv_active = 0;
6996 struct qla_hw_data *ha = base_vha->hw;
6997 int fn;
6998 struct pci_dev *other_pdev = NULL;
6999
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007000 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
7001 "Entered %s.\n", __func__);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007002
7003 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7004
7005 if (base_vha->flags.online) {
7006 /* Abort all outstanding commands,
7007 * so as to be requeued later */
7008 qla2x00_abort_isp_cleanup(base_vha);
7009 }
7010
7011
7012 fn = PCI_FUNC(ha->pdev->devfn);
7013 while (fn > 0) {
7014 fn--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007015 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
7016 "Finding pci device at function = 0x%x.\n", fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007017 other_pdev =
7018 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
7019 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
7020 fn));
7021
7022 if (!other_pdev)
7023 continue;
7024 if (atomic_read(&other_pdev->enable_cnt)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007025 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
7026 "Found PCI func available and enable at 0x%x.\n",
7027 fn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007028 pci_dev_put(other_pdev);
7029 break;
7030 }
7031 pci_dev_put(other_pdev);
7032 }
7033
7034 if (!fn) {
7035 /* Reset owner */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007036 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
7037 "This devfn is reset owner = 0x%x.\n",
7038 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007039 qla82xx_idc_lock(ha);
7040
7041 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007042 QLA8XXX_DEV_INITIALIZING);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007043
7044 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
7045 QLA82XX_IDC_VERSION);
7046
7047 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007048 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
7049 "drv_active = 0x%x.\n", drv_active);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007050
7051 qla82xx_idc_unlock(ha);
7052 /* Reset if device is not already reset
7053 * drv_active would be 0 if a reset has already been done
7054 */
7055 if (drv_active)
7056 rval = qla82xx_start_firmware(base_vha);
7057 else
7058 rval = QLA_SUCCESS;
7059 qla82xx_idc_lock(ha);
7060
7061 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007062 ql_log(ql_log_info, base_vha, 0x900b,
7063 "HW State: FAILED.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007064 qla82xx_clear_drv_active(ha);
7065 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007066 QLA8XXX_DEV_FAILED);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007067 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007068 ql_log(ql_log_info, base_vha, 0x900c,
7069 "HW State: READY.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007070 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007071 QLA8XXX_DEV_READY);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007072 qla82xx_idc_unlock(ha);
Giridhar Malavali71905752011-02-23 15:27:10 -08007073 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007074 rval = qla82xx_restart_isp(base_vha);
7075 qla82xx_idc_lock(ha);
7076 /* Clear driver state register */
7077 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
7078 qla82xx_set_drv_active(base_vha);
7079 }
7080 qla82xx_idc_unlock(ha);
7081 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007082 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
7083 "This devfn is not reset owner = 0x%x.\n",
7084 ha->pdev->devfn);
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007085 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04007086 QLA8XXX_DEV_READY)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08007087 ha->flags.isp82xx_fw_hung = 0;
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007088 rval = qla82xx_restart_isp(base_vha);
7089 qla82xx_idc_lock(ha);
7090 qla82xx_set_drv_active(base_vha);
7091 qla82xx_idc_unlock(ha);
7092 }
7093 }
7094 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7095
7096 return rval;
7097}
7098
Seokmann Ju14e660e2007-09-20 14:07:36 -07007099static pci_ers_result_t
7100qla2xxx_pci_slot_reset(struct pci_dev *pdev)
7101{
7102 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007103 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7104 struct qla_hw_data *ha = base_vha->hw;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007105 struct rsp_que *rsp;
7106 int rc, retries = 10;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007107
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007108 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
7109 "Slot Reset.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007110
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007111 /* Workaround: qla2xxx driver which access hardware earlier
7112 * needs error state to be pci_channel_io_online.
7113 * Otherwise mailbox command timesout.
7114 */
7115 pdev->error_state = pci_channel_io_normal;
7116
7117 pci_restore_state(pdev);
7118
Richard Lary8c1496b2010-02-18 10:07:29 -08007119 /* pci_restore_state() clears the saved_state flag of the device
7120 * save restored state which resets saved_state flag
7121 */
7122 pci_save_state(pdev);
7123
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11007124 if (ha->mem_only)
7125 rc = pci_enable_device_mem(pdev);
7126 else
7127 rc = pci_enable_device(pdev);
7128
7129 if (rc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007130 ql_log(ql_log_warn, base_vha, 0x9005,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007131 "Can't re-enable PCI device after reset.\n");
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007132 goto exit_slot_reset;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007133 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007134
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007135 rsp = ha->rsp_q_map[0];
7136 if (qla2x00_request_irqs(ha, rsp))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007137 goto exit_slot_reset;
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007139 if (ha->isp_ops->pci_config(base_vha))
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007140 goto exit_slot_reset;
7141
7142 if (IS_QLA82XX(ha)) {
7143 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
7144 ret = PCI_ERS_RESULT_RECOVERED;
7145 goto exit_slot_reset;
7146 } else
7147 goto exit_slot_reset;
7148 }
Seokmann Ju14e660e2007-09-20 14:07:36 -07007149
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007150 while (ha->flags.mbox_busy && retries--)
7151 msleep(1000);
Andrew Vasquez85880802009-12-15 21:29:46 -08007152
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007153 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007154 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07007155 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007156 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007157
Joe Carnuccio90a86fc2010-01-12 13:02:46 -08007158
Lalit Chandivadea5b36322010-09-03 15:20:50 -07007159exit_slot_reset:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007160 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
7161 "slot_reset return %x.\n", ret);
Andrew Vasquez85880802009-12-15 21:29:46 -08007162
Seokmann Ju14e660e2007-09-20 14:07:36 -07007163 return ret;
7164}
7165
7166static void
7167qla2xxx_pci_resume(struct pci_dev *pdev)
7168{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007169 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7170 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007171 int ret;
7172
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007173 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
7174 "pci_resume.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -08007175
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007176 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07007177 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007178 ql_log(ql_log_fatal, base_vha, 0x9002,
7179 "The device failed to resume I/O from slot/link_reset.\n");
Seokmann Ju14e660e2007-09-20 14:07:36 -07007180 }
Andrew Vasquez85880802009-12-15 21:29:46 -08007181
7182 ha->flags.eeh_busy = 0;
Seokmann Ju14e660e2007-09-20 14:07:36 -07007183}
7184
Quinn Tran590f8062019-01-24 23:23:40 -08007185static void
7186qla_pci_reset_prepare(struct pci_dev *pdev)
7187{
7188 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7189 struct qla_hw_data *ha = base_vha->hw;
7190 struct qla_qpair *qpair;
7191
7192 ql_log(ql_log_warn, base_vha, 0xffff,
7193 "%s.\n", __func__);
7194
7195 /*
7196 * PCI FLR/function reset is about to reset the
7197 * slot. Stop the chip to stop all DMA access.
7198 * It is assumed that pci_reset_done will be called
7199 * after FLR to resume Chip operation.
7200 */
7201 ha->flags.eeh_busy = 1;
7202 mutex_lock(&ha->mq_lock);
7203 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7204 qpair->online = 0;
7205 mutex_unlock(&ha->mq_lock);
7206
7207 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7208 qla2x00_abort_isp_cleanup(base_vha);
7209 qla2x00_abort_all_cmds(base_vha, DID_RESET << 16);
7210}
7211
7212static void
7213qla_pci_reset_done(struct pci_dev *pdev)
7214{
7215 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
7216 struct qla_hw_data *ha = base_vha->hw;
7217 struct qla_qpair *qpair;
7218
7219 ql_log(ql_log_warn, base_vha, 0xffff,
7220 "%s.\n", __func__);
7221
7222 /*
7223 * FLR just completed by PCI layer. Resume adapter
7224 */
7225 ha->flags.eeh_busy = 0;
7226 mutex_lock(&ha->mq_lock);
7227 list_for_each_entry(qpair, &base_vha->qp_list, qp_list_elem)
7228 qpair->online = 1;
7229 mutex_unlock(&ha->mq_lock);
7230
7231 base_vha->flags.online = 1;
7232 ha->isp_ops->abort_isp(base_vha);
7233 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
7234}
7235
Michael Hernandez56012362016-12-12 14:40:08 -08007236static int qla2xxx_map_queues(struct Scsi_Host *shost)
7237{
Quinn Trand68b8502017-12-04 14:44:59 -08007238 int rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007239 scsi_qla_host_t *vha = (scsi_qla_host_t *)shost->hostdata;
Jens Axboeed76e322018-10-29 13:06:14 -06007240 struct blk_mq_queue_map *qmap = &shost->tag_set.map[0];
Michael Hernandez56012362016-12-12 14:40:08 -08007241
Giridhar Malavalif3e02692019-02-15 16:42:55 -08007242 if (USER_CTRL_IRQ(vha->hw) || !vha->hw->mqiobase)
Jens Axboeed76e322018-10-29 13:06:14 -06007243 rc = blk_mq_map_queues(qmap);
Quinn Trand68b8502017-12-04 14:44:59 -08007244 else
Ming Leif0783d42019-01-11 09:40:47 -08007245 rc = blk_mq_pci_map_queues(qmap, vha->hw->pdev, vha->irq_offset);
Quinn Trand68b8502017-12-04 14:44:59 -08007246 return rc;
Michael Hernandez56012362016-12-12 14:40:08 -08007247}
7248
Stephen Hemmingera55b2d22012-09-07 09:33:16 -07007249static const struct pci_error_handlers qla2xxx_err_handler = {
Seokmann Ju14e660e2007-09-20 14:07:36 -07007250 .error_detected = qla2xxx_pci_error_detected,
7251 .mmio_enabled = qla2xxx_pci_mmio_enabled,
7252 .slot_reset = qla2xxx_pci_slot_reset,
7253 .resume = qla2xxx_pci_resume,
Quinn Tran590f8062019-01-24 23:23:40 -08007254 .reset_prepare = qla_pci_reset_prepare,
7255 .reset_done = qla_pci_reset_done,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007256};
7257
Andrew Vasquez54333832005-11-09 15:49:04 -08007258static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007259 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
7260 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
7261 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
7262 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
7263 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
7264 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
7265 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
7266 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
7267 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007268 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07007269 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
7270 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07007271 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007272 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007273 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Giridhar Malavalia9083012010-04-12 17:59:55 -07007274 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
Chad Dupuis650f5282012-08-22 14:20:55 -04007275 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04007276 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007277 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
Chad Dupuisf73cb692014-02-26 04:15:06 -05007278 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
Joe Carnuccio2c5bbbb2014-04-11 16:54:13 -04007279 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
Sawan Chandak2b489922015-08-04 13:38:03 -04007280 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
Joe Carnuccioecc89f22019-03-12 11:08:13 -07007281 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2061) },
7282 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2081) },
7283 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2281) },
7284 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2089) },
7285 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2289) },
Andrew Vasquez54333832005-11-09 15:49:04 -08007286 { 0 },
7287};
7288MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
7289
Andrew Vasquezfca29702005-07-06 10:31:47 -07007290static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07007291 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06007292 .driver = {
7293 .owner = THIS_MODULE,
7294 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07007295 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007296 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08007297 .remove = qla2x00_remove_one,
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07007298 .shutdown = qla2x00_shutdown,
Seokmann Ju14e660e2007-09-20 14:07:36 -07007299 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07007300};
7301
Al Viro75ef9de2013-04-04 19:09:41 -04007302static const struct file_operations apidev_fops = {
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007303 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +02007304 .llseek = noop_llseek,
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007305};
7306
Linus Torvalds1da177e2005-04-16 15:20:36 -07007307/**
7308 * qla2x00_module_init - Module initialization.
7309 **/
7310static int __init
7311qla2x00_module_init(void)
7312{
Andrew Vasquezfca29702005-07-06 10:31:47 -07007313 int ret = 0;
7314
Linus Torvalds1da177e2005-04-16 15:20:36 -07007315 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007316 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09007317 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007318 if (srb_cachep == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007319 ql_log(ql_log_fatal, NULL, 0x0001,
7320 "Unable to allocate SRB cache...Failing load!.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007321 return -ENOMEM;
7322 }
7323
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007324 /* Initialize target kmem_cache and mem_pools */
7325 ret = qlt_init();
7326 if (ret < 0) {
7327 kmem_cache_destroy(srb_cachep);
7328 return ret;
7329 } else if (ret > 0) {
7330 /*
7331 * If initiator mode is explictly disabled by qlt_init(),
7332 * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
7333 * performing scsi_scan_target() during LOOP UP event.
7334 */
7335 qla2xxx_transport_functions.disable_target_scan = 1;
7336 qla2xxx_transport_vport_functions.disable_target_scan = 1;
7337 }
7338
Linus Torvalds1da177e2005-04-16 15:20:36 -07007339 /* Derive version string. */
7340 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07007341 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07007342 strcat(qla2x00_version_str, "-debug");
Joe Carnucciofed0f682017-08-23 15:05:10 -07007343 if (ql2xextended_error_logging == 1)
7344 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Andrew Vasquez01819442006-06-23 16:11:10 -07007345
Quinn Tran0645cb82018-09-11 10:18:18 -07007346 if (ql2x_ini_mode == QLA2XXX_INI_MODE_DUAL)
7347 qla_insert_tgt_attrs();
7348
Andrew Vasquez1c97a122005-04-21 16:13:36 -04007349 qla2xxx_transport_template =
7350 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007351 if (!qla2xxx_transport_template) {
7352 kmem_cache_destroy(srb_cachep);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007353 ql_log(ql_log_fatal, NULL, 0x0002,
7354 "fc_attach_transport failed...Failing load!.\n");
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007355 qlt_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07007356 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007357 }
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007358
7359 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
7360 if (apidev_major < 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007361 ql_log(ql_log_fatal, NULL, 0x0003,
7362 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007363 }
7364
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007365 qla2xxx_transport_vport_template =
7366 fc_attach_transport(&qla2xxx_transport_vport_functions);
7367 if (!qla2xxx_transport_vport_template) {
7368 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007369 qlt_exit();
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007370 fc_release_transport(qla2xxx_transport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007371 ql_log(ql_log_fatal, NULL, 0x0004,
7372 "fc_attach_transport vport failed...Failing load!.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007373 return -ENODEV;
7374 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007375 ql_log(ql_log_info, NULL, 0x0005,
7376 "QLogic Fibre Channel HBA Driver: %s.\n",
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07007377 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007378 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007379 if (ret) {
7380 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007381 qlt_exit();
Andrew Vasquezfca29702005-07-06 10:31:47 -07007382 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007383 fc_release_transport(qla2xxx_transport_vport_template);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007384 ql_log(ql_log_fatal, NULL, 0x0006,
7385 "pci_register_driver failed...ret=%d Failing load!.\n",
7386 ret);
Andrew Vasquezfca29702005-07-06 10:31:47 -07007387 }
7388 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007389}
7390
7391/**
7392 * qla2x00_module_exit - Module cleanup.
7393 **/
7394static void __exit
7395qla2x00_module_exit(void)
7396{
Harish Zunjarrao6a03b4c2010-05-04 15:01:24 -07007397 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07007398 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08007399 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04007400 kmem_cache_destroy(srb_cachep);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04007401 qlt_exit();
Thomas Meyer75c1d482018-12-02 21:52:11 +01007402 kmem_cache_destroy(ctx_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007403 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007404 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007405}
7406
7407module_init(qla2x00_module_init);
7408module_exit(qla2x00_module_exit);
7409
7410MODULE_AUTHOR("QLogic Corporation");
7411MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
7412MODULE_LICENSE("GPL");
7413MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07007414MODULE_FIRMWARE(FW_FILE_ISP21XX);
7415MODULE_FIRMWARE(FW_FILE_ISP22XX);
7416MODULE_FIRMWARE(FW_FILE_ISP2300);
7417MODULE_FIRMWARE(FW_FILE_ISP2322);
7418MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08007419MODULE_FIRMWARE(FW_FILE_ISP25XX);